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