[llvm] r274446 - [PM] Some preparatory refactoring to minimize the diff of D21921
Sean Silva via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 2 12:12:56 PDT 2016
Author: silvas
Date: Sat Jul 2 14:12:56 2016
New Revision: 274446
URL: http://llvm.org/viewvc/llvm-project?rev=274446&view=rev
Log:
[PM] Some preparatory refactoring to minimize the diff of D21921
The main change here is just moving stuff to static functions.
Modified:
llvm/trunk/lib/Transforms/IPO/PruneEH.cpp
Modified: llvm/trunk/lib/Transforms/IPO/PruneEH.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PruneEH.cpp?rev=274446&r1=274445&r2=274446&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/PruneEH.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/PruneEH.cpp Sat Jul 2 14:12:56 2016
@@ -47,10 +47,10 @@ namespace {
// runOnSCC - Analyze the SCC, performing the transformation if possible.
bool runOnSCC(CallGraphSCC &SCC) override;
- bool SimplifyFunction(Function *F);
- void DeleteBasicBlock(BasicBlock *BB);
};
}
+static bool SimplifyFunction(Function *F, CallGraph &CG);
+static void DeleteBasicBlock(BasicBlock *BB, CallGraph &CG);
char PruneEH::ID = 0;
INITIALIZE_PASS_BEGIN(PruneEH, "prune-eh",
@@ -61,13 +61,8 @@ INITIALIZE_PASS_END(PruneEH, "prune-eh",
Pass *llvm::createPruneEHPass() { return new PruneEH(); }
-
-bool PruneEH::runOnSCC(CallGraphSCC &SCC) {
- if (skipSCC(SCC))
- return false;
-
+static bool runImpl(CallGraphSCC &SCC, CallGraph &CG) {
SmallPtrSet<CallGraphNode *, 8> SCCNodes;
- CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
bool MadeChange = false;
// Fill SCCNodes with the elements of the SCC. Used for quickly
@@ -79,7 +74,7 @@ bool PruneEH::runOnSCC(CallGraphSCC &SCC
// according to what we know.
for (CallGraphNode *I : SCC)
if (Function *F = I->getFunction())
- MadeChange |= SimplifyFunction(F);
+ MadeChange |= SimplifyFunction(F, CG);
// Next, check to see if any callees might throw or if there are any external
// functions in this SCC: if so, we cannot prune any functions in this SCC.
@@ -177,17 +172,25 @@ bool PruneEH::runOnSCC(CallGraphSCC &SCC
// into call instructions with a branch. This makes the exception blocks
// dead.
if (Function *F = I->getFunction())
- MadeChange |= SimplifyFunction(F);
+ MadeChange |= SimplifyFunction(F, CG);
}
return MadeChange;
}
+bool PruneEH::runOnSCC(CallGraphSCC &SCC) {
+ if (skipSCC(SCC))
+ return false;
+ CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
+ return runImpl(SCC, CG);
+}
+
+
// SimplifyFunction - Given information about callees, simplify the specified
// function if we have invokes to non-unwinding functions or code after calls to
// no-return functions.
-bool PruneEH::SimplifyFunction(Function *F) {
+static bool SimplifyFunction(Function *F, CallGraph &CG) {
bool MadeChange = false;
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator()))
@@ -197,7 +200,7 @@ bool PruneEH::SimplifyFunction(Function
// If the unwind block is now dead, nuke it.
if (pred_empty(UnwindBlock))
- DeleteBasicBlock(UnwindBlock); // Delete the new BB.
+ DeleteBasicBlock(UnwindBlock, CG); // Delete the new BB.
++NumRemoved;
MadeChange = true;
@@ -216,7 +219,7 @@ bool PruneEH::SimplifyFunction(Function
BB->getInstList().pop_back();
new UnreachableInst(BB->getContext(), &*BB);
- DeleteBasicBlock(New); // Delete the new BB.
+ DeleteBasicBlock(New, CG); // Delete the new BB.
MadeChange = true;
++NumUnreach;
break;
@@ -229,9 +232,8 @@ bool PruneEH::SimplifyFunction(Function
/// DeleteBasicBlock - remove the specified basic block from the program,
/// updating the callgraph to reflect any now-obsolete edges due to calls that
/// exist in the BB.
-void PruneEH::DeleteBasicBlock(BasicBlock *BB) {
+static void DeleteBasicBlock(BasicBlock *BB, CallGraph &CG) {
assert(pred_empty(BB) && "BB is not dead!");
- CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
Instruction *TokenInst = nullptr;
More information about the llvm-commits
mailing list