Mesa (master): glsl: Convert lower_vec_index_to_cond_assign to using ir_builder

Ian Romanick idr at kemper.freedesktop.org
Mon Oct 2 21:48:14 UTC 2017


Module: Mesa
Branch: master
Commit: acd8b86a76c38fa3c94540ba8fb9afe0c20ab32a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=acd8b86a76c38fa3c94540ba8fb9afe0c20ab32a

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Sep 14 17:28:35 2017 -0700

glsl: Convert lower_vec_index_to_cond_assign to using ir_builder

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
Reviewed-by: Thomas Helland <thomashelland90 at gmail.com>

---

 .../glsl/lower_vec_index_to_cond_assign.cpp        | 56 +++++++---------------
 1 file changed, 17 insertions(+), 39 deletions(-)

diff --git a/src/compiler/glsl/lower_vec_index_to_cond_assign.cpp b/src/compiler/glsl/lower_vec_index_to_cond_assign.cpp
index f60ff7b77f..926a4931fd 100644
--- a/src/compiler/glsl/lower_vec_index_to_cond_assign.cpp
+++ b/src/compiler/glsl/lower_vec_index_to_cond_assign.cpp
@@ -40,6 +40,9 @@
 #include "ir_visitor.h"
 #include "ir_optimization.h"
 #include "compiler/glsl_types.h"
+#include "ir_builder.h"
+
+using namespace ir_builder;
 
 namespace {
 
@@ -80,37 +83,26 @@ ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(void *mem_
                                                                       ir_rvalue *orig_index,
                                                                       const glsl_type *type)
 {
-   ir_assignment *assign, *value_assign;
-   ir_variable *index, *var, *value;
-   ir_dereference *deref, *deref_value;
-   unsigned i;
-
-
    exec_list list;
+   ir_factory body(&list, base_ir);
 
    /* Store the index to a temporary to avoid reusing its tree. */
    assert(orig_index->type == glsl_type::int_type ||
           orig_index->type == glsl_type::uint_type);
-   index = new(base_ir) ir_variable(orig_index->type,
-                                    "vec_index_tmp_i",
-                                    ir_var_temporary);
-   list.push_tail(index);
-   deref = new(base_ir) ir_dereference_variable(index);
-   assign = new(base_ir) ir_assignment(deref, orig_index, NULL);
-   list.push_tail(assign);
+   ir_variable *const index =
+      body.make_temp(orig_index->type, "vec_index_tmp_i");
+
+   body.emit(assign(index, orig_index));
 
    /* Store the value inside a temp, thus avoiding matrixes duplication */
-   value = new(base_ir) ir_variable(orig_vector->type, "vec_value_tmp",
-                                    ir_var_temporary);
-   list.push_tail(value);
-   deref_value = new(base_ir) ir_dereference_variable(value);
-   value_assign = new(base_ir) ir_assignment(deref_value, orig_vector);
-   list.push_tail(value_assign);
+   ir_variable *const value =
+      body.make_temp(orig_vector->type, "vec_value_tmp");
+
+   body.emit(assign(value, orig_vector));
+
 
    /* Temporary where we store whichever value we swizzle out. */
-   var = new(base_ir) ir_variable(type, "vec_index_tmp_v",
-                                  ir_var_temporary);
-   list.push_tail(var);
+   ir_variable *const var = body.make_temp(type, "vec_index_tmp_v");
 
    /* Generate a single comparison condition "mask" for all of the components
     * in the vector.
@@ -121,22 +113,8 @@ ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(void *mem_
                           mem_ctx);
 
    /* 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(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
-       * underlying variable.
-       */
-      ir_rvalue *swizzle =
-         new(base_ir) ir_swizzle(deref_value->clone(mem_ctx, NULL),
-                                 i, 0, 0, 0, 1);
-
-      deref = new(base_ir) ir_dereference_variable(var);
-      assign = new(base_ir) ir_assignment(deref, swizzle, condition_swizzle);
-      list.push_tail(assign);
-   }
+   for (unsigned i = 0; i < orig_vector->type->vector_elements; i++)
+      body.emit(assign(var, swizzle(value, i, 1), swizzle(cond, i, 1)));
 
    /* Put all of the new instructions in the IR stream before the old
     * instruction.
@@ -144,7 +122,7 @@ ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(void *mem_
    base_ir->insert_before(&list);
 
    this->progress = true;
-   return new(base_ir) ir_dereference_variable(var);
+   return deref(var).val;
 }
 
 ir_rvalue *




More information about the mesa-commit mailing list