[llvm-commits] [llvm] r43059 - in /llvm/trunk: include/llvm/Analysis/DominatorInternals.h include/llvm/Analysis/Dominators.h lib/VMCore/Dominators.cpp
Owen Anderson
resistor at mac.com
Tue Oct 16 19:03:18 PDT 2007
Author: resistor
Date: Tue Oct 16 21:03:17 2007
New Revision: 43059
URL: http://llvm.org/viewvc/llvm-project?rev=43059&view=rev
Log:
Move splitBlock into DomTreeBase from DomTree.
Modified:
llvm/trunk/include/llvm/Analysis/DominatorInternals.h
llvm/trunk/include/llvm/Analysis/Dominators.h
llvm/trunk/lib/VMCore/Dominators.cpp
Modified: llvm/trunk/include/llvm/Analysis/DominatorInternals.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DominatorInternals.h?rev=43059&r1=43058&r2=43059&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/DominatorInternals.h (original)
+++ llvm/trunk/include/llvm/Analysis/DominatorInternals.h Tue Oct 16 21:03:17 2007
@@ -303,6 +303,93 @@
DT.DFSInfoValid = false;
}
+// NewBB is split and now it has one successor. Update dominator tree to
+// reflect this change.
+template<class NodeT, class GraphT>
+void Split(DominatorTreeBase<typename GraphT::NodeType>& DT,
+ typename GraphT::NodeType* NewBB) {
+ assert(std::distance(GraphT::child_begin(NewBB), GraphT::child_end(NewBB)) == 1
+ && "NewBB should have a single successor!");
+ typename GraphT::NodeType* NewBBSucc = *GraphT::child_begin(NewBB);
+
+ std::vector<typename GraphT::NodeType*> PredBlocks;
+ for (typename GraphTraits<Inverse<NodeT> >::ChildIteratorType PI =
+ GraphTraits<Inverse<NodeT> >::child_begin(NewBB),
+ PE = GraphTraits<Inverse<NodeT> >::child_end(NewBB); PI != PE; ++PI)
+ PredBlocks.push_back(*PI);
+
+ assert(!PredBlocks.empty() && "No predblocks??");
+
+ // The newly inserted basic block will dominate existing basic blocks iff the
+ // PredBlocks dominate all of the non-pred blocks. If all predblocks dominate
+ // the non-pred blocks, then they all must be the same block!
+ //
+ bool NewBBDominatesNewBBSucc = true;
+ {
+ typename GraphT::NodeType* OnePred = PredBlocks[0];
+ unsigned i = 1, e = PredBlocks.size();
+ for (i = 1; !DT.isReachableFromEntry(OnePred); ++i) {
+ assert(i != e && "Didn't find reachable pred?");
+ OnePred = PredBlocks[i];
+ }
+
+ for (; i != e; ++i)
+ if (PredBlocks[i] != OnePred && DT.isReachableFromEntry(OnePred)) {
+ NewBBDominatesNewBBSucc = false;
+ break;
+ }
+
+ if (NewBBDominatesNewBBSucc)
+ for (typename GraphTraits<Inverse<NodeT> >::ChildIteratorType PI =
+ GraphTraits<Inverse<NodeT> >::child_begin(NewBBSucc),
+ E = GraphTraits<Inverse<NodeT> >::child_end(NewBBSucc); PI != E; ++PI)
+ if (*PI != NewBB && !DT.dominates(NewBBSucc, *PI)) {
+ NewBBDominatesNewBBSucc = false;
+ break;
+ }
+ }
+
+ // The other scenario where the new block can dominate its successors are when
+ // all predecessors of NewBBSucc that are not NewBB are dominated by NewBBSucc
+ // already.
+ if (!NewBBDominatesNewBBSucc) {
+ NewBBDominatesNewBBSucc = true;
+ for (typename GraphTraits<Inverse<NodeT> >::ChildIteratorType PI =
+ GraphTraits<Inverse<NodeT> >::child_begin(NewBBSucc),
+ E = GraphTraits<Inverse<NodeT> >::child_end(NewBBSucc); PI != E; ++PI)
+ if (*PI != NewBB && !DT.dominates(NewBBSucc, *PI)) {
+ NewBBDominatesNewBBSucc = false;
+ break;
+ }
+ }
+
+ // Find NewBB's immediate dominator and create new dominator tree node for
+ // NewBB.
+ BasicBlock *NewBBIDom = 0;
+ unsigned i = 0;
+ for (i = 0; i < PredBlocks.size(); ++i)
+ if (DT.isReachableFromEntry(PredBlocks[i])) {
+ NewBBIDom = PredBlocks[i];
+ break;
+ }
+ assert(i != PredBlocks.size() && "No reachable preds?");
+ for (i = i + 1; i < PredBlocks.size(); ++i) {
+ if (DT.isReachableFromEntry(PredBlocks[i]))
+ NewBBIDom = DT.findNearestCommonDominator(NewBBIDom, PredBlocks[i]);
+ }
+ assert(NewBBIDom && "No immediate dominator found??");
+
+ // Create the new dominator tree node... and set the idom of NewBB.
+ DomTreeNode *NewBBNode = DT.addNewBlock(NewBB, NewBBIDom);
+
+ // If NewBB strictly dominates other blocks, then it is now the immediate
+ // dominator of NewBBSucc. Update the dominator tree as appropriate.
+ if (NewBBDominatesNewBBSucc) {
+ DomTreeNode *NewBBSuccNode = DT.getNode(NewBBSucc);
+ DT.changeImmediateDominator(NewBBSuccNode, NewBBNode);
+ }
+}
+
}
#endif
Modified: llvm/trunk/include/llvm/Analysis/Dominators.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Dominators.h?rev=43059&r1=43058&r2=43059&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/Dominators.h (original)
+++ llvm/trunk/include/llvm/Analysis/Dominators.h Tue Oct 16 21:03:17 2007
@@ -160,6 +160,10 @@
/// DominatorTree - Calculate the immediate dominator tree for a function.
///
+template<class N, class GraphT>
+void Split(DominatorTreeBase<typename GraphT::NodeType>& DT,
+ typename GraphT::NodeType* NewBB);
+
template<class NodeT>
class DominatorTreeBase : public DominatorBase<NodeT> {
protected:
@@ -467,6 +471,21 @@
friend void Calculate(DominatorTreeBase<typename GraphT::NodeType>& DT,
Function& F);
+ template<class N, class GraphT>
+ friend void Split(DominatorTreeBase<typename GraphT::NodeType>& DT,
+ typename GraphT::NodeType* NewBB);
+
+public:
+ /// splitBlock - BB is split and now it has one successor. Update dominator
+ /// tree to reflect this change.
+ void splitBlock(NodeT* NewBB) {
+ if (this->IsPostDominators)
+ Split<Inverse<NodeT*>, GraphTraits<Inverse<NodeT*> > >(*this, NewBB);
+ else
+ Split<NodeT*, GraphTraits<NodeT*> >(*this, NewBB);
+ }
+
+protected:
/// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
/// dominator tree in dfs order.
void updateDFSNumbers() {
@@ -547,11 +566,6 @@
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
}
-
- /// splitBlock
- /// BB is split and now it has one successor. Update dominator tree to
- /// reflect this change.
- void splitBlock(BasicBlock *BB);
};
//===-------------------------------------
Modified: llvm/trunk/lib/VMCore/Dominators.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Dominators.cpp?rev=43059&r1=43058&r2=43059&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Dominators.cpp (original)
+++ llvm/trunk/lib/VMCore/Dominators.cpp Tue Oct 16 21:03:17 2007
@@ -56,88 +56,6 @@
static RegisterPass<DominatorTree>
E("domtree", "Dominator Tree Construction", true);
-// NewBB is split and now it has one successor. Update dominator tree to
-// reflect this change.
-void DominatorTree::splitBlock(BasicBlock *NewBB) {
- assert(NewBB->getTerminator()->getNumSuccessors() == 1
- && "NewBB should have a single successor!");
- BasicBlock *NewBBSucc = NewBB->getTerminator()->getSuccessor(0);
-
- std::vector<BasicBlock*> PredBlocks;
- for (pred_iterator PI = pred_begin(NewBB), PE = pred_end(NewBB);
- PI != PE; ++PI)
- PredBlocks.push_back(*PI);
-
- assert(!PredBlocks.empty() && "No predblocks??");
-
- // The newly inserted basic block will dominate existing basic blocks iff the
- // PredBlocks dominate all of the non-pred blocks. If all predblocks dominate
- // the non-pred blocks, then they all must be the same block!
- //
- bool NewBBDominatesNewBBSucc = true;
- {
- BasicBlock *OnePred = PredBlocks[0];
- unsigned i = 1, e = PredBlocks.size();
- for (i = 1; !isReachableFromEntry(OnePred); ++i) {
- assert(i != e && "Didn't find reachable pred?");
- OnePred = PredBlocks[i];
- }
-
- for (; i != e; ++i)
- if (PredBlocks[i] != OnePred && isReachableFromEntry(OnePred)) {
- NewBBDominatesNewBBSucc = false;
- break;
- }
-
- if (NewBBDominatesNewBBSucc)
- for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
- PI != E; ++PI)
- if (*PI != NewBB && !dominates(NewBBSucc, *PI)) {
- NewBBDominatesNewBBSucc = false;
- break;
- }
- }
-
- // The other scenario where the new block can dominate its successors are when
- // all predecessors of NewBBSucc that are not NewBB are dominated by NewBBSucc
- // already.
- if (!NewBBDominatesNewBBSucc) {
- NewBBDominatesNewBBSucc = true;
- for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
- PI != E; ++PI)
- if (*PI != NewBB && !dominates(NewBBSucc, *PI)) {
- NewBBDominatesNewBBSucc = false;
- break;
- }
- }
-
- // Find NewBB's immediate dominator and create new dominator tree node for
- // NewBB.
- BasicBlock *NewBBIDom = 0;
- unsigned i = 0;
- for (i = 0; i < PredBlocks.size(); ++i)
- if (isReachableFromEntry(PredBlocks[i])) {
- NewBBIDom = PredBlocks[i];
- break;
- }
- assert(i != PredBlocks.size() && "No reachable preds?");
- for (i = i + 1; i < PredBlocks.size(); ++i) {
- if (isReachableFromEntry(PredBlocks[i]))
- NewBBIDom = findNearestCommonDominator(NewBBIDom, PredBlocks[i]);
- }
- assert(NewBBIDom && "No immediate dominator found??");
-
- // Create the new dominator tree node... and set the idom of NewBB.
- DomTreeNode *NewBBNode = addNewBlock(NewBB, NewBBIDom);
-
- // If NewBB strictly dominates other blocks, then it is now the immediate
- // dominator of NewBBSucc. Update the dominator tree as appropriate.
- if (NewBBDominatesNewBBSucc) {
- DomTreeNode *NewBBSuccNode = getNode(NewBBSucc);
- changeImmediateDominator(NewBBSuccNode, NewBBNode);
- }
-}
-
bool DominatorTree::runOnFunction(Function &F) {
reset(); // Reset from the last time we were run...
More information about the llvm-commits
mailing list