diff options
author | Alon Zakai <azakai@google.com> | 2023-11-30 15:16:52 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 15:16:52 -0800 |
commit | 42cddbf88ebe74d17490e2dd13826e6da9104b15 (patch) | |
tree | c0712b1baf3d03f62bd1d6f5372e2ccb6ebdcf69 /test | |
parent | a191d66fce93829e7365f7f2f4be2799c62a1ee4 (diff) | |
download | binaryen-42cddbf88ebe74d17490e2dd13826e6da9104b15.tar.gz binaryen-42cddbf88ebe74d17490e2dd13826e6da9104b15.tar.bz2 binaryen-42cddbf88ebe74d17490e2dd13826e6da9104b15.zip |
wasm-metadce all the things (#6142)
Remove hardcoded paths for globals/functions/etc. in favor of general code
paths that support all the module elements uniformly. As a result of that, we
now support all parts of wasm, such as tables and element segments, that
we didn't before.
This refactoring is NFC aside from adding functionality. Note that this reduces
the size of wasm-metadce by 10% while increasing its functionality - the
benefits of writing generic code.
To support this, add some trivial generic helpers to get or iterate over module
elements using their kind in a dynamic manner. Using them might make
wasm-metadce slightly slower, but I can't measure any difference.
Diffstat (limited to 'test')
-rw-r--r-- | test/metadce/table.wast | 30 | ||||
-rw-r--r-- | test/metadce/table.wast.dced | 21 | ||||
-rw-r--r-- | test/metadce/table.wast.dced.stdout | 2 | ||||
-rw-r--r-- | test/metadce/table.wast.graph.txt | 7 |
4 files changed, 60 insertions, 0 deletions
diff --git a/test/metadce/table.wast b/test/metadce/table.wast new file mode 100644 index 000000000..d1ee93ae4 --- /dev/null +++ b/test/metadce/table.wast @@ -0,0 +1,30 @@ +(module + (type $array (array (mut funcref))) + + (table $table-used 10 funcref) + + (table $table-unused 10 funcref) + + ;; An active element segment, which is always used. + (elem $elem (table $table-used) (i32.const 0) $func) + + (elem $passive-elem-used $func) + + (elem $passive-elem-unused $func) + + (func $func (export "test") + ;; Use the used table and passive element segment. + (table.fill $table-used + (i32.const 0) + (ref.func $func) + (i32.const 0) + ) + (drop + (array.new_elem $array $passive-elem-used + (i32.const 0) + (i32.const 1) + ) + ) + ) +) + diff --git a/test/metadce/table.wast.dced b/test/metadce/table.wast.dced new file mode 100644 index 000000000..b779fee9d --- /dev/null +++ b/test/metadce/table.wast.dced @@ -0,0 +1,21 @@ +(module + (type $0 (func)) + (type $array (array (mut funcref))) + (table $table-used 10 funcref) + (elem $elem (i32.const 0) $func) + (elem $passive-elem-used func $func) + (export "test" (func $func)) + (func $func (type $0) + (table.fill $table-used + (i32.const 0) + (ref.func $func) + (i32.const 0) + ) + (drop + (array.new_elem $array $passive-elem-used + (i32.const 0) + (i32.const 1) + ) + ) + ) +) diff --git a/test/metadce/table.wast.dced.stdout b/test/metadce/table.wast.dced.stdout new file mode 100644 index 000000000..064b9406c --- /dev/null +++ b/test/metadce/table.wast.dced.stdout @@ -0,0 +1,2 @@ +unused: eseg$passive-elem-unused +unused: table$table-unused diff --git a/test/metadce/table.wast.graph.txt b/test/metadce/table.wast.graph.txt new file mode 100644 index 000000000..1da066ae7 --- /dev/null +++ b/test/metadce/table.wast.graph.txt @@ -0,0 +1,7 @@ +[ + { + "name": "func_export", + "root": true, + "export": "test" + } +] |