diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-05-19 16:13:08 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-05-19 16:13:08 -0700 |
commit | 579010855a134a78cab8ed129cbbbe52bd52a380 (patch) | |
tree | 7b9da5de9331ccc2f6084209e136701a80026138 | |
parent | fe1bda7da797e5586d39122aec931a8a84df4ac7 (diff) | |
download | binaryen-579010855a134a78cab8ed129cbbbe52bd52a380.tar.gz binaryen-579010855a134a78cab8ed129cbbbe52bd52a380.tar.bz2 binaryen-579010855a134a78cab8ed129cbbbe52bd52a380.zip |
vacuum the top of functions too
-rw-r--r-- | src/passes/Vacuum.cpp | 12 | ||||
-rw-r--r-- | test/passes/vacuum.txt | 6 | ||||
-rw-r--r-- | test/passes/vacuum.wast | 7 | ||||
-rw-r--r-- | test/unit.fromasm | 21 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise | 21 |
5 files changed, 33 insertions, 34 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 6d6f1490a..1524927ec 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -212,6 +212,18 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum, Visitor<Vacuum>>> { self->pushTask(visitPre, currp); } + + void visitFunction(Function* curr) { + auto* optimized = optimize(curr->body, curr->result != none); + if (optimized) { + curr->body = optimized; + } else { + ExpressionManipulator::nop(curr->body); + } + if (curr->result == none && !EffectAnalyzer(curr->body).hasSideEffects()) { + ExpressionManipulator::nop(curr->body); + } + } }; static RegisterPass<Vacuum> registerPass("vacuum", "removes obviously unneeded code"); diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt index cfe2766c8..fb3731dba 100644 --- a/test/passes/vacuum.txt +++ b/test/passes/vacuum.txt @@ -111,4 +111,10 @@ (unreachable) ) ) + (func $recurse + (nop) + ) + (func $func-block + (nop) + ) ) diff --git a/test/passes/vacuum.wast b/test/passes/vacuum.wast index e2e717807..fb6125e52 100644 --- a/test/passes/vacuum.wast +++ b/test/passes/vacuum.wast @@ -117,5 +117,12 @@ (unreachable) ) ) + (func $recurse + (nop) + (f32.abs (f32.abs (f32.abs (f32.abs (f32.abs (f32.abs (f32.const 1.0) ) ) ) ) ) ) + ) + (func $func-block + (f32.abs (f32.abs (f32.abs (f32.abs (f32.abs (f32.abs (f32.const 1.0) ) ) ) ) ) ) + ) ) diff --git a/test/unit.fromasm b/test/unit.fromasm index a3a4dd189..669aa33d9 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -88,13 +88,7 @@ ) ) (func $hexLiterals - (i32.add - (i32.add - (i32.const 0) - (i32.const 313249263) - ) - (i32.const -19088752) - ) + (nop) ) (func $conversions (local $0 i32) @@ -112,10 +106,7 @@ ) ) (func $seq - (f64.sub - (f64.const 5.1) - (f64.const 4.2) - ) + (nop) ) (func $switcher (param $0 i32) (result i32) (block $switch-default$3 @@ -239,7 +230,7 @@ (f64.const -0) ) (func $abs - (i32.const 0) + (nop) ) (func $neg (local $0 f32) @@ -269,11 +260,7 @@ ) ) (func $___syscall_ret - (local $0 i32) - (i32.gt_u - (get_local $0) - (i32.const -4096) - ) + (nop) ) (func $smallCompare (result i32) (local $0 i32) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index b8e781f09..240cc0bd5 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -86,13 +86,7 @@ ) ) (func $hexLiterals - (i32.add - (i32.add - (i32.const 0) - (i32.const 313249263) - ) - (i32.const -19088752) - ) + (nop) ) (func $conversions (local $0 i32) @@ -104,10 +98,7 @@ ) ) (func $seq - (f64.sub - (f64.const 5.1) - (f64.const 4.2) - ) + (nop) ) (func $switcher (param $0 i32) (result i32) (block $switch-default$3 @@ -231,7 +222,7 @@ (f64.const -0) ) (func $abs - (i32.const 0) + (nop) ) (func $neg (local $0 f32) @@ -261,11 +252,7 @@ ) ) (func $___syscall_ret - (local $0 i32) - (i32.gt_u - (get_local $0) - (i32.const -4096) - ) + (nop) ) (func $smallCompare (result i32) (local $0 i32) |