[Mesa-dev] [PATCH 1/3] nir/dominance: Simplify and expose the dominance intersection function
Jason Ekstrand
jason at jlekstrand.net
Fri Feb 6 14:12:05 PST 2015
Before the function involved three loops and three different branching
conditions. Now it involves one loop and one if statement. This is a
little simpler.
---
src/glsl/nir/nir.h | 2 ++
src/glsl/nir/nir_dominance.c | 16 ++++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 4cb2e92..886dcd2 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1500,6 +1500,8 @@ static inline void nir_validate_shader(nir_shader *shader) { }
void nir_calc_dominance_impl(nir_function_impl *impl);
void nir_calc_dominance(nir_shader *shader);
+nir_block *nir_dominance_lca(nir_block *b1, nir_block *b2);
+
void nir_dump_dom_tree_impl(nir_function_impl *impl, FILE *fp);
void nir_dump_dom_tree(nir_shader *shader, FILE *fp);
diff --git a/src/glsl/nir/nir_dominance.c b/src/glsl/nir/nir_dominance.c
index 67fdcc6..1022692 100644
--- a/src/glsl/nir/nir_dominance.c
+++ b/src/glsl/nir/nir_dominance.c
@@ -65,9 +65,9 @@ intersect(nir_block *b1, nir_block *b2)
* because we index blocks from beginning -> end (i.e. reverse
* post-order) instead of post-order like they assume.
*/
- while (b1->index > b2->index)
+ if (b1->index > b2->index)
b1 = b1->imm_dom;
- while (b2->index > b1->index)
+ else
b2 = b2->imm_dom;
}
@@ -212,6 +212,18 @@ nir_calc_dominance(nir_shader *shader)
}
}
+nir_block *
+nir_dominance_lca(nir_block *b1, nir_block *b2)
+{
+ assert(nir_cf_node_get_function(&b1->cf_node) ==
+ nir_cf_node_get_function(&b2->cf_node));
+
+ assert(nir_cf_node_get_function(&b1->cf_node)->valid_metadata &
+ nir_metadata_dominance);
+
+ return intersect(b1, b2);
+}
+
static bool
dump_block_dom(nir_block *block, void *state)
{
--
2.2.2
More information about the mesa-dev
mailing list