diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-07-07 10:23:41 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-07-07 10:23:41 -0700 |
commit | b8685c30fc9b566cf0fcc397334e5e0fb20a2ecd (patch) | |
tree | 14e1a35c6af725197799c5d67320a7aebe260d04 | |
parent | 9455a8749e1bb2c4788c37495b9cd319f046f6ff (diff) | |
download | binaryen-b8685c30fc9b566cf0fcc397334e5e0fb20a2ecd.tar.gz binaryen-b8685c30fc9b566cf0fcc397334e5e0fb20a2ecd.tar.bz2 binaryen-b8685c30fc9b566cf0fcc397334e5e0fb20a2ecd.zip |
add a relooper test for duff's device, showing irreducible control flow and helper var use
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 13 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 93 |
2 files changed, 106 insertions, 0 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index ace95177a..6fb095d20 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -395,6 +395,19 @@ void test_relooper() { BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0, module); BinaryenFunctionRef sinker = BinaryenAddFunction(module, "switch", v, localTypes, 1, body); } + { // duff's device + RelooperRef relooper = RelooperCreate(); + RelooperBlockRef block0 = RelooperAddBlock(relooper, makeInt32(module, 0)); + RelooperBlockRef block1 = RelooperAddBlock(relooper, makeInt32(module, 1)); + RelooperBlockRef block2 = RelooperAddBlock(relooper, makeInt32(module, 2)); + RelooperAddBranch(block0, block1, makeInt32(module, 10), NULL); + RelooperAddBranch(block0, block2, NULL, NULL); + RelooperAddBranch(block1, block2, NULL, NULL); + RelooperAddBranch(block2, block1, NULL, NULL); + BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 3, module); // use $3 as the helper var + BinaryenType localTypes[] = { BinaryenInt32(), BinaryenInt32(), BinaryenInt64(), BinaryenInt32(), BinaryenFloat32(), BinaryenFloat64(), BinaryenInt32() }; + BinaryenFunctionRef sinker = BinaryenAddFunction(module, "duffs-device", v, localTypes, sizeof(localTypes)/sizeof(BinaryenType), body); + } BinaryenFunctionTypeRef i = BinaryenAddFunctionType(module, "i", BinaryenInt32(), NULL, 0); diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index d4eb5e337..7076622c5 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -667,6 +667,67 @@ raw: ) ) ) + (func $duffs-device (type $v) + (local $0 i32) + (local $1 i32) + (local $2 i64) + (local $3 i32) + (local $4 f32) + (local $5 f64) + (local $6 i32) + (block + (i32.const 0) + (if + (i32.const 10) + (set_local $3 + (i32.const 2) + ) + (set_local $3 + (i32.const 3) + ) + ) + ) + (loop $shape$1$break $shape$1$continue + (block $shape$2$break + (if + (i32.eq + (get_local $3) + (i32.const 2) + ) + (block + (set_local $3 + (i32.const 0) + ) + (i32.const 1) + (block + (set_local $3 + (i32.const 3) + ) + (br $shape$1$continue) + ) + ) + (if + (i32.eq + (get_local $3) + (i32.const 3) + ) + (block + (set_local $3 + (i32.const 0) + ) + (i32.const 2) + (block + (set_local $3 + (i32.const 2) + ) + (br $shape$1$continue) + ) + ) + ) + ) + ) + ) + ) (func $return (type $i) (result i32) (local $0 i32) (block $the-list @@ -685,6 +746,38 @@ optimized: (func $just-one-block (type $v) (nop) ) + (func $duffs-device (type $v) + (local $0 i32) + (set_local $0 + (i32.const 2) + ) + (loop $shape$1$break $shape$1$continue + (if + (i32.eq + (get_local $0) + (i32.const 2) + ) + (block + (set_local $0 + (i32.const 3) + ) + (br $shape$1$continue) + ) + (if + (i32.eq + (get_local $0) + (i32.const 3) + ) + (block + (set_local $0 + (i32.const 2) + ) + (br $shape$1$continue) + ) + ) + ) + ) + ) (func $return (type $i) (result i32) (i32.const 1337) ) |