Skip to content

Commit 3e7e8fb

Browse files
ranapratap55github-actions[bot]
authored andcommitted
Automerge: [AMDGPU] Add a new builtin type for image descriptor rsrc (#160258)
Adding a new builtin type for AMDGPU's image descriptor rsrc data type This requires for llvm/llvm-project#140210
2 parents 89579e7 + 27fa1d0 commit 3e7e8fb

File tree

8 files changed

+72
-0
lines changed

8 files changed

+72
-0
lines changed

clang/include/clang/Basic/AMDGPUTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#endif
2222

2323
AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", AMDGPUBufferRsrc, AMDGPUBufferRsrcTy, 128, 128, 8)
24+
AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_texture_t", AMDGPUTexture, AMDGPUTextureTy, 256, 256, 0)
2425

2526
AMDGPU_NAMED_BARRIER_TYPE("__amdgpu_named_workgroup_barrier_t", AMDGPUNamedWorkgroupBarrier, AMDGPUNamedWorkgroupBarrierTy, 128, 32, 0)
2627

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+
// Qt -> AMDGPU __amdgpu_texture_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
@@ -12590,6 +12590,10 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context,
1259012590
Type = Context.AMDGPUBufferRsrcTy;
1259112591
break;
1259212592
}
12593+
case 't': {
12594+
Type = Context.AMDGPUTextureTy;
12595+
break;
12596+
}
1259312597
default:
1259412598
llvm_unreachable("Unexpected target builtin type");
1259512599
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 ptr, 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 ptr, 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_texture_t img;
16+
(void)img;
17+
}
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_texture_t);
6+
//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
7+
// CHECK: {{.*}}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 = 100;
7+
__amdgpu_texture_t v = 0; // expected-error {{cannot initialize a variable of type '__amdgpu_texture_t' with an rvalue of type 'int'}}
8+
static_cast<__amdgpu_texture_t>(n); // expected-error {{static_cast from 'int' to '__amdgpu_texture_t' is not allowed}}
9+
reinterpret_cast<__amdgpu_texture_t>(n); // expected-error {{reinterpret_cast from 'int' to '__amdgpu_texture_t' is not allowed}}
10+
(void)(v + v); // expected-error {{invalid operands to binary expression ('__amdgpu_texture_t' and '__amdgpu_texture_t')}}
11+
int x(v); // expected-error {{cannot initialize a variable of type 'int' with an lvalue of type '__amdgpu_texture_t'}}
12+
__amdgpu_texture_t k;
13+
}
14+
15+
template<class T> void bar(T);
16+
void use(__amdgpu_texture_t r) { bar(r); }
17+
struct S { __amdgpu_texture_t r; int a; };
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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_texture_t v = (__amdgpu_texture_t)0; // expected-error {{used type '__amdgpu_texture_t' where arithmetic or pointer type is required}}
9+
int k = v; // expected-error {{initializing '__private int' with an expression of incompatible type '__private __amdgpu_texture_t'}}
10+
(void)(v + v); // expected-error {{invalid operands}}
11+
__amdgpu_texture_t r;
12+
int *p = (int*)r; // expected-error {{operand of type '__amdgpu_texture_t' where arithmetic or pointer type is required}}
13+
}
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_texture_t v = 0; // expected-error {{cannot initialize a variable of type '__amdgpu_texture_t' with an rvalue of type 'int'}}
10+
(void)(v + v); // expected-error {{invalid operands to binary expression}}
11+
}
12+
}

0 commit comments

Comments
 (0)