summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2014-12-15 19:38:14 -0800
committerJason Ekstrand <[email protected]>2015-01-15 07:20:22 -0800
commit28a3e164e275114fa536023d6594bbbcbae18157 (patch)
tree144c1b32cc6dd93636b7bbaf58a0c49785442631 /src/glsl
parent193fea9eb6a7ad72360a3ac65b322bab081f9587 (diff)
nir: Use nir_foreach_ssa_def for setting up ssa destinations
Before, we were using foreach_dest and switching on whether the destination was an SSA value. This works, except not all destinations are SSA values so we have to special-case ssa_undef instructions. Now that we have a foreach_ssa_def function, we can iterate over all of the register destinations in one pass and iterate over the SSA destinations in a second. This way, if we add other ssa-only instructions, we won't have to worry about adding them to the special case we have for ssa_undef. Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/nir/nir.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 1c9643c67c1..94840e2edcc 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -1176,27 +1176,28 @@ add_use_cb(nir_src *src, void *state)
return true;
}
-static void
-add_ssa_def(nir_instr *instr, nir_ssa_def *def)
+static bool
+add_ssa_def_cb(nir_ssa_def *def, void *state)
{
+ nir_instr *instr = (nir_instr *) state;
+
if (instr->block && def->index == UINT_MAX) {
nir_function_impl *impl =
nir_cf_node_get_function(&instr->block->cf_node);
def->index = impl->ssa_alloc++;
}
+
+ return true;
}
static bool
-add_def_cb(nir_dest *dest, void *state)
+add_reg_def_cb(nir_dest *dest, void *state)
{
nir_instr *instr = (nir_instr *) state;
- if (dest->is_ssa) {
- add_ssa_def(instr, &dest->ssa);
- } else {
+ if (!dest->is_ssa)
_mesa_set_add(dest->reg.reg->defs, _mesa_hash_pointer(instr), instr);
- }
return true;
}
@@ -1204,12 +1205,9 @@ add_def_cb(nir_dest *dest, void *state)
static void
add_defs_uses(nir_instr *instr)
{
- if (instr->type == nir_instr_type_ssa_undef) {
- add_ssa_def(instr, &nir_instr_as_ssa_undef(instr)->def);
- } else {
- nir_foreach_src(instr, add_use_cb, instr);
- nir_foreach_dest(instr, add_def_cb, instr);
- }
+ nir_foreach_src(instr, add_use_cb, instr);
+ nir_foreach_dest(instr, add_reg_def_cb, instr);
+ nir_foreach_ssa_def(instr, add_ssa_def_cb, instr);
}
void