Skip to content

Commit bdb95b5

Browse files
authored
[SYCL][Fusion] Prevent deletion of original kernel function if inlining fails (intel#12153)
In the unlikely edge case that an original kernel function cannot be inlined into the newly constructed fused kernel function, we have to ensure that a) the original kernel function is not deleted from the module, and b) is called with the correct calling convention and attributes. Signed-off-by: Julian Oppermann <julian.oppermann@codeplay.com>
1 parent b694717 commit bdb95b5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

sycl-fusion/passes/kernel-fusion/SYCLKernelFusion.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ static Expected<CallInst *> createFusionCall(
254254
// Insert call
255255
Builder.SetInsertPoint(IPs.CallInsertion);
256256
auto *Res = Builder.CreateCall(F, CallArgs);
257+
Res->setCallingConv(F->getCallingConv());
258+
Res->setAttributes(F->getAttributes());
257259
{
258260
// If we have introduced a guard, branch to barrier.
259261
auto *BrTarget = IPs.Exit;
@@ -586,11 +588,13 @@ Error SYCLKernelFusion::fuseKernel(
586588
// InlineFunction(...) will leave the program in a well-defined state
587589
// in case it fails, and calling the function is still semantically
588590
// correct, although it might hinder some optimizations across the borders
589-
// of the fused functions.
590-
FUSION_DEBUG(llvm::dbgs()
591-
<< "WARNING: Inlining of "
592-
<< InlineCall->getCalledFunction()->getName()
593-
<< " failed due to: " << InlineRes.getFailureReason());
591+
// of the fused functions. We need to prevent deletion of the called
592+
// function, though.
593+
auto *Callee = InlineCall->getCalledFunction();
594+
FUSION_DEBUG(llvm::dbgs() << "WARNING: Inlining of " << Callee->getName()
595+
<< " failed due to: "
596+
<< InlineRes.getFailureReason() << '\n');
597+
ToCleanUp.erase(Callee);
594598
}
595599
}
596600

0 commit comments

Comments
 (0)