Skip to content

Commit 806fdb3

Browse files
tuStromaigcbot
authored andcommitted
Resolves seg fault for EnqueueKrenel
EnqueueKerlel functionality was dropped with OpenCL 3.0. Fix resolves segmentation fault caused by using EnqueueKernel with OpenCL 2.0
1 parent 5162e70 commit 806fdb3

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

IGC/AdaptorCommon/AddImplicitArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ bool AddImplicitArgs::hasStackCallInCG(
195195
if (const CallInst* call = dyn_cast<CallInst>(*u))
196196
{
197197
const Function* parent = call->getParent()->getParent();
198-
if (hasStackCallInCG(parent, Ctx))
198+
if (parent != F && hasStackCallInCG(parent, Ctx))
199199
return true;
200200
}
201201
}

IGC/Compiler/Optimizer/OpenCLPasses/GenericAddressResolution/LowerGPCallArg.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,23 @@ void LowerGPCallArg::updateAllUsesWithNewFunction(Function* oldFunc, Function* n
283283
// Keep track of old calls and addrspacecast to be deleted later
284284
std::vector<CallInst*> callsToDelete;
285285
std::vector<AddrSpaceCastInst*> ASCToDelete;
286+
std::vector<Use*> UsesToReplace;
286287

287288
for (auto U = oldFunc->user_begin(), E = oldFunc->user_end(); U != E; ++U)
288289
{
289290
CallInst* cInst = dyn_cast<CallInst>(*U);
290291
auto BC = dyn_cast<BitCastInst>(*U);
291292
if (BC && BC->hasOneUse())
292293
cInst = dyn_cast<CallInst>(BC->user_back());
294+
295+
if (cInst->getCalledFunction() != oldFunc)
296+
{
297+
for (Use& cArg : cInst->args())
298+
if (cArg == oldFunc)
299+
UsesToReplace.push_back(&cArg);
300+
continue;
301+
}
302+
293303
if (!cInst)
294304
{
295305
IGC_ASSERT_MESSAGE(0, "Unknown function usage");
@@ -359,4 +369,10 @@ void LowerGPCallArg::updateAllUsesWithNewFunction(Function* oldFunc, Function* n
359369
IGC_ASSERT(i->user_empty());
360370
i->eraseFromParent();
361371
}
372+
373+
// Replace call arguments
374+
for (auto i : UsesToReplace)
375+
{
376+
i->set(newFunc);
377+
}
362378
}

IGC/Compiler/Optimizer/OpenCLPasses/KernelFunctionCloning.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ bool KernelFunctionCloning::runOnModule(Module& M) {
199199
#endif
200200
if (!call)
201201
continue;
202-
call->setCalledFunction(NewF);
202+
203+
if (call->getCalledFunction()->getType() == NewF->getType())
204+
call->setCalledFunction(NewF);
203205
}
204206

205207
Changed = true;

0 commit comments

Comments
 (0)