From b542ab02439d39dd54bc475332977d2c0a2e0920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Wed, 17 Aug 2022 08:12:51 +0200 Subject: [PATCH] aco/optimizer_postRA: Use unique_ptr + array for instruction indices. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to perf, this roughly halves the impact of the post-RA optimizer in ACO's compile times. Measurement was taken using a debug optimized build using NIR_DEBUG=novalidate RADV_DEBUG=nocache and replaying the Fossil DB from the Doom Eternal shaders. Signed-off-by: Timur Kristóf Reviewed-by: Daniel Schürmann Part-of: --- src/amd/compiler/aco_optimizer_postRA.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/amd/compiler/aco_optimizer_postRA.cpp b/src/amd/compiler/aco_optimizer_postRA.cpp index 96edae93071..24d2942595b 100644 --- a/src/amd/compiler/aco_optimizer_postRA.cpp +++ b/src/amd/compiler/aco_optimizer_postRA.cpp @@ -63,11 +63,18 @@ Idx const_or_undef{UINT32_MAX, 2}; Idx overwritten_untrackable{UINT32_MAX, 3}; struct pr_opt_ctx { + using Idx_array = std::array; + Program* program; Block* current_block; uint32_t current_instr_idx; std::vector uses; - std::vector> instr_idx_by_regs; + std::unique_ptr instr_idx_by_regs; + + pr_opt_ctx(Program* p) + : program(p), current_block(nullptr), current_instr_idx(0), uses(dead_code_analysis(p)), + instr_idx_by_regs(std::unique_ptr{new Idx_array[p->blocks.size()]}) + {} void reset_block(Block* block) { @@ -557,10 +564,7 @@ process_instruction(pr_opt_ctx& ctx, aco_ptr& instr) void optimize_postRA(Program* program) { - pr_opt_ctx ctx; - ctx.program = program; - ctx.uses = dead_code_analysis(program); - ctx.instr_idx_by_regs.resize(program->blocks.size()); + pr_opt_ctx ctx(program); /* Forward pass * Goes through each instruction exactly once, and can transform