#include "ir.h"
#include "ir_visitor.h"
+#include "ir_rvalue_visitor.h"
#include "ir_function_inlining.h"
#include "ir_expression_flattening.h"
#include "compiler/glsl_types.h"
static void
do_variable_replacement(exec_list *instructions,
ir_variable *orig,
- ir_dereference *repl);
+ ir_rvalue *repl);
namespace {
ir_variable *sig_param = (ir_variable *) formal_node;
if (should_replace_variable(sig_param, param)) {
- ir_dereference *deref = param->as_dereference();
-
- do_variable_replacement(&new_instructions, sig_param, deref);
+ do_variable_replacement(&new_instructions, sig_param, param);
}
}
* also appear in the sampler field of an ir_tex instruction.
*/
-class ir_variable_replacement_visitor : public ir_hierarchical_visitor {
+class ir_variable_replacement_visitor : public ir_rvalue_visitor {
public:
- ir_variable_replacement_visitor(ir_variable *orig, ir_dereference *repl)
+ ir_variable_replacement_visitor(ir_variable *orig, ir_rvalue *repl)
{
this->orig = orig;
this->repl = repl;
}
virtual ir_visitor_status visit_leave(ir_call *);
- virtual ir_visitor_status visit_leave(ir_dereference_array *);
- virtual ir_visitor_status visit_leave(ir_dereference_record *);
virtual ir_visitor_status visit_leave(ir_texture *);
virtual ir_visitor_status visit_leave(ir_assignment *);
- virtual ir_visitor_status visit_leave(ir_expression *);
- virtual ir_visitor_status visit_leave(ir_return *);
+ void handle_rvalue(ir_rvalue **rvalue);
void replace_deref(ir_dereference **deref);
void replace_rvalue(ir_rvalue **rvalue);
ir_variable *orig;
- ir_dereference *repl;
+ ir_rvalue *repl;
};
void
ir_variable_replacement_visitor::replace_deref(ir_dereference **deref)
{
ir_dereference_variable *deref_var = (*deref)->as_dereference_variable();
- if (deref_var && deref_var->var == this->orig) {
- *deref = this->repl->clone(ralloc_parent(*deref), NULL);
- }
+ if (deref_var && deref_var->var == this->orig)
+ *deref = this->repl->as_dereference()->clone(ralloc_parent(*deref), NULL);
+}
+
+void
+ir_variable_replacement_visitor::handle_rvalue(ir_rvalue **rvalue)
+{
+ replace_rvalue(rvalue);
}
void
if (!deref)
return;
- replace_deref(&deref);
- *rvalue = deref;
+ ir_dereference_variable *deref_var = (deref)->as_dereference_variable();
+ if (deref_var && deref_var->var == this->orig)
+ *rvalue = this->repl->clone(ralloc_parent(deref), NULL);
}
ir_visitor_status
{
replace_deref(&ir->sampler);
- return visit_continue;
+ return rvalue_visit(ir);
}
ir_visitor_status
}
ir_visitor_status
-ir_variable_replacement_visitor::visit_leave(ir_expression *ir)
-{
- for (uint8_t i = 0; i < ir->num_operands; i++)
- replace_rvalue(&ir->operands[i]);
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_variable_replacement_visitor::visit_leave(ir_return *ir)
-{
- replace_rvalue(&ir->value);
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_variable_replacement_visitor::visit_leave(ir_dereference_array *ir)
-{
- replace_rvalue(&ir->array);
- return visit_continue;
-}
-
-ir_visitor_status
-ir_variable_replacement_visitor::visit_leave(ir_dereference_record *ir)
-{
- replace_rvalue(&ir->record);
- return visit_continue;
-}
-
-ir_visitor_status
ir_variable_replacement_visitor::visit_leave(ir_call *ir)
{
foreach_in_list_safe(ir_rvalue, param, &ir->actual_parameters) {
replace_rvalue(&new_param);
if (new_param != param) {
- param->replace_with(new_param);
+ param->replace_with(new_param);
}
}
return visit_continue;
static void
do_variable_replacement(exec_list *instructions,
ir_variable *orig,
- ir_dereference *repl)
+ ir_rvalue *repl)
{
ir_variable_replacement_visitor v(orig, repl);