2002-09-24 00:08:39 +00:00
|
|
|
//===- BreakCriticalEdges.cpp - Critical Edge Elimination Pass ------------===//
|
2005-04-21 23:48:37 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 23:48:37 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-09-24 00:08:39 +00:00
|
|
|
//
|
|
|
|
// BreakCriticalEdges pass - Break all of the critical edges in the CFG by
|
|
|
|
// inserting a dummy basic block. This pass may be "required" by passes that
|
|
|
|
// cannot deal with critical edges. For this usage, the structure type is
|
|
|
|
// forward declared. This pass obviously invalidates the CFG, but can update
|
2003-11-10 04:42:42 +00:00
|
|
|
// forward dominator (set, immediate dominators, tree, and frontier)
|
|
|
|
// information.
|
2002-09-24 00:08:39 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-12-19 22:17:40 +00:00
|
|
|
#define DEBUG_TYPE "break-crit-edges"
|
2002-09-24 00:08:39 +00:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2003-11-10 04:10:50 +00:00
|
|
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
2002-09-24 00:08:39 +00:00
|
|
|
#include "llvm/Analysis/Dominators.h"
|
2005-08-13 01:38:43 +00:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
2002-09-24 00:08:39 +00:00
|
|
|
#include "llvm/Function.h"
|
2004-07-29 17:30:56 +00:00
|
|
|
#include "llvm/Instructions.h"
|
2005-03-17 15:38:16 +00:00
|
|
|
#include "llvm/Type.h"
|
2002-09-24 15:51:56 +00:00
|
|
|
#include "llvm/Support/CFG.h"
|
2006-08-27 12:54:02 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2006-10-03 07:02:02 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2004-01-09 06:12:26 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2006-12-19 22:17:40 +00:00
|
|
|
STATISTIC(NumBroken, "Number of blocks inserted");
|
2002-09-24 15:43:12 +00:00
|
|
|
|
2006-12-19 22:17:40 +00:00
|
|
|
namespace {
|
2006-06-28 23:17:24 +00:00
|
|
|
struct VISIBILITY_HIDDEN BreakCriticalEdges : public FunctionPass {
|
2002-09-24 15:43:12 +00:00
|
|
|
virtual bool runOnFunction(Function &F);
|
2005-04-21 23:48:37 +00:00
|
|
|
|
2002-09-24 15:43:12 +00:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
2006-01-11 05:11:13 +00:00
|
|
|
AU.addPreserved<ETForest>();
|
2002-09-24 15:43:12 +00:00
|
|
|
AU.addPreserved<DominatorSet>();
|
|
|
|
AU.addPreserved<ImmediateDominators>();
|
|
|
|
AU.addPreserved<DominatorTree>();
|
2002-10-31 02:44:36 +00:00
|
|
|
AU.addPreserved<DominanceFrontier>();
|
2005-08-13 01:38:43 +00:00
|
|
|
AU.addPreserved<LoopInfo>();
|
2003-10-12 21:52:28 +00:00
|
|
|
|
|
|
|
// No loop canonicalization guarantees are broken by this pass.
|
|
|
|
AU.addPreservedID(LoopSimplifyID);
|
2002-09-24 15:43:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-08-27 22:42:52 +00:00
|
|
|
RegisterPass<BreakCriticalEdges> X("break-crit-edges",
|
2002-09-24 15:43:12 +00:00
|
|
|
"Break critical edges in CFG");
|
|
|
|
}
|
2002-09-24 00:08:39 +00:00
|
|
|
|
2002-09-24 15:51:56 +00:00
|
|
|
// Publically exposed interface to pass...
|
2004-01-09 06:12:26 +00:00
|
|
|
const PassInfo *llvm::BreakCriticalEdgesID = X.getPassInfo();
|
2004-07-31 10:01:58 +00:00
|
|
|
FunctionPass *llvm::createBreakCriticalEdgesPass() {
|
|
|
|
return new BreakCriticalEdges();
|
|
|
|
}
|
2002-09-24 00:08:39 +00:00
|
|
|
|
2003-11-10 04:42:42 +00:00
|
|
|
// runOnFunction - Loop over all of the edges in the CFG, breaking critical
|
|
|
|
// edges as they are found.
|
|
|
|
//
|
|
|
|
bool BreakCriticalEdges::runOnFunction(Function &F) {
|
|
|
|
bool Changed = false;
|
|
|
|
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
|
|
|
|
TerminatorInst *TI = I->getTerminator();
|
|
|
|
if (TI->getNumSuccessors() > 1)
|
|
|
|
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
|
|
|
|
if (SplitCriticalEdge(TI, i, this)) {
|
|
|
|
++NumBroken;
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Implementation of the external critical edge manipulation functions
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-09-24 15:51:56 +00:00
|
|
|
|
|
|
|
// isCriticalEdge - Return true if the specified edge is a critical edge.
|
|
|
|
// Critical edges are edges from a block with multiple successors to a block
|
|
|
|
// with multiple predecessors.
|
|
|
|
//
|
2006-10-28 06:58:17 +00:00
|
|
|
bool llvm::isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum,
|
|
|
|
bool AllowIdenticalEdges) {
|
2002-09-24 15:51:56 +00:00
|
|
|
assert(SuccNum < TI->getNumSuccessors() && "Illegal edge specification!");
|
2002-10-08 21:06:27 +00:00
|
|
|
if (TI->getNumSuccessors() == 1) return false;
|
2002-09-24 15:51:56 +00:00
|
|
|
|
|
|
|
const BasicBlock *Dest = TI->getSuccessor(SuccNum);
|
|
|
|
pred_const_iterator I = pred_begin(Dest), E = pred_end(Dest);
|
|
|
|
|
|
|
|
// If there is more than one predecessor, this is a critical edge...
|
|
|
|
assert(I != E && "No preds, but we have an edge to the block?");
|
2006-10-28 06:58:17 +00:00
|
|
|
const BasicBlock *FirstPred = *I;
|
2002-09-24 15:51:56 +00:00
|
|
|
++I; // Skip one edge due to the incoming arc from TI.
|
2006-10-28 06:58:17 +00:00
|
|
|
if (!AllowIdenticalEdges)
|
|
|
|
return I != E;
|
|
|
|
|
|
|
|
// If AllowIdenticalEdges is true, then we allow this edge to be considered
|
|
|
|
// non-critical iff all preds come from TI's block.
|
|
|
|
for (; I != E; ++I)
|
|
|
|
if (*I != FirstPred) return true;
|
|
|
|
return false;
|
2002-09-24 15:51:56 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 04:10:50 +00:00
|
|
|
// SplitCriticalEdge - If this edge is a critical edge, insert a new node to
|
|
|
|
// split the critical edge. This will update DominatorSet, ImmediateDominator,
|
|
|
|
// DominatorTree, and DominatorFrontier information if it is available, thus
|
2006-10-28 06:44:56 +00:00
|
|
|
// calling this pass will not invalidate any of them. This returns true if
|
|
|
|
// the edge was split, false otherwise. This ensures that all edges to that
|
|
|
|
// dest go to one block instead of each going to a different block.
|
2002-09-24 15:51:56 +00:00
|
|
|
//
|
2006-10-28 06:44:56 +00:00
|
|
|
bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P,
|
|
|
|
bool MergeIdenticalEdges) {
|
2006-10-28 06:58:17 +00:00
|
|
|
if (!isCriticalEdge(TI, SuccNum, MergeIdenticalEdges)) return false;
|
2002-09-24 15:51:56 +00:00
|
|
|
BasicBlock *TIBB = TI->getParent();
|
2002-10-31 02:44:36 +00:00
|
|
|
BasicBlock *DestBB = TI->getSuccessor(SuccNum);
|
2002-09-24 15:51:56 +00:00
|
|
|
|
|
|
|
// Create a new basic block, linking it into the CFG.
|
2002-10-31 02:44:36 +00:00
|
|
|
BasicBlock *NewBB = new BasicBlock(TIBB->getName() + "." +
|
|
|
|
DestBB->getName() + "_crit_edge");
|
2002-09-24 15:51:56 +00:00
|
|
|
// Create our unconditional branch...
|
2003-11-21 16:52:05 +00:00
|
|
|
new BranchInst(DestBB, NewBB);
|
2005-04-21 23:48:37 +00:00
|
|
|
|
2006-10-28 06:44:56 +00:00
|
|
|
// Branch to the new block, breaking the edge.
|
2002-09-24 15:51:56 +00:00
|
|
|
TI->setSuccessor(SuccNum, NewBB);
|
|
|
|
|
|
|
|
// Insert the block into the function... right after the block TI lives in.
|
|
|
|
Function &F = *TIBB->getParent();
|
|
|
|
F.getBasicBlockList().insert(TIBB->getNext(), NewBB);
|
2006-10-28 06:44:56 +00:00
|
|
|
|
2002-09-24 15:51:56 +00:00
|
|
|
// If there are any PHI nodes in DestBB, we need to update them so that they
|
|
|
|
// merge incoming values from NewBB instead of from TIBB.
|
|
|
|
//
|
2004-09-15 17:06:42 +00:00
|
|
|
for (BasicBlock::iterator I = DestBB->begin(); isa<PHINode>(I); ++I) {
|
|
|
|
PHINode *PN = cast<PHINode>(I);
|
2004-02-29 22:24:41 +00:00
|
|
|
// We no longer enter through TIBB, now we come in through NewBB. Revector
|
|
|
|
// exactly one entry in the PHI node that used to come from TIBB to come
|
|
|
|
// from NewBB.
|
2005-08-12 21:58:07 +00:00
|
|
|
int BBIdx = PN->getBasicBlockIndex(TIBB);
|
|
|
|
PN->setIncomingBlock(BBIdx, NewBB);
|
2002-09-24 15:51:56 +00:00
|
|
|
}
|
2006-10-28 06:44:56 +00:00
|
|
|
|
|
|
|
// If there are any other edges from TIBB to DestBB, update those to go
|
|
|
|
// through the split block, making those edges non-critical as well (and
|
|
|
|
// reducing the number of phi entries in the DestBB if relevant).
|
|
|
|
if (MergeIdenticalEdges) {
|
|
|
|
for (unsigned i = SuccNum+1, e = TI->getNumSuccessors(); i != e; ++i) {
|
|
|
|
if (TI->getSuccessor(i) != DestBB) continue;
|
|
|
|
|
|
|
|
// Remove an entry for TIBB from DestBB phi nodes.
|
|
|
|
DestBB->removePredecessor(TIBB);
|
|
|
|
|
|
|
|
// We found another edge to DestBB, go to NewBB instead.
|
|
|
|
TI->setSuccessor(i, NewBB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-24 15:51:56 +00:00
|
|
|
|
2002-10-08 21:06:27 +00:00
|
|
|
// If we don't have a pass object, we can't update anything...
|
2003-11-10 04:10:50 +00:00
|
|
|
if (P == 0) return true;
|
2002-10-08 21:06:27 +00:00
|
|
|
|
2006-10-03 07:02:02 +00:00
|
|
|
// Now update analysis information. Since the only predecessor of NewBB is
|
|
|
|
// the TIBB, TIBB clearly dominates NewBB. TIBB usually doesn't dominate
|
|
|
|
// anything, as there are other successors of DestBB. However, if all other
|
|
|
|
// predecessors of DestBB are already dominated by DestBB (e.g. DestBB is a
|
|
|
|
// loop header) then NewBB dominates DestBB.
|
|
|
|
SmallVector<BasicBlock*, 8> OtherPreds;
|
2002-09-24 15:51:56 +00:00
|
|
|
|
2006-10-03 07:02:02 +00:00
|
|
|
for (pred_iterator I = pred_begin(DestBB), E = pred_end(DestBB); I != E; ++I)
|
|
|
|
if (*I != NewBB)
|
|
|
|
OtherPreds.push_back(*I);
|
|
|
|
|
|
|
|
// NewBBDominatesDestBB is valid if OtherPreds is empty, otherwise it isn't
|
|
|
|
// yet computed.
|
|
|
|
bool NewBBDominatesDestBB = true;
|
|
|
|
|
2002-09-26 16:18:51 +00:00
|
|
|
// Should we update DominatorSet information?
|
2002-10-08 21:06:27 +00:00
|
|
|
if (DominatorSet *DS = P->getAnalysisToUpdate<DominatorSet>()) {
|
2007-01-14 18:33:35 +00:00
|
|
|
DominatorSet::iterator DSI = DS->find(TIBB);
|
|
|
|
if (DSI != DS->end()) { // TIBB is reachable?
|
|
|
|
// The blocks that dominate the new one are the blocks that dominate TIBB
|
|
|
|
// plus the new block itself.
|
|
|
|
DominatorSet::DomSetType DomSet = DSI->second; // Copy domset.
|
|
|
|
DomSet.insert(NewBB); // A block always dominates itself.
|
|
|
|
DS->addBasicBlock(NewBB, DomSet);
|
|
|
|
|
|
|
|
// If NewBBDominatesDestBB hasn't been computed yet, do so with DS.
|
|
|
|
if (!OtherPreds.empty()) {
|
|
|
|
while (!OtherPreds.empty() && NewBBDominatesDestBB) {
|
|
|
|
NewBBDominatesDestBB = DS->dominates(DestBB, OtherPreds.back());
|
|
|
|
OtherPreds.pop_back();
|
|
|
|
}
|
|
|
|
OtherPreds.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If NewBBDominatesDestBB, then NewBB dominates DestBB, otherwise it
|
|
|
|
// doesn't dominate anything. If NewBB does dominates DestBB, then it
|
|
|
|
// dominates everything that DestBB dominates.
|
|
|
|
if (NewBBDominatesDestBB) {
|
|
|
|
for (DominatorSet::iterator I = DS->begin(), E = DS->end(); I != E; ++I)
|
|
|
|
if (I->second.count(DestBB))
|
|
|
|
I->second.insert(NewBB);
|
2006-10-03 07:02:02 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-26 16:18:51 +00:00
|
|
|
}
|
2002-09-24 15:51:56 +00:00
|
|
|
|
2003-10-10 17:57:28 +00:00
|
|
|
// Should we update ImmediateDominator information?
|
2002-10-08 21:06:27 +00:00
|
|
|
if (ImmediateDominators *ID = P->getAnalysisToUpdate<ImmediateDominators>()) {
|
2007-01-15 00:15:09 +00:00
|
|
|
// Only do this if TIBB is reachable.
|
|
|
|
if (ID->get(TIBB) || &TIBB->getParent()->getEntryBlock() == TIBB) {
|
2007-01-14 18:33:35 +00:00
|
|
|
// TIBB is the new immediate dominator for NewBB.
|
|
|
|
ID->addNewBlock(NewBB, TIBB);
|
|
|
|
|
|
|
|
// If NewBBDominatesDestBB hasn't been computed yet, do so with ID.
|
|
|
|
if (!OtherPreds.empty()) {
|
|
|
|
while (!OtherPreds.empty() && NewBBDominatesDestBB) {
|
|
|
|
NewBBDominatesDestBB = ID->dominates(DestBB, OtherPreds.back());
|
|
|
|
OtherPreds.pop_back();
|
|
|
|
}
|
|
|
|
OtherPreds.clear();
|
2006-10-03 07:02:02 +00:00
|
|
|
}
|
2007-01-14 18:33:35 +00:00
|
|
|
|
|
|
|
// If NewBBDominatesDestBB, then NewBB dominates DestBB, otherwise it
|
|
|
|
// doesn't dominate anything.
|
|
|
|
if (NewBBDominatesDestBB)
|
|
|
|
ID->setImmediateDominator(DestBB, NewBB);
|
2006-10-03 07:02:02 +00:00
|
|
|
}
|
2002-09-26 16:18:51 +00:00
|
|
|
}
|
2005-04-21 23:48:37 +00:00
|
|
|
|
2006-01-11 05:11:13 +00:00
|
|
|
// Update the forest?
|
2006-10-03 07:02:02 +00:00
|
|
|
if (ETForest *EF = P->getAnalysisToUpdate<ETForest>()) {
|
|
|
|
// NewBB is dominated by TIBB.
|
2006-01-11 05:11:13 +00:00
|
|
|
EF->addNewBlock(NewBB, TIBB);
|
2006-10-03 07:02:02 +00:00
|
|
|
|
|
|
|
// If NewBBDominatesDestBB hasn't been computed yet, do so with EF.
|
|
|
|
if (!OtherPreds.empty()) {
|
|
|
|
while (!OtherPreds.empty() && NewBBDominatesDestBB) {
|
|
|
|
NewBBDominatesDestBB = EF->dominates(DestBB, OtherPreds.back());
|
|
|
|
OtherPreds.pop_back();
|
|
|
|
}
|
|
|
|
OtherPreds.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If NewBBDominatesDestBB, then NewBB dominates DestBB, otherwise it
|
|
|
|
// doesn't dominate anything.
|
|
|
|
if (NewBBDominatesDestBB)
|
|
|
|
EF->setImmediateDominator(DestBB, NewBB);
|
|
|
|
}
|
2006-01-11 05:11:13 +00:00
|
|
|
|
2002-09-26 16:18:51 +00:00
|
|
|
// Should we update DominatorTree information?
|
2002-10-08 21:06:27 +00:00
|
|
|
if (DominatorTree *DT = P->getAnalysisToUpdate<DominatorTree>()) {
|
2002-09-26 16:18:51 +00:00
|
|
|
DominatorTree::Node *TINode = DT->getNode(TIBB);
|
2005-04-21 23:48:37 +00:00
|
|
|
|
2002-09-26 16:18:51 +00:00
|
|
|
// The new block is not the immediate dominator for any other nodes, but
|
|
|
|
// TINode is the immediate dominator for the new node.
|
|
|
|
//
|
2006-10-03 07:02:02 +00:00
|
|
|
if (TINode) { // Don't break unreachable code!
|
|
|
|
DominatorTree::Node *NewBBNode = DT->createNewNode(NewBB, TINode);
|
|
|
|
DominatorTree::Node *DestBBNode = 0;
|
|
|
|
|
|
|
|
// If NewBBDominatesDestBB hasn't been computed yet, do so with DT.
|
|
|
|
if (!OtherPreds.empty()) {
|
|
|
|
DestBBNode = DT->getNode(DestBB);
|
|
|
|
while (!OtherPreds.empty() && NewBBDominatesDestBB) {
|
|
|
|
if (DominatorTree::Node *OPNode = DT->getNode(OtherPreds.back()))
|
|
|
|
NewBBDominatesDestBB = DestBBNode->dominates(OPNode);
|
|
|
|
OtherPreds.pop_back();
|
|
|
|
}
|
|
|
|
OtherPreds.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If NewBBDominatesDestBB, then NewBB dominates DestBB, otherwise it
|
|
|
|
// doesn't dominate anything.
|
|
|
|
if (NewBBDominatesDestBB) {
|
|
|
|
if (!DestBBNode) DestBBNode = DT->getNode(DestBB);
|
|
|
|
DT->changeImmediateDominator(DestBBNode, NewBBNode);
|
|
|
|
}
|
|
|
|
}
|
2002-09-24 15:51:56 +00:00
|
|
|
}
|
2002-10-31 02:44:36 +00:00
|
|
|
|
|
|
|
// Should we update DominanceFrontier information?
|
|
|
|
if (DominanceFrontier *DF = P->getAnalysisToUpdate<DominanceFrontier>()) {
|
2006-10-03 07:02:02 +00:00
|
|
|
// If NewBBDominatesDestBB hasn't been computed yet, do so with DF.
|
|
|
|
if (!OtherPreds.empty()) {
|
|
|
|
// FIXME: IMPLEMENT THIS!
|
2006-10-04 04:58:58 +00:00
|
|
|
assert(0 && "Requiring domfrontiers but not idom/domtree/domset."
|
|
|
|
" not implemented yet!");
|
2006-10-03 07:02:02 +00:00
|
|
|
}
|
|
|
|
|
2002-10-31 02:44:36 +00:00
|
|
|
// Since the new block is dominated by its only predecessor TIBB,
|
2006-10-03 07:02:02 +00:00
|
|
|
// it cannot be in any block's dominance frontier. If NewBB dominates
|
|
|
|
// DestBB, its dominance frontier is the same as DestBB's, otherwise it is
|
|
|
|
// just {DestBB}.
|
2002-10-31 02:44:36 +00:00
|
|
|
DominanceFrontier::DomSetType NewDFSet;
|
2006-10-03 07:02:02 +00:00
|
|
|
if (NewBBDominatesDestBB) {
|
|
|
|
DominanceFrontier::iterator I = DF->find(DestBB);
|
|
|
|
if (I != DF->end())
|
|
|
|
DF->addBasicBlock(NewBB, I->second);
|
|
|
|
else
|
|
|
|
DF->addBasicBlock(NewBB, DominanceFrontier::DomSetType());
|
|
|
|
} else {
|
|
|
|
DominanceFrontier::DomSetType NewDFSet;
|
|
|
|
NewDFSet.insert(DestBB);
|
|
|
|
DF->addBasicBlock(NewBB, NewDFSet);
|
|
|
|
}
|
2002-10-31 02:44:36 +00:00
|
|
|
}
|
2005-08-13 01:38:43 +00:00
|
|
|
|
|
|
|
// Update LoopInfo if it is around.
|
|
|
|
if (LoopInfo *LI = P->getAnalysisToUpdate<LoopInfo>()) {
|
|
|
|
// If one or the other blocks were not in a loop, the new block is not
|
|
|
|
// either, and thus LI doesn't need to be updated.
|
|
|
|
if (Loop *TIL = LI->getLoopFor(TIBB))
|
|
|
|
if (Loop *DestLoop = LI->getLoopFor(DestBB)) {
|
|
|
|
if (TIL == DestLoop) {
|
|
|
|
// Both in the same loop, the NewBB joins loop.
|
|
|
|
DestLoop->addBasicBlockToLoop(NewBB, *LI);
|
|
|
|
} else if (TIL->contains(DestLoop->getHeader())) {
|
2006-10-03 07:02:02 +00:00
|
|
|
// Edge from an outer loop to an inner loop. Add to the outer loop.
|
2005-08-13 01:38:43 +00:00
|
|
|
TIL->addBasicBlockToLoop(NewBB, *LI);
|
|
|
|
} else if (DestLoop->contains(TIL->getHeader())) {
|
2006-10-03 07:02:02 +00:00
|
|
|
// Edge from an inner loop to an outer loop. Add to the outer loop.
|
2005-08-13 01:38:43 +00:00
|
|
|
DestLoop->addBasicBlockToLoop(NewBB, *LI);
|
|
|
|
} else {
|
|
|
|
// Edge from two loops with no containment relation. Because these
|
|
|
|
// are natural loops, we know that the destination block must be the
|
|
|
|
// header of its loop (adding a branch into a loop elsewhere would
|
|
|
|
// create an irreducible loop).
|
|
|
|
assert(DestLoop->getHeader() == DestBB &&
|
|
|
|
"Should not create irreducible loops!");
|
|
|
|
if (Loop *P = DestLoop->getParentLoop())
|
|
|
|
P->addBasicBlockToLoop(NewBB, *LI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-11-10 04:10:50 +00:00
|
|
|
return true;
|
2002-09-24 15:51:56 +00:00
|
|
|
}
|