pan/midgard: Add flatten_mir helper
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Sat, 31 Aug 2019 18:08:39 +0000 (11:08 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 30 Sep 2019 12:40:13 +0000 (08:40 -0400)
We would like to flatten a linked list of midgard_instructions into an
array of midgard_instruction pointers on the heap.

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

index 2ed25da2e0db44654ebd6a29cd76f4ae21904e6d..75295b5d1231aed9e447744474cf247da64d18f6 100644 (file)
@@ -620,6 +620,28 @@ schedule_bundle(compiler_context *ctx, midgard_block *block, midgard_instruction
         return bundle;
 }
 
+/* We would like to flatten the linked list of midgard_instructions in a bundle
+ * to an array of pointers on the heap for easy indexing */
+
+static midgard_instruction **
+flatten_mir(midgard_block *block, unsigned *len)
+{
+        *len = list_length(&block->instructions);
+
+        if (!(*len))
+                return NULL;
+
+        midgard_instruction **instructions =
+                calloc(sizeof(midgard_instruction *), *len);
+
+        unsigned i = 0;
+
+        mir_foreach_instr_in_block(block, ins)
+                instructions[i++] = ins;
+
+        return instructions;
+}
+
 /* Schedule a single block by iterating its instruction to create bundles.
  * While we go, tally about the bundle sizes to compute the block size. */