Module: Mesa
Branch: master
Commit: 23fb54bf7facf9368a3d8c633d3e4915c426d7ab
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=23fb54bf7facf9368a3d8c633d3e4915c426d7ab

Author: James Park <[email protected]>
Date:   Thu Oct 22 20:40:04 2020 -0700

aco: Clean up some C++ usages

Iterate over maps by reference to avoid copies.

Replace find/insert with insert to avoid double search.

Use range-based for loop, avoiding copies by reference. Delete comment.

Erase by iterator instead of key to avoid repeat search.

Iterators unneeded to modify unwaited_instrs. Use range-based for loop.

Reviewed-by: Tony Wasserka <[email protected]>
Reviewed-by: Rhys Perry <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7285>

---

 src/amd/compiler/aco_insert_waitcnt.cpp | 34 ++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/amd/compiler/aco_insert_waitcnt.cpp 
b/src/amd/compiler/aco_insert_waitcnt.cpp
index da94bfde12a..bc340764dd1 100644
--- a/src/amd/compiler/aco_insert_waitcnt.cpp
+++ b/src/amd/compiler/aco_insert_waitcnt.cpp
@@ -313,17 +313,17 @@ struct wait_ctx {
       pending_flat_vm |= other->pending_flat_vm;
       pending_s_buffer_store |= other->pending_s_buffer_store;
 
-      for (std::pair<PhysReg,wait_entry> entry : other->gpr_map)
+      for (const std::pair<PhysReg,wait_entry>& entry : other->gpr_map)
       {
-         std::map<PhysReg,wait_entry>::iterator it = gpr_map.find(entry.first);
          if (entry.second.logical != logical)
             continue;
 
-         if (it != gpr_map.end()) {
-            changed |= it->second.join(entry.second);
-         } else {
-            gpr_map.insert(entry);
+         using iterator = std::map<PhysReg,wait_entry>::iterator;
+         const std::pair<iterator, bool> insert_pair = gpr_map.insert(entry);
+         if (insert_pair.second) {
             changed = true;
+         } else {
+            changed |= insert_pair.first->second.join(entry.second);
          }
       }
 
@@ -335,16 +335,16 @@ struct wait_ctx {
 
       /* these are used for statistics, so don't update "changed" */
       for (unsigned i = 0; i < num_counters; i++) {
-         for (std::pair<Instruction *, unsigned> instr : 
other->unwaited_instrs[i]) {
-            auto pos = unwaited_instrs[i].find(instr.first);
-            if (pos == unwaited_instrs[i].end())
-               unwaited_instrs[i].insert(instr);
-            else
+         for (const std::pair<Instruction *, unsigned>& instr : 
other->unwaited_instrs[i]) {
+            using iterator = std::map<Instruction *, unsigned>::iterator;
+            const std::pair<iterator, bool> insert_pair = 
unwaited_instrs[i].insert(instr);
+            if (!insert_pair.second) {
+               const iterator pos = insert_pair.first;
                pos->second = std::min(pos->second, instr.second);
+            }
          }
-         /* don't use a foreach loop to avoid copies */
-         for (auto it = other->reg_instrs[i].begin(); it != 
other->reg_instrs[i].end(); ++it)
-            reg_instrs[i][it->first].insert(it->second.begin(), 
it->second.end());
+         for (const std::pair<PhysReg,std::set<Instruction *>>& instr : 
other->reg_instrs[i])
+            reg_instrs[i][instr.first].insert(instr.second.begin(), 
instr.second.end());
       }
 
       return changed;
@@ -365,7 +365,7 @@ struct wait_ctx {
                wait_distances[event_idx].push_back(distance);
             }
 
-            unwaited_instrs[counter_idx].erase(instr);
+            unwaited_instrs[counter_idx].erase(pos);
          }
          reg_instrs[counter_idx][reg].clear();
       }
@@ -376,8 +376,8 @@ struct wait_ctx {
    void advance_unwaited_instrs()
    {
       for (unsigned i = 0; i < num_counters; i++) {
-         for (auto it = unwaited_instrs[i].begin(); it != 
unwaited_instrs[i].end(); ++it)
-            it->second++;
+         for (std::pair<Instruction * const, unsigned>& instr : 
unwaited_instrs[i])
+            instr.second++;
       }
    }
 };

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to