Skip to content

Commit 7936ebc

Browse files
authored
[SM6.10] Add built-in type for LinAlg Matrix handle (#8090)
Adds a built-in type `__builtin_LinAlgMatrix` that will be used in LinAlg Matrix implementation for SM 6.10. Closes #8121
1 parent da2d4a3 commit 7936ebc

File tree

17 files changed

+165
-42
lines changed

17 files changed

+165
-42
lines changed

tools/clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
844844
CanQualType HalfFloatTy, Min16FloatTy, Min16IntTy, Min16UIntTy;
845845
CanQualType HLSLStringTy;
846846
CanQualType Int8_4PackedTy, UInt8_4PackedTy;
847-
847+
CanQualType LinAlgMatrixTy;
848848
// HLSL Changes end
849849

850850
// Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.

tools/clang/include/clang/AST/BuiltinTypes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ BUILTIN_TYPE(OCLSampler, OCLSamplerTy)
198198
// OpenCL event_t.
199199
BUILTIN_TYPE(OCLEvent, OCLEventTy)
200200

201+
// HLSL Change - __builtin_LinAlgMatrix type
202+
BUILTIN_TYPE(LinAlgMatrix, LinAlgMatrixTy)
203+
201204
// This represents the type of an expression whose type is
202205
// totally unknown, e.g. 'T::foo'. It is permitted for this to
203206
// appear in situations where the structure of the type is

tools/clang/include/clang/AST/Type.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,8 @@ class Type : public ExtQualsTypeCommonBase {
16991699

17001700
bool isOpenCLSpecificType() const; // Any OpenCL specific type
17011701

1702+
bool isLinAlgMatrixType() const; // HLSL __builtin_LinAlgMatrix
1703+
17021704
/// Determines if this type, which must satisfy
17031705
/// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
17041706
/// than implicitly __strong.
@@ -5420,6 +5422,12 @@ inline bool Type::isEventT() const {
54205422
return isSpecificBuiltinType(BuiltinType::OCLEvent);
54215423
}
54225424

5425+
// HLSL Change Starts
5426+
inline bool Type::isLinAlgMatrixType() const {
5427+
return isSpecificBuiltinType(BuiltinType::LinAlgMatrix);
5428+
}
5429+
// HLSL Change Ends
5430+
54235431
inline bool Type::isImageType() const {
54245432
return isImage3dT() ||
54255433
isImage2dT() || isImage2dArrayT() ||

tools/clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -687,73 +687,73 @@ namespace clang {
687687
/// by the AST context when it is created.
688688
enum PredefinedTypeIDs {
689689
/// \brief The NULL type.
690-
PREDEF_TYPE_NULL_ID = 0,
690+
PREDEF_TYPE_NULL_ID = 0,
691691
/// \brief The void type.
692-
PREDEF_TYPE_VOID_ID = 1,
692+
PREDEF_TYPE_VOID_ID = 1,
693693
/// \brief The 'bool' or '_Bool' type.
694-
PREDEF_TYPE_BOOL_ID = 2,
694+
PREDEF_TYPE_BOOL_ID = 2,
695695
/// \brief The 'char' type, when it is unsigned.
696-
PREDEF_TYPE_CHAR_U_ID = 3,
696+
PREDEF_TYPE_CHAR_U_ID = 3,
697697
/// \brief The 'unsigned char' type.
698-
PREDEF_TYPE_UCHAR_ID = 4,
698+
PREDEF_TYPE_UCHAR_ID = 4,
699699
/// \brief The 'unsigned short' type.
700-
PREDEF_TYPE_USHORT_ID = 5,
700+
PREDEF_TYPE_USHORT_ID = 5,
701701
/// \brief The 'unsigned int' type.
702-
PREDEF_TYPE_UINT_ID = 6,
702+
PREDEF_TYPE_UINT_ID = 6,
703703
/// \brief The 'unsigned long' type.
704-
PREDEF_TYPE_ULONG_ID = 7,
704+
PREDEF_TYPE_ULONG_ID = 7,
705705
/// \brief The 'unsigned long long' type.
706-
PREDEF_TYPE_ULONGLONG_ID = 8,
706+
PREDEF_TYPE_ULONGLONG_ID = 8,
707707
/// \brief The 'char' type, when it is signed.
708-
PREDEF_TYPE_CHAR_S_ID = 9,
708+
PREDEF_TYPE_CHAR_S_ID = 9,
709709
/// \brief The 'signed char' type.
710-
PREDEF_TYPE_SCHAR_ID = 10,
710+
PREDEF_TYPE_SCHAR_ID = 10,
711711
/// \brief The C++ 'wchar_t' type.
712-
PREDEF_TYPE_WCHAR_ID = 11,
712+
PREDEF_TYPE_WCHAR_ID = 11,
713713
/// \brief The (signed) 'short' type.
714-
PREDEF_TYPE_SHORT_ID = 12,
714+
PREDEF_TYPE_SHORT_ID = 12,
715715
/// \brief The (signed) 'int' type.
716-
PREDEF_TYPE_INT_ID = 13,
716+
PREDEF_TYPE_INT_ID = 13,
717717
/// \brief The (signed) 'long' type.
718-
PREDEF_TYPE_LONG_ID = 14,
718+
PREDEF_TYPE_LONG_ID = 14,
719719
/// \brief The (signed) 'long long' type.
720-
PREDEF_TYPE_LONGLONG_ID = 15,
720+
PREDEF_TYPE_LONGLONG_ID = 15,
721721
/// \brief The 'float' type.
722-
PREDEF_TYPE_FLOAT_ID = 16,
722+
PREDEF_TYPE_FLOAT_ID = 16,
723723
/// \brief The 'double' type.
724-
PREDEF_TYPE_DOUBLE_ID = 17,
724+
PREDEF_TYPE_DOUBLE_ID = 17,
725725
/// \brief The 'long double' type.
726726
PREDEF_TYPE_LONGDOUBLE_ID = 18,
727727
/// \brief The placeholder type for overloaded function sets.
728-
PREDEF_TYPE_OVERLOAD_ID = 19,
728+
PREDEF_TYPE_OVERLOAD_ID = 19,
729729
/// \brief The placeholder type for dependent types.
730-
PREDEF_TYPE_DEPENDENT_ID = 20,
730+
PREDEF_TYPE_DEPENDENT_ID = 20,
731731
/// \brief The '__uint128_t' type.
732-
PREDEF_TYPE_UINT128_ID = 21,
732+
PREDEF_TYPE_UINT128_ID = 21,
733733
/// \brief The '__int128_t' type.
734-
PREDEF_TYPE_INT128_ID = 22,
734+
PREDEF_TYPE_INT128_ID = 22,
735735
/// \brief The type of 'nullptr'.
736-
PREDEF_TYPE_NULLPTR_ID = 23,
736+
PREDEF_TYPE_NULLPTR_ID = 23,
737737
/// \brief The C++ 'char16_t' type.
738-
PREDEF_TYPE_CHAR16_ID = 24,
738+
PREDEF_TYPE_CHAR16_ID = 24,
739739
/// \brief The C++ 'char32_t' type.
740-
PREDEF_TYPE_CHAR32_ID = 25,
740+
PREDEF_TYPE_CHAR32_ID = 25,
741741
/// \brief The ObjC 'id' type.
742-
PREDEF_TYPE_OBJC_ID = 26,
742+
PREDEF_TYPE_OBJC_ID = 26,
743743
/// \brief The ObjC 'Class' type.
744-
PREDEF_TYPE_OBJC_CLASS = 27,
744+
PREDEF_TYPE_OBJC_CLASS = 27,
745745
/// \brief The ObjC 'SEL' type.
746-
PREDEF_TYPE_OBJC_SEL = 28,
746+
PREDEF_TYPE_OBJC_SEL = 28,
747747
/// \brief The 'unknown any' placeholder type.
748-
PREDEF_TYPE_UNKNOWN_ANY = 29,
748+
PREDEF_TYPE_UNKNOWN_ANY = 29,
749749
/// \brief The placeholder type for bound member functions.
750-
PREDEF_TYPE_BOUND_MEMBER = 30,
750+
PREDEF_TYPE_BOUND_MEMBER = 30,
751751
/// \brief The "auto" deduction type.
752-
PREDEF_TYPE_AUTO_DEDUCT = 31,
752+
PREDEF_TYPE_AUTO_DEDUCT = 31,
753753
/// \brief The "auto &&" deduction type.
754754
PREDEF_TYPE_AUTO_RREF_DEDUCT = 32,
755755
/// \brief The OpenCL 'half' / ARM NEON __fp16 type.
756-
PREDEF_TYPE_HALF_ID = 33,
756+
PREDEF_TYPE_HALF_ID = 33,
757757
/// \brief ARC's unbridged-cast placeholder type.
758758
PREDEF_TYPE_ARC_UNBRIDGED_CAST = 34,
759759
/// \brief The pseudo-object placeholder type.
@@ -763,21 +763,23 @@ namespace clang {
763763
/// \brief The placeholder type for builtin functions.
764764
PREDEF_TYPE_BUILTIN_FN = 37,
765765
/// \brief OpenCL 1d image type.
766-
PREDEF_TYPE_IMAGE1D_ID = 38,
766+
PREDEF_TYPE_IMAGE1D_ID = 38,
767767
/// \brief OpenCL 1d image array type.
768768
PREDEF_TYPE_IMAGE1D_ARR_ID = 39,
769769
/// \brief OpenCL 1d image buffer type.
770770
PREDEF_TYPE_IMAGE1D_BUFF_ID = 40,
771771
/// \brief OpenCL 2d image type.
772-
PREDEF_TYPE_IMAGE2D_ID = 41,
772+
PREDEF_TYPE_IMAGE2D_ID = 41,
773773
/// \brief OpenCL 2d image array type.
774774
PREDEF_TYPE_IMAGE2D_ARR_ID = 42,
775775
/// \brief OpenCL 3d image type.
776-
PREDEF_TYPE_IMAGE3D_ID = 43,
776+
PREDEF_TYPE_IMAGE3D_ID = 43,
777777
/// \brief OpenCL event type.
778-
PREDEF_TYPE_EVENT_ID = 44,
778+
PREDEF_TYPE_EVENT_ID = 44,
779779
/// \brief OpenCL sampler type.
780-
PREDEF_TYPE_SAMPLER_ID = 45
780+
PREDEF_TYPE_SAMPLER_ID = 45,
781+
/// \brief HLSL LinAlg Matrix type.
782+
PREDEF_TYPE_LINALG_MATRIX_ID = 46
781783
};
782784

783785
/// \brief The number of predefined type IDs that are reserved for

tools/clang/lib/AST/ASTContext.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target) {
11061106
InitBuiltinType(LitFloatTy, BuiltinType::LitFloat);
11071107
InitBuiltinType(Int8_4PackedTy, BuiltinType::Int8_4Packed);
11081108
InitBuiltinType(UInt8_4PackedTy, BuiltinType::UInt8_4Packed);
1109+
InitBuiltinType(LinAlgMatrixTy, BuiltinType::LinAlgMatrix);
11091110

11101111
HLSLStringTy = this->getPointerType(CharTy);
11111112

@@ -1697,6 +1698,11 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
16971698
Width = 64;
16981699
Align = 64;
16991700
break;
1701+
case BuiltinType::LinAlgMatrix:
1702+
// Model it as a pointer an to opaque type
1703+
Width = Target->getPointerWidth(0);
1704+
Align = Target->getPointerAlign(0);
1705+
break;
17001706
// HLSL Change Ends
17011707
case BuiltinType::LongDouble:
17021708
Width = Target->getLongDoubleWidth();

tools/clang/lib/AST/ItaniumMangle.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,9 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
20502050
case BuiltinType::HalfFloat: Out << "half_float"; break;
20512051
case BuiltinType::Int8_4Packed: Out << "int8_t4_packed"; break;
20522052
case BuiltinType::UInt8_4Packed: Out << "uint8_t4_packed"; break;
2053+
case BuiltinType::LinAlgMatrix:
2054+
Out << "22__builtin_LinAlgMatrix";
2055+
break;
20532056
// HLSL Change ends
20542057
}
20552058
}

tools/clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,9 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
16231623
case BuiltinType::UInt8_4Packed:
16241624
Out << "$ui8_4pk@";
16251625
break;
1626+
case BuiltinType::LinAlgMatrix:
1627+
Out << "$linalg_matrix@";
1628+
break;
16261629
// HLSL Change Ends
16271630
}
16281631
}

tools/clang/lib/AST/Type.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,9 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
25482548
case LitInt: return "literal int";
25492549
case Int8_4Packed: return "int8_t4_packed";
25502550
case UInt8_4Packed: return "uint8_t4_packed";
2551-
// HLSL Change Ends
2551+
case LinAlgMatrix:
2552+
return "__builtin_LinAlgMatrix";
2553+
// HLSL Change Ends
25522554
}
25532555

25542556
llvm_unreachable("Invalid builtin type.");
@@ -3504,6 +3506,7 @@ bool Type::canHaveNullability() const {
35043506
case BuiltinType::OCLImage3d:
35053507
case BuiltinType::OCLSampler:
35063508
case BuiltinType::OCLEvent:
3509+
case BuiltinType::LinAlgMatrix:
35073510
case BuiltinType::BuiltinFn:
35083511
case BuiltinType::NullPtr:
35093512
return false;

tools/clang/lib/AST/TypeLoc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
320320
case BuiltinType::Float:
321321
case BuiltinType::Double:
322322
case BuiltinType::LongDouble:
323-
// HLSL Change Starts
323+
// HLSL Change Starts
324324
case BuiltinType::HalfFloat:
325325
case BuiltinType::Min10Float:
326326
case BuiltinType::Min16Float:
@@ -331,7 +331,8 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
331331
case BuiltinType::LitInt:
332332
case BuiltinType::Int8_4Packed:
333333
case BuiltinType::UInt8_4Packed:
334-
// HLSL Change Ends
334+
case BuiltinType::LinAlgMatrix:
335+
// HLSL Change Ends
335336
llvm_unreachable("Builtin type needs extra local data!");
336337
// Fall through, if the impossible happens.
337338

tools/clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,14 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
480480
case BuiltinType::OCLEvent:
481481
ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty);
482482
break;
483-
483+
484+
// HLSL Change Starts
485+
case BuiltinType::LinAlgMatrix:
486+
llvm_unreachable("__builtin_LinAlgMatrix type without attributes is not "
487+
"a valid LinAlMatrix handle");
488+
break;
489+
// HLSL Change Ends
490+
484491
case BuiltinType::Dependent:
485492
#define BUILTIN_TYPE(Id, SingletonId)
486493
#define PLACEHOLDER_TYPE(Id, SingletonId) \

0 commit comments

Comments
 (0)