summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2021-10-14 15:42:55 -0700
committerGitHub <noreply@github.com>2021-10-14 15:42:55 -0700
commit0a1ac51b1e7e88f0ce89793c71333bb8bc7335d0 (patch)
tree3e42e4162b94fe537ca0260e236044d80c9ac06c
parentbf665976b1526ca7cf11bacf5745563dfe193206 (diff)
downloadbinaryen-0a1ac51b1e7e88f0ce89793c71333bb8bc7335d0.tar.gz
binaryen-0a1ac51b1e7e88f0ce89793c71333bb8bc7335d0.tar.bz2
binaryen-0a1ac51b1e7e88f0ce89793c71333bb8bc7335d0.zip
[wasm-metadce] Add support for tags (#4250)
This adds support for tag-using instructions (`throw` and `catch`) to wasm-metadce. We had to use a hacky workaround in emscripten-core/emscripten#15266 because of the lack of this support; after this lands we can remove it.
-rw-r--r--src/tools/wasm-metadce.cpp17
-rw-r--r--test/metadce/tag.wast14
-rw-r--r--test/metadce/tag.wast.dced16
-rw-r--r--test/metadce/tag.wast.dced.stdout0
-rw-r--r--test/metadce/tag.wast.graph.txt11
5 files changed, 58 insertions, 0 deletions
diff --git a/src/tools/wasm-metadce.cpp b/src/tools/wasm-metadce.cpp
index 23a2d0fcc..00fa87ce2 100644
--- a/src/tools/wasm-metadce.cpp
+++ b/src/tools/wasm-metadce.cpp
@@ -263,6 +263,12 @@ struct MetaDCEGraph {
}
void visitGlobalGet(GlobalGet* curr) { handleGlobal(curr->name); }
void visitGlobalSet(GlobalSet* curr) { handleGlobal(curr->name); }
+ void visitThrow(Throw* curr) { handleTag(curr->tag); }
+ void visitTry(Try* curr) {
+ for (auto tag : curr->catchTags) {
+ handleTag(tag);
+ }
+ }
private:
MetaDCEGraph* parent;
@@ -282,6 +288,17 @@ struct MetaDCEGraph {
parent->nodes[parent->functionToDCENode[getFunction()->name]]
.reaches.push_back(dceName);
}
+
+ void handleTag(Name name) {
+ Name dceName;
+ if (!getModule()->getTag(name)->imported()) {
+ dceName = parent->tagToDCENode[name];
+ } else {
+ dceName = parent->importIdToDCENode[parent->getTagImportId(name)];
+ }
+ parent->nodes[parent->functionToDCENode[getFunction()->name]]
+ .reaches.push_back(dceName);
+ }
};
PassRunner runner(&wasm);
diff --git a/test/metadce/tag.wast b/test/metadce/tag.wast
new file mode 100644
index 000000000..527e57d33
--- /dev/null
+++ b/test/metadce/tag.wast
@@ -0,0 +1,14 @@
+(module
+ (import "env" "imported_tag" (tag $t0))
+ (tag $t1)
+ (export "test" (func $test))
+
+ (func $test
+ (try
+ (do
+ (throw $t0)
+ )
+ (catch $t1)
+ )
+ )
+)
diff --git a/test/metadce/tag.wast.dced b/test/metadce/tag.wast.dced
new file mode 100644
index 000000000..78ae287f1
--- /dev/null
+++ b/test/metadce/tag.wast.dced
@@ -0,0 +1,16 @@
+(module
+ (type $none_=>_none (func))
+ (import "env" "imported_tag" (tag $t0 (param)))
+ (tag $t1 (param))
+ (export "test" (func $test))
+ (func $test
+ (try $try
+ (do
+ (throw $t0)
+ )
+ (catch $t1
+ (nop)
+ )
+ )
+ )
+)
diff --git a/test/metadce/tag.wast.dced.stdout b/test/metadce/tag.wast.dced.stdout
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/metadce/tag.wast.dced.stdout
diff --git a/test/metadce/tag.wast.graph.txt b/test/metadce/tag.wast.graph.txt
new file mode 100644
index 000000000..34a2d1fdf
--- /dev/null
+++ b/test/metadce/tag.wast.graph.txt
@@ -0,0 +1,11 @@
+[
+ {
+ "name": "tag_import",
+ "import": ["env", "imported_tag"]
+ },
+ {
+ "name": "func_export",
+ "root": true,
+ "export": "test"
+ }
+]