nir: Make an easier helper for setting up SSA defs.
authorEric Anholt <eric@anholt.net>
Wed, 21 Jan 2015 00:23:51 +0000 (16:23 -0800)
committerEric Anholt <eric@anholt.net>
Thu, 22 Jan 2015 21:52:19 +0000 (13:52 -0800)
Almost all instructions we nir_ssa_def_init() for are nir_dests, and you
have to keep from forgetting to set is_ssa when you do.  Just provide the
simpler helper, instead.

Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
13 files changed:
src/glsl/nir/glsl_to_nir.cpp
src/glsl/nir/nir.c
src/glsl/nir/nir.h
src/glsl/nir/nir_from_ssa.c
src/glsl/nir/nir_lower_atomics.c
src/glsl/nir/nir_lower_io.c
src/glsl/nir/nir_lower_locals_to_regs.c
src/glsl/nir/nir_lower_system_values.c
src/glsl/nir/nir_lower_var_copies.c
src/glsl/nir/nir_lower_vars_to_ssa.c
src/glsl/nir/nir_opt_peephole_select.c
src/glsl/nir/nir_search.c
src/glsl/nir/nir_to_ssa.c

index 1457c1cac1c49e4588b657c32d9938a52434640d..46cfac39918cb73b7730c1f9e519d735f047f033 100644 (file)
@@ -612,8 +612,7 @@ nir_visitor::visit(ir_call *ir)
          (ir_dereference *) ir->actual_parameters.get_head();
       param->accept(this);
       instr->variables[0] = this->deref_head;
-      instr->dest.is_ssa = true;
-      nir_ssa_def_init(&instr->instr, &instr->dest.ssa, 1, NULL);
+      nir_ssa_dest_init(&instr->instr, &instr->dest, 1, NULL);
 
       nir_instr_insert_after_cf_list(this->cf_node_list, &instr->instr);
 
@@ -696,9 +695,7 @@ nir_visitor::visit(ir_assignment *ir)
       nir_intrinsic_instr *load =
          nir_intrinsic_instr_create(this->shader, nir_intrinsic_load_var);
       load->num_components = ir->lhs->type->vector_elements;
-      load->dest.is_ssa = true;
-      nir_ssa_def_init(&load->instr, &load->dest.ssa,
-                       num_components, NULL);
+      nir_ssa_dest_init(&load->instr, &load->dest, num_components, NULL);
       load->variables[0] = lhs_deref;
       nir_instr_insert_after_cf_list(this->cf_node_list, &load->instr);
 
@@ -711,9 +708,7 @@ nir_visitor::visit(ir_assignment *ir)
          default: unreachable("Invalid number of components"); break;
       }
       nir_alu_instr *vec = nir_alu_instr_create(this->shader, vec_op);
-      vec->dest.dest.is_ssa = true;
-      nir_ssa_def_init(&vec->instr, &vec->dest.dest.ssa,
-                       num_components, NULL);
+      nir_ssa_dest_init(&vec->instr, &vec->dest.dest, num_components, NULL);
       vec->dest.write_mask = (1 << num_components) - 1;
 
       unsigned component = 0;
@@ -798,8 +793,7 @@ nir_visitor::add_instr(nir_instr *instr, unsigned num_components)
 {
    nir_dest *dest = get_instr_dest(instr);
 
-   dest->is_ssa = true;
-   nir_ssa_def_init(instr, &dest->ssa, num_components, NULL);
+   nir_ssa_dest_init(instr, dest, num_components, NULL);
 
    nir_instr_insert_after_cf_list(this->cf_node_list, instr);
    this->result = instr;
index 89e21fddeb997bee915bf4b03047a409460c5570..16ad2da945c58691b0477b422076e858680a2be4 100644 (file)
@@ -1791,6 +1791,14 @@ nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
    }
 }
 
+void
+nir_ssa_dest_init(nir_instr *instr, nir_dest *dest,
+                 unsigned num_components, const char *name)
+{
+   dest->is_ssa = true;
+   nir_ssa_def_init(instr, &dest->ssa, num_components, name);
+}
+
 struct ssa_def_rewrite_state {
    void *mem_ctx;
    nir_ssa_def *old;
index 52bcd877f44f5c52c54fef83eab58eda8e730d50..15f8f465f19d22ee05d329792af8f39ba7c404f4 100644 (file)
@@ -1456,6 +1456,8 @@ nir_const_value *nir_src_as_const_value(nir_src src);
 bool nir_srcs_equal(nir_src src1, nir_src src2);
 void nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src);
 
+void nir_ssa_dest_init(nir_instr *instr, nir_dest *dest,
+                       unsigned num_components, const char *name);
 void nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
                       unsigned num_components, const char *name);
 void nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_src new_src, void *mem_ctx);
index 8b8f0f5ac758dc327e0f79ba2024b1301620cfa9..840177bff7ead02ee98ed8c9f2bbad077ef96fb9 100644 (file)
@@ -355,9 +355,8 @@ isolate_phi_nodes_block(nir_block *block, void *void_state)
          entry->src = nir_src_copy(src->src, state->dead_ctx);
          _mesa_set_add(src->src.ssa->uses, &pcopy->instr);
 
-         entry->dest.is_ssa = true;
-         nir_ssa_def_init(&pcopy->instr, &entry->dest.ssa,
-                          phi->dest.ssa.num_components, src->src.ssa->name);
+         nir_ssa_dest_init(&pcopy->instr, &entry->dest,
+                           phi->dest.ssa.num_components, src->src.ssa->name);
 
          struct set_entry *use_entry =
             _mesa_set_search(src->src.ssa->uses, instr);
@@ -379,9 +378,8 @@ isolate_phi_nodes_block(nir_block *block, void *void_state)
                                               nir_parallel_copy_entry);
       exec_list_push_tail(&block_pcopy->entries, &entry->node);
 
-      entry->dest.is_ssa = true;
-      nir_ssa_def_init(&block_pcopy->instr, &entry->dest.ssa,
-                       phi->dest.ssa.num_components, phi->dest.ssa.name);
+      nir_ssa_dest_init(&block_pcopy->instr, &entry->dest,
+                        phi->dest.ssa.num_components, phi->dest.ssa.name);
       nir_ssa_def_rewrite_uses(&phi->dest.ssa,
                                nir_src_for_ssa(&entry->dest.ssa),
                                state->mem_ctx);
index c45b397afba8355f113bfaf023fd836c372c086f..ec582f306c3acf6f9d040b344cfbb18edd54c861 100644 (file)
@@ -86,8 +86,7 @@ lower_instr(nir_intrinsic_instr *instr, nir_function_impl *impl)
          nir_instr_insert_before(&instr->instr, &atomic_counter_size->instr);
 
          nir_alu_instr *mul = nir_alu_instr_create(mem_ctx, nir_op_imul);
-         mul->dest.dest.is_ssa = true;
-         nir_ssa_def_init(&mul->instr, &mul->dest.dest.ssa, 1, NULL);
+         nir_ssa_dest_init(&mul->instr, &mul->dest.dest, 1, NULL);
          mul->dest.write_mask = 0x1;
          mul->src[0].src = nir_src_copy(deref_array->indirect, mem_ctx);
          mul->src[1].src.is_ssa = true;
@@ -95,8 +94,7 @@ lower_instr(nir_intrinsic_instr *instr, nir_function_impl *impl)
          nir_instr_insert_before(&instr->instr, &mul->instr);
 
          nir_alu_instr *add = nir_alu_instr_create(mem_ctx, nir_op_iadd);
-         add->dest.dest.is_ssa = true;
-         nir_ssa_def_init(&add->instr, &add->dest.dest.ssa, 1, NULL);
+         nir_ssa_dest_init(&add->instr, &add->dest.dest, 1, NULL);
          add->dest.write_mask = 0x1;
          add->src[0].src.is_ssa = true;
          add->src[0].src.ssa = &mul->dest.dest.ssa;
@@ -112,9 +110,8 @@ lower_instr(nir_intrinsic_instr *instr, nir_function_impl *impl)
    new_instr->src[0].ssa = offset_def;;
 
    if (instr->dest.is_ssa) {
-      new_instr->dest.is_ssa = true;
-      nir_ssa_def_init(&new_instr->instr, &new_instr->dest.ssa,
-                       instr->dest.ssa.num_components, NULL);
+      nir_ssa_dest_init(&new_instr->instr, &new_instr->dest,
+                        instr->dest.ssa.num_components, NULL);
       nir_ssa_def_rewrite_uses(&instr->dest.ssa,
                                nir_src_for_ssa(&new_instr->dest.ssa),
                                mem_ctx);
index c35058c14dcf9ae71f404cac3c562a537f4b21db..8712869a0f55f321ee566d5da30fb252605af064 100644 (file)
@@ -151,8 +151,7 @@ get_io_offset(nir_deref_var *deref, nir_instr *instr, nir_src *indirect,
             mul->src[1].src = nir_src_copy(deref_array->indirect,
                                            state->mem_ctx);
             mul->dest.write_mask = 1;
-            mul->dest.dest.is_ssa = true;
-            nir_ssa_def_init(&mul->instr, &mul->dest.dest.ssa, 1, NULL);
+            nir_ssa_dest_init(&mul->instr, &mul->dest.dest, 1, NULL);
             nir_instr_insert_before(instr, &mul->instr);
 
             if (found_indirect) {
@@ -162,8 +161,7 @@ get_io_offset(nir_deref_var *deref, nir_instr *instr, nir_src *indirect,
                add->src[1].src.is_ssa = true;
                add->src[1].src.ssa = &mul->dest.dest.ssa;
                add->dest.write_mask = 1;
-               add->dest.dest.is_ssa = true;
-               nir_ssa_def_init(&add->instr, &add->dest.dest.ssa, 1, NULL);
+               nir_ssa_dest_init(&add->instr, &add->dest.dest, 1, NULL);
                nir_instr_insert_before(instr, &add->instr);
 
                indirect->is_ssa = true;
@@ -235,9 +233,8 @@ nir_lower_io_block(nir_block *block, void *void_state)
             load->src[0] = indirect;
 
          if (intrin->dest.is_ssa) {
-            load->dest.is_ssa = true;
-            nir_ssa_def_init(&load->instr, &load->dest.ssa,
-                             intrin->num_components, NULL);
+            nir_ssa_dest_init(&load->instr, &load->dest,
+                              intrin->num_components, NULL);
             nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
                                      nir_src_for_ssa(&load->dest.ssa),
                                      state->mem_ctx);
index f50533f95753d72187fa3bc436c8b3ff0b1b6594..c04cb559239b472af977f3edc0c6ba62f30e7bf7 100644 (file)
@@ -158,8 +158,7 @@ get_deref_reg_src(nir_deref_var *deref, nir_instr *instr,
          mul->src[1].src.is_ssa = true;
          mul->src[1].src.ssa = &load_const->def;
          mul->dest.write_mask = 1;
-         mul->dest.dest.is_ssa = true;
-         nir_ssa_def_init(&mul->instr, &mul->dest.dest.ssa, 1, NULL);
+         nir_ssa_dest_init(&mul->instr, &mul->dest.dest, 1, NULL);
          nir_instr_insert_before(instr, &mul->instr);
 
          src.reg.indirect->is_ssa = true;
@@ -178,8 +177,7 @@ get_deref_reg_src(nir_deref_var *deref, nir_instr *instr,
             add->src[1].src = nir_src_copy(deref_array->indirect,
                                            state->mem_ctx);
             add->dest.write_mask = 1;
-            add->dest.dest.is_ssa = true;
-            nir_ssa_def_init(&add->instr, &add->dest.dest.ssa, 1, NULL);
+            nir_ssa_dest_init(&add->instr, &add->dest.dest, 1, NULL);
             nir_instr_insert_before(instr, &add->instr);
 
             src.reg.indirect->is_ssa = true;
@@ -212,9 +210,8 @@ lower_locals_to_regs_block(nir_block *block, void *void_state)
                                              &intrin->instr, state);
          mov->dest.write_mask = (1 << intrin->num_components) - 1;
          if (intrin->dest.is_ssa) {
-            mov->dest.dest.is_ssa = true;
-            nir_ssa_def_init(&mov->instr, &mov->dest.dest.ssa,
-                             intrin->num_components, NULL);
+            nir_ssa_dest_init(&mov->instr, &mov->dest.dest,
+                              intrin->num_components, NULL);
             nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
                                      nir_src_for_ssa(&mov->dest.dest.ssa),
                                      state->mem_ctx);
index 631f7cd46363f4411b27757f5c91b106c331e045..dc12f406e7c54877c45dfe2756535518f469e213 100644 (file)
@@ -70,9 +70,8 @@ convert_instr(nir_intrinsic_instr *instr)
    nir_intrinsic_instr *new_instr = nir_intrinsic_instr_create(mem_ctx, op);
 
    if (instr->dest.is_ssa) {
-      new_instr->dest.is_ssa = true;
-      nir_ssa_def_init(&new_instr->instr, &new_instr->dest.ssa,
-                       instr->dest.ssa.num_components, NULL);
+      nir_ssa_dest_init(&new_instr->instr, &new_instr->dest,
+                        instr->dest.ssa.num_components, NULL);
       nir_ssa_def_rewrite_uses(&instr->dest.ssa,
                                nir_src_for_ssa(&new_instr->dest.ssa),
                                mem_ctx);
index a9d1a47ea696f10daea3747a9df7a7caf61749c9..85ebb281c51383f47bc5c7757ae3614d8655a151 100644 (file)
@@ -155,8 +155,7 @@ emit_copy_load_store(nir_intrinsic_instr *copy_instr,
          nir_intrinsic_instr_create(mem_ctx, nir_intrinsic_load_var);
       load->num_components = num_components;
       load->variables[0] = nir_deref_as_var(src_deref);
-      load->dest.is_ssa = true;
-      nir_ssa_def_init(&load->instr, &load->dest.ssa, num_components, NULL);
+      nir_ssa_dest_init(&load->instr, &load->dest, num_components, NULL);
 
       nir_instr_insert_before(&copy_instr->instr, &load->instr);
 
index 061dbce1782adab9ae276cb42b082dafb915f5f2..168a02595fce8f32c6edc5a0dd97028851d4ef78 100644 (file)
@@ -784,9 +784,8 @@ rename_variables_block(nir_block *block, struct lower_variables_state *state)
             assert(intrin->dest.is_ssa);
 
             mov->dest.write_mask = (1 << intrin->num_components) - 1;
-            mov->dest.dest.is_ssa = true;
-            nir_ssa_def_init(&mov->instr, &mov->dest.dest.ssa,
-                             intrin->num_components, NULL);
+            nir_ssa_dest_init(&mov->instr, &mov->dest.dest,
+                              intrin->num_components, NULL);
 
             nir_instr_insert_before(&intrin->instr, &mov->instr);
             nir_instr_remove(&intrin->instr);
@@ -824,9 +823,8 @@ rename_variables_block(nir_block *block, struct lower_variables_state *state)
                mov->src[0].swizzle[i] = 0;
 
             mov->dest.write_mask = (1 << intrin->num_components) - 1;
-            mov->dest.dest.is_ssa = true;
-            nir_ssa_def_init(&mov->instr, &mov->dest.dest.ssa,
-                             intrin->num_components, NULL);
+            nir_ssa_dest_init(&mov->instr, &mov->dest.dest,
+                              intrin->num_components, NULL);
 
             nir_instr_insert_before(&intrin->instr, &mov->instr);
 
@@ -960,9 +958,8 @@ insert_phi_nodes(struct lower_variables_state *state)
 
             if (has_already[next->index] < iter_count) {
                nir_phi_instr *phi = nir_phi_instr_create(state->mem_ctx);
-               phi->dest.is_ssa = true;
-               nir_ssa_def_init(&phi->instr, &phi->dest.ssa,
-                                glsl_get_vector_elements(node->type), NULL);
+               nir_ssa_dest_init(&phi->instr, &phi->dest,
+                                 glsl_get_vector_elements(node->type), NULL);
                nir_instr_insert_before_block(next, &phi->instr);
 
                _mesa_hash_table_insert(state->phi_table, phi, node);
index a0b19c2ef253f62197ffe45469b85196a70b88c2..9f541fef19d85bc2749e164a71b0dfc31f16f1a7 100644 (file)
@@ -163,9 +163,8 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
          }
       }
 
-      sel->dest.dest.is_ssa = true;
-      nir_ssa_def_init(&sel->instr, &sel->dest.dest.ssa,
-                       phi->dest.ssa.num_components, phi->dest.ssa.name);
+      nir_ssa_dest_init(&sel->instr, &sel->dest.dest,
+                        phi->dest.ssa.num_components, phi->dest.ssa.name);
       sel->dest.write_mask = (1 << phi->dest.ssa.num_components) - 1;
 
       nir_ssa_def_rewrite_uses(&phi->dest.ssa,
index e69fdfd431c8f70f2a231eed5f2465cb6bbcb27e..7ef22e89ab5e76a6769451816ea37afdebef6f0f 100644 (file)
@@ -201,8 +201,7 @@ construct_value(const nir_search_value *value, nir_alu_type type,
          num_components = nir_op_infos[expr->opcode].output_size;
 
       nir_alu_instr *alu = nir_alu_instr_create(mem_ctx, expr->opcode);
-      alu->dest.dest.is_ssa = true;
-      nir_ssa_def_init(&alu->instr, &alu->dest.dest.ssa, num_components, NULL);
+      nir_ssa_dest_init(&alu->instr, &alu->dest.dest, num_components, NULL);
       alu->dest.write_mask = (1 << num_components) - 1;
       alu->dest.saturate = false;
 
@@ -301,9 +300,8 @@ nir_replace_instr(nir_alu_instr *instr, const nir_search_expression *search,
     */
    nir_alu_instr *mov = nir_alu_instr_create(mem_ctx, nir_op_imov);
    mov->dest.write_mask = instr->dest.write_mask;
-   mov->dest.dest.is_ssa = true;
-   nir_ssa_def_init(&mov->instr, &mov->dest.dest.ssa,
-                    instr->dest.dest.ssa.num_components, NULL);
+   nir_ssa_dest_init(&mov->instr, &mov->dest.dest,
+                     instr->dest.dest.ssa.num_components, NULL);
 
    mov->src[0] = construct_value(replace, nir_op_infos[instr->op].output_type,
                                  instr->dest.dest.ssa.num_components, &state,
index 548f0c5ac23af0a9970525222d3a90a18c9b098e..9c577fa99244073f9764ed6ce5b59f11b7ee9d8c 100644 (file)
@@ -214,15 +214,12 @@ rewrite_def_forwards(nir_dest *dest, void *_state)
    if (state->states[index].stack == NULL)
       return true;
 
-   dest->is_ssa = true;
-
    char *name = NULL;
    if (dest->reg.reg->name)
       name = ralloc_asprintf(state->mem_ctx, "%s_%u", dest->reg.reg->name,
                              state->states[index].num_defs);
 
-   nir_ssa_def_init(state->parent_instr, &dest->ssa,
-                    reg->num_components, name);
+   nir_ssa_dest_init(state->parent_instr, dest, reg->num_components, name);
 
    /* push our SSA destination on the stack */
    state->states[index].index++;
@@ -270,9 +267,7 @@ rewrite_alu_instr_forward(nir_alu_instr *instr, rewrite_state *state)
                                 reg->name, state->states[index].num_defs);
 
       instr->dest.write_mask = (1 << num_components) - 1;
-      instr->dest.dest.is_ssa = true;
-      nir_ssa_def_init(&instr->instr, &instr->dest.dest.ssa,
-                       num_components, name);
+      nir_ssa_dest_init(&instr->instr, &instr->dest.dest, num_components, name);
 
       if (nir_op_infos[instr->op].output_size == 0) {
          /*