[Mesa-dev] [PATCH v2 10/12] nir: Add an instruction index

Jason Ekstrand jason at jlekstrand.net
Mon Feb 9 00:19:13 PST 2015


This index, unlike the others, has to be manually updated by passes that
want to use it.

Reviewed-by: Connor Abbott <cwabbott0 at gmail.com>
---
 src/glsl/nir/nir.c | 20 ++++++++++++++++++++
 src/glsl/nir/nir.h |  4 ++++
 2 files changed, 24 insertions(+)

diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 8ea7bb5..6758a72 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -352,6 +352,7 @@ instr_init(nir_instr *instr, nir_instr_type type)
 {
    instr->type = type;
    instr->block = NULL;
+   instr->index = UINT_MAX;
    exec_node_init(&instr->node);
 }
 
@@ -2081,3 +2082,22 @@ nir_index_ssa_defs(nir_function_impl *impl)
    nir_foreach_block(impl, index_ssa_block, &index);
    impl->ssa_alloc = index;
 }
+
+static bool
+index_instrs_block(nir_block *block, void *state)
+{
+   unsigned *index = (unsigned *)state;
+
+   nir_foreach_instr(block, instr)
+      instr->index = (*index)++;
+
+   return true;
+}
+
+unsigned
+nir_index_instrs(nir_function_impl *impl)
+{
+   unsigned index = 0;
+   nir_foreach_block(impl, index_instrs_block, &index);
+   return index;
+}
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index f4056f4..90a7001 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -411,6 +411,9 @@ typedef struct {
    nir_instr_type type;
    struct nir_block *block;
 
+   /** generic instruction index. */
+   unsigned index;
+
    /* flag for dead code elimination (see nir_opt_dce.c) */
    bool live;
 } nir_instr;
@@ -1509,6 +1512,7 @@ nir_if *nir_block_get_following_if(nir_block *block);
 void nir_index_local_regs(nir_function_impl *impl);
 void nir_index_global_regs(nir_shader *shader);
 void nir_index_ssa_defs(nir_function_impl *impl);
+unsigned nir_index_instrs(nir_function_impl *impl);
 
 void nir_index_blocks(nir_function_impl *impl);
 
-- 
2.2.2



More information about the mesa-dev mailing list