From acc10a7e51770919ec215351661d46fa6fc355af Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 11 Mar 2020 10:47:07 +0100 Subject: [PATCH] aco: change some std::map to std::unordered_map in register_allocation This improves compile times slightly for larger shaders Reviewed-by: Rhys Perry Part-of: --- src/amd/compiler/aco_register_allocation.cpp | 28 ++++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp index aab1cd3745f..2332677bd83 100644 --- a/src/amd/compiler/aco_register_allocation.cpp +++ b/src/amd/compiler/aco_register_allocation.cpp @@ -51,7 +51,7 @@ struct ra_ctx { std::bitset<512> war_hint; Program* program; std::vector assignments; - std::map orig_names; + std::unordered_map orig_names; unsigned max_used_sgpr = 0; unsigned max_used_vgpr = 0; std::bitset<64> defs_done; /* see MAX_ARGS in aco_instruction_selection_setup.cpp */ @@ -1114,8 +1114,8 @@ void register_allocation(Program *program, std::vector>& live_out memset(filled, 0, sizeof filled); memset(sealed, 0, sizeof sealed); std::vector> incomplete_phis(program->blocks.size()); - std::map phi_map; - std::map affinities; + std::unordered_map phi_map; + std::unordered_map affinities; std::function read_variable; std::function handle_live_in; std::function try_remove_trivial_phi; @@ -1199,7 +1199,7 @@ void register_allocation(Program *program, std::vector>& live_out }; try_remove_trivial_phi = [&] (Temp temp) -> void { - std::map::iterator info = phi_map.find(temp.id()); + std::unordered_map::iterator info = phi_map.find(temp.id()); if (info == phi_map.end() || !sealed[info->second.block_idx]) return; @@ -1225,7 +1225,7 @@ void register_allocation(Program *program, std::vector>& live_out /* reroute all uses to same and remove phi */ std::vector phi_users; - std::map::iterator same_phi_info = phi_map.find(same.id()); + std::unordered_map::iterator same_phi_info = phi_map.find(same.id()); for (Instruction* instr : info->second.uses) { assert(phi != instr); /* recursively try to remove trivial phis */ @@ -1262,9 +1262,9 @@ void register_allocation(Program *program, std::vector>& live_out return; }; - std::map vectors; + std::unordered_map vectors; std::vector> phi_ressources; - std::map temp_to_phi_ressources; + std::unordered_map temp_to_phi_ressources; for (std::vector::reverse_iterator it = program->blocks.rbegin(); it != program->blocks.rend(); it++) { Block& block = *it; @@ -1315,7 +1315,7 @@ void register_allocation(Program *program, std::vector>& live_out continue; live.erase(def.getTemp()); /* mark last-seen phi operand */ - std::map::iterator it = temp_to_phi_ressources.find(def.tempId()); + std::unordered_map::iterator it = temp_to_phi_ressources.find(def.tempId()); if (it != temp_to_phi_ressources.end() && def.regClass() == phi_ressources[it->second][0].regClass()) { phi_ressources[it->second][0] = def.getTemp(); /* try to coalesce phi affinities with parallelcopies */ @@ -1477,7 +1477,7 @@ void register_allocation(Program *program, std::vector>& live_out } /* rename */ - std::map::iterator orig_it = ctx.orig_names.find(pc.first.tempId()); + std::unordered_map::iterator orig_it = ctx.orig_names.find(pc.first.tempId()); Temp orig = pc.first.getTemp(); if (orig_it != ctx.orig_names.end()) orig = orig_it->second; @@ -1638,7 +1638,7 @@ void register_allocation(Program *program, std::vector>& live_out ctx.war_hint.set(operand.physReg().reg() + j); } } - std::map::iterator phi = phi_map.find(operand.getTemp().id()); + std::unordered_map::iterator phi = phi_map.find(operand.getTemp().id()); if (phi != phi_map.end()) phi->second.uses.emplace(instr.get()); @@ -1883,12 +1883,12 @@ void register_allocation(Program *program, std::vector>& live_out assert(pc->operands[i].size() == pc->definitions[i].size()); /* it might happen that the operand is already renamed. we have to restore the original name. */ - std::map::iterator it = ctx.orig_names.find(pc->operands[i].tempId()); + std::unordered_map::iterator it = ctx.orig_names.find(pc->operands[i].tempId()); Temp orig = it != ctx.orig_names.end() ? it->second : pc->operands[i].getTemp(); ctx.orig_names[pc->definitions[i].tempId()] = orig; renames[block.index][orig.id()] = pc->definitions[i].getTemp(); - std::map::iterator phi = phi_map.find(pc->operands[i].tempId()); + std::unordered_map::iterator phi = phi_map.find(pc->operands[i].tempId()); if (phi != phi_map.end()) phi->second.uses.emplace(pc.get()); } @@ -1993,7 +1993,7 @@ void register_allocation(Program *program, std::vector>& live_out instr->operands[i] = operand; /* keep phi_map up to date */ if (operand.isTemp()) { - std::map::iterator phi = phi_map.find(operand.tempId()); + std::unordered_map::iterator phi = phi_map.find(operand.tempId()); if (phi != phi_map.end()) { phi->second.uses.erase(tmp.get()); phi->second.uses.emplace(instr.get()); @@ -2043,7 +2043,7 @@ void register_allocation(Program *program, std::vector>& live_out continue; operand.setTemp(read_variable(operand.getTemp(), preds[i])); operand.setFixed(ctx.assignments[operand.tempId()].reg); - std::map::iterator phi = phi_map.find(operand.getTemp().id()); + std::unordered_map::iterator phi = phi_map.find(operand.getTemp().id()); if (phi != phi_map.end()) phi->second.uses.emplace(instr.get()); } -- 2.30.2