Skip to content
2 changes: 1 addition & 1 deletion tools/clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
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.
Expand Down
3 changes: 3 additions & 0 deletions tools/clang/include/clang/AST/BuiltinTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tools/clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() ||
Expand Down
76 changes: 39 additions & 37 deletions tools/clang/include/clang/Serialization/ASTBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tools/clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tools/clang/lib/AST/ItaniumMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
3 changes: 3 additions & 0 deletions tools/clang/lib/AST/MicrosoftMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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@";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before, don't we need to capture matrix properties into mangling?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mangling of just the base built-in type, which can be spell out in the code, although the __builtin prefix should discourage people from doing that. The attributes are added in a separate PR.

break;
// HLSL Change Ends
}
}
Expand Down
5 changes: 4 additions & 1 deletion tools/clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions tools/clang/lib/AST/TypeLoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand Down
9 changes: 8 additions & 1 deletion tools/clang/lib/CodeGen/CodeGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
1 change: 1 addition & 0 deletions tools/clang/lib/CodeGen/ItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions tools/clang/lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions tools/clang/lib/Serialization/ASTCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, but we never supported AST serialization in this code base, and there are many missing pieces already. That's why we never added the other HLSL types here.

break;
case BuiltinType::BuiltinFn:
ID = PREDEF_TYPE_BUILTIN_FN; break;

Expand Down
3 changes: 3 additions & 0 deletions tools/clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions tools/clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down