Skip to content

Commit ad59921

Browse files
authored
[Clang][AMDGPU] Add a new builtin type for buffer rsrc (llvm#94830)
This patch adds a new builtin type for AMDGPU's buffer rsrc data type, which is effectively an AS 8 pointer. This is needed because we'd like to expose certain intrinsics to users via builtins which take buffer rsrc as argument.
1 parent 70f41a8 commit ad59921

32 files changed

+299
-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
@@ -1097,6 +1097,9 @@ enum PredefinedTypeIDs {
10971097
// \brief WebAssembly reference types with auto numeration
10981098
#define WASM_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
10991099
#include "clang/Basic/WebAssemblyReferenceTypes.def"
1100+
// \brief AMDGPU types with auto numeration
1101+
#define AMDGPU_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
1102+
#include "clang/Basic/AMDGPUTypes.def"
11001103

11011104
/// The placeholder type for unresolved templates.
11021105
PREDEF_TYPE_UNRESOLVED_TEMPLATE,
@@ -1109,7 +1112,7 @@ enum PredefinedTypeIDs {
11091112
///
11101113
/// Type IDs for non-predefined types will start at
11111114
/// NUM_PREDEF_TYPE_IDs.
1112-
const unsigned NUM_PREDEF_TYPE_IDS = 503;
1115+
const unsigned NUM_PREDEF_TYPE_IDS = 504;
11131116

11141117
// Ensure we do not overrun the predefined types we reserved
11151118
// in the enum PredefinedTypeIDs above.

clang/lib/AST/ASTContext.cpp

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

1388+
if (Target.getTriple().isAMDGPU() ||
1389+
(AuxTarget && AuxTarget->getTriple().isAMDGPU())) {
1390+
#define AMDGPU_TYPE(Name, Id, SingletonId) \
1391+
InitBuiltinType(SingletonId, BuiltinType::Id);
1392+
#include "clang/Basic/AMDGPUTypes.def"
1393+
}
1394+
13881395
// Builtin type for __objc_yes and __objc_no
13891396
ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ?
13901397
SignedCharTy : BoolTy);
@@ -2201,6 +2208,13 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
22012208
Align = 8; \
22022209
break;
22032210
#include "clang/Basic/WebAssemblyReferenceTypes.def"
2211+
#define AMDGPU_OPAQUE_PTR_TYPE(NAME, MANGLEDNAME, AS, WIDTH, ALIGN, ID, \
2212+
SINGLETONID) \
2213+
case BuiltinType::ID: \
2214+
Width = WIDTH; \
2215+
Align = ALIGN; \
2216+
break;
2217+
#include "clang/Basic/AMDGPUTypes.def"
22042218
}
22052219
break;
22062220
case Type::ObjCObjectPointer:
@@ -8169,6 +8183,8 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
81698183
#include "clang/Basic/RISCVVTypes.def"
81708184
#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
81718185
#include "clang/Basic/WebAssemblyReferenceTypes.def"
8186+
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
8187+
#include "clang/Basic/AMDGPUTypes.def"
81728188
{
81738189
DiagnosticsEngine &Diags = C->getDiagnostics();
81748190
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
@@ -11814,6 +11814,8 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
1181411814
#include "clang/Basic/RISCVVTypes.def"
1181511815
#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
1181611816
#include "clang/Basic/WebAssemblyReferenceTypes.def"
11817+
#define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
11818+
#include "clang/Basic/AMDGPUTypes.def"
1181711819
return GCCTypeClass::None;
1181811820

1181911821
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)