-// Postdominator set constructor. This ctor converts the specified function to
-// only have a single exit node (return stmt), then calculates the post
-// dominance sets for the function.
-//
-void DominatorSet::calcPostDominatorSet(Function *F) {
- // 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();
-
- if (Root == 0) { // No exit node for the function? Postdomsets are all empty
- for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
- Doms[*FI] = DomSetType();
- return;
- }
-
- bool Changed;
- do {
- Changed = false;
-
- set<const BasicBlock*> Visited;
- DomSetType WorkingSet;
- idf_iterator<BasicBlock*> It = idf_begin(Root), End = idf_end(Root);
- for ( ; It != End; ++It) {
- BasicBlock *BB = *It;
- succ_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
- if (PI != PEnd) { // Is there SOME predecessor?
- // Loop until we get to a successor 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 successor 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);
-}
-
-// getAnalysisUsage - This obviously provides a dominator set, but it also
-// uses the UnifyFunctionExitNodes pass if building post-dominators
-//
-void DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
- AU.setPreservesAll();
- if (isPostDominator()) {
- AU.addProvided(PostDomID);
- AU.addRequired(UnifyFunctionExitNodes::ID);
- } else {
- AU.addProvided(ID);
- }
-}
-
-