nir_dominance: Use uint32_t instead of int16_t for dominance counters
authorJesse Natalie <jenatali@microsoft.com>
Wed, 9 Sep 2020 00:50:23 +0000 (17:50 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 9 Sep 2020 19:01:01 +0000 (19:01 +0000)
We're seeing OpenCL kernels that can hit this INT16_MAX block count.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6657>

src/compiler/nir/nir.h
src/compiler/nir/nir_dominance.c

index 21cc4a7..30c298c 100644 (file)
@@ -2627,7 +2627,7 @@ typedef struct nir_block {
     * dom_pre_index and dom_post_index for this block, which makes testing if
     * a given block is dominated by another block an O(1) operation.
     */
-   int16_t dom_pre_index, dom_post_index;
+   uint32_t dom_pre_index, dom_post_index;
 
    /* SSA def live in and out for this block; used for liveness analysis.
     * Indexed by ssa_def->index
@@ -2640,7 +2640,7 @@ static inline bool
 nir_block_is_reachable(nir_block *b)
 {
    /* See also nir_block_dominates */
-   return b->dom_post_index != -1;
+   return b->dom_post_index != 0;
 }
 
 static inline nir_instr *
index e13210b..0f4cd5a 100644 (file)
@@ -43,8 +43,8 @@ init_block(nir_block *block, nir_function_impl *impl)
    block->num_dom_children = 0;
 
    /* See nir_block_dominates */
-   block->dom_pre_index = INT16_MAX;
-   block->dom_post_index = -1;
+   block->dom_pre_index = UINT32_MAX;
+   block->dom_post_index = 0;
 
    set_foreach(block->dom_frontier, entry) {
       _mesa_set_remove(block->dom_frontier, entry);
@@ -151,8 +151,11 @@ calc_dom_children(nir_function_impl* impl)
 }
 
 static void
-calc_dfs_indicies(nir_block *block, unsigned *index)
+calc_dfs_indicies(nir_block *block, uint32_t *index)
 {
+   /* UINT32_MAX has special meaning. See nir_block_dominates. */
+   assert(*index < UINT32_MAX - 2);
+
    block->dom_pre_index = (*index)++;
 
    for (unsigned i = 0; i < block->num_dom_children; i++)
@@ -192,7 +195,7 @@ nir_calc_dominance_impl(nir_function_impl *impl)
 
    calc_dom_children(impl);
 
-   unsigned dfs_index = 0;
+   uint32_t dfs_index = 1;
    calc_dfs_indicies(start_block, &dfs_index);
 }
 
@@ -254,8 +257,8 @@ nir_block_dominates(nir_block *parent, nir_block *child)
    assert(nir_cf_node_get_function(&parent->cf_node)->valid_metadata &
           nir_metadata_dominance);
 
-   /* If a block is unreachable, then nir_block::dom_pre_index == INT16_MAX
-    * and nir_block::dom_post_index == -1.  This allows us to trivially handle
+   /* If a block is unreachable, then nir_block::dom_pre_index == UINT32_MAX
+    * and nir_block::dom_post_index == 0.  This allows us to trivially handle
     * unreachable blocks here with zero extra work.
     */
    return child->dom_pre_index >= parent->dom_pre_index &&