[Mesa-dev] [PATCH 14/15] glsl: use the linear allocator in opt_constant_propagation

Marek Olšák maraeo at gmail.com
Sat Oct 8 10:58:38 UTC 2016


From: Marek Olšák <marek.olsak at amd.com>

---
 src/compiler/glsl/opt_constant_propagation.cpp | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/compiler/glsl/opt_constant_propagation.cpp b/src/compiler/glsl/opt_constant_propagation.cpp
index 69bca74..4039512 100644
--- a/src/compiler/glsl/opt_constant_propagation.cpp
+++ b/src/compiler/glsl/opt_constant_propagation.cpp
@@ -40,20 +40,23 @@
 #include "ir_basic_block.h"
 #include "ir_optimization.h"
 #include "compiler/glsl_types.h"
 #include "util/hash_table.h"
 
 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 *var, unsigned write_mask, ir_constant *constant)
    {
       assert(var);
       assert(constant);
       this->var = var;
       this->write_mask = write_mask;
       this->constant = constant;
       this->initial_values = write_mask;
    }
 
@@ -70,38 +73,42 @@ public:
    unsigned write_mask;
 
    /** Mask of values initially available in the constant. */
    unsigned initial_values;
 };
 
 
 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, unsigned write_mask)
    {
       assert(var);
       this->var = var;
       this->write_mask = write_mask;
    }
 
    ir_variable *var;
    unsigned write_mask;
 };
 
 class ir_constant_propagation_visitor : public ir_rvalue_visitor {
 public:
    ir_constant_propagation_visitor()
    {
       progress = false;
       killed_all = false;
       mem_ctx = ralloc_context(0);
+      this->lin_ctx = linear_alloc_parent(this->mem_ctx, 0);
       this->acp = new(mem_ctx) exec_list;
       this->kills = _mesa_hash_table_create(mem_ctx, _mesa_hash_pointer,
                                             _mesa_key_pointer_equal);
    }
    ~ir_constant_propagation_visitor()
    {
       ralloc_free(mem_ctx);
    }
 
    virtual ir_visitor_status visit_enter(class ir_loop *);
@@ -125,20 +132,21 @@ public:
     * Hash table of kill_entry: The masks of variables whose values were
     * killed in this block.
     */
    hash_table *kills;
 
    bool progress;
 
    bool killed_all;
 
    void *mem_ctx;
+   void *lin_ctx;
 };
 
 
 void
 ir_constant_propagation_visitor::constant_folding(ir_rvalue **rvalue)
 {
    if (this->in_assignee || *rvalue == NULL)
       return;
 
    if (ir_constant_fold(rvalue))
@@ -347,21 +355,21 @@ ir_constant_propagation_visitor::handle_if_block(exec_list *instructions)
    hash_table *orig_kills = this->kills;
    bool orig_killed_all = this->killed_all;
 
    this->acp = new(mem_ctx) exec_list;
    this->kills = _mesa_hash_table_create(mem_ctx, _mesa_hash_pointer,
                                          _mesa_key_pointer_equal);
    this->killed_all = false;
 
    /* Populate the initial acp with a constant of the original */
    foreach_in_list(acp_entry, a, orig_acp) {
-      this->acp->push_tail(new(this->mem_ctx) 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();
    }
 
    hash_table *new_kills = this->kills;
    this->kills = orig_kills;
@@ -447,21 +455,21 @@ ir_constant_propagation_visitor::kill(ir_variable *var, unsigned write_mask)
     * variables in this block.
     */
    hash_entry *kill_hash_entry = _mesa_hash_table_search(this->kills, var);
    if (kill_hash_entry) {
       kill_entry *entry = (kill_entry *) kill_hash_entry->data;
       entry->write_mask |= write_mask;
       return;
    }
    /* Not already in the hash table.  Make new entry. */
    _mesa_hash_table_insert(this->kills, var,
-                           new(this->mem_ctx) kill_entry(var, write_mask));
+                           new(this->lin_ctx) kill_entry(var, write_mask));
 }
 
 /**
  * Adds an entry to the available constant list if it's a plain assignment
  * of a variable to a variable.
  */
 void
 ir_constant_propagation_visitor::add_constant(ir_assignment *ir)
 {
    acp_entry *entry;
@@ -486,21 +494,21 @@ ir_constant_propagation_visitor::add_constant(ir_assignment *ir)
 
    /* We can't do copy propagation on buffer variables, since the underlying
     * memory storage is shared across multiple threads we can't be sure that
     * the variable value isn't modified between this assignment and the next
     * instruction where its value is read.
     */
    if (deref->var->data.mode == ir_var_shader_storage ||
        deref->var->data.mode == ir_var_shader_shared)
       return;
 
-   entry = new(this->mem_ctx) acp_entry(deref->var, ir->write_mask, constant);
+   entry = new(this->lin_ctx) acp_entry(deref->var, ir->write_mask, constant);
    this->acp->push_tail(entry);
 }
 
 } /* unnamed namespace */
 
 /**
  * Does a constant propagation pass on the code present in the instruction stream.
  */
 bool
 do_constant_propagation(exec_list *instructions)
-- 
2.7.4



More information about the mesa-dev mailing list