Mercurial > hg > CbC > CbC_llvm
comparison lib/CodeGen/UnreachableBlockElim.cpp @ 95:afa8332a0e37 LLVM3.8
LLVM 3.8
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 17:48:58 +0900 |
parents | 60c9769439b8 |
children | 1172e4bd9c6f |
comparison
equal
deleted
inserted
replaced
84:f3e34b893a5f | 95:afa8332a0e37 |
---|---|
69 | 69 |
70 // Loop over all dead blocks, remembering them and deleting all instructions | 70 // Loop over all dead blocks, remembering them and deleting all instructions |
71 // in them. | 71 // in them. |
72 std::vector<BasicBlock*> DeadBlocks; | 72 std::vector<BasicBlock*> DeadBlocks; |
73 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) |
74 if (!Reachable.count(I)) { | 74 if (!Reachable.count(&*I)) { |
75 BasicBlock *BB = I; | 75 BasicBlock *BB = &*I; |
76 DeadBlocks.push_back(BB); | 76 DeadBlocks.push_back(BB); |
77 while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) { | 77 while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) { |
78 PN->replaceAllUsesWith(Constant::getNullValue(PN->getType())); | 78 PN->replaceAllUsesWith(Constant::getNullValue(PN->getType())); |
79 BB->getInstList().pop_front(); | 79 BB->getInstList().pop_front(); |
80 } | 80 } |
129 | 129 |
130 // Loop over all dead blocks, remembering them and deleting all instructions | 130 // Loop over all dead blocks, remembering them and deleting all instructions |
131 // in them. | 131 // in them. |
132 std::vector<MachineBasicBlock*> DeadBlocks; | 132 std::vector<MachineBasicBlock*> DeadBlocks; |
133 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) { |
134 MachineBasicBlock *BB = I; | 134 MachineBasicBlock *BB = &*I; |
135 | 135 |
136 // Test for deadness. | 136 // Test for deadness. |
137 if (!Reachable.count(BB)) { | 137 if (!Reachable.count(BB)) { |
138 DeadBlocks.push_back(BB); | 138 DeadBlocks.push_back(BB); |
139 | 139 |
165 for (unsigned i = 0, e = DeadBlocks.size(); i != e; ++i) | 165 for (unsigned i = 0, e = DeadBlocks.size(); i != e; ++i) |
166 DeadBlocks[i]->eraseFromParent(); | 166 DeadBlocks[i]->eraseFromParent(); |
167 | 167 |
168 // Cleanup PHI nodes. | 168 // Cleanup PHI nodes. |
169 for (MachineFunction::iterator I = F.begin(), E = F.end(); I != E; ++I) { | 169 for (MachineFunction::iterator I = F.begin(), E = F.end(); I != E; ++I) { |
170 MachineBasicBlock *BB = I; | 170 MachineBasicBlock *BB = &*I; |
171 // Prune unneeded PHI entries. | 171 // Prune unneeded PHI entries. |
172 SmallPtrSet<MachineBasicBlock*, 8> preds(BB->pred_begin(), | 172 SmallPtrSet<MachineBasicBlock*, 8> preds(BB->pred_begin(), |
173 BB->pred_end()); | 173 BB->pred_end()); |
174 MachineBasicBlock::iterator phi = BB->begin(); | 174 MachineBasicBlock::iterator phi = BB->begin(); |
175 while (phi != BB->end() && phi->isPHI()) { | 175 while (phi != BB->end() && phi->isPHI()) { |