[llvm] [SPIR-V] Emit proper pointer type for OpenCL kernel arguments (PR #67726)
Michal Paszkowski via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 5 04:00:51 PDT 2023
================
@@ -194,23 +194,39 @@ getKernelArgTypeQual(const Function &KernelFunction, unsigned ArgIdx) {
return {};
}
-static Type *getArgType(const Function &F, unsigned ArgIdx) {
+static SPIRVType *getArgSPIRVType(const Function &F, unsigned ArgIdx,
+ SPIRVGlobalRegistry *GR,
+ MachineIRBuilder &MIRBuilder) {
+ // Read argument's access qualifier from metadata or default
+ SPIRV::AccessQualifier::AccessQualifier ArgAccessQual =
+ getArgAccessQual(F, ArgIdx);
+
Type *OriginalArgType = getOriginalFunctionType(F)->getParamType(ArgIdx);
- if (F.getCallingConv() != CallingConv::SPIR_KERNEL ||
- isSpecialOpaqueType(OriginalArgType))
- return OriginalArgType;
+
+ // In case of non-kernel SPIR-V function, use the original IR type.
+ if (F.getCallingConv() != CallingConv::SPIR_KERNEL)
+ return GR->getOrCreateSPIRVType(OriginalArgType, MIRBuilder, ArgAccessQual);
+
+ // Use original type if it is already TargetExtType of a builtin type.
+ if (isSpecialOpaqueType(OriginalArgType))
+ return GR->getOrCreateSPIRVType(OriginalArgType, MIRBuilder, ArgAccessQual);
MDString *MDKernelArgType =
getKernelArgAttribute(F, ArgIdx, "kernel_arg_type");
- if (!MDKernelArgType || !MDKernelArgType->getString().endswith("_t"))
- return OriginalArgType;
-
- std::string KernelArgTypeStr = "opencl." + MDKernelArgType->getString().str();
- Type *ExistingOpaqueType =
- StructType::getTypeByName(F.getContext(), KernelArgTypeStr);
- return ExistingOpaqueType
- ? ExistingOpaqueType
- : StructType::create(F.getContext(), KernelArgTypeStr);
+ if (!MDKernelArgType || (MDKernelArgType->getString().ends_with("*") &&
----------------
michalpaszkowski wrote:
@Keenuts I believe this is for historical reasons. These are the metadata we get from the Khronos SPIR-V Translator and Clang. The situation is even more complicated since older versions of the SPIR-V Translator emit these metadata in other format (not attached to functions) and we need to handle both formats.
https://github.com/llvm/llvm-project/pull/67726
More information about the llvm-commits
mailing list