From: Marek Olšák <marek.ol...@amd.com> --- src/compiler/glsl/opt_copy_propagation_elements.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/compiler/glsl/opt_copy_propagation_elements.cpp b/src/compiler/glsl/opt_copy_propagation_elements.cpp index e4237cc..2bbe93d 100644 --- a/src/compiler/glsl/opt_copy_propagation_elements.cpp +++ b/src/compiler/glsl/opt_copy_propagation_elements.cpp @@ -47,20 +47,23 @@ #include "ir_optimization.h" #include "compiler/glsl_types.h" static bool debug = false; namespace { class acp_entry : public exec_node { public: + /* override operator new from exec_node */ + DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(acp_entry) + acp_entry(ir_variable *lhs, ir_variable *rhs, int write_mask, int swizzle[4]) { this->lhs = lhs; this->rhs = rhs; this->write_mask = write_mask; memcpy(this->swizzle, swizzle, sizeof(this->swizzle)); } acp_entry(acp_entry *a) { @@ -73,37 +76,41 @@ public: ir_variable *lhs; ir_variable *rhs; unsigned int write_mask; int swizzle[4]; }; class kill_entry : public exec_node { public: + /* override operator new from exec_node */ + DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(kill_entry) + kill_entry(ir_variable *var, int write_mask) { this->var = var; this->write_mask = write_mask; } ir_variable *var; unsigned int write_mask; }; class ir_copy_propagation_elements_visitor : public ir_rvalue_visitor { public: ir_copy_propagation_elements_visitor() { this->progress = false; this->killed_all = false; this->mem_ctx = ralloc_context(NULL); + this->lin_ctx = linear_alloc_parent(this->mem_ctx, 0); this->shader_mem_ctx = NULL; this->acp = new(mem_ctx) exec_list; this->kills = new(mem_ctx) exec_list; } ~ir_copy_propagation_elements_visitor() { ralloc_free(mem_ctx); } void handle_loop(ir_loop *, bool keep_acp); @@ -127,20 +134,21 @@ public: * block. */ exec_list *kills; bool progress; bool killed_all; /* Context for our local data structures. */ void *mem_ctx; + void *lin_ctx; /* Context for allocating new shader nodes. */ void *shader_mem_ctx; }; } /* unnamed namespace */ ir_visitor_status ir_copy_propagation_elements_visitor::visit_enter(ir_function_signature *ir) { /* Treat entry into a function signature as a completely separate @@ -170,23 +178,23 @@ ir_copy_propagation_elements_visitor::visit_enter(ir_function_signature *ir) ir_visitor_status ir_copy_propagation_elements_visitor::visit_leave(ir_assignment *ir) { ir_dereference_variable *lhs = ir->lhs->as_dereference_variable(); ir_variable *var = ir->lhs->variable_referenced(); if (var->type->is_scalar() || var->type->is_vector()) { kill_entry *k; if (lhs) - k = new(this->kills) kill_entry(var, ir->write_mask); + k = new(this->lin_ctx) kill_entry(var, ir->write_mask); else - k = new(this->kills) kill_entry(var, ~0); + k = new(this->lin_ctx) kill_entry(var, ~0); kill(k); } add_copy(ir); return visit_continue; } ir_visitor_status @@ -331,21 +339,21 @@ ir_copy_propagation_elements_visitor::handle_if_block(exec_list *instructions) exec_list *orig_acp = this->acp; exec_list *orig_kills = this->kills; bool orig_killed_all = this->killed_all; this->acp = new(mem_ctx) exec_list; this->kills = new(mem_ctx) exec_list; this->killed_all = false; /* Populate the initial acp with a copy of the original */ foreach_in_list(acp_entry, a, orig_acp) { - this->acp->push_tail(new(this->acp) acp_entry(a)); + this->acp->push_tail(new(this->lin_ctx) acp_entry(a)); } visit_list_elements(this, instructions); if (this->killed_all) { orig_acp->make_empty(); } exec_list *new_kills = this->kills; this->kills = orig_kills; @@ -386,21 +394,21 @@ ir_copy_propagation_elements_visitor::handle_loop(ir_loop *ir, bool keep_acp) * We could go through once, then go through again with the acp * cloned minus the killed entries after the first run through. */ this->acp = new(mem_ctx) exec_list; this->kills = new(mem_ctx) exec_list; this->killed_all = false; if (keep_acp) { /* Populate the initial acp with a copy of the original */ foreach_in_list(acp_entry, a, orig_acp) { - this->acp->push_tail(new(this->acp) acp_entry(a)); + this->acp->push_tail(new(this->lin_ctx) acp_entry(a)); } } visit_list_elements(this, &ir->body_instructions); if (this->killed_all) { orig_acp->make_empty(); } exec_list *new_kills = this->kills; @@ -440,21 +448,20 @@ ir_copy_propagation_elements_visitor::kill(kill_entry *k) } if (entry->rhs == k->var) { entry->remove(); } } /* If we were on a list, remove ourselves before inserting */ if (k->next) k->remove(); - ralloc_steal(this->kills, k); this->kills->push_tail(k); } /** * Adds directly-copied channels between vector variables to the available * copy propagation list. */ void ir_copy_propagation_elements_visitor::add_copy(ir_assignment *ir) { @@ -504,21 +511,21 @@ ir_copy_propagation_elements_visitor::add_copy(ir_assignment *ir) */ for (int i = 0; i < 4; i++) { if (ir->write_mask & (1 << orig_swizzle[i])) write_mask &= ~(1 << i); } } if (lhs->var->data.precise != rhs->var->data.precise) return; - entry = new(this->mem_ctx) acp_entry(lhs->var, rhs->var, write_mask, + entry = new(this->lin_ctx) acp_entry(lhs->var, rhs->var, write_mask, swizzle); this->acp->push_tail(entry); } bool do_copy_propagation_elements(exec_list *instructions) { ir_copy_propagation_elements_visitor v; visit_list_elements(&v, instructions); -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev