blob: 167075f3be3214f4d5fb975511cfa2ca37bcacb7 [file] [log] [blame]
Chris Lattner67a98012003-10-12 21:44:18 +00001//===- LoopSimplify.cpp - Loop Canonicalization Pass ----------------------===//
John Criswellb576c942003-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 Lattner38acf9e2002-09-26 16:17:31 +00009//
Chris Lattneree2c50c2003-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 Lattnerdbf3cd72003-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 Lattner66ea98e2003-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 Lattnerdbf3cd72003-02-27 20:27:08 +000023//
Chris Lattner2ab6a732003-10-13 00:37:13 +000024// This pass also guarantees that loops will have exactly one backedge.
25//
Chris Lattnerdbf3cd72003-02-27 20:27:08 +000026// Note that the simplifycfg pass will clean up blocks which are split out but
Chris Lattneree2c50c2003-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 Lattner38acf9e2002-09-26 16:17:31 +000032//
33//===----------------------------------------------------------------------===//
34
35#include "llvm/Transforms/Scalar.h"
Chris Lattner2ef703e2004-03-14 03:59:22 +000036#include "llvm/Constant.h"
Chris Lattner38acf9e2002-09-26 16:17:31 +000037#include "llvm/iTerminators.h"
38#include "llvm/iPHINode.h"
Chris Lattner2ef703e2004-03-14 03:59:22 +000039#include "llvm/Function.h"
40#include "llvm/Type.h"
Chris Lattner0f98e752003-12-19 06:27:08 +000041#include "llvm/Analysis/Dominators.h"
42#include "llvm/Analysis/LoopInfo.h"
Chris Lattner38acf9e2002-09-26 16:17:31 +000043#include "llvm/Support/CFG.h"
Chris Lattner529b28d2004-04-13 05:05:33 +000044#include "llvm/Transforms/Utils/Local.h"
Chris Lattnerdbf3cd72003-02-27 20:27:08 +000045#include "Support/SetOperations.h"
Chris Lattnera92f6962002-10-01 22:38:41 +000046#include "Support/Statistic.h"
Chris Lattner74cd04e2003-02-28 03:07:54 +000047#include "Support/DepthFirstIterator.h"
Chris Lattner66ea98e2003-12-10 17:20:35 +000048using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000049
Chris Lattner38acf9e2002-09-26 16:17:31 +000050namespace {
Chris Lattneree2c50c2003-10-12 21:43:28 +000051 Statistic<>
Chris Lattner66ea98e2003-12-10 17:20:35 +000052 NumInserted("loopsimplify", "Number of pre-header or exit blocks inserted");
Chris Lattner529b28d2004-04-13 05:05:33 +000053 Statistic<>
54 NumNested("loopsimplify", "Number of nested loops split out");
Chris Lattner38acf9e2002-09-26 16:17:31 +000055
Chris Lattneree2c50c2003-10-12 21:43:28 +000056 struct LoopSimplify : public FunctionPass {
Chris Lattner38acf9e2002-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 Lattnerdbf3cd72003-02-27 20:27:08 +000062 AU.addRequired<DominatorSet>();
Chris Lattner786c5642004-03-13 22:01:26 +000063 AU.addRequired<DominatorTree>();
Chris Lattner38acf9e2002-09-26 16:17:31 +000064
65 AU.addPreserved<LoopInfo>();
66 AU.addPreserved<DominatorSet>();
67 AU.addPreserved<ImmediateDominators>();
68 AU.addPreserved<DominatorTree>();
Chris Lattnerdbf3cd72003-02-27 20:27:08 +000069 AU.addPreserved<DominanceFrontier>();
Chris Lattner38acf9e2002-09-26 16:17:31 +000070 AU.addPreservedID(BreakCriticalEdgesID); // No crit edges added....
71 }
72 private:
73 bool ProcessLoop(Loop *L);
Chris Lattnerdbf3cd72003-02-27 20:27:08 +000074 BasicBlock *SplitBlockPredecessors(BasicBlock *BB, const char *Suffix,
75 const std::vector<BasicBlock*> &Preds);
76 void RewriteLoopExitBlock(Loop *L, BasicBlock *Exit);
Chris Lattner38acf9e2002-09-26 16:17:31 +000077 void InsertPreheaderForLoop(Loop *L);
Chris Lattner529b28d2004-04-13 05:05:33 +000078 Loop *SeparateNestedLoop(Loop *L);
Chris Lattner2ab6a732003-10-13 00:37:13 +000079 void InsertUniqueBackedgeBlock(Loop *L);
80
81 void UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
82 std::vector<BasicBlock*> &PredBlocks);
Chris Lattner38acf9e2002-09-26 16:17:31 +000083 };
84
Chris Lattneree2c50c2003-10-12 21:43:28 +000085 RegisterOpt<LoopSimplify>
86 X("loopsimplify", "Canonicalize natural loops", true);
Chris Lattner38acf9e2002-09-26 16:17:31 +000087}
88
89// Publically exposed interface to pass...
Chris Lattner66ea98e2003-12-10 17:20:35 +000090const PassInfo *llvm::LoopSimplifyID = X.getPassInfo();
91Pass *llvm::createLoopSimplifyPass() { return new LoopSimplify(); }
Chris Lattner38acf9e2002-09-26 16:17:31 +000092
Chris Lattner38acf9e2002-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 Lattneree2c50c2003-10-12 21:43:28 +000096bool LoopSimplify::runOnFunction(Function &F) {
Chris Lattner38acf9e2002-09-26 16:17:31 +000097 bool Changed = false;
98 LoopInfo &LI = getAnalysis<LoopInfo>();
99
Chris Lattner329c1c62004-01-08 00:09:44 +0000100 for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I)
101 Changed |= ProcessLoop(*I);
Chris Lattner38acf9e2002-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 Lattneree2c50c2003-10-12 21:43:28 +0000110bool LoopSimplify::ProcessLoop(Loop *L) {
Chris Lattner38acf9e2002-09-26 16:17:31 +0000111 bool Changed = false;
112
Chris Lattner2ef703e2004-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 Lattner38acf9e2002-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 Lattner66ea98e2003-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 Lattnerf1ab4b42004-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 Lattner66ea98e2003-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)) {
161 RewriteLoopExitBlock(L, ExitBlock);
162 NumInserted++;
163 Changed = true;
164 break;
165 }
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000166 }
167
Chris Lattner529b28d2004-04-13 05:05:33 +0000168 // If the header has more than two predecessors at this point (from the
169 // preheader and from multiple backedges), we must adjust the loop.
Chris Lattner2ab6a732003-10-13 00:37:13 +0000170 if (L->getNumBackEdges() != 1) {
Chris Lattner529b28d2004-04-13 05:05:33 +0000171 // If this is really a nested loop, rip it out into a child loop.
172 if (Loop *NL = SeparateNestedLoop(L)) {
173 ++NumNested;
174 // This is a big restructuring change, reprocess the whole loop.
175 ProcessLoop(NL);
176 return true;
177 }
178
Chris Lattner2ab6a732003-10-13 00:37:13 +0000179 InsertUniqueBackedgeBlock(L);
180 NumInserted++;
181 Changed = true;
182 }
183
Chris Lattner329c1c62004-01-08 00:09:44 +0000184 for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
185 Changed |= ProcessLoop(*I);
Chris Lattner38acf9e2002-09-26 16:17:31 +0000186 return Changed;
187}
188
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000189/// SplitBlockPredecessors - Split the specified block into two blocks. We want
190/// to move the predecessors specified in the Preds list to point to the new
191/// block, leaving the remaining predecessors pointing to BB. This method
192/// updates the SSA PHINode's, but no other analyses.
193///
Chris Lattneree2c50c2003-10-12 21:43:28 +0000194BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
195 const char *Suffix,
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000196 const std::vector<BasicBlock*> &Preds) {
197
198 // Create new basic block, insert right before the original block...
Chris Lattnerc24a0762004-02-04 03:58:28 +0000199 BasicBlock *NewBB = new BasicBlock(BB->getName()+Suffix, BB->getParent(), BB);
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000200
201 // The preheader first gets an unconditional branch to the loop header...
Chris Lattner108e4ab2003-11-21 16:52:05 +0000202 BranchInst *BI = new BranchInst(BB, NewBB);
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000203
204 // For every PHI node in the block, insert a PHI node into NewBB where the
205 // incoming values from the out of loop edges are moved to NewBB. We have two
206 // possible cases here. If the loop is dead, we just insert dummy entries
207 // into the PHI nodes for the new edge. If the loop is not dead, we move the
208 // incoming edges in BB into new PHI nodes in NewBB.
209 //
210 if (!Preds.empty()) { // Is the loop not obviously dead?
Chris Lattner0f98e752003-12-19 06:27:08 +0000211 // Check to see if the values being merged into the new block need PHI
212 // nodes. If so, insert them.
213 for (BasicBlock::iterator I = BB->begin();
Chris Lattner529b28d2004-04-13 05:05:33 +0000214 PHINode *PN = dyn_cast<PHINode>(I); ) {
215 ++I;
216
Chris Lattner0f98e752003-12-19 06:27:08 +0000217 // Check to see if all of the values coming in are the same. If so, we
218 // don't need to create a new PHI node.
219 Value *InVal = PN->getIncomingValueForBlock(Preds[0]);
220 for (unsigned i = 1, e = Preds.size(); i != e; ++i)
221 if (InVal != PN->getIncomingValueForBlock(Preds[i])) {
222 InVal = 0;
223 break;
224 }
225
226 // If the values coming into the block are not the same, we need a PHI.
227 if (InVal == 0) {
Chris Lattner010ba102003-12-09 23:12:55 +0000228 // Create the new PHI node, insert it into NewBB at the end of the block
229 PHINode *NewPHI = new PHINode(PN->getType(), PN->getName()+".ph", BI);
230
231 // Move all of the edges from blocks outside the loop to the new PHI
232 for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
Chris Lattner529b28d2004-04-13 05:05:33 +0000233 Value *V = PN->removeIncomingValue(Preds[i], false);
Chris Lattner010ba102003-12-09 23:12:55 +0000234 NewPHI->addIncoming(V, Preds[i]);
235 }
Chris Lattner0f98e752003-12-19 06:27:08 +0000236 InVal = NewPHI;
237 } else {
238 // Remove all of the edges coming into the PHI nodes from outside of the
239 // block.
240 for (unsigned i = 0, e = Preds.size(); i != e; ++i)
241 PN->removeIncomingValue(Preds[i], false);
Chris Lattner010ba102003-12-09 23:12:55 +0000242 }
Chris Lattner0f98e752003-12-19 06:27:08 +0000243
244 // Add an incoming value to the PHI node in the loop for the preheader
245 // edge.
246 PN->addIncoming(InVal, NewBB);
Chris Lattner529b28d2004-04-13 05:05:33 +0000247
248 // Can we eliminate this phi node now?
249 if (Value *V = hasConstantValue(PN)) {
250 PN->replaceAllUsesWith(V);
251 BB->getInstList().erase(PN);
252 }
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000253 }
254
255 // Now that the PHI nodes are updated, actually move the edges from
256 // Preds to point to NewBB instead of BB.
257 //
258 for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
259 TerminatorInst *TI = Preds[i]->getTerminator();
260 for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s)
261 if (TI->getSuccessor(s) == BB)
262 TI->setSuccessor(s, NewBB);
263 }
264
265 } else { // Otherwise the loop is dead...
266 for (BasicBlock::iterator I = BB->begin();
Chris Lattnere408e252003-04-23 16:37:45 +0000267 PHINode *PN = dyn_cast<PHINode>(I); ++I)
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000268 // Insert dummy values as the incoming value...
269 PN->addIncoming(Constant::getNullValue(PN->getType()), NewBB);
270 }
271 return NewBB;
272}
273
Chris Lattner38acf9e2002-09-26 16:17:31 +0000274/// InsertPreheaderForLoop - Once we discover that a loop doesn't have a
275/// preheader, this method is called to insert one. This method has two phases:
276/// preheader insertion and analysis updating.
277///
Chris Lattneree2c50c2003-10-12 21:43:28 +0000278void LoopSimplify::InsertPreheaderForLoop(Loop *L) {
Chris Lattner38acf9e2002-09-26 16:17:31 +0000279 BasicBlock *Header = L->getHeader();
280
281 // Compute the set of predecessors of the loop that are not in the loop.
282 std::vector<BasicBlock*> OutsideBlocks;
283 for (pred_iterator PI = pred_begin(Header), PE = pred_end(Header);
284 PI != PE; ++PI)
285 if (!L->contains(*PI)) // Coming in from outside the loop?
286 OutsideBlocks.push_back(*PI); // Keep track of it...
287
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000288 // Split out the loop pre-header
289 BasicBlock *NewBB =
290 SplitBlockPredecessors(Header, ".preheader", OutsideBlocks);
Chris Lattner38acf9e2002-09-26 16:17:31 +0000291
Chris Lattner38acf9e2002-09-26 16:17:31 +0000292 //===--------------------------------------------------------------------===//
Misha Brukmancf00c4a2003-10-10 17:57:28 +0000293 // Update analysis results now that we have performed the transformation
Chris Lattner38acf9e2002-09-26 16:17:31 +0000294 //
295
296 // We know that we have loop information to update... update it now.
297 if (Loop *Parent = L->getParentLoop())
298 Parent->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>());
Chris Lattner9f879cf2003-02-27 22:48:57 +0000299
300 // If the header for the loop used to be an exit node for another loop, then
301 // we need to update this to know that the loop-preheader is now the exit
302 // node. Note that the only loop that could have our header as an exit node
Chris Lattner8f6396e2003-05-12 22:04:34 +0000303 // is a sibling loop, ie, one with the same parent loop, or one if it's
304 // children.
305 //
Chris Lattner329c1c62004-01-08 00:09:44 +0000306 LoopInfo::iterator ParentLoops, ParentLoopsE;
307 if (Loop *Parent = L->getParentLoop()) {
308 ParentLoops = Parent->begin();
309 ParentLoopsE = Parent->end();
310 } else { // Must check top-level loops...
311 ParentLoops = getAnalysis<LoopInfo>().begin();
312 ParentLoopsE = getAnalysis<LoopInfo>().end();
313 }
Chris Lattner9f879cf2003-02-27 22:48:57 +0000314
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000315 DominatorSet &DS = getAnalysis<DominatorSet>(); // Update dominator info
Chris Lattner786c5642004-03-13 22:01:26 +0000316 DominatorTree &DT = getAnalysis<DominatorTree>();
Chris Lattner85ebd542004-03-16 06:00:15 +0000317
318
319 // Update the dominator tree information.
320 // The immediate dominator of the preheader is the immediate dominator of
321 // the old header.
322 DominatorTree::Node *PHDomTreeNode =
323 DT.createNewNode(NewBB, DT.getNode(Header)->getIDom());
324
325 // Change the header node so that PNHode is the new immediate dominator
326 DT.changeImmediateDominator(DT.getNode(Header), PHDomTreeNode);
Chris Lattner786c5642004-03-13 22:01:26 +0000327
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000328 {
Chris Lattner38acf9e2002-09-26 16:17:31 +0000329 // The blocks that dominate NewBB are the blocks that dominate Header,
330 // minus Header, plus NewBB.
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000331 DominatorSet::DomSetType DomSet = DS.getDominators(Header);
Chris Lattner38acf9e2002-09-26 16:17:31 +0000332 DomSet.erase(Header); // Header does not dominate us...
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000333 DS.addBasicBlock(NewBB, DomSet);
Chris Lattner4d018922002-09-29 21:41:38 +0000334
335 // The newly created basic block dominates all nodes dominated by Header.
Chris Lattner85ebd542004-03-16 06:00:15 +0000336 for (df_iterator<DominatorTree::Node*> DFI = df_begin(PHDomTreeNode),
337 E = df_end(PHDomTreeNode); DFI != E; ++DFI)
338 DS.addDominator((*DFI)->getBlock(), NewBB);
Chris Lattner38acf9e2002-09-26 16:17:31 +0000339 }
340
341 // Update immediate dominator information if we have it...
342 if (ImmediateDominators *ID = getAnalysisToUpdate<ImmediateDominators>()) {
343 // Whatever i-dominated the header node now immediately dominates NewBB
344 ID->addNewBlock(NewBB, ID->get(Header));
345
346 // The preheader now is the immediate dominator for the header node...
347 ID->setImmediateDominator(Header, NewBB);
348 }
349
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000350 // Update dominance frontier information...
351 if (DominanceFrontier *DF = getAnalysisToUpdate<DominanceFrontier>()) {
352 // The DF(NewBB) is just (DF(Header)-Header), because NewBB dominates
353 // everything that Header does, and it strictly dominates Header in
354 // addition.
355 assert(DF->find(Header) != DF->end() && "Header node doesn't have DF set?");
356 DominanceFrontier::DomSetType NewDFSet = DF->find(Header)->second;
357 NewDFSet.erase(Header);
358 DF->addBasicBlock(NewBB, NewDFSet);
359
360 // Now we must loop over all of the dominance frontiers in the function,
Misha Brukmandfa5f832003-09-09 21:54:45 +0000361 // replacing occurrences of Header with NewBB in some cases. If a block
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000362 // dominates a (now) predecessor of NewBB, but did not strictly dominate
363 // Header, it will have Header in it's DF set, but should now have NewBB in
364 // its set.
365 for (unsigned i = 0, e = OutsideBlocks.size(); i != e; ++i) {
366 // Get all of the dominators of the predecessor...
367 const DominatorSet::DomSetType &PredDoms =
368 DS.getDominators(OutsideBlocks[i]);
369 for (DominatorSet::DomSetType::const_iterator PDI = PredDoms.begin(),
370 PDE = PredDoms.end(); PDI != PDE; ++PDI) {
371 BasicBlock *PredDom = *PDI;
372 // If the loop header is in DF(PredDom), then PredDom didn't dominate
373 // the header but did dominate a predecessor outside of the loop. Now
374 // we change this entry to include the preheader in the DF instead of
375 // the header.
376 DominanceFrontier::iterator DFI = DF->find(PredDom);
377 assert(DFI != DF->end() && "No dominance frontier for node?");
378 if (DFI->second.count(Header)) {
379 DF->removeFromFrontier(DFI, Header);
380 DF->addToFrontier(DFI, NewBB);
381 }
382 }
383 }
384 }
385}
386
Chris Lattner529b28d2004-04-13 05:05:33 +0000387/// RewriteLoopExitBlock - Ensure that the loop preheader dominates all exit
388/// blocks. This method is used to split exit blocks that have predecessors
389/// outside of the loop.
Chris Lattneree2c50c2003-10-12 21:43:28 +0000390void LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) {
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000391 DominatorSet &DS = getAnalysis<DominatorSet>();
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000392
393 std::vector<BasicBlock*> LoopBlocks;
394 for (pred_iterator I = pred_begin(Exit), E = pred_end(Exit); I != E; ++I)
395 if (L->contains(*I))
396 LoopBlocks.push_back(*I);
397
Chris Lattner7e7ad492003-02-27 22:31:07 +0000398 assert(!LoopBlocks.empty() && "No edges coming in from outside the loop?");
399 BasicBlock *NewBB = SplitBlockPredecessors(Exit, ".loopexit", LoopBlocks);
400
Chris Lattner69269ac2003-02-27 21:50:19 +0000401 // Update Loop Information - we know that the new block will be in the parent
402 // loop of L.
403 if (Loop *Parent = L->getParentLoop())
404 Parent->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>());
Chris Lattner74cd04e2003-02-28 03:07:54 +0000405
Chris Lattner2ab6a732003-10-13 00:37:13 +0000406 // Update dominator information (set, immdom, domtree, and domfrontier)
407 UpdateDomInfoForRevectoredPreds(NewBB, LoopBlocks);
408}
409
Chris Lattner529b28d2004-04-13 05:05:33 +0000410/// AddBlockAndPredsToSet - Add the specified block, and all of its
411/// predecessors, to the specified set, if it's not already in there. Stop
412/// predecessor traversal when we reach StopBlock.
413static void AddBlockAndPredsToSet(BasicBlock *BB, BasicBlock *StopBlock,
414 std::set<BasicBlock*> &Blocks) {
415 if (!Blocks.insert(BB).second) return; // already processed.
416 if (BB == StopBlock) return; // Stop here!
417
418 for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I)
419 AddBlockAndPredsToSet(*I, StopBlock, Blocks);
420}
421
Chris Lattner1f62f822004-04-13 15:21:18 +0000422/// FindPHIToPartitionLoops - The first part of loop-nestification is to find a
423/// PHI node that tells us how to partition the loops.
424static PHINode *FindPHIToPartitionLoops(Loop *L) {
425 for (BasicBlock::iterator I = L->getHeader()->begin();
426 PHINode *PN = dyn_cast<PHINode>(I); ) {
427 ++I;
428 if (Value *V = hasConstantValue(PN)) {
429 // This is a degenerate PHI already, don't modify it!
430 PN->replaceAllUsesWith(V);
431 PN->getParent()->getInstList().erase(PN);
432 } else {
433 // Scan this PHI node looking for a use of the PHI node by itself.
434 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
435 if (PN->getIncomingValue(i) == PN &&
436 L->contains(PN->getIncomingBlock(i)))
437 // We found something tasty to remove.
438 return PN;
439 }
440 }
441 return 0;
442}
443
Chris Lattner529b28d2004-04-13 05:05:33 +0000444/// SeparateNestedLoop - If this loop has multiple backedges, try to pull one of
445/// them out into a nested loop. This is important for code that looks like
446/// this:
447///
448/// Loop:
449/// ...
450/// br cond, Loop, Next
451/// ...
452/// br cond2, Loop, Out
453///
454/// To identify this common case, we look at the PHI nodes in the header of the
455/// loop. PHI nodes with unchanging values on one backedge correspond to values
456/// that change in the "outer" loop, but not in the "inner" loop.
457///
458/// If we are able to separate out a loop, return the new outer loop that was
459/// created.
460///
461Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
Chris Lattner1f62f822004-04-13 15:21:18 +0000462 PHINode *PN = FindPHIToPartitionLoops(L);
463 if (PN == 0) return 0; // No known way to partition.
Chris Lattner529b28d2004-04-13 05:05:33 +0000464
Chris Lattner1f62f822004-04-13 15:21:18 +0000465 // Pull out all predecessors that have varying values in the loop. This
466 // handles the case when a PHI node has multiple instances of itself as
467 // arguments.
Chris Lattner529b28d2004-04-13 05:05:33 +0000468 std::vector<BasicBlock*> OuterLoopPreds;
Chris Lattner1f62f822004-04-13 15:21:18 +0000469 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
470 if (PN->getIncomingValue(i) != PN ||
471 !L->contains(PN->getIncomingBlock(i)))
472 OuterLoopPreds.push_back(PN->getIncomingBlock(i));
Chris Lattner529b28d2004-04-13 05:05:33 +0000473
Chris Lattner4b662422004-04-13 16:23:25 +0000474 BasicBlock *Header = L->getHeader();
Chris Lattner529b28d2004-04-13 05:05:33 +0000475 BasicBlock *NewBB = SplitBlockPredecessors(Header, ".outer", OuterLoopPreds);
476
477 // Update dominator information (set, immdom, domtree, and domfrontier)
478 UpdateDomInfoForRevectoredPreds(NewBB, OuterLoopPreds);
479
480 // Create the new outer loop.
481 Loop *NewOuter = new Loop();
482
483 LoopInfo &LI = getAnalysis<LoopInfo>();
484
485 // Change the parent loop to use the outer loop as its child now.
486 if (Loop *Parent = L->getParentLoop())
487 Parent->replaceChildLoopWith(L, NewOuter);
488 else
489 LI.changeTopLevelLoop(L, NewOuter);
490
491 // This block is going to be our new header block: add it to this loop and all
492 // parent loops.
493 NewOuter->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>());
494
495 // L is now a subloop of our outer loop.
496 NewOuter->addChildLoop(L);
497
Chris Lattner529b28d2004-04-13 05:05:33 +0000498 for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i)
499 NewOuter->addBlockEntry(L->getBlocks()[i]);
500
501 // Determine which blocks should stay in L and which should be moved out to
502 // the Outer loop now.
503 DominatorSet &DS = getAnalysis<DominatorSet>();
504 std::set<BasicBlock*> BlocksInL;
505 for (pred_iterator PI = pred_begin(Header), E = pred_end(Header); PI!=E; ++PI)
506 if (DS.dominates(Header, *PI))
507 AddBlockAndPredsToSet(*PI, Header, BlocksInL);
508
509
510 // Scan all of the loop children of L, moving them to OuterLoop if they are
511 // not part of the inner loop.
512 for (Loop::iterator I = L->begin(); I != L->end(); )
513 if (BlocksInL.count((*I)->getHeader()))
514 ++I; // Loop remains in L
515 else
516 NewOuter->addChildLoop(L->removeChildLoop(I));
517
518 // Now that we know which blocks are in L and which need to be moved to
519 // OuterLoop, move any blocks that need it.
520 for (unsigned i = 0; i != L->getBlocks().size(); ++i) {
521 BasicBlock *BB = L->getBlocks()[i];
522 if (!BlocksInL.count(BB)) {
523 // Move this block to the parent, updating the exit blocks sets
524 L->removeBlockFromLoop(BB);
525 if (LI[BB] == L)
526 LI.changeLoopFor(BB, NewOuter);
527 --i;
528 }
529 }
530
Chris Lattner529b28d2004-04-13 05:05:33 +0000531 return NewOuter;
532}
533
534
535
Chris Lattner2ab6a732003-10-13 00:37:13 +0000536/// InsertUniqueBackedgeBlock - This method is called when the specified loop
537/// has more than one backedge in it. If this occurs, revector all of these
538/// backedges to target a new basic block and have that block branch to the loop
539/// header. This ensures that loops have exactly one backedge.
540///
541void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) {
542 assert(L->getNumBackEdges() > 1 && "Must have > 1 backedge!");
543
544 // Get information about the loop
545 BasicBlock *Preheader = L->getLoopPreheader();
546 BasicBlock *Header = L->getHeader();
547 Function *F = Header->getParent();
548
549 // Figure out which basic blocks contain back-edges to the loop header.
550 std::vector<BasicBlock*> BackedgeBlocks;
551 for (pred_iterator I = pred_begin(Header), E = pred_end(Header); I != E; ++I)
552 if (*I != Preheader) BackedgeBlocks.push_back(*I);
553
554 // Create and insert the new backedge block...
555 BasicBlock *BEBlock = new BasicBlock(Header->getName()+".backedge", F);
Chris Lattner108e4ab2003-11-21 16:52:05 +0000556 BranchInst *BETerminator = new BranchInst(Header, BEBlock);
Chris Lattner2ab6a732003-10-13 00:37:13 +0000557
558 // Move the new backedge block to right after the last backedge block.
559 Function::iterator InsertPos = BackedgeBlocks.back(); ++InsertPos;
560 F->getBasicBlockList().splice(InsertPos, F->getBasicBlockList(), BEBlock);
561
562 // Now that the block has been inserted into the function, create PHI nodes in
563 // the backedge block which correspond to any PHI nodes in the header block.
564 for (BasicBlock::iterator I = Header->begin();
565 PHINode *PN = dyn_cast<PHINode>(I); ++I) {
566 PHINode *NewPN = new PHINode(PN->getType(), PN->getName()+".be",
567 BETerminator);
568 NewPN->op_reserve(2*BackedgeBlocks.size());
569
570 // Loop over the PHI node, moving all entries except the one for the
571 // preheader over to the new PHI node.
572 unsigned PreheaderIdx = ~0U;
573 bool HasUniqueIncomingValue = true;
574 Value *UniqueValue = 0;
575 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
576 BasicBlock *IBB = PN->getIncomingBlock(i);
577 Value *IV = PN->getIncomingValue(i);
578 if (IBB == Preheader) {
579 PreheaderIdx = i;
580 } else {
581 NewPN->addIncoming(IV, IBB);
582 if (HasUniqueIncomingValue) {
583 if (UniqueValue == 0)
584 UniqueValue = IV;
585 else if (UniqueValue != IV)
586 HasUniqueIncomingValue = false;
587 }
588 }
589 }
590
591 // Delete all of the incoming values from the old PN except the preheader's
592 assert(PreheaderIdx != ~0U && "PHI has no preheader entry??");
593 if (PreheaderIdx != 0) {
594 PN->setIncomingValue(0, PN->getIncomingValue(PreheaderIdx));
595 PN->setIncomingBlock(0, PN->getIncomingBlock(PreheaderIdx));
596 }
597 PN->op_erase(PN->op_begin()+2, PN->op_end());
598
599 // Finally, add the newly constructed PHI node as the entry for the BEBlock.
600 PN->addIncoming(NewPN, BEBlock);
601
602 // As an optimization, if all incoming values in the new PhiNode (which is a
603 // subset of the incoming values of the old PHI node) have the same value,
604 // eliminate the PHI Node.
605 if (HasUniqueIncomingValue) {
606 NewPN->replaceAllUsesWith(UniqueValue);
607 BEBlock->getInstList().erase(NewPN);
608 }
609 }
610
611 // Now that all of the PHI nodes have been inserted and adjusted, modify the
612 // backedge blocks to just to the BEBlock instead of the header.
613 for (unsigned i = 0, e = BackedgeBlocks.size(); i != e; ++i) {
614 TerminatorInst *TI = BackedgeBlocks[i]->getTerminator();
615 for (unsigned Op = 0, e = TI->getNumSuccessors(); Op != e; ++Op)
616 if (TI->getSuccessor(Op) == Header)
617 TI->setSuccessor(Op, BEBlock);
618 }
619
620 //===--- Update all analyses which we must preserve now -----------------===//
621
622 // Update Loop Information - we know that this block is now in the current
623 // loop and all parent loops.
624 L->addBasicBlockToLoop(BEBlock, getAnalysis<LoopInfo>());
625
Chris Lattner2ab6a732003-10-13 00:37:13 +0000626 // Update dominator information (set, immdom, domtree, and domfrontier)
627 UpdateDomInfoForRevectoredPreds(BEBlock, BackedgeBlocks);
628}
629
630/// UpdateDomInfoForRevectoredPreds - This method is used to update the four
631/// different kinds of dominator information (dominator sets, immediate
632/// dominators, dominator trees, and dominance frontiers) after a new block has
633/// been added to the CFG.
634///
Chris Lattner4f02fc22004-02-05 21:12:24 +0000635/// This only supports the case when an existing block (known as "NewBBSucc"),
636/// had some of its predecessors factored into a new basic block. This
Chris Lattner2ab6a732003-10-13 00:37:13 +0000637/// transformation inserts a new basic block ("NewBB"), with a single
Chris Lattner4f02fc22004-02-05 21:12:24 +0000638/// unconditional branch to NewBBSucc, and moves some predecessors of
639/// "NewBBSucc" to now branch to NewBB. These predecessors are listed in
640/// PredBlocks, even though they are the same as
641/// pred_begin(NewBB)/pred_end(NewBB).
Chris Lattner2ab6a732003-10-13 00:37:13 +0000642///
643void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
644 std::vector<BasicBlock*> &PredBlocks) {
Chris Lattner4f02fc22004-02-05 21:12:24 +0000645 assert(!PredBlocks.empty() && "No predblocks??");
Chris Lattner2ab6a732003-10-13 00:37:13 +0000646 assert(succ_begin(NewBB) != succ_end(NewBB) &&
647 ++succ_begin(NewBB) == succ_end(NewBB) &&
648 "NewBB should have a single successor!");
Chris Lattner4f02fc22004-02-05 21:12:24 +0000649 BasicBlock *NewBBSucc = *succ_begin(NewBB);
Chris Lattner2ab6a732003-10-13 00:37:13 +0000650 DominatorSet &DS = getAnalysis<DominatorSet>();
651
Chris Lattner4f303bd2004-04-01 19:06:07 +0000652 // Update dominator information... The blocks that dominate NewBB are the
653 // intersection of the dominators of predecessors, plus the block itself.
654 //
655 DominatorSet::DomSetType NewBBDomSet = DS.getDominators(PredBlocks[0]);
656 for (unsigned i = 1, e = PredBlocks.size(); i != e; ++i)
657 set_intersect(NewBBDomSet, DS.getDominators(PredBlocks[i]));
658 NewBBDomSet.insert(NewBB); // All blocks dominate themselves...
659 DS.addBasicBlock(NewBB, NewBBDomSet);
660
Chris Lattner4f02fc22004-02-05 21:12:24 +0000661 // The newly inserted basic block will dominate existing basic blocks iff the
662 // PredBlocks dominate all of the non-pred blocks. If all predblocks dominate
663 // the non-pred blocks, then they all must be the same block!
Chris Lattner4f303bd2004-04-01 19:06:07 +0000664 //
Chris Lattner4f02fc22004-02-05 21:12:24 +0000665 bool NewBBDominatesNewBBSucc = true;
666 {
667 BasicBlock *OnePred = PredBlocks[0];
668 for (unsigned i = 1, e = PredBlocks.size(); i != e; ++i)
669 if (PredBlocks[i] != OnePred) {
670 NewBBDominatesNewBBSucc = false;
671 break;
672 }
673
674 if (NewBBDominatesNewBBSucc)
675 for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
676 PI != E; ++PI)
Chris Lattner99dcc1d2004-02-05 23:20:59 +0000677 if (*PI != NewBB && !DS.dominates(NewBBSucc, *PI)) {
Chris Lattner4f02fc22004-02-05 21:12:24 +0000678 NewBBDominatesNewBBSucc = false;
679 break;
680 }
681 }
682
Chris Lattner4f303bd2004-04-01 19:06:07 +0000683 // The other scenario where the new block can dominate its successors are when
684 // all predecessors of NewBBSucc that are not NewBB are dominated by NewBBSucc
685 // already.
686 if (!NewBBDominatesNewBBSucc) {
687 NewBBDominatesNewBBSucc = true;
688 for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
689 PI != E; ++PI)
690 if (*PI != NewBB && !DS.dominates(NewBBSucc, *PI)) {
691 NewBBDominatesNewBBSucc = false;
692 break;
693 }
694 }
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000695
Chris Lattner4f02fc22004-02-05 21:12:24 +0000696 // If NewBB dominates some blocks, then it will dominate all blocks that
Chris Lattner3e0b8702004-02-05 22:33:26 +0000697 // NewBBSucc does.
Chris Lattner4f02fc22004-02-05 21:12:24 +0000698 if (NewBBDominatesNewBBSucc) {
699 BasicBlock *PredBlock = PredBlocks[0];
700 Function *F = NewBB->getParent();
701 for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
Chris Lattner3e0b8702004-02-05 22:33:26 +0000702 if (DS.dominates(NewBBSucc, I))
Chris Lattner4f02fc22004-02-05 21:12:24 +0000703 DS.addDominator(I, NewBB);
704 }
705
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000706 // Update immediate dominator information if we have it...
707 BasicBlock *NewBBIDom = 0;
708 if (ImmediateDominators *ID = getAnalysisToUpdate<ImmediateDominators>()) {
Chris Lattner4f02fc22004-02-05 21:12:24 +0000709 // To find the immediate dominator of the new exit node, we trace up the
710 // immediate dominators of a predecessor until we find a basic block that
711 // dominates the exit block.
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000712 //
Chris Lattner2ab6a732003-10-13 00:37:13 +0000713 BasicBlock *Dom = PredBlocks[0]; // Some random predecessor...
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000714 while (!NewBBDomSet.count(Dom)) { // Loop until we find a dominator...
715 assert(Dom != 0 && "No shared dominator found???");
716 Dom = ID->get(Dom);
717 }
718
719 // Set the immediate dominator now...
720 ID->addNewBlock(NewBB, Dom);
721 NewBBIDom = Dom; // Reuse this if calculating DominatorTree info...
Chris Lattner4f02fc22004-02-05 21:12:24 +0000722
723 // If NewBB strictly dominates other blocks, we need to update their idom's
724 // now. The only block that need adjustment is the NewBBSucc block, whose
725 // idom should currently be set to PredBlocks[0].
Chris Lattner4edf6c02004-04-01 19:21:46 +0000726 if (NewBBDominatesNewBBSucc)
Chris Lattner4f02fc22004-02-05 21:12:24 +0000727 ID->setImmediateDominator(NewBBSucc, NewBB);
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000728 }
729
730 // Update DominatorTree information if it is active.
731 if (DominatorTree *DT = getAnalysisToUpdate<DominatorTree>()) {
Chris Lattner4f02fc22004-02-05 21:12:24 +0000732 // If we don't have ImmediateDominator info around, calculate the idom as
733 // above.
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000734 DominatorTree::Node *NewBBIDomNode;
735 if (NewBBIDom) {
736 NewBBIDomNode = DT->getNode(NewBBIDom);
737 } else {
Chris Lattner2ab6a732003-10-13 00:37:13 +0000738 NewBBIDomNode = DT->getNode(PredBlocks[0]); // Random pred
Chris Lattnerc444a422003-09-11 16:26:13 +0000739 while (!NewBBDomSet.count(NewBBIDomNode->getBlock())) {
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000740 NewBBIDomNode = NewBBIDomNode->getIDom();
741 assert(NewBBIDomNode && "No shared dominator found??");
742 }
743 }
744
Chris Lattner4f02fc22004-02-05 21:12:24 +0000745 // Create the new dominator tree node... and set the idom of NewBB.
746 DominatorTree::Node *NewBBNode = DT->createNewNode(NewBB, NewBBIDomNode);
747
748 // If NewBB strictly dominates other blocks, then it is now the immediate
749 // dominator of NewBBSucc. Update the dominator tree as appropriate.
750 if (NewBBDominatesNewBBSucc) {
751 DominatorTree::Node *NewBBSuccNode = DT->getNode(NewBBSucc);
Chris Lattner4f02fc22004-02-05 21:12:24 +0000752 DT->changeImmediateDominator(NewBBSuccNode, NewBBNode);
753 }
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000754 }
755
756 // Update dominance frontier information...
757 if (DominanceFrontier *DF = getAnalysisToUpdate<DominanceFrontier>()) {
Chris Lattner4b662422004-04-13 16:23:25 +0000758 // If NewBB dominates NewBBSucc, then DF(NewBB) is now going to be the
759 // DF(PredBlocks[0]) without the stuff that the new block does not dominate
760 // a predecessor of.
Chris Lattner4f02fc22004-02-05 21:12:24 +0000761 if (NewBBDominatesNewBBSucc) {
762 DominanceFrontier::iterator DFI = DF->find(PredBlocks[0]);
763 if (DFI != DF->end()) {
764 DominanceFrontier::DomSetType Set = DFI->second;
765 // Filter out stuff in Set that we do not dominate a predecessor of.
766 for (DominanceFrontier::DomSetType::iterator SetI = Set.begin(),
767 E = Set.end(); SetI != E;) {
768 bool DominatesPred = false;
769 for (pred_iterator PI = pred_begin(*SetI), E = pred_end(*SetI);
770 PI != E; ++PI)
771 if (DS.dominates(NewBB, *PI))
772 DominatesPred = true;
773 if (!DominatesPred)
774 Set.erase(SetI++);
775 else
776 ++SetI;
777 }
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000778
Chris Lattner4f02fc22004-02-05 21:12:24 +0000779 DF->addBasicBlock(NewBB, Set);
780 }
781
782 } else {
783 // DF(NewBB) is {NewBBSucc} because NewBB does not strictly dominate
784 // NewBBSucc, but it does dominate itself (and there is an edge (NewBB ->
785 // NewBBSucc)). NewBBSucc is the single successor of NewBB.
786 DominanceFrontier::DomSetType NewDFSet;
787 NewDFSet.insert(NewBBSucc);
788 DF->addBasicBlock(NewBB, NewDFSet);
Chris Lattner4b662422004-04-13 16:23:25 +0000789 }
Chris Lattner2ab6a732003-10-13 00:37:13 +0000790
Chris Lattner4b662422004-04-13 16:23:25 +0000791 // Now we must loop over all of the dominance frontiers in the function,
792 // replacing occurrences of NewBBSucc with NewBB in some cases. All
793 // blocks that dominate a block in PredBlocks and contained NewBBSucc in
794 // their dominance frontier must be updated to contain NewBB instead.
795 //
796 for (unsigned i = 0, e = PredBlocks.size(); i != e; ++i) {
797 BasicBlock *Pred = PredBlocks[i];
798 // Get all of the dominators of the predecessor...
799 const DominatorSet::DomSetType &PredDoms = DS.getDominators(Pred);
800 for (DominatorSet::DomSetType::const_iterator PDI = PredDoms.begin(),
801 PDE = PredDoms.end(); PDI != PDE; ++PDI) {
802 BasicBlock *PredDom = *PDI;
803
804 // If the NewBBSucc node is in DF(PredDom), then PredDom didn't
805 // dominate NewBBSucc but did dominate a predecessor of it. Now we
806 // change this entry to include NewBB in the DF instead of NewBBSucc.
807 DominanceFrontier::iterator DFI = DF->find(PredDom);
808 assert(DFI != DF->end() && "No dominance frontier for node?");
809 if (DFI->second.count(NewBBSucc)) {
810 // If NewBBSucc should not stay in our dominator frontier, remove it.
811 // We remove it unless there is a predecessor of NewBBSucc that we
812 // dominate, but we don't strictly dominate NewBBSucc.
813 bool ShouldRemove = true;
814 if (PredDom == NewBBSucc || !DS.dominates(PredDom, NewBBSucc)) {
815 // Okay, we know that PredDom does not strictly dominate NewBBSucc.
816 // Check to see if it dominates any predecessors of NewBBSucc.
817 for (pred_iterator PI = pred_begin(NewBBSucc),
818 E = pred_end(NewBBSucc); PI != E; ++PI)
819 if (DS.dominates(PredDom, *PI)) {
820 ShouldRemove = false;
821 break;
822 }
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000823 }
Chris Lattner4b662422004-04-13 16:23:25 +0000824
825 if (ShouldRemove)
826 DF->removeFromFrontier(DFI, NewBBSucc);
827 DF->addToFrontier(DFI, NewBB);
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000828 }
829 }
830 }
Chris Lattnerdbf3cd72003-02-27 20:27:08 +0000831 }
Chris Lattner38acf9e2002-09-26 16:17:31 +0000832}
Brian Gaeked0fde302003-11-11 22:41:34 +0000833