Skip to content

Commit 58bc98c

Browse files
authored
[CallGraphUpdater] Remove some legacy pass manager support (#98362)
We don't have any legacy pass manager CGSCC passes that modify the call graph (we only use it in the codegen pipeline to run function passes in call graph order). This is the beginning of removing CallGraphUpdater and making all the relevant CGSCC passes directly use the new pass manager APIs.
1 parent 19a9f22 commit 58bc98c

File tree

6 files changed

+30
-264
lines changed

6 files changed

+30
-264
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,14 +1828,6 @@ struct Attributor {
18281828
Configuration.InitializationCallback(*this, F);
18291829
}
18301830

1831-
/// Helper function to remove callsite.
1832-
void removeCallSite(CallInst *CI) {
1833-
if (!CI)
1834-
return;
1835-
1836-
Configuration.CGUpdater.removeCallSite(*CI);
1837-
}
1838-
18391831
/// Record that \p U is to be replaces with \p NV after information was
18401832
/// manifested. This also triggers deletion of trivially dead istructions.
18411833
bool changeUseAfterManifest(Use &U, Value &NV) {

llvm/include/llvm/Transforms/Utils/CallGraphUpdater.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ class CallGraphUpdater {
3838
SmallVector<Function *, 16> DeadFunctionsInComdats;
3939
///}
4040

41-
/// Old PM variables
42-
///{
43-
CallGraph *CG = nullptr;
44-
CallGraphSCC *CGSCC = nullptr;
45-
///}
46-
4741
/// New PM variables
4842
///{
4943
LazyCallGraph *LCG = nullptr;
@@ -60,10 +54,6 @@ class CallGraphUpdater {
6054
/// Initializers for usage outside of a CGSCC pass, inside a CGSCC pass in
6155
/// the old and new pass manager (PM).
6256
///{
63-
void initialize(CallGraph &CG, CallGraphSCC &SCC) {
64-
this->CG = &CG;
65-
this->CGSCC = &SCC;
66-
}
6757
void initialize(LazyCallGraph &LCG, LazyCallGraph::SCC &SCC,
6858
CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR) {
6959
this->LCG = &LCG;
@@ -95,14 +85,6 @@ class CallGraphUpdater {
9585
/// Note that \p OldFn is also removed from the call graph
9686
/// (\see removeFunction).
9787
void replaceFunctionWith(Function &OldFn, Function &NewFn);
98-
99-
/// Remove the call site \p CS from the call graph.
100-
void removeCallSite(CallBase &CS);
101-
102-
/// Replace \p OldCS with the new call site \p NewCS.
103-
/// \return True if the replacement was successful, otherwise False. In the
104-
/// latter case the parent function of \p OldCB needs to be re-analyzed.
105-
bool replaceCallSite(CallBase &OldCS, CallBase &NewCS);
10688
};
10789

10890
} // end namespace llvm

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,8 +2557,6 @@ ChangeStatus Attributor::cleanupIR() {
25572557
if (auto *CB = dyn_cast<CallBase>(I)) {
25582558
assert((isa<IntrinsicInst>(CB) || isRunOn(*I->getFunction())) &&
25592559
"Cannot delete an instruction outside the current SCC!");
2560-
if (!isa<IntrinsicInst>(CB))
2561-
Configuration.CGUpdater.removeCallSite(*CB);
25622560
}
25632561
I->dropDroppableUses();
25642562
CGModifiedFunctions.insert(I->getFunction());
@@ -3186,7 +3184,6 @@ ChangeStatus Attributor::rewriteFunctionSignatures(
31863184
assert(OldCB.getType() == NewCB.getType() &&
31873185
"Cannot handle call sites with different types!");
31883186
ModifiedFns.insert(OldCB.getFunction());
3189-
Configuration.CGUpdater.replaceCallSite(OldCB, NewCB);
31903187
OldCB.replaceAllUsesWith(&NewCB);
31913188
OldCB.eraseFromParent();
31923189
}

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,6 @@ struct OpenMPOpt {
14531453
};
14541454
emitRemark<OptimizationRemark>(CI, "OMP160", Remark);
14551455

1456-
CGUpdater.removeCallSite(*CI);
14571456
CI->eraseFromParent();
14581457
Changed = true;
14591458
++NumOpenMPParallelRegionsDeleted;
@@ -1895,7 +1894,6 @@ struct OpenMPOpt {
18951894
else
18961895
emitRemark<OptimizationRemark>(&F, "OMP170", Remark);
18971896

1898-
CGUpdater.removeCallSite(*CI);
18991897
CI->replaceAllUsesWith(ReplVal);
19001898
CI->eraseFromParent();
19011899
++NumOpenMPRuntimeCallsDeduplicated;

llvm/lib/Transforms/Utils/CallGraphUpdater.cpp

Lines changed: 30 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
#include "llvm/Transforms/Utils/CallGraphUpdater.h"
16-
#include "llvm/ADT/STLExtras.h"
17-
#include "llvm/Analysis/CallGraph.h"
18-
#include "llvm/Analysis/CallGraphSCCPass.h"
1916
#include "llvm/IR/Constants.h"
2017
#include "llvm/Transforms/Utils/ModuleUtils.h"
2118

@@ -28,53 +25,33 @@ bool CallGraphUpdater::finalize() {
2825
DeadFunctionsInComdats.end());
2926
}
3027

31-
if (CG) {
32-
// First remove all references, e.g., outgoing via called functions. This is
33-
// necessary as we can delete functions that have circular references.
34-
for (Function *DeadFn : DeadFunctions) {
35-
DeadFn->removeDeadConstantUsers();
36-
CallGraphNode *DeadCGN = (*CG)[DeadFn];
37-
DeadCGN->removeAllCalledFunctions();
38-
CG->getExternalCallingNode()->removeAnyCallEdgeTo(DeadCGN);
39-
DeadFn->replaceAllUsesWith(PoisonValue::get(DeadFn->getType()));
40-
}
41-
42-
// Then remove the node and function from the module.
43-
for (Function *DeadFn : DeadFunctions) {
44-
CallGraphNode *DeadCGN = CG->getOrInsertFunction(DeadFn);
45-
assert(DeadCGN->getNumReferences() == 0 &&
46-
"References should have been handled by now");
47-
delete CG->removeFunctionFromModule(DeadCGN);
48-
}
49-
} else {
50-
// This is the code path for the new lazy call graph and for the case were
51-
// no call graph was provided.
52-
for (Function *DeadFn : DeadFunctions) {
53-
DeadFn->removeDeadConstantUsers();
54-
DeadFn->replaceAllUsesWith(PoisonValue::get(DeadFn->getType()));
55-
56-
if (LCG && !ReplacedFunctions.count(DeadFn)) {
57-
// Taken mostly from the inliner:
58-
LazyCallGraph::Node &N = LCG->get(*DeadFn);
59-
auto *DeadSCC = LCG->lookupSCC(N);
60-
assert(DeadSCC && DeadSCC->size() == 1 &&
61-
&DeadSCC->begin()->getFunction() == DeadFn);
62-
63-
FAM->clear(*DeadFn, DeadFn->getName());
64-
AM->clear(*DeadSCC, DeadSCC->getName());
65-
LCG->markDeadFunction(*DeadFn);
66-
67-
// Mark the relevant parts of the call graph as invalid so we don't
68-
// visit them.
69-
UR->InvalidatedSCCs.insert(LCG->lookupSCC(N));
70-
UR->DeadFunctions.push_back(DeadFn);
71-
} else {
72-
// The CGSCC infrastructure batch deletes functions at the end of the
73-
// call graph walk, so only erase the function if we're not using that
74-
// infrastructure.
75-
// The function is now really dead and de-attached from everything.
76-
DeadFn->eraseFromParent();
77-
}
28+
// This is the code path for the new lazy call graph and for the case were
29+
// no call graph was provided.
30+
for (Function *DeadFn : DeadFunctions) {
31+
DeadFn->removeDeadConstantUsers();
32+
DeadFn->replaceAllUsesWith(PoisonValue::get(DeadFn->getType()));
33+
34+
if (LCG && !ReplacedFunctions.count(DeadFn)) {
35+
// Taken mostly from the inliner:
36+
LazyCallGraph::Node &N = LCG->get(*DeadFn);
37+
auto *DeadSCC = LCG->lookupSCC(N);
38+
assert(DeadSCC && DeadSCC->size() == 1 &&
39+
&DeadSCC->begin()->getFunction() == DeadFn);
40+
41+
FAM->clear(*DeadFn, DeadFn->getName());
42+
AM->clear(*DeadSCC, DeadSCC->getName());
43+
LCG->markDeadFunction(*DeadFn);
44+
45+
// Mark the relevant parts of the call graph as invalid so we don't
46+
// visit them.
47+
UR->InvalidatedSCCs.insert(LCG->lookupSCC(N));
48+
UR->DeadFunctions.push_back(DeadFn);
49+
} else {
50+
// The CGSCC infrastructure batch deletes functions at the end of the
51+
// call graph walk, so only erase the function if we're not using that
52+
// infrastructure.
53+
// The function is now really dead and de-attached from everything.
54+
DeadFn->eraseFromParent();
7855
}
7956
}
8057

@@ -85,11 +62,7 @@ bool CallGraphUpdater::finalize() {
8562
}
8663

8764
void CallGraphUpdater::reanalyzeFunction(Function &Fn) {
88-
if (CG) {
89-
CallGraphNode *OldCGN = CG->getOrInsertFunction(&Fn);
90-
OldCGN->removeAllCalledFunctions();
91-
CG->populateCallGraphNode(OldCGN);
92-
} else if (LCG) {
65+
if (LCG) {
9366
LazyCallGraph::Node &N = LCG->get(Fn);
9467
LazyCallGraph::SCC *C = LCG->lookupSCC(N);
9568
updateCGAndAnalysisManagerForCGSCCPass(*LCG, *C, N, *AM, *UR, *FAM);
@@ -98,9 +71,7 @@ void CallGraphUpdater::reanalyzeFunction(Function &Fn) {
9871

9972
void CallGraphUpdater::registerOutlinedFunction(Function &OriginalFn,
10073
Function &NewFn) {
101-
if (CG)
102-
CG->addToCallGraph(&NewFn);
103-
else if (LCG)
74+
if (LCG)
10475
LCG->addSplitFunction(OriginalFn, NewFn);
10576
}
10677

@@ -112,59 +83,17 @@ void CallGraphUpdater::removeFunction(Function &DeadFn) {
11283
else
11384
DeadFunctions.push_back(&DeadFn);
11485

115-
// For the old call graph we remove the function from the SCC right away.
116-
if (CG && !ReplacedFunctions.count(&DeadFn)) {
117-
CallGraphNode *DeadCGN = (*CG)[&DeadFn];
118-
DeadCGN->removeAllCalledFunctions();
119-
CGSCC->DeleteNode(DeadCGN);
120-
}
12186
if (FAM)
12287
FAM->clear(DeadFn, DeadFn.getName());
12388
}
12489

12590
void CallGraphUpdater::replaceFunctionWith(Function &OldFn, Function &NewFn) {
12691
OldFn.removeDeadConstantUsers();
12792
ReplacedFunctions.insert(&OldFn);
128-
if (CG) {
129-
// Update the call graph for the newly promoted function.
130-
CallGraphNode *OldCGN = (*CG)[&OldFn];
131-
CallGraphNode *NewCGN = CG->getOrInsertFunction(&NewFn);
132-
NewCGN->stealCalledFunctionsFrom(OldCGN);
133-
CG->ReplaceExternalCallEdge(OldCGN, NewCGN);
134-
135-
// And update the SCC we're iterating as well.
136-
CGSCC->ReplaceNode(OldCGN, NewCGN);
137-
} else if (LCG) {
93+
if (LCG) {
13894
// Directly substitute the functions in the call graph.
13995
LazyCallGraph::Node &OldLCGN = LCG->get(OldFn);
14096
SCC->getOuterRefSCC().replaceNodeFunction(OldLCGN, NewFn);
14197
}
14298
removeFunction(OldFn);
14399
}
144-
145-
bool CallGraphUpdater::replaceCallSite(CallBase &OldCS, CallBase &NewCS) {
146-
// This is only necessary in the (old) CG.
147-
if (!CG)
148-
return true;
149-
150-
Function *Caller = OldCS.getCaller();
151-
CallGraphNode *NewCalleeNode =
152-
CG->getOrInsertFunction(NewCS.getCalledFunction());
153-
CallGraphNode *CallerNode = (*CG)[Caller];
154-
if (llvm::none_of(*CallerNode, [&OldCS](const CallGraphNode::CallRecord &CR) {
155-
return CR.first && *CR.first == &OldCS;
156-
}))
157-
return false;
158-
CallerNode->replaceCallEdge(OldCS, NewCS, NewCalleeNode);
159-
return true;
160-
}
161-
162-
void CallGraphUpdater::removeCallSite(CallBase &CS) {
163-
// This is only necessary in the (old) CG.
164-
if (!CG)
165-
return;
166-
167-
Function *Caller = CS.getCaller();
168-
CallGraphNode *CallerNode = (*CG)[Caller];
169-
CallerNode->removeCallEdgeFor(CS);
170-
}

0 commit comments

Comments
 (0)