From b329f8c750af96f9efb968045dcf03b0fad1b34e Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 6 Mar 2020 19:25:00 -0500 Subject: [PATCH] pan/bi: Add dummy scheduler Do the absolute simplest possible thing -- create a clause for every instruction, and just pick whichever slot we can, nopping the other, copying whatever constant we have whether it's used or not. To be clear - this is not to be used in a production compiler. But this lets actual bundles and clauses show up in the BIR, which unblocks work on final code generation and packing (which can happen more or less in parallel to NIR->BIR, optimization, register allocation, and writing an actual scheduling). Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/Makefile.sources | 1 + src/panfrost/bifrost/bi_schedule.c | 76 ++++++++++++++++++++++++++ src/panfrost/bifrost/bifrost_compile.c | 2 + src/panfrost/bifrost/compiler.h | 11 ++-- src/panfrost/bifrost/meson.build | 1 + 5 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 src/panfrost/bifrost/bi_schedule.c diff --git a/src/panfrost/Makefile.sources b/src/panfrost/Makefile.sources index 06ec8a8eb56..54de930ec66 100644 --- a/src/panfrost/Makefile.sources +++ b/src/panfrost/Makefile.sources @@ -3,6 +3,7 @@ bifrost_FILES := \ bifrost/bifrost_compile.c \ bifrost/bifrost_compile.h \ bifrost/bifrost_tables.c \ + bifrost/bi_schedule.c \ bifrost/bi_print.c \ bifrost/bi_print.h \ bifrost/bi_quirks.c \ diff --git a/src/panfrost/bifrost/bi_schedule.c b/src/panfrost/bifrost/bi_schedule.c new file mode 100644 index 00000000000..dc45487f7c8 --- /dev/null +++ b/src/panfrost/bifrost/bi_schedule.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2020 Collabora Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Authors (Collabora): + * Alyssa Rosenzweig + */ + +#include "compiler.h" + +/* Eventually, we'll need a proper scheduling, grouping instructions + * into clauses and ordering/assigning grouped instructions to the + * appropriate FMA/ADD slots. Right now we do the dumbest possible + * thing just to have the scheduler stubbed out so we can focus on + * codegen */ + +void +bi_schedule(bi_context *ctx) +{ + unsigned ids = 0; + unsigned last_id = 0; + bool is_first = true; + + bi_foreach_block(ctx, block) { + list_inithead(&block->clauses); + + bi_foreach_instr_in_block(block, ins) { + unsigned props = bi_class_props[ins->type]; + + bi_clause *u = rzalloc(ctx, bi_clause); + u->bundle_count = 1; + + if (props & BI_SCHED_FMA) + u->bundles[0].fma = ins; + else + u->bundles[0].add = ins; + + u->scoreboard_id = ids++; + + if (is_first) + is_first = false; + else + u->dependencies |= (1 << last_id); + + ids = ids & 1; + last_id = u->scoreboard_id; + u->back_to_back = true; + u->data_register_write_barrier = true; + + u->constant_count = 1; + u->constants[0] = ins->constant.u64; + + list_addtail(&u->link, &block->clauses); + } + + block->scheduled = true; + } +} diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index a0b9d03b1ee..1c3a0f09db3 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -606,6 +606,8 @@ bifrost_compile_shader_nir(nir_shader *nir, bifrost_program *program, unsigned p break; /* TODO: Multi-function shaders */ } + bi_print_shader(ctx, stdout); + bi_schedule(ctx); bi_print_shader(ctx, stdout); ralloc_free(ctx); diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index de417fb8e3e..3b2794095b4 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -308,11 +308,8 @@ typedef struct bi_block { /* If true, uses clauses; if false, uses instructions */ bool scheduled; - - union { - struct list_head instructions; /* pre-schedule, list of bi_instructions */ - struct list_head clauses; /* list of bi_clause */ - }; + struct list_head instructions; /* pre-schedule, list of bi_instructions */ + struct list_head clauses; /* list of bi_clause */ /* Control flow graph */ struct set *predecessors; @@ -486,4 +483,8 @@ bool bi_has_outmod(bi_instruction *ins); bool bi_has_source_mods(bi_instruction *ins); bool bi_is_src_swizzled(bi_instruction *ins, unsigned s); +/* BIR passes */ + +void bi_schedule(bi_context *ctx); + #endif diff --git a/src/panfrost/bifrost/meson.build b/src/panfrost/bifrost/meson.build index 5b885914c78..5eafb1bb178 100644 --- a/src/panfrost/bifrost/meson.build +++ b/src/panfrost/bifrost/meson.build @@ -22,6 +22,7 @@ libpanfrost_bifrost_files = files( 'disassemble.c', 'bi_print.c', + 'bi_schedule.c', 'bi_tables.c', 'bir.c', 'bifrost_compile.c', -- 2.30.2