From fc02a0c40496b60bbcf4715cf349895d1462b1ae Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Mon, 11 May 2015 21:01:48 -0700 Subject: [PATCH] Switching up std::vector use in register allocator. --- build/Xenia.Cpp.x64.Checked.props | 3 ++ .../passes/register_allocation_pass.cc | 36 ++++++++++--------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/build/Xenia.Cpp.x64.Checked.props b/build/Xenia.Cpp.x64.Checked.props index 3e642196c..df6192456 100644 --- a/build/Xenia.Cpp.x64.Checked.props +++ b/build/Xenia.Cpp.x64.Checked.props @@ -10,6 +10,9 @@ Guard ProgramDatabase CHECKED;%(PreprocessorDefinitions) + true + EnableFastChecks + true diff --git a/src/xenia/cpu/compiler/passes/register_allocation_pass.cc b/src/xenia/cpu/compiler/passes/register_allocation_pass.cc index 298faaed2..1a63eb8f8 100644 --- a/src/xenia/cpu/compiler/passes/register_allocation_pass.cc +++ b/src/xenia/cpu/compiler/passes/register_allocation_pass.cc @@ -210,46 +210,48 @@ void RegisterAllocationPass::AdvanceUses(Instr* instr) { if (!usage_set) { break; } - std::vector to_add; auto& upcoming_uses = usage_set->upcoming_uses; - for (auto& it = upcoming_uses.begin(); it != upcoming_uses.end();) { - if (!it->use) { + for (int i = 0; i < upcoming_uses.size();) { + auto& upcoming_use = upcoming_uses.at(i); + if (!upcoming_use.use) { // No uses at all - we can remove right away. // This comes up from instructions where the dest is never used, // like the ATOMIC ops. - MarkRegAvailable(it->value->reg); - it = upcoming_uses.erase(it); + MarkRegAvailable(upcoming_use.value->reg); + upcoming_uses.erase(upcoming_uses.begin() + i); + // i remains the same. continue; } - if (it->use->instr != instr) { + if (upcoming_use.use->instr != instr) { // Not yet at this instruction. - ++it; + ++i; continue; } // The use is from this instruction. - if (!it->use->next) { + if (!upcoming_use.use->next) { // Last use of the value. We can retire it now. - MarkRegAvailable(it->value->reg); - it = upcoming_uses.erase(it); + MarkRegAvailable(upcoming_use.value->reg); + upcoming_uses.erase(upcoming_uses.begin() + i); + // i remains the same. + continue; } else { // Used again. Push back the next use. // Note that we may be used multiple times this instruction, so // eat those. - auto next_use = it->use->next; + auto next_use = upcoming_use.use->next; while (next_use->next && next_use->instr == instr) { next_use = next_use->next; } // Remove the iterator. - auto value = it->value; - it = upcoming_uses.erase(it); + auto value = upcoming_use.value; + upcoming_uses.erase(upcoming_uses.begin() + i); assert_true(next_use->instr->block == instr->block); assert_true(value->def->block == instr->block); - to_add.emplace_back(value, next_use); + upcoming_uses.emplace_back(value, next_use); + // i remains the same. + continue; } } - for (auto& use : to_add) { - upcoming_uses.emplace_back(use); - } } DumpUsage("AdvanceUses"); }