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"

0 commit comments

Comments
 (0)