================
@@ -838,10 +838,37 @@ 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));
+
+ // OpUntypedVariableKHR takes an extra Data Type operand right after the
+ // storage class, holding the global's value type.
+ if (UseUntypedPointers) {
+ SPIRVTypeInst DataType = getPointeeType(BaseType);
+ if (!DataType)
+ DataType = getOrCreateSPIRVType(GV->getValueType(), GVBuilder,
+ SPIRV::AccessQualifier::ReadWrite,
+ /*EmitIR=*/false);
+ if (!DataType) {
+ // Use i8 as a last resort.
----------------
maarquitos14 wrote:
Is this because some corner cases we already know make it impossible to
retrieve the real type, or for unforeseen cases? If the latter, should we emit
a warning or add an assertion?
https://github.com/llvm/llvm-project/pull/201233
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits