summaryrefslogtreecommitdiff
path: root/test/unit/test_stack_ir.py
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-11-26 15:22:04 -0800
committerGitHub <noreply@github.com>2019-11-26 15:22:04 -0800
commitec53d11e0792884e1125fe5a1a437a5eff260259 (patch)
tree0ebeab40cade82309507aceab7f810e9a37929fb /test/unit/test_stack_ir.py
parent7665f703f4e3437564be25ae276e1daaedd98d79 (diff)
downloadbinaryen-ec53d11e0792884e1125fe5a1a437a5eff260259.tar.gz
binaryen-ec53d11e0792884e1125fe5a1a437a5eff260259.tar.bz2
binaryen-ec53d11e0792884e1125fe5a1a437a5eff260259.zip
Refactor and optimize binary writing type collection (#2478)
Create a new ParallelFunctionAnalysis helper, which lets us run in parallel on all functions and collect info from them, without manually handling locks etc. Use that in the binary writing code's type collection logic, avoiding a lock for each type increment. Also add Signature printing which was useful to debug this.
Diffstat (limited to 'test/unit/test_stack_ir.py')
-rw-r--r--test/unit/test_stack_ir.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/unit/test_stack_ir.py b/test/unit/test_stack_ir.py
new file mode 100644
index 000000000..1fcab88d8
--- /dev/null
+++ b/test/unit/test_stack_ir.py
@@ -0,0 +1,19 @@
+import os
+from scripts.test import shared
+from . import utils
+
+
+class StackIRTest(utils.BinaryenTestCase):
+ # test that stack IR opts make a difference.
+ def test_stack_ir_opts(self):
+ path = self.input_path('stack_ir.wast')
+ opt = shared.run_process(shared.WASM_OPT + [path, '-O', '--generate-stack-ir', '--optimize-stack-ir', '--print-stack-ir', '-o', 'a.wasm'], capture_output=True).stdout
+ nonopt = shared.run_process(shared.WASM_OPT + [path, '-O', '--generate-stack-ir', '--print-stack-ir', '-o', 'b.wasm'], capture_output=True).stdout
+ # see a difference in the printed stack IR (the optimizations let us
+ # remove a pair of local.set/get)
+ self.assertNotEqual(opt, nonopt)
+ self.assertLess(len(opt), len(nonopt))
+ # see a difference in the actual emitted wasm binary.
+ opt_size = os.path.getsize('a.wasm')
+ nonopt_size = os.path.getsize('b.wasm')
+ self.assertLess(opt_size, nonopt_size)