From: Ian Romanick Date: Wed, 19 May 2010 11:52:29 +0000 (+0200) Subject: Refactor ir_dereference data fields to subclasses X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=36ea28646c666ac2af9b43c47e65f9f53ffcc390;p=mesa.git Refactor ir_dereference data fields to subclasses --- diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp index b8128fa8a77..64f8ef49681 100644 --- a/ast_to_hir.cpp +++ b/ast_to_hir.cpp @@ -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 f6f2558bc06..a147339b1a7 100644 --- 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 2d641766b2e..2e6a1943214 100644 --- 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; }; diff --git a/ir_constant_expression.cpp b/ir_constant_expression.cpp index 076fdfda75f..b1092de1393 100644 --- a/ir_constant_expression.cpp +++ b/ir_constant_expression.cpp @@ -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. */ } diff --git a/ir_constant_folding.cpp b/ir_constant_folding.cpp index 9a2a7f3f2e7..c7019ffc626 100644 --- a/ir_constant_folding.cpp +++ b/ir_constant_folding.cpp @@ -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); } diff --git a/ir_copy_propagation.cpp b/ir_copy_propagation.cpp index 47f9390710c..e395fa9723b 100644 --- a/ir_copy_propagation.cpp +++ b/ir_copy_propagation.cpp @@ -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); diff --git a/ir_dead_code_local.cpp b/ir_dead_code_local.cpp index e3c0e533032..9ac209df576 100644 --- a/ir_dead_code_local.cpp +++ b/ir_dead_code_local.cpp @@ -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; } diff --git a/ir_expression_flattening.cpp b/ir_expression_flattening.cpp index 1e0244988a2..3403389c9c4 100644 --- a/ir_expression_flattening.cpp +++ b/ir_expression_flattening.cpp @@ -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 diff --git a/ir_function_inlining.cpp b/ir_function_inlining.cpp index 38572a2057a..9109ce698b2 100644 --- a/ir_function_inlining.cpp +++ b/ir_function_inlining.cpp @@ -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 diff --git a/ir_hv_accept.cpp b/ir_hv_accept.cpp index 08f53943142..8d535e24faa 100644 --- a/ir_hv_accept.cpp +++ b/ir_hv_accept.cpp @@ -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); } diff --git a/ir_print_visitor.cpp b/ir_print_visitor.cpp index 7cb5eeba015..e507a0ebf99 100644 --- a/ir_print_visitor.cpp +++ b/ir_print_visitor.cpp @@ -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); }