summaryrefslogtreecommitdiff
path: root/src/passes
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes')
-rw-r--r--src/passes/CodeFolding.cpp8
-rw-r--r--src/passes/DeadCodeElimination.cpp7
-rw-r--r--src/passes/MergeBlocks.cpp2
-rw-r--r--src/passes/OptimizeInstructions.cpp4
-rw-r--r--src/passes/Print.cpp32
-rw-r--r--src/passes/SimplifyLocals.cpp4
-rw-r--r--src/passes/Vacuum.cpp4
7 files changed, 39 insertions, 22 deletions
diff --git a/src/passes/CodeFolding.cpp b/src/passes/CodeFolding.cpp
index ee54c50a6..a0fc11c83 100644
--- a/src/passes/CodeFolding.cpp
+++ b/src/passes/CodeFolding.cpp
@@ -306,10 +306,10 @@ private:
}
if (getModule()->features.hasExceptionHandling()) {
EffectAnalyzer effects(getPassOptions(), getModule()->features, item);
- // Currently pop instructions are only used for exnref.pop, which is a
- // pseudo instruction following a catch. We cannot move expressions
- // containing pops if they are not enclosed in a 'catch' body, because a
- // pop instruction should follow right after 'catch'.
+ // Pop instructions are pseudoinstructions used only after 'catch' to
+ // simulate its behavior. We cannot move expressions containing pops if
+ // they are not enclosed in a 'catch' body, because a pop instruction
+ // should follow right after 'catch'.
if (effects.danglingPop) {
return false;
}
diff --git a/src/passes/DeadCodeElimination.cpp b/src/passes/DeadCodeElimination.cpp
index 3e84a7be1..c30da5428 100644
--- a/src/passes/DeadCodeElimination.cpp
+++ b/src/passes/DeadCodeElimination.cpp
@@ -161,9 +161,12 @@ struct DeadCodeElimination
} else if (auto* tryy = curr->dynCast<Try>()) {
// If both try body and catch body are unreachable, there is no need for a
// concrete type, which may allow more reduction.
+ bool allCatchesUnreachable = true;
+ for (auto* catchBody : tryy->catchBodies) {
+ allCatchesUnreachable &= catchBody->type == Type::unreachable;
+ }
if (tryy->type != Type::unreachable &&
- tryy->body->type == Type::unreachable &&
- tryy->catchBody->type == Type::unreachable) {
+ tryy->body->type == Type::unreachable && allCatchesUnreachable) {
typeUpdater.changeType(tryy, Type::unreachable);
}
} else {
diff --git a/src/passes/MergeBlocks.cpp b/src/passes/MergeBlocks.cpp
index 33dbec77c..0ce776524 100644
--- a/src/passes/MergeBlocks.cpp
+++ b/src/passes/MergeBlocks.cpp
@@ -597,8 +597,6 @@ struct MergeBlocks : public WalkerPass<PostWalker<MergeBlocks>> {
}
}
- void visitRethrow(Rethrow* curr) { optimize(curr, curr->exnref); }
-
void visitBrOnExn(BrOnExn* curr) { optimize(curr, curr->exnref); }
};
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 2b0a95fc7..c06763643 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -1099,7 +1099,9 @@ private:
} else if (auto* tryy = boolean->dynCast<Try>()) {
if (tryy->type == Type::i32) {
tryy->body = optimizeBoolean(tryy->body);
- tryy->catchBody = optimizeBoolean(tryy->catchBody);
+ for (Index i = 0; i < tryy->catchBodies.size(); i++) {
+ tryy->catchBodies[i] = optimizeBoolean(tryy->catchBodies[i]);
+ }
}
}
// TODO: recurse into br values?
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index e1d80a11a..b6da29861 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -1710,7 +1710,10 @@ struct PrintExpressionContents
printMedium(o, "throw ");
printName(curr->event, o);
}
- void visitRethrow(Rethrow* curr) { printMedium(o, "rethrow"); }
+ void visitRethrow(Rethrow* curr) {
+ printMedium(o, "rethrow ");
+ o << curr->depth;
+ }
void visitBrOnExn(BrOnExn* curr) {
printMedium(o, "br_on_exn ");
printName(curr->name, o);
@@ -2363,12 +2366,23 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
maybePrintImplicitBlock(curr->body, true);
decIndent();
o << "\n";
- doIndent(o, indent);
- o << "(catch";
- incIndent();
- maybePrintImplicitBlock(curr->catchBody, true);
- decIndent();
- o << "\n";
+ for (size_t i = 0; i < curr->catchEvents.size(); i++) {
+ doIndent(o, indent);
+ o << "(catch ";
+ printName(curr->catchEvents[i], o);
+ incIndent();
+ maybePrintImplicitBlock(curr->catchBodies[i], true);
+ decIndent();
+ o << "\n";
+ }
+ if (curr->hasCatchAll()) {
+ doIndent(o, indent);
+ o << "(catch_all";
+ incIndent();
+ maybePrintImplicitBlock(curr->catchBodies.back(), true);
+ decIndent();
+ o << "\n";
+ }
decIndent();
if (full) {
o << " ;; end try";
@@ -2386,9 +2400,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
void visitRethrow(Rethrow* curr) {
o << '(';
PrintExpressionContents(currFunction, o).visit(curr);
- incIndent();
- printFullLine(curr->exnref);
- decIndent();
+ o << ')';
}
void visitBrOnExn(BrOnExn* curr) {
o << '(';
diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp
index 963575c5f..9f164ae92 100644
--- a/src/passes/SimplifyLocals.cpp
+++ b/src/passes/SimplifyLocals.cpp
@@ -425,8 +425,8 @@ struct SimplifyLocals
if (set->isTee()) {
return false;
}
- // We cannot move expressions containing exnref.pops that are not enclosed
- // in 'catch', because 'exnref.pop' should follow right after 'catch'.
+ // We cannot move expressions containing pops that are not enclosed in
+ // 'catch', because 'pop' should follow right after 'catch'.
FeatureSet features = this->getModule()->features;
if (features.hasExceptionHandling() &&
EffectAnalyzer(this->getPassOptions(), features, set->value)
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp
index 789c53ad7..ca777431a 100644
--- a/src/passes/Vacuum.cpp
+++ b/src/passes/Vacuum.cpp
@@ -341,7 +341,9 @@ struct Vacuum : public WalkerPass<ExpressionStackWalker<Vacuum>> {
if (!EffectAnalyzer(getPassOptions(), getModule()->features, curr->body)
.throws) {
replaceCurrent(curr->body);
- typeUpdater.noteRecursiveRemoval(curr->catchBody);
+ for (auto* catchBody : curr->catchBodies) {
+ typeUpdater.noteRecursiveRemoval(catchBody);
+ }
}
}