[llvm] [llvm][SPIRV] Add pass to lower Ctors/Dtors for SPIRV (PR #187509)
Alex Duran via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 22 16:50:08 PDT 2026
https://github.com/adurang updated https://github.com/llvm/llvm-project/pull/187509
>From d8bb5a537a5ae0d095dd6146a0a5b4b4962776a3 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Thu, 19 Mar 2026 04:11:08 -0700
Subject: [PATCH 1/9] [llvm][SPIRV] Add pass to lower Ctors/Dtors for SPIRV
---
llvm/lib/Target/SPIRV/CMakeLists.txt | 1 +
llvm/lib/Target/SPIRV/SPIRV.h | 2 +
.../Target/SPIRV/SPIRVCtorDtorLowering.cpp | 249 ++++++++++++++++++
llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.h | 27 ++
llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp | 2 +
5 files changed, 281 insertions(+)
create mode 100644 llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
create mode 100644 llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.h
diff --git a/llvm/lib/Target/SPIRV/CMakeLists.txt b/llvm/lib/Target/SPIRV/CMakeLists.txt
index 58989237ad3ea..0ce96c23603ff 100644
--- a/llvm/lib/Target/SPIRV/CMakeLists.txt
+++ b/llvm/lib/Target/SPIRV/CMakeLists.txt
@@ -22,6 +22,7 @@ add_llvm_target(SPIRVCodeGen
SPIRVCallLowering.cpp
SPIRVInlineAsmLowering.cpp
SPIRVCommandLine.cpp
+ SPIRVCtorDtorLowering.cpp
SPIRVEmitIntrinsics.cpp
SPIRVGlobalRegistry.cpp
SPIRVInstrInfo.cpp
diff --git a/llvm/lib/Target/SPIRV/SPIRV.h b/llvm/lib/Target/SPIRV/SPIRV.h
index da4da1a3fe83b..999e24bbd9771 100644
--- a/llvm/lib/Target/SPIRV/SPIRV.h
+++ b/llvm/lib/Target/SPIRV/SPIRV.h
@@ -35,6 +35,7 @@ FunctionPass *createSPIRVPostLegalizerPass();
ModulePass *createSPIRVEmitIntrinsicsPass(SPIRVTargetMachine *TM);
ModulePass *createSPIRVPrepareGlobalsPass();
MachineFunctionPass *createSPIRVEmitNonSemanticDIPass(SPIRVTargetMachine *TM);
+ModulePass *createSPIRVCtorDtorLoweringLegacyPass();
InstructionSelector *
createSPIRVInstructionSelector(const SPIRVTargetMachine &TM,
const SPIRVSubtarget &Subtarget,
@@ -59,6 +60,7 @@ void initializeSPIRVPrepareGlobalsPass(PassRegistry &);
void initializeSPIRVStripConvergentIntrinsicsPass(PassRegistry &);
void initializeSPIRVLegalizeImplicitBindingPass(PassRegistry &);
void initializeSPIRVLegalizeZeroSizeArraysLegacyPass(PassRegistry &);
+void initializeSPIRVCtorDtorLoweringLegacyPass(PassRegistry &);
} // namespace llvm
#endif // LLVM_LIB_TARGET_SPIRV_SPIRV_H
diff --git a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
new file mode 100644
index 0000000000000..8bcc4cc48e6a5
--- /dev/null
+++ b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
@@ -0,0 +1,249 @@
+//===-- SPIRVCtorDtorLowering.cpp - Handle global ctors and dtors --------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass creates a unified init and fini kernel with the required metadata
+// to call global constructors and destructors on SPIR-V targets.
+//
+//===----------------------------------------------------------------------===//
+
+#include "SPIRVCtorDtorLowering.h"
+#include "MCTargetDesc/SPIRVBaseInfo.h"
+#include "SPIRV.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/CallingConv.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/MD5.h"
+#include "llvm/Transforms/Utils/ModuleUtils.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "spirv-lower-ctor-dtor"
+
+static cl::opt<std::string>
+ GlobalStr("spirv-lower-global-ctor-dtor-id",
+ cl::desc("Override unique ID of ctor/dtor globals."),
+ cl::init(""), cl::Hidden);
+
+static cl::opt<bool>
+ CreateKernels("spirv-emit-init-fini-kernel",
+ cl::desc("Emit kernels to call ctor/dtor globals."),
+ cl::init(true), cl::Hidden);
+
+namespace {
+
+static std::string getHash(StringRef Str) {
+ llvm::MD5 Hasher;
+ llvm::MD5::MD5Result Hash;
+ Hasher.update(Str);
+ Hasher.final(Hash);
+ return llvm::utohexstr(Hash.low(), /*LowerCase=*/true);
+}
+
+static void addKernelAttrs(Function *F) {
+ F->setCallingConv(CallingConv::SPIR_KERNEL);
+ F->addFnAttr("uniform-work-group-size", "true");
+}
+
+static Function *createInitOrFiniKernelFunction(Module &M, bool IsCtor) {
+ StringRef InitOrFiniKernelName =
+ IsCtor ? "spirv$device$init" : "spirv$device$fini";
+ if (M.getFunction(InitOrFiniKernelName))
+ return nullptr;
+
+ Function *InitOrFiniKernel = Function::createWithDefaultAttr(
+ FunctionType::get(Type::getVoidTy(M.getContext()), false),
+ GlobalValue::WeakODRLinkage, 0, InitOrFiniKernelName, &M);
+ addKernelAttrs(InitOrFiniKernel);
+
+ return InitOrFiniKernel;
+}
+
+// We create the IR required to call each callback in this section. This is
+// equivalent to the following code. Normally, the linker would provide us with
+// the definitions of the init and fini array sections. The 'spirv-link' linker
+// does not do this so initializing these values is done by the offload runtime.
+//
+// extern "C" void **__init_array_start = nullptr;
+// extern "C" void **__init_array_end = nullptr;
+// extern "C" void **__fini_array_start = nullptr;
+// extern "C" void **__fini_array_end = nullptr;
+//
+// using InitCallback = void();
+// using FiniCallback = void();
+//
+// void call_init_array_callbacks() {
+// for (auto start = __init_array_start; start != __init_array_end; ++start)
+// reinterpret_cast<InitCallback *>(*start)();
+// }
+//
+// void call_fini_array_callbacks() {
+// size_t fini_array_size = __fini_array_end - __fini_array_start;
+// for (size_t i = fini_array_size; i > 0; --i)
+// reinterpret_cast<FiniCallback *>(__fini_array_start[i - 1])();
+// }
+static void createInitOrFiniCalls(Function &F, bool IsCtor) {
+ Module &M = *F.getParent();
+ LLVMContext &C = M.getContext();
+
+ IRBuilder<> IRB(BasicBlock::Create(C, "entry", &F));
+ auto *LoopBB = BasicBlock::Create(C, "while.entry", &F);
+ auto *ExitBB = BasicBlock::Create(C, "while.end", &F);
+ constexpr unsigned GlobalAddrSpace = 1;
+ Type *PtrTy = IRB.getPtrTy(GlobalAddrSpace);
+
+ auto CreateGlobal = [&](const char *Name) -> GlobalVariable * {
+ auto *GV = new GlobalVariable(
+ M, PointerType::get(C, 0),
+ /*isConstant=*/false, GlobalValue::WeakAnyLinkage,
+ Constant::getNullValue(PointerType::get(C, 0)),
+ Name,
+ /*InsertBefore=*/nullptr, GlobalVariable::NotThreadLocal,
+ /*AddressSpace=*/GlobalAddrSpace);
+ GV->setVisibility(GlobalVariable::ProtectedVisibility);
+ return GV;
+ };
+
+ auto *Begin = M.getOrInsertGlobal(
+ IsCtor ? "__init_array_start" : "__fini_array_start",
+ PointerType::get(C, 0),
+ function_ref<GlobalVariable *()>(
+ [&]() { return CreateGlobal(IsCtor ? "__init_array_start" : "__fini_array_start"); }));
+ auto *End = M.getOrInsertGlobal(
+ IsCtor ? "__init_array_end" : "__fini_array_end", PointerType::get(C, 0),
+ function_ref<GlobalVariable *()>(
+ [&]() { return CreateGlobal(IsCtor ? "__init_array_end" : "__fini_array_end"); }));
+ auto *CallBackTy = FunctionType::get(IRB.getVoidTy(), {});
+
+ // The destructor array must be called in reverse order. Get an expression to
+ // the end of the array and iterate backwards in that case.
+ Value *BeginVal = IRB.CreateLoad(Begin->getType(), Begin, "begin");
+ Value *EndVal = IRB.CreateLoad(Begin->getType(), End, "stop");
+ if (!IsCtor) {
+ Value *OldBeginVal = BeginVal;
+ BeginVal =
+ IRB.CreateInBoundsGEP(PointerType::get(C, 0), EndVal,
+ ArrayRef<Value *>(ConstantInt::getAllOnesValue(
+ IntegerType::getInt64Ty(C))),
+ "start");
+ EndVal = OldBeginVal;
+ }
+ IRB.CreateCondBr(
+ IRB.CreateCmp(IsCtor ? ICmpInst::ICMP_NE : ICmpInst::ICMP_UGE, BeginVal,
+ EndVal),
+ LoopBB, ExitBB);
+ IRB.SetInsertPoint(LoopBB);
+ auto *CallBackPHI = IRB.CreatePHI(PtrTy, 2, "ptr");
+ auto *CallBack = IRB.CreateLoad(IRB.getPtrTy(F.getAddressSpace()),
+ CallBackPHI, "callback");
+ IRB.CreateCall(CallBackTy, CallBack);
+ auto *NewCallBack =
+ IRB.CreateConstGEP1_64(PtrTy, CallBackPHI, IsCtor ? 1 : -1, "next");
+ auto *EndCmp = IRB.CreateCmp(IsCtor ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_ULT,
+ NewCallBack, EndVal, "end");
+ CallBackPHI->addIncoming(BeginVal, &F.getEntryBlock());
+ CallBackPHI->addIncoming(NewCallBack, LoopBB);
+ IRB.CreateCondBr(EndCmp, ExitBB, LoopBB);
+ IRB.SetInsertPoint(ExitBB);
+ IRB.CreateRetVoid();
+}
+
+static bool createInitOrFiniGlobals(Module &M, GlobalVariable *GV,
+ bool IsCtor) {
+ ConstantArray *GA = dyn_cast<ConstantArray>(GV->getInitializer());
+ if (!GA || GA->getNumOperands() == 0)
+ return false;
+
+ // SPIR-V has no way to emit variables at specific sections or support for
+ // the traditional constructor sections. Instead, we emit mangled global
+ // names so the runtime can build the list manually.
+ for (Value *V : GA->operands()) {
+ auto *CS = cast<ConstantStruct>(V);
+ auto *F = cast<Constant>(CS->getOperand(1));
+ uint64_t Priority = cast<ConstantInt>(CS->getOperand(0))->getSExtValue();
+ std::string PriorityStr = "." + std::to_string(Priority);
+ // We append a semi-unique hash and the priority to the global name.
+ std::string GlobalID =
+ !GlobalStr.empty() ? GlobalStr : getHash(M.getSourceFileName());
+ std::string NameStr =
+ ((IsCtor ? "__init_array_object_" : "__fini_array_object_") +
+ F->getName() + "_" + GlobalID + "_" + std::to_string(Priority))
+ .str();
+ llvm::transform(NameStr, NameStr.begin(),
+ [](char c) { return c == '.' ? '_' : c; });
+
+ auto *GV = new GlobalVariable(M, F->getType(), /*IsConstant=*/true,
+ GlobalValue::ExternalLinkage, F, NameStr,
+ nullptr, GlobalValue::NotThreadLocal,
+ /*AddressSpace=*/0);
+ GV->setSection(IsCtor ? ".init_array" + PriorityStr
+ : ".fini_array" + PriorityStr);
+ GV->setVisibility(GlobalVariable::ProtectedVisibility);
+ }
+
+ return true;
+}
+
+static bool createInitOrFiniKernel(Module &M, StringRef GlobalName,
+ bool IsCtor) {
+ GlobalVariable *GV = M.getGlobalVariable(GlobalName);
+ if (!GV || !GV->hasInitializer())
+ return false;
+
+ if (!createInitOrFiniGlobals(M, GV, IsCtor))
+ return false;
+
+ if (!CreateKernels)
+ return true;
+
+ Function *InitOrFiniKernel = createInitOrFiniKernelFunction(M, IsCtor);
+ if (!InitOrFiniKernel)
+ return false;
+
+ createInitOrFiniCalls(*InitOrFiniKernel, IsCtor);
+
+ GV->eraseFromParent();
+ return true;
+}
+
+static bool lowerCtorsAndDtors(Module &M) {
+ bool Modified = false;
+ Modified |= createInitOrFiniKernel(M, "llvm.global_ctors", /*IsCtor =*/true);
+ Modified |= createInitOrFiniKernel(M, "llvm.global_dtors", /*IsCtor =*/false);
+ return Modified;
+}
+
+class SPIRVCtorDtorLoweringLegacy final : public ModulePass {
+public:
+ static char ID;
+ SPIRVCtorDtorLoweringLegacy() : ModulePass(ID) {}
+ bool runOnModule(Module &M) override { return lowerCtorsAndDtors(M); }
+};
+
+} // End anonymous namespace
+
+PreservedAnalyses SPIRVCtorDtorLoweringPass::run(Module &M,
+ ModuleAnalysisManager &AM) {
+ return lowerCtorsAndDtors(M) ? PreservedAnalyses::none()
+ : PreservedAnalyses::all();
+}
+
+char SPIRVCtorDtorLoweringLegacy::ID = 0;
+INITIALIZE_PASS(SPIRVCtorDtorLoweringLegacy, DEBUG_TYPE,
+ "Lower ctors and dtors for SPIR-V", false, false)
+
+ModulePass *llvm::createSPIRVCtorDtorLoweringLegacyPass() {
+ return new SPIRVCtorDtorLoweringLegacy();
+}
diff --git a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.h b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.h
new file mode 100644
index 0000000000000..daeb6da7356cc
--- /dev/null
+++ b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.h
@@ -0,0 +1,27 @@
+//===-- SPIRVCtorDtorLowering.h --------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVCTORDTORLOWERING_H
+#define LLVM_LIB_TARGET_SPIRV_SPIRVCTORDTORLOWERING_H
+
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+class Module;
+class PassRegistry;
+
+/// Lower llvm.global_ctors and llvm.global_dtors to special kernels.
+class SPIRVCtorDtorLoweringPass
+ : public PassInfoMixin<SPIRVCtorDtorLoweringPass> {
+public:
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_LIB_TARGET_SPIRV_SPIRVCTORDTORLOWERING_H
diff --git a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
index 1759b34af3e90..06dee650efe43 100644
--- a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
@@ -66,6 +66,7 @@ extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVTarget() {
initializeSPIRVPrepareFunctionsPass(PR);
initializeSPIRVPrepareGlobalsPass(PR);
initializeSPIRVStripConvergentIntrinsicsPass(PR);
+ initializeSPIRVCtorDtorLoweringLegacyPass(PR);
}
static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
@@ -186,6 +187,7 @@ void SPIRVPassConfig::addIRPasses() {
}
addPass(createSPIRVRegularizerPass());
+ addPass(createSPIRVCtorDtorLoweringLegacyPass());
addPass(createSPIRVPrepareFunctionsPass(TM));
addPass(createSPIRVPrepareGlobalsPass());
}
>From 0d8c546a5a9f05ab71e12ea6f309c53b76a1dcf3 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Thu, 19 Mar 2026 07:24:34 -0700
Subject: [PATCH 2/9] format
---
llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
index 8bcc4cc48e6a5..ed5f9028c7bd3 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
@@ -108,8 +108,7 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
auto *GV = new GlobalVariable(
M, PointerType::get(C, 0),
/*isConstant=*/false, GlobalValue::WeakAnyLinkage,
- Constant::getNullValue(PointerType::get(C, 0)),
- Name,
+ Constant::getNullValue(PointerType::get(C, 0)), Name,
/*InsertBefore=*/nullptr, GlobalVariable::NotThreadLocal,
/*AddressSpace=*/GlobalAddrSpace);
GV->setVisibility(GlobalVariable::ProtectedVisibility);
@@ -118,13 +117,15 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
auto *Begin = M.getOrInsertGlobal(
IsCtor ? "__init_array_start" : "__fini_array_start",
- PointerType::get(C, 0),
- function_ref<GlobalVariable *()>(
- [&]() { return CreateGlobal(IsCtor ? "__init_array_start" : "__fini_array_start"); }));
+ PointerType::get(C, 0), function_ref<GlobalVariable *()>([&]() {
+ return CreateGlobal(IsCtor ? "__init_array_start"
+ : "__fini_array_start");
+ }));
auto *End = M.getOrInsertGlobal(
IsCtor ? "__init_array_end" : "__fini_array_end", PointerType::get(C, 0),
- function_ref<GlobalVariable *()>(
- [&]() { return CreateGlobal(IsCtor ? "__init_array_end" : "__fini_array_end"); }));
+ function_ref<GlobalVariable *()>([&]() {
+ return CreateGlobal(IsCtor ? "__init_array_end" : "__fini_array_end");
+ }));
auto *CallBackTy = FunctionType::get(IRB.getVoidTy(), {});
// The destructor array must be called in reverse order. Get an expression to
>From 46bca4c80c540a60e3ffcd395c8e2be19eddf3ab Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Fri, 20 Mar 2026 05:41:07 -0700
Subject: [PATCH 3/9] Restrict pass to OpenMP offload
---
llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
index ed5f9028c7bd3..5a30ce629a21e 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
@@ -27,6 +27,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MD5.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
+#include "llvm/Transforms/IPO/OpenMPOpt.h"
using namespace llvm;
@@ -220,6 +221,10 @@ static bool createInitOrFiniKernel(Module &M, StringRef GlobalName,
}
static bool lowerCtorsAndDtors(Module &M) {
+ // Only run this pass for OpenMP offload compilation
+ if (!llvm::omp::isOpenMPDevice(M))
+ return false;
+
bool Modified = false;
Modified |= createInitOrFiniKernel(M, "llvm.global_ctors", /*IsCtor =*/true);
Modified |= createInitOrFiniKernel(M, "llvm.global_dtors", /*IsCtor =*/false);
>From 6faf5f0f2554784b7a68af88bbae7fb0b5d24888 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Fri, 20 Mar 2026 05:43:47 -0700
Subject: [PATCH 4/9] Adjust pass desc and fix test
---
llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp | 4 ++--
llvm/test/CodeGen/SPIRV/llc-pipeline.ll | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
index 5a30ce629a21e..7309b7143b9cb 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
@@ -26,8 +26,8 @@
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MD5.h"
-#include "llvm/Transforms/Utils/ModuleUtils.h"
#include "llvm/Transforms/IPO/OpenMPOpt.h"
+#include "llvm/Transforms/Utils/ModuleUtils.h"
using namespace llvm;
@@ -248,7 +248,7 @@ PreservedAnalyses SPIRVCtorDtorLoweringPass::run(Module &M,
char SPIRVCtorDtorLoweringLegacy::ID = 0;
INITIALIZE_PASS(SPIRVCtorDtorLoweringLegacy, DEBUG_TYPE,
- "Lower ctors and dtors for SPIR-V", false, false)
+ "SPIRV lower ctors and dtors", false, false)
ModulePass *llvm::createSPIRVCtorDtorLoweringLegacyPass() {
return new SPIRVCtorDtorLoweringLegacy();
diff --git a/llvm/test/CodeGen/SPIRV/llc-pipeline.ll b/llvm/test/CodeGen/SPIRV/llc-pipeline.ll
index cad07e2557614..6d9f02ba909c8 100644
--- a/llvm/test/CodeGen/SPIRV/llc-pipeline.ll
+++ b/llvm/test/CodeGen/SPIRV/llc-pipeline.ll
@@ -34,6 +34,7 @@
; SPIRV-O0-NEXT: Expand variadic functions
; SPIRV-O0-NEXT: FunctionPass Manager
; SPIRV-O0-NEXT: SPIR-V Regularizer
+; SPIRV-O0-NEXT: SPIRV lower ctors and dtors
; SPIRV-O0-NEXT: SPIRV prepare functions
; SPIRV-O0-NEXT: SPIRV prepare global variables
; SPIRV-O0-NEXT: FunctionPass Manager
@@ -140,6 +141,7 @@
; SPIRV-Opt-NEXT: Expand variadic functions
; SPIRV-Opt-NEXT: FunctionPass Manager
; SPIRV-Opt-NEXT: SPIR-V Regularizer
+; SPIRV-Opt-NEXT: SPIRV lower ctors and dtors
; SPIRV-Opt-NEXT: SPIRV prepare functions
; SPIRV-Opt-NEXT: SPIRV prepare global variables
; SPIRV-Opt-NEXT: FunctionPass Manager
>From 71f51bb038c596906a99ae50887307658ba2aa59 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Fri, 20 Mar 2026 05:49:28 -0700
Subject: [PATCH 5/9] address feedback
---
.../Target/SPIRV/SPIRVCtorDtorLowering.cpp | 26 +++++++++----------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
index 7309b7143b9cb..097f40595fdf7 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
@@ -45,7 +45,7 @@ static cl::opt<bool>
namespace {
-static std::string getHash(StringRef Str) {
+std::string getHash(StringRef Str) {
llvm::MD5 Hasher;
llvm::MD5::MD5Result Hash;
Hasher.update(Str);
@@ -53,12 +53,12 @@ static std::string getHash(StringRef Str) {
return llvm::utohexstr(Hash.low(), /*LowerCase=*/true);
}
-static void addKernelAttrs(Function *F) {
+void addKernelAttrs(Function *F) {
F->setCallingConv(CallingConv::SPIR_KERNEL);
F->addFnAttr("uniform-work-group-size", "true");
}
-static Function *createInitOrFiniKernelFunction(Module &M, bool IsCtor) {
+Function *createInitOrFiniKernelFunction(Module &M, bool IsCtor) {
StringRef InitOrFiniKernelName =
IsCtor ? "spirv$device$init" : "spirv$device$fini";
if (M.getFunction(InitOrFiniKernelName))
@@ -95,7 +95,7 @@ static Function *createInitOrFiniKernelFunction(Module &M, bool IsCtor) {
// for (size_t i = fini_array_size; i > 0; --i)
// reinterpret_cast<FiniCallback *>(__fini_array_start[i - 1])();
// }
-static void createInitOrFiniCalls(Function &F, bool IsCtor) {
+void createInitOrFiniCalls(Function &F, bool IsCtor) {
Module &M = *F.getParent();
LLVMContext &C = M.getContext();
@@ -107,9 +107,9 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
auto CreateGlobal = [&](const char *Name) -> GlobalVariable * {
auto *GV = new GlobalVariable(
- M, PointerType::get(C, 0),
+ M, PointerType::getUnqual(C),
/*isConstant=*/false, GlobalValue::WeakAnyLinkage,
- Constant::getNullValue(PointerType::get(C, 0)), Name,
+ Constant::getNullValue(PointerType::getUnqual(C)), Name,
/*InsertBefore=*/nullptr, GlobalVariable::NotThreadLocal,
/*AddressSpace=*/GlobalAddrSpace);
GV->setVisibility(GlobalVariable::ProtectedVisibility);
@@ -118,12 +118,12 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
auto *Begin = M.getOrInsertGlobal(
IsCtor ? "__init_array_start" : "__fini_array_start",
- PointerType::get(C, 0), function_ref<GlobalVariable *()>([&]() {
+ PointerType::getUnqual(C), function_ref<GlobalVariable *()>([&]() {
return CreateGlobal(IsCtor ? "__init_array_start"
: "__fini_array_start");
}));
auto *End = M.getOrInsertGlobal(
- IsCtor ? "__init_array_end" : "__fini_array_end", PointerType::get(C, 0),
+ IsCtor ? "__init_array_end" : "__fini_array_end", PointerType::getUnqual(C),
function_ref<GlobalVariable *()>([&]() {
return CreateGlobal(IsCtor ? "__init_array_end" : "__fini_array_end");
}));
@@ -136,7 +136,7 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
if (!IsCtor) {
Value *OldBeginVal = BeginVal;
BeginVal =
- IRB.CreateInBoundsGEP(PointerType::get(C, 0), EndVal,
+ IRB.CreateInBoundsGEP(PointerType::getUnqual(C), EndVal,
ArrayRef<Value *>(ConstantInt::getAllOnesValue(
IntegerType::getInt64Ty(C))),
"start");
@@ -162,7 +162,7 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
IRB.CreateRetVoid();
}
-static bool createInitOrFiniGlobals(Module &M, GlobalVariable *GV,
+bool createInitOrFiniGlobals(Module &M, GlobalVariable *GV,
bool IsCtor) {
ConstantArray *GA = dyn_cast<ConstantArray>(GV->getInitializer());
if (!GA || GA->getNumOperands() == 0)
@@ -189,7 +189,7 @@ static bool createInitOrFiniGlobals(Module &M, GlobalVariable *GV,
auto *GV = new GlobalVariable(M, F->getType(), /*IsConstant=*/true,
GlobalValue::ExternalLinkage, F, NameStr,
nullptr, GlobalValue::NotThreadLocal,
- /*AddressSpace=*/0);
+ /*AddressSpace=*/1);
GV->setSection(IsCtor ? ".init_array" + PriorityStr
: ".fini_array" + PriorityStr);
GV->setVisibility(GlobalVariable::ProtectedVisibility);
@@ -198,7 +198,7 @@ static bool createInitOrFiniGlobals(Module &M, GlobalVariable *GV,
return true;
}
-static bool createInitOrFiniKernel(Module &M, StringRef GlobalName,
+bool createInitOrFiniKernel(Module &M, StringRef GlobalName,
bool IsCtor) {
GlobalVariable *GV = M.getGlobalVariable(GlobalName);
if (!GV || !GV->hasInitializer())
@@ -220,7 +220,7 @@ static bool createInitOrFiniKernel(Module &M, StringRef GlobalName,
return true;
}
-static bool lowerCtorsAndDtors(Module &M) {
+bool lowerCtorsAndDtors(Module &M) {
// Only run this pass for OpenMP offload compilation
if (!llvm::omp::isOpenMPDevice(M))
return false;
>From b9970a409ae2cb755dab23be61f4f086d8026f19 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Fri, 20 Mar 2026 05:49:48 -0700
Subject: [PATCH 6/9] Add new tests
---
.../CodeGen/SPIRV/ctor-dtor-lowering-ir.ll | 54 +++++++++++++++++++
llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll | 49 +++++++++++++++++
2 files changed, 103 insertions(+)
create mode 100644 llvm/test/CodeGen/SPIRV/ctor-dtor-lowering-ir.ll
create mode 100644 llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll
diff --git a/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering-ir.ll b/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering-ir.ll
new file mode 100644
index 0000000000000..6f477645081af
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering-ir.ll
@@ -0,0 +1,54 @@
+; NOTE: Test for SPIR-V constructor/destructor lowering pass at IR level
+; RUN: llc -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o /dev/null -print-after=spirv-lower-ctor-dtor 2>&1 | FileCheck %s
+
+; This test verifies that:
+; 1. The init/fini kernels are created
+; 2. Symbol mangling includes function name, hash, and priority
+; 3. Array boundary globals are created
+; 4. The pass only runs when offload metadata is present
+
+; Mark this as an offload module (OpenMP target device)
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"openmp-device", i32 50}
+
+define void @high_priority() {
+entry:
+ ret void
+}
+
+define void @low_priority() {
+entry:
+ ret void
+}
+
+define spir_kernel void @kernel_main() {
+entry:
+ ret void
+}
+
+; Constructor with priority 100
+ at llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [
+ { i32, ptr, ptr } { i32 100, ptr @high_priority, ptr null },
+ { i32, ptr, ptr } { i32 50, ptr @low_priority, ptr null }
+]
+
+ at llvm.global_dtors = appending global [2 x { i32, ptr, ptr }] [
+ { i32, ptr, ptr } { i32 100, ptr @high_priority, ptr null },
+ { i32, ptr, ptr } { i32 50, ptr @low_priority, ptr null }
+]
+
+; CHECK: @__init_array_object_high_priority_{{[a-f0-9]+}}_100 = protected constant ptr @high_priority
+; CHECK: @__init_array_object_low_priority_{{[a-f0-9]+}}_50 = protected constant ptr @low_priority
+; CHECK: @__init_array_start = weak protected addrspace(1) global ptr null
+; CHECK: @__init_array_end = weak protected addrspace(1) global ptr null
+
+; CHECK: @__fini_array_object_high_priority_{{[a-f0-9]+}}_100 = protected constant ptr @high_priority
+; CHECK: @__fini_array_object_low_priority_{{[a-f0-9]+}}_50 = protected constant ptr @low_priority
+; CHECK: @__fini_array_start = weak protected addrspace(1) global ptr null
+; CHECK: @__fini_array_end = weak protected addrspace(1) global ptr null
+
+
+; CHECK: define weak_odr spir_kernel void @"spirv$device$init"()
+; CHECK: define weak_odr spir_kernel void @"spirv$device$fini"()
+
+
diff --git a/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll b/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll
new file mode 100644
index 0000000000000..fa3dbdf66b1d5
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll
@@ -0,0 +1,49 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; Test that the SPIR-V constructor/destructor lowering pass creates the
+; expected init kernel and symbols for offload compilation.
+
+; This module has the openmp.is_target_device metadata to indicate offload mode
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"openmp-device", i32 50}
+
+define void @my_constructor() {
+entry:
+ ret void
+}
+
+define void @my_destructor() {
+entry:
+ ret void
+}
+
+define spir_kernel void @main() {
+entry:
+ ret void
+}
+
+ at llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [
+ { i32, ptr, ptr } { i32 65535, ptr @my_constructor, ptr null }
+]
+
+ at llvm.global_dtors = appending global [1 x { i32, ptr, ptr }] [
+ { i32, ptr, ptr } { i32 65535, ptr @my_destructor, ptr null }
+]
+
+; CHECK-DAG: OpName %[[#INIT_KERNEL:]] "spirv$device$init"
+; CHECK-DAG: OpName %[[#FINI_KERNEL:]] "spirv$device$fini"
+; CHECK-DAG: OpName %[[#INIT_START:]] "__init_array_start"
+; CHECK-DAG: OpName %[[#INIT_END:]] "__init_array_end"
+; CHECK-DAG: OpName %[[#FINI_START:]] "__fini_array_start"
+; CHECK-DAG: OpName %[[#FINI_END:]] "__fini_array_end"
+
+; CHECK-DAG: OpName %[[#INIT_OBJ:]] "__init_array_object_my_constructor_{{[a-f0-9]+}}_65535"
+; CHECK-DAG: OpName %[[#FINI_OBJ:]] "__fini_array_object_my_destructor_{{[a-f0-9]+}}_65535"
+
+; CHECK: %[[#INIT_KERNEL]] = OpFunction
+; CHECK: OpFunctionEnd
+
+; CHECK: %[[#FINI_KERNEL]] = OpFunction
+; CHECK: OpFunctionEnd
>From b33845eede42e2fabbfb39d21c7bb09dcaaf7c86 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Fri, 20 Mar 2026 05:58:24 -0700
Subject: [PATCH 7/9] format
---
llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
index 097f40595fdf7..d86a9f24c6643 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCtorDtorLowering.cpp
@@ -123,8 +123,8 @@ void createInitOrFiniCalls(Function &F, bool IsCtor) {
: "__fini_array_start");
}));
auto *End = M.getOrInsertGlobal(
- IsCtor ? "__init_array_end" : "__fini_array_end", PointerType::getUnqual(C),
- function_ref<GlobalVariable *()>([&]() {
+ IsCtor ? "__init_array_end" : "__fini_array_end",
+ PointerType::getUnqual(C), function_ref<GlobalVariable *()>([&]() {
return CreateGlobal(IsCtor ? "__init_array_end" : "__fini_array_end");
}));
auto *CallBackTy = FunctionType::get(IRB.getVoidTy(), {});
@@ -162,8 +162,7 @@ void createInitOrFiniCalls(Function &F, bool IsCtor) {
IRB.CreateRetVoid();
}
-bool createInitOrFiniGlobals(Module &M, GlobalVariable *GV,
- bool IsCtor) {
+bool createInitOrFiniGlobals(Module &M, GlobalVariable *GV, bool IsCtor) {
ConstantArray *GA = dyn_cast<ConstantArray>(GV->getInitializer());
if (!GA || GA->getNumOperands() == 0)
return false;
@@ -198,8 +197,7 @@ bool createInitOrFiniGlobals(Module &M, GlobalVariable *GV,
return true;
}
-bool createInitOrFiniKernel(Module &M, StringRef GlobalName,
- bool IsCtor) {
+bool createInitOrFiniKernel(Module &M, StringRef GlobalName, bool IsCtor) {
GlobalVariable *GV = M.getGlobalVariable(GlobalName);
if (!GV || !GV->hasInitializer())
return false;
>From 32eafd96a7b01fdb3705f0ea39d9d040164a594b Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Sun, 22 Mar 2026 16:03:57 -0700
Subject: [PATCH 8/9] adjust tests
---
.../CodeGen/SPIRV/ctor-dtor-lowering-ir.ll | 42 +++++++++----------
llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll | 29 +++++++------
2 files changed, 33 insertions(+), 38 deletions(-)
diff --git a/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering-ir.ll b/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering-ir.ll
index 6f477645081af..213c9f2675b2c 100644
--- a/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering-ir.ll
+++ b/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering-ir.ll
@@ -1,22 +1,18 @@
-; NOTE: Test for SPIR-V constructor/destructor lowering pass at IR level
+; Test for SPIR-V constructor/destructor lowering pass at IR level.
; RUN: llc -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o /dev/null -print-after=spirv-lower-ctor-dtor 2>&1 | FileCheck %s
; This test verifies that:
-; 1. The init/fini kernels are created
-; 2. Symbol mangling includes function name, hash, and priority
-; 3. Array boundary globals are created
-; 4. The pass only runs when offload metadata is present
+; 1. The init/fini kernels are created.
+; 2. Symbol mangling includes function name, hash, and priority.
+; 3. Array boundary globals are created.
+; 4. The pass only runs when offload metadata is present.
-; Mark this as an offload module (OpenMP target device)
-!llvm.module.flags = !{!0}
-!0 = !{i32 7, !"openmp-device", i32 50}
-
-define void @high_priority() {
+define void @high_priority() addrspace(4) {
entry:
ret void
}
-define void @low_priority() {
+define void @low_priority() addrspace(4) {
entry:
ret void
}
@@ -26,29 +22,29 @@ entry:
ret void
}
-; Constructor with priority 100
@llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [
- { i32, ptr, ptr } { i32 100, ptr @high_priority, ptr null },
- { i32, ptr, ptr } { i32 50, ptr @low_priority, ptr null }
+ { i32, ptr, ptr } { i32 100, ptr addrspacecast (ptr addrspace(4) @high_priority to ptr), ptr null },
+ { i32, ptr, ptr } { i32 50, ptr addrspacecast (ptr addrspace(4) @low_priority to ptr), ptr null }
]
@llvm.global_dtors = appending global [2 x { i32, ptr, ptr }] [
- { i32, ptr, ptr } { i32 100, ptr @high_priority, ptr null },
- { i32, ptr, ptr } { i32 50, ptr @low_priority, ptr null }
+ { i32, ptr, ptr } { i32 100, ptr addrspacecast (ptr addrspace(4) @high_priority to ptr), ptr null },
+ { i32, ptr, ptr } { i32 50, ptr addrspacecast (ptr addrspace(4) @low_priority to ptr), ptr null }
]
-; CHECK: @__init_array_object_high_priority_{{[a-f0-9]+}}_100 = protected constant ptr @high_priority
-; CHECK: @__init_array_object_low_priority_{{[a-f0-9]+}}_50 = protected constant ptr @low_priority
+; Mark this as an offload module (OpenMP target device).
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"openmp-device", i32 50}
+
+; CHECK: @__init_array_object__{{[a-f0-9]+}}_100 = protected addrspace(1) constant ptr addrspacecast (ptr addrspace(4) @high_priority to ptr)
+; CHECK: @__init_array_object__{{[a-f0-9]+}}_50 = protected addrspace(1) constant ptr addrspacecast (ptr addrspace(4) @low_priority to ptr)
; CHECK: @__init_array_start = weak protected addrspace(1) global ptr null
; CHECK: @__init_array_end = weak protected addrspace(1) global ptr null
-; CHECK: @__fini_array_object_high_priority_{{[a-f0-9]+}}_100 = protected constant ptr @high_priority
-; CHECK: @__fini_array_object_low_priority_{{[a-f0-9]+}}_50 = protected constant ptr @low_priority
+; CHECK: @__fini_array_object__{{[a-f0-9]+}}_100 = protected addrspace(1) constant ptr addrspacecast (ptr addrspace(4) @high_priority to ptr)
+; CHECK: @__fini_array_object__{{[a-f0-9]+}}_50 = protected addrspace(1) constant ptr addrspacecast (ptr addrspace(4) @low_priority to ptr)
; CHECK: @__fini_array_start = weak protected addrspace(1) global ptr null
; CHECK: @__fini_array_end = weak protected addrspace(1) global ptr null
-
; CHECK: define weak_odr spir_kernel void @"spirv$device$init"()
; CHECK: define weak_odr spir_kernel void @"spirv$device$fini"()
-
-
diff --git a/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll b/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll
index fa3dbdf66b1d5..c9853627d3bc2 100644
--- a/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll
+++ b/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll
@@ -1,20 +1,15 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - | FileCheck %s
-; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
-
; Test that the SPIR-V constructor/destructor lowering pass creates the
; expected init kernel and symbols for offload compilation.
-; This module has the openmp.is_target_device metadata to indicate offload mode
-!llvm.module.flags = !{!0}
-!0 = !{i32 7, !"openmp-device", i32 50}
+; RUN: llc -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
-define void @my_constructor() {
+define void @my_constructor() addrspace(4) {
entry:
ret void
}
-define void @my_destructor() {
+define void @my_destructor() addrspace(4) {
entry:
ret void
}
@@ -24,14 +19,18 @@ entry:
ret void
}
- at llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [
- { i32, ptr, ptr } { i32 65535, ptr @my_constructor, ptr null }
+ at llvm.global_ctors = appending global [1 x { i32, ptr, ptr}] [
+ { i32, ptr, ptr } { i32 65535, ptr addrspacecast (ptr addrspace(4) @my_constructor to ptr), ptr null }
]
- at llvm.global_dtors = appending global [1 x { i32, ptr, ptr }] [
- { i32, ptr, ptr } { i32 65535, ptr @my_destructor, ptr null }
+ at llvm.global_dtors = appending global [1 x { i32, ptr, ptr}] [
+ { i32, ptr, ptr } { i32 65535, ptr addrspacecast (ptr addrspace(4) @my_destructor to ptr), ptr null }
]
+; This module has the openmp.is_target_device metadata to indicate offload mode.
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"openmp-device", i32 50}
+
; CHECK-DAG: OpName %[[#INIT_KERNEL:]] "spirv$device$init"
; CHECK-DAG: OpName %[[#FINI_KERNEL:]] "spirv$device$fini"
; CHECK-DAG: OpName %[[#INIT_START:]] "__init_array_start"
@@ -39,8 +38,8 @@ entry:
; CHECK-DAG: OpName %[[#FINI_START:]] "__fini_array_start"
; CHECK-DAG: OpName %[[#FINI_END:]] "__fini_array_end"
-; CHECK-DAG: OpName %[[#INIT_OBJ:]] "__init_array_object_my_constructor_{{[a-f0-9]+}}_65535"
-; CHECK-DAG: OpName %[[#FINI_OBJ:]] "__fini_array_object_my_destructor_{{[a-f0-9]+}}_65535"
+; CHECK-DAG: OpName %[[#INIT_OBJ:]] "__init_array_object__{{[a-f0-9]+}}_65535"
+; CHECK-DAG: OpName %[[#FINI_OBJ:]] "__fini_array_object__{{[a-f0-9]+}}_65535"
; CHECK: %[[#INIT_KERNEL]] = OpFunction
; CHECK: OpFunctionEnd
>From 8810f980e282f661e911d99d1ed1f83cf7469c75 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Sun, 22 Mar 2026 16:49:53 -0700
Subject: [PATCH 9/9] test fix
---
llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll b/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll
index c9853627d3bc2..3eaf878fdc9b5 100644
--- a/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll
+++ b/llvm/test/CodeGen/SPIRV/ctor-dtor-lowering.ll
@@ -2,7 +2,7 @@
; expected init kernel and symbols for offload compilation.
; RUN: llc -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - | FileCheck %s
-; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - -filetype=obj | spirv-val %}
define void @my_constructor() addrspace(4) {
entry:
More information about the llvm-commits
mailing list