Skip to content

Commit 53a6a11

Browse files
authored
[LLVM][NFC] Use used's element type if available (#116804)
When embedding, if `compiler.used` exists, we should re-use it's element type instead of blindly assuming it's an unqualified pointer.
1 parent f5002a0 commit 53a6a11

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cc1 -triple spirv64-amd-amdhsa -emit-llvm -fcuda-is-device -fembed-bitcode=marker -x hip %s -o - \
2+
// RUN: | FileCheck %s --check-prefix=CHECK
3+
4+
// CHECK: @llvm.embedded.module = private addrspace(1) constant [0 x i8] zeroinitializer, section ".llvmbc", align 1
5+
// CHECK-NEXT: @llvm.cmdline = private addrspace(1) constant [{{[0-9]+}} x i8] c"{{.*}}", section ".llvmcmd", align 1
6+
// 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"
7+
8+
__attribute__((managed)) int foo = 42;

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5501,8 +5501,9 @@ void llvm::embedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf,
55015501
// Save llvm.compiler.used and remove it.
55025502
SmallVector<Constant *, 2> UsedArray;
55035503
SmallVector<GlobalValue *, 4> UsedGlobals;
5504-
Type *UsedElementType = PointerType::getUnqual(M.getContext());
55055504
GlobalVariable *Used = collectUsedGlobalVariables(M, UsedGlobals, true);
5505+
Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5506+
: PointerType::getUnqual(M.getContext());
55065507
for (auto *GV : UsedGlobals) {
55075508
if (GV->getName() != "llvm.embedded.module" &&
55085509
GV->getName() != "llvm.cmdline")

0 commit comments

Comments
 (0)