freedreno/ir3: add a pass to collect SSA uses
authorRob Clark <robdclark@chromium.org>
Thu, 12 Mar 2020 21:18:04 +0000 (14:18 -0700)
committerMarge Bot <eric+marge@anholt.net>
Sat, 4 Apr 2020 00:07:10 +0000 (00:07 +0000)
We don't really track these as the ir is transformed, but it would be a
useful thing for some passes to have.  So add a pass to collect this
information.  It uses instr->data (generic per-pass ptr), with the
hashsets hanging under a mem_ctx for easy disposal at the end of the
pass.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4423>

src/freedreno/ir3/ir3.c
src/freedreno/ir3/ir3.h

index bf84270..4ac50ae 100644 (file)
@@ -1128,3 +1128,27 @@ ir3_lookup_array(struct ir3 *ir, unsigned id)
                        return arr;
        return NULL;
 }
+
+void
+ir3_find_ssa_uses(struct ir3 *ir, void *mem_ctx)
+{
+       /* We could do this in a single pass if we can assume instructions
+        * are always sorted.  Which currently might not always be true.
+        * (In particular after ir3_group pass, but maybe other places.)
+        */
+       foreach_block (block, &ir->block_list)
+               foreach_instr (instr, &block->instr_list)
+                       instr->uses = NULL;
+
+       foreach_block (block, &ir->block_list) {
+               foreach_instr (instr, &block->instr_list) {
+                       struct ir3_instruction *src;
+
+                       foreach_ssa_src (src, instr) {
+                               if (!src->uses)
+                                       src->uses = _mesa_pointer_set_create(mem_ctx);
+                               _mesa_set_add(src->uses, instr);
+                       }
+               }
+       }
+}
index c8abd50..ed51189 100644 (file)
@@ -325,6 +325,11 @@ struct ir3_instruction {
         */
        void *data;
 
+       /**
+        * Valid if pass calls ir3_find_ssa_uses().. see foreach_ssa_use()
+        */
+       struct set *uses;
+
        int sun;            /* Sethi–Ullman number, used by sched */
        int use_count;      /* currently just updated/used by cp */
 
@@ -593,6 +598,14 @@ void ir3_clear_mark(struct ir3 *shader);
 
 unsigned ir3_count_instructions(struct ir3 *ir);
 
+void ir3_find_ssa_uses(struct ir3 *ir, void *mem_ctx);
+
+#include "util/set.h"
+#define foreach_ssa_use(__use, __instr) \
+       for (struct ir3_instruction *__use = (void *)~0; \
+            __use && (__instr)->uses; __use = NULL) \
+               set_foreach ((__instr)->uses, __entry) \
+                       if ((__use = (void *)__entry->key))
 
 #define MAX_ARRAYS 16