Skip to content

Commit 1b06131

Browse files
committed
[Clang][AMDGPU] Add a new builtin type for buffer rsrc
1 parent ea2ee5d commit 1b06131

29 files changed

+185
-2
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
11471147
#include "clang/Basic/RISCVVTypes.def"
11481148
#define WASM_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
11491149
#include "clang/Basic/WebAssemblyReferenceTypes.def"
1150+
#define AMDGPU_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
1151+
#include "clang/Basic/AMDGPUTypes.def"
11501152

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

clang/include/clang/AST/Type.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,6 +3015,9 @@ class BuiltinType : public Type {
30153015
// WebAssembly reference types
30163016
#define WASM_TYPE(Name, Id, SingletonId) Id,
30173017
#include "clang/Basic/WebAssemblyReferenceTypes.def"
3018+
// AMDGPU types
3019+
#define AMDGPU_TYPE(Name, Id, SingletonId) Id,
3020+
#include "clang/Basic/AMDGPUTypes.def"
30183021
// All other builtin types
30193022
#define BUILTIN_TYPE(Id, SingletonId) Id,
30203023
#define LAST_BUILTIN_TYPE(Id) LastKind = Id

clang/include/clang/AST/TypeProperties.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,10 @@ let Class = BuiltinType in {
861861
case BuiltinType::ID: return ctx.SINGLETON_ID;
862862
#include "clang/Basic/WebAssemblyReferenceTypes.def"
863863

864+
#define AMDGPU_TYPE(NAME, ID, SINGLETON_ID) \
865+
case BuiltinType::ID: return ctx.SINGLETON_ID;
866+
#include "clang/Basic/AMDGPUTypes.def"
867+
864868
#define BUILTIN_TYPE(ID, SINGLETON_ID) \
865869
case BuiltinType::ID: return ctx.SINGLETON_ID;
866870
#include "clang/AST/BuiltinTypes.def"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- AMDGPUTypes.def - Metadata about AMDGPU 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 various AMDGPU builtin types.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef AMDGPU_OPAQUE_TYPE
14+
#define AMDGPU_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
15+
AMDGPU_TYPE(Name, Id, SingletonId)
16+
#endif
17+
18+
AMDGPU_OPAQUE_TYPE("__buffer_rsrc_t", "__buffer_rsrc_t", AMDGPUBufferRsrc, AMDGPUBufferRsrcTy)
19+
20+
#undef AMDGPU_TYPE
21+
#undef AMDGPU_OPAQUE_TYPE

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,9 @@ enum PredefinedTypeIDs {
10911091
// \brief WebAssembly reference types with auto numeration
10921092
#define WASM_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
10931093
#include "clang/Basic/WebAssemblyReferenceTypes.def"
1094+
// \brief AMDGPU types with auto numeration
1095+
#define AMDGPU_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
1096+
#include "clang/Basic/AMDGPUTypes.def"
10941097

10951098
/// The placeholder type for unresolved templates.
10961099
PREDEF_TYPE_UNRESOLVED_TEMPLATE,
@@ -1103,7 +1106,7 @@ enum PredefinedTypeIDs {
11031106
///
11041107
/// Type IDs for non-predefined types will start at
11051108
/// NUM_PREDEF_TYPE_IDs.
1106-
const unsigned NUM_PREDEF_TYPE_IDS = 503;
1109+
const unsigned NUM_PREDEF_TYPE_IDS = 504;
11071110

11081111
// Ensure we do not overrun the predefined types we reserved
11091112
// in the enum PredefinedTypeIDs above.

clang/lib/AST/ASTContext.cpp

Lines changed: 11 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/WebAssemblyReferenceTypes.def"
13851385
}
13861386

1387+
if (Target.getTriple().isAMDGPU()) {
1388+
#define AMDGPU_TYPE(Name, Id, SingletonId) \
1389+
InitBuiltinType(SingletonId, BuiltinType::Id);
1390+
#include "clang/Basic/AMDGPUTypes.def"
1391+
}
1392+
13871393
// Builtin type for __objc_yes and __objc_no
13881394
ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ?
13891395
SignedCharTy : BoolTy);
@@ -2200,6 +2206,9 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
22002206
Align = 8; \
22012207
break;
22022208
#include "clang/Basic/WebAssemblyReferenceTypes.def"
2209+
case BuiltinType::AMDGPUBufferRsrc:
2210+
Width = 0;
2211+
Align = 128;
22032212
}
22042213
break;
22052214
case Type::ObjCObjectPointer:
@@ -8155,6 +8164,8 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
81558164
#include "clang/Basic/RISCVVTypes.def"
81568165
#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
81578166
#include "clang/Basic/WebAssemblyReferenceTypes.def"
8167+
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
8168+
#include "clang/Basic/AMDGPUTypes.def"
81588169
{
81598170
DiagnosticsEngine &Diags = C->getDiagnostics();
81608171
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,

clang/lib/AST/ASTImporter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,10 @@ ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
10991099
case BuiltinType::Id: \
11001100
return Importer.getToContext().SingletonId;
11011101
#include "clang/Basic/WebAssemblyReferenceTypes.def"
1102+
#define AMDGPU_TYPE(Name, Id, SingletonId) \
1103+
case BuiltinType::Id: \
1104+
return Importer.getToContext().SingletonId;
1105+
#include "clang/Basic/AMDGPUTypes.def"
11021106
#define SHARED_SINGLETON_TYPE(Expansion)
11031107
#define BUILTIN_TYPE(Id, SingletonId) \
11041108
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
@@ -11859,6 +11859,8 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
1185911859
#include "clang/Basic/RISCVVTypes.def"
1186011860
#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
1186111861
#include "clang/Basic/WebAssemblyReferenceTypes.def"
11862+
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
11863+
#include "clang/Basic/AMDGPUTypes.def"
1186211864
return GCCTypeClass::None;
1186311865

1186411866
case BuiltinType::Dependent:

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,6 +3423,12 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
34233423
Out << 'u' << type_name.size() << type_name; \
34243424
break;
34253425
#include "clang/Basic/WebAssemblyReferenceTypes.def"
3426+
#define AMDGPU_OPAQUE_TYPE(InternalName, MangledName, Id, SingletonId) \
3427+
case BuiltinType::Id: \
3428+
type_name = MangledName; \
3429+
Out << 'u' << type_name.size() << type_name; \
3430+
break;
3431+
#include "clang/Basic/AMDGPUTypes.def"
34263432
}
34273433
}
34283434

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,6 +2611,8 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
26112611
#include "clang/Basic/PPCTypes.def"
26122612
#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
26132613
#include "clang/Basic/RISCVVTypes.def"
2614+
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2615+
#include "clang/Basic/AMDGPUTypes.def"
26142616
case BuiltinType::ShortAccum:
26152617
case BuiltinType::Accum:
26162618
case BuiltinType::LongAccum:

0 commit comments

Comments
 (0)