summaryrefslogtreecommitdiff
path: root/test/metadce/outside.wast.dced
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-12-06 14:23:14 -0800
committerGitHub <noreply@github.com>2017-12-06 14:23:14 -0800
commit0571fe31c8a5f91d962fa435ea2f9507d2339280 (patch)
tree66826fbf2e7ab7e1f2af73bc549a9ccea71117d8 /test/metadce/outside.wast.dced
parentb7f0a896efc12bb72b40bdaf19986736ccb9315a (diff)
downloadbinaryen-0571fe31c8a5f91d962fa435ea2f9507d2339280.tar.gz
binaryen-0571fe31c8a5f91d962fa435ea2f9507d2339280.tar.bz2
binaryen-0571fe31c8a5f91d962fa435ea2f9507d2339280.zip
wasm-metadce tool (#1320)
This adds a new tool for better dead code elimination. The problem this helps overcome is when the wasm module is part of something larger, like a wasm+JS combination, and therefore doing DCE in either one is not sufficient as it can't remove a cycle spanning the wasm and JS worlds. Concretely, when binaryen performs DCE by itself, it can never remove an export, because it considers those roots - but in the larger ("meta") space outside, they may actually be removable. To solve that, this tool receives a description of the outside graph (in very abstract form), including which nodes are roots. It then adds to that graph nodes from the wasm, so that we have a single graph representing the entire space (the outside + wasm + connections between them). It then performs DCE, finding what is not reachable from the roots, and cleaning it up from the wasm. It of course can't clean up things from the outside, since all it has is the abstract representation of those things in the graph, but it prints out the ids of the removable nodes, which an outside tool can use. This tool is written in as general a way as possible, hopefully it can have multiple uses. The use I have in mind is to write something in emscripten that uses this to DCE the JS+wasm combination that we emit.
Diffstat (limited to 'test/metadce/outside.wast.dced')
-rw-r--r--test/metadce/outside.wast.dced26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/metadce/outside.wast.dced b/test/metadce/outside.wast.dced
new file mode 100644
index 000000000..083be0dda
--- /dev/null
+++ b/test/metadce/outside.wast.dced
@@ -0,0 +1,26 @@
+(module
+ (type $FUNCSIG$v (func))
+ (import "env" "js_func" (func $a_js_func))
+ (import "env" "DYNAMICTOP_PTR" (global $DYNAMICTOP_PTR$asm2wasm$import i32))
+ (import "env" "memory" (memory $0 256 256))
+ (import "env" "table" (table 10 10 anyfunc))
+ (global $__THREW__ (mut i32) (i32.const 0))
+ (global $from_segment (mut i32) (i32.const 0))
+ (global $from_segment_2 (mut i32) (i32.const 0))
+ (elem (get_global $from_segment_2) $table_func)
+ (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)
+ (call $a_js_func)
+ (drop
+ (get_global $DYNAMICTOP_PTR$asm2wasm$import)
+ )
+ (drop
+ (get_global $__THREW__)
+ )
+ )
+ (func $table_func (; 2 ;) (type $FUNCSIG$v)
+ (nop)
+ )
+)