glsl: Return ir_variable from compare_index_block
authorIan Romanick <ian.d.romanick@intel.com>
Fri, 15 Sep 2017 01:20:14 +0000 (18:20 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Mon, 2 Oct 2017 21:46:01 +0000 (14:46 -0700)
This is basically a wash now, but it simplifies later patches that
convert to using ir_builder.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
src/compiler/glsl/ir_optimization.h
src/compiler/glsl/lower_variable_index_to_cond_assign.cpp
src/compiler/glsl/lower_vec_index_to_cond_assign.cpp

index 573ddb4a8d7b7cc825e9964c09aca6ea250aa054..0fbbf34595f3ae328c8e7bae138d2606174fba19 100644 (file)
@@ -170,9 +170,9 @@ bool lower_blend_equation_advanced(gl_linked_shader *shader);
 bool lower_subroutine(exec_list *instructions, struct _mesa_glsl_parse_state *state);
 void propagate_invariance(exec_list *instructions);
 
-ir_rvalue *
-compare_index_block(exec_list *instructions, ir_variable *index,
-                   unsigned base, unsigned components, void *mem_ctx);
+ir_variable *compare_index_block(exec_list *instructions, ir_variable *index,
+                                 unsigned base, unsigned components,
+                                 void *mem_ctx);
 
 bool lower_64bit_integer_instructions(exec_list *instructions,
                                       unsigned what_to_lower);
index fcb12d1b77d94f25b26cc611daa1e1a00072fcbf..dd49272abb8cf3f30bc9a7d3b86aa5312b1761cb 100644 (file)
  * \param mem_ctx       ralloc memory context to be used for all allocations.
  *
  * \returns
- * An \c ir_rvalue that \b must be cloned for each use in conditional
- * assignments, etc.
+ * An \c ir_variable containing the per-component comparison results.  This
+ * must be dereferenced per use.
  */
-ir_rvalue *
+ir_variable *
 compare_index_block(exec_list *instructions, ir_variable *index,
                    unsigned base, unsigned components, void *mem_ctx)
 {
@@ -113,7 +113,7 @@ compare_index_block(exec_list *instructions, ir_variable *index,
       new(mem_ctx) ir_dereference_variable(condition);
    instructions->push_tail(new(mem_ctx) ir_assignment(cond_deref, condition_val, 0));
 
-   return cond_deref;
+   return condition;
 }
 
 static inline bool
@@ -275,17 +275,21 @@ struct switch_generator
       for (unsigned i = first; i < end; i += 4) {
          const unsigned comps = MIN2(condition_components, end - i);
 
-        ir_rvalue *const cond_deref =
-           compare_index_block(list, index, i, comps, this->mem_ctx);
+         ir_variable *const cond =
+            compare_index_block(list, index, i, comps, this->mem_ctx);
 
          if (comps == 1) {
-            this->generator.generate(i, cond_deref->clone(this->mem_ctx, NULL),
-                                    list);
+            ir_rvalue *const cond_deref =
+               new(mem_ctx) ir_dereference_variable(cond);
+
+            this->generator.generate(i, cond_deref, list);
          } else {
             for (unsigned j = 0; j < comps; j++) {
-              ir_rvalue *const cond_swiz =
-                 new(this->mem_ctx) ir_swizzle(cond_deref->clone(this->mem_ctx, NULL),
-                                               j, 0, 0, 0, 1);
+               ir_rvalue *const cond_deref =
+                  new(mem_ctx) ir_dereference_variable(cond);
+               ir_rvalue *const cond_swiz =
+                  new(this->mem_ctx) ir_swizzle(cond_deref,
+                                                j, 0, 0, 0, 1);
 
                this->generator.generate(i + j, cond_swiz, list);
             }
index 597d852c76eb700525beb4bde64882b16ff0cbc6..f60ff7b77fc140ce48a7dd4b8e768b81f2f22b3b 100644 (file)
@@ -115,7 +115,7 @@ ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(void *mem_
    /* Generate a single comparison condition "mask" for all of the components
     * in the vector.
     */
-   ir_rvalue *const cond_deref =
+   ir_variable *const cond =
       compare_index_block(&list, index, 0,
                           orig_vector->type->vector_elements,
                           mem_ctx);
@@ -123,7 +123,7 @@ ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(void *mem_
    /* Generate a conditional move of each vector element to the temp. */
    for (i = 0; i < orig_vector->type->vector_elements; i++) {
       ir_rvalue *condition_swizzle =
-         new(base_ir) ir_swizzle(cond_deref->clone(mem_ctx, NULL),
+         new(base_ir) ir_swizzle(new(mem_ctx) ir_dereference_variable(cond),
                                  i, 0, 0, 0, 1);
 
       /* Just clone the rest of the deref chain when trying to get at the