Chris Lattner | 55d4788 | 2003-10-12 21:44:18 +0000 | [diff] [blame] | 1 | //===- LoopSimplify.cpp - Loop Canonicalization Pass ----------------------===// |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 154e4d5 | 2003-10-12 21:43:28 +0000 | [diff] [blame] | 10 | // This pass performs several transformations to transform natural loops into a |
| 11 | // simpler form, which makes subsequent analyses and transformations simpler and |
| 12 | // more effective. |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 13 | // |
| 14 | // Loop pre-header insertion guarantees that there is a single, non-critical |
| 15 | // entry edge from outside of the loop to the loop header. This simplifies a |
| 16 | // number of analyses and transformations, such as LICM. |
| 17 | // |
| 18 | // Loop exit-block insertion guarantees that all exit blocks from the loop |
| 19 | // (blocks which are outside of the loop that have predecessors inside of the |
Chris Lattner | 7710f2f | 2003-12-10 17:20:35 +0000 | [diff] [blame] | 20 | // loop) only have predecessors from inside of the loop (and are thus dominated |
| 21 | // by the loop header). This simplifies transformations such as store-sinking |
| 22 | // that are built into LICM. |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 23 | // |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 24 | // This pass also guarantees that loops will have exactly one backedge. |
| 25 | // |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 26 | // Note that the simplifycfg pass will clean up blocks which are split out but |
Chris Lattner | 154e4d5 | 2003-10-12 21:43:28 +0000 | [diff] [blame] | 27 | // end up being unnecessary, so usage of this pass should not pessimize |
| 28 | // generated code. |
| 29 | // |
| 30 | // This pass obviously modifies the CFG, but updates loop information and |
| 31 | // dominator information. |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 32 | // |
| 33 | //===----------------------------------------------------------------------===// |
| 34 | |
| 35 | #include "llvm/Transforms/Scalar.h" |
Chris Lattner | d078812 | 2004-03-14 03:59:22 +0000 | [diff] [blame] | 36 | #include "llvm/Constant.h" |
Misha Brukman | 63b38bd | 2004-07-29 17:30:56 +0000 | [diff] [blame] | 37 | #include "llvm/Instructions.h" |
Chris Lattner | d078812 | 2004-03-14 03:59:22 +0000 | [diff] [blame] | 38 | #include "llvm/Function.h" |
| 39 | #include "llvm/Type.h" |
Chris Lattner | 514e843 | 2005-03-25 06:37:22 +0000 | [diff] [blame] | 40 | #include "llvm/Analysis/AliasAnalysis.h" |
Chris Lattner | 031a3f8 | 2003-12-19 06:27:08 +0000 | [diff] [blame] | 41 | #include "llvm/Analysis/Dominators.h" |
| 42 | #include "llvm/Analysis/LoopInfo.h" |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 43 | #include "llvm/Support/CFG.h" |
Reid Spencer | 7c16caa | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 44 | #include "llvm/ADT/SetOperations.h" |
| 45 | #include "llvm/ADT/SetVector.h" |
| 46 | #include "llvm/ADT/Statistic.h" |
| 47 | #include "llvm/ADT/DepthFirstIterator.h" |
Chris Lattner | 7710f2f | 2003-12-10 17:20:35 +0000 | [diff] [blame] | 48 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 49 | |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 50 | namespace { |
Chris Lattner | 154e4d5 | 2003-10-12 21:43:28 +0000 | [diff] [blame] | 51 | Statistic<> |
Chris Lattner | 7710f2f | 2003-12-10 17:20:35 +0000 | [diff] [blame] | 52 | NumInserted("loopsimplify", "Number of pre-header or exit blocks inserted"); |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 53 | Statistic<> |
| 54 | NumNested("loopsimplify", "Number of nested loops split out"); |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 55 | |
Chris Lattner | 154e4d5 | 2003-10-12 21:43:28 +0000 | [diff] [blame] | 56 | struct LoopSimplify : public FunctionPass { |
Chris Lattner | 514e843 | 2005-03-25 06:37:22 +0000 | [diff] [blame] | 57 | // AA - If we have an alias analysis object to update, this is it, otherwise |
| 58 | // this is null. |
| 59 | AliasAnalysis *AA; |
| 60 | |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 61 | virtual bool runOnFunction(Function &F); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 62 | |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 63 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 64 | // We need loop information to identify the loops... |
| 65 | AU.addRequired<LoopInfo>(); |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 66 | AU.addRequired<DominatorSet>(); |
Chris Lattner | 797cb2f | 2004-03-13 22:01:26 +0000 | [diff] [blame] | 67 | AU.addRequired<DominatorTree>(); |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 68 | |
| 69 | AU.addPreserved<LoopInfo>(); |
| 70 | AU.addPreserved<DominatorSet>(); |
| 71 | AU.addPreserved<ImmediateDominators>(); |
| 72 | AU.addPreserved<DominatorTree>(); |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 73 | AU.addPreserved<DominanceFrontier>(); |
Chris Lattner | f83ce5f | 2005-08-10 02:07:32 +0000 | [diff] [blame^] | 74 | AU.addPreservedID(BreakCriticalEdgesID); // No critical edges added. |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 75 | } |
| 76 | private: |
| 77 | bool ProcessLoop(Loop *L); |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 78 | BasicBlock *SplitBlockPredecessors(BasicBlock *BB, const char *Suffix, |
| 79 | const std::vector<BasicBlock*> &Preds); |
Chris Lattner | 8278263 | 2004-04-18 22:27:10 +0000 | [diff] [blame] | 80 | BasicBlock *RewriteLoopExitBlock(Loop *L, BasicBlock *Exit); |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 81 | void InsertPreheaderForLoop(Loop *L); |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 82 | Loop *SeparateNestedLoop(Loop *L); |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 83 | void InsertUniqueBackedgeBlock(Loop *L); |
| 84 | |
| 85 | void UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB, |
| 86 | std::vector<BasicBlock*> &PredBlocks); |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
Chris Lattner | 154e4d5 | 2003-10-12 21:43:28 +0000 | [diff] [blame] | 89 | RegisterOpt<LoopSimplify> |
| 90 | X("loopsimplify", "Canonicalize natural loops", true); |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | // Publically exposed interface to pass... |
Chris Lattner | 7710f2f | 2003-12-10 17:20:35 +0000 | [diff] [blame] | 94 | const PassInfo *llvm::LoopSimplifyID = X.getPassInfo(); |
Chris Lattner | 3e86084 | 2004-09-20 04:43:15 +0000 | [diff] [blame] | 95 | FunctionPass *llvm::createLoopSimplifyPass() { return new LoopSimplify(); } |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 96 | |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 97 | /// runOnFunction - Run down all loops in the CFG (recursively, but we could do |
| 98 | /// it in any convenient order) inserting preheaders... |
| 99 | /// |
Chris Lattner | 154e4d5 | 2003-10-12 21:43:28 +0000 | [diff] [blame] | 100 | bool LoopSimplify::runOnFunction(Function &F) { |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 101 | bool Changed = false; |
| 102 | LoopInfo &LI = getAnalysis<LoopInfo>(); |
Chris Lattner | 514e843 | 2005-03-25 06:37:22 +0000 | [diff] [blame] | 103 | AA = getAnalysisToUpdate<AliasAnalysis>(); |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 104 | |
Chris Lattner | 59d2d7f | 2004-01-08 00:09:44 +0000 | [diff] [blame] | 105 | for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I) |
| 106 | Changed |= ProcessLoop(*I); |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 107 | |
| 108 | return Changed; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | /// ProcessLoop - Walk the loop structure in depth first order, ensuring that |
| 113 | /// all loops have preheaders. |
| 114 | /// |
Chris Lattner | 154e4d5 | 2003-10-12 21:43:28 +0000 | [diff] [blame] | 115 | bool LoopSimplify::ProcessLoop(Loop *L) { |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 116 | bool Changed = false; |
| 117 | |
Chris Lattner | d078812 | 2004-03-14 03:59:22 +0000 | [diff] [blame] | 118 | // Check to see that no blocks (other than the header) in the loop have |
| 119 | // predecessors that are not in the loop. This is not valid for natural |
| 120 | // loops, but can occur if the blocks are unreachable. Since they are |
| 121 | // unreachable we can just shamelessly destroy their terminators to make them |
| 122 | // not branch into the loop! |
| 123 | assert(L->getBlocks()[0] == L->getHeader() && |
| 124 | "Header isn't first block in loop?"); |
| 125 | for (unsigned i = 1, e = L->getBlocks().size(); i != e; ++i) { |
| 126 | BasicBlock *LoopBB = L->getBlocks()[i]; |
| 127 | Retry: |
| 128 | for (pred_iterator PI = pred_begin(LoopBB), E = pred_end(LoopBB); |
| 129 | PI != E; ++PI) |
| 130 | if (!L->contains(*PI)) { |
| 131 | // This predecessor is not in the loop. Kill its terminator! |
| 132 | BasicBlock *DeadBlock = *PI; |
| 133 | for (succ_iterator SI = succ_begin(DeadBlock), E = succ_end(DeadBlock); |
| 134 | SI != E; ++SI) |
| 135 | (*SI)->removePredecessor(DeadBlock); // Remove PHI node entries |
| 136 | |
| 137 | // Delete the dead terminator. |
Chris Lattner | 514e843 | 2005-03-25 06:37:22 +0000 | [diff] [blame] | 138 | if (AA) AA->deleteValue(&DeadBlock->back()); |
Chris Lattner | d078812 | 2004-03-14 03:59:22 +0000 | [diff] [blame] | 139 | DeadBlock->getInstList().pop_back(); |
| 140 | |
| 141 | Value *RetVal = 0; |
| 142 | if (LoopBB->getParent()->getReturnType() != Type::VoidTy) |
| 143 | RetVal = Constant::getNullValue(LoopBB->getParent()->getReturnType()); |
| 144 | new ReturnInst(RetVal, DeadBlock); |
| 145 | goto Retry; // We just invalidated the pred_iterator. Retry. |
| 146 | } |
| 147 | } |
| 148 | |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 149 | // Does the loop already have a preheader? If so, don't modify the loop... |
| 150 | if (L->getLoopPreheader() == 0) { |
| 151 | InsertPreheaderForLoop(L); |
| 152 | NumInserted++; |
| 153 | Changed = true; |
| 154 | } |
| 155 | |
Chris Lattner | 7710f2f | 2003-12-10 17:20:35 +0000 | [diff] [blame] | 156 | // Next, check to make sure that all exit nodes of the loop only have |
| 157 | // predecessors that are inside of the loop. This check guarantees that the |
| 158 | // loop preheader/header will dominate the exit blocks. If the exit block has |
| 159 | // predecessors from outside of the loop, split the edge now. |
Chris Lattner | d72c3eb | 2004-04-18 22:14:10 +0000 | [diff] [blame] | 160 | std::vector<BasicBlock*> ExitBlocks; |
| 161 | L->getExitBlocks(ExitBlocks); |
Chris Lattner | f2c018c | 2004-07-15 08:20:22 +0000 | [diff] [blame] | 162 | |
| 163 | SetVector<BasicBlock*> ExitBlockSet(ExitBlocks.begin(), ExitBlocks.end()); |
| 164 | for (SetVector<BasicBlock*>::iterator I = ExitBlockSet.begin(), |
| 165 | E = ExitBlockSet.end(); I != E; ++I) { |
| 166 | BasicBlock *ExitBlock = *I; |
Chris Lattner | daa1213 | 2004-07-15 05:36:31 +0000 | [diff] [blame] | 167 | for (pred_iterator PI = pred_begin(ExitBlock), PE = pred_end(ExitBlock); |
| 168 | PI != PE; ++PI) |
| 169 | if (!L->contains(*PI)) { |
Chris Lattner | f2c018c | 2004-07-15 08:20:22 +0000 | [diff] [blame] | 170 | RewriteLoopExitBlock(L, ExitBlock); |
Chris Lattner | daa1213 | 2004-07-15 05:36:31 +0000 | [diff] [blame] | 171 | NumInserted++; |
| 172 | Changed = true; |
| 173 | break; |
| 174 | } |
Chris Lattner | f2c018c | 2004-07-15 08:20:22 +0000 | [diff] [blame] | 175 | } |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 176 | |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 177 | // If the header has more than two predecessors at this point (from the |
| 178 | // preheader and from multiple backedges), we must adjust the loop. |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 179 | if (L->getNumBackEdges() != 1) { |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 180 | // If this is really a nested loop, rip it out into a child loop. |
| 181 | if (Loop *NL = SeparateNestedLoop(L)) { |
| 182 | ++NumNested; |
| 183 | // This is a big restructuring change, reprocess the whole loop. |
| 184 | ProcessLoop(NL); |
| 185 | return true; |
| 186 | } |
| 187 | |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 188 | InsertUniqueBackedgeBlock(L); |
| 189 | NumInserted++; |
| 190 | Changed = true; |
| 191 | } |
| 192 | |
Chris Lattner | f83ce5f | 2005-08-10 02:07:32 +0000 | [diff] [blame^] | 193 | // Scan over the PHI nodes in the loop header. Since they now have only two |
| 194 | // incoming values (the loop is canonicalized), we may have simplified the PHI |
| 195 | // down to 'X = phi [X, Y]', which should be replaced with 'Y'. |
| 196 | PHINode *PN; |
| 197 | DominatorSet &DS = getAnalysis<DominatorSet>(); |
| 198 | for (BasicBlock::iterator I = L->getHeader()->begin(); |
| 199 | (PN = dyn_cast<PHINode>(I++)); ) |
| 200 | if (Value *V = PN->hasConstantValue(true)) |
| 201 | if (!isa<Instruction>(V) || |
| 202 | DS.dominates(cast<Instruction>(V)->getParent(), L->getHeader())) { |
| 203 | PN->replaceAllUsesWith(V); |
| 204 | PN->eraseFromParent(); |
| 205 | } |
| 206 | |
Chris Lattner | 59d2d7f | 2004-01-08 00:09:44 +0000 | [diff] [blame] | 207 | for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I) |
| 208 | Changed |= ProcessLoop(*I); |
Chris Lattner | f83ce5f | 2005-08-10 02:07:32 +0000 | [diff] [blame^] | 209 | |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 210 | return Changed; |
| 211 | } |
| 212 | |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 213 | /// SplitBlockPredecessors - Split the specified block into two blocks. We want |
| 214 | /// to move the predecessors specified in the Preds list to point to the new |
| 215 | /// block, leaving the remaining predecessors pointing to BB. This method |
| 216 | /// updates the SSA PHINode's, but no other analyses. |
| 217 | /// |
Chris Lattner | 154e4d5 | 2003-10-12 21:43:28 +0000 | [diff] [blame] | 218 | BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB, |
| 219 | const char *Suffix, |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 220 | const std::vector<BasicBlock*> &Preds) { |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 221 | |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 222 | // Create new basic block, insert right before the original block... |
Chris Lattner | 8d414ad | 2004-02-04 03:58:28 +0000 | [diff] [blame] | 223 | BasicBlock *NewBB = new BasicBlock(BB->getName()+Suffix, BB->getParent(), BB); |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 224 | |
| 225 | // The preheader first gets an unconditional branch to the loop header... |
Chris Lattner | a296000 | 2003-11-21 16:52:05 +0000 | [diff] [blame] | 226 | BranchInst *BI = new BranchInst(BB, NewBB); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 227 | |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 228 | // For every PHI node in the block, insert a PHI node into NewBB where the |
| 229 | // incoming values from the out of loop edges are moved to NewBB. We have two |
| 230 | // possible cases here. If the loop is dead, we just insert dummy entries |
| 231 | // into the PHI nodes for the new edge. If the loop is not dead, we move the |
| 232 | // incoming edges in BB into new PHI nodes in NewBB. |
| 233 | // |
| 234 | if (!Preds.empty()) { // Is the loop not obviously dead? |
Chris Lattner | 031a3f8 | 2003-12-19 06:27:08 +0000 | [diff] [blame] | 235 | // Check to see if the values being merged into the new block need PHI |
| 236 | // nodes. If so, insert them. |
Alkis Evlogimenos | 3ce42ec | 2004-09-28 02:40:37 +0000 | [diff] [blame] | 237 | for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ) { |
| 238 | PHINode *PN = cast<PHINode>(I); |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 239 | ++I; |
| 240 | |
Chris Lattner | 031a3f8 | 2003-12-19 06:27:08 +0000 | [diff] [blame] | 241 | // Check to see if all of the values coming in are the same. If so, we |
| 242 | // don't need to create a new PHI node. |
| 243 | Value *InVal = PN->getIncomingValueForBlock(Preds[0]); |
| 244 | for (unsigned i = 1, e = Preds.size(); i != e; ++i) |
| 245 | if (InVal != PN->getIncomingValueForBlock(Preds[i])) { |
| 246 | InVal = 0; |
| 247 | break; |
| 248 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 249 | |
Chris Lattner | 031a3f8 | 2003-12-19 06:27:08 +0000 | [diff] [blame] | 250 | // If the values coming into the block are not the same, we need a PHI. |
| 251 | if (InVal == 0) { |
Chris Lattner | 6c237bc | 2003-12-09 23:12:55 +0000 | [diff] [blame] | 252 | // Create the new PHI node, insert it into NewBB at the end of the block |
| 253 | PHINode *NewPHI = new PHINode(PN->getType(), PN->getName()+".ph", BI); |
Chris Lattner | 514e843 | 2005-03-25 06:37:22 +0000 | [diff] [blame] | 254 | if (AA) AA->copyValue(PN, NewPHI); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 255 | |
Chris Lattner | 6c237bc | 2003-12-09 23:12:55 +0000 | [diff] [blame] | 256 | // Move all of the edges from blocks outside the loop to the new PHI |
| 257 | for (unsigned i = 0, e = Preds.size(); i != e; ++i) { |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 258 | Value *V = PN->removeIncomingValue(Preds[i], false); |
Chris Lattner | 6c237bc | 2003-12-09 23:12:55 +0000 | [diff] [blame] | 259 | NewPHI->addIncoming(V, Preds[i]); |
| 260 | } |
Chris Lattner | 031a3f8 | 2003-12-19 06:27:08 +0000 | [diff] [blame] | 261 | InVal = NewPHI; |
| 262 | } else { |
| 263 | // Remove all of the edges coming into the PHI nodes from outside of the |
| 264 | // block. |
| 265 | for (unsigned i = 0, e = Preds.size(); i != e; ++i) |
| 266 | PN->removeIncomingValue(Preds[i], false); |
Chris Lattner | 6c237bc | 2003-12-09 23:12:55 +0000 | [diff] [blame] | 267 | } |
Chris Lattner | 031a3f8 | 2003-12-19 06:27:08 +0000 | [diff] [blame] | 268 | |
| 269 | // Add an incoming value to the PHI node in the loop for the preheader |
| 270 | // edge. |
| 271 | PN->addIncoming(InVal, NewBB); |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 272 | |
| 273 | // Can we eliminate this phi node now? |
Chris Lattner | 257efb2 | 2005-08-05 00:57:45 +0000 | [diff] [blame] | 274 | if (Value *V = PN->hasConstantValue(true)) { |
Chris Lattner | e29d634 | 2004-10-17 21:22:38 +0000 | [diff] [blame] | 275 | if (!isa<Instruction>(V) || |
| 276 | getAnalysis<DominatorSet>().dominates(cast<Instruction>(V), PN)) { |
| 277 | PN->replaceAllUsesWith(V); |
Chris Lattner | 514e843 | 2005-03-25 06:37:22 +0000 | [diff] [blame] | 278 | if (AA) AA->deleteValue(PN); |
Chris Lattner | e29d634 | 2004-10-17 21:22:38 +0000 | [diff] [blame] | 279 | BB->getInstList().erase(PN); |
| 280 | } |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 281 | } |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 282 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 283 | |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 284 | // Now that the PHI nodes are updated, actually move the edges from |
| 285 | // Preds to point to NewBB instead of BB. |
| 286 | // |
| 287 | for (unsigned i = 0, e = Preds.size(); i != e; ++i) { |
| 288 | TerminatorInst *TI = Preds[i]->getTerminator(); |
| 289 | for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) |
| 290 | if (TI->getSuccessor(s) == BB) |
| 291 | TI->setSuccessor(s, NewBB); |
| 292 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 293 | |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 294 | } else { // Otherwise the loop is dead... |
Alkis Evlogimenos | 3ce42ec | 2004-09-28 02:40:37 +0000 | [diff] [blame] | 295 | for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I) { |
| 296 | PHINode *PN = cast<PHINode>(I); |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 297 | // Insert dummy values as the incoming value... |
| 298 | PN->addIncoming(Constant::getNullValue(PN->getType()), NewBB); |
Alkis Evlogimenos | 3ce42ec | 2004-09-28 02:40:37 +0000 | [diff] [blame] | 299 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 300 | } |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 301 | return NewBB; |
| 302 | } |
| 303 | |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 304 | /// InsertPreheaderForLoop - Once we discover that a loop doesn't have a |
| 305 | /// preheader, this method is called to insert one. This method has two phases: |
| 306 | /// preheader insertion and analysis updating. |
| 307 | /// |
Chris Lattner | 154e4d5 | 2003-10-12 21:43:28 +0000 | [diff] [blame] | 308 | void LoopSimplify::InsertPreheaderForLoop(Loop *L) { |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 309 | BasicBlock *Header = L->getHeader(); |
| 310 | |
| 311 | // Compute the set of predecessors of the loop that are not in the loop. |
| 312 | std::vector<BasicBlock*> OutsideBlocks; |
| 313 | for (pred_iterator PI = pred_begin(Header), PE = pred_end(Header); |
| 314 | PI != PE; ++PI) |
| 315 | if (!L->contains(*PI)) // Coming in from outside the loop? |
| 316 | OutsideBlocks.push_back(*PI); // Keep track of it... |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 317 | |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 318 | // Split out the loop pre-header |
| 319 | BasicBlock *NewBB = |
| 320 | SplitBlockPredecessors(Header, ".preheader", OutsideBlocks); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 321 | |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 322 | //===--------------------------------------------------------------------===// |
Misha Brukman | 8b2bd4e | 2003-10-10 17:57:28 +0000 | [diff] [blame] | 323 | // Update analysis results now that we have performed the transformation |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 324 | // |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 325 | |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 326 | // We know that we have loop information to update... update it now. |
| 327 | if (Loop *Parent = L->getParentLoop()) |
| 328 | Parent->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>()); |
Chris Lattner | f2d9f94 | 2003-02-27 22:48:57 +0000 | [diff] [blame] | 329 | |
| 330 | // If the header for the loop used to be an exit node for another loop, then |
| 331 | // we need to update this to know that the loop-preheader is now the exit |
| 332 | // node. Note that the only loop that could have our header as an exit node |
Chris Lattner | 0895025 | 2003-05-12 22:04:34 +0000 | [diff] [blame] | 333 | // is a sibling loop, ie, one with the same parent loop, or one if it's |
| 334 | // children. |
| 335 | // |
Chris Lattner | 59d2d7f | 2004-01-08 00:09:44 +0000 | [diff] [blame] | 336 | LoopInfo::iterator ParentLoops, ParentLoopsE; |
| 337 | if (Loop *Parent = L->getParentLoop()) { |
| 338 | ParentLoops = Parent->begin(); |
| 339 | ParentLoopsE = Parent->end(); |
| 340 | } else { // Must check top-level loops... |
| 341 | ParentLoops = getAnalysis<LoopInfo>().begin(); |
| 342 | ParentLoopsE = getAnalysis<LoopInfo>().end(); |
| 343 | } |
Chris Lattner | f2d9f94 | 2003-02-27 22:48:57 +0000 | [diff] [blame] | 344 | |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 345 | DominatorSet &DS = getAnalysis<DominatorSet>(); // Update dominator info |
Chris Lattner | 797cb2f | 2004-03-13 22:01:26 +0000 | [diff] [blame] | 346 | DominatorTree &DT = getAnalysis<DominatorTree>(); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 347 | |
Chris Lattner | db5b8f4 | 2004-03-16 06:00:15 +0000 | [diff] [blame] | 348 | |
| 349 | // Update the dominator tree information. |
| 350 | // The immediate dominator of the preheader is the immediate dominator of |
| 351 | // the old header. |
| 352 | DominatorTree::Node *PHDomTreeNode = |
| 353 | DT.createNewNode(NewBB, DT.getNode(Header)->getIDom()); |
| 354 | |
| 355 | // Change the header node so that PNHode is the new immediate dominator |
| 356 | DT.changeImmediateDominator(DT.getNode(Header), PHDomTreeNode); |
Chris Lattner | 797cb2f | 2004-03-13 22:01:26 +0000 | [diff] [blame] | 357 | |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 358 | { |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 359 | // The blocks that dominate NewBB are the blocks that dominate Header, |
| 360 | // minus Header, plus NewBB. |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 361 | DominatorSet::DomSetType DomSet = DS.getDominators(Header); |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 362 | DomSet.erase(Header); // Header does not dominate us... |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 363 | DS.addBasicBlock(NewBB, DomSet); |
Chris Lattner | 03a9e15 | 2002-09-29 21:41:38 +0000 | [diff] [blame] | 364 | |
| 365 | // The newly created basic block dominates all nodes dominated by Header. |
Chris Lattner | db5b8f4 | 2004-03-16 06:00:15 +0000 | [diff] [blame] | 366 | for (df_iterator<DominatorTree::Node*> DFI = df_begin(PHDomTreeNode), |
| 367 | E = df_end(PHDomTreeNode); DFI != E; ++DFI) |
| 368 | DS.addDominator((*DFI)->getBlock(), NewBB); |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 369 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 370 | |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 371 | // Update immediate dominator information if we have it... |
| 372 | if (ImmediateDominators *ID = getAnalysisToUpdate<ImmediateDominators>()) { |
| 373 | // Whatever i-dominated the header node now immediately dominates NewBB |
| 374 | ID->addNewBlock(NewBB, ID->get(Header)); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 375 | |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 376 | // The preheader now is the immediate dominator for the header node... |
| 377 | ID->setImmediateDominator(Header, NewBB); |
| 378 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 379 | |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 380 | // Update dominance frontier information... |
| 381 | if (DominanceFrontier *DF = getAnalysisToUpdate<DominanceFrontier>()) { |
| 382 | // The DF(NewBB) is just (DF(Header)-Header), because NewBB dominates |
| 383 | // everything that Header does, and it strictly dominates Header in |
| 384 | // addition. |
| 385 | assert(DF->find(Header) != DF->end() && "Header node doesn't have DF set?"); |
| 386 | DominanceFrontier::DomSetType NewDFSet = DF->find(Header)->second; |
| 387 | NewDFSet.erase(Header); |
| 388 | DF->addBasicBlock(NewBB, NewDFSet); |
| 389 | |
| 390 | // Now we must loop over all of the dominance frontiers in the function, |
Misha Brukman | 4ace48e | 2003-09-09 21:54:45 +0000 | [diff] [blame] | 391 | // replacing occurrences of Header with NewBB in some cases. If a block |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 392 | // dominates a (now) predecessor of NewBB, but did not strictly dominate |
| 393 | // Header, it will have Header in it's DF set, but should now have NewBB in |
| 394 | // its set. |
| 395 | for (unsigned i = 0, e = OutsideBlocks.size(); i != e; ++i) { |
| 396 | // Get all of the dominators of the predecessor... |
| 397 | const DominatorSet::DomSetType &PredDoms = |
| 398 | DS.getDominators(OutsideBlocks[i]); |
| 399 | for (DominatorSet::DomSetType::const_iterator PDI = PredDoms.begin(), |
| 400 | PDE = PredDoms.end(); PDI != PDE; ++PDI) { |
| 401 | BasicBlock *PredDom = *PDI; |
| 402 | // If the loop header is in DF(PredDom), then PredDom didn't dominate |
| 403 | // the header but did dominate a predecessor outside of the loop. Now |
| 404 | // we change this entry to include the preheader in the DF instead of |
| 405 | // the header. |
| 406 | DominanceFrontier::iterator DFI = DF->find(PredDom); |
| 407 | assert(DFI != DF->end() && "No dominance frontier for node?"); |
| 408 | if (DFI->second.count(Header)) { |
| 409 | DF->removeFromFrontier(DFI, Header); |
| 410 | DF->addToFrontier(DFI, NewBB); |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 417 | /// RewriteLoopExitBlock - Ensure that the loop preheader dominates all exit |
| 418 | /// blocks. This method is used to split exit blocks that have predecessors |
| 419 | /// outside of the loop. |
Chris Lattner | 8278263 | 2004-04-18 22:27:10 +0000 | [diff] [blame] | 420 | BasicBlock *LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) { |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 421 | DominatorSet &DS = getAnalysis<DominatorSet>(); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 422 | |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 423 | std::vector<BasicBlock*> LoopBlocks; |
| 424 | for (pred_iterator I = pred_begin(Exit), E = pred_end(Exit); I != E; ++I) |
| 425 | if (L->contains(*I)) |
| 426 | LoopBlocks.push_back(*I); |
| 427 | |
Chris Lattner | 10b2b05 | 2003-02-27 22:31:07 +0000 | [diff] [blame] | 428 | assert(!LoopBlocks.empty() && "No edges coming in from outside the loop?"); |
| 429 | BasicBlock *NewBB = SplitBlockPredecessors(Exit, ".loopexit", LoopBlocks); |
| 430 | |
Chris Lattner | 4e2fbfb | 2003-02-27 21:50:19 +0000 | [diff] [blame] | 431 | // Update Loop Information - we know that the new block will be in the parent |
| 432 | // loop of L. |
| 433 | if (Loop *Parent = L->getParentLoop()) |
| 434 | Parent->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>()); |
Chris Lattner | 32a39c2 | 2003-02-28 03:07:54 +0000 | [diff] [blame] | 435 | |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 436 | // Update dominator information (set, immdom, domtree, and domfrontier) |
| 437 | UpdateDomInfoForRevectoredPreds(NewBB, LoopBlocks); |
Chris Lattner | 8278263 | 2004-04-18 22:27:10 +0000 | [diff] [blame] | 438 | return NewBB; |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 441 | /// AddBlockAndPredsToSet - Add the specified block, and all of its |
| 442 | /// predecessors, to the specified set, if it's not already in there. Stop |
| 443 | /// predecessor traversal when we reach StopBlock. |
| 444 | static void AddBlockAndPredsToSet(BasicBlock *BB, BasicBlock *StopBlock, |
| 445 | std::set<BasicBlock*> &Blocks) { |
| 446 | if (!Blocks.insert(BB).second) return; // already processed. |
| 447 | if (BB == StopBlock) return; // Stop here! |
| 448 | |
| 449 | for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) |
| 450 | AddBlockAndPredsToSet(*I, StopBlock, Blocks); |
| 451 | } |
| 452 | |
Chris Lattner | a6e2281 | 2004-04-13 15:21:18 +0000 | [diff] [blame] | 453 | /// FindPHIToPartitionLoops - The first part of loop-nestification is to find a |
| 454 | /// PHI node that tells us how to partition the loops. |
Chris Lattner | 514e843 | 2005-03-25 06:37:22 +0000 | [diff] [blame] | 455 | static PHINode *FindPHIToPartitionLoops(Loop *L, DominatorSet &DS, |
| 456 | AliasAnalysis *AA) { |
Alkis Evlogimenos | 3ce42ec | 2004-09-28 02:40:37 +0000 | [diff] [blame] | 457 | for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ) { |
| 458 | PHINode *PN = cast<PHINode>(I); |
Chris Lattner | a6e2281 | 2004-04-13 15:21:18 +0000 | [diff] [blame] | 459 | ++I; |
Nate Begeman | b392321 | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 460 | if (Value *V = PN->hasConstantValue()) |
Chris Lattner | e29d634 | 2004-10-17 21:22:38 +0000 | [diff] [blame] | 461 | if (!isa<Instruction>(V) || DS.dominates(cast<Instruction>(V), PN)) { |
| 462 | // This is a degenerate PHI already, don't modify it! |
| 463 | PN->replaceAllUsesWith(V); |
Chris Lattner | 514e843 | 2005-03-25 06:37:22 +0000 | [diff] [blame] | 464 | if (AA) AA->deleteValue(PN); |
Chris Lattner | dd3ec92 | 2005-03-06 21:35:38 +0000 | [diff] [blame] | 465 | PN->eraseFromParent(); |
Chris Lattner | e29d634 | 2004-10-17 21:22:38 +0000 | [diff] [blame] | 466 | continue; |
| 467 | } |
| 468 | |
| 469 | // Scan this PHI node looking for a use of the PHI node by itself. |
| 470 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) |
| 471 | if (PN->getIncomingValue(i) == PN && |
| 472 | L->contains(PN->getIncomingBlock(i))) |
| 473 | // We found something tasty to remove. |
| 474 | return PN; |
Chris Lattner | a6e2281 | 2004-04-13 15:21:18 +0000 | [diff] [blame] | 475 | } |
| 476 | return 0; |
| 477 | } |
| 478 | |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 479 | /// SeparateNestedLoop - If this loop has multiple backedges, try to pull one of |
| 480 | /// them out into a nested loop. This is important for code that looks like |
| 481 | /// this: |
| 482 | /// |
| 483 | /// Loop: |
| 484 | /// ... |
| 485 | /// br cond, Loop, Next |
| 486 | /// ... |
| 487 | /// br cond2, Loop, Out |
| 488 | /// |
| 489 | /// To identify this common case, we look at the PHI nodes in the header of the |
| 490 | /// loop. PHI nodes with unchanging values on one backedge correspond to values |
| 491 | /// that change in the "outer" loop, but not in the "inner" loop. |
| 492 | /// |
| 493 | /// If we are able to separate out a loop, return the new outer loop that was |
| 494 | /// created. |
| 495 | /// |
| 496 | Loop *LoopSimplify::SeparateNestedLoop(Loop *L) { |
Chris Lattner | 514e843 | 2005-03-25 06:37:22 +0000 | [diff] [blame] | 497 | PHINode *PN = FindPHIToPartitionLoops(L, getAnalysis<DominatorSet>(), AA); |
Chris Lattner | a6e2281 | 2004-04-13 15:21:18 +0000 | [diff] [blame] | 498 | if (PN == 0) return 0; // No known way to partition. |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 499 | |
Chris Lattner | a6e2281 | 2004-04-13 15:21:18 +0000 | [diff] [blame] | 500 | // Pull out all predecessors that have varying values in the loop. This |
| 501 | // handles the case when a PHI node has multiple instances of itself as |
| 502 | // arguments. |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 503 | std::vector<BasicBlock*> OuterLoopPreds; |
Chris Lattner | a6e2281 | 2004-04-13 15:21:18 +0000 | [diff] [blame] | 504 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) |
| 505 | if (PN->getIncomingValue(i) != PN || |
| 506 | !L->contains(PN->getIncomingBlock(i))) |
| 507 | OuterLoopPreds.push_back(PN->getIncomingBlock(i)); |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 508 | |
Chris Lattner | 89e959b | 2004-04-13 16:23:25 +0000 | [diff] [blame] | 509 | BasicBlock *Header = L->getHeader(); |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 510 | BasicBlock *NewBB = SplitBlockPredecessors(Header, ".outer", OuterLoopPreds); |
| 511 | |
| 512 | // Update dominator information (set, immdom, domtree, and domfrontier) |
| 513 | UpdateDomInfoForRevectoredPreds(NewBB, OuterLoopPreds); |
| 514 | |
| 515 | // Create the new outer loop. |
| 516 | Loop *NewOuter = new Loop(); |
| 517 | |
| 518 | LoopInfo &LI = getAnalysis<LoopInfo>(); |
| 519 | |
| 520 | // Change the parent loop to use the outer loop as its child now. |
| 521 | if (Loop *Parent = L->getParentLoop()) |
| 522 | Parent->replaceChildLoopWith(L, NewOuter); |
| 523 | else |
| 524 | LI.changeTopLevelLoop(L, NewOuter); |
| 525 | |
| 526 | // This block is going to be our new header block: add it to this loop and all |
| 527 | // parent loops. |
| 528 | NewOuter->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>()); |
| 529 | |
| 530 | // L is now a subloop of our outer loop. |
| 531 | NewOuter->addChildLoop(L); |
| 532 | |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 533 | for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i) |
| 534 | NewOuter->addBlockEntry(L->getBlocks()[i]); |
| 535 | |
| 536 | // Determine which blocks should stay in L and which should be moved out to |
| 537 | // the Outer loop now. |
| 538 | DominatorSet &DS = getAnalysis<DominatorSet>(); |
| 539 | std::set<BasicBlock*> BlocksInL; |
| 540 | for (pred_iterator PI = pred_begin(Header), E = pred_end(Header); PI!=E; ++PI) |
| 541 | if (DS.dominates(Header, *PI)) |
| 542 | AddBlockAndPredsToSet(*PI, Header, BlocksInL); |
| 543 | |
| 544 | |
| 545 | // Scan all of the loop children of L, moving them to OuterLoop if they are |
| 546 | // not part of the inner loop. |
| 547 | for (Loop::iterator I = L->begin(); I != L->end(); ) |
| 548 | if (BlocksInL.count((*I)->getHeader())) |
| 549 | ++I; // Loop remains in L |
| 550 | else |
| 551 | NewOuter->addChildLoop(L->removeChildLoop(I)); |
| 552 | |
| 553 | // Now that we know which blocks are in L and which need to be moved to |
| 554 | // OuterLoop, move any blocks that need it. |
| 555 | for (unsigned i = 0; i != L->getBlocks().size(); ++i) { |
| 556 | BasicBlock *BB = L->getBlocks()[i]; |
| 557 | if (!BlocksInL.count(BB)) { |
| 558 | // Move this block to the parent, updating the exit blocks sets |
| 559 | L->removeBlockFromLoop(BB); |
| 560 | if (LI[BB] == L) |
| 561 | LI.changeLoopFor(BB, NewOuter); |
| 562 | --i; |
| 563 | } |
| 564 | } |
| 565 | |
Chris Lattner | 8417052 | 2004-04-13 05:05:33 +0000 | [diff] [blame] | 566 | return NewOuter; |
| 567 | } |
| 568 | |
| 569 | |
| 570 | |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 571 | /// InsertUniqueBackedgeBlock - This method is called when the specified loop |
| 572 | /// has more than one backedge in it. If this occurs, revector all of these |
| 573 | /// backedges to target a new basic block and have that block branch to the loop |
| 574 | /// header. This ensures that loops have exactly one backedge. |
| 575 | /// |
| 576 | void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) { |
| 577 | assert(L->getNumBackEdges() > 1 && "Must have > 1 backedge!"); |
| 578 | |
| 579 | // Get information about the loop |
| 580 | BasicBlock *Preheader = L->getLoopPreheader(); |
| 581 | BasicBlock *Header = L->getHeader(); |
| 582 | Function *F = Header->getParent(); |
| 583 | |
| 584 | // Figure out which basic blocks contain back-edges to the loop header. |
| 585 | std::vector<BasicBlock*> BackedgeBlocks; |
| 586 | for (pred_iterator I = pred_begin(Header), E = pred_end(Header); I != E; ++I) |
| 587 | if (*I != Preheader) BackedgeBlocks.push_back(*I); |
| 588 | |
| 589 | // Create and insert the new backedge block... |
| 590 | BasicBlock *BEBlock = new BasicBlock(Header->getName()+".backedge", F); |
Chris Lattner | a296000 | 2003-11-21 16:52:05 +0000 | [diff] [blame] | 591 | BranchInst *BETerminator = new BranchInst(Header, BEBlock); |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 592 | |
| 593 | // Move the new backedge block to right after the last backedge block. |
| 594 | Function::iterator InsertPos = BackedgeBlocks.back(); ++InsertPos; |
| 595 | F->getBasicBlockList().splice(InsertPos, F->getBasicBlockList(), BEBlock); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 596 | |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 597 | // Now that the block has been inserted into the function, create PHI nodes in |
| 598 | // the backedge block which correspond to any PHI nodes in the header block. |
Alkis Evlogimenos | 3ce42ec | 2004-09-28 02:40:37 +0000 | [diff] [blame] | 599 | for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) { |
| 600 | PHINode *PN = cast<PHINode>(I); |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 601 | PHINode *NewPN = new PHINode(PN->getType(), PN->getName()+".be", |
| 602 | BETerminator); |
Chris Lattner | d8e2018 | 2005-01-29 00:39:08 +0000 | [diff] [blame] | 603 | NewPN->reserveOperandSpace(BackedgeBlocks.size()); |
Chris Lattner | 514e843 | 2005-03-25 06:37:22 +0000 | [diff] [blame] | 604 | if (AA) AA->copyValue(PN, NewPN); |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 605 | |
| 606 | // Loop over the PHI node, moving all entries except the one for the |
| 607 | // preheader over to the new PHI node. |
| 608 | unsigned PreheaderIdx = ~0U; |
| 609 | bool HasUniqueIncomingValue = true; |
| 610 | Value *UniqueValue = 0; |
| 611 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { |
| 612 | BasicBlock *IBB = PN->getIncomingBlock(i); |
| 613 | Value *IV = PN->getIncomingValue(i); |
| 614 | if (IBB == Preheader) { |
| 615 | PreheaderIdx = i; |
| 616 | } else { |
| 617 | NewPN->addIncoming(IV, IBB); |
| 618 | if (HasUniqueIncomingValue) { |
| 619 | if (UniqueValue == 0) |
| 620 | UniqueValue = IV; |
| 621 | else if (UniqueValue != IV) |
| 622 | HasUniqueIncomingValue = false; |
| 623 | } |
| 624 | } |
| 625 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 626 | |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 627 | // Delete all of the incoming values from the old PN except the preheader's |
| 628 | assert(PreheaderIdx != ~0U && "PHI has no preheader entry??"); |
| 629 | if (PreheaderIdx != 0) { |
| 630 | PN->setIncomingValue(0, PN->getIncomingValue(PreheaderIdx)); |
| 631 | PN->setIncomingBlock(0, PN->getIncomingBlock(PreheaderIdx)); |
| 632 | } |
Chris Lattner | d8e2018 | 2005-01-29 00:39:08 +0000 | [diff] [blame] | 633 | // Nuke all entries except the zero'th. |
| 634 | for (unsigned i = 0, e = PN->getNumIncomingValues()-1; i != e; ++i) |
| 635 | PN->removeIncomingValue(e-i, false); |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 636 | |
| 637 | // Finally, add the newly constructed PHI node as the entry for the BEBlock. |
| 638 | PN->addIncoming(NewPN, BEBlock); |
| 639 | |
| 640 | // As an optimization, if all incoming values in the new PhiNode (which is a |
| 641 | // subset of the incoming values of the old PHI node) have the same value, |
| 642 | // eliminate the PHI Node. |
| 643 | if (HasUniqueIncomingValue) { |
| 644 | NewPN->replaceAllUsesWith(UniqueValue); |
Chris Lattner | 514e843 | 2005-03-25 06:37:22 +0000 | [diff] [blame] | 645 | if (AA) AA->deleteValue(NewPN); |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 646 | BEBlock->getInstList().erase(NewPN); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | // Now that all of the PHI nodes have been inserted and adjusted, modify the |
| 651 | // backedge blocks to just to the BEBlock instead of the header. |
| 652 | for (unsigned i = 0, e = BackedgeBlocks.size(); i != e; ++i) { |
| 653 | TerminatorInst *TI = BackedgeBlocks[i]->getTerminator(); |
| 654 | for (unsigned Op = 0, e = TI->getNumSuccessors(); Op != e; ++Op) |
| 655 | if (TI->getSuccessor(Op) == Header) |
| 656 | TI->setSuccessor(Op, BEBlock); |
| 657 | } |
| 658 | |
| 659 | //===--- Update all analyses which we must preserve now -----------------===// |
| 660 | |
| 661 | // Update Loop Information - we know that this block is now in the current |
| 662 | // loop and all parent loops. |
| 663 | L->addBasicBlockToLoop(BEBlock, getAnalysis<LoopInfo>()); |
| 664 | |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 665 | // Update dominator information (set, immdom, domtree, and domfrontier) |
| 666 | UpdateDomInfoForRevectoredPreds(BEBlock, BackedgeBlocks); |
| 667 | } |
| 668 | |
| 669 | /// UpdateDomInfoForRevectoredPreds - This method is used to update the four |
| 670 | /// different kinds of dominator information (dominator sets, immediate |
| 671 | /// dominators, dominator trees, and dominance frontiers) after a new block has |
| 672 | /// been added to the CFG. |
| 673 | /// |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 674 | /// This only supports the case when an existing block (known as "NewBBSucc"), |
| 675 | /// had some of its predecessors factored into a new basic block. This |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 676 | /// transformation inserts a new basic block ("NewBB"), with a single |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 677 | /// unconditional branch to NewBBSucc, and moves some predecessors of |
| 678 | /// "NewBBSucc" to now branch to NewBB. These predecessors are listed in |
| 679 | /// PredBlocks, even though they are the same as |
| 680 | /// pred_begin(NewBB)/pred_end(NewBB). |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 681 | /// |
| 682 | void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB, |
| 683 | std::vector<BasicBlock*> &PredBlocks) { |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 684 | assert(!PredBlocks.empty() && "No predblocks??"); |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 685 | assert(succ_begin(NewBB) != succ_end(NewBB) && |
| 686 | ++succ_begin(NewBB) == succ_end(NewBB) && |
| 687 | "NewBB should have a single successor!"); |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 688 | BasicBlock *NewBBSucc = *succ_begin(NewBB); |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 689 | DominatorSet &DS = getAnalysis<DominatorSet>(); |
| 690 | |
Chris Lattner | 146d0df | 2004-04-01 19:06:07 +0000 | [diff] [blame] | 691 | // Update dominator information... The blocks that dominate NewBB are the |
| 692 | // intersection of the dominators of predecessors, plus the block itself. |
| 693 | // |
| 694 | DominatorSet::DomSetType NewBBDomSet = DS.getDominators(PredBlocks[0]); |
| 695 | for (unsigned i = 1, e = PredBlocks.size(); i != e; ++i) |
| 696 | set_intersect(NewBBDomSet, DS.getDominators(PredBlocks[i])); |
| 697 | NewBBDomSet.insert(NewBB); // All blocks dominate themselves... |
| 698 | DS.addBasicBlock(NewBB, NewBBDomSet); |
| 699 | |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 700 | // The newly inserted basic block will dominate existing basic blocks iff the |
| 701 | // PredBlocks dominate all of the non-pred blocks. If all predblocks dominate |
| 702 | // the non-pred blocks, then they all must be the same block! |
Chris Lattner | 146d0df | 2004-04-01 19:06:07 +0000 | [diff] [blame] | 703 | // |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 704 | bool NewBBDominatesNewBBSucc = true; |
| 705 | { |
| 706 | BasicBlock *OnePred = PredBlocks[0]; |
| 707 | for (unsigned i = 1, e = PredBlocks.size(); i != e; ++i) |
| 708 | if (PredBlocks[i] != OnePred) { |
| 709 | NewBBDominatesNewBBSucc = false; |
| 710 | break; |
| 711 | } |
| 712 | |
| 713 | if (NewBBDominatesNewBBSucc) |
| 714 | for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc); |
| 715 | PI != E; ++PI) |
Chris Lattner | 2dd1c8d | 2004-02-05 23:20:59 +0000 | [diff] [blame] | 716 | if (*PI != NewBB && !DS.dominates(NewBBSucc, *PI)) { |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 717 | NewBBDominatesNewBBSucc = false; |
| 718 | break; |
| 719 | } |
| 720 | } |
| 721 | |
Chris Lattner | 146d0df | 2004-04-01 19:06:07 +0000 | [diff] [blame] | 722 | // The other scenario where the new block can dominate its successors are when |
| 723 | // all predecessors of NewBBSucc that are not NewBB are dominated by NewBBSucc |
| 724 | // already. |
| 725 | if (!NewBBDominatesNewBBSucc) { |
| 726 | NewBBDominatesNewBBSucc = true; |
| 727 | for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc); |
| 728 | PI != E; ++PI) |
| 729 | if (*PI != NewBB && !DS.dominates(NewBBSucc, *PI)) { |
| 730 | NewBBDominatesNewBBSucc = false; |
| 731 | break; |
| 732 | } |
| 733 | } |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 734 | |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 735 | // If NewBB dominates some blocks, then it will dominate all blocks that |
Chris Lattner | c0c953f | 2004-02-05 22:33:26 +0000 | [diff] [blame] | 736 | // NewBBSucc does. |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 737 | if (NewBBDominatesNewBBSucc) { |
| 738 | BasicBlock *PredBlock = PredBlocks[0]; |
| 739 | Function *F = NewBB->getParent(); |
| 740 | for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) |
Chris Lattner | c0c953f | 2004-02-05 22:33:26 +0000 | [diff] [blame] | 741 | if (DS.dominates(NewBBSucc, I)) |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 742 | DS.addDominator(I, NewBB); |
| 743 | } |
| 744 | |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 745 | // Update immediate dominator information if we have it... |
| 746 | BasicBlock *NewBBIDom = 0; |
| 747 | if (ImmediateDominators *ID = getAnalysisToUpdate<ImmediateDominators>()) { |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 748 | // To find the immediate dominator of the new exit node, we trace up the |
| 749 | // immediate dominators of a predecessor until we find a basic block that |
| 750 | // dominates the exit block. |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 751 | // |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 752 | BasicBlock *Dom = PredBlocks[0]; // Some random predecessor... |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 753 | while (!NewBBDomSet.count(Dom)) { // Loop until we find a dominator... |
| 754 | assert(Dom != 0 && "No shared dominator found???"); |
| 755 | Dom = ID->get(Dom); |
| 756 | } |
| 757 | |
| 758 | // Set the immediate dominator now... |
| 759 | ID->addNewBlock(NewBB, Dom); |
| 760 | NewBBIDom = Dom; // Reuse this if calculating DominatorTree info... |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 761 | |
| 762 | // If NewBB strictly dominates other blocks, we need to update their idom's |
| 763 | // now. The only block that need adjustment is the NewBBSucc block, whose |
| 764 | // idom should currently be set to PredBlocks[0]. |
Chris Lattner | 59fdf74 | 2004-04-01 19:21:46 +0000 | [diff] [blame] | 765 | if (NewBBDominatesNewBBSucc) |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 766 | ID->setImmediateDominator(NewBBSucc, NewBB); |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | // Update DominatorTree information if it is active. |
| 770 | if (DominatorTree *DT = getAnalysisToUpdate<DominatorTree>()) { |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 771 | // If we don't have ImmediateDominator info around, calculate the idom as |
| 772 | // above. |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 773 | DominatorTree::Node *NewBBIDomNode; |
| 774 | if (NewBBIDom) { |
| 775 | NewBBIDomNode = DT->getNode(NewBBIDom); |
| 776 | } else { |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 777 | NewBBIDomNode = DT->getNode(PredBlocks[0]); // Random pred |
Chris Lattner | bb9d03b | 2003-09-11 16:26:13 +0000 | [diff] [blame] | 778 | while (!NewBBDomSet.count(NewBBIDomNode->getBlock())) { |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 779 | NewBBIDomNode = NewBBIDomNode->getIDom(); |
| 780 | assert(NewBBIDomNode && "No shared dominator found??"); |
| 781 | } |
| 782 | } |
| 783 | |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 784 | // Create the new dominator tree node... and set the idom of NewBB. |
| 785 | DominatorTree::Node *NewBBNode = DT->createNewNode(NewBB, NewBBIDomNode); |
| 786 | |
| 787 | // If NewBB strictly dominates other blocks, then it is now the immediate |
| 788 | // dominator of NewBBSucc. Update the dominator tree as appropriate. |
| 789 | if (NewBBDominatesNewBBSucc) { |
| 790 | DominatorTree::Node *NewBBSuccNode = DT->getNode(NewBBSucc); |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 791 | DT->changeImmediateDominator(NewBBSuccNode, NewBBNode); |
| 792 | } |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | // Update dominance frontier information... |
| 796 | if (DominanceFrontier *DF = getAnalysisToUpdate<DominanceFrontier>()) { |
Chris Lattner | 89e959b | 2004-04-13 16:23:25 +0000 | [diff] [blame] | 797 | // If NewBB dominates NewBBSucc, then DF(NewBB) is now going to be the |
| 798 | // DF(PredBlocks[0]) without the stuff that the new block does not dominate |
| 799 | // a predecessor of. |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 800 | if (NewBBDominatesNewBBSucc) { |
| 801 | DominanceFrontier::iterator DFI = DF->find(PredBlocks[0]); |
| 802 | if (DFI != DF->end()) { |
| 803 | DominanceFrontier::DomSetType Set = DFI->second; |
| 804 | // Filter out stuff in Set that we do not dominate a predecessor of. |
| 805 | for (DominanceFrontier::DomSetType::iterator SetI = Set.begin(), |
| 806 | E = Set.end(); SetI != E;) { |
| 807 | bool DominatesPred = false; |
| 808 | for (pred_iterator PI = pred_begin(*SetI), E = pred_end(*SetI); |
| 809 | PI != E; ++PI) |
| 810 | if (DS.dominates(NewBB, *PI)) |
| 811 | DominatesPred = true; |
| 812 | if (!DominatesPred) |
| 813 | Set.erase(SetI++); |
| 814 | else |
| 815 | ++SetI; |
| 816 | } |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 817 | |
Chris Lattner | 14ab84a | 2004-02-05 21:12:24 +0000 | [diff] [blame] | 818 | DF->addBasicBlock(NewBB, Set); |
| 819 | } |
| 820 | |
| 821 | } else { |
| 822 | // DF(NewBB) is {NewBBSucc} because NewBB does not strictly dominate |
| 823 | // NewBBSucc, but it does dominate itself (and there is an edge (NewBB -> |
| 824 | // NewBBSucc)). NewBBSucc is the single successor of NewBB. |
| 825 | DominanceFrontier::DomSetType NewDFSet; |
| 826 | NewDFSet.insert(NewBBSucc); |
| 827 | DF->addBasicBlock(NewBB, NewDFSet); |
Chris Lattner | 89e959b | 2004-04-13 16:23:25 +0000 | [diff] [blame] | 828 | } |
Chris Lattner | c4622a6 | 2003-10-13 00:37:13 +0000 | [diff] [blame] | 829 | |
Chris Lattner | 89e959b | 2004-04-13 16:23:25 +0000 | [diff] [blame] | 830 | // Now we must loop over all of the dominance frontiers in the function, |
| 831 | // replacing occurrences of NewBBSucc with NewBB in some cases. All |
| 832 | // blocks that dominate a block in PredBlocks and contained NewBBSucc in |
| 833 | // their dominance frontier must be updated to contain NewBB instead. |
| 834 | // |
| 835 | for (unsigned i = 0, e = PredBlocks.size(); i != e; ++i) { |
| 836 | BasicBlock *Pred = PredBlocks[i]; |
| 837 | // Get all of the dominators of the predecessor... |
| 838 | const DominatorSet::DomSetType &PredDoms = DS.getDominators(Pred); |
| 839 | for (DominatorSet::DomSetType::const_iterator PDI = PredDoms.begin(), |
| 840 | PDE = PredDoms.end(); PDI != PDE; ++PDI) { |
| 841 | BasicBlock *PredDom = *PDI; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 842 | |
Chris Lattner | 89e959b | 2004-04-13 16:23:25 +0000 | [diff] [blame] | 843 | // If the NewBBSucc node is in DF(PredDom), then PredDom didn't |
| 844 | // dominate NewBBSucc but did dominate a predecessor of it. Now we |
| 845 | // change this entry to include NewBB in the DF instead of NewBBSucc. |
| 846 | DominanceFrontier::iterator DFI = DF->find(PredDom); |
| 847 | assert(DFI != DF->end() && "No dominance frontier for node?"); |
| 848 | if (DFI->second.count(NewBBSucc)) { |
| 849 | // If NewBBSucc should not stay in our dominator frontier, remove it. |
| 850 | // We remove it unless there is a predecessor of NewBBSucc that we |
| 851 | // dominate, but we don't strictly dominate NewBBSucc. |
| 852 | bool ShouldRemove = true; |
| 853 | if (PredDom == NewBBSucc || !DS.dominates(PredDom, NewBBSucc)) { |
| 854 | // Okay, we know that PredDom does not strictly dominate NewBBSucc. |
| 855 | // Check to see if it dominates any predecessors of NewBBSucc. |
| 856 | for (pred_iterator PI = pred_begin(NewBBSucc), |
| 857 | E = pred_end(NewBBSucc); PI != E; ++PI) |
| 858 | if (DS.dominates(PredDom, *PI)) { |
| 859 | ShouldRemove = false; |
| 860 | break; |
| 861 | } |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 862 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 863 | |
Chris Lattner | 89e959b | 2004-04-13 16:23:25 +0000 | [diff] [blame] | 864 | if (ShouldRemove) |
| 865 | DF->removeFromFrontier(DFI, NewBBSucc); |
| 866 | DF->addToFrontier(DFI, NewBB); |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 867 | } |
| 868 | } |
| 869 | } |
Chris Lattner | 650096a | 2003-02-27 20:27:08 +0000 | [diff] [blame] | 870 | } |
Chris Lattner | 61992f6 | 2002-09-26 16:17:31 +0000 | [diff] [blame] | 871 | } |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 872 | |