Mercurial > hg > CbC > CbC_llvm
comparison lib/CodeGen/UnreachableBlockElim.cpp @ 77:54457678186b LLVM3.6
LLVM 3.6
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Sep 2014 22:06:00 +0900 |
parents | 95c75e76d11b |
children | 60c9769439b8 |
comparison
equal
deleted
inserted
replaced
34:e874dbf0ad9d | 77:54457678186b |
---|---|
21 //===----------------------------------------------------------------------===// | 21 //===----------------------------------------------------------------------===// |
22 | 22 |
23 #include "llvm/CodeGen/Passes.h" | 23 #include "llvm/CodeGen/Passes.h" |
24 #include "llvm/ADT/DepthFirstIterator.h" | 24 #include "llvm/ADT/DepthFirstIterator.h" |
25 #include "llvm/ADT/SmallPtrSet.h" | 25 #include "llvm/ADT/SmallPtrSet.h" |
26 #include "llvm/Analysis/Dominators.h" | |
27 #include "llvm/CodeGen/MachineDominators.h" | 26 #include "llvm/CodeGen/MachineDominators.h" |
28 #include "llvm/CodeGen/MachineFunctionPass.h" | 27 #include "llvm/CodeGen/MachineFunctionPass.h" |
29 #include "llvm/CodeGen/MachineLoopInfo.h" | 28 #include "llvm/CodeGen/MachineLoopInfo.h" |
30 #include "llvm/CodeGen/MachineModuleInfo.h" | 29 #include "llvm/CodeGen/MachineModuleInfo.h" |
31 #include "llvm/CodeGen/MachineRegisterInfo.h" | 30 #include "llvm/CodeGen/MachineRegisterInfo.h" |
31 #include "llvm/IR/CFG.h" | |
32 #include "llvm/IR/Constant.h" | 32 #include "llvm/IR/Constant.h" |
33 #include "llvm/IR/Dominators.h" | |
33 #include "llvm/IR/Function.h" | 34 #include "llvm/IR/Function.h" |
34 #include "llvm/IR/Instructions.h" | 35 #include "llvm/IR/Instructions.h" |
35 #include "llvm/IR/Type.h" | 36 #include "llvm/IR/Type.h" |
36 #include "llvm/Pass.h" | 37 #include "llvm/Pass.h" |
37 #include "llvm/Support/CFG.h" | |
38 #include "llvm/Target/TargetInstrInfo.h" | 38 #include "llvm/Target/TargetInstrInfo.h" |
39 using namespace llvm; | 39 using namespace llvm; |
40 | 40 |
41 namespace { | 41 namespace { |
42 class UnreachableBlockElim : public FunctionPass { | 42 class UnreachableBlockElim : public FunctionPass { |
43 virtual bool runOnFunction(Function &F); | 43 bool runOnFunction(Function &F) override; |
44 public: | 44 public: |
45 static char ID; // Pass identification, replacement for typeid | 45 static char ID; // Pass identification, replacement for typeid |
46 UnreachableBlockElim() : FunctionPass(ID) { | 46 UnreachableBlockElim() : FunctionPass(ID) { |
47 initializeUnreachableBlockElimPass(*PassRegistry::getPassRegistry()); | 47 initializeUnreachableBlockElimPass(*PassRegistry::getPassRegistry()); |
48 } | 48 } |
49 | 49 |
50 virtual void getAnalysisUsage(AnalysisUsage &AU) const { | 50 void getAnalysisUsage(AnalysisUsage &AU) const override { |
51 AU.addPreserved<DominatorTree>(); | 51 AU.addPreserved<DominatorTreeWrapperPass>(); |
52 } | 52 } |
53 }; | 53 }; |
54 } | 54 } |
55 char UnreachableBlockElim::ID = 0; | 55 char UnreachableBlockElim::ID = 0; |
56 INITIALIZE_PASS(UnreachableBlockElim, "unreachableblockelim", | 56 INITIALIZE_PASS(UnreachableBlockElim, "unreachableblockelim", |
62 | 62 |
63 bool UnreachableBlockElim::runOnFunction(Function &F) { | 63 bool UnreachableBlockElim::runOnFunction(Function &F) { |
64 SmallPtrSet<BasicBlock*, 8> Reachable; | 64 SmallPtrSet<BasicBlock*, 8> Reachable; |
65 | 65 |
66 // Mark all reachable blocks. | 66 // Mark all reachable blocks. |
67 for (df_ext_iterator<Function*, SmallPtrSet<BasicBlock*, 8> > I = | 67 for (BasicBlock *BB : depth_first_ext(&F, Reachable)) |
68 df_ext_begin(&F, Reachable), E = df_ext_end(&F, Reachable); I != E; ++I) | 68 (void)BB/* Mark all reachable blocks */; |
69 /* Mark all reachable blocks */; | |
70 | 69 |
71 // Loop over all dead blocks, remembering them and deleting all instructions | 70 // Loop over all dead blocks, remembering them and deleting all instructions |
72 // in them. | 71 // in them. |
73 std::vector<BasicBlock*> DeadBlocks; | 72 std::vector<BasicBlock*> DeadBlocks; |
74 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) | 73 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) |
93 } | 92 } |
94 | 93 |
95 | 94 |
96 namespace { | 95 namespace { |
97 class UnreachableMachineBlockElim : public MachineFunctionPass { | 96 class UnreachableMachineBlockElim : public MachineFunctionPass { |
98 virtual bool runOnMachineFunction(MachineFunction &F); | 97 bool runOnMachineFunction(MachineFunction &F) override; |
99 virtual void getAnalysisUsage(AnalysisUsage &AU) const; | 98 void getAnalysisUsage(AnalysisUsage &AU) const override; |
100 MachineModuleInfo *MMI; | 99 MachineModuleInfo *MMI; |
101 public: | 100 public: |
102 static char ID; // Pass identification, replacement for typeid | 101 static char ID; // Pass identification, replacement for typeid |
103 UnreachableMachineBlockElim() : MachineFunctionPass(ID) {} | 102 UnreachableMachineBlockElim() : MachineFunctionPass(ID) {} |
104 }; | 103 }; |
123 MMI = getAnalysisIfAvailable<MachineModuleInfo>(); | 122 MMI = getAnalysisIfAvailable<MachineModuleInfo>(); |
124 MachineDominatorTree *MDT = getAnalysisIfAvailable<MachineDominatorTree>(); | 123 MachineDominatorTree *MDT = getAnalysisIfAvailable<MachineDominatorTree>(); |
125 MachineLoopInfo *MLI = getAnalysisIfAvailable<MachineLoopInfo>(); | 124 MachineLoopInfo *MLI = getAnalysisIfAvailable<MachineLoopInfo>(); |
126 | 125 |
127 // Mark all reachable blocks. | 126 // Mark all reachable blocks. |
128 for (df_ext_iterator<MachineFunction*, SmallPtrSet<MachineBasicBlock*, 8> > | 127 for (MachineBasicBlock *BB : depth_first_ext(&F, Reachable)) |
129 I = df_ext_begin(&F, Reachable), E = df_ext_end(&F, Reachable); | 128 (void)BB/* Mark all reachable blocks */; |
130 I != E; ++I) | |
131 /* Mark all reachable blocks */; | |
132 | 129 |
133 // Loop over all dead blocks, remembering them and deleting all instructions | 130 // Loop over all dead blocks, remembering them and deleting all instructions |
134 // in them. | 131 // in them. |
135 std::vector<MachineBasicBlock*> DeadBlocks; | 132 std::vector<MachineBasicBlock*> DeadBlocks; |
136 for (MachineFunction::iterator I = F.begin(), E = F.end(); I != E; ++I) { | 133 for (MachineFunction::iterator I = F.begin(), E = F.end(); I != E; ++I) { |