From f9b37723d0e0f688a5d0f05fae18905dddc9b4b5 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Thu, 29 Feb 2024 18:22:40 +0000 Subject: [PATCH] aco/ra: emit linear VGPR parallel copy separately MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rhys Perry Reviewed-by: Daniel Schürmann Part-of: --- src/amd/compiler/aco_register_allocation.cpp | 41 ++++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp index b8014e62b8c..12f8f005817 100644 --- a/src/amd/compiler/aco_register_allocation.cpp +++ b/src/amd/compiler/aco_register_allocation.cpp @@ -2879,9 +2879,10 @@ optimize_encoding(Program* program, ra_ctx& ctx, RegisterFile& register_file, } void -emit_parallel_copy(ra_ctx& ctx, std::vector>& parallelcopy, - aco_ptr& instr, std::vector>& instructions, - bool temp_in_scc, RegisterFile& register_file) +emit_parallel_copy_internal(ra_ctx& ctx, std::vector>& parallelcopy, + aco_ptr& instr, + std::vector>& instructions, bool temp_in_scc, + RegisterFile& register_file) { if (parallelcopy.empty()) return; @@ -2945,6 +2946,38 @@ emit_parallel_copy(ra_ctx& ctx, std::vector>& par parallelcopy.clear(); } +void +emit_parallel_copy(ra_ctx& ctx, std::vector>& parallelcopy, + aco_ptr& instr, std::vector>& instructions, + bool temp_in_scc, RegisterFile& register_file) +{ + if (parallelcopy.empty()) + return; + + std::vector> linear_vgpr; + if (ctx.num_linear_vgprs) { + unsigned next = 0; + for (unsigned i = 0; i < parallelcopy.size(); i++) { + if (parallelcopy[i].first.regClass().is_linear_vgpr()) { + linear_vgpr.push_back(parallelcopy[i]); + continue; + } + + if (next != i) + parallelcopy[next] = parallelcopy[i]; + next++; + } + parallelcopy.resize(next); + } + + /* Because of how linear VGPRs are allocated, we should never have to move a linear VGPR into the + * space of a normal one. This means the copy can be done entirely before normal VGPR copies. */ + emit_parallel_copy_internal(ctx, linear_vgpr, instr, instructions, temp_in_scc, + register_file); + emit_parallel_copy_internal(ctx, parallelcopy, instr, instructions, temp_in_scc, + register_file); +} + } /* end namespace */ void @@ -3325,7 +3358,7 @@ register_allocation(Program* program, live& live_vars, ra_test_policy policy) std::vector> parallelcopy; compact_linear_vgprs(ctx, register_file, parallelcopy); update_renames(ctx, register_file, parallelcopy, br, rename_not_killed_ops); - emit_parallel_copy(ctx, parallelcopy, br, instructions, temp_in_scc, register_file); + emit_parallel_copy_internal(ctx, parallelcopy, br, instructions, temp_in_scc, register_file); instructions.push_back(std::move(br)); }