[llvm] [SPIR-V] Insert a bitcast before load/store instruction to keep SPIR-V code valid (PR #84069)
Michal Paszkowski via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 7 21:42:10 PST 2024
================
@@ -705,33 +714,37 @@ SPIRVType *SPIRVGlobalRegistry::createSPIRVType(
}
return getOpTypeFunction(RetTy, ParamTypes, MIRBuilder);
}
- if (auto PType = dyn_cast<PointerType>(Ty)) {
- SPIRVType *SpvElementType;
- // At the moment, all opaque pointers correspond to i8 element type.
- // TODO: change the implementation once opaque pointers are supported
- // in the SPIR-V specification.
- SpvElementType = getOrCreateSPIRVIntegerType(8, MIRBuilder);
- // Get access to information about available extensions
- const SPIRVSubtarget *ST =
- static_cast<const SPIRVSubtarget *>(&MIRBuilder.getMF().getSubtarget());
- auto SC = addressSpaceToStorageClass(PType->getAddressSpace(), *ST);
- // Null pointer means we have a loop in type definitions, make and
- // return corresponding OpTypeForwardPointer.
- if (SpvElementType == nullptr) {
- if (!ForwardPointerTypes.contains(Ty))
- ForwardPointerTypes[PType] = getOpTypeForwardPointer(SC, MIRBuilder);
- return ForwardPointerTypes[PType];
- }
- // If we have forward pointer associated with this type, use its register
- // operand to create OpTypePointer.
- if (ForwardPointerTypes.contains(PType)) {
- Register Reg = getSPIRVTypeID(ForwardPointerTypes[PType]);
- return getOpTypePointer(SC, SpvElementType, MIRBuilder, Reg);
- }
-
- return getOrCreateSPIRVPointerType(SpvElementType, MIRBuilder, SC);
+ unsigned AddrSpace = 0xFFFF;
+ if (auto PType = dyn_cast<TypedPointerType>(Ty))
----------------
michalpaszkowski wrote:
I did not realize that TypedPointerType will remain available after the opaque pointer transition, I thought that the type will be removed in the coming months. Though it does not look like that is the case -- good :)
Not necessarily in this patch, but we might consider removing GR->getOrCreateSPIRVPointerType() completely and assume to always pass TypedPointerType to GR->getOrCreateSPIRVType(). Possibly this could help resolve some issues. We could also remove special handling of pointer types in DuplicatesTracker and just lookup based on TypedPointerType.
https://github.com/llvm/llvm-project/pull/84069
More information about the llvm-commits
mailing list