summaryrefslogtreecommitdiff
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
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.
-rw-r--r--src/passes/RemoveUnusedModuleElements.cpp39
-rw-r--r--test/passes/remove-unused-module-elements_all-features.txt3
2 files changed, 18 insertions, 24 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));
}
}
};
diff --git a/test/passes/remove-unused-module-elements_all-features.txt b/test/passes/remove-unused-module-elements_all-features.txt
index fdd768e8b..96fbb8c99 100644
--- a/test/passes/remove-unused-module-elements_all-features.txt
+++ b/test/passes/remove-unused-module-elements_all-features.txt
@@ -291,11 +291,12 @@
)
)
(module
- (type $none_=>_none (func))
(type $i32_=>_none (func (param i32)))
+ (type $none_=>_none (func))
(type $i64_=>_none (func (param i64)))
(event $e-export (attr 0) (param i64))
(event $e-throw (attr 0) (param i32))
+ (event $e-catch (attr 0) (param i32))
(export "e-export" (event $e-export))
(start $start)
(func $start