[llvm] [SPIRV] Track Function placeholder via OpUndef + recordFunctionPointer (PR #197668)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 14 05:19:52 PDT 2026


https://github.com/idubinov created https://github.com/llvm/llvm-project/pull/197668

Emit OpUndef and record the operand -> Function mapping instead of
OpConstantNull, so a future consumer can resolve the function's <id>.
NFC for current behavior.

>From 307b459edd65fbee9160a079ef4cdb3feacefa4b Mon Sep 17 00:00:00 2001
From: idubinov <igor.dubinov at amd.com>
Date: Thu, 14 May 2026 07:14:49 -0500
Subject: [PATCH] Track Function placeholder via OpUndef +
 recordFunctionPointer

---
 llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 616a274be9867..e2976831eabc7 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -6608,11 +6608,20 @@ bool SPIRVInstructionSelector::selectGlobalValue(
         MIB2.constrainAllUses(TII, TRI, RBI);
         return true;
       }
+      // Even without SPV_INTEL_function_pointers a function reference can
+      // still be load-bearing (e.g. the Invoke operand of OpEnqueueKernel).
+      // Emit an OpUndef placeholder of the pointer type and record the
+      // operand -> Function mapping; a later consumer can then resolve it
+      // to the function's <id>. If the placeholder ends up unused, it is
+      // emitted unchanged - functionally equivalent to the previous
+      // OpConstantNull for the existing not-used scenarios.
       MachineInstrBuilder MIB3 =
-          BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpConstantNull))
+          BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpUndef))
               .addDef(ResVReg)
               .addUse(GR.getSPIRVTypeID(ResType));
       GR.add(ConstVal, MIB3);
+      GR.recordFunctionPointer(&MIB3.getInstr()->getOperand(0),
+                               cast<Function>(GV));
       MIB3.constrainAllUses(TII, TRI, RBI);
       return true;
     }



More information about the llvm-commits mailing list