nir/dominance: Expose the dominance intersection function
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 6 Feb 2015 20:06:04 +0000 (12:06 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 20 Feb 2015 01:06:16 +0000 (17:06 -0800)
Being able to find the least common anscestor in the dominance tree is a
useful thing that we may want to do in other passes.  In particular, we
need it for GCM.

v2: Handle NULL inputs by returning the other block

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/glsl/nir/nir.h
src/glsl/nir/nir_dominance.c

index f46ec151f6dfff112f380b6f615ae35cb1149ec4..0784218c0db10b3ecc5ca3370ec682b00cbe0b1c 100644 (file)
@@ -1517,6 +1517,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);
 
index 4927a292882f3306412b295300708a1ab56affaa..29589cbce230b95ac88b004fd25a7cf3aa3c0d73 100644 (file)
@@ -212,6 +212,28 @@ nir_calc_dominance(nir_shader *shader)
    }
 }
 
+/**
+ * Computes the least common anscestor of two blocks.  If one of the blocks
+ * is null, the other block is returned.
+ */
+nir_block *
+nir_dominance_lca(nir_block *b1, nir_block *b2)
+{
+   if (b1 == NULL)
+      return b2;
+
+   if (b2 == NULL)
+      return b1;
+
+   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)
 {