comparison lib/Transforms/IPO/PruneEH.cpp @ 83:60c9769439b8 LLVM3.7

LLVM 3.7
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Wed, 18 Feb 2015 14:55:36 +0900
parents 54457678186b
children afa8332a0e37
comparison
equal deleted inserted replaced
78:af83660cff7b 83:60c9769439b8
16 16
17 #include "llvm/Transforms/IPO.h" 17 #include "llvm/Transforms/IPO.h"
18 #include "llvm/ADT/SmallPtrSet.h" 18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/ADT/SmallVector.h" 19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/Statistic.h" 20 #include "llvm/ADT/Statistic.h"
21 #include "llvm/Support/raw_ostream.h"
21 #include "llvm/Analysis/CallGraph.h" 22 #include "llvm/Analysis/CallGraph.h"
22 #include "llvm/Analysis/CallGraphSCCPass.h" 23 #include "llvm/Analysis/CallGraphSCCPass.h"
24 #include "llvm/Analysis/LibCallSemantics.h"
23 #include "llvm/IR/CFG.h" 25 #include "llvm/IR/CFG.h"
24 #include "llvm/IR/Constants.h" 26 #include "llvm/IR/Constants.h"
25 #include "llvm/IR/Function.h" 27 #include "llvm/IR/Function.h"
26 #include "llvm/IR/Instructions.h" 28 #include "llvm/IR/Instructions.h"
27 #include "llvm/IR/IntrinsicInst.h" 29 #include "llvm/IR/IntrinsicInst.h"
173 // no-return functions. 175 // no-return functions.
174 bool PruneEH::SimplifyFunction(Function *F) { 176 bool PruneEH::SimplifyFunction(Function *F) {
175 bool MadeChange = false; 177 bool MadeChange = false;
176 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { 178 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
177 if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) 179 if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator()))
178 if (II->doesNotThrow()) { 180 if (II->doesNotThrow() && canSimplifyInvokeNoUnwind(II)) {
179 SmallVector<Value*, 8> Args(II->op_begin(), II->op_end() - 3); 181 SmallVector<Value*, 8> Args(II->op_begin(), II->op_end() - 3);
180 // Insert a call instruction before the invoke. 182 // Insert a call instruction before the invoke.
181 CallInst *Call = CallInst::Create(II->getCalledValue(), Args, "", II); 183 CallInst *Call = CallInst::Create(II->getCalledValue(), Args, "", II);
182 Call->takeName(II); 184 Call->takeName(II);
183 Call->setCallingConv(II->getCallingConv()); 185 Call->setCallingConv(II->getCallingConv());
198 200
199 // Finally, delete the invoke instruction! 201 // Finally, delete the invoke instruction!
200 BB->getInstList().pop_back(); 202 BB->getInstList().pop_back();
201 203
202 // If the unwind block is now dead, nuke it. 204 // If the unwind block is now dead, nuke it.
203 if (pred_begin(UnwindBlock) == pred_end(UnwindBlock)) 205 if (pred_empty(UnwindBlock))
204 DeleteBasicBlock(UnwindBlock); // Delete the new BB. 206 DeleteBasicBlock(UnwindBlock); // Delete the new BB.
205 207
206 ++NumRemoved; 208 ++NumRemoved;
207 MadeChange = true; 209 MadeChange = true;
208 } 210 }
232 234
233 /// DeleteBasicBlock - remove the specified basic block from the program, 235 /// DeleteBasicBlock - remove the specified basic block from the program,
234 /// updating the callgraph to reflect any now-obsolete edges due to calls that 236 /// updating the callgraph to reflect any now-obsolete edges due to calls that
235 /// exist in the BB. 237 /// exist in the BB.
236 void PruneEH::DeleteBasicBlock(BasicBlock *BB) { 238 void PruneEH::DeleteBasicBlock(BasicBlock *BB) {
237 assert(pred_begin(BB) == pred_end(BB) && "BB is not dead!"); 239 assert(pred_empty(BB) && "BB is not dead!");
238 CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph(); 240 CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
239 241
240 CallGraphNode *CGN = CG[BB->getParent()]; 242 CallGraphNode *CGN = CG[BB->getParent()];
241 for (BasicBlock::iterator I = BB->end(), E = BB->begin(); I != E; ) { 243 for (BasicBlock::iterator I = BB->end(), E = BB->begin(); I != E; ) {
242 --I; 244 --I;