diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -345,7 +345,6 @@ void initializeRenameIndependentSubregsPass(PassRegistry&); void initializeReplaceWithVeclibLegacyPass(PassRegistry &); void initializeResetMachineFunctionPass(PassRegistry&); -void initializeReversePostOrderFunctionAttrsLegacyPassPass(PassRegistry&); void initializeRewriteStatepointsForGCLegacyPassPass(PassRegistry &); void initializeRewriteSymbolsLegacyPassPass(PassRegistry&); void initializeSCCPLegacyPassPass(PassRegistry&); diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -168,7 +168,6 @@ (void) llvm::createAttributorLegacyPass(); (void) llvm::createAttributorCGSCCLegacyPass(); (void) llvm::createPostOrderFunctionAttrsLegacyPass(); - (void) llvm::createReversePostOrderFunctionAttrsPass(); (void) llvm::createMergeICmpsLegacyPass(); (void) llvm::createExpandLargeDivRemPass(); (void) llvm::createExpandMemCmpPass(); diff --git a/llvm/include/llvm/Transforms/IPO.h b/llvm/include/llvm/Transforms/IPO.h --- a/llvm/include/llvm/Transforms/IPO.h +++ b/llvm/include/llvm/Transforms/IPO.h @@ -116,13 +116,6 @@ /// Pass *createSingleLoopExtractorPass(); -//===----------------------------------------------------------------------===// -/// createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call -/// graph in RPO to deduce and propagate function attributes. Currently it -/// only handles synthesizing norecurse attributes. -/// -Pass *createReversePostOrderFunctionAttrsPass(); - //===----------------------------------------------------------------------===// /// createBarrierNoopPass - This pass is purely a module pass barrier in a pass /// manager. diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -1871,42 +1871,6 @@ return runImpl(SCC, LegacyAARGetter(*this)); } -namespace { - -struct ReversePostOrderFunctionAttrsLegacyPass : public ModulePass { - // Pass identification, replacement for typeid - static char ID; - - ReversePostOrderFunctionAttrsLegacyPass() : ModulePass(ID) { - initializeReversePostOrderFunctionAttrsLegacyPassPass( - *PassRegistry::getPassRegistry()); - } - - bool runOnModule(Module &M) override; - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesCFG(); - AU.addRequired(); - AU.addPreserved(); - } -}; - -} // end anonymous namespace - -char ReversePostOrderFunctionAttrsLegacyPass::ID = 0; - -INITIALIZE_PASS_BEGIN(ReversePostOrderFunctionAttrsLegacyPass, - "rpo-function-attrs", "Deduce function attributes in RPO", - false, false) -INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass) -INITIALIZE_PASS_END(ReversePostOrderFunctionAttrsLegacyPass, - "rpo-function-attrs", "Deduce function attributes in RPO", - false, false) - -Pass *llvm::createReversePostOrderFunctionAttrsPass() { - return new ReversePostOrderFunctionAttrsLegacyPass(); -} - static bool addNoRecurseAttrsTopDown(Function &F) { // We check the preconditions for the function prior to calling this to avoid // the cost of building up a reversible post-order list. We assert them here @@ -1939,7 +1903,7 @@ return true; } -static bool deduceFunctionAttributeInRPO(Module &M, CallGraph &CG) { +static bool deduceFunctionAttributeInRPO(Module &M, LazyCallGraph &CG) { // We only have a post-order SCC traversal (because SCCs are inherently // discovered in post-order), so we accumulate them in a vector and then walk // it in reverse. This is simpler than using the RPO iterator infrastructure @@ -1947,17 +1911,18 @@ // graph. We can also cheat egregiously because we're primarily interested in // synthesizing norecurse and so we can only save the singular SCCs as SCCs // with multiple functions in them will clearly be recursive. - SmallVector Worklist; - for (scc_iterator I = scc_begin(&CG); !I.isAtEnd(); ++I) { - if (I->size() != 1) - continue; - Function *F = I->front()->getFunction(); - if (F && !F->isDeclaration() && !F->doesNotRecurse() && - F->hasInternalLinkage()) - Worklist.push_back(F); + SmallVector Worklist; + CG.buildRefSCCs(); + for (LazyCallGraph::RefSCC &RC : CG.postorder_ref_sccs()) { + for (LazyCallGraph::SCC &SCC : RC) { + if (SCC.size() != 1) + continue; + Function &F = SCC.begin()->getFunction(); + if (!F.isDeclaration() && !F.doesNotRecurse() && F.hasInternalLinkage()) + Worklist.push_back(&F); + } } - bool Changed = false; for (auto *F : llvm::reverse(Worklist)) Changed |= addNoRecurseAttrsTopDown(*F); @@ -1965,23 +1930,14 @@ return Changed; } -bool ReversePostOrderFunctionAttrsLegacyPass::runOnModule(Module &M) { - if (skipModule(M)) - return false; - - auto &CG = getAnalysis().getCallGraph(); - - return deduceFunctionAttributeInRPO(M, CG); -} - PreservedAnalyses ReversePostOrderFunctionAttrsPass::run(Module &M, ModuleAnalysisManager &AM) { - auto &CG = AM.getResult(M); + auto &CG = AM.getResult(M); if (!deduceFunctionAttributeInRPO(M, CG)) return PreservedAnalyses::all(); PreservedAnalyses PA; - PA.preserve(); + PA.preserve(); return PA; } diff --git a/llvm/lib/Transforms/IPO/IPO.cpp b/llvm/lib/Transforms/IPO/IPO.cpp --- a/llvm/lib/Transforms/IPO/IPO.cpp +++ b/llvm/lib/Transforms/IPO/IPO.cpp @@ -40,7 +40,6 @@ initializeAttributorLegacyPassPass(Registry); initializeAttributorCGSCCLegacyPassPass(Registry); initializePostOrderFunctionAttrsLegacyPassPass(Registry); - initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry); initializeIPSCCPLegacyPassPass(Registry); initializeBarrierNoopPass(Registry); initializeEliminateAvailableExternallyLegacyPassPass(Registry); diff --git a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp --- a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -357,8 +357,6 @@ // and saves running remaining passes on the eliminated functions. MPM.add(createEliminateAvailableExternallyPass()); - MPM.add(createReversePostOrderFunctionAttrsPass()); - // The inliner performs some kind of dead code elimination as it goes, // but there are cases that are not really caught by it. We might // at some point consider teaching the inliner about them, but it diff --git a/llvm/test/Other/new-pm-lto-defaults.ll b/llvm/test/Other/new-pm-lto-defaults.ll --- a/llvm/test/Other/new-pm-lto-defaults.ll +++ b/llvm/test/Other/new-pm-lto-defaults.ll @@ -62,7 +62,6 @@ ; CHECK-O-NEXT: Running analysis: TypeBasedAA ; CHECK-O-NEXT: Running analysis: OuterAnalysisManagerProxy ; CHECK-O-NEXT: Running pass: ReversePostOrderFunctionAttrsPass -; CHECK-O-NEXT: Running analysis: CallGraphAnalysis ; CHECK-O-NEXT: Running pass: GlobalSplitPass ; CHECK-O-NEXT: Running pass: WholeProgramDevirtPass ; CHECK-O1-NEXT: Running pass: LowerTypeTestsPass @@ -92,6 +91,7 @@ ; CHECK-O23SZ-NEXT: Running pass: PostOrderFunctionAttrsPass on (foo) ; CHECK-O23SZ-NEXT: Running pass: RequireAnalysisPass<{{.*}}GlobalsAA ; CHECK-O23SZ-NEXT: Running analysis: GlobalsAA on [module] +; CHECK-O23SZ-NEXT: Running analysis: CallGraphAnalysis on [module] ; CHECK-O23SZ-NEXT: Running pass: InvalidateAnalysisPass<{{.*}}AAManager ; CHECK-O23SZ-NEXT: Invalidating analysis: AAManager on foo ; CHECK-O23SZ-NEXT: Running pass: OpenMPOptCGSCCPass on (foo)