#include "llvm/iTerminators.h"
#include "llvm/iPHINode.h"
#include "llvm/Support/CFG.h"
-#include "Support/StatisticReporter.h"
+#include "Support/Statistic.h"
namespace {
- Statistic<> NumBroken("break-crit-edges\t- Number of blocks inserted");
+ Statistic<> NumBroken("break-crit-edges", "Number of blocks inserted");
struct BreakCriticalEdges : public FunctionPass {
virtual bool runOnFunction(Function &F);
AU.addPreserved<DominatorSet>();
AU.addPreserved<ImmediateDominators>();
AU.addPreserved<DominatorTree>();
+ AU.addPreservedID(LoopPreheadersID); // No preheaders deleted.
}
};
// 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.
//
-static void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P) {
+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);
}
- // Now if we have a pass object, update analysis information. Currently we
- // update DominatorSet and DominatorTree information if it's available.
- //
- if (P) {
- // Should we update DominatorSet information?
- 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);
- DomSet.insert(NewBB); // A block always dominates itself.
- DS->addBasicBlock(NewBB, DomSet);
- }
+ // If we don't have a pass object, we can't update anything...
+ if (P == 0) return;
- // Should we update ImmdediateDominator information?
- if (ImmediateDominators *ID =
- P->getAnalysisToUpdate<ImmediateDominators>()) {
- // TIBB is the new immediate dominator for NewBB. NewBB doesn't dominate
- // anything.
- ID->addNewBlock(NewBB, TIBB);
- }
+ // Now update analysis information. These are the analyses that we are
+ // currently capable of updating...
+ //
- // Should we update DominatorTree information?
- if (DominatorTree *DT = P->getAnalysisToUpdate<DominatorTree>()) {
- DominatorTree::Node *TINode = DT->getNode(TIBB);
+ // Should we update DominatorSet information?
+ 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);
+ DomSet.insert(NewBB); // A block always dominates itself.
+ DS->addBasicBlock(NewBB, DomSet);
+ }
- // The new block is not the immediate dominator for any other nodes, but
- // TINode is the immediate dominator for the new node.
- //
+ // Should we update ImmdediateDominator information?
+ 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 = P->getAnalysisToUpdate<DominatorTree>()) {
+ DominatorTree::Node *TINode = DT->getNode(TIBB);
+
+ // The new block is not the immediate dominator for any other nodes, but
+ // TINode is the immediate dominator for the new node.
+ //
+ if (TINode) // Don't break unreachable code!
DT->createNewNode(NewBB, TINode);
- }
}
}