Refactor ir_dereference data fields to subclasses
This commit is contained in:
parent
7fe3de6fde
commit
36ea28646c
|
@ -482,7 +482,7 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
|
||||||
|
|
||||||
assert(d != NULL);
|
assert(d != NULL);
|
||||||
|
|
||||||
ir_variable *const var = d->var->as_variable();
|
ir_variable *const var = d->variable_referenced();
|
||||||
|
|
||||||
assert(var != NULL);
|
assert(var != NULL);
|
||||||
|
|
||||||
|
|
26
ir.cpp
26
ir.cpp
|
@ -235,7 +235,7 @@ ir_dereference_array::ir_dereference_array(ir_rvalue *value,
|
||||||
ir_rvalue *array_index)
|
ir_rvalue *array_index)
|
||||||
: ir_dereference(ir_reference_array)
|
: ir_dereference(ir_reference_array)
|
||||||
{
|
{
|
||||||
this->selector.array_index = array_index;
|
this->array_index = array_index;
|
||||||
this->set_array(value);
|
this->set_array(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ ir_dereference_array::ir_dereference_array(ir_variable *var,
|
||||||
ir_rvalue *array_index)
|
ir_rvalue *array_index)
|
||||||
: ir_dereference(ir_reference_array)
|
: ir_dereference(ir_reference_array)
|
||||||
{
|
{
|
||||||
this->selector.array_index = array_index;
|
this->array_index = array_index;
|
||||||
this->set_array(new ir_dereference_variable(var));
|
this->set_array(new ir_dereference_variable(var));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,11 +252,11 @@ ir_dereference_array::ir_dereference_array(ir_variable *var,
|
||||||
void
|
void
|
||||||
ir_dereference_array::set_array(ir_rvalue *value)
|
ir_dereference_array::set_array(ir_rvalue *value)
|
||||||
{
|
{
|
||||||
this->var = value;
|
this->array = value;
|
||||||
this->type = glsl_type::error_type;
|
this->type = glsl_type::error_type;
|
||||||
|
|
||||||
if (this->var != NULL) {
|
if (this->array != NULL) {
|
||||||
const glsl_type *const vt = this->var->type;
|
const glsl_type *const vt = this->array->type;
|
||||||
|
|
||||||
if (vt->is_array()) {
|
if (vt->is_array()) {
|
||||||
type = vt->element_type();
|
type = vt->element_type();
|
||||||
|
@ -273,10 +273,10 @@ ir_dereference_record::ir_dereference_record(ir_rvalue *value,
|
||||||
const char *field)
|
const char *field)
|
||||||
: ir_dereference(ir_reference_record)
|
: ir_dereference(ir_reference_record)
|
||||||
{
|
{
|
||||||
this->var = value;
|
this->record = value;
|
||||||
this->selector.field = field;
|
this->field = field;
|
||||||
this->type = (this->var != NULL)
|
this->type = (this->record != NULL)
|
||||||
? this->var->type->field_type(field) : glsl_type::error_type;
|
? 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)
|
const char *field)
|
||||||
: ir_dereference(ir_reference_record)
|
: ir_dereference(ir_reference_record)
|
||||||
{
|
{
|
||||||
this->var = new ir_dereference_variable(var);
|
this->record = new ir_dereference_variable(var);
|
||||||
this->selector.field = field;
|
this->field = field;
|
||||||
this->type = (this->var != NULL)
|
this->type = (this->record != NULL)
|
||||||
? this->var->type->field_type(field) : glsl_type::error_type;
|
? this->record->type->field_type(field) : glsl_type::error_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
29
ir.h
29
ir.h
|
@ -806,18 +806,6 @@ public:
|
||||||
ir_reference_record
|
ir_reference_record
|
||||||
} mode;
|
} 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:
|
protected:
|
||||||
ir_dereference(ir_deref_mode mode)
|
ir_dereference(ir_deref_mode mode)
|
||||||
: mode(mode)
|
: mode(mode)
|
||||||
|
@ -836,7 +824,7 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual ir_variable *variable_referenced()
|
virtual ir_variable *variable_referenced()
|
||||||
{
|
{
|
||||||
return (ir_variable *) this->var;
|
return this->var;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void accept(ir_visitor *v)
|
virtual void accept(ir_visitor *v)
|
||||||
|
@ -845,6 +833,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
|
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object being dereferenced.
|
||||||
|
*/
|
||||||
|
ir_variable *var;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -859,7 +852,7 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual ir_variable *variable_referenced()
|
virtual ir_variable *variable_referenced()
|
||||||
{
|
{
|
||||||
return ((ir_rvalue *) this->var)->variable_referenced();
|
return this->array->variable_referenced();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void accept(ir_visitor *v)
|
virtual void accept(ir_visitor *v)
|
||||||
|
@ -869,6 +862,9 @@ public:
|
||||||
|
|
||||||
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
|
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
|
||||||
|
|
||||||
|
ir_rvalue *array;
|
||||||
|
ir_rvalue *array_index;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void set_array(ir_rvalue *value);
|
void set_array(ir_rvalue *value);
|
||||||
};
|
};
|
||||||
|
@ -885,7 +881,7 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual ir_variable *variable_referenced()
|
virtual ir_variable *variable_referenced()
|
||||||
{
|
{
|
||||||
return ((ir_rvalue *) this->var)->variable_referenced();
|
return this->record->variable_referenced();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void accept(ir_visitor *v)
|
virtual void accept(ir_visitor *v)
|
||||||
|
@ -894,6 +890,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
|
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
|
||||||
|
|
||||||
|
ir_rvalue *record;
|
||||||
|
const char *field;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -427,6 +427,7 @@ ir_constant_visitor::visit(ir_dereference_variable *ir)
|
||||||
void
|
void
|
||||||
ir_constant_visitor::visit(ir_dereference_array *ir)
|
ir_constant_visitor::visit(ir_dereference_array *ir)
|
||||||
{
|
{
|
||||||
|
(void) ir;
|
||||||
value = NULL;
|
value = NULL;
|
||||||
/* FINISHME: Other dereference modes. */
|
/* FINISHME: Other dereference modes. */
|
||||||
}
|
}
|
||||||
|
@ -435,6 +436,7 @@ ir_constant_visitor::visit(ir_dereference_array *ir)
|
||||||
void
|
void
|
||||||
ir_constant_visitor::visit(ir_dereference_record *ir)
|
ir_constant_visitor::visit(ir_dereference_record *ir)
|
||||||
{
|
{
|
||||||
|
(void) ir;
|
||||||
value = NULL;
|
value = NULL;
|
||||||
/* FINISHME: Other dereference modes. */
|
/* FINISHME: Other dereference modes. */
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,21 +129,21 @@ void
|
||||||
ir_constant_folding_visitor::visit(ir_dereference_array *ir)
|
ir_constant_folding_visitor::visit(ir_dereference_array *ir)
|
||||||
{
|
{
|
||||||
ir_constant *const_val =
|
ir_constant *const_val =
|
||||||
ir->selector.array_index->constant_expression_value();
|
ir->array_index->constant_expression_value();
|
||||||
|
|
||||||
if (const_val)
|
if (const_val)
|
||||||
ir->selector.array_index = const_val;
|
ir->array_index = const_val;
|
||||||
else
|
else
|
||||||
ir->selector.array_index->accept(this);
|
ir->array_index->accept(this);
|
||||||
|
|
||||||
ir->var->accept(this);
|
ir->array->accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ir_constant_folding_visitor::visit(ir_dereference_record *ir)
|
ir_constant_folding_visitor::visit(ir_dereference_record *ir)
|
||||||
{
|
{
|
||||||
ir->var->accept(this);
|
ir->record->accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -169,14 +169,14 @@ ir_copy_propagation_visitor::visit(ir_dereference_variable *ir)
|
||||||
void
|
void
|
||||||
ir_copy_propagation_visitor::visit(ir_dereference_array *ir)
|
ir_copy_propagation_visitor::visit(ir_dereference_array *ir)
|
||||||
{
|
{
|
||||||
ir->var->accept(this);
|
ir->array->accept(this);
|
||||||
ir->selector.array_index->accept(this);
|
ir->array_index->accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ir_copy_propagation_visitor::visit(ir_dereference_record *ir)
|
ir_copy_propagation_visitor::visit(ir_dereference_record *ir)
|
||||||
{
|
{
|
||||||
ir->var->accept(this);
|
ir->record->accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -270,12 +270,12 @@ add_copy(ir_assignment *ir, exec_list *acp)
|
||||||
ir_dereference *lhs_deref = ir->lhs->as_dereference();
|
ir_dereference *lhs_deref = ir->lhs->as_dereference();
|
||||||
if (!lhs_deref || lhs_deref->mode != ir_dereference::ir_reference_variable)
|
if (!lhs_deref || lhs_deref->mode != ir_dereference::ir_reference_variable)
|
||||||
return;
|
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();
|
ir_dereference *rhs_deref = ir->rhs->as_dereference();
|
||||||
if (!rhs_deref || rhs_deref->mode != ir_dereference::ir_reference_variable)
|
if (!rhs_deref || rhs_deref->mode != ir_dereference::ir_reference_variable)
|
||||||
return;
|
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);
|
entry = new acp_entry(lhs_var, rhs_var);
|
||||||
acp->push_tail(entry);
|
acp->push_tail(entry);
|
||||||
|
|
|
@ -94,7 +94,7 @@ public:
|
||||||
|
|
||||||
virtual ir_visitor_status visit_enter(class ir_dereference_array *ir)
|
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;
|
return visit_continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -172,14 +172,14 @@ ir_expression_flattening_visitor::visit(ir_dereference_variable *ir)
|
||||||
void
|
void
|
||||||
ir_expression_flattening_visitor::visit(ir_dereference_array *ir)
|
ir_expression_flattening_visitor::visit(ir_dereference_array *ir)
|
||||||
{
|
{
|
||||||
ir->selector.array_index->accept(this);
|
ir->array_index->accept(this);
|
||||||
ir->var->accept(this);
|
ir->array->accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ir_expression_flattening_visitor::visit(ir_dereference_record *ir)
|
ir_expression_flattening_visitor::visit(ir_dereference_record *ir)
|
||||||
{
|
{
|
||||||
ir->var->accept(this);
|
ir->record->accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -231,11 +231,11 @@ ir_function_cloning_visitor::visit(ir_dereference_variable *ir)
|
||||||
void
|
void
|
||||||
ir_function_cloning_visitor::visit(ir_dereference_array *ir)
|
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_rvalue *var = this->result->as_rvalue();
|
||||||
|
|
||||||
ir->selector.array_index->accept(this);
|
ir->array_index->accept(this);
|
||||||
|
|
||||||
ir_rvalue *index = this->result->as_rvalue();
|
ir_rvalue *index = this->result->as_rvalue();
|
||||||
|
|
||||||
|
@ -245,11 +245,11 @@ ir_function_cloning_visitor::visit(ir_dereference_array *ir)
|
||||||
void
|
void
|
||||||
ir_function_cloning_visitor::visit(ir_dereference_record *ir)
|
ir_function_cloning_visitor::visit(ir_dereference_record *ir)
|
||||||
{
|
{
|
||||||
ir->var->accept(this);
|
ir->record->accept(this);
|
||||||
|
|
||||||
ir_rvalue *var = this->result->as_rvalue();
|
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
|
void
|
||||||
|
@ -525,14 +525,14 @@ ir_function_inlining_visitor::visit(ir_dereference_variable *ir)
|
||||||
void
|
void
|
||||||
ir_function_inlining_visitor::visit(ir_dereference_array *ir)
|
ir_function_inlining_visitor::visit(ir_dereference_array *ir)
|
||||||
{
|
{
|
||||||
ir->selector.array_index->accept(this);
|
ir->array_index->accept(this);
|
||||||
ir->var->accept(this);
|
ir->array->accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ir_function_inlining_visitor::visit(ir_dereference_record *ir)
|
ir_function_inlining_visitor::visit(ir_dereference_record *ir)
|
||||||
{
|
{
|
||||||
ir->var->accept(this);
|
ir->record->accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -183,11 +183,11 @@ ir_dereference_array::accept(ir_hierarchical_visitor *v)
|
||||||
if (s != visit_continue)
|
if (s != visit_continue)
|
||||||
return (s == visit_continue_with_parent) ? visit_continue : s;
|
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)
|
if (s != visit_continue)
|
||||||
return (s == visit_continue_with_parent) ? visit_continue : s;
|
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);
|
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)
|
if (s != visit_continue)
|
||||||
return (s == visit_continue_with_parent) ? visit_continue : s;
|
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);
|
return (s == visit_stop) ? s : v->visit_leave(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,8 +171,8 @@ void ir_print_visitor::visit(ir_dereference_variable *ir)
|
||||||
void ir_print_visitor::visit(ir_dereference_array *ir)
|
void ir_print_visitor::visit(ir_dereference_array *ir)
|
||||||
{
|
{
|
||||||
printf("(array_ref ");
|
printf("(array_ref ");
|
||||||
ir->var->accept(this);
|
ir->array->accept(this);
|
||||||
ir->selector.array_index->accept(this);
|
ir->array_index->accept(this);
|
||||||
printf(") ");
|
printf(") ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,8 +180,8 @@ void ir_print_visitor::visit(ir_dereference_array *ir)
|
||||||
void ir_print_visitor::visit(ir_dereference_record *ir)
|
void ir_print_visitor::visit(ir_dereference_record *ir)
|
||||||
{
|
{
|
||||||
printf("(record_ref ");
|
printf("(record_ref ");
|
||||||
ir->var->accept(this);
|
ir->record->accept(this);
|
||||||
printf("(%s)) ", ir->selector.field);
|
printf("(%s)) ", ir->field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue