Skip to content

Commit 52956b0

Browse files
hekotabogner
andauthored
[HLSL] Implement intangible AST type (#97362)
HLSL has a set of intangible types which are described in in the [draft HLSL Specification (**[Basic.types]**)](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf): There are special implementation-defined types such as handle types, which fall into a category of standard intangible types. Intangible types are types that have no defined object representation or value representation, as such the size is unknown at compile time. A class type T is an intangible class type if it contains an base classes or members of intangible class type, standard intangible type, or arrays of such types. Standard intangible types and intangible class types are collectively called intangible types([9](https://microsoft.github.io/hlsl-specs/specs/hlsl.html#Intangible)). This PR implements one standard intangible type `__hlsl_resource_t` and sets up the infrastructure that will make it easier to add more in the future, such as samplers or raytracing payload handles. The HLSL intangible types are declared in `clang/include/clang/Basic/HLSLIntangibleTypes.def` and this file is included with related macro definition in most places that require edits when a new type is added. The new types are added as keywords and not typedefs to make sure they cannot be redeclared, and they can only be declared in builtin implicit headers. The `__hlsl_resource_t` type represents a handle to a memory resource and it is going to be used in builtin HLSL buffer types like this: template <typename T> class RWBuffer { [[hlsl::contained_type(T)]] [[hlsl::is_rov(false)]] [[hlsl::resource_class(uav)]] __hlsl_resource_t Handle; }; Part 1/3 of #90631. --------- Co-authored-by: Justin Bogner <[email protected]>
1 parent cec341b commit 52956b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+315
-12
lines changed

clang/include/clang-c/Index.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2978,7 +2978,10 @@ enum CXTypeKind {
29782978

29792979
CXType_ExtVector = 176,
29802980
CXType_Atomic = 177,
2981-
CXType_BTFTagAttributed = 178
2981+
CXType_BTFTagAttributed = 178,
2982+
2983+
// HLSL Intangible Types
2984+
CXType_HLSLResource = 179,
29822985
};
29832986

29842987
/**

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
11731173
#include "clang/Basic/WebAssemblyReferenceTypes.def"
11741174
#define AMDGPU_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
11751175
#include "clang/Basic/AMDGPUTypes.def"
1176+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
1177+
#include "clang/Basic/HLSLIntangibleTypes.def"
11761178

11771179
// Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
11781180
mutable QualType AutoDeductTy; // Deduction against 'auto'.

clang/include/clang/AST/Type.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
26302630
bool isBitIntType() const; // Bit-precise integer type
26312631
bool isOpenCLSpecificType() const; // Any OpenCL specific type
26322632

2633+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) bool is##Id##Type() const;
2634+
#include "clang/Basic/HLSLIntangibleTypes.def"
2635+
bool isHLSLSpecificType() const; // Any HLSL specific type
2636+
26332637
/// Determines if this type, which must satisfy
26342638
/// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
26352639
/// than implicitly __strong.
@@ -3022,6 +3026,9 @@ class BuiltinType : public Type {
30223026
// AMDGPU types
30233027
#define AMDGPU_TYPE(Name, Id, SingletonId) Id,
30243028
#include "clang/Basic/AMDGPUTypes.def"
3029+
// HLSL intangible Types
3030+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) Id,
3031+
#include "clang/Basic/HLSLIntangibleTypes.def"
30253032
// All other builtin types
30263033
#define BUILTIN_TYPE(Id, SingletonId) Id,
30273034
#define LAST_BUILTIN_TYPE(Id) LastKind = Id
@@ -8261,6 +8268,19 @@ inline bool Type::isOpenCLSpecificType() const {
82618268
isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
82628269
}
82638270

8271+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
8272+
inline bool Type::is##Id##Type() const { \
8273+
return isSpecificBuiltinType(BuiltinType::Id); \
8274+
}
8275+
#include "clang/Basic/HLSLIntangibleTypes.def"
8276+
8277+
inline bool Type::isHLSLSpecificType() const {
8278+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
8279+
return
8280+
#include "clang/Basic/HLSLIntangibleTypes.def"
8281+
false; // end boolean or operation
8282+
}
8283+
82648284
inline bool Type::isTemplateTypeParmType() const {
82658285
return isa<TemplateTypeParmType>(CanonicalType);
82668286
}

clang/include/clang/AST/TypeProperties.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,10 @@ let Class = BuiltinType in {
872872
case BuiltinType::ID: return ctx.SINGLETON_ID;
873873
#include "clang/Basic/AMDGPUTypes.def"
874874

875+
#define HLSL_INTANGIBLE_TYPE(NAME, ID, SINGLETON_ID) \
876+
case BuiltinType::ID: return ctx.SINGLETON_ID;
877+
#include "clang/Basic/HLSLIntangibleTypes.def"
878+
875879
#define BUILTIN_TYPE(ID, SINGLETON_ID) \
876880
case BuiltinType::ID: return ctx.SINGLETON_ID;
877881
#include "clang/AST/BuiltinTypes.def"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===-- HLSLIntangibleTypes.def - HLSL standard intangible types ----*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===--------------------------------------------------------------------------===//
8+
//
9+
// This file defines HLSL standard intangible types. These are implementation-
10+
// defined types such as handle types that have no defined object
11+
// representation or value representation and their size is unknown at compile
12+
// time.
13+
//
14+
// The macro is:
15+
//
16+
// HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)
17+
//
18+
// where:
19+
//
20+
// - Name is the name of the builtin type.
21+
//
22+
// - BuiltinType::Id is the enumerator defining the type.
23+
//
24+
// - Context.SingletonId is the global singleton of this type.
25+
//
26+
// To include this file, define HLSL_INTANGIBLE_TYPE.
27+
// The macro will be undefined after inclusion.
28+
//
29+
//===----------------------------------------------------------------------===//
30+
31+
HLSL_INTANGIBLE_TYPE(__hlsl_resource_t, HLSLResource, HLSLResourceTy)
32+
33+
#undef HLSL_INTANGIBLE_TYPE

clang/include/clang/Basic/Specifiers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ namespace clang {
9898
#define GENERIC_IMAGE_TYPE(ImgType, Id) \
9999
TST_##ImgType##_t, // OpenCL image types
100100
#include "clang/Basic/OpenCLImageTypes.def"
101+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
102+
TST_##Name, // HLSL Intangible Types
103+
#include "clang/Basic/HLSLIntangibleTypes.def"
101104
TST_error // erroneous type
102105
};
103106

clang/include/clang/Basic/TokenKinds.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,9 @@ KEYWORD(groupshared , KEYHLSL)
654654
KEYWORD(in , KEYHLSL)
655655
KEYWORD(inout , KEYHLSL)
656656
KEYWORD(out , KEYHLSL)
657+
// HLSL Intangible Types
658+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
659+
#include "clang/Basic/HLSLIntangibleTypes.def"
657660

658661
// OpenMP Type Traits
659662
UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, OpenMPRequiredSimdAlign, KEYALL)

clang/include/clang/Sema/DeclSpec.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ class DeclSpec {
322322
#define GENERIC_IMAGE_TYPE(ImgType, Id) \
323323
static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t;
324324
#include "clang/Basic/OpenCLImageTypes.def"
325+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
326+
static const TST TST_##Name = clang::TST_##Name;
327+
#include "clang/Basic/HLSLIntangibleTypes.def"
325328
static const TST TST_error = clang::TST_error;
326329

327330
// type-qualifiers

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,9 @@ enum PredefinedTypeIDs {
11211121
// \brief AMDGPU types with auto numeration
11221122
#define AMDGPU_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
11231123
#include "clang/Basic/AMDGPUTypes.def"
1124+
// \brief HLSL intangible types with auto numeration
1125+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
1126+
#include "clang/Basic/HLSLIntangibleTypes.def"
11241127

11251128
/// The placeholder type for unresolved templates.
11261129
PREDEF_TYPE_UNRESOLVED_TEMPLATE,
@@ -1133,7 +1136,7 @@ enum PredefinedTypeIDs {
11331136
///
11341137
/// Type IDs for non-predefined types will start at
11351138
/// NUM_PREDEF_TYPE_IDs.
1136-
const unsigned NUM_PREDEF_TYPE_IDS = 504;
1139+
const unsigned NUM_PREDEF_TYPE_IDS = 505;
11371140

11381141
// Ensure we do not overrun the predefined types we reserved
11391142
// in the enum PredefinedTypeIDs above.

clang/include/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module Clang_Basic {
7070
textual header "clang/Basic/DiagnosticOptions.def"
7171
textual header "clang/Basic/FPOptions.def"
7272
textual header "clang/Basic/Features.def"
73+
textual header "clang/Basic/HLSLIntangibleTypes.def"
7374
textual header "clang/Basic/LangOptions.def"
7475
textual header "clang/Basic/MSP430Target.def"
7576
textual header "clang/Basic/OpenACCClauses.def"

clang/lib/AST/ASTContext.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,12 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
13841384
#include "clang/Basic/OpenCLExtensionTypes.def"
13851385
}
13861386

1387+
if (LangOpts.HLSL) {
1388+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1389+
InitBuiltinType(SingletonId, BuiltinType::Id);
1390+
#include "clang/Basic/HLSLIntangibleTypes.def"
1391+
}
1392+
13871393
if (Target.hasAArch64SVETypes() ||
13881394
(AuxTarget && AuxTarget->hasAArch64SVETypes())) {
13891395
#define SVE_TYPE(Name, Id, SingletonId) \
@@ -2242,6 +2248,11 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
22422248
Align = ALIGN; \
22432249
break;
22442250
#include "clang/Basic/AMDGPUTypes.def"
2251+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2252+
#include "clang/Basic/HLSLIntangibleTypes.def"
2253+
Width = 0;
2254+
Align = 8;
2255+
break;
22452256
}
22462257
break;
22472258
case Type::ObjCObjectPointer:
@@ -3355,6 +3366,10 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
33553366
case BuiltinType::Id: \
33563367
return;
33573368
#include "clang/Basic/AArch64SVEACLETypes.def"
3369+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3370+
case BuiltinType::Id: \
3371+
return;
3372+
#include "clang/Basic/HLSLIntangibleTypes.def"
33583373
case BuiltinType::Dependent:
33593374
llvm_unreachable("should never get here");
33603375
case BuiltinType::AMDGPUBufferRsrc:
@@ -8552,6 +8567,8 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
85528567
#define PPC_VECTOR_TYPE(Name, Id, Size) \
85538568
case BuiltinType::Id:
85548569
#include "clang/Basic/PPCTypes.def"
8570+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
8571+
#include "clang/Basic/HLSLIntangibleTypes.def"
85558572
#define BUILTIN_TYPE(KIND, ID)
85568573
#define PLACEHOLDER_TYPE(KIND, ID) \
85578574
case BuiltinType::KIND:

clang/lib/AST/ASTImporter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,10 @@ ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
11511151
case BuiltinType::Id: \
11521152
return Importer.getToContext().SingletonId;
11531153
#include "clang/Basic/AMDGPUTypes.def"
1154+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1155+
case BuiltinType::Id: \
1156+
return Importer.getToContext().SingletonId;
1157+
#include "clang/Basic/HLSLIntangibleTypes.def"
11541158
#define SHARED_SINGLETON_TYPE(Expansion)
11551159
#define BUILTIN_TYPE(Id, SingletonId) \
11561160
case BuiltinType::Id: return Importer.getToContext().SingletonId;

clang/lib/AST/ExprConstant.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11879,6 +11879,8 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
1187911879
#include "clang/Basic/WebAssemblyReferenceTypes.def"
1188011880
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
1188111881
#include "clang/Basic/AMDGPUTypes.def"
11882+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
11883+
#include "clang/Basic/HLSLIntangibleTypes.def"
1188211884
return GCCTypeClass::None;
1188311885

1188411886
case BuiltinType::Dependent:

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,6 +3428,12 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
34283428
Out << 'u' << type_name.size() << type_name; \
34293429
break;
34303430
#include "clang/Basic/AMDGPUTypes.def"
3431+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3432+
case BuiltinType::Id: \
3433+
type_name = #Name; \
3434+
Out << 'u' << type_name.size() << type_name; \
3435+
break;
3436+
#include "clang/Basic/HLSLIntangibleTypes.def"
34313437
}
34323438
}
34333439

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,6 +2741,13 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
27412741
break;
27422742

27432743
#include "clang/Basic/WebAssemblyReferenceTypes.def"
2744+
2745+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2746+
case BuiltinType::Id: \
2747+
mangleArtificialTagType(TagTypeKind::Struct, #Name); \
2748+
break;
2749+
#include "clang/Basic/HLSLIntangibleTypes.def"
2750+
27442751
#define SVE_TYPE(Name, Id, SingletonId) \
27452752
case BuiltinType::Id:
27462753
#include "clang/Basic/AArch64SVEACLETypes.def"

clang/lib/AST/NSAPI.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
455455
#include "clang/Basic/WebAssemblyReferenceTypes.def"
456456
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
457457
#include "clang/Basic/AMDGPUTypes.def"
458+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
459+
#include "clang/Basic/HLSLIntangibleTypes.def"
458460
case BuiltinType::BoundMember:
459461
case BuiltinType::UnresolvedTemplate:
460462
case BuiltinType::Dependent:

clang/lib/AST/PrintfFormatString.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,8 @@ bool PrintfSpecifier::fixType(QualType QT, const LangOptions &LangOpt,
867867
#include "clang/Basic/WebAssemblyReferenceTypes.def"
868868
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
869869
#include "clang/Basic/AMDGPUTypes.def"
870+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
871+
#include "clang/Basic/HLSLIntangibleTypes.def"
870872
#define SIGNED_TYPE(Id, SingletonId)
871873
#define UNSIGNED_TYPE(Id, SingletonId)
872874
#define FLOATING_TYPE(Id, SingletonId)

clang/lib/AST/Type.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,6 +2447,9 @@ bool Type::isSizelessBuiltinType() const {
24472447
// WebAssembly reference types
24482448
#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
24492449
#include "clang/Basic/WebAssemblyReferenceTypes.def"
2450+
// HLSL intangible types
2451+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2452+
#include "clang/Basic/HLSLIntangibleTypes.def"
24502453
return true;
24512454
default:
24522455
return false;
@@ -3454,6 +3457,10 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
34543457
case Id: \
34553458
return Name;
34563459
#include "clang/Basic/AMDGPUTypes.def"
3460+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3461+
case Id: \
3462+
return #Name;
3463+
#include "clang/Basic/HLSLIntangibleTypes.def"
34573464
}
34583465

34593466
llvm_unreachable("Invalid builtin type.");
@@ -4786,6 +4793,8 @@ bool Type::canHaveNullability(bool ResultIfUnknown) const {
47864793
#include "clang/Basic/WebAssemblyReferenceTypes.def"
47874794
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
47884795
#include "clang/Basic/AMDGPUTypes.def"
4796+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
4797+
#include "clang/Basic/HLSLIntangibleTypes.def"
47894798
case BuiltinType::BuiltinFn:
47904799
case BuiltinType::NullPtr:
47914800
case BuiltinType::IncompleteMatrixIdx:

clang/lib/AST/TypeLoc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
430430
#include "clang/Basic/WebAssemblyReferenceTypes.def"
431431
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
432432
#include "clang/Basic/AMDGPUTypes.def"
433+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
434+
#include "clang/Basic/HLSLIntangibleTypes.def"
433435
case BuiltinType::BuiltinFn:
434436
case BuiltinType::IncompleteMatrixIdx:
435437
case BuiltinType::ArraySection:

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
744744
case BuiltinType::Id: \
745745
return getOrCreateStructPtrType("opencl_" #ExtType, Id##Ty);
746746
#include "clang/Basic/OpenCLExtensionTypes.def"
747+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
748+
case BuiltinType::Id: \
749+
return getOrCreateStructPtrType(#Name, SingletonId);
750+
#include "clang/Basic/HLSLIntangibleTypes.def"
747751

748752
#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
749753
#include "clang/Basic/AArch64SVEACLETypes.def"

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ class CGDebugInfo {
8787
#include "clang/Basic/WebAssemblyReferenceTypes.def"
8888
#define AMDGPU_TYPE(Name, Id, SingletonId) llvm::DIType *SingletonId = nullptr;
8989
#include "clang/Basic/AMDGPUTypes.def"
90+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
91+
llvm::DIType *SingletonId = nullptr;
92+
#include "clang/Basic/HLSLIntangibleTypes.def"
9093

9194
/// Cache of previously constructed Types.
9295
llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "CGHLSLRuntime.h"
1616
#include "CGDebugInfo.h"
1717
#include "CodeGenModule.h"
18+
#include "TargetInfo.h"
1819
#include "clang/AST/Decl.h"
1920
#include "clang/Basic/TargetOptions.h"
2021
#include "llvm/IR/Metadata.h"
@@ -115,6 +116,16 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
115116

116117
} // namespace
117118

119+
llvm::Type *CGHLSLRuntime::convertHLSLSpecificType(const Type *T) {
120+
assert(T->isHLSLSpecificType() && "Not an HLSL specific type!");
121+
122+
// Check if the target has a specific translation for this type first.
123+
if (llvm::Type *TargetTy = CGM.getTargetCodeGenInfo().getHLSLType(CGM, T))
124+
return TargetTy;
125+
126+
llvm_unreachable("Generic handling of HLSL types is not supported.");
127+
}
128+
118129
llvm::Triple::ArchType CGHLSLRuntime::getArch() {
119130
return CGM.getTarget().getTriple().getArch();
120131
}

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class CGHLSLRuntime {
113113
CGHLSLRuntime(CodeGenModule &CGM) : CGM(CGM) {}
114114
virtual ~CGHLSLRuntime() {}
115115

116+
llvm::Type *convertHLSLSpecificType(const Type *T);
117+
116118
void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV);
117119
void generateGlobalCtorDtorCalls();
118120

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "CodeGenTypes.h"
1414
#include "CGCXXABI.h"
1515
#include "CGCall.h"
16+
#include "CGHLSLRuntime.h"
1617
#include "CGOpenCLRuntime.h"
1718
#include "CGRecordLayout.h"
1819
#include "TargetInfo.h"
@@ -593,6 +594,10 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
593594
case BuiltinType::Id: \
594595
return llvm::PointerType::get(getLLVMContext(), AS);
595596
#include "clang/Basic/AMDGPUTypes.def"
597+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
598+
#include "clang/Basic/HLSLIntangibleTypes.def"
599+
ResultType = CGM.getHLSLRuntime().convertHLSLSpecificType(Ty);
600+
break;
596601
case BuiltinType::Dependent:
597602
#define BUILTIN_TYPE(Id, SingletonId)
598603
#define PLACEHOLDER_TYPE(Id, SingletonId) \

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,8 @@ static bool TypeInfoIsInStandardLibrary(const BuiltinType *Ty) {
36303630
#include "clang/Basic/WebAssemblyReferenceTypes.def"
36313631
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
36323632
#include "clang/Basic/AMDGPUTypes.def"
3633+
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
3634+
#include "clang/Basic/HLSLIntangibleTypes.def"
36333635
case BuiltinType::ShortAccum:
36343636
case BuiltinType::Accum:
36353637
case BuiltinType::LongAccum:

0 commit comments

Comments
 (0)