From 1a952ad65ea2b21f718e34ea8c0a0af97983190e Mon Sep 17 00:00:00 2001 From: Kirsten <32720576+kirstenmg@users.noreply.github.com> Date: Tue, 4 Jun 2024 20:52:51 -0700 Subject: [PATCH] Add benchmark files --- .../peggy_comparison/branch_hoisting.bril | 33 +++++++++++++++++++ .../conditional_constant_folding.bril | 29 ++++++++++++++++ .../peggy_comparison/dead_loop_deletion.bril | 20 +++++++++++ tests/passing/peggy_comparison/if_true.bril | 12 +++++++ .../peggy_comparison/infinite_loop.bril | 17 ++++++++++ .../loop_based_code_motion.bril | 19 +++++++++++ .../loop_invariant_code_motion.bril | 25 ++++++++++++++ .../peggy_comparison/loop_peeling.bril | 18 ++++++++++ .../loop_strength_reduction.bril | 21 ++++++++++++ .../loop_strength_reduction_modified.bril | 31 +++++++++++++++++ .../passing/peggy_comparison/loop_unroll.bril | 15 +++++++++ .../simple_loop_unswitch.bril | 28 ++++++++++++++++ 12 files changed, 268 insertions(+) create mode 100644 tests/passing/peggy_comparison/branch_hoisting.bril create mode 100644 tests/passing/peggy_comparison/conditional_constant_folding.bril create mode 100644 tests/passing/peggy_comparison/dead_loop_deletion.bril create mode 100644 tests/passing/peggy_comparison/if_true.bril create mode 100644 tests/passing/peggy_comparison/infinite_loop.bril create mode 100644 tests/passing/peggy_comparison/loop_based_code_motion.bril create mode 100644 tests/passing/peggy_comparison/loop_invariant_code_motion.bril create mode 100644 tests/passing/peggy_comparison/loop_peeling.bril create mode 100644 tests/passing/peggy_comparison/loop_strength_reduction.bril create mode 100644 tests/passing/peggy_comparison/loop_strength_reduction_modified.bril create mode 100644 tests/passing/peggy_comparison/loop_unroll.bril create mode 100644 tests/passing/peggy_comparison/simple_loop_unswitch.bril diff --git a/tests/passing/peggy_comparison/branch_hoisting.bril b/tests/passing/peggy_comparison/branch_hoisting.bril new file mode 100644 index 000000000..141084a87 --- /dev/null +++ b/tests/passing/peggy_comparison/branch_hoisting.bril @@ -0,0 +1,33 @@ +# ARGS: 0 +@main(n: int): int { + zero: int = const 0; + x: int = id zero; + y: int = id zero; + fivehundred: int = const 500; + +.pred: + whilecond: bool = lt y fivehundred; + br whilecond .loopbody .end; + +.loopbody: + two: int = const 2; + ifcond: bool = eq n zero; + br ifcond .thn .els; + +.thn: + x: int = mul y two; + jmp .ifend; + +.els: + three: int = const 3; + x: int = mul y three; + +.ifend: + one: int = const 1; + y: int = add one y; + + jmp .pred; + +.end: + ret x; +} \ No newline at end of file diff --git a/tests/passing/peggy_comparison/conditional_constant_folding.bril b/tests/passing/peggy_comparison/conditional_constant_folding.bril new file mode 100644 index 000000000..d7304b9e7 --- /dev/null +++ b/tests/passing/peggy_comparison/conditional_constant_folding.bril @@ -0,0 +1,29 @@ +# ARGS: 4 +@main(x: int): int { + five: int = const 5; + four: int = const 4; + twenty: int = const 20; + cond: bool = eq x five; + br cond .if .else_if_check; + +.if: + res: int = mul four x; + jmp .end; + +.else_if_check: + cond: bool = eq x four; + br cond .else_if .else; + jmp .end; + +.else_if: + res: int = mul five x; + jmp .end; + +.else: + res: int = id twenty; + jmp .end; + +.end: + print res; + ret res; +} \ No newline at end of file diff --git a/tests/passing/peggy_comparison/dead_loop_deletion.bril b/tests/passing/peggy_comparison/dead_loop_deletion.bril new file mode 100644 index 000000000..d14185e0a --- /dev/null +++ b/tests/passing/peggy_comparison/dead_loop_deletion.bril @@ -0,0 +1,20 @@ +@main(): int { + j: int = const 3; + i: int = const 0; + forty: int = const 40; + one: int = const 1; + +.loop_test: + cond: bool = lt i forty; + br cond .loop_body .loop_end; + +.loop_body: + j: int = add j one; + i: int = add i one; + jmp .loop_test; + +.loop_end: + j: int = const 2; + + ret j; +} \ No newline at end of file diff --git a/tests/passing/peggy_comparison/if_true.bril b/tests/passing/peggy_comparison/if_true.bril new file mode 100644 index 000000000..3434ed51e --- /dev/null +++ b/tests/passing/peggy_comparison/if_true.bril @@ -0,0 +1,12 @@ +@main(x: int): int { + cond: bool = const true; + br cond .thn .els; + +.thn: + ret x; + +.els: + one: int = const 1; + res: int = sub x one; + ret res; +} \ No newline at end of file diff --git a/tests/passing/peggy_comparison/infinite_loop.bril b/tests/passing/peggy_comparison/infinite_loop.bril new file mode 100644 index 000000000..b1267d5bc --- /dev/null +++ b/tests/passing/peggy_comparison/infinite_loop.bril @@ -0,0 +1,17 @@ +@main: int { + five: int = const 5; + one: int = const 1; + j: int = const 0; + i: int = id five; + +.loop_test: + cond: bool = eq i five; + br cond .loop_body .loop_end; + +.loop_body: + j: int = add one j; + jmp .loop_test; + +.loop_end: + ret j; +} \ No newline at end of file diff --git a/tests/passing/peggy_comparison/loop_based_code_motion.bril b/tests/passing/peggy_comparison/loop_based_code_motion.bril new file mode 100644 index 000000000..ec68357e4 --- /dev/null +++ b/tests/passing/peggy_comparison/loop_based_code_motion.bril @@ -0,0 +1,19 @@ +@main: int { + x: int = const 0; + three: int = const 3; + +.loop_test: + cond: bool = lt x three; + br cond .loop_body .loop_end; + +.loop_body: + one: int = const 1; + x: int = add x one; + jmp .loop_test; + +.loop_end: + five: int = const 5; + x: int = mul x five; + + ret x; +} \ No newline at end of file diff --git a/tests/passing/peggy_comparison/loop_invariant_code_motion.bril b/tests/passing/peggy_comparison/loop_invariant_code_motion.bril new file mode 100644 index 000000000..43eb09a45 --- /dev/null +++ b/tests/passing/peggy_comparison/loop_invariant_code_motion.bril @@ -0,0 +1,25 @@ +@main(n: int, m: int) { + i: int = const 0; + twenty: int = const 20; + one: int = const 1; + +.loop_test: + cond: bool = lt i twenty; + br cond .loop_body .loop_end; + +.loop_body: + j: int = mul n twenty; + if_cond: bool = lt j m; + br if_cond .thn .end_if; + +.thn: + j: int = add j one; + +.end_if: + output: int = mul i j; + print output; + i: int = add i one; + jmp .loop_test; + +.loop_end: +} \ No newline at end of file diff --git a/tests/passing/peggy_comparison/loop_peeling.bril b/tests/passing/peggy_comparison/loop_peeling.bril new file mode 100644 index 000000000..d2c50e9a9 --- /dev/null +++ b/tests/passing/peggy_comparison/loop_peeling.bril @@ -0,0 +1,18 @@ +@main(n: int): int { + x: int = const 0; + i: int = const 0; + +.loop_test: + cond: bool = lt i n; + br cond .loop_body .loop_end; + +.loop_body: + five: int = const 5; + one: int = const 1; + x: int = add x five; + i: int = add i one; + jmp .loop_test; + +.loop_end: + ret x; +} \ No newline at end of file diff --git a/tests/passing/peggy_comparison/loop_strength_reduction.bril b/tests/passing/peggy_comparison/loop_strength_reduction.bril new file mode 100644 index 000000000..463873602 --- /dev/null +++ b/tests/passing/peggy_comparison/loop_strength_reduction.bril @@ -0,0 +1,21 @@ +@main { + i: int = const 0; + d: int = const 0; + three_hundred: int = const 300; + five: int = const 5; + one: int = const 1; + +.loop_test: + cond: bool = lt d three_hundred; + br cond .loop_body .loop_end; + +.loop_body: + out: int = mul i five; + print out; + + i: int = add i one; + d: int = add d one; + jmp .loop_test; + +.loop_end: +} \ No newline at end of file diff --git a/tests/passing/peggy_comparison/loop_strength_reduction_modified.bril b/tests/passing/peggy_comparison/loop_strength_reduction_modified.bril new file mode 100644 index 000000000..5e8338179 --- /dev/null +++ b/tests/passing/peggy_comparison/loop_strength_reduction_modified.bril @@ -0,0 +1,31 @@ +@main { + i: int = const 0; + d: int = const 0; + three_hundred: int = const 300; + three: int = const 3; + five: int = const 5; + one: int = const 1; + one_hundred_fifty: int = const 150; + +.loop_test: + cond: bool = lt d three_hundred; + br cond .loop_body .loop_end; + +.loop_body: + out: int = mul i five; + print out; + + i: int = add i one; + if_cond: bool = eq d one_hundred_fifty; + br if_cond .if_then .end_if; + +.if_then: + i: int = add i three; + +.end_if: + d: int = add d one; + + jmp .loop_test; + +.loop_end: +} \ No newline at end of file diff --git a/tests/passing/peggy_comparison/loop_unroll.bril b/tests/passing/peggy_comparison/loop_unroll.bril new file mode 100644 index 000000000..c913c1972 --- /dev/null +++ b/tests/passing/peggy_comparison/loop_unroll.bril @@ -0,0 +1,15 @@ +@main: int { + i: int = const 0; + one: int = const 1; + +.loop_test: + cond: bool = lt i one; + br cond .loop_body .loop_end; + +.loop_body: + i: int = add one i; + jmp .loop_test; + +.loop_end: + ret i; +} \ No newline at end of file diff --git a/tests/passing/peggy_comparison/simple_loop_unswitch.bril b/tests/passing/peggy_comparison/simple_loop_unswitch.bril new file mode 100644 index 000000000..de7a80cd4 --- /dev/null +++ b/tests/passing/peggy_comparison/simple_loop_unswitch.bril @@ -0,0 +1,28 @@ +# ARGS: 40 +@main(n: int): int { + one: int = const 1; + zero: int = const 0; + i: int = id zero; + j: int = id zero; + +.loop_test: + cond: bool = lt i n; + br cond .loop_body .loop_end; + +.loop_body: + print i; + + cond: bool = lt n zero; + br cond .thn .ifend; + +.thn: + j: int = const 2; + +.ifend: + j: int = add one j; + i: int = add one i; + jmp .loop_test; + +.loop_end: + ret j; +} \ No newline at end of file