diff options
author | Alon Zakai <azakai@google.com> | 2019-03-06 14:12:26 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2019-03-06 16:34:34 -0800 |
commit | 83aa0dc2daf327ed264cc22e51af1a866787a764 (patch) | |
tree | 70660819a1cd694c9776b0eb93db7c162eab274f /src/passes/SimplifyLocals.cpp | |
parent | 22fe3269f79c38c7954967ec303642b5168844c3 (diff) | |
download | binaryen-83aa0dc2daf327ed264cc22e51af1a866787a764.tar.gz binaryen-83aa0dc2daf327ed264cc22e51af1a866787a764.tar.bz2 binaryen-83aa0dc2daf327ed264cc22e51af1a866787a764.zip |
Optimize added constants with propagation only if we see we will remove all uses of the original add, as otherwise we may just be adding work (both an offset, and an add). Refactor local-utils.h, and make UnneededSetRemover also check for side effects, so it cleanly removes all traces of unneeded sets.
Diffstat (limited to 'src/passes/SimplifyLocals.cpp')
-rw-r--r-- | src/passes/SimplifyLocals.cpp | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp index a4931f06c..8007d92ff 100644 --- a/src/passes/SimplifyLocals.cpp +++ b/src/passes/SimplifyLocals.cpp @@ -51,7 +51,7 @@ #include <wasm-traversal.h> #include <pass.h> #include <ir/branch-utils.h> -#include <ir/count.h> +#include <ir/local-utils.h> #include <ir/effects.h> #include "ir/equivalent_sets.h" #include <ir/find_all.h> @@ -844,31 +844,9 @@ struct SimplifyLocals : public WalkerPass<LinearExecutionWalker<SimplifyLocals<a // We may have already had a local with no uses, or we may have just // gotten there thanks to the EquivalentOptimizer. If there are such // locals, remove all their sets. - struct UneededSetRemover : public PostWalker<UneededSetRemover> { - std::vector<Index>* numGetLocals; - - bool anotherCycle = false; - - void visitSetLocal(SetLocal *curr) { - if ((*numGetLocals)[curr->index] == 0) { - auto* value = curr->value; - if (curr->isTee()) { - this->replaceCurrent(value); - } else { - Drop* drop = ExpressionManipulator::convert<SetLocal, Drop>(curr); - drop->value = value; - drop->finalize(); - } - anotherCycle = true; - } - } - }; - - UneededSetRemover setRemover; - setRemover.numGetLocals = &getCounter.num; - setRemover.walkFunction(func); + UnneededSetRemover setRemover(getCounter, func, this->getPassOptions()); - return eqOpter.anotherCycle || setRemover.anotherCycle; + return eqOpter.anotherCycle || setRemover.removed; } }; |