From c750ecaa1265c3f77d52e69697006cc5ecc3d6dd Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 29 Jan 2015 21:45:53 -0800 Subject: [PATCH] nir/register: Add a parent_instr field 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. Reviewed-by: Connor Abbott Reviewed-by: Matt Turner Reviewed-by: Eric Anholt --- 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 5b0e4bc5061..ab57fd4e280 100644 --- a/src/glsl/nir/nir.c +++ b/src/glsl/nir/nir.c @@ -63,6 +63,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 d74caa959cc..d5df5960984 100644 --- a/src/glsl/nir/nir.h +++ b/src/glsl/nir/nir.h @@ -66,6 +66,7 @@ name(const in_type *parent) \ struct nir_function_overload; struct nir_function; struct nir_shader; +struct nir_instr; /** @@ -386,6 +387,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; @@ -408,7 +417,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 7c500957767..c695c951f31 100644 --- a/src/glsl/nir/nir_from_ssa.c +++ b/src/glsl/nir/nir_from_ssa.c @@ -508,6 +508,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.30.2