X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fglsl%2Fopt_copy_propagation.cpp;h=806027b280ea9d39e80f8b681a0e0bcf2d06460a;hb=1286bd3160bc1e70fa3bba2ec12999b2a02ffad9;hp=0fe8fa6c41959e8c3a7d0cac8e8844e964388e3f;hpb=32aaf89823de11e98cb59d5ec78c66cd3e74bcd4;p=mesa.git diff --git a/src/glsl/opt_copy_propagation.cpp b/src/glsl/opt_copy_propagation.cpp index 0fe8fa6c419..806027b280e 100644 --- a/src/glsl/opt_copy_propagation.cpp +++ b/src/glsl/opt_copy_propagation.cpp @@ -22,7 +22,7 @@ */ /** - * \file ir_copy_propagation.cpp + * \file opt_copy_propagation.cpp * * Moves usage of recently-copied variables to the previous copy of * the variable. @@ -38,6 +38,8 @@ #include "ir_optimization.h" #include "glsl_types.h" +namespace { + class acp_entry : public exec_node { public: @@ -71,13 +73,13 @@ public: ir_copy_propagation_visitor() { progress = false; - mem_ctx = talloc_new(0); + mem_ctx = ralloc_context(0); this->acp = new(mem_ctx) exec_list; this->kills = new(mem_ctx) exec_list; } ~ir_copy_propagation_visitor() { - talloc_free(mem_ctx); + ralloc_free(mem_ctx); } virtual ir_visitor_status visit(class ir_dereference_variable *); @@ -107,6 +109,8 @@ public: void *mem_ctx; }; +} /* unnamed namespace */ + ir_visitor_status ir_copy_propagation_visitor::visit_enter(ir_function_signature *ir) { @@ -124,6 +128,9 @@ ir_copy_propagation_visitor::visit_enter(ir_function_signature *ir) visit_list_elements(this, &ir->body); + ralloc_free(this->acp); + ralloc_free(this->kills); + this->kills = orig_kills; this->acp = orig_acp; this->killed_all = orig_killed_all; @@ -163,9 +170,7 @@ ir_copy_propagation_visitor::visit(ir_dereference_variable *ir) ir_variable *var = ir->var; - foreach_iter(exec_list_iterator, iter, *this->acp) { - acp_entry *entry = (acp_entry *)iter.get(); - + foreach_in_list(acp_entry, entry, this->acp) { if (var == entry->lhs) { ir->var = entry->rhs; this->progress = true; @@ -181,17 +186,17 @@ ir_visitor_status ir_copy_propagation_visitor::visit_enter(ir_call *ir) { /* Do copy propagation on call parameters, but skip any out params */ - exec_list_iterator sig_param_iter = ir->get_callee()->parameters.iterator(); - foreach_iter(exec_list_iterator, iter, ir->actual_parameters) { - ir_variable *sig_param = (ir_variable *)sig_param_iter.get(); - ir_instruction *ir = (ir_instruction *)iter.get(); - if (sig_param->mode != ir_var_out && sig_param->mode != ir_var_inout) { + foreach_two_lists(formal_node, &ir->callee->parameters, + actual_node, &ir->actual_parameters) { + ir_variable *sig_param = (ir_variable *) formal_node; + ir_rvalue *ir = (ir_rvalue *) actual_node; + if (sig_param->data.mode != ir_var_function_out + && sig_param->data.mode != ir_var_function_inout) { ir->accept(this); } - sig_param_iter.next(); } - /* Since we're unlinked, we don't (necssarily) know the side effects of + /* Since we're unlinked, we don't (necessarily) know the side effects of * this call. So kill all copies. */ acp->make_empty(); @@ -212,9 +217,8 @@ ir_copy_propagation_visitor::handle_if_block(exec_list *instructions) this->killed_all = false; /* Populate the initial acp with a copy of the original */ - foreach_iter(exec_list_iterator, iter, *orig_acp) { - acp_entry *a = (acp_entry *)iter.get(); - this->acp->push_tail(new(this->mem_ctx) acp_entry(a->lhs, a->rhs)); + foreach_in_list(acp_entry, a, orig_acp) { + this->acp->push_tail(new(this->acp) acp_entry(a->lhs, a->rhs)); } visit_list_elements(this, instructions); @@ -225,13 +229,15 @@ ir_copy_propagation_visitor::handle_if_block(exec_list *instructions) exec_list *new_kills = this->kills; this->kills = orig_kills; + ralloc_free(this->acp); this->acp = orig_acp; this->killed_all = this->killed_all || orig_killed_all; - foreach_iter(exec_list_iterator, iter, *new_kills) { - kill_entry *k = (kill_entry *)iter.get(); + foreach_in_list(kill_entry, k, new_kills) { kill(k->var); } + + ralloc_free(new_kills); } ir_visitor_status @@ -269,14 +275,16 @@ ir_copy_propagation_visitor::visit_enter(ir_loop *ir) exec_list *new_kills = this->kills; this->kills = orig_kills; + ralloc_free(this->acp); this->acp = orig_acp; this->killed_all = this->killed_all || orig_killed_all; - foreach_iter(exec_list_iterator, iter, *new_kills) { - kill_entry *k = (kill_entry *)iter.get(); + foreach_in_list(kill_entry, k, new_kills) { kill(k->var); } + ralloc_free(new_kills); + /* already descended into the children. */ return visit_continue_with_parent; } @@ -287,9 +295,7 @@ ir_copy_propagation_visitor::kill(ir_variable *var) assert(var != NULL); /* Remove any entries currently in the ACP for this kill. */ - foreach_iter(exec_list_iterator, iter, *acp) { - acp_entry *entry = (acp_entry *)iter.get(); - + foreach_in_list_safe(acp_entry, entry, acp) { if (entry->lhs == var || entry->rhs == var) { entry->remove(); } @@ -297,7 +303,7 @@ ir_copy_propagation_visitor::kill(ir_variable *var) /* Add the LHS variable to the list of killed variables in this block. */ - this->kills->push_tail(new(this->mem_ctx) kill_entry(var)); + this->kills->push_tail(new(this->kills) kill_entry(var)); } /** @@ -309,11 +315,8 @@ ir_copy_propagation_visitor::add_copy(ir_assignment *ir) { acp_entry *entry; - if (ir->condition) { - ir_constant *condition = ir->condition->as_constant(); - if (!condition || !condition->value.b[0]) - return; - } + if (ir->condition) + return; ir_variable *lhs_var = ir->whole_variable_written(); ir_variable *rhs_var = ir->rhs->whole_variable_referenced(); @@ -325,10 +328,10 @@ ir_copy_propagation_visitor::add_copy(ir_assignment *ir) * calling us. Just flag it to not execute, and someone else * will clean up the mess. */ - ir->condition = new(talloc_parent(ir)) ir_constant(false); + ir->condition = new(ralloc_parent(ir)) ir_constant(false); this->progress = true; } else { - entry = new(this->mem_ctx) acp_entry(lhs_var, rhs_var); + entry = new(this->acp) acp_entry(lhs_var, rhs_var); this->acp->push_tail(entry); } }