summaryrefslogtreecommitdiff
path: root/test/metadce
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-12-07 21:33:47 -0800
committerGitHub <noreply@github.com>2017-12-07 21:33:47 -0800
commit9c51f2b51ecc57dfad1478bbc6932ec2795b1374 (patch)
treeb0ded3086e10dd776fa20d8a4b45e2fb54b60a8e /test/metadce
parent22f1ce86e48173e9e55a021350c1ec9ca046080f (diff)
downloadbinaryen-9c51f2b51ecc57dfad1478bbc6932ec2795b1374.tar.gz
binaryen-9c51f2b51ecc57dfad1478bbc6932ec2795b1374.tar.bz2
binaryen-9c51f2b51ecc57dfad1478bbc6932ec2795b1374.zip
metadce fixes (#1329)
* ignore missing imports (the wasm may have already had them optimized out) * handle segments that hold on to globals (root them, for now, as we can't remove segments) * run reorder-functions, as the optimal order may have changed after we dce * fix global, global init, and segment offset reachability * fix import rooting and processing - imports may be imported more than once
Diffstat (limited to 'test/metadce')
-rw-r--r--test/metadce/corners.wast23
-rw-r--r--test/metadce/corners.wast.dced17
-rw-r--r--test/metadce/corners.wast.dced.stdout2
-rw-r--r--test/metadce/corners.wast.graph.txt16
-rw-r--r--test/metadce/no-outside.wast.dced.stdout2
-rw-r--r--test/metadce/outside.wast.dced8
-rw-r--r--test/metadce/outside.wast.dced.stdout7
-rw-r--r--test/metadce/threaded.wast.dced16
-rw-r--r--test/metadce/threaded_cycle.wast.dced16
9 files changed, 79 insertions, 28 deletions
diff --git a/test/metadce/corners.wast b/test/metadce/corners.wast
new file mode 100644
index 000000000..1005a781b
--- /dev/null
+++ b/test/metadce/corners.wast
@@ -0,0 +1,23 @@
+(module
+ (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32))
+ (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import))
+
+ (import "env" "UNUSEDTOP" (global $UNUSEDTOP$asm2wasm$import i32))
+ (global $UNUSEDTOP (mut i32) (get_global $UNUSEDTOP$asm2wasm$import))
+
+ (import "env" "imported_twice" (func $imported_twice_a)) ;; and used just once,
+ (import "env" "imported_twice" (func $imported_twice_b)) ;; but the other should not kill the import for both!
+
+ (import "env" "an-imported-table-func" (func $imported_table_func))
+
+ (import "env" "table" (table 10 10 anyfunc))
+ (elem (i32.const 0) $imported_table_func)
+
+ (export "stackAlloc" (func $stackAlloc))
+
+ (func $stackAlloc
+ (drop (get_global $STACKTOP))
+ (call $imported_twice_a)
+ )
+)
+
diff --git a/test/metadce/corners.wast.dced b/test/metadce/corners.wast.dced
new file mode 100644
index 000000000..cf6346877
--- /dev/null
+++ b/test/metadce/corners.wast.dced
@@ -0,0 +1,17 @@
+(module
+ (type $FUNCSIG$v (func))
+ (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32))
+ (import "env" "imported_twice" (func $imported_twice_a))
+ (import "env" "an-imported-table-func" (func $imported_table_func))
+ (import "env" "table" (table 10 10 anyfunc))
+ (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import))
+ (elem (i32.const 0) $imported_table_func)
+ (memory $0 0)
+ (export "stackAlloc" (func $stackAlloc))
+ (func $stackAlloc (; 2 ;) (type $FUNCSIG$v)
+ (drop
+ (get_global $STACKTOP)
+ )
+ (call $imported_twice_a)
+ )
+)
diff --git a/test/metadce/corners.wast.dced.stdout b/test/metadce/corners.wast.dced.stdout
new file mode 100644
index 000000000..2c8983d24
--- /dev/null
+++ b/test/metadce/corners.wast.dced.stdout
@@ -0,0 +1,2 @@
+unused: global$UNUSEDTOP$2
+unused: ignorable import
diff --git a/test/metadce/corners.wast.graph.txt b/test/metadce/corners.wast.graph.txt
new file mode 100644
index 000000000..60c2bc4ff
--- /dev/null
+++ b/test/metadce/corners.wast.graph.txt
@@ -0,0 +1,16 @@
+[
+ {
+ "name": "ignorable import",
+ "import": ["non", "existent"]
+ },
+ {
+ "name": "imported_twice",
+ "import": ["env", "imported_twice"]
+ },
+ {
+ "name": "stackAllocGood",
+ "export": "stackAlloc",
+ "root": true
+ }
+]
+
diff --git a/test/metadce/no-outside.wast.dced.stdout b/test/metadce/no-outside.wast.dced.stdout
index 32ed99f0e..cb849efbb 100644
--- a/test/metadce/no-outside.wast.dced.stdout
+++ b/test/metadce/no-outside.wast.dced.stdout
@@ -2,5 +2,3 @@ unused: export$wasm_func$4
unused: export$wasm_func_unused$5
unused: func$a_wasm_func$0
unused: func$an_unused_wasm_func$1
-unused: import$a_js_func$2
-unused: import$an_unused_js_func$3
diff --git a/test/metadce/outside.wast.dced b/test/metadce/outside.wast.dced
index 083be0dda..087906b58 100644
--- a/test/metadce/outside.wast.dced
+++ b/test/metadce/outside.wast.dced
@@ -11,7 +11,10 @@
(data (i32.const 1024) "abcd")
(data (get_global $from_segment) "abcd")
(export "wasm_func" (func $a_wasm_func))
- (func $a_wasm_func (; 1 ;) (type $FUNCSIG$v)
+ (func $table_func (; 1 ;) (type $FUNCSIG$v)
+ (nop)
+ )
+ (func $a_wasm_func (; 2 ;) (type $FUNCSIG$v)
(call $a_js_func)
(drop
(get_global $DYNAMICTOP_PTR$asm2wasm$import)
@@ -20,7 +23,4 @@
(get_global $__THREW__)
)
)
- (func $table_func (; 2 ;) (type $FUNCSIG$v)
- (nop)
- )
)
diff --git a/test/metadce/outside.wast.dced.stdout b/test/metadce/outside.wast.dced.stdout
index ed95ab195..6095ebf6a 100644
--- a/test/metadce/outside.wast.dced.stdout
+++ b/test/metadce/outside.wast.dced.stdout
@@ -1,11 +1,6 @@
-unused: export$wasm_func_unused$14
+unused: export$wasm_func_unused$12
unused: func$an_unused_wasm_func$1
-unused: global$__THREW__$3
unused: global$__THREW__unused$4
unused: global$from_segment$5
unused: global$from_segment_2$6
unused: global$from_segment_never_used$7
-unused: import$0$12
-unused: import$DYNAMICTOP_PTR$asm2wasm$import_unused$11
-unused: import$an_unused_js_func$9
-unused: import$import$table$0$13
diff --git a/test/metadce/threaded.wast.dced b/test/metadce/threaded.wast.dced
index 5e26e4666..1122cb536 100644
--- a/test/metadce/threaded.wast.dced
+++ b/test/metadce/threaded.wast.dced
@@ -8,16 +8,16 @@
(export "wasm_func2" (func $wasm_func_2))
(export "wasm_func3" (func $wasm_func_3))
(export "wasm_func4" (func $wasm_func_4))
- (func $wasm_func_1 (; 3 ;) (type $FUNCSIG$v)
- (call $js_func_2)
- )
- (func $wasm_func_2 (; 4 ;) (type $FUNCSIG$v)
- (call $js_func_3)
+ (func $wasm_func_4 (; 3 ;) (type $FUNCSIG$v)
+ (nop)
)
- (func $wasm_func_3 (; 5 ;) (type $FUNCSIG$v)
+ (func $wasm_func_3 (; 4 ;) (type $FUNCSIG$v)
(call $js_func_4)
)
- (func $wasm_func_4 (; 6 ;) (type $FUNCSIG$v)
- (nop)
+ (func $wasm_func_2 (; 5 ;) (type $FUNCSIG$v)
+ (call $js_func_3)
+ )
+ (func $wasm_func_1 (; 6 ;) (type $FUNCSIG$v)
+ (call $js_func_2)
)
)
diff --git a/test/metadce/threaded_cycle.wast.dced b/test/metadce/threaded_cycle.wast.dced
index 91b5b45e0..b73266fcc 100644
--- a/test/metadce/threaded_cycle.wast.dced
+++ b/test/metadce/threaded_cycle.wast.dced
@@ -9,16 +9,16 @@
(export "wasm_func2" (func $wasm_func_2))
(export "wasm_func3" (func $wasm_func_3))
(export "wasm_func4" (func $wasm_func_4))
- (func $wasm_func_1 (; 4 ;) (type $FUNCSIG$v)
- (call $js_func_2)
- )
- (func $wasm_func_2 (; 5 ;) (type $FUNCSIG$v)
- (call $js_func_3)
+ (func $wasm_func_4 (; 4 ;) (type $FUNCSIG$v)
+ (call $js_func_1)
)
- (func $wasm_func_3 (; 6 ;) (type $FUNCSIG$v)
+ (func $wasm_func_3 (; 5 ;) (type $FUNCSIG$v)
(call $js_func_4)
)
- (func $wasm_func_4 (; 7 ;) (type $FUNCSIG$v)
- (call $js_func_1)
+ (func $wasm_func_2 (; 6 ;) (type $FUNCSIG$v)
+ (call $js_func_3)
+ )
+ (func $wasm_func_1 (; 7 ;) (type $FUNCSIG$v)
+ (call $js_func_2)
)
)