[llvm-commits] CVS: llvm/lib/VMCore/Dominators.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Oct 4 09:46:01 PDT 2002


Changes in directory llvm/lib/VMCore:

Dominators.cpp updated: 1.40 -> 1.41

---
Log message:

Fix a nasty problem with dominance calculation for unreachable blocks.
If we had a CFG that look like Entry -> B, Unreachable -> B, then we would
not correctly determine that Entry dominated B, because Entry did not 
apparently dominate "unreachable".  This patch fixes this by making the entry
node dominate all blocks, including unreachable ones.



---
Diffs of the changes:

Index: llvm/lib/VMCore/Dominators.cpp
diff -u llvm/lib/VMCore/Dominators.cpp:1.40 llvm/lib/VMCore/Dominators.cpp:1.41
--- llvm/lib/VMCore/Dominators.cpp:1.40	Sun Sep 29 16:42:42 2002
+++ llvm/lib/VMCore/Dominators.cpp	Fri Oct  4 09:45:48 2002
@@ -61,6 +61,18 @@
 	  if (PredSet.size())
 	    set_intersect(WorkingSet, PredSet);
 	}
+      } else if (BB != Root) {
+        // If this isn't the root basic block and it has no predecessors, it
+        // must be an unreachable block.  Fib a bit by saying that the root node
+        // dominates this unreachable node.  This isn't exactly true, because
+        // there is no path from the entry node to this node, but it is sorta
+        // true because any paths to this node would have to go through the
+        // entry node.
+        //
+        // This allows for dominator properties to be built for unreachable code
+        // in a reasonable manner.
+        //
+        WorkingSet = Doms[Root];
       }
 	
       WorkingSet.insert(BB);           // A block always dominates itself
@@ -95,9 +107,8 @@
   // unreachable blocks.
   //
   for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
-    if (Doms[I].empty()) {
+    if (Doms[I].count(I) == 0)
       calculateDominatorsFromBlock(I);
-    }
 
   return false;
 }
@@ -166,10 +177,14 @@
 }
 
 void ImmediateDominatorsBase::print(std::ostream &o) const {
-  for (const_iterator I = begin(), E = end(); I != E; ++I)
+  for (const_iterator I = begin(), E = end(); I != E; ++I) {
     o << "=============================--------------------------------\n"
-      << "\nImmediate Dominator For Basic Block\n" << *I->first
-      << "is: \n" << *I->second << "\n";
+      << "\nImmediate Dominator For Basic Block:";
+    WriteAsOperand(o, I->first, false);
+    o << " is:";
+    WriteAsOperand(o, I->second, false);
+    o << "\n";
+  }
 }
 
 





More information about the llvm-commits mailing list