]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
dominance.c: Add comment about why we use DFS numbering of dominance tree.
authorDaniel Berlin <dberlin@dberlin.org>
Wed, 4 Jan 2006 02:03:19 +0000 (02:03 +0000)
committerDaniel Berlin <dberlin@gcc.gnu.org>
Wed, 4 Jan 2006 02:03:19 +0000 (02:03 +0000)
2006-01-03  Daniel Berlin  <dberlin@dberlin.org>

* dominance.c: Add comment about why we use DFS numbering
of dominance tree.

From-SVN: r109308

gcc/ChangeLog
gcc/dominance.c

index d2e57cebcd8e845ffa18fc414b2ec21c9414e11e..eb0cd80f422b3c75ce1c7c2096e642ec5d83970c 100644 (file)
@@ -1,3 +1,8 @@
+2006-01-03  Daniel Berlin  <dberlin@dberlin.org>
+
+       * dominance.c: Add comment about why we use DFS numbering
+       of dominance tree.
+
 2006-01-03  Jakub Jelinek  <jakub@redhat.com>
            Richard Henderson  <rth@redhat.com>
 
index f89b6f618871559ccb066b5b994c749997c0b1fe..c7e39b50ca5b4fb808966a1c298bf932671e86f0 100644 (file)
@@ -814,6 +814,80 @@ nearest_common_dominator_for_set (enum cdi_direction dir, bitmap blocks)
   return dom;
 }
 
+/*  Given a dominator tree, we can determine whether one thing
+    dominates another in constant time by using two DFS numbers:
+
+    1. The number for when we visit a node on the way down the tree
+    2. The number for when we visit a node on the way back up the tree
+
+    You can view these as bounds for the range of dfs numbers the
+    nodes in the subtree of the dominator tree rooted at that node
+    will contain.
+    
+    The dominator tree is always a simple acyclic tree, so there are
+    only three possible relations two nodes in the dominator tree have
+    to each other:
+    
+    1. Node A is above Node B (and thus, Node A dominates node B)
+
+     A
+     |
+     C
+    / \
+   B   D
+
+
+   In the above case, DFS_Number_In of A will be <= DFS_Number_In of
+   B, and DFS_Number_Out of A will be >= DFS_Number_Out of B.  This is
+   because we must hit A in the dominator tree *before* B on the walk
+   down, and we will hit A *after* B on the walk back up
+   
+   2. Node A is below node B (and thus, node B dominates node B)
+   
+   
+     B
+     |
+     A
+    / \
+   C   D
+
+   In the above case, DFS_Number_In of A will be >= DFS_Number_In of
+   B, and DFS_Number_Out of A will be <= DFS_Number_Out of B.
+   
+   This is because we must hit A in the dominator tree *after* B on
+   the walk down, and we will hit A *before* B on the walk back up
+   
+   3. Node A and B are siblings (and thus, neither dominates the other)
+
+     C
+     |
+     D
+    / \
+   A   B
+
+   In the above case, DFS_Number_In of A will *always* be <=
+   DFS_Number_In of B, and DFS_Number_Out of A will *always* be <=
+   DFS_Number_Out of B.  This is because we will always finish the dfs
+   walk of one of the subtrees before the other, and thus, the dfs
+   numbers for one subtree can't intersect with the range of dfs
+   numbers for the other subtree.  If you swap A and B's position in
+   the dominator tree, the comparison changes direction, but the point
+   is that both comparisons will always go the same way if there is no
+   dominance relationship.
+
+   Thus, it is sufficient to write
+
+   A_Dominates_B (node A, node B)
+   {
+     return DFS_Number_In(A) <= DFS_Number_In(B) 
+            && DFS_Number_Out (A) >= DFS_Number_Out(B);
+   }
+
+   A_Dominated_by_B (node A, node B)
+   {
+     return DFS_Number_In(A) >= DFS_Number_In(A)
+            && DFS_Number_Out (A) <= DFS_Number_Out(B);
+   }  */
 
 /* Return TRUE in case BB1 is dominated by BB2.  */
 bool