From cc8a85d05a9cf47e89c6a8c5e6db98caba79e00d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timur=20Krist=C3=B3f?= Date: Mon, 6 Apr 2020 16:34:45 +0200 Subject: [PATCH] aco: Fix crash in insert_wait_states. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Timur Kristóf Reviewed-by: Daniel Schürmann Tested-by: Marge Bot Part-of: --- src/amd/compiler/aco_insert_waitcnt.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/amd/compiler/aco_insert_waitcnt.cpp b/src/amd/compiler/aco_insert_waitcnt.cpp index fc874ae793c..e4087e7add5 100644 --- a/src/amd/compiler/aco_insert_waitcnt.cpp +++ b/src/amd/compiler/aco_insert_waitcnt.cpp @@ -869,14 +869,14 @@ void handle_block(Program *program, Block& block, wait_ctx& ctx) } /* end namespace */ -static uint32_t calculate_score(unsigned num_ctx, wait_ctx *ctx, uint32_t event_mask) +static uint32_t calculate_score(std::vector &ctx_vec, uint32_t event_mask) { double result = 0.0; unsigned num_waits = 0; while (event_mask) { unsigned event_index = u_bit_scan(&event_mask); - for (unsigned i = 0; i < num_ctx; i++) { - for (unsigned dist : ctx[i].wait_distances[event_index]) { + for (const wait_ctx &ctx : ctx_vec) { + for (unsigned dist : ctx.wait_distances[event_index]) { double score = dist; /* for many events, excessive distances provide little benefit, so * decrease the score in that case. */ @@ -918,11 +918,9 @@ void insert_wait_states(Program* program) { /* per BB ctx */ std::vector done(program->blocks.size()); - wait_ctx in_ctx[program->blocks.size()]; - wait_ctx out_ctx[program->blocks.size()]; + std::vector in_ctx(program->blocks.size(), wait_ctx(program)); + std::vector out_ctx(program->blocks.size(), wait_ctx(program)); - for (unsigned i = 0; i < program->blocks.size(); i++) - in_ctx[i] = wait_ctx(program); std::stack loop_header_indices; unsigned loop_progress = 0; @@ -972,9 +970,9 @@ void insert_wait_states(Program* program) if (program->collect_statistics) { program->statistics[statistic_vmem_score] = - calculate_score(program->blocks.size(), out_ctx, event_vmem | event_flat | event_vmem_store); + calculate_score(out_ctx, event_vmem | event_flat | event_vmem_store); program->statistics[statistic_smem_score] = - calculate_score(program->blocks.size(), out_ctx, event_smem); + calculate_score(out_ctx, event_smem); } } -- 2.30.2