[llvm] [SPIR-V] Set non-kernel function linkage type via OpDecorate for all linkage types except for static functions (PR #91598)
Vyacheslav Levytskyy via llvm-commits
llvm-commits at lists.llvm.org
Thu May 9 07:09:38 PDT 2024
https://github.com/VyacheslavLevytskyy created https://github.com/llvm/llvm-project/pull/91598
This PR fixes the issue https://github.com/llvm/llvm-project/issues/91595 by setting non-kernel function linkage type via OpDecorate for all linkage types except for static functions. A new test case is added.
>From c130598942b4e40e56725ecd8c2faa468ca12ce4 Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Thu, 9 May 2024 07:07:30 -0700
Subject: [PATCH] Set non-kernel function linkage type via OpDecorate for all
linkage types except for static functions
---
llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp | 4 ++--
.../CodeGen/SPIRV/{ => linkage}/LinkOnceODR.ll | 0
.../SPIRV/{ => linkage}/LinkOnceODRFun.ll | 0
.../CodeGen/SPIRV/linkage/extern-weak-linkage.ll | 16 ++++++++++++++++
.../SPIRV/{ => linkage}/link-attribute.ll | 0
.../CodeGen/SPIRV/{ => linkage}/linkage-types.ll | 0
6 files changed, 18 insertions(+), 2 deletions(-)
rename llvm/test/CodeGen/SPIRV/{ => linkage}/LinkOnceODR.ll (100%)
rename llvm/test/CodeGen/SPIRV/{ => linkage}/LinkOnceODRFun.ll (100%)
create mode 100644 llvm/test/CodeGen/SPIRV/linkage/extern-weak-linkage.ll
rename llvm/test/CodeGen/SPIRV/{ => linkage}/link-attribute.ll (100%)
rename llvm/test/CodeGen/SPIRV/{ => linkage}/linkage-types.ll (100%)
diff --git a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
index c107b99cf4cb6..727e4e584c053 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
@@ -430,8 +430,8 @@ bool SPIRVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
.addImm(static_cast<uint32_t>(executionModel))
.addUse(FuncVReg);
addStringImm(F.getName(), MIB);
- } else if (F.getLinkage() == GlobalValue::LinkageTypes::ExternalLinkage ||
- F.getLinkage() == GlobalValue::LinkOnceODRLinkage) {
+ } else if (F.getLinkage() != GlobalValue::InternalLinkage &&
+ F.getLinkage() != GlobalValue::PrivateLinkage) {
SPIRV::LinkageType::LinkageType LnkTy =
F.isDeclaration()
? SPIRV::LinkageType::Import
diff --git a/llvm/test/CodeGen/SPIRV/LinkOnceODR.ll b/llvm/test/CodeGen/SPIRV/linkage/LinkOnceODR.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/LinkOnceODR.ll
rename to llvm/test/CodeGen/SPIRV/linkage/LinkOnceODR.ll
diff --git a/llvm/test/CodeGen/SPIRV/LinkOnceODRFun.ll b/llvm/test/CodeGen/SPIRV/linkage/LinkOnceODRFun.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/LinkOnceODRFun.ll
rename to llvm/test/CodeGen/SPIRV/linkage/LinkOnceODRFun.ll
diff --git a/llvm/test/CodeGen/SPIRV/linkage/extern-weak-linkage.ll b/llvm/test/CodeGen/SPIRV/linkage/extern-weak-linkage.ll
new file mode 100644
index 0000000000000..e742de4bc1e21
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/linkage/extern-weak-linkage.ll
@@ -0,0 +1,16 @@
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK-SPIRV: Capability Linkage
+; CHECK-SPIRV-DAG: OpName %[[#AbsFun:]] "abs"
+; CHECK-SPIRV-DAG: OpName %[[#ExternalFun:]] "__devicelib_abs"
+; CHECK-SPIRV-DAG: OpDecorate %[[#AbsFun]] LinkageAttributes "abs" Export
+; CHECK-SPIRV-DAG: OpDecorate %[[#ExternalFun]] LinkageAttributes "__devicelib_abs" Import
+
+define weak dso_local spir_func i32 @abs(i32 noundef %x) {
+entry:
+ %call = tail call spir_func i32 @__devicelib_abs(i32 noundef %x) #11
+ ret i32 %call
+}
+
+declare extern_weak dso_local spir_func i32 @__devicelib_abs(i32 noundef)
diff --git a/llvm/test/CodeGen/SPIRV/link-attribute.ll b/llvm/test/CodeGen/SPIRV/linkage/link-attribute.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/link-attribute.ll
rename to llvm/test/CodeGen/SPIRV/linkage/link-attribute.ll
diff --git a/llvm/test/CodeGen/SPIRV/linkage-types.ll b/llvm/test/CodeGen/SPIRV/linkage/linkage-types.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/linkage-types.ll
rename to llvm/test/CodeGen/SPIRV/linkage/linkage-types.ll
More information about the llvm-commits
mailing list