Separate higher level logic of visiting instructions and chosing when
to store and use new copy data from the datastructure holding the copy
propagation information. This will also make easier later patches that
change the structure.
v2: Remove empty destructor and clarify how hash tables are destroyed.
---
.../glsl/opt_copy_propagation_elements.cpp| 267 +-
1 file changed, 141 insertions(+), 126 deletions(-)
diff --git a/src/compiler/glsl/opt_copy_propagation_elements.cpp
b/src/compiler/glsl/opt_copy_propagation_elements.cpp
index 8975e727522..05965128fd9 100644
--- a/src/compiler/glsl/opt_copy_propagation_elements.cpp
+++ b/src/compiler/glsl/opt_copy_propagation_elements.cpp
@@ -89,6 +89,119 @@ public:
acp_ref rhs_node;
};
+class copy_propagation_state {
+public:
+ DECLARE_RZALLOC_CXX_OPERATORS(copy_propagation_state);
+
+ copy_propagation_state(void *mem_ctx, void *lin_ctx)
+ {
+ /* Use 'this' as context for the tables, no explicit destruction
+ * needed later. */
+ lhs_ht = _mesa_hash_table_create(this, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
+ rhs_ht = _mesa_hash_table_create(this, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
+ this->mem_ctx = mem_ctx;
+ this->lin_ctx = lin_ctx;
+ }
+
+ copy_propagation_state* clone()
+ {
+ return new (ralloc_parent(this)) copy_propagation_state(this);
+ }
+
+ void erase_all()
+ {
+ _mesa_hash_table_clear(lhs_ht, NULL);
+ _mesa_hash_table_clear(rhs_ht, NULL);
+ }
+
+ void erase(ir_variable *var, unsigned write_mask)
+ {
+ /* removal of lhs entries */
+ hash_entry *ht_entry = _mesa_hash_table_search(lhs_ht, var);
+ if (ht_entry) {
+ exec_list *lhs_list = (exec_list *) ht_entry->data;
+ foreach_in_list_safe(acp_entry, entry, lhs_list) {
+entry->write_mask = entry->write_mask & ~write_mask;
+if (entry->write_mask == 0) {
+ entry->remove();
+ continue;
+}
+ }
+ }
+
+ /* removal of rhs entries */
+ ht_entry = _mesa_hash_table_search(rhs_ht, var);
+ if (ht_entry) {
+ exec_list *rhs_list = (exec_list *) ht_entry->data;
+ acp_ref *ref;
+
+ while ((ref = (acp_ref *) rhs_list->pop_head()) != NULL) {
+acp_entry *entry = ref->entry;
+
+/* If entry is still in a list (not already removed by lhs entry
+ * removal above), remove it.
+ */
+if (entry->prev || entry->next)
+ entry->remove();
+ }
+ }
+ }
+
+ exec_list *read(ir_variable *var)
+ {
+ hash_entry *ht_entry = _mesa_hash_table_search(lhs_ht, var);
+ if (ht_entry)
+ return (exec_list *) ht_entry->data;
+ return NULL;
+ }
+
+ void write(ir_variable *lhs, ir_variable *rhs, unsigned write_mask, int
swizzle[4])
+ {
+ acp_entry *entry = new(this->lin_ctx) acp_entry(lhs, rhs, write_mask,
swizzle);
+
+ /* lhs hash, hash of lhs -> acp_entry lists */
+ hash_entry *ht_entry = _mesa_hash_table_search(lhs_ht, lhs);
+ if (ht_entry) {
+ exec_list *lhs_list = (exec_list *) ht_entry->data;
+ lhs_list->push_tail(entry);
+ } else {
+ exec_list *lhs_list = new(mem_ctx) exec_list;
+ lhs_list->push_tail(entry);
+ _mesa_hash_table_insert(lhs_ht, lhs, lhs_list);
+ }
+
+ /* rhs hash, hash of rhs -> acp_entry pointers to lhs lists */
+ ht_entry = _mesa_hash_table_search(rhs_ht, rhs);
+ if (ht_entry) {
+ exec_list *rhs_list = (exec_list *) ht_entry->data;
+ rhs_list->push_tail(>rhs_node);
+ } else {
+ exec_list *rhs_list = new(mem_ctx) exec_list;
+ rhs_list->push_tail(>rhs_node);
+ _mesa_hash_table_insert(rhs_ht, rhs, rhs_list);
+ }
+ }
+
+private:
+ explicit copy_propagation_state(copy_propagation_state *original)
+ {
+ lhs_ht = _mesa_hash_table_clone(original->lhs_ht, this);
+ rhs_ht = _mesa_hash_table_clone(original->rhs_ht, this);
+ lin_ctx = original->lin_ctx;
+ mem_ctx = original->mem_ctx;
+ }
+
+ /** Hash of acp_entry: The available copies to propagate */
+ hash_table *lhs_ht;
+
+ /** Reverse index of the lhs_ht, to optimize finding uses of a certain
variable. */
+ hash_table *rhs_ht;
+
+ void *mem_ctx;
+ void *lin_ctx;
+};
class kill_entry : public exec_node
{
@@ -116,34 +229,13 @@ public:
this->lin_ctx = linear_alloc_parent(this->mem_ctx, 0);
this->shader_mem_ctx = NULL;
this->kills = new(mem_ctx) exec_list;
-
- create_acp();
+ this->state = new(mem_ctx) copy_propagation_state(mem_ctx, lin_ctx);
}
~ir_copy_propagation_elements_visitor()
{
ralloc_free(mem_ctx);
}
- void clone_acp(hash_table *lhs, hash_table *rhs)
- {
- lhs_ht =