[Mesa-dev] [RFC] nir/register: Add a parent_instr field

Jason Ekstrand jason at jlekstrand.net
Thu Jan 29 21:45:53 PST 2015


This adds a parent_instr field similar to the one for ssa_def.  The
difference here is that the parent_instr field on a nir_register can be
NULL if the register does not have a unique definition or if that
definition does not dominate all its uses.  We set this field in the
out-of-SSA pass so that backends can get SSA-like information even after
they have gone out of SSA.
---

Note: This has not been compile-tested

 src/glsl/nir/nir.c          |  1 +
 src/glsl/nir/nir.h          | 11 ++++++++++-
 src/glsl/nir/nir_from_ssa.c |  7 +++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 25cdac0..b3b825b 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -61,6 +61,7 @@ reg_create(void *mem_ctx, struct exec_list *list)
 {
    nir_register *reg = ralloc(mem_ctx, nir_register);
 
+   reg->parent_instr = NULL;
    reg->uses = _mesa_set_create(mem_ctx, _mesa_hash_pointer,
                                 _mesa_key_pointer_equal);
    reg->defs = _mesa_set_create(mem_ctx, _mesa_hash_pointer,
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 980fdd0..2c7ffdc 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -64,6 +64,7 @@ name(const in_type *parent)                              \
 struct nir_function_overload;
 struct nir_function;
 struct nir_shader;
+struct nir_instr;
 
 
 /**
@@ -384,6 +385,14 @@ typedef struct {
     */
    bool is_packed;
 
+   /**
+    * If this pointer is non-NULL then this register has exactly one
+    * definition and that definition dominates all of its uses.  This is
+    * set by the out-of-SSA pass so that backends can get SSA-like
+    * information even once they have gone out of SSA.
+    */
+   struct nir_instr *parent_instr;
+
    /** set of nir_instr's where this register is used (read from) */
    struct set *uses;
 
@@ -406,7 +415,7 @@ typedef enum {
    nir_instr_type_parallel_copy,
 } nir_instr_type;
 
-typedef struct {
+typedef struct nir_instr {
    struct exec_node node;
    nir_instr_type type;
    struct nir_block *block;
diff --git a/src/glsl/nir/nir_from_ssa.c b/src/glsl/nir/nir_from_ssa.c
index 2e7add3..f0105fb 100644
--- a/src/glsl/nir/nir_from_ssa.c
+++ b/src/glsl/nir/nir_from_ssa.c
@@ -513,6 +513,13 @@ get_register_for_ssa_def(nir_ssa_def *def, struct from_ssa_state *state)
       reg->num_components = def->num_components;
       reg->num_array_elems = 0;
 
+      /* This register comes from an SSA definition that was not part of a
+       * phi-web.  Therefore, we know it has a single unique definition
+       * that dominates all of its uses.  Therefore, we can copy the
+       * parent_instr from the SSA def safely.
+       */
+      reg->parent_instr = def->parent_instr;
+
       _mesa_hash_table_insert(state->ssa_table, def, reg);
       return reg;
    }
-- 
2.1.0



More information about the mesa-dev mailing list