nir: Add a block_is_unreachable helper
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 2 Sep 2019 17:53:16 +0000 (12:53 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Fri, 6 Sep 2019 23:39:01 +0000 (23:39 +0000)
Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
src/compiler/nir/nir.h
src/compiler/nir/nir_dominance.c

index ab1aab774a076267e63df06c3276036d6b9e91e2..1bfea2b2143f22ff95cfee4907545b332a25e182 100644 (file)
@@ -3373,6 +3373,7 @@ void nir_calc_dominance(nir_shader *shader);
 
 nir_block *nir_dominance_lca(nir_block *b1, nir_block *b2);
 bool nir_block_dominates(nir_block *parent, nir_block *child);
+bool nir_block_is_unreachable(nir_block *block);
 
 void nir_dump_dom_tree_impl(nir_function_impl *impl, FILE *fp);
 void nir_dump_dom_tree(nir_shader *shader, FILE *fp);
index c678727b471c10b3735aea0b5647cc268a61f8e3..8369c28984deb2e0d8fb655c7a31b8dff2b98826 100644 (file)
@@ -239,6 +239,20 @@ nir_block_dominates(nir_block *parent, nir_block *child)
           child->dom_post_index <= parent->dom_post_index;
 }
 
+bool
+nir_block_is_unreachable(nir_block *block)
+{
+   assert(nir_cf_node_get_function(&block->cf_node)->valid_metadata &
+          nir_metadata_dominance);
+   assert(nir_cf_node_get_function(&block->cf_node)->valid_metadata &
+          nir_metadata_block_index);
+
+   /* Unreachable blocks have no dominator.  The only reachable block with no
+    * dominator is the start block which has index 0.
+    */
+   return block->index > 0 && block->imm_dom == NULL;
+}
+
 void
 nir_dump_dom_tree_impl(nir_function_impl *impl, FILE *fp)
 {