diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-23 21:39:52 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-24 09:36:04 -0700 |
commit | 203d502f9c3c5fc1f16822d3432087785653d767 (patch) | |
tree | a69336ce42338687081b3d1fe5b61ce6ba682d42 /src | |
parent | 9f1849ef99db9fa8a8a44daec348b7f2bb562453 (diff) | |
download | binaryen-203d502f9c3c5fc1f16822d3432087785653d767.tar.gz binaryen-203d502f9c3c5fc1f16822d3432087785653d767.tar.bz2 binaryen-203d502f9c3c5fc1f16822d3432087785653d767.zip |
get rid of nops in ifs
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Vacuum.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 12565f603..dd88fa0eb 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -21,6 +21,7 @@ #include <wasm.h> #include <pass.h> #include <ast_utils.h> +#include <wasm-builder.h> namespace wasm { @@ -62,6 +63,25 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum, Visitor<Vacuum>>> { } } } + + void visitIf(If* curr) { + if (curr->ifFalse) { + if (curr->ifFalse->is<Nop>()) { + curr->ifFalse = nullptr; + } else if (curr->ifTrue->is<Nop>()) { + curr->ifTrue = curr->ifFalse; + curr->ifFalse = nullptr; + curr->condition = Builder(*getModule()).makeUnary(EqZ, curr->condition, curr->condition->type); + } + } + if (!curr->ifFalse) { + // no else + if (curr->ifTrue->is<Nop>()) { + // no nothing + replaceCurrent(curr->condition); + } + } + } }; static RegisterPass<Vacuum> registerPass("vacuum", "removes obviously unneeded code"); |