nir: Automatically handle SSA uses when an instruction is inserted
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 4 Nov 2014 19:02:09 +0000 (11:02 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 15 Jan 2015 15:19:00 +0000 (07:19 -0800)
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/glsl/nir/nir.c
src/glsl/nir/nir_to_ssa.c

index 5e5f1aca7505f4908b45afda3efc93fcdb6fe2f5..3b74e424bbe828c092515577c6c851b824b41faa 100644 (file)
@@ -1144,12 +1144,9 @@ add_use_cb(nir_src *src, void *state)
 {
    nir_instr *instr = (nir_instr *) state;
 
-   if (src->is_ssa)
-      return true;
-
-   nir_register *reg = src->reg.reg;
+   struct set *uses_set = src->is_ssa ? src->ssa->uses : src->reg.reg->uses;
 
-   _mesa_set_add(reg->uses, _mesa_hash_pointer(instr), instr);
+   _mesa_set_add(uses_set, _mesa_hash_pointer(instr), instr);
 
    return true;
 }
@@ -1280,16 +1277,13 @@ remove_use_cb(nir_src *src, void *state)
 {
    nir_instr *instr = (nir_instr *) state;
 
-   if (src->is_ssa)
-      return true;
-
-   nir_register *reg = src->reg.reg;
+   struct set *uses_set = src->is_ssa ? src->ssa->uses : src->reg.reg->uses;
 
-   struct set_entry *entry = _mesa_set_search(reg->uses,
+   struct set_entry *entry = _mesa_set_search(uses_set,
                                               _mesa_hash_pointer(instr),
                                               instr);
    if (entry)
-      _mesa_set_remove(reg->uses, entry);
+      _mesa_set_remove(uses_set, entry);
 
    return true;
 }
index 26deb355e9ce103d8dc45adbadc1ec382dbb12f4..fb36ff4f6499645353d5b38739804d43cd5287e2 100644 (file)
@@ -235,13 +235,8 @@ rewrite_def_forwards(nir_dest *dest, void *_state)
       csel->dest.dest.reg.reg = dest->reg.reg;
       csel->dest.write_mask = (1 << dest->reg.reg->num_components) - 1;
       csel->src[0].src = nir_src_copy(*state->predicate, state->mem_ctx);
-      if (csel->src[0].src.is_ssa)
-         _mesa_set_add(csel->src[0].src.ssa->uses,
-                       _mesa_hash_pointer(&csel->instr), &csel->instr);
       csel->src[2].src.is_ssa = true;
       csel->src[2].src.ssa = get_ssa_src(dest->reg.reg, state);
-      _mesa_set_add(csel->src[2].src.ssa->uses,
-                    _mesa_hash_pointer(&csel->instr), &csel->instr);
    }
 
    dest->is_ssa = true;
@@ -265,8 +260,6 @@ rewrite_def_forwards(nir_dest *dest, void *_state)
    if (state->predicate) {
       csel->src[1].src.is_ssa = true;
       csel->src[1].src.ssa = &dest->ssa;
-      _mesa_set_add(dest->ssa.uses, _mesa_hash_pointer(&csel->instr),
-                    &csel->instr);
 
       nir_instr *old_parent_instr = state->parent_instr;
       nir_src *old_predicate = state->predicate;
@@ -386,18 +379,11 @@ rewrite_alu_instr_forward(nir_alu_instr *instr, rewrite_state *state)
             vec->src[i].src.ssa = old_src;
             vec->src[i].swizzle[0] = i;
          }
-
-         _mesa_set_add(vec->src[i].src.ssa->uses,
-                       _mesa_hash_pointer(&vec->instr), &vec->instr);
       }
 
       vec->has_predicate = instr->has_predicate;
-      if (instr->has_predicate) {
+      if (instr->has_predicate)
          vec->predicate = nir_src_copy(instr->predicate, state->mem_ctx);
-         if (vec->predicate.is_ssa)
-            _mesa_set_add(vec->predicate.ssa->uses,
-                          _mesa_hash_pointer(&vec->instr), &vec->instr);
-      }
 
       nir_instr_insert_after(&instr->instr, &vec->instr);