[Mesa-dev] [PATCH] nir: Delete the nir_function_impl::start_block field.

Kenneth Graunke kenneth at whitecape.org
Thu Aug 6 18:18:40 PDT 2015


It's simply the first nir_cf_node in the nir_function_impl::body list,
which is easy enough to access - we don't to store a pointer to it
explicitly.  Removing it means we don't need to maintain the pointer
when, say, splitting the start block when modifying control flow.

Thanks to Connor Abbott for suggesting this.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/nir/nir.c                   | 1 -
 src/glsl/nir/nir.h                   | 8 +++++++-
 src/glsl/nir/nir_dominance.c         | 9 +++++----
 src/glsl/nir/nir_lower_vars_to_ssa.c | 2 +-
 src/glsl/nir/nir_opt_gcm.c           | 2 +-
 src/glsl/nir/nir_to_ssa.c            | 2 +-
 6 files changed, 15 insertions(+), 9 deletions(-)

Hey Connor,

This fixes my problem, and your series rebases cleanly on top of it,
so perhaps you can just push this before the rest of your series...

Thanks!

diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 78ff886..0ec08db 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -262,7 +262,6 @@ nir_function_impl_create(nir_function_overload *overload)
    nir_block *end_block = nir_block_create(mem_ctx);
    start_block->cf_node.parent = &impl->cf_node;
    end_block->cf_node.parent = &impl->cf_node;
-   impl->start_block = start_block;
    impl->end_block = end_block;
 
    exec_list_push_tail(&impl->body, &start_block->cf_node.node);
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 9aae6d7..e6b66ee 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1309,7 +1309,7 @@ typedef struct {
 
    struct exec_list body; /** < list of nir_cf_node */
 
-   nir_block *start_block, *end_block;
+   nir_block *end_block;
 
    /** list for all local variables in the function */
    struct exec_list locals;
@@ -1336,6 +1336,12 @@ typedef struct {
    nir_metadata valid_metadata;
 } nir_function_impl;
 
+static inline nir_block *
+nir_start_block(nir_function_impl *impl)
+{
+   return (nir_block *) exec_list_get_head(&impl->body);
+}
+
 static inline nir_cf_node *
 nir_cf_node_next(nir_cf_node *node)
 {
diff --git a/src/glsl/nir/nir_dominance.c b/src/glsl/nir/nir_dominance.c
index 2f50db1..af4caae 100644
--- a/src/glsl/nir/nir_dominance.c
+++ b/src/glsl/nir/nir_dominance.c
@@ -42,7 +42,7 @@ static bool
 init_block_cb(nir_block *block, void *_state)
 {
    dom_state *state = (dom_state *) _state;
-   if (block == state->impl->start_block)
+   if (block == nir_start_block(state->impl))
       block->imm_dom = block;
    else
       block->imm_dom = NULL;
@@ -78,7 +78,7 @@ static bool
 calc_dominance_cb(nir_block *block, void *_state)
 {
    dom_state *state = (dom_state *) _state;
-   if (block == state->impl->start_block)
+   if (block == nir_start_block(state->impl))
       return true;
 
    nir_block *new_idom = NULL;
@@ -209,12 +209,13 @@ nir_calc_dominance_impl(nir_function_impl *impl)
 
    nir_foreach_block(impl, calc_dom_frontier_cb, &state);
 
-   impl->start_block->imm_dom = NULL;
+   nir_block *start_block = nir_start_block(impl);
+   start_block->imm_dom = NULL;
 
    calc_dom_children(impl);
 
    unsigned dfs_index = 0;
-   calc_dfs_indicies(impl->start_block, &dfs_index);
+   calc_dfs_indicies(start_block, &dfs_index);
 }
 
 void
diff --git a/src/glsl/nir/nir_lower_vars_to_ssa.c b/src/glsl/nir/nir_lower_vars_to_ssa.c
index ccb8f99..4ff2166 100644
--- a/src/glsl/nir/nir_lower_vars_to_ssa.c
+++ b/src/glsl/nir/nir_lower_vars_to_ssa.c
@@ -935,7 +935,7 @@ nir_lower_vars_to_ssa_impl(nir_function_impl *impl)
    nir_foreach_block(impl, register_variable_uses_block, &state);
 
    insert_phi_nodes(&state);
-   rename_variables_block(impl->start_block, &state);
+   rename_variables_block(nir_start_block(impl), &state);
 
    nir_metadata_preserve(impl, nir_metadata_block_index |
                                nir_metadata_dominance);
diff --git a/src/glsl/nir/nir_opt_gcm.c b/src/glsl/nir/nir_opt_gcm.c
index 44068bf..5b412ee 100644
--- a/src/glsl/nir/nir_opt_gcm.c
+++ b/src/glsl/nir/nir_opt_gcm.c
@@ -256,7 +256,7 @@ gcm_schedule_early_instr(nir_instr *instr, struct gcm_state *state)
    /* Start with the instruction at the top.  As we iterate over the
     * sources, it will get moved down as needed.
     */
-   instr->block = state->impl->start_block;
+   instr->block = nir_start_block(state->impl);
    state->instr = instr;
 
    nir_foreach_src(instr, gcm_schedule_early_src, state);
diff --git a/src/glsl/nir/nir_to_ssa.c b/src/glsl/nir/nir_to_ssa.c
index a3c35fa..b089df7 100644
--- a/src/glsl/nir/nir_to_ssa.c
+++ b/src/glsl/nir/nir_to_ssa.c
@@ -516,7 +516,7 @@ nir_convert_to_ssa_impl(nir_function_impl *impl)
    rewrite_state state;
    init_rewrite_state(impl, &state);
 
-   rewrite_block(impl->start_block, &state);
+   rewrite_block(nir_start_block(impl), &state);
 
    remove_unused_regs(impl, &state);
 
-- 
2.4.6



More information about the mesa-dev mailing list