From b08aa103597b00a2b4a54d81cde6454f3082b4d5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 18 Apr 2016 11:47:04 -0700 Subject: index locals, so that get_local and set_local have just an index, and local names are kept on the Function object (#354) --- src/passes/SimplifyLocals.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/passes/SimplifyLocals.cpp') diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp index 6220d0780..ddb3bccae 100644 --- a/src/passes/SimplifyLocals.cpp +++ b/src/passes/SimplifyLocals.cpp @@ -45,12 +45,12 @@ struct SimplifyLocals : public WalkerPass> }; // locals in current linear execution trace, which we try to sink - std::map sinkables; + std::map sinkables; bool sunk; - // name => # of get_locals for it - std::map numGetLocals; + // local => # of get_locals for it + std::map numGetLocals; // for each set_local, its origin pointer std::map setLocalOrigins; @@ -60,7 +60,7 @@ struct SimplifyLocals : public WalkerPass> } void visitGetLocal(GetLocal *curr) { - auto found = sinkables.find(curr->name); + auto found = sinkables.find(curr->index); if (found != sinkables.end()) { // sink it, and nop the origin TODO: clean up nops replaceCurrent(*found->second.item); @@ -70,7 +70,7 @@ struct SimplifyLocals : public WalkerPass> sinkables.erase(found); sunk = true; } else { - numGetLocals[curr->name]++; + numGetLocals[curr->index]++; } } @@ -78,7 +78,7 @@ struct SimplifyLocals : public WalkerPass> // if we are a potentially-sinkable thing, forget it - this // write overrides the last TODO: optimizable // TODO: if no get_locals left, can remove the set as well (== expressionizer in emscripten optimizer) - auto found = sinkables.find(curr->name); + auto found = sinkables.find(curr->index); if (found != sinkables.end()) { sinkables.erase(found); } @@ -86,14 +86,14 @@ struct SimplifyLocals : public WalkerPass> void checkInvalidations(EffectAnalyzer& effects) { // TODO: this is O(bad) - std::vector invalidated; + std::vector invalidated; for (auto& sinkable : sinkables) { if (effects.invalidates(sinkable.second.effects)) { invalidated.push_back(sinkable.first); } } - for (auto name : invalidated) { - sinkables.erase(name); + for (auto index : invalidated) { + sinkables.erase(index); } } @@ -125,9 +125,9 @@ struct SimplifyLocals : public WalkerPass> static void tryMarkSinkable(SimplifyLocals* self, Expression** currp) { auto* curr = (*currp)->dynCast(); if (curr) { - Name name = curr->name; - assert(self->sinkables.count(name) == 0); - self->sinkables.emplace(std::make_pair(name, SinkableInfo(currp))); + Index index = curr->index; + assert(self->sinkables.count(index) == 0); + self->sinkables.emplace(std::make_pair(index, SinkableInfo(currp))); } } @@ -175,7 +175,7 @@ struct SimplifyLocals : public WalkerPass> std::vector optimizables; for (auto pair : setLocalOrigins) { SetLocal* curr = pair.first; - if (numGetLocals[curr->name] == 0) { + if (numGetLocals[curr->index] == 0) { // no gets, can remove the set and leave just the value optimizables.push_back(curr); } -- cgit v1.2.3