diff options
author | Heejin Ahn <aheejin@gmail.com> | 2020-02-20 18:09:55 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-20 18:09:54 -0800 |
commit | 3f4837b2d17181a4de9a2619372f0b38033bb432 (patch) | |
tree | 829972835e403141d3a5fe6a302ff325838cc162 | |
parent | 42e566c7983ef54e1fedf8ec2addfb23153509fa (diff) | |
download | binaryen-3f4837b2d17181a4de9a2619372f0b38033bb432.tar.gz binaryen-3f4837b2d17181a4de9a2619372f0b38033bb432.tar.bz2 binaryen-3f4837b2d17181a4de9a2619372f0b38033bb432.zip |
Add AutoDrop support for Try (#2663)
This adds AutoDrop (+ ReFinalize) support for Try. We don't have
`--autodrop` option so I can't add a separate test for this, but this is
basically the same as what If does.
-rw-r--r-- | src/ir/ReFinalize.cpp | 3 | ||||
-rw-r--r-- | src/ir/utils.h | 14 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/ir/ReFinalize.cpp b/src/ir/ReFinalize.cpp index 422f462c0..6d20d6597 100644 --- a/src/ir/ReFinalize.cpp +++ b/src/ir/ReFinalize.cpp @@ -128,6 +128,9 @@ void ReFinalize::visitThrow(Throw* curr) { curr->finalize(); } void ReFinalize::visitRethrow(Rethrow* curr) { curr->finalize(); } void ReFinalize::visitBrOnExn(BrOnExn* curr) { curr->finalize(); + if (curr->exnref->type == Type::unreachable) { + replaceUntaken(curr->exnref, nullptr); + } updateBreakValueType(curr->name, curr->sent); } void ReFinalize::visitNop(Nop* curr) { curr->finalize(); } diff --git a/src/ir/utils.h b/src/ir/utils.h index b7c5b9cba..7362cbe1a 100644 --- a/src/ir/utils.h +++ b/src/ir/utils.h @@ -301,6 +301,20 @@ struct AutoDrop : public WalkerPass<ExpressionStackWalker<AutoDrop>> { } } + void visitTry(Try* curr) { + bool acted = false; + if (maybeDrop(curr->body)) { + acted = true; + } + if (maybeDrop(curr->catchBody)) { + acted = true; + } + if (acted) { + reFinalize(); + assert(curr->type == Type::none); + } + } + void doWalkFunction(Function* curr) { ReFinalize().walkFunctionInModule(curr, getModule()); walk(curr->body); |