aboutsummaryrefslogtreecommitdiffstats
path: root/src/panfrost
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <[email protected]>2020-03-05 10:25:19 -0500
committerMarge Bot <[email protected]>2020-03-07 00:37:39 +0000
commit83c4562503cc96ee04d873ee5c814e43b9e61b56 (patch)
treeaa9965e360eb0a0521cb050c0e880e5bfdcd0957 /src/panfrost
parent0d29184f6985b5e88c3a32526850acd7c8f3ab46 (diff)
pan/bi: Walk through the NIR control flow graph
Copypaste from Midgard with some cleanups. That seems to be a trend these days. Hopefully boilerplate will come to a close soon. Signed-off-by: Alyssa Rosenzweig <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4097>
Diffstat (limited to 'src/panfrost')
-rw-r--r--src/panfrost/bifrost/bifrost_compile.c75
-rw-r--r--src/panfrost/bifrost/compiler.h7
2 files changed, 82 insertions, 0 deletions
diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c
index 87a447a9ab3..d6666f1c831 100644
--- a/src/panfrost/bifrost/bifrost_compile.c
+++ b/src/panfrost/bifrost/bifrost_compile.c
@@ -34,6 +34,72 @@
#include "bifrost_compile.h"
#include "compiler.h"
#include "bi_quirks.h"
+#include "bi_print.h"
+
+static bi_block *emit_cf_list(bi_context *ctx, struct exec_list *list);
+
+static bi_block *
+create_empty_block(bi_context *ctx)
+{
+ bi_block *blk = rzalloc(ctx, bi_block);
+
+ blk->predecessors = _mesa_set_create(blk,
+ _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
+
+ blk->name = ctx->block_name_count++;
+
+ return blk;
+}
+
+static bi_block *
+emit_block(bi_context *ctx, nir_block *block)
+{
+ ctx->current_block = create_empty_block(ctx);
+ list_addtail(&ctx->current_block->link, &ctx->blocks);
+ list_inithead(&ctx->current_block->instructions);
+
+ nir_foreach_instr(instr, block) {
+ //emit_instr(ctx, instr);
+ ++ctx->instruction_count;
+ }
+
+ return ctx->current_block;
+}
+
+static bi_block *
+emit_cf_list(bi_context *ctx, struct exec_list *list)
+{
+ bi_block *start_block = NULL;
+
+ foreach_list_typed(nir_cf_node, node, node, list) {
+ switch (node->type) {
+ case nir_cf_node_block: {
+ bi_block *block = emit_block(ctx, nir_cf_node_as_block(node));
+
+ if (!start_block)
+ start_block = block;
+
+ break;
+ }
+
+#if 0
+ case nir_cf_node_if:
+ emit_if(ctx, nir_cf_node_as_if(node));
+ break;
+
+ case nir_cf_node_loop:
+ emit_loop(ctx, nir_cf_node_as_loop(node));
+ break;
+#endif
+
+ default:
+ unreachable("Unknown control flow");
+ }
+ }
+
+ return start_block;
+}
static int
glsl_type_size(const struct glsl_type *type, bool bindless)
@@ -115,6 +181,7 @@ bifrost_compile_shader_nir(nir_shader *nir, bifrost_program *program, unsigned p
ctx->nir = nir;
ctx->stage = nir->info.stage;
ctx->quirks = bifrost_get_quirks(product_id);
+ list_inithead(&ctx->blocks);
/* Lower gl_Position pre-optimisation, but after lowering vars to ssa
* (so we don't accidentally duplicate the epilogue since mesa/st has
@@ -141,6 +208,14 @@ bifrost_compile_shader_nir(nir_shader *nir, bifrost_program *program, unsigned p
bi_optimize_nir(nir);
nir_print_shader(nir, stdout);
+ nir_foreach_function(func, nir) {
+ if (!func->impl)
+ continue;
+
+ emit_cf_list(ctx, &func->impl->body);
+ break; /* TODO: Multi-function shaders */
+ }
+
bi_print_shader(ctx, stdout);
ralloc_free(ctx);
diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h
index 97147d0a723..2b390c19add 100644
--- a/src/panfrost/bifrost/compiler.h
+++ b/src/panfrost/bifrost/compiler.h
@@ -320,6 +320,13 @@ typedef struct {
gl_shader_stage stage;
struct list_head blocks; /* list of bi_block */
uint32_t quirks;
+
+ /* During NIR->BIR */
+ bi_block *current_block;
+ unsigned block_name_count;
+
+ /* Stats for shader-db */
+ unsigned instruction_count;
} bi_context;
/* So we can distinguish between SSA/reg/sentinel quickly */