Skip to content

Commit 3ae6343

Browse files
[SPIR-V] Set non-kernel function linkage type via OpDecorate for all linkage types except for static functions (#91598)
This PR fixes the issue #91595 by setting non-kernel function linkage type via OpDecorate for all linkage types except for static functions. A new test case is added.
1 parent 2df06e4 commit 3ae6343

File tree

6 files changed

+18
-2
lines changed

6 files changed

+18
-2
lines changed

llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ bool SPIRVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
430430
.addImm(static_cast<uint32_t>(executionModel))
431431
.addUse(FuncVReg);
432432
addStringImm(F.getName(), MIB);
433-
} else if (F.getLinkage() == GlobalValue::LinkageTypes::ExternalLinkage ||
434-
F.getLinkage() == GlobalValue::LinkOnceODRLinkage) {
433+
} else if (F.getLinkage() != GlobalValue::InternalLinkage &&
434+
F.getLinkage() != GlobalValue::PrivateLinkage) {
435435
SPIRV::LinkageType::LinkageType LnkTy =
436436
F.isDeclaration()
437437
? SPIRV::LinkageType::Import
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK-SPIRV: Capability Linkage
5+
; CHECK-SPIRV-DAG: OpName %[[#AbsFun:]] "abs"
6+
; CHECK-SPIRV-DAG: OpName %[[#ExternalFun:]] "__devicelib_abs"
7+
; CHECK-SPIRV-DAG: OpDecorate %[[#AbsFun]] LinkageAttributes "abs" Export
8+
; CHECK-SPIRV-DAG: OpDecorate %[[#ExternalFun]] LinkageAttributes "__devicelib_abs" Import
9+
10+
define weak dso_local spir_func i32 @abs(i32 noundef %x) {
11+
entry:
12+
%call = tail call spir_func i32 @__devicelib_abs(i32 noundef %x) #11
13+
ret i32 %call
14+
}
15+
16+
declare extern_weak dso_local spir_func i32 @__devicelib_abs(i32 noundef)

0 commit comments

Comments
 (0)