summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-02-18 22:02:51 +0000
committerGitHub <noreply@github.com>2021-02-18 14:02:51 -0800
commitec2aa7e870ef4d9926e35c5f4bfc7cdbabe2441a (patch)
tree25858a9869946fb867ba65cd60ceecda15e07d50 /src
parent7089ada7c62618d36f5a0a3339334603c5b61a30 (diff)
downloadbinaryen-ec2aa7e870ef4d9926e35c5f4bfc7cdbabe2441a.tar.gz
binaryen-ec2aa7e870ef4d9926e35c5f4bfc7cdbabe2441a.tar.bz2
binaryen-ec2aa7e870ef4d9926e35c5f4bfc7cdbabe2441a.zip
[Wasm Exceptions] Scan catch events in RemoveUnusedModuleElements (#3582)
Also refactor away some annoying repeated code in that pass. visitTry is the only actual change.
Diffstat (limited to 'src')
-rw-r--r--src/passes/RemoveUnusedModuleElements.cpp39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/passes/RemoveUnusedModuleElements.cpp b/src/passes/RemoveUnusedModuleElements.cpp
index 8401f5e1f..d12fdb487 100644
--- a/src/passes/RemoveUnusedModuleElements.cpp
+++ b/src/passes/RemoveUnusedModuleElements.cpp
@@ -85,32 +85,26 @@ struct ReachabilityAnalyzer : public PostWalker<ReachabilityAnalyzer> {
}
}
- void visitCall(Call* curr) {
- if (reachable.count(
- ModuleElement(ModuleElementKind::Function, curr->target)) == 0) {
- queue.emplace_back(ModuleElementKind::Function, curr->target);
+ void maybeAdd(ModuleElement element) {
+ if (reachable.count(element) == 0) {
+ queue.emplace_back(element);
}
}
+
+ void visitCall(Call* curr) {
+ maybeAdd(ModuleElement(ModuleElementKind::Function, curr->target));
+ }
void visitCallIndirect(CallIndirect* curr) {
assert(!module->tables.empty() && "call-indirect to undefined table.");
- if (reachable.count(ModuleElement(ModuleElementKind::Table, curr->table)) ==
- 0) {
- queue.emplace_back(ModuleElementKind::Table, curr->table);
- }
+ maybeAdd(ModuleElement(ModuleElementKind::Table, curr->table));
}
void visitGlobalGet(GlobalGet* curr) {
- if (reachable.count(ModuleElement(ModuleElementKind::Global, curr->name)) ==
- 0) {
- queue.emplace_back(ModuleElementKind::Global, curr->name);
- }
+ maybeAdd(ModuleElement(ModuleElementKind::Global, curr->name));
}
void visitGlobalSet(GlobalSet* curr) {
- if (reachable.count(ModuleElement(ModuleElementKind::Global, curr->name)) ==
- 0) {
- queue.emplace_back(ModuleElementKind::Global, curr->name);
- }
+ maybeAdd(ModuleElement(ModuleElementKind::Global, curr->name));
}
void visitLoad(Load* curr) { usesMemory = true; }
@@ -127,15 +121,14 @@ struct ReachabilityAnalyzer : public PostWalker<ReachabilityAnalyzer> {
void visitMemorySize(MemorySize* curr) { usesMemory = true; }
void visitMemoryGrow(MemoryGrow* curr) { usesMemory = true; }
void visitRefFunc(RefFunc* curr) {
- if (reachable.count(
- ModuleElement(ModuleElementKind::Function, curr->func)) == 0) {
- queue.emplace_back(ModuleElementKind::Function, curr->func);
- }
+ maybeAdd(ModuleElement(ModuleElementKind::Function, curr->func));
}
void visitThrow(Throw* curr) {
- if (reachable.count(ModuleElement(ModuleElementKind::Event, curr->event)) ==
- 0) {
- queue.emplace_back(ModuleElementKind::Event, curr->event);
+ maybeAdd(ModuleElement(ModuleElementKind::Event, curr->event));
+ }
+ void visitTry(Try* curr) {
+ for (auto event : curr->catchEvents) {
+ maybeAdd(ModuleElement(ModuleElementKind::Event, event));
}
}
};