[Mesa-dev] [PATCH] nir: move nir_block_cf_tree_{next, prev}() NULL checking to caller

Timothy Arceri tarceri at itsqueeze.com
Thu Jan 31 03:23:52 UTC 2019


Rather than doing a NULL check on every block that is passed in
just do it for nir_foreach_block_{reverse}_safe() where the
potential problem is.

This is a micro optimisation after seeing nir_block_cf_tree_next()
when profiling shader compile-times.
---
 src/compiler/nir/nir.c | 13 -------------
 src/compiler/nir/nir.h |  4 ++--
 2 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 60e30ae1008..104f87debea 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -1552,14 +1552,6 @@ nir_ssa_def_components_read(const nir_ssa_def *def)
 nir_block *
 nir_block_cf_tree_next(nir_block *block)
 {
-   if (block == NULL) {
-      /* nir_foreach_block_safe() will call this function on a NULL block
-       * after the last iteration, but it won't use the result so just return
-       * NULL here.
-       */
-      return NULL;
-   }
-
    nir_cf_node *cf_next = nir_cf_node_next(&block->cf_node);
    if (cf_next)
       return nir_cf_node_cf_tree_first(cf_next);
@@ -1591,11 +1583,6 @@ nir_block_cf_tree_next(nir_block *block)
 nir_block *
 nir_block_cf_tree_prev(nir_block *block)
 {
-   if (block == NULL) {
-      /* do this for consistency with nir_block_cf_tree_next() */
-      return NULL;
-   }
-
    nir_cf_node *cf_prev = nir_cf_node_prev(&block->cf_node);
    if (cf_prev)
       return nir_cf_node_cf_tree_last(cf_prev);
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index ff2c41faf27..65c904e4b1f 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2727,7 +2727,7 @@ nir_block *nir_cf_node_cf_tree_next(nir_cf_node *node);
    for (nir_block *block = nir_start_block(impl), \
         *next = nir_block_cf_tree_next(block); \
         block != NULL; \
-        block = next, next = nir_block_cf_tree_next(block))
+        block = next, next = block ? nir_block_cf_tree_next(block) : NULL)
 
 #define nir_foreach_block_reverse(block, impl) \
    for (nir_block *block = nir_impl_last_block(impl); block != NULL; \
@@ -2737,7 +2737,7 @@ nir_block *nir_cf_node_cf_tree_next(nir_cf_node *node);
    for (nir_block *block = nir_impl_last_block(impl), \
         *prev = nir_block_cf_tree_prev(block); \
         block != NULL; \
-        block = prev, prev = nir_block_cf_tree_prev(block))
+        block = prev, prev = block ? nir_block_cf_tree_prev(block) : NULL)
 
 #define nir_foreach_block_in_cf_node(block, node) \
    for (nir_block *block = nir_cf_node_cf_tree_first(node); \
-- 
2.20.1



More information about the mesa-dev mailing list