diff --git a/tools/clang/include/clang/AST/ASTContext.h b/tools/clang/include/clang/AST/ASTContext.h index ab0e33513b..94093a2733 100644 --- a/tools/clang/include/clang/AST/ASTContext.h +++ b/tools/clang/include/clang/AST/ASTContext.h @@ -844,7 +844,7 @@ class ASTContext : public RefCountedBase { CanQualType HalfFloatTy, Min16FloatTy, Min16IntTy, Min16UIntTy; CanQualType HLSLStringTy; CanQualType Int8_4PackedTy, UInt8_4PackedTy; - + CanQualType LinAlgMatrixTy; // HLSL Changes end // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. diff --git a/tools/clang/include/clang/AST/BuiltinTypes.def b/tools/clang/include/clang/AST/BuiltinTypes.def index 0887f9a319..640b5412ad 100644 --- a/tools/clang/include/clang/AST/BuiltinTypes.def +++ b/tools/clang/include/clang/AST/BuiltinTypes.def @@ -198,6 +198,9 @@ BUILTIN_TYPE(OCLSampler, OCLSamplerTy) // OpenCL event_t. BUILTIN_TYPE(OCLEvent, OCLEventTy) +// HLSL Change - __builtin_LinAlgMatrix type +BUILTIN_TYPE(LinAlgMatrix, LinAlgMatrixTy) + // This represents the type of an expression whose type is // totally unknown, e.g. 'T::foo'. It is permitted for this to // appear in situations where the structure of the type is diff --git a/tools/clang/include/clang/AST/Type.h b/tools/clang/include/clang/AST/Type.h index 2c96bbc295..7f23fd5fdf 100644 --- a/tools/clang/include/clang/AST/Type.h +++ b/tools/clang/include/clang/AST/Type.h @@ -1699,6 +1699,8 @@ class Type : public ExtQualsTypeCommonBase { bool isOpenCLSpecificType() const; // Any OpenCL specific type + bool isLinAlgMatrixType() const; // HLSL __builtin_LinAlgMatrix + /// Determines if this type, which must satisfy /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather /// than implicitly __strong. @@ -5420,6 +5422,12 @@ inline bool Type::isEventT() const { return isSpecificBuiltinType(BuiltinType::OCLEvent); } +// HLSL Change Starts +inline bool Type::isLinAlgMatrixType() const { + return isSpecificBuiltinType(BuiltinType::LinAlgMatrix); +} +// HLSL Change Ends + inline bool Type::isImageType() const { return isImage3dT() || isImage2dT() || isImage2dArrayT() || diff --git a/tools/clang/include/clang/Serialization/ASTBitCodes.h b/tools/clang/include/clang/Serialization/ASTBitCodes.h index b80b94e8d3..a3d3050077 100644 --- a/tools/clang/include/clang/Serialization/ASTBitCodes.h +++ b/tools/clang/include/clang/Serialization/ASTBitCodes.h @@ -687,73 +687,73 @@ namespace clang { /// by the AST context when it is created. enum PredefinedTypeIDs { /// \brief The NULL type. - PREDEF_TYPE_NULL_ID = 0, + PREDEF_TYPE_NULL_ID = 0, /// \brief The void type. - PREDEF_TYPE_VOID_ID = 1, + PREDEF_TYPE_VOID_ID = 1, /// \brief The 'bool' or '_Bool' type. - PREDEF_TYPE_BOOL_ID = 2, + PREDEF_TYPE_BOOL_ID = 2, /// \brief The 'char' type, when it is unsigned. - PREDEF_TYPE_CHAR_U_ID = 3, + PREDEF_TYPE_CHAR_U_ID = 3, /// \brief The 'unsigned char' type. - PREDEF_TYPE_UCHAR_ID = 4, + PREDEF_TYPE_UCHAR_ID = 4, /// \brief The 'unsigned short' type. - PREDEF_TYPE_USHORT_ID = 5, + PREDEF_TYPE_USHORT_ID = 5, /// \brief The 'unsigned int' type. - PREDEF_TYPE_UINT_ID = 6, + PREDEF_TYPE_UINT_ID = 6, /// \brief The 'unsigned long' type. - PREDEF_TYPE_ULONG_ID = 7, + PREDEF_TYPE_ULONG_ID = 7, /// \brief The 'unsigned long long' type. - PREDEF_TYPE_ULONGLONG_ID = 8, + PREDEF_TYPE_ULONGLONG_ID = 8, /// \brief The 'char' type, when it is signed. - PREDEF_TYPE_CHAR_S_ID = 9, + PREDEF_TYPE_CHAR_S_ID = 9, /// \brief The 'signed char' type. - PREDEF_TYPE_SCHAR_ID = 10, + PREDEF_TYPE_SCHAR_ID = 10, /// \brief The C++ 'wchar_t' type. - PREDEF_TYPE_WCHAR_ID = 11, + PREDEF_TYPE_WCHAR_ID = 11, /// \brief The (signed) 'short' type. - PREDEF_TYPE_SHORT_ID = 12, + PREDEF_TYPE_SHORT_ID = 12, /// \brief The (signed) 'int' type. - PREDEF_TYPE_INT_ID = 13, + PREDEF_TYPE_INT_ID = 13, /// \brief The (signed) 'long' type. - PREDEF_TYPE_LONG_ID = 14, + PREDEF_TYPE_LONG_ID = 14, /// \brief The (signed) 'long long' type. - PREDEF_TYPE_LONGLONG_ID = 15, + PREDEF_TYPE_LONGLONG_ID = 15, /// \brief The 'float' type. - PREDEF_TYPE_FLOAT_ID = 16, + PREDEF_TYPE_FLOAT_ID = 16, /// \brief The 'double' type. - PREDEF_TYPE_DOUBLE_ID = 17, + PREDEF_TYPE_DOUBLE_ID = 17, /// \brief The 'long double' type. PREDEF_TYPE_LONGDOUBLE_ID = 18, /// \brief The placeholder type for overloaded function sets. - PREDEF_TYPE_OVERLOAD_ID = 19, + PREDEF_TYPE_OVERLOAD_ID = 19, /// \brief The placeholder type for dependent types. - PREDEF_TYPE_DEPENDENT_ID = 20, + PREDEF_TYPE_DEPENDENT_ID = 20, /// \brief The '__uint128_t' type. - PREDEF_TYPE_UINT128_ID = 21, + PREDEF_TYPE_UINT128_ID = 21, /// \brief The '__int128_t' type. - PREDEF_TYPE_INT128_ID = 22, + PREDEF_TYPE_INT128_ID = 22, /// \brief The type of 'nullptr'. - PREDEF_TYPE_NULLPTR_ID = 23, + PREDEF_TYPE_NULLPTR_ID = 23, /// \brief The C++ 'char16_t' type. - PREDEF_TYPE_CHAR16_ID = 24, + PREDEF_TYPE_CHAR16_ID = 24, /// \brief The C++ 'char32_t' type. - PREDEF_TYPE_CHAR32_ID = 25, + PREDEF_TYPE_CHAR32_ID = 25, /// \brief The ObjC 'id' type. - PREDEF_TYPE_OBJC_ID = 26, + PREDEF_TYPE_OBJC_ID = 26, /// \brief The ObjC 'Class' type. - PREDEF_TYPE_OBJC_CLASS = 27, + PREDEF_TYPE_OBJC_CLASS = 27, /// \brief The ObjC 'SEL' type. - PREDEF_TYPE_OBJC_SEL = 28, + PREDEF_TYPE_OBJC_SEL = 28, /// \brief The 'unknown any' placeholder type. - PREDEF_TYPE_UNKNOWN_ANY = 29, + PREDEF_TYPE_UNKNOWN_ANY = 29, /// \brief The placeholder type for bound member functions. - PREDEF_TYPE_BOUND_MEMBER = 30, + PREDEF_TYPE_BOUND_MEMBER = 30, /// \brief The "auto" deduction type. - PREDEF_TYPE_AUTO_DEDUCT = 31, + PREDEF_TYPE_AUTO_DEDUCT = 31, /// \brief The "auto &&" deduction type. PREDEF_TYPE_AUTO_RREF_DEDUCT = 32, /// \brief The OpenCL 'half' / ARM NEON __fp16 type. - PREDEF_TYPE_HALF_ID = 33, + PREDEF_TYPE_HALF_ID = 33, /// \brief ARC's unbridged-cast placeholder type. PREDEF_TYPE_ARC_UNBRIDGED_CAST = 34, /// \brief The pseudo-object placeholder type. @@ -763,21 +763,23 @@ namespace clang { /// \brief The placeholder type for builtin functions. PREDEF_TYPE_BUILTIN_FN = 37, /// \brief OpenCL 1d image type. - PREDEF_TYPE_IMAGE1D_ID = 38, + PREDEF_TYPE_IMAGE1D_ID = 38, /// \brief OpenCL 1d image array type. PREDEF_TYPE_IMAGE1D_ARR_ID = 39, /// \brief OpenCL 1d image buffer type. PREDEF_TYPE_IMAGE1D_BUFF_ID = 40, /// \brief OpenCL 2d image type. - PREDEF_TYPE_IMAGE2D_ID = 41, + PREDEF_TYPE_IMAGE2D_ID = 41, /// \brief OpenCL 2d image array type. PREDEF_TYPE_IMAGE2D_ARR_ID = 42, /// \brief OpenCL 3d image type. - PREDEF_TYPE_IMAGE3D_ID = 43, + PREDEF_TYPE_IMAGE3D_ID = 43, /// \brief OpenCL event type. - PREDEF_TYPE_EVENT_ID = 44, + PREDEF_TYPE_EVENT_ID = 44, /// \brief OpenCL sampler type. - PREDEF_TYPE_SAMPLER_ID = 45 + PREDEF_TYPE_SAMPLER_ID = 45, + /// \brief HLSL LinAlg Matrix type. + PREDEF_TYPE_LINALG_MATRIX_ID = 46 }; /// \brief The number of predefined type IDs that are reserved for diff --git a/tools/clang/lib/AST/ASTContext.cpp b/tools/clang/lib/AST/ASTContext.cpp index e86874d119..a3a362cfea 100644 --- a/tools/clang/lib/AST/ASTContext.cpp +++ b/tools/clang/lib/AST/ASTContext.cpp @@ -1106,6 +1106,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target) { InitBuiltinType(LitFloatTy, BuiltinType::LitFloat); InitBuiltinType(Int8_4PackedTy, BuiltinType::Int8_4Packed); InitBuiltinType(UInt8_4PackedTy, BuiltinType::UInt8_4Packed); + InitBuiltinType(LinAlgMatrixTy, BuiltinType::LinAlgMatrix); HLSLStringTy = this->getPointerType(CharTy); @@ -1697,6 +1698,11 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { Width = 64; Align = 64; break; + case BuiltinType::LinAlgMatrix: + // Model it as a pointer an to opaque type + Width = Target->getPointerWidth(0); + Align = Target->getPointerAlign(0); + break; // HLSL Change Ends case BuiltinType::LongDouble: Width = Target->getLongDoubleWidth(); diff --git a/tools/clang/lib/AST/ItaniumMangle.cpp b/tools/clang/lib/AST/ItaniumMangle.cpp index 8da491871b..32a146b633 100644 --- a/tools/clang/lib/AST/ItaniumMangle.cpp +++ b/tools/clang/lib/AST/ItaniumMangle.cpp @@ -2050,6 +2050,9 @@ void CXXNameMangler::mangleType(const BuiltinType *T) { case BuiltinType::HalfFloat: Out << "half_float"; break; case BuiltinType::Int8_4Packed: Out << "int8_t4_packed"; break; case BuiltinType::UInt8_4Packed: Out << "uint8_t4_packed"; break; + case BuiltinType::LinAlgMatrix: + Out << "22__builtin_LinAlgMatrix"; + break; // HLSL Change ends } } diff --git a/tools/clang/lib/AST/MicrosoftMangle.cpp b/tools/clang/lib/AST/MicrosoftMangle.cpp index 35cbb7cd46..cf7f0bc2b3 100644 --- a/tools/clang/lib/AST/MicrosoftMangle.cpp +++ b/tools/clang/lib/AST/MicrosoftMangle.cpp @@ -1623,6 +1623,9 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers, case BuiltinType::UInt8_4Packed: Out << "$ui8_4pk@"; break; + case BuiltinType::LinAlgMatrix: + Out << "$linalg_matrix@"; + break; // HLSL Change Ends } } diff --git a/tools/clang/lib/AST/Type.cpp b/tools/clang/lib/AST/Type.cpp index 51c20218cc..cbfa49dfd8 100644 --- a/tools/clang/lib/AST/Type.cpp +++ b/tools/clang/lib/AST/Type.cpp @@ -2548,7 +2548,9 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const { case LitInt: return "literal int"; case Int8_4Packed: return "int8_t4_packed"; case UInt8_4Packed: return "uint8_t4_packed"; - // HLSL Change Ends + case LinAlgMatrix: + return "__builtin_LinAlgMatrix"; + // HLSL Change Ends } llvm_unreachable("Invalid builtin type."); @@ -3504,6 +3506,7 @@ bool Type::canHaveNullability() const { case BuiltinType::OCLImage3d: case BuiltinType::OCLSampler: case BuiltinType::OCLEvent: + case BuiltinType::LinAlgMatrix: case BuiltinType::BuiltinFn: case BuiltinType::NullPtr: return false; diff --git a/tools/clang/lib/AST/TypeLoc.cpp b/tools/clang/lib/AST/TypeLoc.cpp index e21b4b76fd..362b5f7a2a 100644 --- a/tools/clang/lib/AST/TypeLoc.cpp +++ b/tools/clang/lib/AST/TypeLoc.cpp @@ -320,7 +320,7 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const { case BuiltinType::Float: case BuiltinType::Double: case BuiltinType::LongDouble: - // HLSL Change Starts + // HLSL Change Starts case BuiltinType::HalfFloat: case BuiltinType::Min10Float: case BuiltinType::Min16Float: @@ -331,7 +331,8 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const { case BuiltinType::LitInt: case BuiltinType::Int8_4Packed: case BuiltinType::UInt8_4Packed: - // HLSL Change Ends + case BuiltinType::LinAlgMatrix: + // HLSL Change Ends llvm_unreachable("Builtin type needs extra local data!"); // Fall through, if the impossible happens. diff --git a/tools/clang/lib/CodeGen/CodeGenTypes.cpp b/tools/clang/lib/CodeGen/CodeGenTypes.cpp index 82328c8fb5..51fbaa8935 100644 --- a/tools/clang/lib/CodeGen/CodeGenTypes.cpp +++ b/tools/clang/lib/CodeGen/CodeGenTypes.cpp @@ -480,7 +480,14 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { case BuiltinType::OCLEvent: ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty); break; - + + // HLSL Change Starts + case BuiltinType::LinAlgMatrix: + llvm_unreachable("__builtin_LinAlgMatrix type without attributes is not " + "a valid LinAlMatrix handle"); + break; + // HLSL Change Ends + case BuiltinType::Dependent: #define BUILTIN_TYPE(Id, SingletonId) #define PLACEHOLDER_TYPE(Id, SingletonId) \ diff --git a/tools/clang/lib/CodeGen/ItaniumCXXABI.cpp b/tools/clang/lib/CodeGen/ItaniumCXXABI.cpp index f39ec6d497..d1ac099950 100644 --- a/tools/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/tools/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -2378,6 +2378,7 @@ static bool TypeInfoIsInStandardLibrary(const BuiltinType *Ty) { case BuiltinType::LitFloat: case BuiltinType::Int8_4Packed: case BuiltinType::UInt8_4Packed: + case BuiltinType::LinAlgMatrix: llvm_unreachable("FIXME: HLSL types are unsupported!"); break; } diff --git a/tools/clang/lib/Sema/Sema.cpp b/tools/clang/lib/Sema/Sema.cpp index ab2d023dbb..0698b97e87 100644 --- a/tools/clang/lib/Sema/Sema.cpp +++ b/tools/clang/lib/Sema/Sema.cpp @@ -242,6 +242,10 @@ void Sema::Initialize() { } } + // HLSL Change - '__builtin_LinAlgMatrix' + if (PP.getLangOpts().HLSL) + addImplicitTypedef("__builtin_LinAlgMatrix", Context.LinAlgMatrixTy); + DeclarationName BuiltinVaList = &Context.Idents.get("__builtin_va_list"); if (IdResolver.begin(BuiltinVaList) == IdResolver.end()) PushOnScopeChains(Context.getBuiltinVaListDecl(), TUScope); diff --git a/tools/clang/lib/Serialization/ASTCommon.cpp b/tools/clang/lib/Serialization/ASTCommon.cpp index b1bf4a6bff..dca4c3fc53 100644 --- a/tools/clang/lib/Serialization/ASTCommon.cpp +++ b/tools/clang/lib/Serialization/ASTCommon.cpp @@ -70,6 +70,9 @@ serialization::TypeIdxFromBuiltin(const BuiltinType *BT) { case BuiltinType::OCLImage3d: ID = PREDEF_TYPE_IMAGE3D_ID; break; case BuiltinType::OCLSampler: ID = PREDEF_TYPE_SAMPLER_ID; break; case BuiltinType::OCLEvent: ID = PREDEF_TYPE_EVENT_ID; break; + case BuiltinType::LinAlgMatrix: + ID = PREDEF_TYPE_LINALG_MATRIX_ID; + break; case BuiltinType::BuiltinFn: ID = PREDEF_TYPE_BUILTIN_FN; break; diff --git a/tools/clang/lib/Serialization/ASTReader.cpp b/tools/clang/lib/Serialization/ASTReader.cpp index 7f9bb26734..68367fc582 100644 --- a/tools/clang/lib/Serialization/ASTReader.cpp +++ b/tools/clang/lib/Serialization/ASTReader.cpp @@ -5755,6 +5755,9 @@ QualType ASTReader::GetType(TypeID ID) { case PREDEF_TYPE_IMAGE3D_ID: T = Context.OCLImage3dTy; break; case PREDEF_TYPE_SAMPLER_ID: T = Context.OCLSamplerTy; break; case PREDEF_TYPE_EVENT_ID: T = Context.OCLEventTy; break; + case PREDEF_TYPE_LINALG_MATRIX_ID: + T = Context.LinAlgMatrixTy; + break; case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; case PREDEF_TYPE_AUTO_RREF_DEDUCT: diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/builtin-matrix-handle-type-ast.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/builtin-matrix-handle-type-ast.hlsl new file mode 100644 index 0000000000..05241a9b8d --- /dev/null +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/builtin-matrix-handle-type-ast.hlsl @@ -0,0 +1,28 @@ +// REQUIRES: dxil-1-10 +// RUN: %dxc -T lib_6_10 -ast-dump %s | FileCheck %s + +// CHECK: CXXRecordDecl {{.*}} struct S definition +// CHECK: FieldDecl {{.*}} handle '__builtin_LinAlgMatrix':'__builtin_LinAlgMatrix' +struct S { + __builtin_LinAlgMatrix handle; +}; + +// CHECK: VarDecl {{.*}} global_handle '__builtin_LinAlgMatrix':'__builtin_LinAlgMatrix' +__builtin_LinAlgMatrix global_handle; + +// CHECK: FunctionDecl {{.*}} f1 'void (__builtin_LinAlgMatrix)' +// CHECK: ParmVarDecl {{.*}} m '__builtin_LinAlgMatrix':'__builtin_LinAlgMatrix' +void f1(__builtin_LinAlgMatrix m); + +// CHECK: FunctionDecl {{.*}} f2 '__builtin_LinAlgMatrix ()' +__builtin_LinAlgMatrix f2(); + +// CHECK: FunctionDecl {{.*}} main 'void ()' +// CHECK-NEXT: CompoundStmt +// CHECK-NEXT: DeclStmt +// CHECK-NEXT: VarDecl {{.*}} m '__builtin_LinAlgMatrix':'__builtin_LinAlgMatrix' +[shader("compute")] +[numthreads(4,1,1)] +void main() { + __builtin_LinAlgMatrix m; +} diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/builtin-matrix-handle-type.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/builtin-matrix-handle-type.hlsl new file mode 100644 index 0000000000..c9c885f3ec --- /dev/null +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/builtin-matrix-handle-type.hlsl @@ -0,0 +1,47 @@ +// REQUIRES: dxil-1-10 +// RUN: %dxc -T lib_6_10 -verify %s + +__builtin_LinAlgMatrix global_handle; + +static __builtin_LinAlgMatrix static_handle; + +groupshared __builtin_LinAlgMatrix gs_handle; + +__builtin_LinAlgMatrix array[2]; + +cbuffer CB { + __builtin_LinAlgMatrix cb_handle; +}; + +struct S { + __builtin_LinAlgMatrix handle; +}; + +S s; + +void f1(__builtin_LinAlgMatrix m); + +__builtin_LinAlgMatrix f2(); + +// expected-error@+1 {{typedef redefinition with different types ('int' vs '__builtin_LinAlgMatrix')}} +typedef int __builtin_LinAlgMatrix; + +[shader("compute")] +[numthreads(4,1,1)] +void main() { + __builtin_LinAlgMatrix m; + + m = s.handle; + + f1(m); + m = f2(); + + // expected-error@+1 {{numeric type expected}} + m++; + + // expected-error@+1 {{numeric type expected}} + m = m * 2; + + // expected-error@+1 {{numeric type expected}} + bool a = m && s.handle; +} diff --git a/tools/clang/tools/libclang/CIndex.cpp b/tools/clang/tools/libclang/CIndex.cpp index be1414bab1..f308848c98 100644 --- a/tools/clang/tools/libclang/CIndex.cpp +++ b/tools/clang/tools/libclang/CIndex.cpp @@ -1465,6 +1465,7 @@ bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { case BuiltinType::OCLImage3d: case BuiltinType::OCLSampler: case BuiltinType::OCLEvent: + case BuiltinType::LinAlgMatrix: #define BUILTIN_TYPE(Id, SingletonId) #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id: #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id: