diff options
author | Heejin Ahn <aheejin@gmail.com> | 2020-02-07 16:58:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 16:58:53 -0800 |
commit | f16078bf354b91ac56329b12e5c0274524579675 (patch) | |
tree | f475ba7259f3a32e1382f4f968f37712ebb8a242 /src | |
parent | 2b77f6ae60cfaf3f3cbdcc4121e82a619b9372c3 (diff) | |
download | binaryen-f16078bf354b91ac56329b12e5c0274524579675.tar.gz binaryen-f16078bf354b91ac56329b12e5c0274524579675.tar.bz2 binaryen-f16078bf354b91ac56329b12e5c0274524579675.zip |
Optimize Try in Vacuum (#2644)
If try's body does not throw, the whole try-catch can be replaced with
the try body.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Vacuum.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index f0bdd7722..54707fddc 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -414,6 +414,15 @@ struct Vacuum : public WalkerPass<ExpressionStackWalker<Vacuum>> { } } + void visitTry(Try* curr) { + // If try's body does not throw, the whole try-catch can be replaced with + // the try's body. + if (!EffectAnalyzer(getPassOptions(), getModule()->features, curr->body) + .throws) { + replaceCurrent(curr->body); + } + } + void visitFunction(Function* curr) { auto* optimized = optimize(curr->body, curr->sig.results != Type::none, true); |