From 1fb79b4aa26b937a78f02c0064cc6f6319f20b5b Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 12 Jan 2024 19:27:48 +0000 Subject: [PATCH] aco: refactor schedule_ilp main loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Besides switching to "ctx.active_mask" as the condition, this is basically the same. Signed-off-by: Rhys Perry Reviewed-by: Georg Lehmann Reviewed-by: Daniel Schürmann Part-of: --- src/amd/compiler/aco_scheduler_ilp.cpp | 54 +++++++++++++++----------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/amd/compiler/aco_scheduler_ilp.cpp b/src/amd/compiler/aco_scheduler_ilp.cpp index 007386cef7b..4bcd1d80e8c 100644 --- a/src/amd/compiler/aco_scheduler_ilp.cpp +++ b/src/amd/compiler/aco_scheduler_ilp.cpp @@ -377,6 +377,36 @@ select_instruction(const SchedILPContext& ctx) return idx; } +template +void +do_schedule(SchedILPContext& ctx, It& insert_it, It& remove_it, It instructions_begin, + It instructions_end) +{ + for (unsigned i = 0; i < num_nodes; i++) { + if (remove_it == instructions_end) + break; + + add_entry(ctx, (remove_it++)->get(), i); + } + + while (ctx.active_mask) { + unsigned next_idx = select_instruction(ctx); + Instruction* next_instr = ctx.nodes[next_idx].instr; + + (insert_it++)->reset(next_instr); + + remove_entry(ctx, next_instr, next_idx); + ctx.nodes[next_idx].instr = NULL; + + if (remove_it != instructions_end) { + add_entry(ctx, (remove_it++)->get(), next_idx); + } else if (ctx.last_non_reorderable != UINT8_MAX) { + ctx.nodes[ctx.last_non_reorderable].potential_clause = false; + ctx.last_non_reorderable = UINT8_MAX; + } + } +} + } // namespace void @@ -386,29 +416,9 @@ schedule_ilp(Program* program) for (Block& block : program->blocks) { auto it = block.instructions.begin(); - for (unsigned i = 0; i < num_nodes; i++) { - if (it == block.instructions.end()) - break; - - add_entry(ctx, (it++)->get(), i); - } - auto insert_it = block.instructions.begin(); - while (insert_it != block.instructions.end()) { - unsigned next_idx = select_instruction(ctx); - Instruction* next_instr = ctx.nodes[next_idx].instr; - remove_entry(ctx, next_instr, next_idx); - (insert_it++)->reset(next_instr); - ctx.nodes[next_idx].instr = NULL; - - if (it != block.instructions.end()) { - add_entry(ctx, (it++)->get(), next_idx); - } else if (ctx.last_non_reorderable != UINT8_MAX) { - ctx.nodes[ctx.last_non_reorderable].potential_clause = false; - ctx.last_non_reorderable = UINT8_MAX; - } - } - assert(it == block.instructions.end()); + do_schedule(ctx, insert_it, it, block.instructions.begin(), block.instructions.end()); + block.instructions.resize(insert_it - block.instructions.begin()); } }