Skip to content
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

[SPIR-V] Set non-kernel function linkage type via OpDecorate for all linkage types except for static functions #91598

Merged

Conversation

VyacheslavLevytskyy
Copy link
Contributor

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.

@llvmbot
Copy link
Collaborator

llvmbot commented May 9, 2024

@llvm/pr-subscribers-backend-spir-v

Author: Vyacheslav Levytskyy (VyacheslavLevytskyy)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/91598.diff

6 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp (+2-2)
  • (renamed) llvm/test/CodeGen/SPIRV/linkage/LinkOnceODR.ll ()
  • (renamed) llvm/test/CodeGen/SPIRV/linkage/LinkOnceODRFun.ll ()
  • (added) llvm/test/CodeGen/SPIRV/linkage/extern-weak-linkage.ll (+16)
  • (renamed) llvm/test/CodeGen/SPIRV/linkage/link-attribute.ll ()
  • (renamed) llvm/test/CodeGen/SPIRV/linkage/linkage-types.ll ()
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

@VyacheslavLevytskyy VyacheslavLevytskyy merged commit 3ae6343 into llvm:main May 14, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants