pan/midgard: Begin tracking liveness metadata
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 4 Oct 2019 01:16:56 +0000 (21:16 -0400)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 4 Oct 2019 02:29:51 +0000 (22:29 -0400)
This will allow us to explicitly invalidate liveness analysis results so
we can cache liveness results.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/panfrost/midgard/compiler.h
src/panfrost/midgard/midgard_liveness.c
src/panfrost/midgard/midgard_ra.c
src/panfrost/midgard/midgard_schedule.c

index 5d5c26e3db95642d9bc0076d05a04510b22acb20..a4d78c2239b7336bf32501cc1a7f781f9b45d4b8 100644 (file)
@@ -288,8 +288,14 @@ typedef struct compiler_context {
         unsigned sysvals[MAX_SYSVAL_COUNT];
         unsigned sysval_count;
         struct hash_table_u64 *sysval_to_id;
+
+        /* Bitmask of valid metadata */
+        unsigned metadata;
 } compiler_context;
 
+/* Per-block live_in/live_out */
+#define MIDGARD_METADATA_LIVENESS (1 << 0)
+
 /* Helpers for manipulating the above structures (forming the driver IR) */
 
 /* Append instruction to end of current block */
@@ -606,6 +612,7 @@ struct ra_graph* allocate_registers(compiler_context *ctx, bool *spilled);
 void install_registers(compiler_context *ctx, struct ra_graph *g);
 void mir_liveness_ins_update(uint8_t *live, midgard_instruction *ins, unsigned max);
 void mir_compute_liveness(compiler_context *ctx);
+void mir_invalidate_liveness(compiler_context *ctx);
 bool mir_is_live_after(compiler_context *ctx, midgard_block *block, midgard_instruction *start, int src);
 
 void mir_create_pipeline_registers(compiler_context *ctx);
index ebc6390fe4059f4db8b11f87312fc7f737d09001..b432ca43b47c51ce22cac07b3f210e2088674dbf 100644 (file)
@@ -113,6 +113,10 @@ liveness_block_update(compiler_context *ctx, midgard_block *blk)
 void
 mir_compute_liveness(compiler_context *ctx)
 {
+        /* If we already have fresh liveness, nothing to do */
+        if (ctx->metadata & MIDGARD_METADATA_LIVENESS)
+                return;
+
         /* List of midgard_block */
         struct set *work_list = _mesa_set_create(ctx,
                         _mesa_hash_pointer,
@@ -148,6 +152,33 @@ mir_compute_liveness(compiler_context *ctx)
                                 _mesa_set_add(work_list, pred);
                 }
         } while((cur = _mesa_set_next_entry(work_list, NULL)) != NULL);
+
+        /* Liveness is now valid */
+        ctx->metadata |= MIDGARD_METADATA_LIVENESS;
+}
+
+/* Once liveness data is no longer valid, call this */
+
+void
+mir_invalidate_liveness(compiler_context *ctx)
+{
+        /* If we didn't already compute liveness, there's nothing to do */
+        if (!(ctx->metadata & MIDGARD_METADATA_LIVENESS))
+                return;
+
+        /* It's now invalid regardless */
+        ctx->metadata &= ~MIDGARD_METADATA_LIVENESS;
+
+        mir_foreach_block(ctx, block) {
+                if (block->live_in)
+                        free(block->live_in);
+
+                if (block->live_out)
+                        free(block->live_out);
+
+                block->live_in = NULL;
+                block->live_out = NULL;
+        }
 }
 
 /* Determine if a variable is live in the successors of a block */
index dacc0d9106e950be50c8251b4ce5fb70e05149a1..afee5b82745fdea1d98e1585e73f5258bba5b90f 100644 (file)
@@ -574,11 +574,6 @@ mir_compute_interference(
 
                 free(live);
         }
-
-        mir_foreach_block(ctx, blk) {
-                free(blk->live_in);
-                free(blk->live_out);
-        }
 }
 
 /* This routine performs the actual register allocation. It should be succeeded
index d5fd17bc6db3c2294d3b1e0f646348a96c7e2513..a4ffa54c532be91d9e599e3a3a55a533307410d1 100644 (file)
@@ -1393,6 +1393,7 @@ schedule_program(compiler_context *ctx)
                         mir_spill_register(ctx, g, &spill_count);
 
                 mir_squeeze_index(ctx);
+                mir_invalidate_liveness(ctx);
 
                 g = NULL;
                 g = allocate_registers(ctx, &spilled);