util/hash_table: Rework the API to know about hashing
[mesa.git] / src / gallium / drivers / vc4 / vc4_opt_cse.c
index 33e17d73401cd141267b6ef7b5589782f1ffe336..2ca736fe4d5b7b30e9ec0ded260a192791aad4c9 100644 (file)
@@ -62,7 +62,8 @@ inst_key_equals(const void *a, const void *b)
 }
 
 static struct qinst *
-vc4_find_cse(struct hash_table *ht, struct qinst *inst, uint32_t sf_count,
+vc4_find_cse(struct vc4_compile *c, struct hash_table *ht,
+             struct qinst *inst, uint32_t sf_count,
              uint32_t r4_count)
 {
         if (inst->dst.file != QFILE_TEMP ||
@@ -83,18 +84,18 @@ vc4_find_cse(struct hash_table *ht, struct qinst *inst, uint32_t sf_count,
 
         uint32_t hash = _mesa_hash_data(&key, sizeof(key));
         struct hash_entry *entry =
-                _mesa_hash_table_search(ht, hash, &key);
+                _mesa_hash_table_search_pre_hashed(ht, hash, &key);
 
         if (entry) {
                 if (debug) {
                         fprintf(stderr, "CSE found match:\n");
 
                         fprintf(stderr, "  Original inst: ");
-                        qir_dump_inst(entry->data);
+                        qir_dump_inst(c, entry->data);
                         fprintf(stderr, "\n");
 
                         fprintf(stderr, "  Our inst:      ");
-                        qir_dump_inst(inst);
+                        qir_dump_inst(c, inst);
                         fprintf(stderr, "\n");
                 }
 
@@ -105,11 +106,11 @@ vc4_find_cse(struct hash_table *ht, struct qinst *inst, uint32_t sf_count,
         if (!alloc_key)
                 return NULL;
         memcpy(alloc_key, &key, sizeof(*alloc_key));
-        _mesa_hash_table_insert(ht, hash, alloc_key, inst);
+        _mesa_hash_table_insert_with_hash(ht, hash, alloc_key, inst);
 
         if (debug) {
                 fprintf(stderr, "Added to CSE HT: ");
-                qir_dump_inst(inst);
+                qir_dump_inst(c, inst);
                 fprintf(stderr, "\n");
         }
 
@@ -124,15 +125,15 @@ qir_opt_cse(struct vc4_compile *c)
         struct qinst *last_sf = NULL;
         uint32_t sf_count = 0, r4_count = 0;
 
-        return false;
-        struct hash_table *ht = _mesa_hash_table_create(NULL, inst_key_equals);
+        struct hash_table *ht = _mesa_hash_table_create(NULL, NULL,
+                                                        inst_key_equals);
         if (!ht)
                 return false;
 
         foreach_s(node, t, &c->instructions) {
                 struct qinst *inst = (struct qinst *)node;
 
-                if (qir_has_side_effects(inst)) {
+                if (qir_has_side_effects(c, inst)) {
                         if (inst->op == QOP_TLB_DISCARD_SETUP)
                                 last_sf = NULL;
                         continue;
@@ -144,7 +145,7 @@ qir_opt_cse(struct vc4_compile *c)
                                 if (debug) {
                                         fprintf(stderr,
                                                 "Removing redundant SF: ");
-                                        qir_dump_inst(inst);
+                                        qir_dump_inst(c, inst);
                                         fprintf(stderr, "\n");
                                 }
                                 qir_remove_instruction(inst);
@@ -155,7 +156,7 @@ qir_opt_cse(struct vc4_compile *c)
                                 sf_count++;
                         }
                 } else {
-                        struct qinst *cse = vc4_find_cse(ht, inst,
+                        struct qinst *cse = vc4_find_cse(c, ht, inst,
                                                          sf_count, r4_count);
                         if (cse) {
                                 inst->src[0] = cse->dst;
@@ -167,7 +168,7 @@ qir_opt_cse(struct vc4_compile *c)
 
                                 if (debug) {
                                         fprintf(stderr, "  Turned into:   ");
-                                        qir_dump_inst(inst);
+                                        qir_dump_inst(c, inst);
                                         fprintf(stderr, "\n");
                                 }
                         }