Skip to content

Commit 4e3aae1

Browse files
saeubankaeubanks
authored andcommitted
[RPOFunctionAttrs] Use LazyCallGraph instead of CallGraph
There are a few more uses of CallGraph that should be replaced with LazyCallGraph Also delete legacy version of RPOFunctionAttrs since it is deprecated and LazyCallGraph is not available under the legacy pass manager. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D143358
1 parent 0776fc3 commit 4e3aae1

File tree

7 files changed

+14
-70
lines changed

7 files changed

+14
-70
lines changed

llvm/include/llvm/InitializePasses.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ void initializeRemoveRedundantDebugValuesPass(PassRegistry&);
345345
void initializeRenameIndependentSubregsPass(PassRegistry&);
346346
void initializeReplaceWithVeclibLegacyPass(PassRegistry &);
347347
void initializeResetMachineFunctionPass(PassRegistry&);
348-
void initializeReversePostOrderFunctionAttrsLegacyPassPass(PassRegistry&);
349348
void initializeRewriteStatepointsForGCLegacyPassPass(PassRegistry &);
350349
void initializeRewriteSymbolsLegacyPassPass(PassRegistry&);
351350
void initializeSCCPLegacyPassPass(PassRegistry&);

llvm/include/llvm/LinkAllPasses.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ namespace {
168168
(void) llvm::createAttributorLegacyPass();
169169
(void) llvm::createAttributorCGSCCLegacyPass();
170170
(void) llvm::createPostOrderFunctionAttrsLegacyPass();
171-
(void) llvm::createReversePostOrderFunctionAttrsPass();
172171
(void) llvm::createMergeICmpsLegacyPass();
173172
(void) llvm::createExpandLargeDivRemPass();
174173
(void) llvm::createExpandMemCmpPass();

llvm/include/llvm/Transforms/IPO.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ Pass *createLoopExtractorPass();
116116
///
117117
Pass *createSingleLoopExtractorPass();
118118

119-
//===----------------------------------------------------------------------===//
120-
/// createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call
121-
/// graph in RPO to deduce and propagate function attributes. Currently it
122-
/// only handles synthesizing norecurse attributes.
123-
///
124-
Pass *createReversePostOrderFunctionAttrsPass();
125-
126119
//===----------------------------------------------------------------------===//
127120
/// createBarrierNoopPass - This pass is purely a module pass barrier in a pass
128121
/// manager.

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,42 +1871,6 @@ bool PostOrderFunctionAttrsLegacyPass::runOnSCC(CallGraphSCC &SCC) {
18711871
return runImpl(SCC, LegacyAARGetter(*this));
18721872
}
18731873

1874-
namespace {
1875-
1876-
struct ReversePostOrderFunctionAttrsLegacyPass : public ModulePass {
1877-
// Pass identification, replacement for typeid
1878-
static char ID;
1879-
1880-
ReversePostOrderFunctionAttrsLegacyPass() : ModulePass(ID) {
1881-
initializeReversePostOrderFunctionAttrsLegacyPassPass(
1882-
*PassRegistry::getPassRegistry());
1883-
}
1884-
1885-
bool runOnModule(Module &M) override;
1886-
1887-
void getAnalysisUsage(AnalysisUsage &AU) const override {
1888-
AU.setPreservesCFG();
1889-
AU.addRequired<CallGraphWrapperPass>();
1890-
AU.addPreserved<CallGraphWrapperPass>();
1891-
}
1892-
};
1893-
1894-
} // end anonymous namespace
1895-
1896-
char ReversePostOrderFunctionAttrsLegacyPass::ID = 0;
1897-
1898-
INITIALIZE_PASS_BEGIN(ReversePostOrderFunctionAttrsLegacyPass,
1899-
"rpo-function-attrs", "Deduce function attributes in RPO",
1900-
false, false)
1901-
INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
1902-
INITIALIZE_PASS_END(ReversePostOrderFunctionAttrsLegacyPass,
1903-
"rpo-function-attrs", "Deduce function attributes in RPO",
1904-
false, false)
1905-
1906-
Pass *llvm::createReversePostOrderFunctionAttrsPass() {
1907-
return new ReversePostOrderFunctionAttrsLegacyPass();
1908-
}
1909-
19101874
static bool addNoRecurseAttrsTopDown(Function &F) {
19111875
// We check the preconditions for the function prior to calling this to avoid
19121876
// the cost of building up a reversible post-order list. We assert them here
@@ -1939,49 +1903,41 @@ static bool addNoRecurseAttrsTopDown(Function &F) {
19391903
return true;
19401904
}
19411905

1942-
static bool deduceFunctionAttributeInRPO(Module &M, CallGraph &CG) {
1906+
static bool deduceFunctionAttributeInRPO(Module &M, LazyCallGraph &CG) {
19431907
// We only have a post-order SCC traversal (because SCCs are inherently
19441908
// discovered in post-order), so we accumulate them in a vector and then walk
19451909
// it in reverse. This is simpler than using the RPO iterator infrastructure
19461910
// because we need to combine SCC detection and the PO walk of the call
19471911
// graph. We can also cheat egregiously because we're primarily interested in
19481912
// synthesizing norecurse and so we can only save the singular SCCs as SCCs
19491913
// with multiple functions in them will clearly be recursive.
1950-
SmallVector<Function *, 16> Worklist;
1951-
for (scc_iterator<CallGraph *> I = scc_begin(&CG); !I.isAtEnd(); ++I) {
1952-
if (I->size() != 1)
1953-
continue;
19541914

1955-
Function *F = I->front()->getFunction();
1956-
if (F && !F->isDeclaration() && !F->doesNotRecurse() &&
1957-
F->hasInternalLinkage())
1958-
Worklist.push_back(F);
1915+
SmallVector<Function *, 16> Worklist;
1916+
CG.buildRefSCCs();
1917+
for (LazyCallGraph::RefSCC &RC : CG.postorder_ref_sccs()) {
1918+
for (LazyCallGraph::SCC &SCC : RC) {
1919+
if (SCC.size() != 1)
1920+
continue;
1921+
Function &F = SCC.begin()->getFunction();
1922+
if (!F.isDeclaration() && !F.doesNotRecurse() && F.hasInternalLinkage())
1923+
Worklist.push_back(&F);
1924+
}
19591925
}
1960-
19611926
bool Changed = false;
19621927
for (auto *F : llvm::reverse(Worklist))
19631928
Changed |= addNoRecurseAttrsTopDown(*F);
19641929

19651930
return Changed;
19661931
}
19671932

1968-
bool ReversePostOrderFunctionAttrsLegacyPass::runOnModule(Module &M) {
1969-
if (skipModule(M))
1970-
return false;
1971-
1972-
auto &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
1973-
1974-
return deduceFunctionAttributeInRPO(M, CG);
1975-
}
1976-
19771933
PreservedAnalyses
19781934
ReversePostOrderFunctionAttrsPass::run(Module &M, ModuleAnalysisManager &AM) {
1979-
auto &CG = AM.getResult<CallGraphAnalysis>(M);
1935+
auto &CG = AM.getResult<LazyCallGraphAnalysis>(M);
19801936

19811937
if (!deduceFunctionAttributeInRPO(M, CG))
19821938
return PreservedAnalyses::all();
19831939

19841940
PreservedAnalyses PA;
1985-
PA.preserve<CallGraphAnalysis>();
1941+
PA.preserve<LazyCallGraphAnalysis>();
19861942
return PA;
19871943
}

llvm/lib/Transforms/IPO/IPO.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ void llvm::initializeIPO(PassRegistry &Registry) {
4040
initializeAttributorLegacyPassPass(Registry);
4141
initializeAttributorCGSCCLegacyPassPass(Registry);
4242
initializePostOrderFunctionAttrsLegacyPassPass(Registry);
43-
initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry);
4443
initializeIPSCCPLegacyPassPass(Registry);
4544
initializeBarrierNoopPass(Registry);
4645
initializeEliminateAvailableExternallyLegacyPassPass(Registry);

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,6 @@ void PassManagerBuilder::populateModulePassManager(
357357
// and saves running remaining passes on the eliminated functions.
358358
MPM.add(createEliminateAvailableExternallyPass());
359359

360-
MPM.add(createReversePostOrderFunctionAttrsPass());
361-
362360
// The inliner performs some kind of dead code elimination as it goes,
363361
// but there are cases that are not really caught by it. We might
364362
// at some point consider teaching the inliner about them, but it

llvm/test/Other/new-pm-lto-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
; CHECK-O-NEXT: Running analysis: TypeBasedAA
6363
; CHECK-O-NEXT: Running analysis: OuterAnalysisManagerProxy
6464
; CHECK-O-NEXT: Running pass: ReversePostOrderFunctionAttrsPass
65-
; CHECK-O-NEXT: Running analysis: CallGraphAnalysis
6665
; CHECK-O-NEXT: Running pass: GlobalSplitPass
6766
; CHECK-O-NEXT: Running pass: WholeProgramDevirtPass
6867
; CHECK-O1-NEXT: Running pass: LowerTypeTestsPass
@@ -92,6 +91,7 @@
9291
; CHECK-O23SZ-NEXT: Running pass: PostOrderFunctionAttrsPass on (foo)
9392
; CHECK-O23SZ-NEXT: Running pass: RequireAnalysisPass<{{.*}}GlobalsAA
9493
; CHECK-O23SZ-NEXT: Running analysis: GlobalsAA on [module]
94+
; CHECK-O23SZ-NEXT: Running analysis: CallGraphAnalysis on [module]
9595
; CHECK-O23SZ-NEXT: Running pass: InvalidateAnalysisPass<{{.*}}AAManager
9696
; CHECK-O23SZ-NEXT: Invalidating analysis: AAManager on foo
9797
; CHECK-O23SZ-NEXT: Running pass: OpenMPOptCGSCCPass on (foo)

0 commit comments

Comments
 (0)