[llvm] [SPIRV] Emit hidden/local function decls as Import linkage (PR #185673)
Nick Sarnie via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 10 08:42:28 PDT 2026
https://github.com/sarnex created https://github.com/llvm/llvm-project/pull/185673
None
>From 98a01afeee75c7231da907938bf1eb3a4eba1b49 Mon Sep 17 00:00:00 2001
From: Nick Sarnie <nick.sarnie at intel.com>
Date: Tue, 10 Mar 2026 08:37:29 -0700
Subject: [PATCH] [SPIRV] Emit hidden/local function decls as Import linkage
Signed-off-by: Nick Sarnie <nick.sarnie at intel.com>
---
llvm/lib/Target/SPIRV/SPIRVUtils.cpp | 7 ++++++-
.../SPIRV/linkage/hidden-function-decl.ll | 16 ++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/SPIRV/linkage/hidden-function-decl.ll
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index 7858f7f932a46..2c070865ef68c 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -1197,8 +1197,13 @@ Type *reconstitutePeeledArrayType(Type *Ty) {
std::optional<SPIRV::LinkageType::LinkageType>
getSpirvLinkageTypeFor(const SPIRVSubtarget &ST, const GlobalValue &GV) {
- if (GV.hasLocalLinkage() || GV.hasHiddenVisibility())
+ if (GV.hasLocalLinkage() || GV.hasHiddenVisibility()) {
+ // Emit local/hidden function decls that are accessed within the module
+ // as Import.
+ if (GV.isDeclarationForLinker() && isa<Function>(GV) && !GV.user_empty())
+ return SPIRV::LinkageType::Import;
return std::nullopt;
+ }
if (GV.isDeclarationForLinker())
return SPIRV::LinkageType::Import;
diff --git a/llvm/test/CodeGen/SPIRV/linkage/hidden-function-decl.ll b/llvm/test/CodeGen/SPIRV/linkage/hidden-function-decl.ll
new file mode 100644
index 0000000000000..d2ff215bb0a42
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/linkage/hidden-function-decl.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 %}
+
+; RUN: llc -O0 -mtriple=spirv64-vulkan1.6-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-vulkan1.6-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK-SPIRV: OpName %[[#FOO:]] "foo"
+; CHECK-SPIRV: OpDecorate %[[#FOO]] LinkageAttributes "foo" Import
+
+define spir_func void @use() {
+entry:
+ call spir_func void @foo()
+ ret void
+}
+
+declare hidden spir_func void @foo()
More information about the llvm-commits
mailing list