[clang] [llvm] [SPIR-V] Implement SPV_KHR_untyped_pointers extension (PR #201233)
Dmitry Sidorov via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 4 08:55:25 PDT 2026
================
@@ -6917,11 +7040,33 @@ bool SPIRVInstructionSelector::selectFrameIndex(Register ResVReg,
// Change order of instructions if needed: all OpVariable instructions in a
// function must be the first instructions in the first block
auto It = getOpVariableMBBIt(*I.getMF());
- BuildMI(*It->getParent(), It, It->getDebugLoc(), TII.get(SPIRV::OpVariable))
- .addDef(ResVReg)
- .addUse(GR.getSPIRVTypeID(ResType))
- .addImm(static_cast<uint32_t>(SPIRV::StorageClass::Function))
- .constrainAllUses(TII, TRI, RBI);
+
+ // Pointers to opaque types stay typed even with the extension on, so emit the
+ // untyped variant only when the result is actually an untyped pointer.
+ bool UseUntypedPointers =
+ ResType->getOpcode() == SPIRV::OpTypeUntypedPointerKHR;
+ unsigned Opcode =
+ UseUntypedPointers ? SPIRV::OpUntypedVariableKHR : SPIRV::OpVariable;
+
+ auto MIB = BuildMI(*It->getParent(), It, It->getDebugLoc(), TII.get(Opcode))
+ .addDef(ResVReg)
+ .addUse(GR.getSPIRVTypeID(ResType));
+
+ // Add storage class (comes before DataType for OpUntypedVariableKHR).
+ MIB.addImm(static_cast<uint32_t>(SPIRV::StorageClass::Function));
----------------
MrSidims wrote:
reworded with addImm folded
https://github.com/llvm/llvm-project/pull/201233
More information about the cfe-commits
mailing list