[llvm-commits] [llvm] r50628 - in /llvm/trunk: include/llvm/Analysis/DominatorInternals.h include/llvm/Analysis/Dominators.h test/Analysis/PostDominators/ test/Analysis/PostDominators/dg.exp test/Analysis/PostDominators/pr1098.ll

Owen Anderson resistor at mac.com
Sun May 4 14:07:35 PDT 2008


Author: resistor
Date: Sun May  4 16:07:35 2008
New Revision: 50628

URL: http://llvm.org/viewvc/llvm-project?rev=50628&view=rev
Log:
Fix PR1098 by correcting the postdominators analysis.

Patch by Florian Brandner.

Added:
    llvm/trunk/test/Analysis/PostDominators/
    llvm/trunk/test/Analysis/PostDominators/dg.exp
    llvm/trunk/test/Analysis/PostDominators/pr1098.ll
Modified:
    llvm/trunk/include/llvm/Analysis/DominatorInternals.h
    llvm/trunk/include/llvm/Analysis/Dominators.h

Modified: llvm/trunk/include/llvm/Analysis/DominatorInternals.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DominatorInternals.h?rev=50628&r1=50627&r2=50628&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/DominatorInternals.h (original)
+++ llvm/trunk/include/llvm/Analysis/DominatorInternals.h Sun May  4 16:07:35 2008
@@ -233,14 +233,7 @@
   typedef GraphTraits<NodeT> GraphT;
 
   unsigned N = 0;
-
-  // Add a node for the root.  This node might be the actual root, if there is
-  // one exit block, or it may be the virtual exit (denoted by (BasicBlock *)0)
-  // which postdominates all real exits if there are multiple exit blocks.
-  typename GraphT::NodeType* Root = DT.Roots.size() == 1 ? DT.Roots[0]
-                   : 0;
   bool MultipleRoots = (DT.Roots.size() > 1);
-
   if (MultipleRoots) {
     typename DominatorTreeBase<typename GraphT::NodeType>::InfoRec &BBInfo =
         DT.Info[NULL];
@@ -258,6 +251,10 @@
   for (unsigned i = 0, e = DT.Roots.size(); i != e; ++i)
     N = DFSPass<GraphT>(DT, DT.Roots[i], N);
 
+  // it might be that some blocks did not get a DFS number (e.g., blocks of 
+  // infinite loops). In these cases an artificial exit node is required.
+  MultipleRoots |= (DT.isPostDominator() && N != F.size());
+
   for (unsigned i = N; i >= 2; --i) {
     typename GraphT::NodeType* W = DT.Vertex[i];
     typename DominatorTreeBase<typename GraphT::NodeType>::InfoRec &WInfo =
@@ -311,15 +308,18 @@
     if (WIDom != DT.Vertex[DT.Info[W].Semi])
       WIDom = DT.IDoms[WIDom];
   }
-  
+
   if (DT.Roots.empty()) return;
-  
+
   // Add a node for the root.  This node might be the actual root, if there is
   // one exit block, or it may be the virtual exit (denoted by (BasicBlock *)0)
-  // which postdominates all real exits if there are multiple exit blocks.
+  // which postdominates all real exits if there are multiple exit blocks, or
+  // an infinite loop.
+  typename GraphT::NodeType* Root = !MultipleRoots ? DT.Roots[0] : 0;
+
   DT.DomTreeNodes[Root] = DT.RootNode =
                         new DomTreeNodeBase<typename GraphT::NodeType>(Root, 0);
-  
+
   // Loop over all of the reachable blocks in the function...
   for (unsigned i = 2; i <= N; ++i) {
     typename GraphT::NodeType* W = DT.Vertex[i];
@@ -329,20 +329,12 @@
 
     typename GraphT::NodeType* ImmDom = DT.getIDom(W);
 
-    // skip all non root nodes that have no dominator - this occures with 
-    // infinite loops.
-    if (!ImmDom && std::count(DT.Roots.begin(), DT.Roots.end(), W) == 0)
-      continue;
+    assert(ImmDom || DT.DomTreeNodes[NULL]);
 
     // Get or calculate the node for the immediate dominator
     DomTreeNodeBase<typename GraphT::NodeType> *IDomNode =
                                                      DT.getNodeForBlock(ImmDom);
 
-    // skip all children that are dominated by a non root node that, by itself,
-    // has no dominator.
-    if (!IDomNode)
-      continue;
-
     // Add a new tree node for this BasicBlock, and link it as a child of
     // IDomNode
     DomTreeNodeBase<typename GraphT::NodeType> *C =

Modified: llvm/trunk/include/llvm/Analysis/Dominators.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Dominators.h?rev=50628&r1=50627&r2=50628&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/Dominators.h (original)
+++ llvm/trunk/include/llvm/Analysis/Dominators.h Sun May  4 16:07:35 2008
@@ -605,17 +605,9 @@
     // immediate dominator.
     NodeT *IDom = getIDom(BB);
 
-    // skip all non root nodes that have no dominator
-    if (!IDom && std::count(this->Roots.begin(), this->Roots.end(), BB) == 0)
-      return NULL;
-
+    assert(IDom || this->DomTreeNodes[NULL]);
     DomTreeNodeBase<NodeT> *IDomNode = getNodeForBlock(IDom);
 
-    // skip all nodes that are dominated by a non root node that, by itself,
-    // has no dominator.
-    if (!IDomNode)
-      return NULL;
-
     // Add a new tree node for this BasicBlock, and link it as a child of
     // IDomNode
     DomTreeNodeBase<NodeT> *C = new DomTreeNodeBase<NodeT>(BB, IDomNode);

Added: llvm/trunk/test/Analysis/PostDominators/dg.exp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/PostDominators/dg.exp?rev=50628&view=auto

==============================================================================
--- llvm/trunk/test/Analysis/PostDominators/dg.exp (added)
+++ llvm/trunk/test/Analysis/PostDominators/dg.exp Sun May  4 16:07:35 2008
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,llx,c,cpp,tr}]]

Added: llvm/trunk/test/Analysis/PostDominators/pr1098.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/PostDominators/pr1098.ll?rev=50628&view=auto

==============================================================================
--- llvm/trunk/test/Analysis/PostDominators/pr1098.ll (added)
+++ llvm/trunk/test/Analysis/PostDominators/pr1098.ll Sun May  4 16:07:35 2008
@@ -0,0 +1,14 @@
+; RUN: llvm-as < %s | opt -postdomtree -analyze | grep entry
+; PR932
+
+define void @foo(i1 %x) {
+entry:
+        br i1 %x, label %bb1, label %bb0
+bb0:            ; preds = %entry, bb0
+        br label %bb0
+bb1:            ; preds = %entry
+        br label %bb2
+bb2:            ; preds = %bb1
+        ret void
+}
+





More information about the llvm-commits mailing list