diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-24 18:25:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-24 18:25:26 -0700 |
commit | f6bc44f11bace70754470694f9101ba9cc5c2887 (patch) | |
tree | c6862019f90650140f86c2c5c02377ba2b6ad3ce /src/passes/Precompute.cpp | |
parent | 49ddf2f8ba2439f767cdbeb656c6ff42d5530cf8 (diff) | |
parent | 97cf0d7bf6f115d44636dd52dc7c0036567ca798 (diff) | |
download | binaryen-f6bc44f11bace70754470694f9101ba9cc5c2887.tar.gz binaryen-f6bc44f11bace70754470694f9101ba9cc5c2887.tar.bz2 binaryen-f6bc44f11bace70754470694f9101ba9cc5c2887.zip |
Merge pull request #714 from WebAssembly/precompute-void
Precompute void expressions, which helps ifs
Diffstat (limited to 'src/passes/Precompute.cpp')
-rw-r--r-- | src/passes/Precompute.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp index a341ba938..008058d58 100644 --- a/src/passes/Precompute.cpp +++ b/src/passes/Precompute.cpp @@ -15,23 +15,14 @@ */ // -// Removes dead, i.e. unreachable, code. -// -// We keep a record of when control flow is reachable. When it isn't, we -// kill (turn into unreachable). We then fold away entire unreachable -// expressions. -// -// When dead code causes an operation to not happen, like a store, a call -// or an add, we replace with a block with a list of what does happen. -// That isn't necessarily smaller, but blocks are friendlier to other -// optimizations: blocks can be merged and eliminated, and they clearly -// have no side effects. +// Computes code at compile time where possible. // #include <wasm.h> #include <pass.h> #include <wasm-builder.h> #include <wasm-interpreter.h> +#include <ast_utils.h> namespace wasm { @@ -90,7 +81,7 @@ struct Precompute : public WalkerPass<PostWalker<Precompute, UnifiedExpressionVi Pass* create() override { return new Precompute; } void visitExpression(Expression* curr) { - if (curr->is<Const>()) return; + if (curr->is<Const>() || curr->is<Nop>()) return; // try to evaluate this into a const Flow flow; try { @@ -99,8 +90,11 @@ struct Precompute : public WalkerPass<PostWalker<Precompute, UnifiedExpressionVi return; } if (flow.breaking()) return; // TODO: can create a break as a replacement in some cases (not NONSTANDALONE) + // this was precomputed if (isConcreteWasmType(flow.value.type)) { replaceCurrent(Builder(*getModule()).makeConst(flow.value)); + } else { + ExpressionManipulator::nop(curr); } } }; |