[Mesa-dev] [PATCH 07/10] nir/dominance: Also record the dominance depth

Jason Ekstrand jason at jlekstrand.net
Thu Feb 5 14:29:02 PST 2015


---
 src/glsl/nir/nir.h           | 3 +++
 src/glsl/nir/nir_dominance.c | 9 ++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 32c991a..8e5e686 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1136,6 +1136,9 @@ typedef struct nir_block {
     */
    struct nir_block *imm_dom;
 
+   /* This block's depth in the dominator tree; zero for the start block */
+   unsigned dom_depth;
+
    /* This node's children in the dominance tree */
    unsigned num_dom_children;
    struct nir_block **dom_children;
diff --git a/src/glsl/nir/nir_dominance.c b/src/glsl/nir/nir_dominance.c
index 67fdcc6..898b139 100644
--- a/src/glsl/nir/nir_dominance.c
+++ b/src/glsl/nir/nir_dominance.c
@@ -131,6 +131,9 @@ calc_dom_frontier_cb(nir_block *block, void *state)
  * 3. For each node, add itself to its parent's list of children, using
  *    num_dom_children as an index - at the end of this step, num_dom_children
  *    for each node will be the same as it was at the end of step #1.
+ *
+ *    While we're at it, this is also a convenient time to set the
+ *    dominator depth for each node.
  */
 
 static bool
@@ -161,8 +164,12 @@ block_add_child(nir_block *block, void *state)
 {
    (void) state;
 
-   if (block->imm_dom)
+   if (block->imm_dom) {
       block->imm_dom->dom_children[block->imm_dom->num_dom_children++] = block;
+      block->dom_depth = block->imm_dom->dom_depth + 1;
+   } else {
+      block->dom_depth = 0;
+   }
 
    return true;
 }
-- 
2.2.2



More information about the mesa-dev mailing list