-cfg::DominatorSet::DominatorSet(const Method *M) : DominatorBase(M->front()) {
- calcForwardDominatorSet(M);
-}
-
-// calcForwardDominatorSet - This method calculates the forward dominator sets
-// for the specified method.
-//
-void cfg::DominatorSet::calcForwardDominatorSet(const Method *M) {
- assert(Root && M && "Can't build dominator set of null method!");
- assert(Root->pred_begin() == Root->pred_end() &&
- "Root node has predecessors in method!");
-
- bool Changed;
- do {
- Changed = false;
-
- DomSetType WorkingSet;
- df_iterator<const Method*> It = df_begin(M), End = df_end(M);
- for ( ; It != End; ++It) {
- const BasicBlock *BB = *It;
- BasicBlock::pred_const_iterator PI = BB->pred_begin(),
- PEnd = BB->pred_end();
- if (PI != PEnd) { // Is there SOME predecessor?
- // Loop until we get to a predecessor that has had it's dom set filled
- // in at least once. We are guaranteed to have this because we are
- // traversing the graph in DFO and have handled start nodes specially.
- //
- while (Doms[*PI].size() == 0) ++PI;
- WorkingSet = Doms[*PI];
-
- for (++PI; PI != PEnd; ++PI) { // Intersect all of the predecessor sets
- DomSetType &PredSet = Doms[*PI];
- if (PredSet.size())
- set_intersect(WorkingSet, PredSet);
- }
- }
-
- WorkingSet.insert(BB); // A block always dominates itself
- DomSetType &BBSet = Doms[BB];
- if (BBSet != WorkingSet) {
- BBSet.swap(WorkingSet); // Constant time operation!
- Changed = true; // The sets changed.
- }
- WorkingSet.clear(); // Clear out the set for next iteration
- }
- } while (Changed);
-}
-
-// Postdominator set constructor. This ctor converts the specified method to
-// only have a single exit node (return stmt), then calculates the post
-// dominance sets for the method.
-//
-cfg::DominatorSet::DominatorSet(Method *M, bool PostDomSet)
- : DominatorBase(M->front()) {
- if (!PostDomSet) { calcForwardDominatorSet(M); return; }
+bool PostDominatorSet::runOnFunction(Function &F) {
+ Doms.clear(); // Reset from the last time we were run...
+ // Since we require that the unify all exit nodes pass has been run, we know
+ // that there can be at most one return instruction in the function left.
+ // Get it.
+ //
+ Root = getAnalysis<UnifyFunctionExitNodes>().getExitNode();