https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/66205:
>From 97642f663099cfb42792cd2415387170a146d9e2 Mon Sep 17 00:00:00 2001 From: Joseph Huber <jhub...@vols.utk.edu> Date: Wed, 13 Sep 2023 07:57:47 -0500 Subject: [PATCH] [Clang][AMDGPU] Permit language address spaces for AMDGPU globals Summary: Currently, there is an assertion that prevents us from emitting an AMDGPU global with a non-target specific address space (i.e. numerical attribute). I'm unsure what the original intentions of this assertion were, but we should be able to use OpenCL address spaces when compiling directly to AMDGPU from C++. This is permitted on NVPTX so I'm unsure what this assertion is guarding. The patch simply removes the assertion and adds a test to ensure that these emit the expected address spaces. Fixes https://github.com/llvm/llvm-project/issues/65069 --- clang/lib/CodeGen/Targets/AMDGPU.cpp | 1 - clang/test/CodeGen/amdgpu-address-spaces.cpp | 52 ++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGen/amdgpu-address-spaces.cpp diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp b/clang/lib/CodeGen/Targets/AMDGPU.cpp index c168bd4b7c7cc15..5aca4e540752524 100644 --- a/clang/lib/CodeGen/Targets/AMDGPU.cpp +++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp @@ -438,7 +438,6 @@ AMDGPUTargetCodeGenInfo::getGlobalVarAddressSpace(CodeGenModule &CGM, return DefaultGlobalAS; LangAS AddrSpace = D->getType().getAddressSpace(); - assert(AddrSpace == LangAS::Default || isTargetAddressSpace(AddrSpace)); if (AddrSpace != LangAS::Default) return AddrSpace; diff --git a/clang/test/CodeGen/amdgpu-address-spaces.cpp b/clang/test/CodeGen/amdgpu-address-spaces.cpp new file mode 100644 index 000000000000000..d97c5ca9495025a --- /dev/null +++ b/clang/test/CodeGen/amdgpu-address-spaces.cpp @@ -0,0 +1,52 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals --version 3 +// RUN: %clang_cc1 -cc1 -triple amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s + +int [[clang::opencl_global]] a = 1; +int [[clang::opencl_generic]] b = 2; +int [[clang::opencl_constant]] c = 3; +[[clang::loader_uninitialized]] int [[clang::opencl_local]] d; +[[clang::loader_uninitialized]] int [[clang::opencl_private]] e; + +int [[clang::address_space(1)]] x = 1; +int [[clang::address_space(0)]] y = 2; +int [[clang::address_space(4)]] z = 3; +[[clang::loader_uninitialized]] int [[clang::address_space(3)]] w; +[[clang::loader_uninitialized]] int [[clang::address_space(5)]] u; + +//. +// CHECK: @a = addrspace(1) global i32 1, align 4 +// CHECK: @b = global i32 2, align 4 +// CHECK: @c = addrspace(4) constant i32 3, align 4 +// CHECK: @d = addrspace(3) global i32 undef, align 4 +// CHECK: @e = addrspace(5) global i32 undef, align 4 +// CHECK: @x = addrspace(1) global i32 1, align 4 +// CHECK: @y = global i32 2, align 4 +// CHECK: @z = addrspace(4) global i32 3, align 4 +// CHECK: @w = addrspace(3) global i32 undef, align 4 +// CHECK: @u = addrspace(5) global i32 undef, align 4 +// CHECK: @llvm.amdgcn.abi.version = weak_odr hidden local_unnamed_addr addrspace(4) constant i32 400 +//. +// CHECK-LABEL: define dso_local amdgpu_kernel void @foo( +// CHECK-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT: store i32 1, ptr addrspace(1) @a, align 4 +// CHECK-NEXT: store i32 1, ptr @b, align 4 +// CHECK-NEXT: store i32 1, ptr addrspace(3) @d, align 4 +// CHECK-NEXT: store i32 1, ptr addrspace(5) @e, align 4 +// CHECK-NEXT: store i32 1, ptr addrspace(1) @x, align 4 +// CHECK-NEXT: store i32 1, ptr @y, align 4 +// CHECK-NEXT: store i32 1, ptr addrspace(3) @d, align 4 +// CHECK-NEXT: store i32 1, ptr addrspace(5) @u, align 4 +// CHECK-NEXT: ret void +// +extern "C" [[clang::amdgpu_kernel]] void foo() { + a = 1; + b = 1; + d = 1; + e = 1; + + x = 1; + y = 1; + d = 1; + u = 1; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits