blob: b2752089d44614531eb019186060aa1b26e6865b [file] [log] [blame]
Chris Lattner55d47882003-10-12 21:44:18 +00001//===- LoopSimplify.cpp - Loop Canonicalization Pass ----------------------===//
John Criswell482202a2003-10-20 19:43:21 +00002//
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.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner61992f62002-09-26 16:17:31 +00009//
Chris Lattner154e4d52003-10-12 21:43:28 +000010// 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 Lattner650096a2003-02-27 20:27:08 +000013//
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 Lattner7710f2f2003-12-10 17:20:35 +000020// 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 Lattner650096a2003-02-27 20:27:08 +000023//
Chris Lattnerc4622a62003-10-13 00:37:13 +000024// This pass also guarantees that loops will have exactly one backedge.
25//
Chris Lattner650096a2003-02-27 20:27:08 +000026// Note that the simplifycfg pass will clean up blocks which are split out but
Chris Lattner154e4d52003-10-12 21:43:28 +000027// 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 Lattner61992f62002-09-26 16:17:31 +000032//
33//===----------------------------------------------------------------------===//
34
35#include "llvm/Transforms/Scalar.h"
Chris Lattnerd0788122004-03-14 03:59:22 +000036#include "llvm/Constant.h"
Chris Lattner61992f62002-09-26 16:17:31 +000037#include "llvm/iTerminators.h"
38#include "llvm/iPHINode.h"
Chris Lattnerd0788122004-03-14 03:59:22 +000039#include "llvm/Function.h"
40#include "llvm/Type.h"
Chris Lattner031a3f82003-12-19 06:27:08 +000041#include "llvm/Analysis/Dominators.h"
42#include "llvm/Analysis/LoopInfo.h"
Chris Lattner61992f62002-09-26 16:17:31 +000043#include "llvm/Support/CFG.h"
Chris Lattner84170522004-04-13 05:05:33 +000044#include "llvm/Transforms/Utils/Local.h"
Chris Lattner650096a2003-02-27 20:27:08 +000045#include "Support/SetOperations.h"
Chris Lattnerbf3a0992002-10-01 22:38:41 +000046#include "Support/Statistic.h"
Chris Lattner32a39c22003-02-28 03:07:54 +000047#include "Support/DepthFirstIterator.h"
Chris Lattner7710f2f2003-12-10 17:20:35 +000048using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000049
Chris Lattner61992f62002-09-26 16:17:31 +000050namespace {
Chris Lattner154e4d52003-10-12 21:43:28 +000051 Statistic<>
Chris Lattner7710f2f2003-12-10 17:20:35 +000052 NumInserted("loopsimplify", "Number of pre-header or exit blocks inserted");
Chris Lattner84170522004-04-13 05:05:33 +000053 Statistic<>
54 NumNested("loopsimplify", "Number of nested loops split out");
Chris Lattner61992f62002-09-26 16:17:31 +000055
Chris Lattner154e4d52003-10-12 21:43:28 +000056 struct LoopSimplify : public FunctionPass {
Chris Lattner61992f62002-09-26 16:17:31 +000057 virtual bool runOnFunction(Function &F);
58
59 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
60 // We need loop information to identify the loops...
61 AU.addRequired<LoopInfo>();
Chris Lattner650096a2003-02-27 20:27:08 +000062 AU.addRequired<DominatorSet>();
Chris Lattner797cb2f2004-03-13 22:01:26 +000063 AU.addRequired<DominatorTree>();
Chris Lattner61992f62002-09-26 16:17:31 +000064
65 AU.addPreserved<LoopInfo>();
66 AU.addPreserved<DominatorSet>();
67 AU.addPreserved<ImmediateDominators>();
68 AU.addPreserved<DominatorTree>();
Chris Lattner650096a2003-02-27 20:27:08 +000069 AU.addPreserved<DominanceFrontier>();
Chris Lattner61992f62002-09-26 16:17:31 +000070 AU.addPreservedID(BreakCriticalEdgesID); // No crit edges added....
71 }
72 private:
73 bool ProcessLoop(Loop *L);
Chris Lattner650096a2003-02-27 20:27:08 +000074 BasicBlock *SplitBlockPredecessors(BasicBlock *BB, const char *Suffix,
75 const std::vector<BasicBlock*> &Preds);
Chris Lattner82782632004-04-18 22:27:10 +000076 BasicBlock *RewriteLoopExitBlock(Loop *L, BasicBlock *Exit);
Chris Lattner61992f62002-09-26 16:17:31 +000077 void InsertPreheaderForLoop(Loop *L);
Chris Lattner84170522004-04-13 05:05:33 +000078 Loop *SeparateNestedLoop(Loop *L);
Chris Lattnerc4622a62003-10-13 00:37:13 +000079 void InsertUniqueBackedgeBlock(Loop *L);
80
81 void UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
82 std::vector<BasicBlock*> &PredBlocks);
Chris Lattner61992f62002-09-26 16:17:31 +000083 };
84
Chris Lattner154e4d52003-10-12 21:43:28 +000085 RegisterOpt<LoopSimplify>
86 X("loopsimplify", "Canonicalize natural loops", true);
Chris Lattner61992f62002-09-26 16:17:31 +000087}
88
89// Publically exposed interface to pass...
Chris Lattner7710f2f2003-12-10 17:20:35 +000090const PassInfo *llvm::LoopSimplifyID = X.getPassInfo();
91Pass *llvm::createLoopSimplifyPass() { return new LoopSimplify(); }
Chris Lattner61992f62002-09-26 16:17:31 +000092
Chris Lattner61992f62002-09-26 16:17:31 +000093/// runOnFunction - Run down all loops in the CFG (recursively, but we could do
94/// it in any convenient order) inserting preheaders...
95///
Chris Lattner154e4d52003-10-12 21:43:28 +000096bool LoopSimplify::runOnFunction(Function &F) {
Chris Lattner61992f62002-09-26 16:17:31 +000097 bool Changed = false;
98 LoopInfo &LI = getAnalysis<LoopInfo>();
99
Chris Lattner59d2d7f2004-01-08 00:09:44 +0000100 for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I)
101 Changed |= ProcessLoop(*I);
Chris Lattner61992f62002-09-26 16:17:31 +0000102
103 return Changed;
104}
105
106
107/// ProcessLoop - Walk the loop structure in depth first order, ensuring that
108/// all loops have preheaders.
109///
Chris Lattner154e4d52003-10-12 21:43:28 +0000110bool LoopSimplify::ProcessLoop(Loop *L) {
Chris Lattner61992f62002-09-26 16:17:31 +0000111 bool Changed = false;
112
Chris Lattnerd0788122004-03-14 03:59:22 +0000113 // Check to see that no blocks (other than the header) in the loop have
114 // predecessors that are not in the loop. This is not valid for natural
115 // loops, but can occur if the blocks are unreachable. Since they are
116 // unreachable we can just shamelessly destroy their terminators to make them
117 // not branch into the loop!
118 assert(L->getBlocks()[0] == L->getHeader() &&
119 "Header isn't first block in loop?");
120 for (unsigned i = 1, e = L->getBlocks().size(); i != e; ++i) {
121 BasicBlock *LoopBB = L->getBlocks()[i];
122 Retry:
123 for (pred_iterator PI = pred_begin(LoopBB), E = pred_end(LoopBB);
124 PI != E; ++PI)
125 if (!L->contains(*PI)) {
126 // This predecessor is not in the loop. Kill its terminator!
127 BasicBlock *DeadBlock = *PI;
128 for (succ_iterator SI = succ_begin(DeadBlock), E = succ_end(DeadBlock);
129 SI != E; ++SI)
130 (*SI)->removePredecessor(DeadBlock); // Remove PHI node entries
131
132 // Delete the dead terminator.
133 DeadBlock->getInstList().pop_back();
134
135 Value *RetVal = 0;
136 if (LoopBB->getParent()->getReturnType() != Type::VoidTy)
137 RetVal = Constant::getNullValue(LoopBB->getParent()->getReturnType());
138 new ReturnInst(RetVal, DeadBlock);
139 goto Retry; // We just invalidated the pred_iterator. Retry.
140 }
141 }
142
Chris Lattner61992f62002-09-26 16:17:31 +0000143 // Does the loop already have a preheader? If so, don't modify the loop...
144 if (L->getLoopPreheader() == 0) {
145 InsertPreheaderForLoop(L);
146 NumInserted++;
147 Changed = true;
148 }
149
Chris Lattner7710f2f2003-12-10 17:20:35 +0000150 // Next, check to make sure that all exit nodes of the loop only have
151 // predecessors that are inside of the loop. This check guarantees that the
152 // loop preheader/header will dominate the exit blocks. If the exit block has
153 // predecessors from outside of the loop, split the edge now.
Chris Lattnerd72c3eb2004-04-18 22:14:10 +0000154 std::vector<BasicBlock*> ExitBlocks;
155 L->getExitBlocks(ExitBlocks);
156 for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
157 BasicBlock *ExitBlock = ExitBlocks[i];
Chris Lattner7710f2f2003-12-10 17:20:35 +0000158 for (pred_iterator PI = pred_begin(ExitBlock), PE = pred_end(ExitBlock);
159 PI != PE; ++PI)
160 if (!L->contains(*PI)) {
Chris Lattner82782632004-04-18 22:27:10 +0000161 BasicBlock *NewBB = RewriteLoopExitBlock(L, ExitBlock);
162 for (unsigned j = i; j != ExitBlocks.size(); ++j)
163 if (ExitBlocks[j] == ExitBlock)
164 ExitBlocks[j] = NewBB;
165
Chris Lattner7710f2f2003-12-10 17:20:35 +0000166 NumInserted++;
167 Changed = true;
168 break;
169 }
Chris Lattner650096a2003-02-27 20:27:08 +0000170 }
171
Chris Lattner84170522004-04-13 05:05:33 +0000172 // If the header has more than two predecessors at this point (from the
173 // preheader and from multiple backedges), we must adjust the loop.
Chris Lattnerc4622a62003-10-13 00:37:13 +0000174 if (L->getNumBackEdges() != 1) {
Chris Lattner84170522004-04-13 05:05:33 +0000175 // If this is really a nested loop, rip it out into a child loop.
176 if (Loop *NL = SeparateNestedLoop(L)) {
177 ++NumNested;
178 // This is a big restructuring change, reprocess the whole loop.
179 ProcessLoop(NL);
180 return true;
181 }
182
Chris Lattnerc4622a62003-10-13 00:37:13 +0000183 InsertUniqueBackedgeBlock(L);
184 NumInserted++;
185 Changed = true;
186 }
187
Chris Lattner59d2d7f2004-01-08 00:09:44 +0000188 for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
189 Changed |= ProcessLoop(*I);
Chris Lattner61992f62002-09-26 16:17:31 +0000190 return Changed;
191}
192
Chris Lattner650096a2003-02-27 20:27:08 +0000193/// SplitBlockPredecessors - Split the specified block into two blocks. We want
194/// to move the predecessors specified in the Preds list to point to the new
195/// block, leaving the remaining predecessors pointing to BB. This method
196/// updates the SSA PHINode's, but no other analyses.
197///
Chris Lattner154e4d52003-10-12 21:43:28 +0000198BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
199 const char *Suffix,
Chris Lattner650096a2003-02-27 20:27:08 +0000200 const std::vector<BasicBlock*> &Preds) {
201
202 // Create new basic block, insert right before the original block...
Chris Lattner8d414ad2004-02-04 03:58:28 +0000203 BasicBlock *NewBB = new BasicBlock(BB->getName()+Suffix, BB->getParent(), BB);
Chris Lattner650096a2003-02-27 20:27:08 +0000204
205 // The preheader first gets an unconditional branch to the loop header...
Chris Lattnera2960002003-11-21 16:52:05 +0000206 BranchInst *BI = new BranchInst(BB, NewBB);
Chris Lattner650096a2003-02-27 20:27:08 +0000207
208 // For every PHI node in the block, insert a PHI node into NewBB where the
209 // incoming values from the out of loop edges are moved to NewBB. We have two
210 // possible cases here. If the loop is dead, we just insert dummy entries
211 // into the PHI nodes for the new edge. If the loop is not dead, we move the
212 // incoming edges in BB into new PHI nodes in NewBB.
213 //
214 if (!Preds.empty()) { // Is the loop not obviously dead?
Chris Lattner031a3f82003-12-19 06:27:08 +0000215 // Check to see if the values being merged into the new block need PHI
216 // nodes. If so, insert them.
217 for (BasicBlock::iterator I = BB->begin();
Chris Lattner84170522004-04-13 05:05:33 +0000218 PHINode *PN = dyn_cast<PHINode>(I); ) {
219 ++I;
220
Chris Lattner031a3f82003-12-19 06:27:08 +0000221 // Check to see if all of the values coming in are the same. If so, we
222 // don't need to create a new PHI node.
223 Value *InVal = PN->getIncomingValueForBlock(Preds[0]);
224 for (unsigned i = 1, e = Preds.size(); i != e; ++i)
225 if (InVal != PN->getIncomingValueForBlock(Preds[i])) {
226 InVal = 0;
227 break;
228 }
229
230 // If the values coming into the block are not the same, we need a PHI.
231 if (InVal == 0) {
Chris Lattner6c237bc2003-12-09 23:12:55 +0000232 // Create the new PHI node, insert it into NewBB at the end of the block
233 PHINode *NewPHI = new PHINode(PN->getType(), PN->getName()+".ph", BI);
234
235 // Move all of the edges from blocks outside the loop to the new PHI
236 for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
Chris Lattner84170522004-04-13 05:05:33 +0000237 Value *V = PN->removeIncomingValue(Preds[i], false);
Chris Lattner6c237bc2003-12-09 23:12:55 +0000238 NewPHI->addIncoming(V, Preds[i]);
239 }
Chris Lattner031a3f82003-12-19 06:27:08 +0000240 InVal = NewPHI;
241 } else {
242 // Remove all of the edges coming into the PHI nodes from outside of the
243 // block.
244 for (unsigned i = 0, e = Preds.size(); i != e; ++i)
245 PN->removeIncomingValue(Preds[i], false);
Chris Lattner6c237bc2003-12-09 23:12:55 +0000246 }
Chris Lattner031a3f82003-12-19 06:27:08 +0000247
248 // Add an incoming value to the PHI node in the loop for the preheader
249 // edge.
250 PN->addIncoming(InVal, NewBB);
Chris Lattner84170522004-04-13 05:05:33 +0000251
252 // Can we eliminate this phi node now?
253 if (Value *V = hasConstantValue(PN)) {
254 PN->replaceAllUsesWith(V);
255 BB->getInstList().erase(PN);
256 }
Chris Lattner650096a2003-02-27 20:27:08 +0000257 }
258
259 // Now that the PHI nodes are updated, actually move the edges from
260 // Preds to point to NewBB instead of BB.
261 //
262 for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
263 TerminatorInst *TI = Preds[i]->getTerminator();
264 for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s)
265 if (TI->getSuccessor(s) == BB)
266 TI->setSuccessor(s, NewBB);
267 }
268
269 } else { // Otherwise the loop is dead...
270 for (BasicBlock::iterator I = BB->begin();
Chris Lattner889f6202003-04-23 16:37:45 +0000271 PHINode *PN = dyn_cast<PHINode>(I); ++I)
Chris Lattner650096a2003-02-27 20:27:08 +0000272 // Insert dummy values as the incoming value...
273 PN->addIncoming(Constant::getNullValue(PN->getType()), NewBB);
274 }
275 return NewBB;
276}
277
Chris Lattner61992f62002-09-26 16:17:31 +0000278/// InsertPreheaderForLoop - Once we discover that a loop doesn't have a
279/// preheader, this method is called to insert one. This method has two phases:
280/// preheader insertion and analysis updating.
281///
Chris Lattner154e4d52003-10-12 21:43:28 +0000282void LoopSimplify::InsertPreheaderForLoop(Loop *L) {
Chris Lattner61992f62002-09-26 16:17:31 +0000283 BasicBlock *Header = L->getHeader();
284
285 // Compute the set of predecessors of the loop that are not in the loop.
286 std::vector<BasicBlock*> OutsideBlocks;
287 for (pred_iterator PI = pred_begin(Header), PE = pred_end(Header);
288 PI != PE; ++PI)
289 if (!L->contains(*PI)) // Coming in from outside the loop?
290 OutsideBlocks.push_back(*PI); // Keep track of it...
291
Chris Lattner650096a2003-02-27 20:27:08 +0000292 // Split out the loop pre-header
293 BasicBlock *NewBB =
294 SplitBlockPredecessors(Header, ".preheader", OutsideBlocks);
Chris Lattner61992f62002-09-26 16:17:31 +0000295
Chris Lattner61992f62002-09-26 16:17:31 +0000296 //===--------------------------------------------------------------------===//
Misha Brukman8b2bd4e2003-10-10 17:57:28 +0000297 // Update analysis results now that we have performed the transformation
Chris Lattner61992f62002-09-26 16:17:31 +0000298 //
299
300 // We know that we have loop information to update... update it now.
301 if (Loop *Parent = L->getParentLoop())
302 Parent->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>());
Chris Lattnerf2d9f942003-02-27 22:48:57 +0000303
304 // If the header for the loop used to be an exit node for another loop, then
305 // we need to update this to know that the loop-preheader is now the exit
306 // node. Note that the only loop that could have our header as an exit node
Chris Lattner08950252003-05-12 22:04:34 +0000307 // is a sibling loop, ie, one with the same parent loop, or one if it's
308 // children.
309 //
Chris Lattner59d2d7f2004-01-08 00:09:44 +0000310 LoopInfo::iterator ParentLoops, ParentLoopsE;
311 if (Loop *Parent = L->getParentLoop()) {
312 ParentLoops = Parent->begin();
313 ParentLoopsE = Parent->end();
314 } else { // Must check top-level loops...
315 ParentLoops = getAnalysis<LoopInfo>().begin();
316 ParentLoopsE = getAnalysis<LoopInfo>().end();
317 }
Chris Lattnerf2d9f942003-02-27 22:48:57 +0000318
Chris Lattner650096a2003-02-27 20:27:08 +0000319 DominatorSet &DS = getAnalysis<DominatorSet>(); // Update dominator info
Chris Lattner797cb2f2004-03-13 22:01:26 +0000320 DominatorTree &DT = getAnalysis<DominatorTree>();
Chris Lattnerdb5b8f42004-03-16 06:00:15 +0000321
322
323 // Update the dominator tree information.
324 // The immediate dominator of the preheader is the immediate dominator of
325 // the old header.
326 DominatorTree::Node *PHDomTreeNode =
327 DT.createNewNode(NewBB, DT.getNode(Header)->getIDom());
328
329 // Change the header node so that PNHode is the new immediate dominator
330 DT.changeImmediateDominator(DT.getNode(Header), PHDomTreeNode);
Chris Lattner797cb2f2004-03-13 22:01:26 +0000331
Chris Lattner650096a2003-02-27 20:27:08 +0000332 {
Chris Lattner61992f62002-09-26 16:17:31 +0000333 // The blocks that dominate NewBB are the blocks that dominate Header,
334 // minus Header, plus NewBB.
Chris Lattner650096a2003-02-27 20:27:08 +0000335 DominatorSet::DomSetType DomSet = DS.getDominators(Header);
Chris Lattner61992f62002-09-26 16:17:31 +0000336 DomSet.erase(Header); // Header does not dominate us...
Chris Lattner650096a2003-02-27 20:27:08 +0000337 DS.addBasicBlock(NewBB, DomSet);
Chris Lattner03a9e152002-09-29 21:41:38 +0000338
339 // The newly created basic block dominates all nodes dominated by Header.
Chris Lattnerdb5b8f42004-03-16 06:00:15 +0000340 for (df_iterator<DominatorTree::Node*> DFI = df_begin(PHDomTreeNode),
341 E = df_end(PHDomTreeNode); DFI != E; ++DFI)
342 DS.addDominator((*DFI)->getBlock(), NewBB);
Chris Lattner61992f62002-09-26 16:17:31 +0000343 }
344
345 // Update immediate dominator information if we have it...
346 if (ImmediateDominators *ID = getAnalysisToUpdate<ImmediateDominators>()) {
347 // Whatever i-dominated the header node now immediately dominates NewBB
348 ID->addNewBlock(NewBB, ID->get(Header));
349
350 // The preheader now is the immediate dominator for the header node...
351 ID->setImmediateDominator(Header, NewBB);
352 }
353
Chris Lattner650096a2003-02-27 20:27:08 +0000354 // Update dominance frontier information...
355 if (DominanceFrontier *DF = getAnalysisToUpdate<DominanceFrontier>()) {
356 // The DF(NewBB) is just (DF(Header)-Header), because NewBB dominates
357 // everything that Header does, and it strictly dominates Header in
358 // addition.
359 assert(DF->find(Header) != DF->end() && "Header node doesn't have DF set?");
360 DominanceFrontier::DomSetType NewDFSet = DF->find(Header)->second;
361 NewDFSet.erase(Header);
362 DF->addBasicBlock(NewBB, NewDFSet);
363
364 // Now we must loop over all of the dominance frontiers in the function,
Misha Brukman4ace48e2003-09-09 21:54:45 +0000365 // replacing occurrences of Header with NewBB in some cases. If a block
Chris Lattner650096a2003-02-27 20:27:08 +0000366 // dominates a (now) predecessor of NewBB, but did not strictly dominate
367 // Header, it will have Header in it's DF set, but should now have NewBB in
368 // its set.
369 for (unsigned i = 0, e = OutsideBlocks.size(); i != e; ++i) {
370 // Get all of the dominators of the predecessor...
371 const DominatorSet::DomSetType &PredDoms =
372 DS.getDominators(OutsideBlocks[i]);
373 for (DominatorSet::DomSetType::const_iterator PDI = PredDoms.begin(),
374 PDE = PredDoms.end(); PDI != PDE; ++PDI) {
375 BasicBlock *PredDom = *PDI;
376 // If the loop header is in DF(PredDom), then PredDom didn't dominate
377 // the header but did dominate a predecessor outside of the loop. Now
378 // we change this entry to include the preheader in the DF instead of
379 // the header.
380 DominanceFrontier::iterator DFI = DF->find(PredDom);
381 assert(DFI != DF->end() && "No dominance frontier for node?");
382 if (DFI->second.count(Header)) {
383 DF->removeFromFrontier(DFI, Header);
384 DF->addToFrontier(DFI, NewBB);
385 }
386 }
387 }
388 }
389}
390
Chris Lattner84170522004-04-13 05:05:33 +0000391/// RewriteLoopExitBlock - Ensure that the loop preheader dominates all exit
392/// blocks. This method is used to split exit blocks that have predecessors
393/// outside of the loop.
Chris Lattner82782632004-04-18 22:27:10 +0000394BasicBlock *LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) {
Chris Lattner650096a2003-02-27 20:27:08 +0000395 DominatorSet &DS = getAnalysis<DominatorSet>();
Chris Lattner650096a2003-02-27 20:27:08 +0000396
397 std::vector<BasicBlock*> LoopBlocks;
398 for (pred_iterator I = pred_begin(Exit), E = pred_end(Exit); I != E; ++I)
399 if (L->contains(*I))
400 LoopBlocks.push_back(*I);
401
Chris Lattner10b2b052003-02-27 22:31:07 +0000402 assert(!LoopBlocks.empty() && "No edges coming in from outside the loop?");
403 BasicBlock *NewBB = SplitBlockPredecessors(Exit, ".loopexit", LoopBlocks);
404
Chris Lattner4e2fbfb2003-02-27 21:50:19 +0000405 // Update Loop Information - we know that the new block will be in the parent
406 // loop of L.
407 if (Loop *Parent = L->getParentLoop())
408 Parent->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>());
Chris Lattner32a39c22003-02-28 03:07:54 +0000409
Chris Lattnerc4622a62003-10-13 00:37:13 +0000410 // Update dominator information (set, immdom, domtree, and domfrontier)
411 UpdateDomInfoForRevectoredPreds(NewBB, LoopBlocks);
Chris Lattner82782632004-04-18 22:27:10 +0000412 return NewBB;
Chris Lattnerc4622a62003-10-13 00:37:13 +0000413}
414
Chris Lattner84170522004-04-13 05:05:33 +0000415/// AddBlockAndPredsToSet - Add the specified block, and all of its
416/// predecessors, to the specified set, if it's not already in there. Stop
417/// predecessor traversal when we reach StopBlock.
418static void AddBlockAndPredsToSet(BasicBlock *BB, BasicBlock *StopBlock,
419 std::set<BasicBlock*> &Blocks) {
420 if (!Blocks.insert(BB).second) return; // already processed.
421 if (BB == StopBlock) return; // Stop here!
422
423 for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I)
424 AddBlockAndPredsToSet(*I, StopBlock, Blocks);
425}
426
Chris Lattnera6e22812004-04-13 15:21:18 +0000427/// FindPHIToPartitionLoops - The first part of loop-nestification is to find a
428/// PHI node that tells us how to partition the loops.
429static PHINode *FindPHIToPartitionLoops(Loop *L) {
430 for (BasicBlock::iterator I = L->getHeader()->begin();
431 PHINode *PN = dyn_cast<PHINode>(I); ) {
432 ++I;
433 if (Value *V = hasConstantValue(PN)) {
434 // This is a degenerate PHI already, don't modify it!
435 PN->replaceAllUsesWith(V);
436 PN->getParent()->getInstList().erase(PN);
437 } else {
438 // Scan this PHI node looking for a use of the PHI node by itself.
439 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
440 if (PN->getIncomingValue(i) == PN &&
441 L->contains(PN->getIncomingBlock(i)))
442 // We found something tasty to remove.
443 return PN;
444 }
445 }
446 return 0;
447}
448
Chris Lattner84170522004-04-13 05:05:33 +0000449/// SeparateNestedLoop - If this loop has multiple backedges, try to pull one of
450/// them out into a nested loop. This is important for code that looks like
451/// this:
452///
453/// Loop:
454/// ...
455/// br cond, Loop, Next
456/// ...
457/// br cond2, Loop, Out
458///
459/// To identify this common case, we look at the PHI nodes in the header of the
460/// loop. PHI nodes with unchanging values on one backedge correspond to values
461/// that change in the "outer" loop, but not in the "inner" loop.
462///
463/// If we are able to separate out a loop, return the new outer loop that was
464/// created.
465///
466Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
Chris Lattnera6e22812004-04-13 15:21:18 +0000467 PHINode *PN = FindPHIToPartitionLoops(L);
468 if (PN == 0) return 0; // No known way to partition.
Chris Lattner84170522004-04-13 05:05:33 +0000469
Chris Lattnera6e22812004-04-13 15:21:18 +0000470 // Pull out all predecessors that have varying values in the loop. This
471 // handles the case when a PHI node has multiple instances of itself as
472 // arguments.
Chris Lattner84170522004-04-13 05:05:33 +0000473 std::vector<BasicBlock*> OuterLoopPreds;
Chris Lattnera6e22812004-04-13 15:21:18 +0000474 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
475 if (PN->getIncomingValue(i) != PN ||
476 !L->contains(PN->getIncomingBlock(i)))
477 OuterLoopPreds.push_back(PN->getIncomingBlock(i));
Chris Lattner84170522004-04-13 05:05:33 +0000478
Chris Lattner89e959b2004-04-13 16:23:25 +0000479 BasicBlock *Header = L->getHeader();
Chris Lattner84170522004-04-13 05:05:33 +0000480 BasicBlock *NewBB = SplitBlockPredecessors(Header, ".outer", OuterLoopPreds);
481
482 // Update dominator information (set, immdom, domtree, and domfrontier)
483 UpdateDomInfoForRevectoredPreds(NewBB, OuterLoopPreds);
484
485 // Create the new outer loop.
486 Loop *NewOuter = new Loop();
487
488 LoopInfo &LI = getAnalysis<LoopInfo>();
489
490 // Change the parent loop to use the outer loop as its child now.
491 if (Loop *Parent = L->getParentLoop())
492 Parent->replaceChildLoopWith(L, NewOuter);
493 else
494 LI.changeTopLevelLoop(L, NewOuter);
495
496 // This block is going to be our new header block: add it to this loop and all
497 // parent loops.
498 NewOuter->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>());
499
500 // L is now a subloop of our outer loop.
501 NewOuter->addChildLoop(L);
502
Chris Lattner84170522004-04-13 05:05:33 +0000503 for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i)
504 NewOuter->addBlockEntry(L->getBlocks()[i]);
505
506 // Determine which blocks should stay in L and which should be moved out to
507 // the Outer loop now.
508 DominatorSet &DS = getAnalysis<DominatorSet>();
509 std::set<BasicBlock*> BlocksInL;
510 for (pred_iterator PI = pred_begin(Header), E = pred_end(Header); PI!=E; ++PI)
511 if (DS.dominates(Header, *PI))
512 AddBlockAndPredsToSet(*PI, Header, BlocksInL);
513
514
515 // Scan all of the loop children of L, moving them to OuterLoop if they are
516 // not part of the inner loop.
517 for (Loop::iterator I = L->begin(); I != L->end(); )
518 if (BlocksInL.count((*I)->getHeader()))
519 ++I; // Loop remains in L
520 else
521 NewOuter->addChildLoop(L->removeChildLoop(I));
522
523 // Now that we know which blocks are in L and which need to be moved to
524 // OuterLoop, move any blocks that need it.
525 for (unsigned i = 0; i != L->getBlocks().size(); ++i) {
526 BasicBlock *BB = L->getBlocks()[i];
527 if (!BlocksInL.count(BB)) {
528 // Move this block to the parent, updating the exit blocks sets
529 L->removeBlockFromLoop(BB);
530 if (LI[BB] == L)
531 LI.changeLoopFor(BB, NewOuter);
532 --i;
533 }
534 }
535
Chris Lattner84170522004-04-13 05:05:33 +0000536 return NewOuter;
537}
538
539
540
Chris Lattnerc4622a62003-10-13 00:37:13 +0000541/// InsertUniqueBackedgeBlock - This method is called when the specified loop
542/// has more than one backedge in it. If this occurs, revector all of these
543/// backedges to target a new basic block and have that block branch to the loop
544/// header. This ensures that loops have exactly one backedge.
545///
546void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) {
547 assert(L->getNumBackEdges() > 1 && "Must have > 1 backedge!");
548
549 // Get information about the loop
550 BasicBlock *Preheader = L->getLoopPreheader();
551 BasicBlock *Header = L->getHeader();
552 Function *F = Header->getParent();
553
554 // Figure out which basic blocks contain back-edges to the loop header.
555 std::vector<BasicBlock*> BackedgeBlocks;
556 for (pred_iterator I = pred_begin(Header), E = pred_end(Header); I != E; ++I)
557 if (*I != Preheader) BackedgeBlocks.push_back(*I);
558
559 // Create and insert the new backedge block...
560 BasicBlock *BEBlock = new BasicBlock(Header->getName()+".backedge", F);
Chris Lattnera2960002003-11-21 16:52:05 +0000561 BranchInst *BETerminator = new BranchInst(Header, BEBlock);
Chris Lattnerc4622a62003-10-13 00:37:13 +0000562
563 // Move the new backedge block to right after the last backedge block.
564 Function::iterator InsertPos = BackedgeBlocks.back(); ++InsertPos;
565 F->getBasicBlockList().splice(InsertPos, F->getBasicBlockList(), BEBlock);
566
567 // Now that the block has been inserted into the function, create PHI nodes in
568 // the backedge block which correspond to any PHI nodes in the header block.
569 for (BasicBlock::iterator I = Header->begin();
570 PHINode *PN = dyn_cast<PHINode>(I); ++I) {
571 PHINode *NewPN = new PHINode(PN->getType(), PN->getName()+".be",
572 BETerminator);
573 NewPN->op_reserve(2*BackedgeBlocks.size());
574
575 // Loop over the PHI node, moving all entries except the one for the
576 // preheader over to the new PHI node.
577 unsigned PreheaderIdx = ~0U;
578 bool HasUniqueIncomingValue = true;
579 Value *UniqueValue = 0;
580 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
581 BasicBlock *IBB = PN->getIncomingBlock(i);
582 Value *IV = PN->getIncomingValue(i);
583 if (IBB == Preheader) {
584 PreheaderIdx = i;
585 } else {
586 NewPN->addIncoming(IV, IBB);
587 if (HasUniqueIncomingValue) {
588 if (UniqueValue == 0)
589 UniqueValue = IV;
590 else if (UniqueValue != IV)
591 HasUniqueIncomingValue = false;
592 }
593 }
594 }
595
596 // Delete all of the incoming values from the old PN except the preheader's
597 assert(PreheaderIdx != ~0U && "PHI has no preheader entry??");
598 if (PreheaderIdx != 0) {
599 PN->setIncomingValue(0, PN->getIncomingValue(PreheaderIdx));
600 PN->setIncomingBlock(0, PN->getIncomingBlock(PreheaderIdx));
601 }
602 PN->op_erase(PN->op_begin()+2, PN->op_end());
603
604 // Finally, add the newly constructed PHI node as the entry for the BEBlock.
605 PN->addIncoming(NewPN, BEBlock);
606
607 // As an optimization, if all incoming values in the new PhiNode (which is a
608 // subset of the incoming values of the old PHI node) have the same value,
609 // eliminate the PHI Node.
610 if (HasUniqueIncomingValue) {
611 NewPN->replaceAllUsesWith(UniqueValue);
612 BEBlock->getInstList().erase(NewPN);
613 }
614 }
615
616 // Now that all of the PHI nodes have been inserted and adjusted, modify the
617 // backedge blocks to just to the BEBlock instead of the header.
618 for (unsigned i = 0, e = BackedgeBlocks.size(); i != e; ++i) {
619 TerminatorInst *TI = BackedgeBlocks[i]->getTerminator();
620 for (unsigned Op = 0, e = TI->getNumSuccessors(); Op != e; ++Op)
621 if (TI->getSuccessor(Op) == Header)
622 TI->setSuccessor(Op, BEBlock);
623 }
624
625 //===--- Update all analyses which we must preserve now -----------------===//
626
627 // Update Loop Information - we know that this block is now in the current
628 // loop and all parent loops.
629 L->addBasicBlockToLoop(BEBlock, getAnalysis<LoopInfo>());
630
Chris Lattnerc4622a62003-10-13 00:37:13 +0000631 // Update dominator information (set, immdom, domtree, and domfrontier)
632 UpdateDomInfoForRevectoredPreds(BEBlock, BackedgeBlocks);
633}
634
635/// UpdateDomInfoForRevectoredPreds - This method is used to update the four
636/// different kinds of dominator information (dominator sets, immediate
637/// dominators, dominator trees, and dominance frontiers) after a new block has
638/// been added to the CFG.
639///
Chris Lattner14ab84a2004-02-05 21:12:24 +0000640/// This only supports the case when an existing block (known as "NewBBSucc"),
641/// had some of its predecessors factored into a new basic block. This
Chris Lattnerc4622a62003-10-13 00:37:13 +0000642/// transformation inserts a new basic block ("NewBB"), with a single
Chris Lattner14ab84a2004-02-05 21:12:24 +0000643/// unconditional branch to NewBBSucc, and moves some predecessors of
644/// "NewBBSucc" to now branch to NewBB. These predecessors are listed in
645/// PredBlocks, even though they are the same as
646/// pred_begin(NewBB)/pred_end(NewBB).
Chris Lattnerc4622a62003-10-13 00:37:13 +0000647///
648void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
649 std::vector<BasicBlock*> &PredBlocks) {
Chris Lattner14ab84a2004-02-05 21:12:24 +0000650 assert(!PredBlocks.empty() && "No predblocks??");
Chris Lattnerc4622a62003-10-13 00:37:13 +0000651 assert(succ_begin(NewBB) != succ_end(NewBB) &&
652 ++succ_begin(NewBB) == succ_end(NewBB) &&
653 "NewBB should have a single successor!");
Chris Lattner14ab84a2004-02-05 21:12:24 +0000654 BasicBlock *NewBBSucc = *succ_begin(NewBB);
Chris Lattnerc4622a62003-10-13 00:37:13 +0000655 DominatorSet &DS = getAnalysis<DominatorSet>();
656
Chris Lattner146d0df2004-04-01 19:06:07 +0000657 // Update dominator information... The blocks that dominate NewBB are the
658 // intersection of the dominators of predecessors, plus the block itself.
659 //
660 DominatorSet::DomSetType NewBBDomSet = DS.getDominators(PredBlocks[0]);
661 for (unsigned i = 1, e = PredBlocks.size(); i != e; ++i)
662 set_intersect(NewBBDomSet, DS.getDominators(PredBlocks[i]));
663 NewBBDomSet.insert(NewBB); // All blocks dominate themselves...
664 DS.addBasicBlock(NewBB, NewBBDomSet);
665
Chris Lattner14ab84a2004-02-05 21:12:24 +0000666 // The newly inserted basic block will dominate existing basic blocks iff the
667 // PredBlocks dominate all of the non-pred blocks. If all predblocks dominate
668 // the non-pred blocks, then they all must be the same block!
Chris Lattner146d0df2004-04-01 19:06:07 +0000669 //
Chris Lattner14ab84a2004-02-05 21:12:24 +0000670 bool NewBBDominatesNewBBSucc = true;
671 {
672 BasicBlock *OnePred = PredBlocks[0];
673 for (unsigned i = 1, e = PredBlocks.size(); i != e; ++i)
674 if (PredBlocks[i] != OnePred) {
675 NewBBDominatesNewBBSucc = false;
676 break;
677 }
678
679 if (NewBBDominatesNewBBSucc)
680 for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
681 PI != E; ++PI)
Chris Lattner2dd1c8d2004-02-05 23:20:59 +0000682 if (*PI != NewBB && !DS.dominates(NewBBSucc, *PI)) {
Chris Lattner14ab84a2004-02-05 21:12:24 +0000683 NewBBDominatesNewBBSucc = false;
684 break;
685 }
686 }
687
Chris Lattner146d0df2004-04-01 19:06:07 +0000688 // The other scenario where the new block can dominate its successors are when
689 // all predecessors of NewBBSucc that are not NewBB are dominated by NewBBSucc
690 // already.
691 if (!NewBBDominatesNewBBSucc) {
692 NewBBDominatesNewBBSucc = true;
693 for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
694 PI != E; ++PI)
695 if (*PI != NewBB && !DS.dominates(NewBBSucc, *PI)) {
696 NewBBDominatesNewBBSucc = false;
697 break;
698 }
699 }
Chris Lattner650096a2003-02-27 20:27:08 +0000700
Chris Lattner14ab84a2004-02-05 21:12:24 +0000701 // If NewBB dominates some blocks, then it will dominate all blocks that
Chris Lattnerc0c953f2004-02-05 22:33:26 +0000702 // NewBBSucc does.
Chris Lattner14ab84a2004-02-05 21:12:24 +0000703 if (NewBBDominatesNewBBSucc) {
704 BasicBlock *PredBlock = PredBlocks[0];
705 Function *F = NewBB->getParent();
706 for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
Chris Lattnerc0c953f2004-02-05 22:33:26 +0000707 if (DS.dominates(NewBBSucc, I))
Chris Lattner14ab84a2004-02-05 21:12:24 +0000708 DS.addDominator(I, NewBB);
709 }
710
Chris Lattner650096a2003-02-27 20:27:08 +0000711 // Update immediate dominator information if we have it...
712 BasicBlock *NewBBIDom = 0;
713 if (ImmediateDominators *ID = getAnalysisToUpdate<ImmediateDominators>()) {
Chris Lattner14ab84a2004-02-05 21:12:24 +0000714 // To find the immediate dominator of the new exit node, we trace up the
715 // immediate dominators of a predecessor until we find a basic block that
716 // dominates the exit block.
Chris Lattner650096a2003-02-27 20:27:08 +0000717 //
Chris Lattnerc4622a62003-10-13 00:37:13 +0000718 BasicBlock *Dom = PredBlocks[0]; // Some random predecessor...
Chris Lattner650096a2003-02-27 20:27:08 +0000719 while (!NewBBDomSet.count(Dom)) { // Loop until we find a dominator...
720 assert(Dom != 0 && "No shared dominator found???");
721 Dom = ID->get(Dom);
722 }
723
724 // Set the immediate dominator now...
725 ID->addNewBlock(NewBB, Dom);
726 NewBBIDom = Dom; // Reuse this if calculating DominatorTree info...
Chris Lattner14ab84a2004-02-05 21:12:24 +0000727
728 // If NewBB strictly dominates other blocks, we need to update their idom's
729 // now. The only block that need adjustment is the NewBBSucc block, whose
730 // idom should currently be set to PredBlocks[0].
Chris Lattner59fdf742004-04-01 19:21:46 +0000731 if (NewBBDominatesNewBBSucc)
Chris Lattner14ab84a2004-02-05 21:12:24 +0000732 ID->setImmediateDominator(NewBBSucc, NewBB);
Chris Lattner650096a2003-02-27 20:27:08 +0000733 }
734
735 // Update DominatorTree information if it is active.
736 if (DominatorTree *DT = getAnalysisToUpdate<DominatorTree>()) {
Chris Lattner14ab84a2004-02-05 21:12:24 +0000737 // If we don't have ImmediateDominator info around, calculate the idom as
738 // above.
Chris Lattner650096a2003-02-27 20:27:08 +0000739 DominatorTree::Node *NewBBIDomNode;
740 if (NewBBIDom) {
741 NewBBIDomNode = DT->getNode(NewBBIDom);
742 } else {
Chris Lattnerc4622a62003-10-13 00:37:13 +0000743 NewBBIDomNode = DT->getNode(PredBlocks[0]); // Random pred
Chris Lattnerbb9d03b2003-09-11 16:26:13 +0000744 while (!NewBBDomSet.count(NewBBIDomNode->getBlock())) {
Chris Lattner650096a2003-02-27 20:27:08 +0000745 NewBBIDomNode = NewBBIDomNode->getIDom();
746 assert(NewBBIDomNode && "No shared dominator found??");
747 }
748 }
749
Chris Lattner14ab84a2004-02-05 21:12:24 +0000750 // Create the new dominator tree node... and set the idom of NewBB.
751 DominatorTree::Node *NewBBNode = DT->createNewNode(NewBB, NewBBIDomNode);
752
753 // If NewBB strictly dominates other blocks, then it is now the immediate
754 // dominator of NewBBSucc. Update the dominator tree as appropriate.
755 if (NewBBDominatesNewBBSucc) {
756 DominatorTree::Node *NewBBSuccNode = DT->getNode(NewBBSucc);
Chris Lattner14ab84a2004-02-05 21:12:24 +0000757 DT->changeImmediateDominator(NewBBSuccNode, NewBBNode);
758 }
Chris Lattner650096a2003-02-27 20:27:08 +0000759 }
760
761 // Update dominance frontier information...
762 if (DominanceFrontier *DF = getAnalysisToUpdate<DominanceFrontier>()) {
Chris Lattner89e959b2004-04-13 16:23:25 +0000763 // If NewBB dominates NewBBSucc, then DF(NewBB) is now going to be the
764 // DF(PredBlocks[0]) without the stuff that the new block does not dominate
765 // a predecessor of.
Chris Lattner14ab84a2004-02-05 21:12:24 +0000766 if (NewBBDominatesNewBBSucc) {
767 DominanceFrontier::iterator DFI = DF->find(PredBlocks[0]);
768 if (DFI != DF->end()) {
769 DominanceFrontier::DomSetType Set = DFI->second;
770 // Filter out stuff in Set that we do not dominate a predecessor of.
771 for (DominanceFrontier::DomSetType::iterator SetI = Set.begin(),
772 E = Set.end(); SetI != E;) {
773 bool DominatesPred = false;
774 for (pred_iterator PI = pred_begin(*SetI), E = pred_end(*SetI);
775 PI != E; ++PI)
776 if (DS.dominates(NewBB, *PI))
777 DominatesPred = true;
778 if (!DominatesPred)
779 Set.erase(SetI++);
780 else
781 ++SetI;
782 }
Chris Lattner650096a2003-02-27 20:27:08 +0000783
Chris Lattner14ab84a2004-02-05 21:12:24 +0000784 DF->addBasicBlock(NewBB, Set);
785 }
786
787 } else {
788 // DF(NewBB) is {NewBBSucc} because NewBB does not strictly dominate
789 // NewBBSucc, but it does dominate itself (and there is an edge (NewBB ->
790 // NewBBSucc)). NewBBSucc is the single successor of NewBB.
791 DominanceFrontier::DomSetType NewDFSet;
792 NewDFSet.insert(NewBBSucc);
793 DF->addBasicBlock(NewBB, NewDFSet);
Chris Lattner89e959b2004-04-13 16:23:25 +0000794 }
Chris Lattnerc4622a62003-10-13 00:37:13 +0000795
Chris Lattner89e959b2004-04-13 16:23:25 +0000796 // Now we must loop over all of the dominance frontiers in the function,
797 // replacing occurrences of NewBBSucc with NewBB in some cases. All
798 // blocks that dominate a block in PredBlocks and contained NewBBSucc in
799 // their dominance frontier must be updated to contain NewBB instead.
800 //
801 for (unsigned i = 0, e = PredBlocks.size(); i != e; ++i) {
802 BasicBlock *Pred = PredBlocks[i];
803 // Get all of the dominators of the predecessor...
804 const DominatorSet::DomSetType &PredDoms = DS.getDominators(Pred);
805 for (DominatorSet::DomSetType::const_iterator PDI = PredDoms.begin(),
806 PDE = PredDoms.end(); PDI != PDE; ++PDI) {
807 BasicBlock *PredDom = *PDI;
808
809 // If the NewBBSucc node is in DF(PredDom), then PredDom didn't
810 // dominate NewBBSucc but did dominate a predecessor of it. Now we
811 // change this entry to include NewBB in the DF instead of NewBBSucc.
812 DominanceFrontier::iterator DFI = DF->find(PredDom);
813 assert(DFI != DF->end() && "No dominance frontier for node?");
814 if (DFI->second.count(NewBBSucc)) {
815 // If NewBBSucc should not stay in our dominator frontier, remove it.
816 // We remove it unless there is a predecessor of NewBBSucc that we
817 // dominate, but we don't strictly dominate NewBBSucc.
818 bool ShouldRemove = true;
819 if (PredDom == NewBBSucc || !DS.dominates(PredDom, NewBBSucc)) {
820 // Okay, we know that PredDom does not strictly dominate NewBBSucc.
821 // Check to see if it dominates any predecessors of NewBBSucc.
822 for (pred_iterator PI = pred_begin(NewBBSucc),
823 E = pred_end(NewBBSucc); PI != E; ++PI)
824 if (DS.dominates(PredDom, *PI)) {
825 ShouldRemove = false;
826 break;
827 }
Chris Lattner650096a2003-02-27 20:27:08 +0000828 }
Chris Lattner89e959b2004-04-13 16:23:25 +0000829
830 if (ShouldRemove)
831 DF->removeFromFrontier(DFI, NewBBSucc);
832 DF->addToFrontier(DFI, NewBB);
Chris Lattner650096a2003-02-27 20:27:08 +0000833 }
834 }
835 }
Chris Lattner650096a2003-02-27 20:27:08 +0000836 }
Chris Lattner61992f62002-09-26 16:17:31 +0000837}
Brian Gaeke960707c2003-11-11 22:41:34 +0000838