Mesa (master): glsl2: Refactor testing for whether a deref is of a matrix or array

Ian Romanick idr at kemper.freedesktop.org
Fri Sep 17 09:45:06 UTC 2010


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Sep 16 12:12:22 2010 +0200

glsl2: Refactor testing for whether a deref is of a matrix or array

---

 src/glsl/lower_variable_index_to_cond_assign.cpp |   23 +++++++++++----------
 1 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/glsl/lower_variable_index_to_cond_assign.cpp b/src/glsl/lower_variable_index_to_cond_assign.cpp
index d9e6379..095592b 100644
--- a/src/glsl/lower_variable_index_to_cond_assign.cpp
+++ b/src/glsl/lower_variable_index_to_cond_assign.cpp
@@ -217,16 +217,19 @@ public:
 
    bool progress;
 
+   bool is_array_or_matrix(const ir_instruction *ir) const
+   {
+      return (ir->type->is_array() || ir->type->is_matrix());
+   }
+
    ir_variable *convert_dereference_array(ir_dereference_array *orig_deref,
 					  ir_rvalue* value)
    {
-      unsigned length;
-      if (orig_deref->array->type->is_array())
-         length = orig_deref->array->type->length;
-      else if (orig_deref->array->type->is_matrix())
-         length = orig_deref->array->type->matrix_columns;
-      else
-         assert(0);
+      assert(is_array_or_matrix(orig_deref->array));
+
+      const unsigned length = (orig_deref->array->type->is_array())
+         ? orig_deref->array->type->length
+         : orig_deref->array->type->matrix_columns;
 
       void *const mem_ctx = talloc_parent(base_ir);
       ir_variable *var =
@@ -274,8 +277,7 @@ public:
 
       ir_dereference_array* orig_deref = (*pir)->as_dereference_array();
       if (orig_deref && !orig_deref->array_index->as_constant()
-            && (orig_deref->array->type->is_array()
-		|| orig_deref->array->type->is_matrix())) {
+	  && is_array_or_matrix(orig_deref->array)) {
          ir_variable* var = convert_dereference_array(orig_deref, 0);
          assert(var);
          *pir = new(talloc_parent(base_ir)) ir_dereference_variable(var);
@@ -291,8 +293,7 @@ public:
       ir_dereference_array *orig_deref = ir->lhs->as_dereference_array();
 
       if (orig_deref && !orig_deref->array_index->as_constant()
-            && (orig_deref->array->type->is_array()
-		|| orig_deref->array->type->is_matrix())) {
+	  && is_array_or_matrix(orig_deref->array)) {
          convert_dereference_array(orig_deref, ir->rhs);
          ir->remove();
          this->progress = true;




More information about the mesa-commit mailing list