-bool cfg::DominatorBase::isPostDominator() const {
- // Root can be null if there is no exit node from the CFG and is postdom set
- return Root == 0 || Root != Root->getParent()->front();
-}
-
-
-//===----------------------------------------------------------------------===//
-// DominatorSet Implementation
-//===----------------------------------------------------------------------===//
-
-// DominatorSet ctor - Build either the dominator set or the post-dominator
-// set for a method...
-//
-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);
-}