Fix a few typos
[mesa.git] / src / glsl / nir / nir_from_ssa.c
index 3625237dd3dc41d67ac43e5190ed911358ddf2c4..6a3b141bd3f0e9b7d87db800c9edca47e5b5b09b 100644 (file)
@@ -26,6 +26,7 @@
  */
 
 #include "nir.h"
+#include "nir_vla.h"
 
 /*
  * This file implements an out-of-SSA pass as described in "Revisiting
@@ -181,7 +182,7 @@ merge_merge_sets(merge_set *a, merge_set *b)
 static bool
 merge_sets_interfere(merge_set *a, merge_set *b)
 {
-   merge_node *dom[a->size + b->size];
+   NIR_VLA(merge_node *, dom, a->size + b->size);
    int dom_idx = -1;
 
    struct exec_node *an = exec_list_get_head(&a->nodes);
@@ -272,7 +273,7 @@ get_parallel_copy_at_end_of_block(nir_block *block)
    if (last_instr->type == nir_instr_type_jump)
       last_instr = nir_instr_prev(last_instr);
 
-   if (last_instr->type == nir_instr_type_parallel_copy)
+   if (last_instr && last_instr->type == nir_instr_type_parallel_copy)
       return nir_instr_as_parallel_copy(last_instr);
    else
       return NULL;
@@ -508,6 +509,14 @@ 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 is defined and not
+       * part of a phi-web.  Therefore, we know it has a single unique
+       * definition that dominates all of its uses; we can copy the
+       * parent_instr from the SSA def safely.
+       */
+      if (def->parent_instr->type != nir_instr_type_ssa_undef)
+         reg->parent_instr = def->parent_instr;
+
       _mesa_hash_table_insert(state->ssa_table, def, reg);
       return reg;
    }
@@ -633,7 +642,7 @@ emit_copy(nir_parallel_copy_instr *pcopy, nir_src src, nir_src dest_src,
  *
  * The algorithm works by playing this little shell game with the values.
  * We start by recording where every source value is and which source value
- * each destination value should recieve.  We then grab any copy whose
+ * each destination value should receive.  We then grab any copy whose
  * destination is "empty", i.e. not used as a source, and do the following:
  *  - Find where its source value currently lives
  *  - Emit the move instruction
@@ -666,21 +675,16 @@ resolve_parallel_copy(nir_parallel_copy_instr *pcopy,
    }
 
    /* The register/source corresponding to the given index */
-   nir_src values[num_copies * 2];
-   memset(values, 0, sizeof values);
-
-   /* The current location of a given piece of data */
-   int loc[num_copies * 2];
+   NIR_VLA_ZERO(nir_src, values, num_copies * 2);
 
-   /* The piece of data that the given piece of data is to be copied from */
-   int pred[num_copies * 2];
+   /* The current location of a given piece of data.  We will use -1 for "null" */
+   NIR_VLA_FILL(int, loc, num_copies * 2, -1);
 
-   /* Initialize loc and pred.  We will use -1 for "null" */
-   memset(loc, -1, sizeof loc);
-   memset(pred, -1, sizeof pred);
+   /* The piece of data that the given piece of data is to be copied from.  We will use -1 for "null" */
+   NIR_VLA_FILL(int, pred, num_copies * 2, -1);
 
    /* The destinations we have yet to properly fill */
-   int to_do[num_copies * 2];
+   NIR_VLA(int, to_do, num_copies * 2);
    int to_do_idx = -1;
 
    /* Now we set everything up:
@@ -730,7 +734,7 @@ resolve_parallel_copy(nir_parallel_copy_instr *pcopy,
    }
 
    /* Currently empty destinations we can go ahead and fill */
-   int ready[num_copies * 2];
+   NIR_VLA(int, ready, num_copies * 2);
    int ready_idx = -1;
 
    /* Mark the ones that are ready for copying.  We know an index is a