Skip to content

Commit 2da2208

Browse files
committed
[AMDGPU] Add a new builtin type for image descriptor rsrc
1 parent cae73be commit 2da2208

File tree

11 files changed

+97
-0
lines changed

11 files changed

+97
-0
lines changed

clang/include/clang/Basic/AMDGPUTypes.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@
2020
AMDGPU_TYPE(Name, Id, SingletonId, Width, Align)
2121
#endif
2222

23+
#ifndef AMDGPU_IMAGE_RSRC_TYPE
24+
#define AMDGPU_IMAGE_RSRC_TYPE(Name, Id, SingletonId) \
25+
AMDGPU_TYPE(Name, Id, SingletonId, 256, 256)
26+
#endif
27+
2328
AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", AMDGPUBufferRsrc, AMDGPUBufferRsrcTy, 128, 128, 8)
29+
AMDGPU_IMAGE_RSRC_TYPE("__amdgpu_image_rsrc_t", AMDGPUImageDescRsrc, AMDGPUImageDescRsrcTy)
2430

2531
AMDGPU_NAMED_BARRIER_TYPE("__amdgpu_named_workgroup_barrier_t", AMDGPUNamedWorkgroupBarrier, AMDGPUNamedWorkgroupBarrierTy, 128, 32, 0)
2632

2733
#undef AMDGPU_TYPE
2834
#undef AMDGPU_OPAQUE_PTR_TYPE
2935
#undef AMDGPU_NAMED_BARRIER_TYPE
36+
#undef AMDGPU_IMAGE_RSRC_TYPE

clang/include/clang/Basic/Builtins.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
// Q -> target builtin type, followed by a character to distinguish the builtin type
3535
// Qa -> AArch64 svcount_t builtin type.
3636
// Qb -> AMDGPU __amdgpu_buffer_rsrc_t builtin type.
37+
// Qc -> AMDGPU __amdgpu_image_desc_t builtin type.
3738
// E -> ext_vector, followed by the number of elements and the base type.
3839
// X -> _Complex, followed by the base type.
3940
// Y -> ptrdiff_t

clang/lib/AST/ASTContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12580,6 +12580,10 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context,
1258012580
Type = Context.AMDGPUBufferRsrcTy;
1258112581
break;
1258212582
}
12583+
case 'c': {
12584+
Type = Context.AMDGPUImageDescRsrcTy;
12585+
break;
12586+
}
1258312587
default:
1258412588
llvm_unreachable("Unexpected target builtin type");
1258512589
}

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,14 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
10201020
DBuilder.createBasicType(Name, Width, llvm::dwarf::DW_ATE_unsigned); \
10211021
return SingletonId; \
10221022
}
1023+
#define AMDGPU_IMAGE_RSRC_TYPE(Name, Id, SingletonId) \
1024+
case BuiltinType::Id: { \
1025+
if (!SingletonId) \
1026+
SingletonId = \
1027+
DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name, \
1028+
TheCU, TheCU->getFile(), 0); \
1029+
return SingletonId; \
1030+
}
10231031
#include "clang/Basic/AMDGPUTypes.def"
10241032
case BuiltinType::UChar:
10251033
case BuiltinType::Char_U:

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,10 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
581581
case BuiltinType::Id: \
582582
return llvm::TargetExtType::get(getLLVMContext(), "amdgcn.named.barrier", \
583583
{}, {Scope});
584+
#define AMDGPU_IMAGE_RSRC_TYPE(Name, Id, SingletonId) \
585+
case BuiltinType::Id: \
586+
return llvm::VectorType::get(llvm::Type::getInt32Ty(getLLVMContext()), 8, \
587+
false);
584588
#include "clang/Basic/AMDGPUTypes.def"
585589
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
586590
#include "clang/Basic/HLSLIntangibleTypes.def"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
// REQUIRES: amdgpu-registered-target
3+
// RUN: %clang_cc1 -triple amdgcn -emit-llvm -o - %s -debug-info-kind=limited | FileCheck %s
4+
5+
// CHECK-LABEL: define dso_local void @test_locals(
6+
// CHECK-SAME: ) #[[ATTR0:[0-9]+]] !dbg [[DBG6:![0-9]+]] {
7+
// CHECK-NEXT: [[ENTRY:.*:]]
8+
// CHECK-NEXT: [[IMG:%.*]] = alloca <8 x i32>, align 32, addrspace(5)
9+
// CHECK-NEXT: [[IMG_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[IMG]] to ptr
10+
// CHECK-NEXT: #dbg_declare(ptr addrspace(5) [[IMG]], [[META11:![0-9]+]], !DIExpression(DW_OP_constu, 1, DW_OP_swap, DW_OP_xderef), [[META14:![0-9]+]])
11+
// CHECK-NEXT: [[TMP0:%.*]] = load <8 x i32>, ptr [[IMG_ASCAST]], align 32, !dbg [[DBG15:![0-9]+]]
12+
// CHECK-NEXT: ret void, !dbg [[DBG16:![0-9]+]]
13+
//
14+
void test_locals(void) {
15+
__amdgpu_image_rsrc_t img;
16+
(void)img;
17+
}
18+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
// REQUIRES: amdgpu-registered-target
3+
// RUN: %clang_cc1 -triple amdgcn %s -emit-llvm -o - | FileCheck %s
4+
namespace std { class type_info; }
5+
auto &a = typeid(__amdgpu_image_rsrc_t);
6+
//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
7+
// CHECK: {{.*}}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
// REQUIRES: amdgpu-registered-target
3+
// RUN: %clang_cc1 -fsyntax-only -verify -std=gnu++11 -triple amdgcn -Wno-unused-value %s
4+
5+
void foo() {
6+
int n = 1;
7+
__amdgpu_image_rsrc_t v = 0; // expected-error {{cannot initialize a variable of type '__amdgpu_image_rsrc_t' with an rvalue of type 'int'}}
8+
static_cast<__amdgpu_image_rsrc_t>(n); // expected-error {{static_cast from 'int' to '__amdgpu_image_rsrc_t' is not allowed}}
9+
reinterpret_cast<__amdgpu_image_rsrc_t>(n); // expected-error {{reinterpret_cast from 'int' to '__amdgpu_image_rsrc_t' is not allowed}}
10+
(void)(v + v); // expected-error {{invalid operands}}
11+
int x(v); // expected-error {{cannot initialize a variable of type 'int' with an lvalue of type '__amdgpu_image_rsrc_t'}}
12+
__amdgpu_image_rsrc_t k;
13+
}
14+
15+
static_assert(sizeof(__amdgpu_image_rsrc_t) == 32, "size");
16+
static_assert(alignof(__amdgpu_image_rsrc_t) == 32, "align");
17+
18+
template<class T> void bar(T);
19+
void use(__amdgpu_image_rsrc_t r) { bar(r); }
20+
struct S { __amdgpu_image_rsrc_t r; int a; };
21+
static_assert(sizeof(S) == 64, "struct layout");
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
// REQUIRES: amdgpu-registered-target
3+
// RUN: %clang_cc1 -verify -cl-std=CL1.2 -triple amdgcn-amd-amdhsa %s
4+
// RUN: %clang_cc1 -verify -cl-std=CL2.0 -triple amdgcn-amd-amdhsa %s
5+
6+
void f() {
7+
int n = 3;
8+
__amdgpu_image_rsrc_t v = 0; // expected-error {{initializing '__private __amdgpu_image_rsrc_t' with an expression of incompatible type 'int'}}
9+
int k = v; // expected-error {{initializing '__private int' with an expression of incompatible type '__private __amdgpu_image_rsrc_t'}}
10+
(void)(v + v); // expected-error {{invalid operands}}
11+
__amdgpu_image_rsrc_t r;
12+
int *p = (int*)r; // expected-error {{operand of type '__amdgpu_image_rsrc_t' where arithmetic or pointer type is required}}
13+
(void)p;
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
// REQUIRES: amdgpu-registered-target
3+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -triple amdgcn-amd-amdhsa -fopenmp-is-target-device -Wno-unused-value %s
4+
5+
void foo() {
6+
#pragma omp target
7+
{
8+
int n = 5;
9+
__amdgpu_image_rsrc_t v = 0; // expected-error {{cannot initialize a variable of type '__amdgpu_image_rsrc_t' with an rvalue of type 'int'}}
10+
(void)(v + v); // expected-error {{invalid operands to binary expression ('__amdgpu_image_rsrc_t' and '__amdgpu_image_rsrc_t'}}
11+
}
12+
}

0 commit comments

Comments
 (0)