Skip to content

Commit 7b31bbb

Browse files
committed
[Clang][AMDGPU] Add a new builtin type for buffer rsrc
1 parent 29d857f commit 7b31bbb

29 files changed

+251
-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_PTR_TYPE
14+
#define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id, SingletonId) \
15+
AMDGPU_TYPE(Name, Id, SingletonId)
16+
#endif
17+
18+
AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", "__amdgpu_buffer_rsrc_t", 8, 128, 128, AMDGPUBufferRsrc, AMDGPUBufferRsrcTy)
19+
20+
#undef AMDGPU_TYPE
21+
#undef AMDGPU_OPAQUE_PTR_TYPE

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,9 @@ enum PredefinedTypeIDs {
10941094
// \brief WebAssembly reference types with auto numeration
10951095
#define WASM_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
10961096
#include "clang/Basic/WebAssemblyReferenceTypes.def"
1097+
// \brief AMDGPU types with auto numeration
1098+
#define AMDGPU_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
1099+
#include "clang/Basic/AMDGPUTypes.def"
10971100

10981101
/// The placeholder type for unresolved templates.
10991102
PREDEF_TYPE_UNRESOLVED_TEMPLATE,
@@ -1106,7 +1109,7 @@ enum PredefinedTypeIDs {
11061109
///
11071110
/// Type IDs for non-predefined types will start at
11081111
/// NUM_PREDEF_TYPE_IDs.
1109-
const unsigned NUM_PREDEF_TYPE_IDS = 503;
1112+
const unsigned NUM_PREDEF_TYPE_IDS = 504;
11101113

11111114
// Ensure we do not overrun the predefined types we reserved
11121115
// in the enum PredefinedTypeIDs above.

clang/lib/AST/ASTContext.cpp

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

1387+
if (Target.getTriple().isAMDGPU() ||
1388+
(AuxTarget && AuxTarget->getTriple().isAMDGPU())) {
1389+
#define AMDGPU_TYPE(Name, Id, SingletonId) \
1390+
InitBuiltinType(SingletonId, BuiltinType::Id);
1391+
#include "clang/Basic/AMDGPUTypes.def"
1392+
}
1393+
13871394
// Builtin type for __objc_yes and __objc_no
13881395
ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ?
13891396
SignedCharTy : BoolTy);
@@ -2200,6 +2207,13 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
22002207
Align = 8; \
22012208
break;
22022209
#include "clang/Basic/WebAssemblyReferenceTypes.def"
2210+
#define AMDGPU_OPAQUE_PTR_TYPE(NAME, MANGLEDNAME, AS, WIDTH, ALIGN, ID, \
2211+
SINGLETONID) \
2212+
case BuiltinType::ID: \
2213+
Width = WIDTH; \
2214+
Align = ALIGN; \
2215+
break;
2216+
#include "clang/Basic/AMDGPUTypes.def"
22032217
}
22042218
break;
22052219
case Type::ObjCObjectPointer:
@@ -8168,6 +8182,8 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
81688182
#include "clang/Basic/RISCVVTypes.def"
81698183
#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
81708184
#include "clang/Basic/WebAssemblyReferenceTypes.def"
8185+
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
8186+
#include "clang/Basic/AMDGPUTypes.def"
81718187
{
81728188
DiagnosticsEngine &Diags = C->getDiagnostics();
81738189
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
@@ -11807,6 +11807,8 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
1180711807
#include "clang/Basic/RISCVVTypes.def"
1180811808
#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
1180911809
#include "clang/Basic/WebAssemblyReferenceTypes.def"
11810+
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
11811+
#include "clang/Basic/AMDGPUTypes.def"
1181011812
return GCCTypeClass::None;
1181111813

1181211814
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_TYPE(Name, Id, SingletonId) \
3427+
case BuiltinType::Id: \
3428+
type_name = Name; \
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
@@ -2612,6 +2612,8 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
26122612
#include "clang/Basic/PPCTypes.def"
26132613
#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
26142614
#include "clang/Basic/RISCVVTypes.def"
2615+
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2616+
#include "clang/Basic/AMDGPUTypes.def"
26152617
case BuiltinType::ShortAccum:
26162618
case BuiltinType::Accum:
26172619
case BuiltinType::LongAccum:

0 commit comments

Comments
 (0)