Mesa (main): aco/spill: Avoid copying next_use maps more often than needed

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 1 09:57:11 UTC 2021


Module: Mesa
Branch: main
Commit: 387b315ea047779db4a0657c1280bc3bd5531eaa
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=387b315ea047779db4a0657c1280bc3bd5531eaa

Author: Tony Wasserka <tony.wasserka at gmx.de>
Date:   Sat Jul 10 13:59:42 2021 +0200

aco/spill: Avoid copying next_use maps more often than needed

Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11925>

---

 src/amd/compiler/aco_spill.cpp | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/amd/compiler/aco_spill.cpp b/src/amd/compiler/aco_spill.cpp
index 646b492fbc9..fcb0eafbb2b 100644
--- a/src/amd/compiler/aco_spill.cpp
+++ b/src/amd/compiler/aco_spill.cpp
@@ -359,10 +359,11 @@ local_next_uses(spill_ctx& ctx, Block* block)
 {
    std::vector<std::map<Temp, uint32_t>> local_next_uses(block->instructions.size());
 
-   std::map<Temp, uint32_t> next_uses;
    for (std::pair<const Temp, std::pair<uint32_t, uint32_t>>& pair :
-        ctx.next_use_distances_end[block->index])
-      next_uses.insert({pair.first, pair.second.second + block->instructions.size()});
+        ctx.next_use_distances_end[block->index]) {
+      local_next_uses[block->instructions.size() - 1].insert(
+         {pair.first, pair.second.second + block->instructions.size()});
+   }
 
    for (int idx = block->instructions.size() - 1; idx >= 0; idx--) {
       aco_ptr<Instruction>& instr = block->instructions[idx];
@@ -371,19 +372,24 @@ local_next_uses(spill_ctx& ctx, Block* block)
       if (instr->opcode == aco_opcode::p_phi || instr->opcode == aco_opcode::p_linear_phi)
          break;
 
+      if (idx != (int)block->instructions.size() - 1) {
+         local_next_uses[idx] = local_next_uses[idx + 1];
+      }
+
       for (const Operand& op : instr->operands) {
          if (op.isFixed() && op.physReg() == exec)
             continue;
          if (op.regClass().type() == RegType::vgpr && op.regClass().is_linear())
             continue;
-         if (op.isTemp())
-            next_uses[op.getTemp()] = idx;
+         if (op.isTemp()) {
+            local_next_uses[idx][op.getTemp()] = idx;
+         }
       }
       for (const Definition& def : instr->definitions) {
-         if (def.isTemp())
-            next_uses.erase(def.getTemp());
+         if (def.isTemp()) {
+            local_next_uses[idx].erase(def.getTemp());
+         }
       }
-      local_next_uses[idx] = next_uses;
    }
    return local_next_uses;
 }



More information about the mesa-commit mailing list