Skip to content

Commit b7ac8fd

Browse files
[SPIR-V] Improve type inference: deduce types of composite data structures (#86782)
This PR improves type inference in general and deduces types of composite data structures in particular. Also added a way to insert a bitcast to make a fun call valid in case of arguments types mismatch due to opaque pointers type inference. The attached test `pointers/nested-struct-opaque-pointers.ll` demonstrates new capabilities: the SPIRV code emitted for this test is now (1) valid in a sense of data field types and (2) accepted by `spirv-val`. More strict LIT checks, support of more composite data structures and improvement of fun calls from the perspective of type correctness are main todo's at the moment.
1 parent e5b9399 commit b7ac8fd

10 files changed

+412
-81
lines changed

llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,30 @@ static SPIRVType *getArgSPIRVType(const Function &F, unsigned ArgIdx,
201201
if (!isPointerTy(OriginalArgType))
202202
return GR->getOrCreateSPIRVType(OriginalArgType, MIRBuilder, ArgAccessQual);
203203

204-
// In case OriginalArgType is of pointer type, there are three possibilities:
204+
Argument *Arg = F.getArg(ArgIdx);
205+
Type *ArgType = Arg->getType();
206+
if (isTypedPointerTy(ArgType)) {
207+
SPIRVType *ElementType = GR->getOrCreateSPIRVType(
208+
cast<TypedPointerType>(ArgType)->getElementType(), MIRBuilder);
209+
return GR->getOrCreateSPIRVPointerType(
210+
ElementType, MIRBuilder,
211+
addressSpaceToStorageClass(getPointerAddressSpace(ArgType), ST));
212+
}
213+
214+
// In case OriginalArgType is of untyped pointer type, there are three
215+
// possibilities:
205216
// 1) This is a pointer of an LLVM IR element type, passed byval/byref.
206217
// 2) This is an OpenCL/SPIR-V builtin type if there is spv_assign_type
207-
// intrinsic assigning a TargetExtType.
218+
// intrinsic assigning a TargetExtType.
208219
// 3) This is a pointer, try to retrieve pointer element type from a
209220
// spv_assign_ptr_type intrinsic or otherwise use default pointer element
210221
// type.
211-
Argument *Arg = F.getArg(ArgIdx);
212-
if (HasPointeeTypeAttr(Arg)) {
213-
Type *ByValRefType = Arg->hasByValAttr() ? Arg->getParamByValType()
214-
: Arg->getParamByRefType();
215-
SPIRVType *ElementType = GR->getOrCreateSPIRVType(ByValRefType, MIRBuilder);
222+
if (hasPointeeTypeAttr(Arg)) {
223+
SPIRVType *ElementType =
224+
GR->getOrCreateSPIRVType(getPointeeTypeByAttr(Arg), MIRBuilder);
216225
return GR->getOrCreateSPIRVPointerType(
217226
ElementType, MIRBuilder,
218-
addressSpaceToStorageClass(getPointerAddressSpace(Arg->getType()), ST));
227+
addressSpaceToStorageClass(getPointerAddressSpace(ArgType), ST));
219228
}
220229

221230
for (auto User : Arg->users()) {

0 commit comments

Comments
 (0)