summaryrefslogtreecommitdiff
path: root/src/passes/DeadCodeElimination.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-03-14 10:22:09 -0700
committerGitHub <noreply@github.com>2024-03-14 10:22:09 -0700
commit08e47de21223c3605edd71347e6b8b24b4187294 (patch)
tree0a9b941fb4822a67b1e2cbc79f4ef4ebd05e5a8b /src/passes/DeadCodeElimination.cpp
parent6e8fefe1ea13346f8908075d1f35b23317cfcc0f (diff)
downloadbinaryen-08e47de21223c3605edd71347e6b8b24b4187294.tar.gz
binaryen-08e47de21223c3605edd71347e6b8b24b4187294.tar.bz2
binaryen-08e47de21223c3605edd71347e6b8b24b4187294.zip
DCE: Fix old EH on a pop that gets moved in a catch body (#6400)
Diffstat (limited to 'src/passes/DeadCodeElimination.cpp')
-rw-r--r--src/passes/DeadCodeElimination.cpp32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/passes/DeadCodeElimination.cpp b/src/passes/DeadCodeElimination.cpp
index 0b382f465..996133ad5 100644
--- a/src/passes/DeadCodeElimination.cpp
+++ b/src/passes/DeadCodeElimination.cpp
@@ -28,13 +28,14 @@
// have no side effects.
//
-#include <ir/iteration.h>
-#include <ir/properties.h>
-#include <ir/type-updating.h>
-#include <pass.h>
-#include <vector>
-#include <wasm-builder.h>
-#include <wasm.h>
+#include "ir/eh-utils.h"
+#include "ir/iteration.h"
+#include "ir/properties.h"
+#include "ir/type-updating.h"
+#include "pass.h"
+#include "vector"
+#include "wasm-builder.h"
+#include "wasm.h"
namespace wasm {
@@ -89,7 +90,11 @@ struct DeadCodeElimination
Builder builder(*getModule());
std::vector<Expression*> remainingChildren;
bool afterUnreachable = false;
+ bool hasPop = false;
for (auto* child : ChildIterator(curr)) {
+ if (child->is<Pop>()) {
+ hasPop = true;
+ }
if (afterUnreachable) {
typeUpdater.noteRecursiveRemoval(child);
continue;
@@ -105,6 +110,11 @@ struct DeadCodeElimination
replaceCurrent(remainingChildren[0]);
} else {
replaceCurrent(builder.makeBlock(remainingChildren));
+ if (hasPop) {
+ // We are moving a pop into a new block we just created, which
+ // means we may need to fix things up here.
+ needEHFixups = true;
+ }
}
}
}
@@ -179,6 +189,14 @@ struct DeadCodeElimination
WASM_UNREACHABLE("unimplemented DCE control flow structure");
}
}
+
+ bool needEHFixups = false;
+
+ void visitFunction(Function* curr) {
+ if (needEHFixups) {
+ EHUtils::handleBlockNestedPops(curr, *getModule());
+ }
+ }
};
Pass* createDeadCodeEliminationPass() { return new DeadCodeElimination(); }