comparison lib/Transforms/IPO/PruneEH.cpp @ 80:67baa08a3894

update to LLVM 3.6
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Thu, 25 Sep 2014 16:56:18 +0900
parents 54457678186b
children 60c9769439b8
comparison
equal deleted inserted replaced
76:9e74acfe8c42 80:67baa08a3894
12 // throw an exception, and marking functions 'nounwind' if they cannot throw. 12 // throw an exception, and marking functions 'nounwind' if they cannot throw.
13 // It implements this as a bottom-up traversal of the call-graph. 13 // It implements this as a bottom-up traversal of the call-graph.
14 // 14 //
15 //===----------------------------------------------------------------------===// 15 //===----------------------------------------------------------------------===//
16 16
17 #define DEBUG_TYPE "prune-eh"
18 #include "llvm/Transforms/IPO.h" 17 #include "llvm/Transforms/IPO.h"
19 #include "llvm/ADT/SmallPtrSet.h" 18 #include "llvm/ADT/SmallPtrSet.h"
20 #include "llvm/ADT/SmallVector.h" 19 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/Statistic.h" 20 #include "llvm/ADT/Statistic.h"
22 #include "llvm/Analysis/CallGraph.h" 21 #include "llvm/Analysis/CallGraph.h"
23 #include "llvm/Analysis/CallGraphSCCPass.h" 22 #include "llvm/Analysis/CallGraphSCCPass.h"
23 #include "llvm/IR/CFG.h"
24 #include "llvm/IR/Constants.h" 24 #include "llvm/IR/Constants.h"
25 #include "llvm/IR/Function.h" 25 #include "llvm/IR/Function.h"
26 #include "llvm/IR/Instructions.h" 26 #include "llvm/IR/Instructions.h"
27 #include "llvm/IR/IntrinsicInst.h" 27 #include "llvm/IR/IntrinsicInst.h"
28 #include "llvm/IR/LLVMContext.h" 28 #include "llvm/IR/LLVMContext.h"
29 #include "llvm/Support/CFG.h"
30 #include <algorithm> 29 #include <algorithm>
31 using namespace llvm; 30 using namespace llvm;
31
32 #define DEBUG_TYPE "prune-eh"
32 33
33 STATISTIC(NumRemoved, "Number of invokes removed"); 34 STATISTIC(NumRemoved, "Number of invokes removed");
34 STATISTIC(NumUnreach, "Number of noreturn calls optimized"); 35 STATISTIC(NumUnreach, "Number of noreturn calls optimized");
35 36
36 namespace { 37 namespace {
39 PruneEH() : CallGraphSCCPass(ID) { 40 PruneEH() : CallGraphSCCPass(ID) {
40 initializePruneEHPass(*PassRegistry::getPassRegistry()); 41 initializePruneEHPass(*PassRegistry::getPassRegistry());
41 } 42 }
42 43
43 // runOnSCC - Analyze the SCC, performing the transformation if possible. 44 // runOnSCC - Analyze the SCC, performing the transformation if possible.
44 bool runOnSCC(CallGraphSCC &SCC); 45 bool runOnSCC(CallGraphSCC &SCC) override;
45 46
46 bool SimplifyFunction(Function *F); 47 bool SimplifyFunction(Function *F);
47 void DeleteBasicBlock(BasicBlock *BB); 48 void DeleteBasicBlock(BasicBlock *BB);
48 }; 49 };
49 } 50 }
83 // 84 //
84 bool SCCMightUnwind = false, SCCMightReturn = false; 85 bool SCCMightUnwind = false, SCCMightReturn = false;
85 for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); 86 for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end();
86 (!SCCMightUnwind || !SCCMightReturn) && I != E; ++I) { 87 (!SCCMightUnwind || !SCCMightReturn) && I != E; ++I) {
87 Function *F = (*I)->getFunction(); 88 Function *F = (*I)->getFunction();
88 if (F == 0) { 89 if (!F) {
89 SCCMightUnwind = true; 90 SCCMightUnwind = true;
90 SCCMightReturn = true; 91 SCCMightReturn = true;
91 } else if (F->isDeclaration() || F->mayBeOverridden()) { 92 } else if (F->isDeclaration() || F->mayBeOverridden()) {
92 SCCMightUnwind |= !F->doesNotThrow(); 93 SCCMightUnwind |= !F->doesNotThrow();
93 SCCMightReturn |= !F->doesNotReturn(); 94 SCCMightReturn |= !F->doesNotReturn();