Skip to content

Commit 6980f4d

Browse files
kkreczkoigcbot
authored andcommitted
Fix SubroutineInliner CallGraph crash.
LLVM 22 removed CallGraphNode::removeCallEdgeFor. The initial porting effort replaced it with removeOneAbstractEdgeTo, which matches edges with a null call site and would cause assertion within this function when called on real direct call. Restored original behaviour with removeCallEdgeForLegacy helper function.
1 parent 33ef151 commit 6980f4d

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

IGC/WrapperLLVM/include/llvmWrapper/Analysis/CallGraph.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,37 @@ SPDX-License-Identifier: MIT
99
#ifndef IGCLLVM_CALL_GRAPH_H
1010
#define IGCLLVM_CALL_GRAPH_H
1111

12+
#include "Probe/Assertion.h"
1213
#include "IGC/common/LLVMWarningsPush.hpp"
1314
#include "llvm/Config/llvm-config.h"
1415
#include "llvm/Analysis/CallGraph.h"
16+
#include "llvm/IR/AbstractCallSite.h"
1517
#include "IGC/common/LLVMWarningsPop.hpp"
1618

1719
namespace IGCLLVM {
18-
using CallGraphNode = llvm::CallGraphNode;
20+
// Compatibility for CallGraphNode::removeCallEdgeFor(CallBase&), removed in LLVM 22. Drops the call-graph
21+
// edge for the concrete call site CB (removeOneAbstractEdgeTo alone only matches null/abstract edges),
22+
// then drops the abstract edges for any callback functions.
23+
inline void removeCallEdgeFor(llvm::CallGraphNode *Node, llvm::CallGraph &CG, llvm::CallBase &CB) {
24+
#if LLVM_VERSION_MAJOR < 22
25+
(void)CG;
26+
Node->removeCallEdgeFor(CB);
27+
#else
28+
for (auto I = Node->begin(), E = Node->end(); I != E; ++I) {
29+
if (I->first && *I->first == &CB) {
30+
Node->removeCallEdge(I);
31+
llvm::forEachCallbackFunction(
32+
CB, [&](llvm::Function *Cb) { Node->removeOneAbstractEdgeTo(CG.getOrInsertFunction(Cb)); });
33+
return;
34+
}
35+
}
36+
IGC_ASSERT_MESSAGE(false, "Cannot find callsite to remove!");
37+
#endif
38+
}
1939

40+
using CallGraphNode = llvm::CallGraphNode;
2041
using CallRecord = llvm::CallGraphNode::CallRecord;
42+
2143
} // namespace IGCLLVM
2244

2345
#endif

IGC/WrapperLLVM/lib/llvmWrapper/Transforms/IPO/InlineHelper.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,9 @@ bool inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG, std::function<AssumptionC
400400
LLVM_DEBUG(dbgs() << " -> Deleting dead call: " << CB << "\n");
401401
// Update the call graph by deleting the edge from Callee to Caller.
402402
setInlineRemark(CB, "trivially dead");
403-
#if LLVM_VERSION_MAJOR >= 22
404-
CG[Caller]->removeOneAbstractEdgeTo(CG[Callee]);
405-
#else
406-
CG[Caller]->removeCallEdgeFor(CB);
407-
#endif
403+
404+
IGCLLVM::removeCallEdgeFor(CG[Caller], CG, CB);
405+
408406
CB.eraseFromParent();
409407
} else {
410408
// Get DebugLoc to report. CB will be invalid after Inliner.
@@ -416,11 +414,7 @@ bool inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG, std::function<AssumptionC
416414

417415
#if LLVM_VERSION_MAJOR >= 17
418416
CallGraphNode *CallerNode = CG[Caller];
419-
#if LLVM_VERSION_MAJOR >= 22
420-
CallerNode->removeOneAbstractEdgeTo(CG[Callee]);
421-
#else
422-
CallerNode->removeCallEdgeFor(CB);
423-
#endif
417+
IGCLLVM::removeCallEdgeFor(CallerNode, CG, CB);
424418
#endif
425419

426420
InlineResult IR = inlineCallIfPossible(CB, InlineInfo, InlinedArrayAllocas, InlineHistoryID, InsertLifetime,

0 commit comments

Comments
 (0)