summaryrefslogtreecommitdiff
path: root/src/wasm/wasm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm.cpp')
-rw-r--r--src/wasm/wasm.cpp28
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))) {