diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-11 21:21:50 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-11 21:24:24 -0700 |
commit | 5da280167ac6f3e76d27c109ee08ae1747405b5c (patch) | |
tree | 6b84391334e16e8bef46fc8629a33fc9b0747659 /src | |
parent | 546a234d6e195a69c5e0b89cf20ed020f8d09db5 (diff) | |
download | binaryen-5da280167ac6f3e76d27c109ee08ae1747405b5c.tar.gz binaryen-5da280167ac6f3e76d27c109ee08ae1747405b5c.tar.bz2 binaryen-5da280167ac6f3e76d27c109ee08ae1747405b5c.zip |
drop completely unused locals in ReorderLocals
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/ReorderLocals.cpp | 7 | ||||
-rw-r--r-- | src/passes/SimplifyLocals.cpp | 4 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/passes/ReorderLocals.cpp b/src/passes/ReorderLocals.cpp index e378408b6..7f64c00f3 100644 --- a/src/passes/ReorderLocals.cpp +++ b/src/passes/ReorderLocals.cpp @@ -31,12 +31,17 @@ struct ReorderLocals : public WalkerPass<PostWalker<ReorderLocals>> { std::map<Name, uint32_t> counts; void visitFunction(Function *curr) { - sort(curr->locals.begin(), curr->locals.end(), [this](NameType a, NameType b) -> bool { + auto& locals = curr->locals; + sort(locals.begin(), locals.end(), [this](NameType a, NameType b) -> bool { if (this->counts[a.name] == this->counts[b.name]) { return strcmp(a.name.str, b.name.str) > 0; } return this->counts[a.name] > this->counts[b.name]; }); + // drop completely unused locals + while (locals.size() > 0 && counts[locals.back().name] == 0) { + locals.pop_back(); + } counts.clear(); } diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp index faf6e3a6e..408fea7ab 100644 --- a/src/passes/SimplifyLocals.cpp +++ b/src/passes/SimplifyLocals.cpp @@ -20,6 +20,10 @@ // This "sinks" set_locals, pushing them to the next get_local where possible, // and removing the set if there are no gets remaining (the latter is // particularly useful in ssa mode, but not only). +// +// After this pass, some locals may be completely unused. reorder-locals +// can get rid of those (the operation is trivial there after it sorts by use +// frequency). #include <wasm.h> #include <wasm-traversal.h> |