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 <tony.wasserka@gmx.de> Reviewed-by: Rhys Perry <pendingchaos02@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7285>
This commit is contained in:
parent
79347f5cd4
commit
23fb54bf7f
|
@ -313,17 +313,17 @@ struct wait_ctx {
|
||||||
pending_flat_vm |= other->pending_flat_vm;
|
pending_flat_vm |= other->pending_flat_vm;
|
||||||
pending_s_buffer_store |= other->pending_s_buffer_store;
|
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)
|
if (entry.second.logical != logical)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (it != gpr_map.end()) {
|
using iterator = std::map<PhysReg,wait_entry>::iterator;
|
||||||
changed |= it->second.join(entry.second);
|
const std::pair<iterator, bool> insert_pair = gpr_map.insert(entry);
|
||||||
} else {
|
if (insert_pair.second) {
|
||||||
gpr_map.insert(entry);
|
|
||||||
changed = true;
|
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" */
|
/* these are used for statistics, so don't update "changed" */
|
||||||
for (unsigned i = 0; i < num_counters; i++) {
|
for (unsigned i = 0; i < num_counters; i++) {
|
||||||
for (std::pair<Instruction *, unsigned> instr : other->unwaited_instrs[i]) {
|
for (const std::pair<Instruction *, unsigned>& instr : other->unwaited_instrs[i]) {
|
||||||
auto pos = unwaited_instrs[i].find(instr.first);
|
using iterator = std::map<Instruction *, unsigned>::iterator;
|
||||||
if (pos == unwaited_instrs[i].end())
|
const std::pair<iterator, bool> insert_pair = unwaited_instrs[i].insert(instr);
|
||||||
unwaited_instrs[i].insert(instr);
|
if (!insert_pair.second) {
|
||||||
else
|
const iterator pos = insert_pair.first;
|
||||||
pos->second = std::min(pos->second, instr.second);
|
pos->second = std::min(pos->second, instr.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* don't use a foreach loop to avoid copies */
|
for (const std::pair<PhysReg,std::set<Instruction *>>& instr : other->reg_instrs[i])
|
||||||
for (auto it = other->reg_instrs[i].begin(); it != other->reg_instrs[i].end(); ++it)
|
reg_instrs[i][instr.first].insert(instr.second.begin(), instr.second.end());
|
||||||
reg_instrs[i][it->first].insert(it->second.begin(), it->second.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
|
@ -365,7 +365,7 @@ struct wait_ctx {
|
||||||
wait_distances[event_idx].push_back(distance);
|
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();
|
reg_instrs[counter_idx][reg].clear();
|
||||||
}
|
}
|
||||||
|
@ -376,8 +376,8 @@ struct wait_ctx {
|
||||||
void advance_unwaited_instrs()
|
void advance_unwaited_instrs()
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < num_counters; i++) {
|
for (unsigned i = 0; i < num_counters; i++) {
|
||||||
for (auto it = unwaited_instrs[i].begin(); it != unwaited_instrs[i].end(); ++it)
|
for (std::pair<Instruction * const, unsigned>& instr : unwaited_instrs[i])
|
||||||
it->second++;
|
instr.second++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue