class Pass;
class GetElementPtrInst;
class PassInfo;
+class TerminatorInst;
//===----------------------------------------------------------------------===//
//
Pass *createBreakCriticalEdgesPass();
extern const PassInfo *BreakCriticalEdgesID;
+// The BreakCriticalEdges pass also exposes some low-level functionality that
+// may be used by other passes.
+
+/// 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.
+///
+bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum);
+
+/// SplitCriticalEdge - Insert a new node node to split the critical edge. This
+/// will update DominatorSet, ImmediateDominator and DominatorTree information
+/// if a pass is specified, thus calling this pass will not invalidate these
+/// analyses.
+///
+void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P = 0);
//===----------------------------------------------------------------------===//
//
AU.addPreserved<DominatorTree>();
AU.addPreservedID(LoopPreheadersID); // No preheaders deleted.
}
- private:
- void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum);
};
RegisterOpt<BreakCriticalEdges> X("break-crit-edges",
// Critical edges are edges from a block with multiple successors to a block
// with multiple predecessors.
//
-static bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum) {
+bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum) {
assert(SuccNum < TI->getNumSuccessors() && "Illegal edge specification!");
- assert (TI->getNumSuccessors() > 1);
+ if (TI->getNumSuccessors() == 1) return false;
const BasicBlock *Dest = TI->getSuccessor(SuccNum);
pred_const_iterator I = pred_begin(Dest), E = pred_end(Dest);
// will update DominatorSet, ImmediateDominator and DominatorTree information if
// it is available, thus calling this pass will not invalidate either of them.
//
-void BreakCriticalEdges::SplitCriticalEdge(TerminatorInst *TI,unsigned SuccNum){
+void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P) {
assert(isCriticalEdge(TI, SuccNum) &&
"Cannot break a critical edge, if it isn't a critical edge");
BasicBlock *TIBB = TI->getParent();
PN->replaceUsesOfWith(TIBB, NewBB);
}
+ // If we don't have a pass object, we can't update anything...
+ if (P == 0) return;
+
// Now update analysis information. These are the analyses that we are
// currently capable of updating...
//
// Should we update DominatorSet information?
- if (DominatorSet *DS = getAnalysisToUpdate<DominatorSet>()) {
+ if (DominatorSet *DS = P->getAnalysisToUpdate<DominatorSet>()) {
// The blocks that dominate the new one are the blocks that dominate TIBB
// plus the new block itself.
DominatorSet::DomSetType DomSet = DS->getDominators(TIBB);
}
// Should we update ImmdediateDominator information?
- if (ImmediateDominators *ID = getAnalysisToUpdate<ImmediateDominators>()) {
+ if (ImmediateDominators *ID = P->getAnalysisToUpdate<ImmediateDominators>()) {
// TIBB is the new immediate dominator for NewBB. NewBB doesn't dominate
// anything.
ID->addNewBlock(NewBB, TIBB);
}
// Should we update DominatorTree information?
- if (DominatorTree *DT = getAnalysisToUpdate<DominatorTree>()) {
+ if (DominatorTree *DT = P->getAnalysisToUpdate<DominatorTree>()) {
DominatorTree::Node *TINode = DT->getNode(TIBB);
// The new block is not the immediate dominator for any other nodes, but
if (TI->getNumSuccessors() > 1)
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
if (isCriticalEdge(TI, i)) {
- SplitCriticalEdge(TI, i);
+ SplitCriticalEdge(TI, i, this);
++NumBroken;
Changed = true;
}
AU.addPreserved<DominatorTree>();
AU.addPreservedID(LoopPreheadersID); // No preheaders deleted.
}
- private:
- void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum);
};
RegisterOpt<BreakCriticalEdges> X("break-crit-edges",
// Critical edges are edges from a block with multiple successors to a block
// with multiple predecessors.
//
-static bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum) {
+bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum) {
assert(SuccNum < TI->getNumSuccessors() && "Illegal edge specification!");
- assert (TI->getNumSuccessors() > 1);
+ if (TI->getNumSuccessors() == 1) return false;
const BasicBlock *Dest = TI->getSuccessor(SuccNum);
pred_const_iterator I = pred_begin(Dest), E = pred_end(Dest);
// will update DominatorSet, ImmediateDominator and DominatorTree information if
// it is available, thus calling this pass will not invalidate either of them.
//
-void BreakCriticalEdges::SplitCriticalEdge(TerminatorInst *TI,unsigned SuccNum){
+void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P) {
assert(isCriticalEdge(TI, SuccNum) &&
"Cannot break a critical edge, if it isn't a critical edge");
BasicBlock *TIBB = TI->getParent();
PN->replaceUsesOfWith(TIBB, NewBB);
}
+ // If we don't have a pass object, we can't update anything...
+ if (P == 0) return;
+
// Now update analysis information. These are the analyses that we are
// currently capable of updating...
//
// Should we update DominatorSet information?
- if (DominatorSet *DS = getAnalysisToUpdate<DominatorSet>()) {
+ if (DominatorSet *DS = P->getAnalysisToUpdate<DominatorSet>()) {
// The blocks that dominate the new one are the blocks that dominate TIBB
// plus the new block itself.
DominatorSet::DomSetType DomSet = DS->getDominators(TIBB);
}
// Should we update ImmdediateDominator information?
- if (ImmediateDominators *ID = getAnalysisToUpdate<ImmediateDominators>()) {
+ if (ImmediateDominators *ID = P->getAnalysisToUpdate<ImmediateDominators>()) {
// TIBB is the new immediate dominator for NewBB. NewBB doesn't dominate
// anything.
ID->addNewBlock(NewBB, TIBB);
}
// Should we update DominatorTree information?
- if (DominatorTree *DT = getAnalysisToUpdate<DominatorTree>()) {
+ if (DominatorTree *DT = P->getAnalysisToUpdate<DominatorTree>()) {
DominatorTree::Node *TINode = DT->getNode(TIBB);
// The new block is not the immediate dominator for any other nodes, but
if (TI->getNumSuccessors() > 1)
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
if (isCriticalEdge(TI, i)) {
- SplitCriticalEdge(TI, i);
+ SplitCriticalEdge(TI, i, this);
++NumBroken;
Changed = true;
}