diff --git a/auto_update_tests.py b/auto_update_tests.py index 6f86bc1fec4..0a42d8357b1 100755 --- a/auto_update_tests.py +++ b/auto_update_tests.py @@ -67,7 +67,8 @@ if t.endswith('.wast'): print '..', t passname = os.path.basename(t).replace('.wast', '') - cmd = [os.path.join('bin', 'binaryen-shell'), ('--' + passname if passname != 'O' else '-O'), os.path.join('test', 'passes', t), '--print'] + opts = ['-O'] if passname == 'O' else ['--' + p for p in passname.split('_')] + cmd = [os.path.join('bin', 'binaryen-shell')] + opts + [os.path.join('test', 'passes', t), '--print'] print ' ', ' '.join(cmd) actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() open(os.path.join('test', 'passes', passname + '.txt'), 'w').write(actual) diff --git a/check.py b/check.py index c0733cb6c90..722371f2a35 100755 --- a/check.py +++ b/check.py @@ -276,8 +276,8 @@ def minify_check(wast, verify_final_result=True): if t.endswith('.wast'): print '..', t passname = os.path.basename(t).replace('.wast', '') - opt = '-O' if passname == 'O' else '--' + passname - cmd = [os.path.join('bin', 'binaryen-shell'), opt, os.path.join('test', 'passes', t), '--print'] + opts = ['-O'] if passname == 'O' else ['--' + p for p in passname.split('_')] + cmd = [os.path.join('bin', 'binaryen-shell')] + opts + [os.path.join('test', 'passes', t), '--print'] actual = run_command(cmd) fail_if_not_identical(actual, open(os.path.join('test', 'passes', passname + '.txt')).read()) diff --git a/src/passes/MergeBlocks.cpp b/src/passes/MergeBlocks.cpp index 5794e1379ca..7b9723b0bb5 100644 --- a/src/passes/MergeBlocks.cpp +++ b/src/passes/MergeBlocks.cpp @@ -100,7 +100,7 @@ struct MergeBlocks : public WalkerPassdynCast()) { - if (block->list.size() >= 2) { + if (!block->name.is() && block->list.size() >= 2) { child = block->list.back(); if (outer == nullptr) { // reuse the block, move it out diff --git a/test/passes/merge-blocks.txt b/test/passes/merge-blocks.txt deleted file mode 100644 index f5d772c7495..00000000000 --- a/test/passes/merge-blocks.txt +++ /dev/null @@ -1,537 +0,0 @@ -(module - (memory 256 256) - (type $i (func (param i32))) - (type $ii (func (param i32 i32))) - (type $iii (func (param i32 i32 i32))) - (table $call-i) - (func $call-i (param $0 i32) - (nop) - ) - (func $call-ii (param $0 i32) (param $1 i32) - (nop) - ) - (func $call-iii (param $0 i32) (param $1 i32) (param $2 i32) - (nop) - ) - (func $b0-yes (param $i1 i32) - (block $topmost - (block $block0 - (i32.const 10) - ) - ) - ) - (func $b1-yes (param $i1 i32) - (block $topmost - (block $block0 - (block $block1 - (i32.const 10) - ) - ) - ) - ) - (func $b2-yes (param $i1 i32) - (block $topmost - (i32.const 5) - (block $block0 - (i32.const 10) - ) - (i32.const 15) - ) - ) - (func $b3-yes (param $i1 i32) - (block $topmost - (i32.const 3) - (block $block0 - (i32.const 6) - (block $block1 - (i32.const 10) - ) - (i32.const 15) - ) - (i32.const 20) - ) - ) - (func $b4 (param $i1 i32) - (block $topmost - (block $inner - (i32.const 10) - (br $inner) - ) - ) - ) - (func $b5 (param $i1 i32) - (block $topmost - (block $middle - (block $inner - (i32.const 10) - (br $inner) - ) - (br $middle) - ) - ) - ) - (func $b6 (param $i1 i32) - (block $topmost - (i32.const 5) - (block $inner - (i32.const 10) - (br $inner) - ) - (i32.const 15) - ) - ) - (func $b7 (param $i1 i32) - (block $topmost - (i32.const 3) - (block $middle - (i32.const 6) - (block $inner - (i32.const 10) - (br $inner) - ) - (i32.const 15) - (br $middle) - ) - (i32.const 20) - ) - ) - (func $unary - (local $x i32) - (i32.eqz - (block $block0 - (i32.const 10) - ) - ) - (block $block1 - (i32.const 10) - (i32.eqz - (i32.const 20) - ) - ) - (block $block2 - (i32.const 10) - (i32.const 20) - (i32.eqz - (i32.const 30) - ) - ) - (block $block3 - (i32.const 10) - (set_local $x - (i32.const 20) - ) - ) - (block $block4 - (i32.const 10) - (i32.load - (i32.const 20) - ) - ) - (block $block5 - (i32.const 10) - (return - (unreachable) - ) - ) - ) - (func $binary - (i32.add - (block $block0 - (i32.const 10) - ) - (i32.const 20) - ) - (block $block1 - (i32.const 10) - (i32.add - (i32.const 20) - (i32.const 30) - ) - ) - (block $block2 - (i32.const 10) - (i32.const 20) - (i32.add - (i32.const 30) - (i32.const 40) - ) - ) - (i32.add - (i32.const 10) - (block $block3 - (i32.const 20) - ) - ) - (block $block4 - (i32.const 20) - (i32.add - (i32.const 10) - (i32.const 30) - ) - ) - (block $block5 - (i32.const 20) - (i32.const 30) - (i32.add - (i32.const 10) - (i32.const 40) - ) - ) - (i32.add - (block $block6 - (i32.const 10) - ) - (block $block7 - (i32.const 20) - ) - ) - (block $block8 - (i32.const 10) - (i32.const 30) - (i32.add - (i32.const 20) - (i32.const 40) - ) - ) - (block $block10 - (i32.const 10) - (i32.const 20) - (i32.const 40) - (i32.const 50) - (i32.add - (i32.const 30) - (i32.const 60) - ) - ) - (block $block12 - (i32.const 20) - (i32.store - (i32.const 10) - (i32.const 30) - ) - ) - (block $block13 - (i32.const 10) - (i32.store - (i32.const 20) - (i32.const 30) - ) - ) - (i32.add - (unreachable) - (block $block14 - (i32.const 10) - (i32.const 20) - ) - ) - (block $block15 - (unreachable) - (i32.const 20) - (i32.add - (i32.const 10) - (i32.const 30) - ) - ) - ) - (func $trinary - (block $block0 - (i32.const 10) - (i32.const 30) - (i32.const 50) - (select - (i32.const 20) - (i32.const 40) - (i32.const 60) - ) - ) - (block $block4 - (i32.const 20) - (i32.const 40) - (select - (block $block3 - (i32.const 10) - ) - (i32.const 30) - (i32.const 50) - ) - ) - (block $block6 - (i32.const 10) - (i32.const 40) - (select - (i32.const 20) - (block $block7 - (i32.const 30) - ) - (i32.const 50) - ) - ) - (block $block9 - (i32.const 10) - (i32.const 30) - (select - (i32.const 20) - (i32.const 40) - (block $block11 - (i32.const 50) - ) - ) - ) - (block $block14 - (i32.const 30) - (select - (block $block12 - (i32.const 10) - ) - (block $block13 - (i32.const 20) - ) - (i32.const 40) - ) - ) - (block $block16 - (i32.const 20) - (select - (block $block15 - (i32.const 10) - ) - (i32.const 30) - (block $block17 - (i32.const 40) - ) - ) - ) - (block $block18 - (i32.const 10) - (select - (i32.const 20) - (block $block19 - (i32.const 30) - ) - (block $block20 - (i32.const 40) - ) - ) - ) - (block $block21 - (unreachable) - (i32.const 30) - (i32.const 50) - (select - (i32.const 20) - (i32.const 40) - (i32.const 60) - ) - ) - (block $block24 - (i32.const 10) - (select - (unreachable) - (block $block25 - (i32.const 30) - (i32.const 40) - ) - (block $block26 - (i32.const 50) - (i32.const 60) - ) - ) - ) - (block $block27 - (i32.const 10) - (unreachable) - (i32.const 50) - (select - (i32.const 20) - (i32.const 40) - (i32.const 60) - ) - ) - (block $block30 - (i32.const 10) - (i32.const 30) - (select - (i32.const 20) - (unreachable) - (block $block32 - (i32.const 50) - (i32.const 60) - ) - ) - ) - (block $block33 - (i32.const 10) - (i32.const 30) - (unreachable) - (select - (i32.const 20) - (i32.const 40) - (i32.const 60) - ) - ) - (block $block36 - (i32.const 10) - (i32.const 30) - (i32.const 50) - (select - (i32.const 20) - (i32.const 40) - (unreachable) - ) - ) - ) - (func $breaks - (block $out - (block $block0 - (i32.const 10) - (br $out - (i32.const 20) - ) - ) - (block $block1 - (i32.const 10) - (br_if $out - (i32.const 20) - ) - ) - (block $block2 - (i32.const 10) - (i32.const 30) - (br_if $out - (i32.const 20) - (i32.const 40) - ) - ) - (block $block4 - (i32.const 10) - (br_table $out $out - (i32.const 20) - ) - ) - (block $block5 - (i32.const 10) - (i32.const 30) - (br_table $out $out - (i32.const 20) - (i32.const 40) - ) - ) - ) - ) - (func $calls - (call $call-i - (block $block0 - (i32.const 10) - ) - ) - (block $block1 - (i32.const 10) - (call $call-i - (i32.const 20) - ) - ) - (block $block2 - (i32.const 10) - (i32.const 20) - (call $call-i - (i32.const 30) - ) - ) - (block $block3 - (i32.const 10) - (i32.const 30) - (call $call-ii - (i32.const 20) - (i32.const 40) - ) - ) - (block $block5 - (unreachable) - (i32.const 20) - (call $call-ii - (i32.const 10) - (i32.const 30) - ) - ) - (block $block7 - (i32.const 10) - (call $call-ii - (unreachable) - (block $block8 - (i32.const 20) - (i32.const 30) - ) - ) - ) - (block $block9 - (i32.const 10) - (unreachable) - (call $call-ii - (i32.const 20) - (i32.const 30) - ) - ) - (block $block11 - (i32.const 10) - (i32.const 30) - (call $call-ii - (i32.const 20) - (unreachable) - ) - ) - (block $block13 - (i32.const 10) - (i32.const 30) - (i32.const 50) - (call $call-iii - (i32.const 20) - (i32.const 40) - (i32.const 60) - ) - ) - (block $block16 - (i32.const 10) - (i32.const 40) - (call $call-iii - (i32.const 20) - (i32.const 30) - (i32.const 50) - ) - ) - (block $block18 - (i32.const 10) - (i32.const 30) - (i32.const 50) - (call_indirect $ii - (i32.const 20) - (i32.const 40) - (i32.const 60) - ) - ) - (call_indirect $ii - (unreachable) - (block $block21 - (i32.const 30) - (i32.const 40) - ) - (block $block22 - (i32.const 50) - (i32.const 60) - ) - ) - ) - (func $block-type-change - (local $0 f64) - (local $1 f64) - (if - (block $block0 - (nop) - (f64.gt - (get_local $0) - (get_local $1) - ) - ) - (nop) - ) - ) -) diff --git a/test/passes/remove-unused-names_merge-blocks.txt b/test/passes/remove-unused-names_merge-blocks.txt new file mode 100644 index 00000000000..a0ed7ea326a --- /dev/null +++ b/test/passes/remove-unused-names_merge-blocks.txt @@ -0,0 +1,438 @@ +(module + (memory 256 256) + (type $i (func (param i32))) + (type $ii (func (param i32 i32))) + (type $iii (func (param i32 i32 i32))) + (table $call-i) + (func $call-i (param $0 i32) + (nop) + ) + (func $call-ii (param $0 i32) (param $1 i32) + (nop) + ) + (func $call-iii (param $0 i32) (param $1 i32) (param $2 i32) + (nop) + ) + (func $b0-yes (param $i1 i32) + (i32.const 10) + ) + (func $b0-no (param $i1 i32) + (block $topmost + (block $block0 + (br $block0) + ) + (br $topmost) + ) + ) + (func $b0-br-but-ok (param $i1 i32) + (block $topmost + (br $topmost) + ) + ) + (func $b1-yes (param $i1 i32) + (i32.const 10) + ) + (func $b2-yes (param $i1 i32) + (i32.const 5) + (i32.const 10) + (i32.const 15) + ) + (func $b3-yes (param $i1 i32) + (i32.const 3) + (i32.const 6) + (i32.const 10) + (i32.const 15) + (i32.const 20) + ) + (func $b4 (param $i1 i32) + (block $inner + (i32.const 10) + (br $inner) + ) + ) + (func $b5 (param $i1 i32) + (block $middle + (block $inner + (i32.const 10) + (br $inner) + ) + (br $middle) + ) + ) + (func $b6 (param $i1 i32) + (i32.const 5) + (block $inner + (i32.const 10) + (br $inner) + ) + (i32.const 15) + ) + (func $b7 (param $i1 i32) + (i32.const 3) + (block $middle + (i32.const 6) + (block $inner + (i32.const 10) + (br $inner) + ) + (i32.const 15) + (br $middle) + ) + (i32.const 20) + ) + (func $unary + (local $x i32) + (i32.eqz + (block + (i32.const 10) + ) + ) + (i32.const 10) + (i32.eqz + (i32.const 20) + ) + (i32.const 10) + (i32.const 20) + (i32.eqz + (i32.const 30) + ) + (i32.const 10) + (set_local $x + (i32.const 20) + ) + (i32.const 10) + (i32.load + (i32.const 20) + ) + (i32.const 10) + (return + (unreachable) + ) + ) + (func $binary + (i32.add + (block + (i32.const 10) + ) + (i32.const 20) + ) + (i32.const 10) + (i32.add + (i32.const 20) + (i32.const 30) + ) + (i32.const 10) + (i32.const 20) + (i32.add + (i32.const 30) + (i32.const 40) + ) + (i32.add + (i32.const 10) + (block + (i32.const 20) + ) + ) + (i32.const 20) + (i32.add + (i32.const 10) + (i32.const 30) + ) + (i32.const 20) + (i32.const 30) + (i32.add + (i32.const 10) + (i32.const 40) + ) + (i32.add + (block + (i32.const 10) + ) + (block + (i32.const 20) + ) + ) + (i32.const 10) + (i32.const 30) + (i32.add + (i32.const 20) + (i32.const 40) + ) + (i32.const 10) + (i32.const 20) + (i32.const 40) + (i32.const 50) + (i32.add + (i32.const 30) + (i32.const 60) + ) + (i32.const 20) + (i32.store + (i32.const 10) + (i32.const 30) + ) + (i32.const 10) + (i32.store + (i32.const 20) + (i32.const 30) + ) + (i32.add + (unreachable) + (block + (i32.const 10) + (i32.const 20) + ) + ) + (unreachable) + (i32.const 20) + (i32.add + (i32.const 10) + (i32.const 30) + ) + ) + (func $trinary + (i32.const 10) + (i32.const 30) + (i32.const 50) + (select + (i32.const 20) + (i32.const 40) + (i32.const 60) + ) + (i32.const 20) + (i32.const 40) + (select + (block + (i32.const 10) + ) + (i32.const 30) + (i32.const 50) + ) + (i32.const 10) + (i32.const 40) + (select + (i32.const 20) + (block + (i32.const 30) + ) + (i32.const 50) + ) + (i32.const 10) + (i32.const 30) + (select + (i32.const 20) + (i32.const 40) + (block + (i32.const 50) + ) + ) + (i32.const 30) + (select + (block + (i32.const 10) + ) + (block + (i32.const 20) + ) + (i32.const 40) + ) + (i32.const 20) + (select + (block + (i32.const 10) + ) + (i32.const 30) + (block + (i32.const 40) + ) + ) + (i32.const 10) + (select + (i32.const 20) + (block + (i32.const 30) + ) + (block + (i32.const 40) + ) + ) + (unreachable) + (i32.const 30) + (i32.const 50) + (select + (i32.const 20) + (i32.const 40) + (i32.const 60) + ) + (i32.const 10) + (select + (unreachable) + (block + (i32.const 30) + (i32.const 40) + ) + (block + (i32.const 50) + (i32.const 60) + ) + ) + (i32.const 10) + (unreachable) + (i32.const 50) + (select + (i32.const 20) + (i32.const 40) + (i32.const 60) + ) + (i32.const 10) + (i32.const 30) + (select + (i32.const 20) + (unreachable) + (block + (i32.const 50) + (i32.const 60) + ) + ) + (i32.const 10) + (i32.const 30) + (unreachable) + (select + (i32.const 20) + (i32.const 40) + (i32.const 60) + ) + (i32.const 10) + (i32.const 30) + (i32.const 50) + (select + (i32.const 20) + (i32.const 40) + (unreachable) + ) + ) + (func $breaks + (block $out + (i32.const 10) + (br $out + (i32.const 20) + ) + (i32.const 10) + (br_if $out + (i32.const 20) + ) + (i32.const 10) + (i32.const 30) + (br_if $out + (i32.const 20) + (i32.const 40) + ) + (i32.const 10) + (br_table $out $out + (i32.const 20) + ) + (i32.const 10) + (i32.const 30) + (br_table $out $out + (i32.const 20) + (i32.const 40) + ) + ) + ) + (func $calls + (call $call-i + (block + (i32.const 10) + ) + ) + (i32.const 10) + (call $call-i + (i32.const 20) + ) + (i32.const 10) + (i32.const 20) + (call $call-i + (i32.const 30) + ) + (i32.const 10) + (i32.const 30) + (call $call-ii + (i32.const 20) + (i32.const 40) + ) + (unreachable) + (i32.const 20) + (call $call-ii + (i32.const 10) + (i32.const 30) + ) + (i32.const 10) + (call $call-ii + (unreachable) + (block + (i32.const 20) + (i32.const 30) + ) + ) + (i32.const 10) + (unreachable) + (call $call-ii + (i32.const 20) + (i32.const 30) + ) + (i32.const 10) + (i32.const 30) + (call $call-ii + (i32.const 20) + (unreachable) + ) + (i32.const 10) + (i32.const 30) + (i32.const 50) + (call $call-iii + (i32.const 20) + (i32.const 40) + (i32.const 60) + ) + (i32.const 10) + (i32.const 40) + (call $call-iii + (i32.const 20) + (i32.const 30) + (i32.const 50) + ) + (i32.const 10) + (i32.const 30) + (i32.const 50) + (call_indirect $ii + (i32.const 20) + (i32.const 40) + (i32.const 60) + ) + (call_indirect $ii + (unreachable) + (block + (i32.const 30) + (i32.const 40) + ) + (block + (i32.const 50) + (i32.const 60) + ) + ) + ) + (func $block-type-change + (local $0 f64) + (local $1 f64) + (if + (block + (nop) + (f64.gt + (get_local $0) + (get_local $1) + ) + ) + (nop) + ) + ) +) diff --git a/test/passes/merge-blocks.wast b/test/passes/remove-unused-names_merge-blocks.wast similarity index 97% rename from test/passes/merge-blocks.wast rename to test/passes/remove-unused-names_merge-blocks.wast index a4a9873e900..85bb11da62d 100644 --- a/test/passes/merge-blocks.wast +++ b/test/passes/remove-unused-names_merge-blocks.wast @@ -17,6 +17,21 @@ ) ) ) + (func $b0-no (param $i1 i32) + (block $topmost + (block $block0 + (br $block0) + ) + (br $topmost) + ) + ) + (func $b0-br-but-ok (param $i1 i32) + (block $topmost + (block $block0 + (br $topmost) + ) + ) + ) (func $b1-yes (param $i1 i32) (block $topmost (block