Refactor ir_dereference data fields to subclasses
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 19 May 2010 11:52:29 +0000 (13:52 +0200)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 26 May 2010 22:23:25 +0000 (15:23 -0700)
ast_to_hir.cpp
ir.cpp
ir.h
ir_constant_expression.cpp
ir_constant_folding.cpp
ir_copy_propagation.cpp
ir_dead_code_local.cpp
ir_expression_flattening.cpp
ir_function_inlining.cpp
ir_hv_accept.cpp
ir_print_visitor.cpp

index b8128fa8a778fb5ab7c6f6b4b1e7120405ff0c16..64f8ef49681a7e7a482f6e91d09c609415f65845 100644 (file)
@@ -482,7 +482,7 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
 
         assert(d != NULL);
 
-        ir_variable *const var = d->var->as_variable();
+        ir_variable *const var = d->variable_referenced();
 
         assert(var != NULL);
 
diff --git a/ir.cpp b/ir.cpp
index f6f2558bc06bb5dfd7bcae019cbb289ea0f062d9..a147339b1a7cb0411c42bad4af8190e0e5d2dbb3 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -235,7 +235,7 @@ ir_dereference_array::ir_dereference_array(ir_rvalue *value,
                                           ir_rvalue *array_index)
    : ir_dereference(ir_reference_array)
 {
-   this->selector.array_index = array_index;
+   this->array_index = array_index;
    this->set_array(value);
 }
 
@@ -244,7 +244,7 @@ ir_dereference_array::ir_dereference_array(ir_variable *var,
                                           ir_rvalue *array_index)
    : ir_dereference(ir_reference_array)
 {
-   this->selector.array_index = array_index;
+   this->array_index = array_index;
    this->set_array(new ir_dereference_variable(var));
 }
 
@@ -252,11 +252,11 @@ ir_dereference_array::ir_dereference_array(ir_variable *var,
 void
 ir_dereference_array::set_array(ir_rvalue *value)
 {
-   this->var = value;
+   this->array = value;
    this->type = glsl_type::error_type;
 
-   if (this->var != NULL) {
-      const glsl_type *const vt = this->var->type;
+   if (this->array != NULL) {
+      const glsl_type *const vt = this->array->type;
 
       if (vt->is_array()) {
         type = vt->element_type();
@@ -273,10 +273,10 @@ ir_dereference_record::ir_dereference_record(ir_rvalue *value,
                                             const char *field)
    : ir_dereference(ir_reference_record)
 {
-   this->var = value;
-   this->selector.field = field;
-   this->type = (this->var != NULL)
-      ? this->var->type->field_type(field) : glsl_type::error_type;
+   this->record = value;
+   this->field = field;
+   this->type = (this->record != NULL)
+      ? this->record->type->field_type(field) : glsl_type::error_type;
 }
 
 
@@ -284,10 +284,10 @@ ir_dereference_record::ir_dereference_record(ir_variable *var,
                                             const char *field)
    : ir_dereference(ir_reference_record)
 {
-   this->var = new ir_dereference_variable(var);
-   this->selector.field = field;
-   this->type = (this->var != NULL)
-      ? this->var->type->field_type(field) : glsl_type::error_type;
+   this->record = new ir_dereference_variable(var);
+   this->field = field;
+   this->type = (this->record != NULL)
+      ? this->record->type->field_type(field) : glsl_type::error_type;
 }
 
 
diff --git a/ir.h b/ir.h
index 2d641766b2e6e255e9b742e68911d37c4c72ad9a..2e6a19432149094e515abe49bf3e49d2d2d211bd 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -806,18 +806,6 @@ public:
       ir_reference_record
    } mode;
 
-   /**
-    * Object being dereferenced.
-    *
-    * Must be either an \c ir_variable or an \c ir_rvalue.
-    */
-   ir_instruction *var;
-
-   union {
-      ir_rvalue *array_index;
-      const char *field;
-   } selector;
-
 protected:
    ir_dereference(ir_deref_mode mode)
       : mode(mode)
@@ -836,7 +824,7 @@ public:
     */
    virtual ir_variable *variable_referenced()
    {
-      return (ir_variable *) this->var;
+      return this->var;
    }
 
    virtual void accept(ir_visitor *v)
@@ -845,6 +833,11 @@ public:
    }
 
    virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+   /**
+    * Object being dereferenced.
+    */
+   ir_variable *var;
 };
 
 
@@ -859,7 +852,7 @@ public:
     */
    virtual ir_variable *variable_referenced()
    {
-      return ((ir_rvalue *) this->var)->variable_referenced();
+      return this->array->variable_referenced();
    }
 
    virtual void accept(ir_visitor *v)
@@ -869,6 +862,9 @@ public:
 
    virtual ir_visitor_status accept(ir_hierarchical_visitor *);
 
+   ir_rvalue *array;
+   ir_rvalue *array_index;
+
 private:
    void set_array(ir_rvalue *value);
 };
@@ -885,7 +881,7 @@ public:
     */
    virtual ir_variable *variable_referenced()
    {
-      return ((ir_rvalue *) this->var)->variable_referenced();
+      return this->record->variable_referenced();
    }
 
    virtual void accept(ir_visitor *v)
@@ -894,6 +890,9 @@ public:
    }
 
    virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+   ir_rvalue *record;
+   const char *field;
 };
 
 
index 076fdfda75fa2bbbb501a62afe9723d1b962cf7e..b1092de1393fd2b01f6d0b0dbbafdb8a7e51ec3c 100644 (file)
@@ -427,6 +427,7 @@ ir_constant_visitor::visit(ir_dereference_variable *ir)
 void
 ir_constant_visitor::visit(ir_dereference_array *ir)
 {
+   (void) ir;
    value = NULL;
    /* FINISHME: Other dereference modes. */
 }
@@ -435,6 +436,7 @@ ir_constant_visitor::visit(ir_dereference_array *ir)
 void
 ir_constant_visitor::visit(ir_dereference_record *ir)
 {
+   (void) ir;
    value = NULL;
    /* FINISHME: Other dereference modes. */
 }
index 9a2a7f3f2e7e13f433037f27ab2e394114d70a3f..c7019ffc6262971e65c259a89c2db4066dfa5d3c 100644 (file)
@@ -129,21 +129,21 @@ void
 ir_constant_folding_visitor::visit(ir_dereference_array *ir)
 {
    ir_constant *const_val =
-      ir->selector.array_index->constant_expression_value();
+      ir->array_index->constant_expression_value();
 
    if (const_val)
-      ir->selector.array_index = const_val;
+      ir->array_index = const_val;
    else
-      ir->selector.array_index->accept(this);
+      ir->array_index->accept(this);
 
-   ir->var->accept(this);
+   ir->array->accept(this);
 }
 
 
 void
 ir_constant_folding_visitor::visit(ir_dereference_record *ir)
 {
-   ir->var->accept(this);
+   ir->record->accept(this);
 }
 
 
index 47f9390710c61ff64d620973fe3011cd82fa7779..e395fa9723b4b30a5bc8df44da49ece71b926742 100644 (file)
@@ -169,14 +169,14 @@ ir_copy_propagation_visitor::visit(ir_dereference_variable *ir)
 void
 ir_copy_propagation_visitor::visit(ir_dereference_array *ir)
 {
-   ir->var->accept(this);
-   ir->selector.array_index->accept(this);
+   ir->array->accept(this);
+   ir->array_index->accept(this);
 }
 
 void
 ir_copy_propagation_visitor::visit(ir_dereference_record *ir)
 {
-   ir->var->accept(this);
+   ir->record->accept(this);
 }
 
 void
@@ -270,12 +270,12 @@ add_copy(ir_assignment *ir, exec_list *acp)
    ir_dereference *lhs_deref = ir->lhs->as_dereference();
    if (!lhs_deref || lhs_deref->mode != ir_dereference::ir_reference_variable)
       return;
-   ir_variable *lhs_var = lhs_deref->var->as_variable();
+   ir_variable *lhs_var = lhs_deref->variable_referenced();
 
    ir_dereference *rhs_deref = ir->rhs->as_dereference();
    if (!rhs_deref || rhs_deref->mode != ir_dereference::ir_reference_variable)
       return;
-   ir_variable *rhs_var = rhs_deref->var->as_variable();
+   ir_variable *rhs_var = rhs_deref->variable_referenced();
 
    entry = new acp_entry(lhs_var, rhs_var);
    acp->push_tail(entry);
index e3c0e53303224219eca05818fd32088a42513b90..9ac209df576e9880bb006249b175c9fe94f43714 100644 (file)
@@ -94,7 +94,7 @@ public:
 
    virtual ir_visitor_status visit_enter(class ir_dereference_array *ir)
    {
-      ir->selector.array_index->accept(visitor);
+      ir->array_index->accept(visitor);
       return visit_continue;
    }
 
index 1e0244988a253cf690b21df3c2716aad3e49af6b..3403389c9c417c1dfb6ed8a94fed06624b381a15 100644 (file)
@@ -172,14 +172,14 @@ ir_expression_flattening_visitor::visit(ir_dereference_variable *ir)
 void
 ir_expression_flattening_visitor::visit(ir_dereference_array *ir)
 {
-   ir->selector.array_index->accept(this);
-   ir->var->accept(this);
+   ir->array_index->accept(this);
+   ir->array->accept(this);
 }
 
 void
 ir_expression_flattening_visitor::visit(ir_dereference_record *ir)
 {
-   ir->var->accept(this);
+   ir->record->accept(this);
 }
 
 void
index 38572a2057a099e760b2699d934a941c4482751b..9109ce698b234e98ddc9b0cf5c324cdd47591731 100644 (file)
@@ -231,11 +231,11 @@ ir_function_cloning_visitor::visit(ir_dereference_variable *ir)
 void
 ir_function_cloning_visitor::visit(ir_dereference_array *ir)
 {
-   ir->var->accept(this);
+   ir->array->accept(this);
 
    ir_rvalue *var = this->result->as_rvalue();
 
-   ir->selector.array_index->accept(this);
+   ir->array_index->accept(this);
 
    ir_rvalue *index = this->result->as_rvalue();
 
@@ -245,11 +245,11 @@ ir_function_cloning_visitor::visit(ir_dereference_array *ir)
 void
 ir_function_cloning_visitor::visit(ir_dereference_record *ir)
 {
-   ir->var->accept(this);
+   ir->record->accept(this);
 
    ir_rvalue *var = this->result->as_rvalue();
 
-   this->result = new ir_dereference_record(var, strdup(ir->selector.field));
+   this->result = new ir_dereference_record(var, strdup(ir->field));
 }
 
 void
@@ -525,14 +525,14 @@ ir_function_inlining_visitor::visit(ir_dereference_variable *ir)
 void
 ir_function_inlining_visitor::visit(ir_dereference_array *ir)
 {
-   ir->selector.array_index->accept(this);
-   ir->var->accept(this);
+   ir->array_index->accept(this);
+   ir->array->accept(this);
 }
 
 void
 ir_function_inlining_visitor::visit(ir_dereference_record *ir)
 {
-   ir->var->accept(this);
+   ir->record->accept(this);
 }
 
 void
index 08f5394314204f9980a25023e0d92a2570ed0dad..8d535e24faa5bb105c00809e4591f8e4eeb34c97 100644 (file)
@@ -183,11 +183,11 @@ ir_dereference_array::accept(ir_hierarchical_visitor *v)
    if (s != visit_continue)
       return (s == visit_continue_with_parent) ? visit_continue : s;
 
-   s = this->selector.array_index->accept(v);
+   s = this->array_index->accept(v);
    if (s != visit_continue)
       return (s == visit_continue_with_parent) ? visit_continue : s;
 
-   s = this->var->accept(v);
+   s = this->array->accept(v);
    return (s == visit_stop) ? s : v->visit_leave(this);
 }
 
@@ -199,7 +199,7 @@ ir_dereference_record::accept(ir_hierarchical_visitor *v)
    if (s != visit_continue)
       return (s == visit_continue_with_parent) ? visit_continue : s;
 
-   s = this->var->accept(v);
+   s = this->record->accept(v);
    return (s == visit_stop) ? s : v->visit_leave(this);
 }
 
index 7cb5eeba0155bfc05d961007a793d46d7f818104..e507a0ebf99fda0066a34a76ea04f4667a9d9a39 100644 (file)
@@ -171,8 +171,8 @@ void ir_print_visitor::visit(ir_dereference_variable *ir)
 void ir_print_visitor::visit(ir_dereference_array *ir)
 {
    printf("(array_ref ");
-   ir->var->accept(this);
-   ir->selector.array_index->accept(this);
+   ir->array->accept(this);
+   ir->array_index->accept(this);
    printf(") ");
 }
 
@@ -180,8 +180,8 @@ void ir_print_visitor::visit(ir_dereference_array *ir)
 void ir_print_visitor::visit(ir_dereference_record *ir)
 {
    printf("(record_ref ");
-   ir->var->accept(this);
-   printf("(%s)) ", ir->selector.field);
+   ir->record->accept(this);
+   printf("(%s)) ", ir->field);
 }