Skip to content

Commit bf2bf74

Browse files
mnaczkigcbot
authored andcommitted
Add type to Parameter Attributes which change in LLVM12
As of llvm12, the byVal and sret parameter attributes must have type. This was not required in earlier versions of LLVM, so SpirvReader did not add types there. It is now necessary
1 parent b7f0605 commit bf2bf74

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -4189,7 +4189,20 @@ SPIRVToLLVM::transFunction(SPIRVFunction *BF) {
41894189
BA->foreachAttr([&](SPIRVFuncParamAttrKind Kind){
41904190
if (Kind == FunctionParameterAttributeCount)
41914191
return;
4192-
F->addAttribute(I->getArgNo() + 1, SPIRSPIRVFuncParamAttrMap::rmap(Kind));
4192+
#if LLVM_VERSION_MAJOR >= 12
4193+
Attribute::AttrKind LLVMKind = SPIRSPIRVFuncParamAttrMap::rmap(Kind);
4194+
Type *AttrTy = nullptr;
4195+
if (LLVMKind == Attribute::AttrKind::ByVal)
4196+
AttrTy = cast<PointerType>(I->getType())->getElementType();
4197+
else if (LLVMKind == Attribute::AttrKind::StructRet)
4198+
AttrTy = I->getType();
4199+
// Make sure to use a correct constructor for a typed/typeless attribute
4200+
auto A = AttrTy ? Attribute::get(*Context, LLVMKind, AttrTy)
4201+
: Attribute::get(*Context, LLVMKind);
4202+
I->addAttr(A);
4203+
#else
4204+
F->addAttribute(I->getArgNo() + 1, SPIRSPIRVFuncParamAttrMap::rmap(Kind));
4205+
#endif
41934206
});
41944207
}
41954208
BF->foreachReturnValueAttr([&](SPIRVFuncParamAttrKind Kind){

0 commit comments

Comments
 (0)