Skip to content

Commit b468736

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

28 files changed

+168
-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
@@ -1385,6 +1385,12 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
13851385
#include "clang/Basic/WebAssemblyReferenceTypes.def"
13861386
}
13871387

1388+
if (Target.getTriple().isAMDGPU()) {
1389+
#define AMDGPU_TYPE(Name, Id, SingletonId) \
1390+
InitBuiltinType(SingletonId, BuiltinType::Id);
1391+
#include "clang/Basic/AMDGPUTypes.def"
1392+
}
1393+
13881394
// Builtin type for __objc_yes and __objc_no
13891395
ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ?
13901396
SignedCharTy : BoolTy);
@@ -2201,6 +2207,9 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
22012207
Align = 8; \
22022208
break;
22032209
#include "clang/Basic/WebAssemblyReferenceTypes.def"
2210+
case BuiltinType::AMDGPUBufferRsrc:
2211+
Width = 0;
2212+
Align = 256;
22042213
}
22052214
break;
22062215
case Type::ObjCObjectPointer:
@@ -8156,6 +8165,8 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
81568165
#include "clang/Basic/RISCVVTypes.def"
81578166
#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
81588167
#include "clang/Basic/WebAssemblyReferenceTypes.def"
8168+
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
8169+
#include "clang/Basic/AMDGPUTypes.def"
81598170
{
81608171
DiagnosticsEngine &Diags = C->getDiagnostics();
81618172
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_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
@@ -2609,6 +2609,8 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
26092609
#include "clang/Basic/PPCTypes.def"
26102610
#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
26112611
#include "clang/Basic/RISCVVTypes.def"
2612+
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2613+
#include "clang/Basic/AMDGPUTypes.def"
26122614
case BuiltinType::ShortAccum:
26132615
case BuiltinType::Accum:
26142616
case BuiltinType::LongAccum:

0 commit comments

Comments
 (0)