From f81eb2a8276ea7ab7143e7e5de8457d4894b2901 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sat, 10 Jul 2021 12:17:37 +0200 Subject: [PATCH] aco/spill: Avoid unneeded copies when iterating over maps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Daniel Schürmann Part-of: --- src/amd/compiler/aco_spill.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/amd/compiler/aco_spill.cpp b/src/amd/compiler/aco_spill.cpp index 205a687b7e4..dc1d3bc34f7 100644 --- a/src/amd/compiler/aco_spill.cpp +++ b/src/amd/compiler/aco_spill.cpp @@ -217,7 +217,7 @@ next_uses_per_block(spill_ctx& ctx, unsigned block_idx, std::set& work } /* all remaining live vars must be live-out at the predecessors */ - for (std::pair> pair : next_uses) { + for (std::pair>& pair : next_uses) { Temp temp = pair.first; uint32_t distance = pair.second.second; uint32_t dom = pair.second.first; @@ -360,7 +360,7 @@ local_next_uses(spill_ctx& ctx, Block* block) std::vector> local_next_uses(block->instructions.size()); std::map next_uses; - for (std::pair> pair : + for (std::pair>& pair : ctx.next_use_distances_end[block->index]) next_uses[pair.first] = pair.second.second + block->instructions.size(); @@ -489,7 +489,7 @@ init_live_in_vars(spill_ctx& ctx, Block* block, unsigned block_idx) unsigned distance = 0; Temp to_spill; - for (std::pair> pair : next_use_distances) { + for (std::pair>& pair : next_use_distances) { if (pair.first.type() == type && (pair.second.first >= loop_end || (ctx.remat.count(pair.first) && type == RegType::sgpr)) && @@ -533,7 +533,7 @@ init_live_in_vars(spill_ctx& ctx, Block* block, unsigned block_idx) Temp to_spill; type = reg_pressure.vgpr > ctx.target_pressure.vgpr ? RegType::vgpr : RegType::sgpr; - for (std::pair> pair : next_use_distances) { + for (std::pair>& pair : next_use_distances) { if (pair.first.type() == type && pair.second.second > distance && ctx.spills_entry[block_idx].find(pair.first) == ctx.spills_entry[block_idx].end()) { to_spill = pair.first; @@ -604,7 +604,7 @@ init_live_in_vars(spill_ctx& ctx, Block* block, unsigned block_idx) std::set partial_spills; /* keep variables spilled on all incoming paths */ - for (std::pair> pair : next_use_distances) { + for (std::pair>& pair : next_use_distances) { std::vector& preds = pair.first.is_linear() ? block->linear_preds : block->logical_preds; /* If it can be rematerialized, keep the variable spilled if all predecessors do not reload @@ -722,7 +722,7 @@ add_coupling_code(spill_ctx& ctx, Block* block, unsigned block_idx) unsigned insert_idx = 0; RegisterDemand demand_before = get_demand_before(ctx, block_idx, 0); - for (std::pair> live : + for (std::pair>& live : ctx.next_use_distances_start[block_idx]) { const unsigned pred_idx = block->linear_preds[0]; @@ -758,7 +758,7 @@ add_coupling_code(spill_ctx& ctx, Block* block, unsigned block_idx) } while (instructions.back()->opcode != aco_opcode::p_logical_start); unsigned pred_idx = block->logical_preds[0]; - for (std::pair> live : + for (std::pair>& live : ctx.next_use_distances_start[block_idx]) { if (live.first.is_linear()) continue; @@ -993,7 +993,7 @@ add_coupling_code(spill_ctx& ctx, Block* block, unsigned block_idx) /* iterate live variables for which to reload */ // TODO: reload at current block if variable is spilled on all predecessors - for (std::pair> pair : + for (std::pair>& pair : ctx.next_use_distances_start[block_idx]) { /* skip spilled variables */ if (ctx.spills_entry[block_idx].find(pair.first) != ctx.spills_entry[block_idx].end()) @@ -1189,7 +1189,7 @@ process_block(spill_ctx& ctx, unsigned block_idx, Block* block, /* add interferences with currently spilled variables */ for (std::pair pair : current_spills) ctx.add_interference(spill_id, pair.second); - for (std::pair> pair : reloads) + for (std::pair>& pair : reloads) ctx.add_interference(spill_id, pair.second.second); current_spills[to_spill] = spill_id; @@ -1210,7 +1210,7 @@ process_block(spill_ctx& ctx, unsigned block_idx, Block* block, } /* add reloads and instruction to new instructions */ - for (std::pair> pair : reloads) { + for (std::pair>& pair : reloads) { aco_ptr reload = do_reload(ctx, pair.second.first, pair.first, pair.second.second); instructions.emplace_back(std::move(reload));