Skip to content

Commit a877a9d

Browse files
kkreczkoigcbot
authored andcommitted
Change BIImport pass get func pointer interpretation
1 parent 2a8de5a commit a877a9d

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

IGC/Compiler/Optimizer/BuiltInFuncImport.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -686,15 +686,24 @@ bool BIImport::runOnModule(Module& M)
686686
{
687687
if (CallInst* CI = dyn_cast<CallInst>(&*user))
688688
{
689-
// Get the function by name
690-
GetElementPtrInst* const funcStrV = cast<GetElementPtrInst>(CI->getArgOperand(0));
691-
IGC_ASSERT(nullptr != funcStrV);
692-
GlobalVariable* const global = cast<GlobalVariable>(funcStrV->getOperand(0));
689+
// Strip if CI->getArgOperand(0) is ConstExpr bitcast which happens when
690+
// Translating with SPIRV-LLVM-Translator >= 16
691+
// Before 16 CI->getArgOperand(0) would return GEP instruction
692+
Value* arg0 = CI->getArgOperand(0)->stripPointerCasts();
693+
GlobalVariable* global = nullptr;
694+
695+
if (auto* gepOp = dyn_cast<GEPOperator>(arg0))
696+
global = cast<GlobalVariable>(gepOp->getPointerOperand());
697+
else
698+
global = cast<GlobalVariable>(arg0);
699+
693700
IGC_ASSERT(nullptr != global);
694-
ConstantDataArray* const gArray = cast<ConstantDataArray>(global->getInitializer());
695-
IGC_ASSERT(nullptr != gArray);
696-
Function* const pFunc = GetBuiltinFunction(gArray->getAsCString(), &M);
701+
702+
auto* gArray = cast<ConstantDataArray>(global->getInitializer());
703+
auto* pFunc = GetBuiltinFunction(gArray->getAsCString(), &M);
704+
697705
IGC_ASSERT(nullptr != pFunc);
706+
698707
pFunc->addFnAttr("IFCALL_BUILTIN");
699708
pFunc->setCallingConv(llvm::CallingConv::SPIR_FUNC);
700709
// Replace builtin with the actual function pointer

0 commit comments

Comments
 (0)