-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[Clang] Make the AS of llvm.compiler.used & llvm.used elements addrspace(0) #164432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] Make the AS of llvm.compiler.used & llvm.used elements addrspace(0) #164432
Conversation
|
@llvm/pr-subscribers-clang-codegen Author: Juan Manuel Martinez Caamaño (jmmartinez) ChangesBy convention the AS of the elements of This leaves some LLVM helpers ( This patch makes the AS of the elements of these variables to be 0. This PR is related to #162660 Full diff: https://github.com/llvm/llvm-project/pull/164432.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 1085f45e0fc21..94e3c8bead385 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3281,18 +3281,18 @@ static void emitUsed(CodeGenModule &CGM, StringRef Name,
if (List.empty())
return;
+ llvm::PointerType *UnqualPtr =
+ llvm::PointerType::getUnqual(CGM.getLLVMContext());
+
// Convert List to what ConstantArray needs.
SmallVector<llvm::Constant*, 8> UsedArray;
UsedArray.resize(List.size());
for (unsigned i = 0, e = List.size(); i != e; ++i) {
- UsedArray[i] =
- llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
- cast<llvm::Constant>(&*List[i]), CGM.Int8PtrTy);
+ UsedArray[i] = llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
+ cast<llvm::Constant>(&*List[i]), UnqualPtr);
}
- if (UsedArray.empty())
- return;
- llvm::ArrayType *ATy = llvm::ArrayType::get(CGM.Int8PtrTy, UsedArray.size());
+ llvm::ArrayType *ATy = llvm::ArrayType::get(UnqualPtr, UsedArray.size());
auto *GV = new llvm::GlobalVariable(
CGM.getModule(), ATy, false, llvm::GlobalValue::AppendingLinkage,
diff --git a/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c b/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c
index df7118859c764..8af9708a1bfb8 100644
--- a/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c
+++ b/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c
@@ -3,6 +3,6 @@
// CHECK: @llvm.embedded.module = private addrspace(1) constant [0 x i8] zeroinitializer, section ".llvmbc", align 1
// CHECK-NEXT: @llvm.cmdline = private addrspace(1) constant [{{[0-9]+}} x i8] c"{{.*}}", section ".llvmcmd", align 1
-// CHECK-NEXT: @llvm.compiler.used = appending addrspace(1) global [5 x ptr addrspace(4)] [ptr addrspace(4) addrspacecast (ptr addrspace(1) @foo.managed to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @foo to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @__hip_cuid_ to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @llvm.embedded.module to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @llvm.cmdline to ptr addrspace(4))], section "llvm.metadata"
+// CHECK-NEXT: @llvm.compiler.used = appending addrspace(1) global [5 x ptr] [ptr addrspacecast (ptr addrspace(1) @foo.managed to ptr), ptr addrspacecast (ptr addrspace(1) @foo to ptr), ptr addrspacecast (ptr addrspace(1) @__hip_cuid_ to ptr), ptr addrspacecast (ptr addrspace(1) @llvm.embedded.module to ptr), ptr addrspacecast (ptr addrspace(1) @llvm.cmdline to ptr)], section "llvm.metadata"
__attribute__((managed)) int foo = 42;
|
|
@llvm/pr-subscribers-clang Author: Juan Manuel Martinez Caamaño (jmmartinez) ChangesBy convention the AS of the elements of This leaves some LLVM helpers ( This patch makes the AS of the elements of these variables to be 0. This PR is related to #162660 Full diff: https://github.com/llvm/llvm-project/pull/164432.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 1085f45e0fc21..94e3c8bead385 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3281,18 +3281,18 @@ static void emitUsed(CodeGenModule &CGM, StringRef Name,
if (List.empty())
return;
+ llvm::PointerType *UnqualPtr =
+ llvm::PointerType::getUnqual(CGM.getLLVMContext());
+
// Convert List to what ConstantArray needs.
SmallVector<llvm::Constant*, 8> UsedArray;
UsedArray.resize(List.size());
for (unsigned i = 0, e = List.size(); i != e; ++i) {
- UsedArray[i] =
- llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
- cast<llvm::Constant>(&*List[i]), CGM.Int8PtrTy);
+ UsedArray[i] = llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
+ cast<llvm::Constant>(&*List[i]), UnqualPtr);
}
- if (UsedArray.empty())
- return;
- llvm::ArrayType *ATy = llvm::ArrayType::get(CGM.Int8PtrTy, UsedArray.size());
+ llvm::ArrayType *ATy = llvm::ArrayType::get(UnqualPtr, UsedArray.size());
auto *GV = new llvm::GlobalVariable(
CGM.getModule(), ATy, false, llvm::GlobalValue::AppendingLinkage,
diff --git a/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c b/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c
index df7118859c764..8af9708a1bfb8 100644
--- a/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c
+++ b/clang/test/CodeGen/embed-bitcode-marker-with-nonzero-as.c
@@ -3,6 +3,6 @@
// CHECK: @llvm.embedded.module = private addrspace(1) constant [0 x i8] zeroinitializer, section ".llvmbc", align 1
// CHECK-NEXT: @llvm.cmdline = private addrspace(1) constant [{{[0-9]+}} x i8] c"{{.*}}", section ".llvmcmd", align 1
-// CHECK-NEXT: @llvm.compiler.used = appending addrspace(1) global [5 x ptr addrspace(4)] [ptr addrspace(4) addrspacecast (ptr addrspace(1) @foo.managed to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @foo to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @__hip_cuid_ to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @llvm.embedded.module to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @llvm.cmdline to ptr addrspace(4))], section "llvm.metadata"
+// CHECK-NEXT: @llvm.compiler.used = appending addrspace(1) global [5 x ptr] [ptr addrspacecast (ptr addrspace(1) @foo.managed to ptr), ptr addrspacecast (ptr addrspace(1) @foo to ptr), ptr addrspacecast (ptr addrspace(1) @__hip_cuid_ to ptr), ptr addrspacecast (ptr addrspace(1) @llvm.embedded.module to ptr), ptr addrspacecast (ptr addrspace(1) @llvm.cmdline to ptr)], section "llvm.metadata"
__attribute__((managed)) int foo = 42;
|
efriedma-quic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a testcase that doesn't involve -fembed-bitcode?
Otherwise LGTM
889c8a1 to
184b601
Compare
Thanks! I've added a test with a function and a global using |
|
@efriedma-quic is the test I've added ok ? |
|
If there are no concerns about this patch, I'd like to land it. |
|
If there are no complains I'll land this patch next week. |
c6bf96d to
9b82500
Compare
…ace(0) (llvm#164432) By convention the AS of the elements of `llvm.compiler.used` & `llvm.used` is 0. However, the AS of `CGM.Int8PtrTy` is not always 0. This leaves some LLVM helpers (`appendToUsed/appendToCompilerUsed/removeFromUsedLists`) unusable. This patch makes the AS of the elements of these variables to be 0. This PR is related to llvm#162660
…s addrspace(0) (llvm#164432)" This reverts commit bf2f577.
…s addrspace(0)" (#166242) Reverts #164432 Breaks Comgr tests with the following: [2025-11-03T19:18:20.564Z] + clang -x hip --offload-arch=amdgcnspirv -nogpulib -nogpuinc --no-gpu-bundle-output --offload-device-only -O3 /jenkins/workspace/compiler-psdb-amd-staging/repos/llvm-project/amd/comgr/test-lit/spirv-tests/spirv-to-reloc.hip -o /jenkins/workspace/compiler-psdb-amd-staging/repos/out/ubuntu-22.04/22.04/build/amd_comgr/test-lit/spirv-tests/Output/spirv-to-reloc.hip.tmp.spv -fvisibility=hidden -fno-autolink -fexceptions -fcolor-diagnostics [2025-11-03T19:18:20.564Z] InvalidModule: Invalid SPIR-V module: Casts from private/local/global address space are allowed only to generic [2025-11-03T19:18:20.564Z] [2025-11-03T19:18:20.564Z] <badref> = addrspacecast ptr addrspace(1) @__hip_cuid_94fb83be5559070 to ptr [2025-11-03T19:18:20.564Z] clang: error: amdgcn-link command failed with exit code 10 (use -v to see invocation)
…sed elements addrspace(0)" (#166242) Reverts llvm/llvm-project#164432 Breaks Comgr tests with the following: [2025-11-03T19:18:20.564Z] + clang -x hip --offload-arch=amdgcnspirv -nogpulib -nogpuinc --no-gpu-bundle-output --offload-device-only -O3 /jenkins/workspace/compiler-psdb-amd-staging/repos/llvm-project/amd/comgr/test-lit/spirv-tests/spirv-to-reloc.hip -o /jenkins/workspace/compiler-psdb-amd-staging/repos/out/ubuntu-22.04/22.04/build/amd_comgr/test-lit/spirv-tests/Output/spirv-to-reloc.hip.tmp.spv -fvisibility=hidden -fno-autolink -fexceptions -fcolor-diagnostics [2025-11-03T19:18:20.564Z] InvalidModule: Invalid SPIR-V module: Casts from private/local/global address space are allowed only to generic [2025-11-03T19:18:20.564Z] [2025-11-03T19:18:20.564Z] <badref> = addrspacecast ptr addrspace(1) @__hip_cuid_94fb83be5559070 to ptr [2025-11-03T19:18:20.564Z] clang: error: amdgcn-link command failed with exit code 10 (use -v to see invocation)
By convention the AS of the elements of
llvm.compiler.used&llvm.usedis 0. However, the AS ofCGM.Int8PtrTyis not always 0.This leaves some LLVM helpers (
appendToUsed/appendToCompilerUsed/removeFromUsedLists) unusable.This patch makes the AS of the elements of these variables to be 0.
This PR is related to #162660