- 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);
- }
- }
+
+ for (unsigned i = 0, e = Roots.size(); i != e; ++i)
+ for (idf_iterator<BasicBlock*> It = idf_begin(Roots[i]),
+ E = idf_end(Roots[i]); It != E; ++It) {
+ BasicBlock *BB = *It;
+ succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
+ if (SI != SE) { // Is there SOME successor?
+ // 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[*SI].size() == 0) ++SI;
+ WorkingSet = Doms[*SI];
+
+ for (++SI; SI != SE; ++SI) { // Intersect all of the successor sets
+ DomSetType &SuccSet = Doms[*SI];
+ if (SuccSet.size())
+ set_intersect(WorkingSet, SuccSet);
+ }
+ } else {
+ // If this node has no successors, it must be one of the root nodes.
+ // We will already take care of the notion that the node
+ // post-dominates itself. The only thing we have to add is that if
+ // there are multiple root nodes, we want to insert a special "null"
+ // exit node which dominates the roots as well.
+ if (Roots.size() > 1)
+ WorkingSet.insert(0);
+ }