[Mesa-dev] [PATCH 6/7] nir: Prehash in instr_set to avoid unnecessary hashing

Thomas Helland thomashelland90 at gmail.com
Thu Feb 2 20:57:32 UTC 2017


This should prove benefitial in the common case of inserting
and not rewriting anything.
---
 src/compiler/nir/nir_instr_set.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/compiler/nir/nir_instr_set.c b/src/compiler/nir/nir_instr_set.c
index 9cb9ed43e8..4c45d051f8 100644
--- a/src/compiler/nir/nir_instr_set.c
+++ b/src/compiler/nir/nir_instr_set.c
@@ -508,7 +508,11 @@ nir_instr_set_add_or_rewrite(struct set *instr_set, nir_instr *instr)
    if (!instr_can_rewrite(instr))
       return false;
 
-   struct set_entry *entry = _mesa_set_search(instr_set, instr);
+   uint32_t hash = instr_set->key_hash_function(instr);
+
+   struct set_entry *entry =
+      _mesa_set_search_pre_hashed(instr_set, hash, instr);
+
    if (entry) {
       nir_ssa_def *def = nir_instr_get_dest_ssa_def(instr);
       nir_instr *match = (nir_instr *) entry->key;
@@ -526,7 +530,7 @@ nir_instr_set_add_or_rewrite(struct set *instr_set, nir_instr *instr)
       return true;
    }
 
-   _mesa_set_add(instr_set, instr);
+   _mesa_set_add_pre_hashed(instr_set, hash, instr);
    return false;
 }
 
-- 
2.11.0



More information about the mesa-dev mailing list