diff options
author | Alon Zakai <alonzakai@gmail.com> | 2018-04-05 14:49:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-05 14:49:25 -0700 |
commit | 5b5789495a97602869f18d552b2a9e1814edefae (patch) | |
tree | f70e304fc85dca03ebd6d2311007476700e1ffd0 /src/wasm/wasm.cpp | |
parent | 82151243bbd4c018191721dce5381c8e449f3c77 (diff) | |
download | binaryen-5b5789495a97602869f18d552b2a9e1814edefae.tar.gz binaryen-5b5789495a97602869f18d552b2a9e1814edefae.tar.bz2 binaryen-5b5789495a97602869f18d552b2a9e1814edefae.zip |
when creating blocks in binary format parsing, we know if a block has a break to it - use that to avoid rescanning blocks for unreachability purposes (#1495)
Diffstat (limited to 'src/wasm/wasm.cpp')
-rw-r--r-- | src/wasm/wasm.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index cf847d5aa..5fc2ee715 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -171,7 +171,7 @@ static Type mergeTypes(std::vector<Type>& types) { // a block is unreachable if one of its elements is unreachable, // and there are no branches to it -static void handleUnreachable(Block* block) { +static void handleUnreachable(Block* block, bool breakabilityKnown=false, bool hasBreak=false) { if (block->type == unreachable) return; // nothing to do if (block->list.size() == 0) return; // nothing to do // if we are concrete, stop - even an unreachable child @@ -182,7 +182,10 @@ static void handleUnreachable(Block* block) { for (auto* child : block->list) { if (child->type == unreachable) { // there is an unreachable child, so we are unreachable, unless we have a break - if (!BranchUtils::BranchSeeker::hasNamed(block, block->name)) { + if (!breakabilityKnown) { + hasBreak = BranchUtils::BranchSeeker::hasNamed(block, block->name); + } + if (!hasBreak) { block->type = unreachable; } return; @@ -190,13 +193,6 @@ static void handleUnreachable(Block* block) { } } -void Block::finalize(Type type_) { - type = type_; - if (type == none && list.size() > 0) { - handleUnreachable(this); - } -} - void Block::finalize() { if (!name.is()) { if (list.size() > 0) { @@ -231,6 +227,20 @@ void Block::finalize() { handleUnreachable(this); } +void Block::finalize(Type type_) { + type = type_; + if (type == none && list.size() > 0) { + handleUnreachable(this); + } +} + +void Block::finalize(Type type_, bool hasBreak) { + type = type_; + if (type == none && list.size() > 0) { + handleUnreachable(this, true, hasBreak); + } +} + void If::finalize(Type type_) { type = type_; if (type == none && (condition->type == unreachable || (ifFalse && ifTrue->type == unreachable && ifFalse->type == unreachable))) { |