[Mesa-dev] [PATCH 05/14] glsl: Use dyn_array instead of the exec_list
Thomas Helland
thomashelland90 at gmail.com
Sun Jan 1 18:37:49 UTC 2017
This should give us lower memory consumption, allocation overhead,
better cache locality, and all this nice stuff.
---
src/compiler/glsl/opt_copy_propagation.cpp | 57 +++++++++++++-----------------
1 file changed, 25 insertions(+), 32 deletions(-)
diff --git a/src/compiler/glsl/opt_copy_propagation.cpp b/src/compiler/glsl/opt_copy_propagation.cpp
index e9f82e0644..aa5e813553 100644
--- a/src/compiler/glsl/opt_copy_propagation.cpp
+++ b/src/compiler/glsl/opt_copy_propagation.cpp
@@ -38,24 +38,10 @@
#include "ir_optimization.h"
#include "compiler/glsl_types.h"
#include "util/hash_table.h"
+#include "util/dyn_array.h"
namespace {
-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)
- {
- assert(var);
- this->var = var;
- }
-
- ir_variable *var;
-};
-
class ir_copy_propagation_visitor : public ir_hierarchical_visitor {
public:
ir_copy_propagation_visitor()
@@ -65,7 +51,8 @@ public:
lin_ctx = linear_alloc_parent(mem_ctx, 0);
acp = _mesa_hash_table_create(mem_ctx, _mesa_hash_pointer,
_mesa_key_pointer_equal);
- this->kills = new(mem_ctx) exec_list;
+ this->kills = ralloc(mem_ctx, dyn_array);
+ dyn_array_init(this->kills, mem_ctx);
killed_all = false;
}
~ir_copy_propagation_visitor()
@@ -89,10 +76,9 @@ public:
/** Hash of lhs->rhs: The available copies to propagate */
hash_table *acp;
/**
- * List of kill_entry: The variables whose values were killed in this
- * block.
+ * List of the variables whose values were killed in this block.
*/
- exec_list *kills;
+ dyn_array *kills;
bool progress;
@@ -112,12 +98,13 @@ ir_copy_propagation_visitor::visit_enter(ir_function_signature *ir)
* main() at link time, so they're irrelevant to us.
*/
hash_table *orig_acp = this->acp;
- exec_list *orig_kills = this->kills;
+ dyn_array *orig_kills = this->kills;
bool orig_killed_all = this->killed_all;
acp = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal);
- this->kills = new(mem_ctx) exec_list;
+ this->kills = ralloc(mem_ctx, dyn_array);
+ dyn_array_init(this->kills, mem_ctx);
this->killed_all = false;
visit_list_elements(this, &ir->body);
@@ -199,12 +186,13 @@ void
ir_copy_propagation_visitor::handle_if_block(exec_list *instructions)
{
hash_table *orig_acp = this->acp;
- exec_list *orig_kills = this->kills;
+ dyn_array *orig_kills = this->kills;
bool orig_killed_all = this->killed_all;
acp = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal);
- this->kills = new(mem_ctx) exec_list;
+ this->kills = ralloc(mem_ctx, dyn_array);
+ dyn_array_init(this->kills, mem_ctx);
this->killed_all = false;
/* Populate the initial acp with a copy of the original */
@@ -220,16 +208,18 @@ ir_copy_propagation_visitor::handle_if_block(exec_list *instructions)
_mesa_hash_table_clear(orig_acp, NULL);
}
- exec_list *new_kills = this->kills;
+ dyn_array *new_kills = this->kills;
this->kills = orig_kills;
_mesa_hash_table_destroy(acp, NULL);
this->acp = orig_acp;
this->killed_all = this->killed_all || orig_killed_all;
- foreach_in_list(kill_entry, k, new_kills) {
- kill(k->var);
+ dyn_array_foreach(new_kills, ir_variable *, var_ptr) {
+ ir_variable *var = *var_ptr;
+ kill(var);
}
+ dyn_array_fini(new_kills);
ralloc_free(new_kills);
}
@@ -249,12 +239,13 @@ void
ir_copy_propagation_visitor::handle_loop(ir_loop *ir, bool keep_acp)
{
hash_table *orig_acp = this->acp;
- exec_list *orig_kills = this->kills;
+ dyn_array *orig_kills = this->kills;
bool orig_killed_all = this->killed_all;
acp = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal);
- this->kills = new(mem_ctx) exec_list;
+ this->kills = ralloc(mem_ctx, dyn_array);
+ dyn_array_init(this->kills, mem_ctx);
this->killed_all = false;
if (keep_acp) {
@@ -271,16 +262,18 @@ ir_copy_propagation_visitor::handle_loop(ir_loop *ir, bool keep_acp)
_mesa_hash_table_clear(orig_acp, NULL);
}
- exec_list *new_kills = this->kills;
+ dyn_array *new_kills = this->kills;
this->kills = orig_kills;
_mesa_hash_table_destroy(acp, NULL);
this->acp = orig_acp;
this->killed_all = this->killed_all || orig_killed_all;
- foreach_in_list(kill_entry, k, new_kills) {
- kill(k->var);
+ dyn_array_foreach(new_kills, ir_variable *, var_ptr) {
+ ir_variable *var = *var_ptr;
+ kill(var);
}
+ dyn_array_fini(new_kills);
ralloc_free(new_kills);
}
@@ -320,7 +313,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->lin_ctx) kill_entry(var));
+ dyn_array_add(this->kills, ir_variable *, var);
}
/**
--
2.11.0
More information about the mesa-dev
mailing list