================
@@ -843,10 +844,40 @@ Register SPIRVGlobalRegistry::buildGlobalVariable(
if (&GVBuilder.getMBB() != &EntryBB)
GVBuilder.setInsertPt(EntryBB, EntryBB.getFirstTerminator());
- auto MIB = GVBuilder.buildInstr(SPIRV::OpVariable)
+ // 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.
+ const SPIRVSubtarget &Subtarget =
+ cast<SPIRVSubtarget>(MIRBuilder.getMF().getSubtarget());
+ const bool UseUntypedPointers =
+ BaseType->getOpcode() == SPIRV::OpTypeUntypedPointerKHR;
+ const unsigned VariableOpcode =
+ UseUntypedPointers ? SPIRV::OpUntypedVariableKHR : SPIRV::OpVariable;
+
+ auto MIB = GVBuilder.buildInstr(VariableOpcode)
.addDef(ResVReg)
- .addUse(getSPIRVTypeID(BaseType))
- .addImm(static_cast<uint32_t>(Storage));
+ .addUse(getSPIRVTypeID(BaseType));
+
+ // Add storage class (comes before DataType for OpUntypedVariableKHR).
+ MIB.addImm(static_cast<uint32_t>(Storage));
+
+ // For OpUntypedVariableKHR, add the Data Type operand after the storage
+ // class.
+ if (UseUntypedPointers) {
+ // Data Type = the global's value type.
+ SPIRVTypeInst DataType = getPointeeType(BaseType);
+ if (!DataType && GVar)
----------------
MrSidims wrote:
indeed, applied
https://github.com/llvm/llvm-project/pull/201233
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits