From eb7e20b378baf7798b31e6842b3dc9055f7b0b07 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 27 Nov 2020 18:56:11 -0500 Subject: [PATCH] pan/bi: Add builder data structure In preparation for builder routines. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/compiler.h | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index f90c738b582..c356004281a 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -1149,4 +1149,38 @@ bi_after_instr(bi_instr *instr) }; } +/* IR builder in terms of cursor infrastructure */ + +typedef struct { + bi_context *shader; + bi_cursor cursor; +} bi_builder; + +/* Insert an instruction at the cursor and move the cursor */ + +static inline void +bi_builder_insert(bi_cursor *cursor, bi_instr *I) +{ + switch (cursor->option) { + case bi_cursor_after_instr: + list_add(&I->link, &cursor->instr->link); + cursor->instr = I; + return; + + case bi_cursor_after_block: + list_addtail(&I->link, &cursor->block->base.instructions); + cursor->option = bi_cursor_after_instr; + cursor->instr = I; + return; + + case bi_cursor_before_instr: + list_addtail(&I->link, &cursor->instr->link); + cursor->option = bi_cursor_after_instr; + cursor->instr = I; + return; + } + + unreachable("Invalid cursor option"); +} + #endif