Skip to content
Snippets Groups Projects
Commit 766d11e8 authored by Kenneth Graunke's avatar Kenneth Graunke Committed by Emil Velikov
Browse files

glsl: Use hash tables for opt_constant_propagation() kill sets.

Cuts compile/link time of the fragment shader in #91857 by 19%
(16.28 -> 13.05).

I didn't bother with the acp sets because they're smaller, but it
might be worth doing as well.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91857


Signed-off-by: Kenneth Graunke's avatarKenneth Graunke <kenneth@whitecape.org>
Reviewed-by: default avatarThomas Helland <thomashelland90@gmail.com>
Reviewed-by: default avatarTimothy Arceri <t_arceri@yahoo.com.au>
Tested-by: default avatarTapani Pälli <tapani.palli@intel.com>
(cherry picked from commit 4654439f)
Nominated-by: default avatarEmil Velikov <emil.l.velikov@gmail.com>
parent 5923bd6d
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@
#include "ir_basic_block.h"
#include "ir_optimization.h"
#include "glsl_types.h"
#include "util/hash_table.h"
namespace {
......@@ -95,7 +96,8 @@ public:
killed_all = false;
mem_ctx = ralloc_context(0);
this->acp = new(mem_ctx) exec_list;
this->kills = new(mem_ctx) exec_list;
this->kills = _mesa_hash_table_create(mem_ctx, _mesa_hash_pointer,
_mesa_key_pointer_equal);
}
~ir_constant_propagation_visitor()
{
......@@ -123,7 +125,7 @@ public:
* List of kill_entry: The masks of variables whose values were
* killed in this block.
*/
exec_list *kills;
hash_table *kills;
bool progress;
......@@ -263,11 +265,12 @@ ir_constant_propagation_visitor::visit_enter(ir_function_signature *ir)
* main() at link time, so they're irrelevant to us.
*/
exec_list *orig_acp = this->acp;
exec_list *orig_kills = this->kills;
hash_table *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->kills = _mesa_hash_table_create(mem_ctx, _mesa_hash_pointer,
_mesa_key_pointer_equal);
this->killed_all = false;
visit_list_elements(this, &ir->body);
......@@ -352,11 +355,12 @@ void
ir_constant_propagation_visitor::handle_if_block(exec_list *instructions)
{
exec_list *orig_acp = this->acp;
exec_list *orig_kills = this->kills;
hash_table *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->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 */
......@@ -370,12 +374,14 @@ ir_constant_propagation_visitor::handle_if_block(exec_list *instructions)
orig_acp->make_empty();
}
exec_list *new_kills = this->kills;
hash_table *new_kills = this->kills;
this->kills = orig_kills;
this->acp = orig_acp;
this->killed_all = this->killed_all || orig_killed_all;
foreach_in_list(kill_entry, k, new_kills) {
hash_entry *htk;
hash_table_foreach(new_kills, htk) {
kill_entry *k = (kill_entry *) htk->data;
kill(k->var, k->write_mask);
}
}
......@@ -397,7 +403,7 @@ ir_visitor_status
ir_constant_propagation_visitor::visit_enter(ir_loop *ir)
{
exec_list *orig_acp = this->acp;
exec_list *orig_kills = this->kills;
hash_table *orig_kills = this->kills;
bool orig_killed_all = this->killed_all;
/* FINISHME: For now, the initial acp for loops is totally empty.
......@@ -405,7 +411,8 @@ ir_constant_propagation_visitor::visit_enter(ir_loop *ir)
* 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->kills = _mesa_hash_table_create(mem_ctx, _mesa_hash_pointer,
_mesa_key_pointer_equal);
this->killed_all = false;
visit_list_elements(this, &ir->body_instructions);
......@@ -414,12 +421,14 @@ ir_constant_propagation_visitor::visit_enter(ir_loop *ir)
orig_acp->make_empty();
}
exec_list *new_kills = this->kills;
hash_table *new_kills = this->kills;
this->kills = orig_kills;
this->acp = orig_acp;
this->killed_all = this->killed_all || orig_killed_all;
foreach_in_list(kill_entry, k, new_kills) {
hash_entry *htk;
hash_table_foreach(new_kills, htk) {
kill_entry *k = (kill_entry *) htk->data;
kill(k->var, k->write_mask);
}
......@@ -448,14 +457,15 @@ ir_constant_propagation_visitor::kill(ir_variable *var, unsigned write_mask)
/* Add this writemask of the variable to the list of killed
* variables in this block.
*/
foreach_in_list(kill_entry, entry, this->kills) {
if (entry->var == var) {
entry->write_mask |= write_mask;
return;
}
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 list. Make new entry. */
this->kills->push_tail(new(this->mem_ctx) kill_entry(var, write_mask));
_mesa_hash_table_insert(this->kills, var,
new(this->mem_ctx) kill_entry(var, write_mask));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment