Skip to content

Commit 22629a0

Browse files
authored
Linkage type fix for global variables translation (#1148)
This is a workaround to fix translation of linkage type of "llvm.used" and "llvm.compiler.used" global variables that should be "appending" instead of "export".
1 parent 36ee44b commit 22629a0

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4143,6 +4143,9 @@ bool SPIRVToLLVM::transSourceExtension() {
41434143

41444144
llvm::GlobalValue::LinkageTypes
41454145
SPIRVToLLVM::transLinkageType(const SPIRVValue *V) {
4146+
std::string ValueName = V->getName();
4147+
if (ValueName == "llvm.used" || ValueName == "llvm.compiler.used")
4148+
return GlobalValue::AppendingLinkage;
41464149
int LT = V->getLinkageType();
41474150
switch (LT) {
41484151
case internal::LinkageTypeInternal:

test/appending-linkage-type.ll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv -spirv-ext=+SPV_INTEL_vector_compute,+SPV_INTEL_usm_storage_classes
3+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
4+
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
5+
; RUN: FileCheck %s --input-file %t.rev.ll --check-prefix CHECK-LLVM
6+
7+
; ModuleID = 'appending-linkage-type'
8+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
9+
target triple = "spir64-unknown-unknown"
10+
11+
%union.int_double = type { i64 }
12+
13+
@_c0 = internal addrspace(1) constant %union.int_double { i64 4607182418800017408 }, align 8 #0
14+
@._c0.ref = internal constant %union.int_double addrspace(1)* @_c0 #0
15+
; CHECK-LLVM: @llvm.compiler.used = appending global
16+
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (%union.int_double addrspace(1)** @._c0.ref to i8*)] #0
17+
18+
attributes #0 = { "VCGlobalVariable" }
19+
20+
!spirv.MemoryModel = !{!0}
21+
!opencl.enable.FP_CONTRACT = !{}
22+
!spirv.Source = !{!1}
23+
!opencl.spir.version = !{!2}
24+
!opencl.ocl.version = !{!1}
25+
!opencl.used.extensions = !{!3}
26+
!opencl.used.optional.core.features = !{!3}
27+
!spirv.Generator = !{!4}
28+
29+
!0 = !{i32 2, i32 2}
30+
!1 = !{i32 0, i32 0}
31+
!2 = !{i32 1, i32 2}
32+
!3 = !{}
33+
!4 = !{i16 6, i16 14}

0 commit comments

Comments
 (0)