panfrost: Use ralloc() to allocate instructions to avoid leaking those objs
authorBoris Brezillon <boris.brezillon@collabora.com>
Wed, 28 Aug 2019 07:17:21 +0000 (09:17 +0200)
committerBoris Brezillon <boris.brezillon@collabora.com>
Wed, 28 Aug 2019 15:50:01 +0000 (17:50 +0200)
Instructions attached to blocks are never explicitly freed. Let's
use ralloc() to attach those objects to the compiler context so that
they are automatically freed when the ctx object is freed.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/panfrost/midgard/compiler.h
src/panfrost/midgard/midgard_compile.c
src/panfrost/midgard/midgard_derivatives.c
src/panfrost/midgard/midgard_opt_invert.c
src/panfrost/midgard/midgard_opt_perspective.c
src/panfrost/midgard/midgard_ra.c
src/panfrost/midgard/midgard_schedule.c
src/panfrost/midgard/mir_promote_uniforms.c

index f9ba31b5959d079d40e28a8b10910920efba7ac2..68716f92b0b9080a8d5d1228b247cd8d42529006 100644 (file)
@@ -288,9 +288,9 @@ typedef struct compiler_context {
 /* Append instruction to end of current block */
 
 static inline midgard_instruction *
-mir_upload_ins(struct midgard_instruction ins)
+mir_upload_ins(struct compiler_context *ctx, struct midgard_instruction ins)
 {
-        midgard_instruction *heap = malloc(sizeof(ins));
+        midgard_instruction *heap = ralloc(ctx, struct midgard_instruction);
         memcpy(heap, &ins, sizeof(ins));
         return heap;
 }
@@ -298,15 +298,17 @@ mir_upload_ins(struct midgard_instruction ins)
 static inline midgard_instruction *
 emit_mir_instruction(struct compiler_context *ctx, struct midgard_instruction ins)
 {
-        midgard_instruction *u = mir_upload_ins(ins);
+        midgard_instruction *u = mir_upload_ins(ctx, ins);
         list_addtail(&u->link, &ctx->current_block->instructions);
         return u;
 }
 
 static inline struct midgard_instruction *
-mir_insert_instruction_before(struct midgard_instruction *tag, struct midgard_instruction ins)
+mir_insert_instruction_before(struct compiler_context *ctx,
+                              struct midgard_instruction *tag,
+                              struct midgard_instruction ins)
 {
-        struct midgard_instruction *u = mir_upload_ins(ins);
+        struct midgard_instruction *u = mir_upload_ins(ctx, ins);
         list_addtail(&u->link, &tag->link);
         return u;
 }
@@ -315,7 +317,6 @@ static inline void
 mir_remove_instruction(struct midgard_instruction *ins)
 {
         list_del(&ins->link);
-        free(ins);
 }
 
 static inline midgard_instruction*
index 74511b278d16527328a212b4479619c58b339422..74796b661df6fa4edf292ad8809909722081b379 100644 (file)
@@ -1962,7 +1962,7 @@ inline_alu_constants(compiler_context *ctx)
                                 alu->src[1] = scratch;
 
                                 /* Inject us -before- the last instruction which set r31 */
-                                mir_insert_instruction_before(mir_prev_op(alu), ins);
+                                mir_insert_instruction_before(ctx, mir_prev_op(alu), ins);
                         }
                 }
         }
index ce45b46ecb9c528776a299d96c1f4e2610b747d0..bfeae5077fce12e9d6d57045d327372f53ddc03e 100644 (file)
@@ -148,7 +148,7 @@ midgard_lower_derivatives(compiler_context *ctx, midgard_block *block)
                 dup.texture.in_reg_swizzle = SWIZZLE_ZWWW;
 
                 /* Insert the new instruction */
-                mir_insert_instruction_before(mir_next_op(ins), dup);
+                mir_insert_instruction_before(ctx, mir_next_op(ins), dup);
 
                 /* TODO: Set .cont/.last automatically via dataflow analysis */
                 ctx->texture_op_count++;
index c3dc8142663effe7297e5f308cfbf0c4786d942a..729169f9a4a896176d3ea50b47cdb9fe1d42d257 100644 (file)
@@ -56,7 +56,7 @@ midgard_lower_invert(compiler_context *ctx, midgard_block *block)
 
                 ins->dest = temp;
                 ins->invert = false;
-                mir_insert_instruction_before(mir_next_op(ins), not);
+                mir_insert_instruction_before(ctx, mir_next_op(ins), not);
         }
 }
 
index feec5a5be390f710ca3e4d17d1ad70360bae2cf5..aa4c58c470c20aaed61777ac05769708767497f6 100644 (file)
@@ -125,7 +125,7 @@ midgard_opt_combine_projection(compiler_context *ctx, midgard_block *block)
                         }
                 };
 
-                mir_insert_instruction_before(ins, accel);
+                mir_insert_instruction_before(ctx, ins, accel);
                 mir_remove_instruction(ins);
 
                 progress |= true;
index 16cb31f04135979f6da4a794a7937b18e8c47d84..9125d0f03925e5c173d583d8b57d9390f0cd61c7 100644 (file)
@@ -499,13 +499,13 @@ mir_lower_special_reads(compiler_context *ctx)
                                 if (hazard_write) {
                                         midgard_instruction *use = mir_next_op(pre_use);
                                         assert(use);
-                                        mir_insert_instruction_before(use, m);
+                                        mir_insert_instruction_before(ctx, use, m);
                                         mir_rewrite_index_dst_single(pre_use, i, idx);
                                 } else {
                                         idx = spill_idx++;
                                         m = v_mov(i, blank_alu_src, idx);
                                         m.mask = mir_mask_of_read_components(pre_use, i);
-                                        mir_insert_instruction_before(pre_use, m);
+                                        mir_insert_instruction_before(ctx, pre_use, m);
                                         mir_rewrite_index_src_single(pre_use, i, idx);
                                 }
                         }
index 60ad5ebb79c803ee0ce68722a7f61435c25943b0..5c6878e9f6b0d9741fe2726416101bee65da164c 100644 (file)
@@ -641,7 +641,7 @@ midgard_pair_load_store(compiler_context *ctx, midgard_block *block)
 
                                 /* We found one! Move it up to pair and remove it from the old location */
 
-                                mir_insert_instruction_before(ins, *c);
+                                mir_insert_instruction_before(ctx, ins, *c);
                                 mir_remove_instruction(c);
 
                                 break;
@@ -805,7 +805,7 @@ static void mir_spill_register(
                         /* Hint: don't rewrite this node */
                         st.hint = true;
 
-                        mir_insert_instruction_before(mir_next_op(ins), st);
+                        mir_insert_instruction_before(ctx, mir_next_op(ins), st);
 
                         if (!is_special)
                                 ctx->spills++;
@@ -873,7 +873,7 @@ static void mir_spill_register(
 
                                 st.mask = read_mask;
 
-                                mir_insert_instruction_before(before, st);
+                                mir_insert_instruction_before(ctx, before, st);
                                // consecutive_skip = true;
                         } else {
                                 /* Special writes already have their move spilled in */
index 500230f78205971f911e7c27f0ebf6ab008da7c6..428710e5154ff402f2da913045e94b93f93c2b6d 100644 (file)
@@ -103,7 +103,7 @@ midgard_promote_uniforms(compiler_context *ctx, unsigned promoted_count)
                 if (needs_move) {
                         midgard_instruction mov = v_mov(promoted, blank_alu_src, ins->dest);
                         mov.mask = ins->mask;
-                        mir_insert_instruction_before(ins, mov);
+                        mir_insert_instruction_before(ctx, ins, mov);
                 } else {
                         mir_rewrite_index_src_swizzle(ctx, ins->dest,
                                         promoted, swizzle_of(nr_components));