├── .github └── workflows │ └── Test.yml ├── .gitignore ├── .gitmodules ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── Makefile ├── README.md ├── benchmarks ├── README.md ├── failing │ ├── move_to_passing.py │ └── polybench │ │ ├── _lib.bril │ │ └── float_to_int.py └── passing │ ├── bril │ ├── README.md │ ├── core │ │ ├── ackermann.bril │ │ ├── armstrong.bril │ │ ├── binary-fmt.bril │ │ ├── birthday.bril │ │ ├── bitshift.bril │ │ ├── bitwise-ops.bril │ │ ├── catalan.bril │ │ ├── check-primes.bril │ │ ├── collatz.bril │ │ ├── digital-root.bril │ │ ├── dot-product.bril │ │ ├── euclid.bril │ │ ├── fact.bril │ │ ├── factors.bril │ │ ├── fitsinside.bril │ │ ├── fizz-buzz.bril │ │ ├── gcd.bril │ │ ├── hanoi.bril │ │ ├── is-decreasing.bril │ │ ├── lcm.bril │ │ ├── loopfact.bril │ │ ├── mod_inv.bril │ │ ├── orders.bril │ │ ├── palindrome.bril │ │ ├── pascals-row.bril │ │ ├── perfect.bril │ │ ├── primes-between.bril │ │ ├── pythagorean_triple.bril │ │ ├── quadratic.bril │ │ ├── recfact.bril │ │ ├── relative-primes.bril │ │ ├── reverse.bril │ │ ├── sum-bits.bril │ │ ├── sum-check.bril │ │ ├── sum-divisors.bril │ │ ├── sum-sq-diff.bril │ │ ├── totient.bril │ │ └── up-arrow.bril │ ├── float │ │ ├── conjugate-gradient.bril │ │ ├── cordic.bril │ │ ├── euler.bril │ │ ├── leibniz.bril │ │ ├── mandelbrot.bril │ │ ├── n_root.bril │ │ ├── newton.bril │ │ ├── norm.bril │ │ ├── ray-sphere-intersection.bril │ │ ├── riemann.bril │ │ └── sqrt.bril │ ├── long │ │ └── dead-branch.bril │ ├── mem │ │ ├── adj2csr.bril │ │ ├── adler32.bril │ │ ├── binary-search.bril │ │ ├── bubblesort.bril │ │ ├── csrmv.bril │ │ ├── fib.bril │ │ ├── major-elm.bril │ │ ├── mat-mul.bril │ │ ├── max-subarray.bril │ │ ├── quickselect.bril │ │ ├── quicksort.bril │ │ └── vsmul.bril │ └── mixed │ │ ├── cholesky_decomp.bril │ │ └── mat-inv.bril │ ├── fenwick │ └── fenwick_tree.rs │ ├── polybench │ ├── README.md │ ├── datamining │ │ ├── correlation.rs │ │ └── covariance.rs │ ├── linear-algebra │ │ ├── blas │ │ │ ├── gemm.bril │ │ │ ├── gemver.bril │ │ │ ├── gesummv.bril │ │ │ ├── symm.bril │ │ │ ├── syr2k.bril │ │ │ ├── syrk.bril │ │ │ └── trmm.bril │ │ ├── kernels │ │ │ ├── 2mm.bril │ │ │ ├── 3mm.bril │ │ │ ├── atax.bril │ │ │ ├── bicg.bril │ │ │ ├── doitgen.bril │ │ │ └── mvt.bril │ │ └── solvers │ │ │ ├── cholesky.bril │ │ │ ├── durbin.bril │ │ │ ├── gramschmidt.bril │ │ │ ├── lu.bril │ │ │ ├── ludcmp.bril │ │ │ └── trisolv.bril │ ├── medley │ │ ├── deriche.rs │ │ ├── floyd-warshall.rs │ │ └── nussinov.rs │ └── stencils │ │ ├── adi.rs │ │ ├── fdtd-2d.rs │ │ ├── heat-3d.rs │ │ ├── jacobi-1d.rs │ │ ├── jacobi-2d.rs │ │ └── seidel-2d.rs │ └── raytrace │ └── raytrace.rs ├── dag_in_context ├── Cargo.lock ├── Cargo.toml ├── rust-toolchain └── src │ ├── add_context.rs │ ├── ast.rs │ ├── config.rs │ ├── dag2svg.rs │ ├── dag_typechecker.rs │ ├── extractiongymfastergreedydag.rs │ ├── fastercbcextractor.rs │ ├── from_egglog.rs │ ├── greedy_dag_extractor.rs │ ├── interpreter.rs │ ├── interval_analysis.egg │ ├── interval_analysis.rs │ ├── lib.rs │ ├── linearity.rs │ ├── main.rs │ ├── optimizations │ ├── body_contains.rs │ ├── conditional_invariant_code_motion.egg │ ├── conditional_invariant_code_motion.rs │ ├── conditional_push_in.egg │ ├── function_inlining.rs │ ├── hackers_delight.egg │ ├── is_resolved.rs │ ├── is_valid.rs │ ├── ivt.egg │ ├── ivt.rs │ ├── loop_invariant.egg │ ├── loop_invariant.rs │ ├── loop_simplify.egg │ ├── loop_strength_reduction.egg │ ├── loop_unroll.egg │ ├── loop_unroll.rs │ ├── mem_simple.egg │ ├── memory.egg │ ├── memory.rs │ ├── mod.rs │ ├── passthrough.egg │ ├── passthrough.rs │ ├── peepholes.egg │ ├── peepholes.rs │ ├── purity_analysis.egg │ ├── rec_to_loop.egg │ ├── select.egg │ ├── swap_if.egg │ ├── switch_rewrites.egg │ └── switch_rewrites.rs │ ├── pretty_print.rs │ ├── remove_dead_code_nodes.rs │ ├── schedule.rs │ ├── schema.egg │ ├── schema.rs │ ├── schema_helpers.rs │ ├── snapshots │ └── dag_in_context__pretty_print__pretty_print_snapshot.snap │ ├── to_egglog.rs │ ├── type_analysis.egg │ ├── type_analysis.rs │ ├── typechecker.rs │ └── utility │ ├── add_context.egg │ ├── add_context.rs │ ├── canonicalize.egg │ ├── context-prop.egg │ ├── context_of.egg │ ├── context_of.rs │ ├── debug-helper.egg │ ├── drop_at.egg │ ├── expr_size.egg │ ├── expr_size.rs │ ├── mod.rs │ ├── subst.egg │ ├── subst.rs │ ├── term-subst.egg │ ├── terms.egg │ ├── util.egg │ ├── util.rs │ └── wildcard.rs ├── infra ├── dump_irs │ ├── dump_all.sh │ └── dump_one.sh ├── generate_cfgs.py ├── generate_line_counts.py ├── get_egglog_files.py ├── graphs.py ├── localnightly.sh ├── nightly-resources │ ├── Plugin.Errorbars.js │ ├── chart.js │ ├── data.js │ ├── handlers.js │ ├── index.html │ ├── index.js │ ├── latex.js │ ├── llvm.html │ ├── llvm.js │ ├── previousRuns.js │ ├── stylesheet.css │ ├── table.html │ ├── table.js │ └── utils.js ├── nightly.sh ├── nightly_table.py ├── output_test_egraphs.sh ├── profile.py └── visualize_raytrace_result.py ├── install_ubuntu.sh ├── proofs └── proofs.v ├── runtime ├── Cargo.lock ├── Cargo.toml ├── build.rs ├── install.sh ├── rt.c └── src │ └── main.rs ├── rust-toolchain ├── src ├── canonicalize_names.rs ├── cfg │ ├── mod.rs │ ├── tests.rs │ └── to_bril.rs ├── conversions.rs ├── lib.rs ├── main.rs ├── rvsdg │ ├── from_cfg.rs │ ├── from_dag.rs │ ├── live_variables.rs │ ├── mod.rs │ ├── optimize_direct_jumps.rs │ ├── restructure.rs │ ├── rvsdg2svg.rs │ ├── simplify_branches.rs │ ├── snapshots │ │ ├── eggcc__rvsdg__optimize_direct_jumps__add_block_ind_test_snapshot.snap │ │ ├── eggcc__rvsdg__rvsdg2svg__add_rvsdg_svg.snap │ │ ├── eggcc__rvsdg__rvsdg2svg__diamond_rvsdg_svg.snap │ │ ├── eggcc__rvsdg__rvsdg2svg__fib_shape_rvsdg_svg.snap │ │ ├── eggcc__rvsdg__rvsdg2svg__tests__rvsdg2svg_basic_snapshot.snap │ │ ├── eggcc__rvsdg__tests__rvsdg_state_mem_to_cfg_more_blocks_snapshot.snap │ │ └── eggcc__rvsdg__tests__rvsdg_state_mem_to_cfg_snapshot.snap │ ├── tests.rs │ ├── to_cfg.rs │ └── to_dag.rs ├── test_util.rs └── util.rs ├── tests ├── failing │ ├── brils │ │ ├── char │ │ │ ├── char.bril │ │ │ ├── char.out │ │ │ ├── char_args.bril │ │ │ ├── char_args.out │ │ │ ├── char_ops.bril │ │ │ ├── char_ops.out │ │ │ ├── control_char.bril │ │ │ ├── control_char.out │ │ │ ├── conversions.bril │ │ │ └── conversions.out │ │ ├── mixed │ │ │ ├── store-char.bril │ │ │ ├── store-char.out │ │ │ ├── store-float.bril │ │ │ └── store-float.out │ │ └── ssa │ │ │ ├── ssa-simple-inv.bril │ │ │ ├── ssa-simple-inv.out │ │ │ ├── ssa-simple.bril │ │ │ └── ssa-simple.out │ ├── peggy_comparison │ │ └── infinite_loop.bril │ └── small │ │ ├── cycle.bril │ │ ├── odd_control_flow_ptr.bril │ │ ├── peggy_loop.bril │ │ └── queens-func.bril ├── files.rs ├── passing │ ├── brils │ │ ├── core │ │ │ ├── add-overflow.bril │ │ │ ├── add-overflow.out │ │ │ ├── br.bril │ │ │ ├── br.out │ │ │ ├── call-with-args.bril │ │ │ ├── call-with-args.out │ │ │ ├── call.bril │ │ │ ├── call.out │ │ │ ├── div.bril │ │ │ ├── div.out │ │ │ ├── jmp.bril │ │ │ ├── jmp.out │ │ │ ├── main-args.bril │ │ │ ├── main-args.out │ │ │ ├── main-bool-args.bril │ │ │ ├── main-bool-args.out │ │ │ ├── nop.bril │ │ │ ├── nop.out │ │ │ ├── rectangles-area-difference.bril │ │ │ ├── ret.bril │ │ │ ├── ret.out │ │ │ ├── tiny.bril │ │ │ └── tiny.out │ │ ├── float │ │ │ ├── float.bril │ │ │ ├── float.out │ │ │ ├── float_divide_by_zero.bril │ │ │ ├── float_divide_by_zero.out │ │ │ ├── float_special.bril │ │ │ ├── float_special.out │ │ │ └── pow.bril │ │ ├── long │ │ │ └── function_call.bril │ │ ├── mem │ │ │ ├── access.bril │ │ │ ├── access.out │ │ │ ├── access_many.bril │ │ │ ├── access_many.out │ │ │ ├── access_ptr.bril │ │ │ ├── access_ptr.out │ │ │ ├── alloc.bril │ │ │ ├── alloc.out │ │ │ ├── alloc_large.bril │ │ │ ├── alloc_large.out │ │ │ ├── alloc_many.bril │ │ │ ├── alloc_many.out │ │ │ ├── fib.out │ │ │ ├── fib_test.bril │ │ │ ├── mem_id.bril │ │ │ ├── mem_id.out │ │ │ ├── ptr_call.bril │ │ │ ├── ptr_call.out │ │ │ ├── ptr_ret.bril │ │ │ ├── ptr_ret.out │ │ │ ├── test-fib.bril │ │ │ └── test-fib.out │ │ └── rs2bril-example.rs │ ├── other │ │ ├── do_while_if.bril │ │ ├── eliminate_gamma_false.bril │ │ ├── odd_control_flow.bril │ │ ├── repro-directjumps.bril │ │ ├── repro-forgotprint.bril │ │ ├── repro-if-conversion-region.bril │ │ ├── unroll_and_constant_fold_three.bril │ │ └── unstructured.bril │ └── small │ │ ├── add.bril │ │ ├── add_block_indirection.bril │ │ ├── block-diamond.bril │ │ ├── bool.bril │ │ ├── branch_duplicate_work.bril │ │ ├── collatz_redundant_computation.bril │ │ ├── constant_fold_simple.bril │ │ ├── count.bril │ │ ├── diamond.bril │ │ ├── double-for.bril │ │ ├── duplicate_branch.bril │ │ ├── eliminate_gamma.bril │ │ ├── eliminate_gamma_interval.bril │ │ ├── eliminate_loop.bril │ │ ├── fib-2-unroll.bril │ │ ├── fib-2.bril │ │ ├── fib_recursive.bril │ │ ├── fib_shape.bril │ │ ├── five_call_nestings.bril │ │ ├── flatten_loop.bril │ │ ├── four_call_nestings.bril │ │ ├── gamma_condition_and.bril │ │ ├── gamma_pull_in.bril │ │ ├── if_constant_fold.bril │ │ ├── if_constant_fold2.bril │ │ ├── if_context.rs │ │ ├── if_context2.bril │ │ ├── if_dead_code.bril │ │ ├── if_dead_code_nested.bril │ │ ├── if_in_loop.bril │ │ ├── if_interval.bril │ │ ├── if_invariant_do_pull_out.rs │ │ ├── if_invariant_dont_pull_out.rs │ │ ├── if_push_in.rs │ │ ├── implicit-return.bril │ │ ├── impossible_if.bril │ │ ├── ivt.rs │ │ ├── jumping_loop.bril │ │ ├── loop_hoist.bril │ │ ├── loop_if.bril │ │ ├── loop_pass_through.bril │ │ ├── loop_with_mul_by_inv.bril │ │ ├── lowbit.rs │ │ ├── lowbit_br.bril │ │ ├── lowbit_naive.rs │ │ ├── lowbit_naive_br.bril │ │ ├── lowbit_naive_extra.rs │ │ ├── max.bril │ │ ├── mem_loop_store_forwarding.bril │ │ ├── mem_simple_redundant_load.bril │ │ ├── mem_simple_store_forwarding.bril │ │ ├── min.bril │ │ ├── nested_call.bril │ │ ├── peel_twice.bril │ │ ├── peel_twice_precalc_pred.bril │ │ ├── peggy_comparison │ │ ├── branch_hoisting.bril │ │ ├── conditional_constant_folding.bril │ │ ├── dead_loop_deletion.bril │ │ ├── if_true.bril │ │ ├── loop_based_code_motion.bril │ │ ├── loop_invariant_code_motion.bril │ │ ├── loop_peeling.bril │ │ ├── loop_strength_reduction.bril │ │ ├── loop_strength_reduction_modified.bril │ │ ├── loop_unroll.bril │ │ └── simple_loop_unswitch.bril │ │ ├── pull_out_small.rs │ │ ├── range_check.bril │ │ ├── range_splitting.bril │ │ ├── reassoc.bril │ │ ├── rec_to_loop.bril │ │ ├── rec_to_loop_sub.bril │ │ ├── recurse_once.bril │ │ ├── select.rs │ │ ├── select_simple.rs │ │ ├── simple-call.bril │ │ ├── simple_branch.bril │ │ ├── simple_call.bril │ │ ├── simple_loop.bril │ │ ├── simple_loop_swap.bril │ │ ├── simple_recursive.bril │ │ ├── simple_select_after_block_diamond.bril │ │ ├── simplest_loop.bril │ │ ├── small-collatz.bril │ │ ├── small-fib.bril │ │ ├── sqrt_small.bril │ │ ├── strong_loop.bril │ │ ├── two_fns.bril │ │ ├── unroll_and_constant_fold.bril │ │ └── unroll_multiple_4.bril ├── slow │ ├── many-allocs.bril │ ├── polybench │ │ ├── README.md │ │ └── linear-algebra │ │ │ ├── blas │ │ │ ├── gemm-test.bril │ │ │ ├── gemver-test.bril │ │ │ ├── gesummv-test.bril │ │ │ ├── symm-test.bril │ │ │ ├── syr2k-test.bril │ │ │ ├── syrk-test.bril │ │ │ └── trmm-test.bril │ │ │ ├── kernels │ │ │ ├── 2mm-test.bril │ │ │ ├── 3mm-test.bril │ │ │ ├── atax-test.bril │ │ │ ├── bicg-test.bril │ │ │ ├── doitgen-test.bril │ │ │ └── mvt-test.bril │ │ │ └── solvers │ │ │ ├── cholesky-test.bril │ │ │ ├── durbin-test.bril │ │ │ ├── gramschmidt-test.bril │ │ │ ├── lu-test.bril │ │ │ ├── ludcmp-test.bril │ │ │ └── trisolv-test.bril │ └── raytracewithscreen.rs └── snapshots │ ├── files__add-optimize-sequential.snap │ ├── files__add-optimize.snap │ ├── files__add_block_indirection-optimize-sequential.snap │ ├── files__add_block_indirection-optimize.snap │ ├── files__block-diamond-optimize-sequential.snap │ ├── files__block-diamond-optimize.snap │ ├── files__bool-optimize-sequential.snap │ ├── files__bool-optimize.snap │ ├── files__branch_duplicate_work-optimize-sequential.snap │ ├── files__branch_duplicate_work-optimize.snap │ ├── files__branch_hoisting-optimize-sequential.snap │ ├── files__branch_hoisting-optimize.snap │ ├── files__collatz_redundant_computation-optimize-sequential.snap │ ├── files__collatz_redundant_computation-optimize.snap │ ├── files__conditional_constant_folding-optimize-sequential.snap │ ├── files__conditional_constant_folding-optimize.snap │ ├── files__constant_fold_simple-optimize-sequential.snap │ ├── files__constant_fold_simple-optimize.snap │ ├── files__count-optimize-sequential.snap │ ├── files__count-optimize.snap │ ├── files__dead_loop_deletion-optimize-sequential.snap │ ├── files__dead_loop_deletion-optimize.snap │ ├── files__diamond-optimize-sequential.snap │ ├── files__diamond-optimize.snap │ ├── files__double-for-optimize-sequential.snap │ ├── files__double-for-optimize.snap │ ├── files__duplicate_branch-optimize-sequential.snap │ ├── files__duplicate_branch-optimize.snap │ ├── files__eliminate_gamma-optimize-sequential.snap │ ├── files__eliminate_gamma-optimize.snap │ ├── files__eliminate_gamma_interval-optimize-sequential.snap │ ├── files__eliminate_gamma_interval-optimize.snap │ ├── files__eliminate_loop-optimize-sequential.snap │ ├── files__eliminate_loop-optimize.snap │ ├── files__fib-2-optimize-sequential.snap │ ├── files__fib-2-optimize.snap │ ├── files__fib-2-unroll-optimize-sequential.snap │ ├── files__fib-2-unroll-optimize.snap │ ├── files__fib_recursive-optimize-sequential.snap │ ├── files__fib_recursive-optimize.snap │ ├── files__fib_shape-optimize-sequential.snap │ ├── files__fib_shape-optimize.snap │ ├── files__five_call_nestings-optimize-sequential.snap │ ├── files__five_call_nestings-optimize.snap │ ├── files__flatten_loop-optimize-sequential.snap │ ├── files__flatten_loop-optimize.snap │ ├── files__four_call_nestings-optimize-sequential.snap │ ├── files__four_call_nestings-optimize.snap │ ├── files__gamma_condition_and-optimize-sequential.snap │ ├── files__gamma_condition_and-optimize.snap │ ├── files__gamma_pull_in-optimize-sequential.snap │ ├── files__gamma_pull_in-optimize.snap │ ├── files__if_constant_fold-optimize-sequential.snap │ ├── files__if_constant_fold-optimize.snap │ ├── files__if_constant_fold2-optimize-sequential.snap │ ├── files__if_constant_fold2-optimize.snap │ ├── files__if_context-optimize-sequential.snap │ ├── files__if_context-optimize.snap │ ├── files__if_context2-optimize-sequential.snap │ ├── files__if_context2-optimize.snap │ ├── files__if_dead_code-optimize-sequential.snap │ ├── files__if_dead_code-optimize.snap │ ├── files__if_dead_code_nested-optimize-sequential.snap │ ├── files__if_dead_code_nested-optimize.snap │ ├── files__if_in_loop-optimize-sequential.snap │ ├── files__if_in_loop-optimize.snap │ ├── files__if_interval-optimize-sequential.snap │ ├── files__if_interval-optimize.snap │ ├── files__if_invariant_do_pull_out-optimize-sequential.snap │ ├── files__if_invariant_do_pull_out-optimize.snap │ ├── files__if_invariant_dont_pull_out-optimize-sequential.snap │ ├── files__if_invariant_dont_pull_out-optimize.snap │ ├── files__if_push_in-optimize-sequential.snap │ ├── files__if_push_in-optimize.snap │ ├── files__if_true-optimize-sequential.snap │ ├── files__if_true-optimize.snap │ ├── files__implicit-return-optimize-sequential.snap │ ├── files__implicit-return-optimize.snap │ ├── files__impossible_if-optimize-sequential.snap │ ├── files__impossible_if-optimize.snap │ ├── files__ivt-optimize-sequential.snap │ ├── files__ivt-optimize.snap │ ├── files__jumping_loop-optimize-sequential.snap │ ├── files__jumping_loop-optimize.snap │ ├── files__loop_based_code_motion-optimize-sequential.snap │ ├── files__loop_based_code_motion-optimize.snap │ ├── files__loop_hoist-optimize-sequential.snap │ ├── files__loop_hoist-optimize.snap │ ├── files__loop_if-optimize-sequential.snap │ ├── files__loop_if-optimize.snap │ ├── files__loop_invariant_code_motion-optimize-sequential.snap │ ├── files__loop_invariant_code_motion-optimize.snap │ ├── files__loop_pass_through-optimize-sequential.snap │ ├── files__loop_pass_through-optimize.snap │ ├── files__loop_peeling-optimize-sequential.snap │ ├── files__loop_peeling-optimize.snap │ ├── files__loop_strength_reduction-optimize-sequential.snap │ ├── files__loop_strength_reduction-optimize.snap │ ├── files__loop_strength_reduction_modified-optimize-sequential.snap │ ├── files__loop_strength_reduction_modified-optimize.snap │ ├── files__loop_unroll-optimize-sequential.snap │ ├── files__loop_unroll-optimize.snap │ ├── files__loop_with_mul_by_inv-optimize-sequential.snap │ ├── files__loop_with_mul_by_inv-optimize.snap │ ├── files__lowbit-optimize-sequential.snap │ ├── files__lowbit-optimize.snap │ ├── files__lowbit_br-optimize-sequential.snap │ ├── files__lowbit_br-optimize.snap │ ├── files__lowbit_naive-optimize-sequential.snap │ ├── files__lowbit_naive-optimize.snap │ ├── files__lowbit_naive_br-optimize-sequential.snap │ ├── files__lowbit_naive_br-optimize.snap │ ├── files__lowbit_naive_extra-optimize-sequential.snap │ ├── files__lowbit_naive_extra-optimize.snap │ ├── files__max-optimize-sequential.snap │ ├── files__max-optimize.snap │ ├── files__mem_loop_store_forwarding-optimize-sequential.snap │ ├── files__mem_loop_store_forwarding-optimize.snap │ ├── files__mem_simple_redundant_load-optimize-sequential.snap │ ├── files__mem_simple_redundant_load-optimize.snap │ ├── files__mem_simple_store_forwarding-optimize-sequential.snap │ ├── files__mem_simple_store_forwarding-optimize.snap │ ├── files__min-optimize-sequential.snap │ ├── files__min-optimize.snap │ ├── files__nested_call-optimize-sequential.snap │ ├── files__nested_call-optimize.snap │ ├── files__peel_twice-optimize-sequential.snap │ ├── files__peel_twice-optimize.snap │ ├── files__peel_twice_precalc_pred-optimize-sequential.snap │ ├── files__peel_twice_precalc_pred-optimize.snap │ ├── files__pull_out_small-optimize-sequential.snap │ ├── files__pull_out_small-optimize.snap │ ├── files__range_check-optimize-sequential.snap │ ├── files__range_check-optimize.snap │ ├── files__range_splitting-optimize-sequential.snap │ ├── files__range_splitting-optimize.snap │ ├── files__reassoc-optimize-sequential.snap │ ├── files__reassoc-optimize.snap │ ├── files__rec_to_loop-optimize-sequential.snap │ ├── files__rec_to_loop-optimize.snap │ ├── files__rec_to_loop_sub-optimize-sequential.snap │ ├── files__rec_to_loop_sub-optimize.snap │ ├── files__recurse_once-optimize-sequential.snap │ ├── files__recurse_once-optimize.snap │ ├── files__select-optimize-sequential.snap │ ├── files__select-optimize.snap │ ├── files__select_simple-optimize-sequential.snap │ ├── files__select_simple-optimize.snap │ ├── files__simple-call-optimize-sequential.snap │ ├── files__simple-call-optimize.snap │ ├── files__simple_branch-optimize-sequential.snap │ ├── files__simple_branch-optimize.snap │ ├── files__simple_call-optimize-sequential.snap │ ├── files__simple_call-optimize.snap │ ├── files__simple_loop-optimize-sequential.snap │ ├── files__simple_loop-optimize.snap │ ├── files__simple_loop_swap-optimize-sequential.snap │ ├── files__simple_loop_swap-optimize.snap │ ├── files__simple_loop_unswitch-optimize-sequential.snap │ ├── files__simple_loop_unswitch-optimize.snap │ ├── files__simple_recursive-optimize-sequential.snap │ ├── files__simple_recursive-optimize.snap │ ├── files__simple_select_after_block_diamond-optimize-sequential.snap │ ├── files__simple_select_after_block_diamond-optimize.snap │ ├── files__simplest_loop-optimize-sequential.snap │ ├── files__simplest_loop-optimize.snap │ ├── files__small-collatz-optimize-sequential.snap │ ├── files__small-collatz-optimize.snap │ ├── files__small-fib-optimize-sequential.snap │ ├── files__small-fib-optimize.snap │ ├── files__sqrt_small-optimize-sequential.snap │ ├── files__sqrt_small-optimize.snap │ ├── files__strong_loop-optimize-sequential.snap │ ├── files__strong_loop-optimize.snap │ ├── files__two_fns-optimize-sequential.snap │ ├── files__two_fns-optimize.snap │ ├── files__unroll_and_constant_fold-optimize-sequential.snap │ ├── files__unroll_and_constant_fold-optimize.snap │ ├── files__unroll_multiple_4-optimize-sequential.snap │ └── files__unroll_multiple_4-optimize.snap └── writing ├── .gitignore ├── Makefile ├── bcprules.sty ├── macros.tex ├── main.tex └── semantics.tex /.github/workflows/Test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v3 10 | with: 11 | submodules: 'true' 12 | - run: sudo apt install graphviz 13 | - run: ./install_ubuntu.sh 14 | - uses: Swatinem/rust-cache@v2 15 | - run: cargo install cargo-insta 16 | - run: make runtime 17 | - run: make test 18 | nits: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v3 22 | with: 23 | submodules: 'true' 24 | - run: ./install_ubuntu.sh 25 | - uses: Swatinem/rust-cache@v2 26 | - run: make nits 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | debug/ 4 | target/ 5 | 6 | # These are backup files generated by rustfmt 7 | **/*.rs.bk 8 | 9 | # MSVC Windows builds of rustc generate these, which store debugging information 10 | *.pdb 11 | 12 | # vscode prefs 13 | .vscode/ 14 | 15 | # vim prefs 16 | .*.swp 17 | 18 | # Added by cargo 19 | 20 | /target 21 | 22 | # Generated nightly files 23 | /nightly 24 | 25 | # Profiler output 26 | profile.json 27 | 28 | # commonly used test file 29 | test.egg 30 | 31 | infra/__pycache__/ 32 | 33 | runtime/rt.bc 34 | runtime/rt.o 35 | 36 | .DS_Store 37 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Oliver Flatt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test test-clean nits nightly runtime 2 | 3 | DIRS = . dag_in_context 4 | 5 | all: nits test 6 | 7 | test: 8 | cargo insta test --release --unreferenced=reject 9 | cd dag_in_context && cargo insta test --release --unreferenced=reject 10 | 11 | test-clean: 12 | cargo insta test --release --unreferenced=delete 13 | cd dag_in_context && cargo insta test --release --unreferenced=delete 14 | 15 | nits: 16 | npx prettier infra/nightly-resources/*.js --check 17 | @rustup component add clippy 18 | @rustup component add rustfmt 19 | cargo clippy --tests -- -D warnings && cargo fmt --check 20 | cd dag_in_context && cargo clippy --tests -- -D warnings && cargo fmt --check 21 | 22 | 23 | 24 | # build the llvm runtime for bril 25 | # if you edit the runtime crate, you must re-run this to rebuild rt.bc 26 | runtime: 27 | bash runtime/install.sh 28 | 29 | nightly: 30 | bash infra/nightly.sh "benchmarks/passing" 31 | -------------------------------------------------------------------------------- /benchmarks/README.md: -------------------------------------------------------------------------------- 1 | # Benchmarks 2 | 3 | Run ```python3 benchmarks/failing/move_to_passing.py``` from root to automatically move passing benchmarks from failing to passing. -------------------------------------------------------------------------------- /benchmarks/failing/move_to_passing.py: -------------------------------------------------------------------------------- 1 | from glob import glob 2 | import subprocess 3 | import os 4 | 5 | TIMEOUT = 60 6 | 7 | if __name__ == "__main__": 8 | files = glob("benchmarks/failing/**/*.bril", recursive=True) 9 | for file in files: 10 | if file[-9:] == '_lib.bril': 11 | continue 12 | print(file) 13 | try: 14 | p = subprocess.run(['cargo', 'run', '--release', file], 15 | timeout=TIMEOUT, stdout=subprocess.DEVNULL) 16 | if p.returncode == 0: 17 | passing = file.replace('failing', 'passing') 18 | os.makedirs("/".join(passing.split("/")[:-1]), exist_ok=True) 19 | os.system(f'mv {file} {passing}') 20 | print("passed and moved") 21 | else: 22 | print("failed") 23 | except subprocess.TimeoutExpired: 24 | print(f"timed out after {TIMEOUT} seconds") 25 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/README.md: -------------------------------------------------------------------------------- 1 | # Bril benchmarks 2 | 3 | Bril benchmarks from the [official bril repository](https://github.com/sampsyo/bril/blob/main/benchmarks/), cloned 2024 Apr 16. 4 | Edited to run in loop with various inputs to achieve reasonable running times for benchmarking. -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/ackermann.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 2 480 2 | # Compute the Ackermann function recursively. 3 | # WARNING: Will quickly exceed stack size 4 | 5 | @main(m: int, n: int) { 6 | t: int = call @ack m n; 7 | print t; 8 | } 9 | 10 | @ack(m: int, n: int): int { 11 | zero: int = const 0; 12 | one: int = const 1; 13 | cond_m: bool = eq m zero; 14 | br cond_m .m_zero .m_nonzero; 15 | .m_zero: 16 | tmp: int = add n one; 17 | ret tmp; 18 | .m_nonzero: 19 | cond_n: bool = eq n zero; 20 | br cond_n .n_zero .n_nonzero; 21 | .n_zero: 22 | m1: int = sub m one; 23 | tmp: int = call @ack m1 one; 24 | ret tmp; 25 | .n_nonzero: 26 | m1: int = sub m one; 27 | n1: int = sub n one; 28 | t1: int = call @ack m n1; 29 | t2: int = call @ack m1 t1; 30 | ret t2; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/binary-fmt.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 3501010 2 | @main(n : int) { 3 | zero: int = const 0; 4 | output: int = call @printBinary n zero; 5 | print output; 6 | } 7 | 8 | @printBinary(n: int, sum: int): int { 9 | zero: int = const 0; 10 | cond: bool = eq n zero; 11 | br cond .end .rec; 12 | .rec: 13 | two: int = const 2; 14 | v0: int = call @mod n two; 15 | v1: int = div n two; 16 | sum: int = call @printBinary v1 sum; 17 | sum: int = add sum v0; 18 | .end: 19 | ret sum; 20 | } 21 | 22 | @mod(a0: int, a1: int) : int { 23 | v0: int = div a0 a1; 24 | v1: int = mul v0 a1; 25 | v2: int = sub a0 v1; 26 | ret v2; 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/catalan.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 14 2 | 3 | # Compute the 10th element in the catalan sequence, which is given by: 4 | # c0 = 0; c(n+1) = sum(ci * c(n-i) for i = 0..n) 5 | @main(input : int) { 6 | catn: int = call @catalan input; 7 | print catn; 8 | } 9 | 10 | # Compute the nth term in the catalan sequence 11 | @catalan(n: int):int{ 12 | one: int = const 1; 13 | zero: int = const 0; 14 | guard0: bool = eq n zero; 15 | br guard0 .if .else; 16 | .if: 17 | ret one; 18 | .else: 19 | sum: int = id zero; 20 | idx: int = id zero; 21 | n: int = sub n one; 22 | .while: 23 | guard1: bool = le idx n; 24 | br guard1 .while.body .while.end; 25 | .while.body: 26 | n2: int = sub n idx; 27 | v1: int = call @catalan idx; 28 | v2: int = call @catalan n2; 29 | elti: int = mul v1 v2; 30 | sum: int = add sum elti; 31 | idx: int = add idx one; 32 | jmp .while; 33 | .while.end: 34 | ret sum; 35 | } 36 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/collatz.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 450000 2 | 3 | # Compute the Collatz sequence from *n*. This may not terminate for all *n*, but 4 | # it is at least known to terminate for all *n* up to a large value. 5 | # see https://en.wikipedia.org/wiki/Collatz_conjecture 6 | @main(x : int) { 7 | one: int = const 1; 8 | two: int = const 2; 9 | three: int = const 3; 10 | sum: int = const 0; 11 | jmp .print; 12 | .cond: 13 | eq_one: bool = eq x one; 14 | br eq_one .end .loop; 15 | .loop: 16 | # No modulus! x is even iff x/2 * 2 = x 17 | half: int = div x two; 18 | doublehalf: int = mul half two; 19 | even: bool = eq x doublehalf; 20 | br even .even .odd; 21 | .even: 22 | x: int = div x two; 23 | jmp .print; 24 | .odd: 25 | x: int = mul x three; 26 | x: int = add x one; 27 | # fallthrough 28 | .print: 29 | sum: int = add sum x; 30 | jmp .cond; 31 | .end: 32 | print sum; 33 | } 34 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/fact.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 920 2 | 3 | # Recursive factorial 4 | @main(a: int) { 5 | x: int = call @fact a; 6 | v13: int = const 0; 7 | print x; 8 | } 9 | 10 | 11 | @fact(a: int): int { 12 | v1: int = id a; 13 | v2: int = const 0; 14 | v3: bool = eq v1 v2; 15 | br v3 .then.0 .else.0; 16 | .then.0: 17 | v4: int = const 1; 18 | ret v4; 19 | .else.0: 20 | v5: int = id a; 21 | v6: int = id a; 22 | v7: int = const 1; 23 | v8: int = sub v6 v7; 24 | v9: int = call @fact v8; 25 | v10: int = mul v5 v9; 26 | ret v10; 27 | } 28 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/factors.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 57000 2 | 3 | # Prints out the integer factors of the input 4 | # Trial division algorithm: https://en.wikipedia.org/wiki/Trial_division 5 | 6 | # input: a positive integer 7 | # output: the integer's factors 8 | @main(num: int) { 9 | zer: int = const 0; 10 | one: int = const 1; 11 | fac: int = const 2; 12 | sum: int = const 0; 13 | 14 | .loopcheck: 15 | ispos: bool = lt one num; 16 | br ispos .loopbody .loopend; 17 | 18 | .loopbody: 19 | quo: int = div num fac; 20 | tmp: int = mul quo fac; 21 | mod: int = sub num tmp; # num % fac 22 | iszero: bool = eq mod zer; 23 | br iszero .ifyes .ifno; 24 | 25 | .ifyes: 26 | sum: int = add sum fac; 27 | num: int = div num fac; 28 | jmp .loopcheck; 29 | 30 | .ifno: 31 | fac: int = add fac one; 32 | jmp .loopcheck; 33 | 34 | .loopend: 35 | print sum; 36 | } -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/fitsinside.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 112 233 900 3211 2 | @main (width1:int, height1:int, width2:int, height2:int) { 3 | output: bool = call @fitsInside width1 height1 width2 height2; 4 | print output; 5 | } 6 | 7 | @fitsInside(w1: int, h1: int, w2: int, h2: int) : bool { 8 | width_check: bool = le w1 w2; 9 | height_check: bool = le h1 h2; 10 | first_check: bool = and width_check height_check; 11 | widthheight_check: bool = le w1 h2; 12 | heightwidth_check: bool = le h1 w2; 13 | second_check: bool = and widthheight_check heightwidth_check; 14 | ret_val: bool = or first_check second_check; 15 | ret ret_val; 16 | } -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/gcd.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1190 83 2 | 3 | # TODO failing on nightly- hanging during benchmarking 4 | 5 | # GCD: Greatest Common Divisor 6 | # Euclidean algorithm 7 | 8 | # input: two positive integer - op1, op2 9 | # output: one positive integer - gcd(op1, op2) 10 | @main(op1 : int, op2: int) { 11 | # const 12 | vc0: int = const 0; 13 | # take two input ops, first iteration 14 | v0: int = id op1; 15 | v1: int = id op2; 16 | .cmp.val: 17 | v2: bool = lt v0 v1; 18 | br v2 .if.1 .else.1; 19 | .if.1: 20 | v3: int = sub v1 v0; 21 | jmp .loop.bound; 22 | .else.1: 23 | v3: int = sub v0 v1; 24 | jmp .loop.bound; 25 | # check results 26 | .loop.bound: 27 | v4: bool = eq v3 vc0; 28 | br v4 .program.end .update.val; 29 | .update.val: 30 | br v2 .if.2 .else.2; 31 | # update v1 32 | .if.2: 33 | v1: int = id v3; 34 | jmp .cmp.val; 35 | # update v0 36 | .else.2: 37 | v0: int = id v3; 38 | jmp .cmp.val; 39 | # print out the results 40 | .program.end: 41 | print v1; 42 | } 43 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/hanoi.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 3 2 | 3 | # Tower of Hanoi puzzle. 4 | # 5 | # Input: Number of disks. 6 | # Output: Each move in order, one on each line, where a move `src dst` indicates 7 | # that the top disk from rod `src` should be moved to rod `dst`. 8 | 9 | @hanoi (disks: int, src: int, dst: int, spare: int): int { 10 | zero: int = const 0; 11 | pos: bool = gt disks zero; 12 | res: int = const 0; 13 | br pos .then .else; 14 | .then: 15 | one: int = const 1; 16 | above: int = sub disks one; 17 | rec1: int = call @hanoi above src spare dst; 18 | res: int = add src res; 19 | ten: int = const 10; 20 | intermediate: int = mul ten dst; 21 | res: int = add intermediate res; 22 | rec2: int = call @hanoi above spare dst src; 23 | res: int = add rec1 res; 24 | res: int = add rec2 res; 25 | .else: 26 | ret res; 27 | } 28 | 29 | @main (disks: int) { 30 | src: int = const 0; 31 | dst: int = const 2; 32 | spare: int = const 1; 33 | res: int = call @hanoi disks src dst spare; 34 | print res; 35 | } 36 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/lcm.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 165 233 2 | @main(x : int, y : int) { 3 | greater: int = id y; 4 | v4: bool = gt x y; 5 | br v4 .then.1 .else.1; 6 | .then.1: 7 | greater: int = id x; 8 | jmp .endif.1; 9 | .else.1: 10 | .endif.1: 11 | .foreverloop: 12 | modX : int = call @getMod greater x; 13 | modY : int = call @getMod greater y; 14 | zero: int = const 0; 15 | xZero : bool = eq modX zero; 16 | yZero : bool = eq modY zero; 17 | bothZero : bool = and xZero yZero; 18 | br bothZero .then.2 .else.2; 19 | .then.2: 20 | jmp .loopend; 21 | .else.2: 22 | one: int = const 1; 23 | greater:int = add greater one; 24 | jmp .foreverloop; 25 | .loopend: 26 | print greater; 27 | } 28 | 29 | @getMod(val: int, mod: int): int{ 30 | divisor: int = div val mod; 31 | multiple: int = mul divisor mod; 32 | rem: int = sub val multiple; 33 | ret rem; 34 | } 35 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/loopfact.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 13500 2 | @main(input : int) { 3 | value: int = id input; 4 | v1: int = const 1; 5 | result: int = id v1; 6 | v3: int = id value; 7 | i: int = id v3; 8 | .for.cond.2: 9 | v4: int = id i; 10 | v5: int = const 0; 11 | v6: bool = gt v4 v5; 12 | br v6 .for.body.2 .for.end.2; 13 | .for.body.2: 14 | v7: int = id result; 15 | v8: int = id i; 16 | v9: int = mul v7 v8; 17 | result: int = id v9; 18 | v10: int = id i; 19 | v11: int = const 1; 20 | v12: int = sub v10 v11; 21 | i: int = id v12; 22 | jmp .for.cond.2; 23 | .for.end.2: 24 | v13: int = id result; 25 | v14: int = const 0; 26 | print v13; 27 | } 28 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/perfect.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 265000 2 | @main(input: int) { 3 | n: int = id input; 4 | v0: int = const 0; 5 | v1: int = const 1; 6 | v2: int = const 2; 7 | sum: int = id v1; 8 | i: int = id v2; 9 | result: int = id v1; 10 | .for.cond.1: 11 | ii: int = mul i i; 12 | comp: bool = gt ii n; 13 | br comp .for.end .for.body; 14 | .for.body: 15 | qut: int = div n i; 16 | mpt: int = mul qut i; 17 | dif: int = sub n mpt; 18 | comp1: bool = eq dif v0; 19 | br comp1 .if.body .for.incre; 20 | .if.body: 21 | sum: int = add sum i; 22 | sum: int = add sum qut; 23 | .for.incre: 24 | i: int = add i v1; 25 | jmp .for.cond.1; 26 | .for.end: 27 | comp2: bool = eq sum n; 28 | br comp2 .if.success .if.failure.end; 29 | .if.success: 30 | result: int = id v0; 31 | .if.failure.end: 32 | print result; 33 | } 34 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/recfact.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 9300 2 | @main(input: int) { 3 | x: int = id input; 4 | v1: int = id x; 5 | f: int = call @fac v1; 6 | f: int = id f; 7 | v2: int = id f; 8 | v3: int = const 0; 9 | print v2; 10 | } 11 | 12 | @fac(x: int): int { 13 | v1: int = id x; 14 | v2: int = const 1; 15 | v3: bool = le v1 v2; 16 | br v3 .then.0 .else.0; 17 | .then.0: 18 | v4: int = const 1; 19 | ret v4; 20 | jmp .endif.0; 21 | .else.0: 22 | .endif.0: 23 | v5: int = id x; 24 | v6: int = id x; 25 | v7: int = const 1; 26 | v8: int = sub v6 v7; 27 | v9: int = call @fac v8; 28 | v10: int = mul v5 v9; 29 | result: int = id v10; 30 | v11: int = id result; 31 | ret v11; 32 | } 33 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/reverse.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 8010002 2 | 3 | @main(input : int) { 4 | n: int = id input; 5 | v0: int = const 0; 6 | v1: int = const 10; 7 | result: int = id v0; 8 | v2: bool = const true; 9 | notdone: bool = id v2; 10 | .for.cond.3: 11 | v4: bool = id notdone; 12 | br v4 .for.body.3 .for.end.3; 13 | .for.body.3: 14 | v5: int = id n; 15 | a: int = div v5 v1; 16 | floor: int = mul a v1; 17 | remainder: int = sub v5 floor; 18 | result: int = mul result v1; 19 | result: int = add result remainder; 20 | n: int = id a; 21 | comp1: bool = eq n v0; 22 | br comp1 .if.body .for.incre; 23 | .if.body: 24 | notdone: bool = const false; 25 | jmp .for.cond.3; 26 | .for.incre: 27 | jmp .for.cond.3; 28 | .for.end.3: 29 | print result; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/sum-bits.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 3124109 2 | @main(input: int) { 3 | sum : int = const 0; 4 | two : int = const 2; 5 | zero : int = const 0; 6 | .loop: 7 | cond : bool = eq input zero; 8 | br cond .done .body; 9 | .body: 10 | bit : int = call @mod input two; 11 | input : int = div input two; 12 | sum : int = add sum bit; 13 | jmp .loop; 14 | .done: 15 | print sum; 16 | } 17 | 18 | @mod(dividend : int, divisor : int) : int { 19 | quotient : int = div dividend divisor; 20 | two : int = const 2; 21 | prod : int = mul two quotient; 22 | diff : int = sub dividend prod; 23 | ret diff; 24 | } 25 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/sum-check.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 14500 2 | # compute the sum of [1, n] by both loop and formula 3 | # and compare them to see if the result is the same 4 | @main(n: int) { 5 | sum: int = const 0; 6 | first: int = call @sum_by_loop n; 7 | second: int = call @sum_by_formula n; 8 | isSame: bool = eq first second; 9 | sum: int = add sum first; 10 | sum: int = add sum second; 11 | br isSame .addone .done; 12 | .addone: 13 | one: int = const 1; 14 | sum: int = add sum one; 15 | .done: 16 | print sum; 17 | } 18 | 19 | @sum_by_loop(n: int): int { 20 | one: int = const 1; 21 | sum: int = const 0; 22 | i: int = const 1; 23 | 24 | .for_start: 25 | con: bool = le i n; 26 | br con .for .end; 27 | .for: 28 | sum: int = add sum i; 29 | i: int = add i one; 30 | jmp .for_start; 31 | .end: 32 | ret sum; 33 | } 34 | 35 | # sum = (1 + n) * n / 2 36 | @sum_by_formula(n: int): int { 37 | one: int = const 1; 38 | two: int = const 2; 39 | n_1: int = add one n; 40 | multi: int = mul n_1 n; 41 | sum: int = div multi two; 42 | ret sum; 43 | } -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/sum-divisors.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 415000 2 | 3 | # Finds the sum of an integer input's positive divisors. 4 | # Prints the divisors as they are found, followed by the sum. 5 | @main(n : int) { 6 | sum: int = const 0; 7 | i : int = const 0; 8 | res : int = const 0; 9 | one : int = const 1; 10 | non : int = const -1; 11 | zer : int = const 0; 12 | nlz : bool = lt n zer; 13 | br nlz .neg .begin; 14 | .neg: 15 | n : int = mul n non; 16 | .begin: 17 | i : int = add i one; 18 | isq : int = mul i i; 19 | sqgt : bool = gt isq n; 20 | br sqgt .end .check; 21 | .check: 22 | m : int = call @mod n i; 23 | eqz : bool = eq m zer; 24 | br eqz .body .begin; 25 | .body: 26 | sum: int = add sum i; 27 | res : int = add res i; 28 | d : int = div n i; 29 | deqi : bool = eq d i; 30 | br deqi .begin .then; 31 | .then: 32 | sum: int = add sum d; 33 | res : int = add res d; 34 | jmp .begin; 35 | .end: 36 | print res; 37 | } 38 | 39 | @mod(dividend: int, divisor: int) : int { 40 | quot: int = div dividend divisor; 41 | prod: int = mul divisor quot; 42 | diff: int = sub dividend prod; 43 | ret diff; 44 | } 45 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/core/up-arrow.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 6 2 | @main(n: int) { 3 | arrows: int = const 2; 4 | repeats: int = const 3; 5 | ans: int = call @up_arrow n arrows repeats; 6 | print ans; 7 | } 8 | 9 | # Computes Knuth’s up arrow notation, with the first argument being the number, the second argument being the number of Knuth’s up arrows, and the third argument being the number of repeats. 10 | 11 | @up_arrow(num: int, arrows: int, repeats: int): int { 12 | one: int = const 1; 13 | 14 | ans: int = id num; 15 | i: int = const 1; 16 | 17 | .loopstart: 18 | keepgoing: bool = lt i repeats; 19 | br keepgoing .loopbody .endloop; 20 | 21 | .loopbody: 22 | base_case: bool = le arrows one; 23 | br base_case .base .arrowsgreaterthan1; 24 | 25 | .base: 26 | ans: int = mul ans num; 27 | jmp .finally; 28 | 29 | .arrowsgreaterthan1: 30 | new_arrows: int = sub arrows one; 31 | ans: int = call @up_arrow num new_arrows ans; 32 | 33 | .finally: 34 | i: int = add i one; 35 | jmp .loopstart; 36 | 37 | .endloop: 38 | ret ans; 39 | } 40 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/float/leibniz.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 36000000 2 | 3 | @main(end: int) { 4 | pi: float = const 0; 5 | # denominator 6 | denom: float = const 1; 7 | is_even: bool = const false; 8 | i: int = const 1; 9 | 10 | .for.start: 11 | b: bool = lt i end; 12 | br b .for.body .for.end; 13 | 14 | .for.body: 15 | fone: float = const 1; 16 | br is_even .if.true .if.false; 17 | 18 | .if.true: 19 | f1: float = fdiv fone denom; 20 | pi: float = fsub pi f1; 21 | jmp .if.end; 22 | 23 | .if.false: 24 | f2: float = fdiv fone denom; 25 | pi: float = fadd pi f2; 26 | 27 | .if.end: 28 | two: float = const 2; 29 | denom: float= fadd denom two; 30 | 31 | # step 32 | is_even: bool = not is_even; 33 | one: int = const 1; 34 | i: int = add i one; 35 | jmp .for.start; 36 | 37 | .for.end: 38 | four: float = const 4; 39 | pi: float = fmul pi four; 40 | print pi; 41 | } 42 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/float/newton.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 2200000 2 | @main(n: float) { 3 | two: float = const 2; 4 | x: float = fdiv n two; # fist approximation 5 | prev_x: float = id n; 6 | target: float = const 0.00001; 7 | .for.cond.1: 8 | d: float = call @diff prev_x x; 9 | v6: bool = fgt d target; 10 | br v6 .for.body.1 .for.end.1; 11 | .for.body.1: 12 | prev_x: float = id x; 13 | x: float = call @sqrt x n; 14 | jmp .for.cond.1; 15 | .for.end.1: 16 | print x; 17 | } 18 | 19 | # one iteration of the newton method: 20 | # sqrt(x, n) = x - (x^2 - n) / (2*x) 21 | @sqrt(x: float, n: float): float { 22 | two: float = const 2; 23 | v0: float = fmul x x; 24 | v1: float = fsub v0 n; 25 | v2: float = fmul two x; 26 | v3: float = fdiv v1 v2; 27 | v4: float = fsub x v3; 28 | ret v4; 29 | } 30 | 31 | # returns a postivie difference between a and b 32 | @diff(a: float, b: float): float { 33 | c: bool = fgt a b; 34 | br c .then.1 .else.1; 35 | .then.1: 36 | v5: float = fsub a b; 37 | ret v5; 38 | .else.1: 39 | v5: float = fsub b a; 40 | ret v5; 41 | } 42 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/long/dead-branch.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v1: int = const 1; 3 | v2: int = const 0; 4 | counter: int = const 0; 5 | 6 | .loop_start: 7 | v7: int = id counter; 8 | v8: int = const 99; 9 | v9: bool = lt v7 v8; 10 | br v9 .loop_body .loop_end; 11 | 12 | .loop_body: 13 | v3: bool = eq v1 v2; # Always false 14 | br v3 .then .else; # .then is a dead branch - this br instruction can be optimized out by a smart compiler 15 | 16 | .then: 17 | v4: int = const 100; 18 | 19 | .else: 20 | v4: int = const 50; 21 | 22 | v10: int = id counter; 23 | v11: int = const 1; 24 | v12: int = add v10 v11; 25 | counter: int = id v12; 26 | 27 | jmp .loop_start; 28 | 29 | .loop_end: 30 | print v4; 31 | } 32 | -------------------------------------------------------------------------------- /benchmarks/passing/bril/mem/fib.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 12000 2 | 3 | @main(input : int) { 4 | zero: int = const 0; 5 | one: int = const 1; 6 | neg_one: int = const -1; 7 | vals: ptr = alloc input; 8 | store vals zero; 9 | vals_i: ptr = ptradd vals one; 10 | store vals_i one; 11 | i: int = const 2; 12 | i_minus_one: int = add i neg_one; 13 | i_minus_two: int = add i_minus_one neg_one; 14 | .loop: 15 | cond: bool = lt i input; 16 | br cond .body .done; 17 | .body: 18 | vals_i: ptr = ptradd vals i; 19 | vals_i_minus_one: ptr = ptradd vals i_minus_one; 20 | vals_i_minus_two: ptr = ptradd vals i_minus_two; 21 | tmp: int = load vals_i_minus_one; 22 | tmp2: int = load vals_i_minus_two; 23 | tmp: int = add tmp tmp2; 24 | store vals_i tmp; 25 | i: int = add i one; 26 | i_minus_one: int = add i_minus_one one; 27 | i_minus_two: int = add i_minus_two one; 28 | jmp .loop; 29 | .done: 30 | last: ptr = ptradd vals i_minus_one; 31 | tmp: int = load last; 32 | free vals; 33 | print tmp; 34 | } 35 | -------------------------------------------------------------------------------- /benchmarks/passing/fenwick/fenwick_tree.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 200001 2 | 3 | fn main(n : i64) { 4 | let mut x : [i64; 200001] = [0; 200001]; 5 | let mut i : i64 = 1; 6 | while i < n { 7 | let mut j : i64 = i; 8 | while j < n { 9 | x[j as usize] = x[j as usize] + 1; 10 | j = j + lowbit_naive(j); 11 | } 12 | i = i + 1; 13 | } 14 | let mut i : i64 = n - 1; 15 | let mut ans : i64 = 0; 16 | while i > 0 { 17 | let mut j : i64 = i; 18 | let mut sum : i64 = 0; 19 | while j > 0 { 20 | sum = sum + x[j as usize]; 21 | j = j - lowbit_naive(j); 22 | } 23 | i = i - 1; 24 | ans = ans + sum; 25 | } 26 | drop(x); 27 | println!("{:}", ans); 28 | } 29 | 30 | fn lowbit_naive(a : i64) -> i64 { 31 | let mut n : i64 = a; 32 | let mut lb : i64 = 1; 33 | while n == n / 2 * 2 { 34 | n = n / 2; 35 | lb = lb * 2; 36 | } 37 | return lb; 38 | } 39 | 40 | /* 41 | fn lowbit(n : i64) -> i64 { 42 | let lb : i64 = n & (-n); 43 | return lb; 44 | } 45 | */ -------------------------------------------------------------------------------- /benchmarks/passing/polybench/README.md: -------------------------------------------------------------------------------- 1 | # Polybench/Bril 2 | 3 | A port of Polybench/C 4.2.1 benchmarks to Bril. Original source [here](https://github.com/MatthiasJReisinger/PolyBenchC-4.2.1). -------------------------------------------------------------------------------- /dag_in_context/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dag_in_context" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | egglog = { git = "https://github.com/egraphs-good/egglog", rev = "161a36f" } 10 | smallvec = "1.11.1" 11 | strum = "0.25" 12 | strum_macros = "0.25" 13 | main_error = "0.1.2" 14 | thiserror = "1.0" 15 | egraph-serialize = "0.2.0" 16 | bril-rs = { git = "https://github.com/uwplse/bril", rev = "06117c089c2d235ff8d040bb3d0cfd1e2a1c4880" } 17 | indexmap = "2.0.0" 18 | rustc-hash = "1.1.0" 19 | ordered-float = "3" 20 | graphviz-rust = "0.8.0" 21 | dot-structures = "0.1.1" 22 | symbol_table = { version = "0.3.0", features = ["global"] } 23 | rpds = "1.1.0" 24 | log = "0.4" 25 | env_logger = "0.11.3" 26 | insta = { version = "1.31.0", features = ["yaml"] } 27 | coin_cbc = "0.1.8" 28 | serde_json = "1.0.103" 29 | serde = "1.0.217" 30 | 31 | 32 | clap = { version = "4.4.7", features = ["derive"] } 33 | -------------------------------------------------------------------------------- /dag_in_context/rust-toolchain: -------------------------------------------------------------------------------- 1 | 1.78.0 2 | -------------------------------------------------------------------------------- /dag_in_context/src/config.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | pub(crate) const FUNCTION_INLINING_ITERATIONS: usize = 2; 3 | -------------------------------------------------------------------------------- /dag_in_context/src/dag_typechecker.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /dag_in_context/src/main.rs: -------------------------------------------------------------------------------- 1 | use dag_in_context::{prologue, schedule::parallel_schedule}; 2 | 3 | fn main() { 4 | println!( 5 | "{} \n {}", 6 | prologue(), 7 | parallel_schedule() 8 | .iter() 9 | .map(|s| s.egglog_schedule().to_string()) 10 | .collect::>() 11 | .join("\n") 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /dag_in_context/src/optimizations/loop_simplify.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/egraphs-good/eggcc/a1b06ea52e6a25200fd8014a7c11de9c21c08635/dag_in_context/src/optimizations/loop_simplify.egg -------------------------------------------------------------------------------- /dag_in_context/src/optimizations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod body_contains; 2 | pub mod conditional_invariant_code_motion; 3 | pub mod function_inlining; 4 | pub mod is_resolved; 5 | pub mod is_valid; 6 | pub mod ivt; 7 | pub mod loop_invariant; 8 | pub mod loop_unroll; 9 | pub mod memory; 10 | pub mod passthrough; 11 | mod peepholes; 12 | pub mod switch_rewrites; 13 | -------------------------------------------------------------------------------- /dag_in_context/src/optimizations/peepholes.rs: -------------------------------------------------------------------------------- 1 | //! Tests for the peepholes ruleset 2 | #![cfg(test)] 3 | 4 | use crate::{egglog_test, Result}; 5 | 6 | #[test] 7 | fn arith_rewrites() -> Result { 8 | use crate::ast::*; 9 | // (0 + x + 0 + 1 + 2 + y * 1) -> (x + 3 + y) 10 | let ctx_ty = tuplet_vec(vec![intt(), intt(), statet()]); 11 | let zero = int_ty(0, ctx_ty.clone()); 12 | let one = int_ty(1, ctx_ty.clone()); 13 | let two = int_ty(2, ctx_ty.clone()); 14 | let three = int_ty(3, ctx_ty.clone()); 15 | let x = get(arg_ty(ctx_ty.clone()), 0); 16 | let y = get(arg_ty(ctx_ty.clone()), 1); 17 | let expr = add( 18 | add(add(zero.clone(), x.clone()), zero.clone()), 19 | add(add(one.clone(), two.clone()), mul(y.clone(), one.clone())), 20 | ); 21 | 22 | let expected = add(x.clone(), add(three.clone(), y.clone())); 23 | egglog_test( 24 | &format!("(let expr_ {expr})"), 25 | &format!("(check (= expr_ {expected}))"), 26 | vec![], 27 | emptyv(), 28 | intv(1), 29 | vec![], 30 | ) 31 | } 32 | -------------------------------------------------------------------------------- /dag_in_context/src/optimizations/select.egg: -------------------------------------------------------------------------------- 1 | (ruleset select_opt) 2 | 3 | 4 | ;; inlined (Get thn i) makes the query faster ): 5 | (rule 6 | ( 7 | (= if_e (If pred inputs thn els)) 8 | 9 | (ExprIsPure (Get thn i)) 10 | (ExprIsPure (Get els i)) 11 | 12 | (> 10 (Expr-size (Get thn i))) ; TODO: Tune these size limits 13 | (> 10 (Expr-size (Get els i))) 14 | (= (TCPair t1 c1) (ExtractedExpr (Get thn i))) 15 | (= (TCPair t2 c2) (ExtractedExpr (Get els i))) 16 | 17 | (ContextOf if_e ctx) 18 | ) 19 | ( 20 | (union (Get if_e i) 21 | (Top (Select) pred (TermSubst ctx inputs t1) (TermSubst ctx inputs t2))) 22 | ) 23 | :ruleset select_opt 24 | ) -------------------------------------------------------------------------------- /dag_in_context/src/optimizations/swap_if.egg: -------------------------------------------------------------------------------- 1 | (ruleset swap-if) 2 | 3 | ;; swaps the order of the then and else branches 4 | ;; in an if using Not 5 | 6 | (rule 7 | ((= lhs (If pred inputs then else))) 8 | ( 9 | (union lhs (If (Uop (Not) pred) inputs else then)) 10 | ) 11 | :ruleset swap-if) 12 | 13 | 14 | ;; for if statements with two outputs, swaps the order 15 | ;; of the outputs 16 | (rule 17 | ((= lhs (If pred inputs then else)) 18 | (= (tuple-length then) 2) 19 | (= (tuple-length else) 2)) 20 | ( 21 | (union 22 | (Concat (Single (Get lhs 1)) (Single (Get lhs 0))) 23 | (If pred inputs 24 | (Concat (Single (Get then 1)) (Single (Get then 0))) 25 | (Concat (Single (Get else 1)) (Single (Get else 0))))) 26 | ) 27 | :ruleset swap-if) -------------------------------------------------------------------------------- /dag_in_context/src/snapshots/dag_in_context__pretty_print__pretty_print_snapshot.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/pretty_print.rs 3 | expression: ast 4 | --- 5 | let tpl_s_v0 = tuplet!(statet()); 6 | 7 | let dowhile_v2 = dowhile(parallel!(int(1), int(2), int(3), int(4), getat(0)), 8 | parallel!(less_than(getat(0), 9 | getat(3)), getat(0), getat(1), getat(2), getat(3), tprint(sub(getat(2), 10 | getat(1)), 11 | getat(4)))); 12 | let tpl__v3 = emptyt(); 13 | let tpl_i_v4 = tuplet!(intt()); 14 | 15 | 16 | let dowhile_v7 = dowhile(single(int(1)), 17 | parallel!(less_than(getat(0), 18 | int(3)), get(switch!(int(0), arg(); parallel!(int(4), int(5))), 0))); 19 | let concat_v8 = concat(dowhile_v2.clone(), 20 | dowhile_v7.clone()); 21 | -------------------------------------------------------------------------------- /dag_in_context/src/utility/context-prop.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/egraphs-good/eggcc/a1b06ea52e6a25200fd8014a7c11de9c21c08635/dag_in_context/src/utility/context-prop.egg -------------------------------------------------------------------------------- /dag_in_context/src/utility/expr_size.rs: -------------------------------------------------------------------------------- 1 | #[cfg(test)] 2 | use crate::{egglog_test, interpreter::Value}; 3 | 4 | #[test] 5 | fn test_expr_size() -> crate::Result { 6 | use crate::ast::*; 7 | let pureloop = dowhile( 8 | single(int(1)), 9 | parallel!( 10 | less_than(getat(0), int(3)), 11 | get(switch!(int(2), arg(); parallel!(int(4), int(5))), 0) 12 | ), 13 | ) 14 | .with_arg_types(emptyt(), tuplet!(intt())); 15 | let build: String = format!("(let loop {})", pureloop); 16 | 17 | let check = "(check (= 10 (Expr-size loop)))"; 18 | egglog_test( 19 | build.as_str(), 20 | check, 21 | vec![], 22 | Value::Tuple(vec![]), 23 | Value::Tuple(vec![]), 24 | vec![], 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /dag_in_context/src/utility/mod.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod add_context; 2 | pub(crate) mod context_of; 3 | pub mod expr_size; 4 | pub(crate) mod subst; 5 | pub(crate) mod util; 6 | pub mod wildcard; 7 | -------------------------------------------------------------------------------- /dag_in_context/src/utility/wildcard.rs: -------------------------------------------------------------------------------- 1 | #[cfg(test)] 2 | use crate::{egglog_test, interpreter::Value}; 3 | 4 | #[test] 5 | fn test_wildcard() -> crate::Result { 6 | use crate::ast::*; 7 | 8 | let in_ty = tuplet!(intt(), intt()); 9 | let (expr, expr_cache) = add(getat(0), getat(1)) 10 | .with_arg_types(in_ty.clone(), base(intt())) 11 | .add_dummy_ctx(); 12 | let (expr_with_wildcard, wildcard_cache) = add(getat(0), getat(1)) 13 | .with_arg_types(in_ty.clone(), base(intt())) 14 | .add_ctx(wildcardctx("CTX".to_string())); 15 | 16 | let build = format!("(let expr {expr})\n{}", expr_cache.get_unions()); 17 | let check = format!( 18 | "{}\n(check {expr_with_wildcard})", 19 | wildcard_cache.get_unions() 20 | ); 21 | 22 | egglog_test( 23 | &build, 24 | &check, 25 | vec![], 26 | Value::Tuple(vec![]), 27 | Value::Tuple(vec![]), 28 | vec![], 29 | ) 30 | } 31 | -------------------------------------------------------------------------------- /infra/dump_irs/dump_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | 3 | # Generate optimized and unoptimized LLVM IR for all passing tests & benchmarks 4 | for subdir in "tests" "benchmarks"; do 5 | for f in ../../$subdir/passing/**/*.bril; do 6 | echo $f # ../../benchmarks/passing/bril/mem/bubblesort.bril 7 | output=$(dirname $(echo $f | cut -c7-)) # benchmarks/passing/bril/mem 8 | ./dump_one.sh $f $output 9 | st=$? 10 | if [ $st -ne 0 ]; then 11 | exit $st 12 | fi 13 | done 14 | done 15 | -------------------------------------------------------------------------------- /infra/dump_irs/dump_one.sh: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | 3 | if [ ! -d "$EGGCC_ROOT" ]; then 4 | echo "Please set \$EGGCC_ROOT to your eggcc repo root directory. Current value: $EGGCC_ROOT" 5 | exit 1 6 | fi 7 | 8 | try() { 9 | echo $1 10 | eval $1 11 | st=$? 12 | if [ $st -ne 0 ]; then 13 | exit $st 14 | fi 15 | } 16 | 17 | # argument 1 is input file, argument 2 is output directory 18 | # e.g. 1=../passing/bril/mem/bubblesort.bril 19 | # 2=passing/bril/mem 20 | base=$(basename $1 .bril) # bubblesort 21 | try "cargo run -r $1 --optimize-egglog=false --optimize-bril-llvm=true --run-mode=compile-bril-llvm --llvm-output-dir=$2" 22 | try "cargo run -r $1 --optimize-egglog=false --optimize-bril-llvm=false --run-mode=compile-bril-llvm --llvm-output-dir=$2" 23 | try "cargo run -r $1 --optimize-egglog=true --optimize-bril-llvm=false --run-mode=compile-bril-llvm --llvm-output-dir=$2" 24 | try "cargo run -r $1 --run-mode=dag-conversion > $2/$base.svg" 25 | try "cargo run -r $1 --run-mode=dag-optimize > $2/${base}_egglog_opt.svg" 26 | -------------------------------------------------------------------------------- /infra/localnightly.sh: -------------------------------------------------------------------------------- 1 | # Usage example: 2 | # bash infra/localnightly.sh benchmarks/passing/bril/core --parallel 3 | # First argument: path to benchmark or benchmark folder to run. 4 | # Second argument: optional flag to run timing measurements in parallel (innacurate). 5 | 6 | # optionally, the first argument can be --update to skip profiling and only update the front end visualizations 7 | 8 | # -x: before executing each command, print it 9 | # -e: exit immediately upon first error 10 | set -x -e 11 | 12 | # pass arguments to nightly.sh 13 | LOCAL=1 bash infra/nightly.sh "$@" 14 | cd nightly/output && python3 -m http.server 8002 -------------------------------------------------------------------------------- /infra/nightly-resources/llvm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | LLVM 13 | 14 | 15 |

LLVM

16 | 17 |
18 | 19 |
20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /infra/nightly-resources/table.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | TABLE 13 | 14 | 15 |

16 |
17 | PDF 18 |
19 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /infra/output_test_egraphs.sh: -------------------------------------------------------------------------------- 1 | # TODO: take in file glob as command line argument 2 | PROFILES=(tests/passing/**/*.bril benchmarks/passing/**/*.bril) 3 | 4 | # exit script if serialized directory already exists 5 | if [ -d "./serialized" ]; then 6 | echo "serialized already exists, exiting" 7 | exit 1 8 | fi 9 | 10 | # make serialized directory 11 | mkdir -p ./serialized 12 | 13 | bench() { 14 | echo "json for $1" 15 | # store just the file name to a variable 16 | PROFILE_FILE=$(basename -- "$1") 17 | cargo run --release "$1" --run-mode serialize > ./serialized/"$PROFILE_FILE".json 18 | } 19 | 20 | for p in "${PROFILES[@]}" 21 | do 22 | bench "$p" 23 | done 24 | -------------------------------------------------------------------------------- /install_ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | wget -O- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - 4 | sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" -y 5 | 6 | sudo apt-get update 7 | 8 | sudo apt-get install clang-18 llvm-18 libllvm18 llvm-18-dev llvm-18-runtime 9 | 10 | sudo apt-get install libpolly-18-dev 11 | sudo apt-get install libzstd-dev 12 | sudo apt-get install zlib1g-dev 13 | sudo apt install coinor-libcbc-dev 14 | -------------------------------------------------------------------------------- /runtime/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "libc" 7 | version = "0.2.154" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" 10 | 11 | [[package]] 12 | name = "libc-print" 13 | version = "0.1.23" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "a4a660208db49e35faf57b37484350f1a61072f2a5becf0592af6015d9ddd4b0" 16 | dependencies = [ 17 | "libc", 18 | ] 19 | 20 | [[package]] 21 | name = "runtime" 22 | version = "0.1.0" 23 | dependencies = [ 24 | "libc-print", 25 | ] 26 | -------------------------------------------------------------------------------- /runtime/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "runtime" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | libc-print = "0.1" 10 | 11 | # To properly set up the rt library for linking with LLVM 12 | [profile.dev] 13 | panic = "abort" 14 | lto = true 15 | 16 | [profile.release] 17 | panic = "abort" 18 | lto = true 19 | -------------------------------------------------------------------------------- /runtime/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | #[cfg(target_os = "linux")] 3 | println!("cargo:rustc-link-arg=-nostdlib"); 4 | #[cfg(target_os = "macos")] 5 | println!("cargo:rustc-link-arg=-undefined"); 6 | #[cfg(target_os = "macos")] 7 | println!("cargo:rustc-link-arg=dynamic_lookup"); 8 | 9 | #[cfg(not(any(target_os = "linux", target_os = "macos")))] 10 | assert!(false) 11 | } 12 | -------------------------------------------------------------------------------- /runtime/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Building runtime.bc and rt.o" 4 | 5 | set -e 6 | 7 | # remove rt.bc if it exists 8 | if [ -f runtime/rt.bc ]; then 9 | rm runtime/rt.bc 10 | fi 11 | 12 | if [ -f runtime/rt.bc ]; then 13 | rm runtime/rt.o 14 | fi 15 | 16 | cd runtime 17 | # Duplicate runtime.bc files can mess things up, 18 | # so make sure we start from a clean slate. 19 | cargo clean 20 | cargo rustc --release -- --emit=llvm-bc 21 | cp ./target/release/deps/runtime-*.bc ./rt.bc 22 | cc -c rt.c -o rt.o 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | 1.78.0 2 | -------------------------------------------------------------------------------- /src/rvsdg/snapshots/eggcc__rvsdg__optimize_direct_jumps__add_block_ind_test_snapshot.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/rvsdg/optimize_direct_jumps.rs 3 | expression: cfg.optimize_jumps().to_bril().to_string() 4 | --- 5 | @main { 6 | v0: int = const 1; 7 | v1: int = const 2; 8 | v2: int = add v0 v1; 9 | print v2; 10 | ret; 11 | } 12 | -------------------------------------------------------------------------------- /src/rvsdg/snapshots/eggcc__rvsdg__tests__rvsdg_state_mem_to_cfg_more_blocks_snapshot.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/rvsdg/tests.rs 3 | expression: prog.to_string() 4 | --- 5 | @main { 6 | v1: int = const 1; 7 | v4: ptr = alloc v1; 8 | v7: int = const 10; 9 | store v4 v7; 10 | v11: int = load v4; 11 | v14: bool = lt v11 v7; 12 | br v14 .__39__ .__32__; 13 | .__39__: 14 | print v11; 15 | free v4; 16 | v31: int = id v7; 17 | print v31; 18 | ret; 19 | jmp .__42__; 20 | .__32__: 21 | v24: int = add v11 v1; 22 | free v4; 23 | print v24; 24 | v31: int = id v7; 25 | print v31; 26 | ret; 27 | .__42__: 28 | } 29 | -------------------------------------------------------------------------------- /src/rvsdg/snapshots/eggcc__rvsdg__tests__rvsdg_state_mem_to_cfg_snapshot.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/rvsdg/tests.rs 3 | expression: prog.to_string() 4 | --- 5 | @main { 6 | v1: int = const 1; 7 | v4: ptr = alloc v1; 8 | v8: int = const 10; 9 | store v4 v8; 10 | v12: int = load v4; 11 | print v12; 12 | free v4; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /tests/failing/brils/char/char.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | c1: char = const 'h'; 3 | c2: char = const 'e'; 4 | c3: char = const 'y'; 5 | c4: char = const '🐶'; 6 | print c1 c2 c3 c4; 7 | } -------------------------------------------------------------------------------- /tests/failing/brils/char/char.out: -------------------------------------------------------------------------------- 1 | h e y 🐶 2 | -------------------------------------------------------------------------------- /tests/failing/brils/char/char_args.bril: -------------------------------------------------------------------------------- 1 | # ARGS: h e y 🐱 2 | @main(c1: char, c2: char, c3: char, c4: char) { 3 | print c1 c2 c3 c4; 4 | } -------------------------------------------------------------------------------- /tests/failing/brils/char/char_args.out: -------------------------------------------------------------------------------- 1 | h e y 🐱 2 | -------------------------------------------------------------------------------- /tests/failing/brils/char/char_ops.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | c1: char = const 'a'; 3 | c2: char = const 'b'; 4 | 5 | b1: bool = ceq c1 c2; 6 | b2: bool = clt c1 c2; 7 | b3: bool = cle c1 c2; 8 | b4: bool = cgt c1 c2; 9 | b5: bool = cge c1 c2; 10 | 11 | print b1 b2 b3 b4 b5; 12 | } -------------------------------------------------------------------------------- /tests/failing/brils/char/char_ops.out: -------------------------------------------------------------------------------- 1 | false true true false false 2 | -------------------------------------------------------------------------------- /tests/failing/brils/char/control_char.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | 3 | c1: char = const '\a'; 4 | c2: char = const '\b'; 5 | c3: char = const '\f'; 6 | c4: char = const '\n'; 7 | c5: char = const '\r'; 8 | c6: char = const '\t'; 9 | c7: char = const '\v'; 10 | c8: char = const '\0'; 11 | 12 | print c1 c2 c3 c4 c5 c6 c7 c8; 13 | } -------------------------------------------------------------------------------- /tests/failing/brils/char/control_char.out: -------------------------------------------------------------------------------- 1 |   2 | 3 | -------------------------------------------------------------------------------- /tests/failing/brils/char/conversions.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | c1: char = const 'A'; 3 | c2: char = const '𝛀'; 4 | i1: int = const 65; 5 | i2: int = const 120512; 6 | 7 | c3: char = int2char i1; 8 | i3: int = char2int c1; 9 | c4: char = int2char i2; 10 | i4: int = char2int c2; 11 | 12 | print c3 i3 c4 i4; 13 | } -------------------------------------------------------------------------------- /tests/failing/brils/char/conversions.out: -------------------------------------------------------------------------------- 1 | A 65 𝛀 120512 2 | -------------------------------------------------------------------------------- /tests/failing/brils/mixed/store-char.bril: -------------------------------------------------------------------------------- 1 | @helloBR(end: char) : ptr { 2 | c1: char = const 'o'; 3 | c2: char = const 'i'; 4 | 5 | tam: int = const 3; 6 | pos1: int = const 1; 7 | pos2: int = const 2; 8 | charvec: ptr = alloc tam; 9 | charvec2: ptr = ptradd charvec pos1; 10 | charvec3: ptr = ptradd charvec pos2; 11 | 12 | store charvec c1; 13 | store charvec2 c2; 14 | store charvec3 end; 15 | 16 | ret charvec; 17 | } 18 | 19 | @main() { 20 | end: char = const '.'; 21 | hello: ptr = call @helloBR end; 22 | 23 | pos: int = const 1; 24 | cpos1: ptr = ptradd hello pos; 25 | cpos2: ptr = ptradd cpos1 pos; 26 | 27 | c0: char = load hello; 28 | c1: char = load cpos1; 29 | c2: char = load cpos2; 30 | 31 | print c0; 32 | print c1; 33 | print c2; 34 | 35 | free hello; 36 | } -------------------------------------------------------------------------------- /tests/failing/brils/mixed/store-char.out: -------------------------------------------------------------------------------- 1 | o 2 | i 3 | . 4 | -------------------------------------------------------------------------------- /tests/failing/brils/mixed/store-float.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | one: int = const 1; 3 | seed: float = const 109658.0; 4 | rng: ptr = alloc one; 5 | store rng seed; 6 | x: float = load rng; 7 | print x; 8 | free rng; 9 | } -------------------------------------------------------------------------------- /tests/failing/brils/mixed/store-float.out: -------------------------------------------------------------------------------- 1 | 109658.00000000000000000 2 | -------------------------------------------------------------------------------- /tests/failing/brils/ssa/ssa-simple-inv.bril: -------------------------------------------------------------------------------- 1 | # ARGS: true 2 | @main(cond: bool) { 3 | .top: 4 | a: int = const 5; 5 | br cond .here .there; 6 | .here: 7 | b: int = const 7; 8 | .there: 9 | c: int = phi a .top b .here; 10 | print c; 11 | } 12 | -------------------------------------------------------------------------------- /tests/failing/brils/ssa/ssa-simple-inv.out: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /tests/failing/brils/ssa/ssa-simple.bril: -------------------------------------------------------------------------------- 1 | # ARGS: true 2 | @main(cond: bool) { 3 | .top: 4 | a: int = const 5; 5 | br cond .here .there; 6 | .here: 7 | b: int = const 7; 8 | .there: 9 | c: int = phi a .top b .here; 10 | print c; 11 | } 12 | -------------------------------------------------------------------------------- /tests/failing/brils/ssa/ssa-simple.out: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /tests/failing/peggy_comparison/infinite_loop.bril: -------------------------------------------------------------------------------- 1 | @main: int { 2 | five: int = const 5; 3 | one: int = const 1; 4 | j: int = const 0; 5 | i: int = id five; 6 | 7 | .loop_test: 8 | cond: bool = eq i five; 9 | br cond .loop_body .loop_end; 10 | 11 | .loop_body: 12 | j: int = add one j; 13 | jmp .loop_test; 14 | 15 | .loop_end: 16 | ret j; 17 | } -------------------------------------------------------------------------------- /tests/failing/small/cycle.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | cond: bool = const true; 3 | 4 | .loop: 5 | br cond .loop .end; 6 | 7 | .end: 8 | } -------------------------------------------------------------------------------- /tests/failing/small/odd_control_flow_ptr.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | one: int = const 1; 3 | three: int = const 3; 4 | four: int = const 4; 5 | six: int = const 6; 6 | seven: int = const 7; 7 | 8 | in1: ptr = alloc one; 9 | in2: ptr = alloc one; 10 | store in1 six; 11 | store in2 seven; 12 | a: bool = lt three four; 13 | br a .N .B; 14 | .N: 15 | br a .A .B; 16 | .A: 17 | y: ptr = id in1; 18 | jmp .end; 19 | .B: 20 | y: ptr = id in2; 21 | jmp .end; 22 | .end: 23 | x: int = load y; 24 | free in1; 25 | free in2; 26 | print x; 27 | } -------------------------------------------------------------------------------- /tests/failing/small/peggy_loop.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 5 2 | @main (n: int) { 3 | one: int = const 1; 4 | three: int = const 3; 5 | five: int = const 5; 6 | i: int = const 0; 7 | 8 | .loop_test: 9 | cond: bool = lt i n; 10 | br cond .loop_body .loop_end; 11 | 12 | .loop_body: 13 | out: int = mul i five; 14 | i: int = add i one; 15 | cond: bool = eq i five; 16 | br cond .if_then .if_end; 17 | 18 | .if_then: 19 | i: int = add i three; 20 | 21 | .if_end: 22 | jmp .loop_test; 23 | 24 | .loop_end: 25 | 26 | } -------------------------------------------------------------------------------- /tests/passing/brils/core/add-overflow.bril: -------------------------------------------------------------------------------- 1 | @pow(base: int, exp: int): int { 2 | out: int = const 1; 3 | one: int = const 1; 4 | .loop: 5 | end: bool = lt exp one; 6 | br end .ret .body; 7 | .body: 8 | out: int = mul out base; 9 | exp: int = sub exp one; 10 | jmp .loop; 11 | .ret: 12 | ret out; 13 | } 14 | 15 | @main() { 16 | one: int = const 1; 17 | two: int = const 2; 18 | sixtytwo: int = const 62; 19 | 20 | half: int = call @pow two sixtytwo; 21 | print half; 22 | 23 | smaller: int = sub half one; 24 | maxint: int = add half smaller; 25 | print maxint; 26 | 27 | overflow: int = add maxint one; 28 | print overflow; 29 | } 30 | -------------------------------------------------------------------------------- /tests/passing/brils/core/add-overflow.out: -------------------------------------------------------------------------------- 1 | 4611686018427387904 2 | 9223372036854775807 3 | -9223372036854775808 4 | -------------------------------------------------------------------------------- /tests/passing/brils/core/br.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | b: bool = const false; 4 | br b .there .here; 5 | .here: 6 | v: int = const 2; 7 | .there: 8 | print v; 9 | } 10 | -------------------------------------------------------------------------------- /tests/passing/brils/core/br.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /tests/passing/brils/core/call-with-args.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 2; 3 | y: int = const 2; 4 | z: int = call @add2 x y; 5 | print y; 6 | print z; 7 | } 8 | 9 | @add2(x: int, y: int): int { 10 | w: int = add x y; 11 | y: int = const 5; 12 | print w; 13 | ret w; 14 | } 15 | -------------------------------------------------------------------------------- /tests/passing/brils/core/call-with-args.out: -------------------------------------------------------------------------------- 1 | 4 2 | 2 3 | 4 4 | -------------------------------------------------------------------------------- /tests/passing/brils/core/call.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | v: int = const 2; 3 | call @print4; 4 | print v; 5 | } 6 | @print4 { 7 | v: int = const 4; 8 | print v; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/passing/brils/core/call.out: -------------------------------------------------------------------------------- 1 | 4 2 | 2 3 | -------------------------------------------------------------------------------- /tests/passing/brils/core/div.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 9; 3 | v1: int = const -20; 4 | res: int = div v0 v1; 5 | print res; 6 | } 7 | -------------------------------------------------------------------------------- /tests/passing/brils/core/div.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /tests/passing/brils/core/jmp.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | jmp .somewhere; 4 | v: int = const 2; 5 | .somewhere: 6 | print v; 7 | } 8 | -------------------------------------------------------------------------------- /tests/passing/brils/core/jmp.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /tests/passing/brils/core/main-args.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 2 | @main(x: int, y: int) { 3 | v: int = add x y; 4 | print v; 5 | } 6 | -------------------------------------------------------------------------------- /tests/passing/brils/core/main-args.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /tests/passing/brils/core/main-bool-args.bril: -------------------------------------------------------------------------------- 1 | # ARGS: true 2 | @main(b: bool) { 3 | br b .here .there; 4 | .here: 5 | v: int = const 1; 6 | print v; 7 | ret; 8 | .there: 9 | v: int = const 2; 10 | print v; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/passing/brils/core/main-bool-args.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /tests/passing/brils/core/nop.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | nop; 3 | v: int = const 5; 4 | nop; 5 | print v; 6 | nop; 7 | } 8 | -------------------------------------------------------------------------------- /tests/passing/brils/core/nop.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /tests/passing/brils/core/rectangles-area-difference.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 106 233 323 233 2 | @main (x1 : int, y1: int, x2: int, y2 : int) { 3 | a1: int = call @area x1 y1; 4 | a2: int = call @area x2 y2; 5 | res: int = sub a1 a2; 6 | a1_bigger: bool = gt a1 a2; 7 | br a1_bigger .end .flip; 8 | .flip: 9 | neg1: int = const -1; 10 | res: int = mul res neg1; 11 | .end: 12 | print res; 13 | } 14 | 15 | @area (x : int, y : int) : int { 16 | area: int = mul x y; 17 | ret area; 18 | } 19 | -------------------------------------------------------------------------------- /tests/passing/brils/core/ret.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | print v; 4 | ret; 5 | print v; 6 | } 7 | -------------------------------------------------------------------------------- /tests/passing/brils/core/ret.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /tests/passing/brils/core/tiny.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 5; 3 | print v; 4 | } 5 | -------------------------------------------------------------------------------- /tests/passing/brils/core/tiny.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /tests/passing/brils/float/float.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | v0: float = const 9.0; 3 | v1: float = const -20.0; 4 | res: float = fdiv v0 v1; 5 | print res; 6 | 7 | v2: float = const .1; 8 | v3: float = const 0.1; 9 | add1: float = fadd v2 v3; 10 | dres: float = fadd add1 v2; 11 | print dres; 12 | 13 | v4: float = const .1; 14 | add2: float = fadd v4 v4; 15 | fres: float = fadd add2 v4; 16 | print fres; 17 | } 18 | -------------------------------------------------------------------------------- /tests/passing/brils/float/float.out: -------------------------------------------------------------------------------- 1 | -0.45000000000000001 2 | 0.30000000000000004 3 | 0.30000000000000004 4 | -------------------------------------------------------------------------------- /tests/passing/brils/float/float_divide_by_zero.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: float = const -1.0; 3 | v1: float = const 1.0; 4 | zero: float = const 0.0; 5 | res: float = fdiv v0 zero; 6 | print res; 7 | res: float = fdiv v1 zero; 8 | print res; 9 | res: float = fdiv zero zero; 10 | print res; 11 | } 12 | -------------------------------------------------------------------------------- /tests/passing/brils/float/float_divide_by_zero.out: -------------------------------------------------------------------------------- 1 | -Infinity 2 | Infinity 3 | NaN 4 | -------------------------------------------------------------------------------- /tests/passing/brils/float/float_special.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: float = const 0.0; 3 | v1: float = const -0.0; 4 | res: bool = feq v0 v1; 5 | print v0; 6 | print v1; 7 | print res; 8 | } 9 | -------------------------------------------------------------------------------- /tests/passing/brils/float/float_special.out: -------------------------------------------------------------------------------- 1 | 0.00000000000000000 2 | -0.00000000000000000 3 | true 4 | -------------------------------------------------------------------------------- /tests/passing/brils/float/pow.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 4300.0 2 | 3 | @main(v0: float) { 4 | x: float = id v0; 5 | v1: int = const 2; 6 | n: int = id v1; 7 | v2: float = id x; 8 | v3: int = id n; 9 | output: float = call @pow v2 v3; 10 | print output; 11 | } 12 | 13 | @pow(x: float, n: int): float { 14 | v0: float = id x; 15 | res: float = id v0; 16 | v2: int = const 0; 17 | _i: int = id v2; 18 | .for.cond.1: 19 | v3: int = id _i; 20 | v4: int = id n; 21 | v5: int = const 1; 22 | v6: int = sub v4 v5; 23 | v7: bool = lt v3 v6; 24 | br v7 .for.body.1 .for.end.1; 25 | .for.body.1: 26 | v8: float = id res; 27 | v9: float = id x; 28 | v10: float = fmul v8 v9; 29 | res: float = id v10; 30 | v11: int = id _i; 31 | v12: int = const 1; 32 | v13: int = add v11 v12; 33 | _i: int = id v13; 34 | jmp .for.cond.1; 35 | .for.end.1: 36 | v14: float = id res; 37 | v15: int = const 0; 38 | ret v14; 39 | } 40 | -------------------------------------------------------------------------------- /tests/passing/brils/long/function_call.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 25 2 | 3 | @main(starting_m: int) { 4 | res: int = call @myrec starting_m; 5 | print res; 6 | } 7 | 8 | @myrec(starting_m: int): int { 9 | m : int = id starting_m; 10 | zero: int = const 0; 11 | one: int = const 1; 12 | two: int = const 2; 13 | cond_m: bool = eq m zero; 14 | res: int = const 0; 15 | tmp: int = const 0; 16 | br cond_m .end .m_nonzero; 17 | .m_nonzero: 18 | m:int = sub m one; 19 | tmp:int = call @myrec m; 20 | res:int = add res tmp; 21 | cond_m: bool = eq m zero; 22 | br cond_m .end .m_nonzero2; 23 | .m_nonzero2: 24 | m:int = sub m one; 25 | tmp:int = call @myrec m; 26 | res:int = add res tmp; 27 | cond_m: bool = eq m zero; 28 | br cond_m .end .m_nonzero3; 29 | .m_nonzero3: 30 | m:int = sub m one; 31 | tmp:int = call @myrec m; 32 | res:int = add res tmp; 33 | .end: 34 | ret res; 35 | } -------------------------------------------------------------------------------- /tests/passing/brils/mem/access.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | inc: int = const 1; 3 | v: int = const 1000000; 4 | max: int = const 1000000; 5 | p: ptr = alloc v; 6 | count: int = const 0; 7 | .lbl: 8 | count: int = add count inc; 9 | store p v; 10 | val: int = load p; 11 | loop: bool = ge count max; 12 | br loop .end .lbl; 13 | .end: 14 | free p; 15 | print count; 16 | } 17 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/access.out: -------------------------------------------------------------------------------- 1 | 1000000 2 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/access_many.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | inc: int = const 1; 3 | v: int = const 1000000; 4 | max: int = const 1000000; 5 | p: ptr = alloc v; 6 | count: int = const 0; 7 | p2: ptr = ptradd p count; 8 | .lbl: 9 | count: int = add count inc; 10 | store p2 v; 11 | val: int = load p2; 12 | loop: bool = ge count max; 13 | br loop .end .lbl; 14 | .end: 15 | free p; 16 | print count; 17 | } 18 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/access_many.out: -------------------------------------------------------------------------------- 1 | 1000000 2 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/access_ptr.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | inc: int = const 1; 3 | v: int = const 1000; 4 | max: int = const 1000000; 5 | count: int = const 0; 6 | pi: ptr = alloc v; 7 | pp: ptr> = alloc v; 8 | .lbl: 9 | count: int = add count inc; 10 | store pp pi; 11 | pi: ptr = load pp; 12 | loop: bool = ge count max; 13 | br loop .end .lbl; 14 | .end: 15 | free pi; 16 | free pp; 17 | print count; 18 | } 19 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/access_ptr.out: -------------------------------------------------------------------------------- 1 | 1000000 2 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/alloc.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | o1: int = const 1; 4 | bp: ptr = alloc v; 5 | bp2: ptr = ptradd bp o1; 6 | b: bool = const true; 7 | store bp b; 8 | store bp2 b; 9 | b: bool = load bp2; 10 | print b; 11 | free bp; 12 | } 13 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/alloc.out: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/alloc_large.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | inc: int = const 1; 3 | v: int = const 1000; 4 | max: int = const 1000000; 5 | count: int = const 0; 6 | .lbl: 7 | count: int = add count inc; 8 | p: ptr = alloc v; 9 | free p; 10 | loop: bool = ge count max; 11 | br loop .end .lbl; 12 | .end: 13 | print count; 14 | } 15 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/alloc_large.out: -------------------------------------------------------------------------------- 1 | 1000000 2 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/alloc_many.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 1; 3 | max: int = const 1000000; 4 | count: int = const 0; 5 | .lbl: 6 | count: int = add count v; 7 | p: ptr = alloc v; 8 | free p; 9 | loop: bool = ge count max; 10 | br loop .end .lbl; 11 | .end: 12 | print count; 13 | } 14 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/alloc_many.out: -------------------------------------------------------------------------------- 1 | 1000000 2 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/fib.out: -------------------------------------------------------------------------------- 1 | 34 2 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/fib_test.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | ten: int = const 10; 3 | zero: int = const 0; 4 | one: int = const 1; 5 | neg_one: int = const -1; 6 | vals: ptr = alloc ten; 7 | store vals zero; 8 | vals_i: ptr = ptradd vals one; 9 | store vals_i one; 10 | i: int = const 2; 11 | i_minus_one: int = add i neg_one; 12 | i_minus_two: int = add i_minus_one neg_one; 13 | .loop: 14 | cond: bool = lt i ten; 15 | br cond .body .done; 16 | .body: 17 | vals_i: ptr = ptradd vals i; 18 | vals_i_minus_one: ptr = ptradd vals i_minus_one; 19 | vals_i_minus_two: ptr = ptradd vals i_minus_two; 20 | tmp: int = load vals_i_minus_one; 21 | tmp2: int = load vals_i_minus_two; 22 | tmp: int = add tmp tmp2; 23 | store vals_i tmp; 24 | i: int = add i one; 25 | i_minus_one: int = add i_minus_one one; 26 | i_minus_two: int = add i_minus_two one; 27 | jmp .loop; 28 | .done: 29 | last: ptr = ptradd vals i_minus_one; 30 | tmp: int = load last; 31 | print tmp; 32 | free vals; 33 | ret; 34 | } 35 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/mem_id.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v: int = const 4; 3 | bp: ptr = alloc v; 4 | bp2: ptr = id bp; 5 | b: bool = const true; 6 | store bp2 b; 7 | b: bool = load bp2; 8 | print b; 9 | free bp; 10 | } 11 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/mem_id.out: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/ptr_call.bril: -------------------------------------------------------------------------------- 1 | @funcA(p: ptr) { 2 | ret; 3 | } 4 | 5 | @main { 6 | five: int = const 5; 7 | x: ptr = alloc five; 8 | call @funcA x; 9 | free x; 10 | } 11 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/ptr_call.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/egraphs-good/eggcc/a1b06ea52e6a25200fd8014a7c11de9c21c08635/tests/passing/brils/mem/ptr_call.out -------------------------------------------------------------------------------- /tests/passing/brils/mem/ptr_ret.bril: -------------------------------------------------------------------------------- 1 | @ident(p: ptr): ptr { 2 | ret p; 3 | } 4 | @main { 5 | a: int = const 9; 6 | b: ptr = alloc a; 7 | c: ptr = call @ident b; 8 | free b; 9 | } 10 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/ptr_ret.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/egraphs-good/eggcc/a1b06ea52e6a25200fd8014a7c11de9c21c08635/tests/passing/brils/mem/ptr_ret.out -------------------------------------------------------------------------------- /tests/passing/brils/mem/test-fib.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | ten: int = const 10; 3 | zero: int = const 0; 4 | one: int = const 1; 5 | neg_one: int = const -1; 6 | vals: ptr = alloc ten; 7 | store vals zero; 8 | vals_i: ptr = ptradd vals one; 9 | store vals_i one; 10 | i: int = const 2; 11 | i_minus_one: int = add i neg_one; 12 | i_minus_two: int = add i_minus_one neg_one; 13 | .loop: 14 | cond: bool = lt i ten; 15 | br cond .body .done; 16 | .body: 17 | vals_i: ptr = ptradd vals i; 18 | vals_i_minus_one: ptr = ptradd vals i_minus_one; 19 | vals_i_minus_two: ptr = ptradd vals i_minus_two; 20 | tmp: int = load vals_i_minus_one; 21 | tmp2: int = load vals_i_minus_two; 22 | tmp: int = add tmp tmp2; 23 | store vals_i tmp; 24 | i: int = add i one; 25 | i_minus_one: int = add i_minus_one one; 26 | i_minus_two: int = add i_minus_two one; 27 | jmp .loop; 28 | .done: 29 | last: ptr = ptradd vals i_minus_one; 30 | tmp: int = load last; 31 | print tmp; 32 | free vals; 33 | ret; 34 | } 35 | -------------------------------------------------------------------------------- /tests/passing/brils/mem/test-fib.out: -------------------------------------------------------------------------------- 1 | 34 2 | -------------------------------------------------------------------------------- /tests/passing/brils/rs2bril-example.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 50 2.0 true 2 | fn main(x: i64, f: f64, b: bool) { 3 | let ptr: [i64; 2] = [0, 0]; 4 | let x: i64 = -1; 5 | let y: bool = !(!true); 6 | let z: f64 = -0.0; 7 | z = -1.0; 8 | f = 5.0; 9 | f /= 2.0; 10 | ptr[0] = 1; 11 | ptr[1] = ptr[2 + x]; 12 | 13 | let foo: i64 = test2(1, 2); 14 | test3(); 15 | 16 | let test: [i64; 2] = [0, 1]; 17 | let test2: [[i64; 2]; 1] = [test]; 18 | let test3: [f64; 10] = [z; 10]; 19 | 20 | if true { 21 | let cond: i64 = 0; 22 | while cond < 2 { 23 | cond += 1; 24 | } 25 | } else { 26 | if true { 27 | let cond2: bool = false; 28 | while cond2 {} 29 | } 30 | } 31 | 32 | drop(test); 33 | drop(test2); 34 | drop(test3); 35 | drop(ptr); 36 | println!("{}", x); 37 | } 38 | 39 | fn test2(x: i64, y: i64) -> i64 { 40 | return x; 41 | } 42 | 43 | fn test3() { 44 | return; 45 | } 46 | -------------------------------------------------------------------------------- /tests/passing/other/do_while_if.bril: -------------------------------------------------------------------------------- 1 | 2 | @main() { 3 | i: int = const 6; 4 | 5 | .top: 6 | c: int = const 9; 7 | 8 | 9 | b: int = const 9; 10 | if_cond: bool = le i b; 11 | br if_cond .then_if .else_if; 12 | .then_if: 13 | one: int = const 1; 14 | print one; 15 | jmp .end_if; 16 | .else_if: 17 | two: int = const 2; 18 | print two; 19 | .end_if: 20 | 21 | one: int = const 1; 22 | i: int = add i one; 23 | 24 | loop_cond: bool = lt i c; 25 | br loop_cond .top .end; 26 | .end: 27 | 28 | print i; 29 | } -------------------------------------------------------------------------------- /tests/passing/other/eliminate_gamma_false.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 1; 3 | b: int = const 2; 4 | condition: bool = lt b a; 5 | br condition .then .else; 6 | .then: 7 | thenval: int = const 1; 8 | print thenval; 9 | jmp .end; 10 | .else: 11 | elseval: int = const 2; 12 | print elseval; 13 | jmp .end; 14 | .end: 15 | } 16 | -------------------------------------------------------------------------------- /tests/passing/other/odd_control_flow.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | in1: int = const 1; 3 | in2: int = const 2; 4 | four: int = const 4; 5 | a: bool = lt in1 four; 6 | br a .N .B; 7 | .N: 8 | br a .A .B; 9 | .A: 10 | y: int = const 6; 11 | jmp .end; 12 | .B: 13 | y: int = const 7; 14 | jmp .end; 15 | .end: 16 | print y; 17 | } -------------------------------------------------------------------------------- /tests/passing/other/repro-directjumps.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | .entry: 3 | a: int = const 0; 4 | c: int = call @inc a; 5 | print c; 6 | ret; 7 | } 8 | @inc(x: int): int { 9 | .entry: 10 | max: int = const 2; 11 | cond: bool = lt x max; 12 | br cond .sblock1 .sblock2; 13 | .sblock1: 14 | .recurse: 15 | one: int = const 1; 16 | x: int = add one x; 17 | print x; 18 | x: int = call @inc x; 19 | jmp .sblock3; 20 | .sblock2: 21 | .sblock3: 22 | .sblock0: 23 | .done: 24 | ret x; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /tests/passing/other/repro-forgotprint.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(arg: int) { 3 | one: int = const 1; 4 | two: int = const 2; 5 | x: int = const 0; 6 | a_cond: bool = lt arg two; 7 | br a_cond .A .B; 8 | .A: 9 | x: int = const 1; 10 | print two; 11 | jmp .end; 12 | .B: 13 | x: int = const 2; 14 | jmp .end; 15 | .end: 16 | x: int = add x one; 17 | } -------------------------------------------------------------------------------- /tests/passing/other/repro-if-conversion-region.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | size: int = const 10; 3 | mem1: ptr = alloc size; 4 | one: int = const 1; 5 | two: int = const 2; 6 | three: int = const 3; 7 | mem2: ptr = ptradd mem1 one; 8 | store mem2 two; 9 | cond: bool = const true; 10 | br cond .outerthen .outerelse; 11 | .outerthen: 12 | br cond .thenbranch .elsebranch; 13 | # else shares same effect as elsebranch 14 | .outerelse: 15 | store mem2 three; 16 | jmp .end; 17 | .thenbranch: 18 | store mem1 one; 19 | jmp .end; 20 | .elsebranch: 21 | store mem2 three; 22 | jmp .end; 23 | .end: 24 | atmem1: int = load mem1; 25 | atmem2: int = load mem2; 26 | print atmem1; 27 | print atmem2; 28 | free mem1; 29 | ret; 30 | } 31 | -------------------------------------------------------------------------------- /tests/passing/other/unroll_and_constant_fold_three.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | i: int = const 0; 3 | one: int = const 1; 4 | three: int = const 3; 5 | .loop: 6 | i: int = add i one; 7 | cond: bool = lt i three; 8 | br cond .loop .done; 9 | .done: 10 | print i; 11 | } 12 | -------------------------------------------------------------------------------- /tests/passing/other/unstructured.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 0 2 | @main(input: int) { 3 | one: int = const 1; 4 | x: int = const 4; 5 | a_cond: bool = lt x x; 6 | br a_cond .B .C; 7 | .B: 8 | a: int = const 1; 9 | b_cond: bool = lt x one; 10 | br b_cond .C .D; 11 | .C: 12 | z: int = const 1; 13 | jmp .B; 14 | .D: 15 | ret; 16 | } -------------------------------------------------------------------------------- /tests/passing/small/add.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 1; 3 | v1: int = const 2; 4 | v2: int = add v0 v1; 5 | print v2; 6 | } 7 | -------------------------------------------------------------------------------- /tests/passing/small/add_block_indirection.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | .entry: 3 | v0: int = const 1; 4 | .second: 5 | v1: int = const 2; 6 | v2: int = add v0 v1; 7 | .end: 8 | print v2; 9 | } 10 | -------------------------------------------------------------------------------- /tests/passing/small/block-diamond.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(arg: int) { 3 | one: int = const 1; 4 | two: int = const 2; 5 | five: int = const 5; 6 | x: int = const 0; 7 | a_cond: bool = lt arg two; 8 | br a_cond .B .D; 9 | .B: 10 | b_cond: bool = lt arg five; 11 | x: int = add x two; 12 | br b_cond .C .E; 13 | .C: 14 | x: int = add x two; 15 | jmp .F; 16 | .D: 17 | x: int = add x one; 18 | jmp .E; 19 | .E: 20 | x: int = add x two; 21 | jmp .F; 22 | .F: 23 | x: int = add x one; 24 | print x; 25 | ret; 26 | } -------------------------------------------------------------------------------- /tests/passing/small/bool.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | cond: bool = const true; 3 | print cond; 4 | } -------------------------------------------------------------------------------- /tests/passing/small/branch_duplicate_work.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(x: int) { 3 | two: int = const 2; 4 | isless: bool = lt x two; 5 | br isless .less .greater; 6 | .less: 7 | result: int = add x x; 8 | jmp .done; 9 | .greater: 10 | double: int = add x x; 11 | result: int = mul double two; 12 | .done: 13 | print result; 14 | } 15 | -------------------------------------------------------------------------------- /tests/passing/small/collatz_redundant_computation.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 8888 2 | @main (arg : int) { 3 | three : int = const 3; 4 | two : int = const 2; 5 | one : int = const 1; 6 | zero : int = const 0; 7 | var : int = id arg; 8 | .cond: 9 | cond : bool = eq var one; 10 | br cond .break .body; 11 | .body: 12 | d : int = div var two; 13 | m : int = mul d two; 14 | mod : int = sub var m; 15 | cond : bool = eq mod zero; 16 | print var; 17 | var_then : int = div var two; 18 | v1_else : int = mul three var; 19 | var_else : int = add one v1_else; 20 | br cond .then .else; 21 | .then: 22 | var : int = id var_then; 23 | jmp .cond; 24 | .else: 25 | var : int = id var_else; 26 | jmp .cond; 27 | .break: 28 | print arg; 29 | } 30 | -------------------------------------------------------------------------------- /tests/passing/small/constant_fold_simple.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | v0: int = const 1; 3 | v1: int = const 2; 4 | # 1*2 = 2 5 | v2: int = mul v0 v1; 6 | # 1+2 = 3 7 | v3: int = add v0 v1; 8 | # 3/2 = 1 9 | v4: int = div v3 v2; 10 | print v4; 11 | } 12 | -------------------------------------------------------------------------------- /tests/passing/small/diamond.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 3 2 | @main(x: int) { 3 | cond: bool = lt x x; 4 | br cond .B .C; 5 | .B: 6 | a: int = const 1; 7 | print a; 8 | jmp .D; 9 | .C: 10 | a: int = const 2; 11 | print a; 12 | jmp .D; 13 | .D: 14 | ret; 15 | } -------------------------------------------------------------------------------- /tests/passing/small/double-for.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 20 2 | @main(loop_bound: int) { 3 | loop_incr: int = const 1; 4 | loop_counter: int = const 10; 5 | final_output: int = const 0; 6 | .loop_cond: 7 | loop_cond: bool = lt loop_counter loop_bound; 8 | br loop_cond .loop_body .loop_done; 9 | .loop_body: 10 | inner_counter: int = const 10; 11 | .inner_cond: 12 | inner_cond: bool = lt inner_counter loop_bound; 13 | br inner_cond .inner_body .inner_done; 14 | .inner_body: 15 | output: int = add loop_counter inner_counter; 16 | final_output: int = add final_output output; 17 | inner_counter: int = add inner_counter loop_incr; 18 | jmp .inner_cond; 19 | .inner_done: 20 | loop_counter: int = add loop_counter loop_incr; 21 | jmp .loop_cond; 22 | .loop_done: 23 | print final_output; 24 | } -------------------------------------------------------------------------------- /tests/passing/small/duplicate_branch.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 5 2 | @main(y: int) { 3 | x: int = const 4; 4 | cond: bool = lt x y; 5 | br cond .B .C; 6 | .B: 7 | a: int = const 1; 8 | jmp .D; 9 | .C: 10 | a: int = const 1; 11 | jmp .B; 12 | .D: 13 | print x; 14 | ret; 15 | } -------------------------------------------------------------------------------- /tests/passing/small/eliminate_gamma.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 1; 3 | b: int = const 2; 4 | condition: bool = lt a b; 5 | br condition .then .else; 6 | .then: 7 | thenval: int = const 1; 8 | print thenval; 9 | jmp .end; 10 | .else: 11 | elseval: int = const 2; 12 | print elseval; 13 | jmp .end; 14 | .end: 15 | } 16 | -------------------------------------------------------------------------------- /tests/passing/small/eliminate_gamma_interval.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(input: int) { 3 | ten: int = const 10; 4 | five: int = const 5; 5 | cond1: bool = lt input ten; 6 | br cond1 .then .else; 7 | .then: 8 | x: int = const 2; 9 | y: int = add x five; 10 | jmp .end; 11 | .else: 12 | x: int = const 3; 13 | y: int = const 3; 14 | jmp .end; 15 | .end: 16 | z: bool = lt ten y; 17 | print z; 18 | } -------------------------------------------------------------------------------- /tests/passing/small/eliminate_loop.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | .loop: 3 | one: int = const 1; 4 | three: int = const 3; 5 | cond: bool = lt three one; 6 | br cond .loop .done; 7 | .done: 8 | print one; 9 | } 10 | -------------------------------------------------------------------------------- /tests/passing/small/fib-2.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 100000 2 | 3 | @main(input : int) { 4 | zero: int = const 0; 5 | one: int = const 1; 6 | vals: ptr = alloc input; 7 | store vals zero; 8 | vals_i: ptr = ptradd vals one; 9 | store vals_i one; 10 | i: int = const 2; 11 | .loop: 12 | cond: bool = lt i input; 13 | br cond .body .done; 14 | .body: 15 | neg_one: int = const -1; 16 | neg_two: int = const -2; 17 | vals_i: ptr = ptradd vals i; 18 | vals_i_minus_one: ptr = ptradd vals_i neg_one; 19 | vals_i_minus_two: ptr = ptradd vals_i neg_two; 20 | tmp: int = load vals_i_minus_one; 21 | tmp2: int = load vals_i_minus_two; 22 | tmp: int = add tmp tmp2; 23 | store vals_i tmp; 24 | i: int = add i one; 25 | jmp .loop; 26 | .done: 27 | last_plus_one: ptr = ptradd vals i; 28 | neg_one_: int = const -1; 29 | last: ptr = ptradd last_plus_one neg_one_; 30 | tmp: int = load last; 31 | free vals; 32 | print tmp; 33 | } 34 | -------------------------------------------------------------------------------- /tests/passing/small/fib_recursive.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | two: int = const 2; 3 | result: int = call @fac two; 4 | print result; 5 | } 6 | 7 | @fac(i: int): int { 8 | zero: int = const 0; 9 | one: int = const 1; 10 | 11 | is_zero: bool = eq i zero; 12 | br is_zero .base.zero .recurse; 13 | 14 | .base.zero: 15 | ret one; 16 | 17 | .recurse: 18 | is_one: bool = eq i one; 19 | br is_one .base.one .general; 20 | 21 | .base.one: 22 | result: int = call @fac zero; 23 | ret one; 24 | 25 | .general: 26 | prev_i: int = sub i one; 27 | prev: int = call @fac prev_i; 28 | 29 | prev_prev_i: int = sub prev_i one; 30 | prev_prev: int = call @fac prev_prev_i; 31 | 32 | result: int = add prev prev_prev; 33 | ret result; 34 | } 35 | -------------------------------------------------------------------------------- /tests/passing/small/fib_shape.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 10 2 | @main(input: int) { 3 | one: int = const 1; 4 | i: int = const 0; 5 | .loop: 6 | cond: bool = lt i input; 7 | br cond .body .done; 8 | .body: 9 | i: int = add i one; 10 | bodyvar: int = const 1; 11 | jmp .loop; 12 | .done: 13 | donebody: int = const 1; 14 | print i; 15 | } 16 | -------------------------------------------------------------------------------- /tests/passing/small/five_call_nestings.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | call @one; 3 | } 4 | 5 | @one { 6 | call @two; 7 | } 8 | 9 | @two { 10 | call @three; 11 | } 12 | 13 | @three { 14 | call @four; 15 | } 16 | 17 | @four { 18 | four: int = const 4; 19 | print four; 20 | } -------------------------------------------------------------------------------- /tests/passing/small/flatten_loop.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 10 10 2 | @main(N: int, M: int) { 3 | one: int = const 1; 4 | i: int = const 0; 5 | 6 | .outer_cond: 7 | cond: bool = lt i N; 8 | br cond .inner_start .done; 9 | 10 | .inner_start: 11 | j: int = const 0; 12 | .inner_cond: 13 | cond: bool = lt j M; 14 | br cond .inner_body .outer_body; 15 | 16 | .inner_body: 17 | i_times_m: int = mul i M; 18 | plus_j: int = add i_times_m j; 19 | print plus_j; 20 | 21 | j: int = add j one; 22 | jmp .inner_cond; 23 | 24 | .outer_body: 25 | i: int = add i one; 26 | jmp .outer_cond; 27 | 28 | .done: 29 | print i; 30 | } 31 | -------------------------------------------------------------------------------- /tests/passing/small/four_call_nestings.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | call @one; 3 | } 4 | 5 | @one { 6 | call @two; 7 | } 8 | 9 | @two { 10 | call @three; 11 | } 12 | 13 | @three { 14 | three: int = const 3; 15 | print three; 16 | } -------------------------------------------------------------------------------- /tests/passing/small/gamma_condition_and.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(x: int) { 3 | zero: int = const 0; 4 | one: int = const 1; 5 | 6 | a: bool = lt x zero; 7 | b: bool = gt x zero; 8 | c: bool = and a b; 9 | br c .A .B; 10 | 11 | .A: 12 | x: int = const 1; 13 | jmp .C; 14 | 15 | .B: 16 | d: bool = lt x zero; 17 | e: bool = gt x zero; 18 | f: bool = and d e; 19 | br f .X .Y; 20 | 21 | .X: 22 | x: int = const 2; 23 | .top: 24 | x: int = add x one; 25 | g: bool = gt x zero; 26 | br g .C .top; 27 | 28 | .Y: 29 | x: int = const 3; 30 | 31 | .C: 32 | print x; 33 | } 34 | -------------------------------------------------------------------------------- /tests/passing/small/gamma_pull_in.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(input: int) { 3 | ten: int = const 10; 4 | cond: bool = lt input ten; 5 | br cond .then .else; 6 | .then: 7 | x: int = const 2; 8 | jmp .second; 9 | .else: 10 | x: int = const 3; 11 | jmp .second; 12 | .second: 13 | y: int = add x x; 14 | print y; 15 | jmp .end; 16 | .end: 17 | } -------------------------------------------------------------------------------- /tests/passing/small/if_constant_fold.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(input: int) { 3 | zero: int = const 0; 4 | one: int = const 1; 5 | cond: bool = lt zero one; 6 | br cond .then .else; 7 | .then: 8 | x: int = const 3; 9 | jmp .second; 10 | .else: 11 | x: int = const 4; 12 | jmp .second; 13 | .second: 14 | five: int = const 5; 15 | ten: int = const 10; 16 | cond2: bool = lt ten five; 17 | br cond2 .then2 .else2; 18 | .then2: 19 | y: int = const 5; 20 | jmp .end; 21 | .else2: 22 | y: int = const 6; 23 | jmp .end; 24 | .end: 25 | print x; 26 | print y; 27 | } -------------------------------------------------------------------------------- /tests/passing/small/if_constant_fold2.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(arg: int) { 3 | four: int = const 4; 4 | twenty: int = const 20; 5 | five: int = const 5; 6 | cond1: bool = eq arg five; 7 | br cond1 .then1 .else1; 8 | .then1: 9 | z: int = mul four arg; 10 | jmp .end; 11 | .else1: 12 | cond2: bool = eq arg four; 13 | br cond2 .then2 .else2; 14 | .then2: 15 | z: int = mul five arg; 16 | jmp .end; 17 | .else2: 18 | z: int = id twenty; 19 | jmp .end; 20 | .end: 21 | print z; 22 | ret; 23 | } 24 | -------------------------------------------------------------------------------- /tests/passing/small/if_context.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 20 2 | fn main(x: i64) { 3 | let res: i64 = 0; 4 | if (x == 3) { 5 | res = x; 6 | } else { 7 | res = x * 3; 8 | } 9 | println!("{}", res); 10 | } 11 | -------------------------------------------------------------------------------- /tests/passing/small/if_context2.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(input: int) { 3 | zero: int = const 0; 4 | cond: bool = le input zero; 5 | br cond .then .else; 6 | .then: 7 | y: int = id input; 8 | jmp .end; 9 | .else: 10 | neg: int = const -1; 11 | y: int = mul input neg; 12 | jmp .end; 13 | .end: 14 | z: bool = le y zero; 15 | print z; 16 | } -------------------------------------------------------------------------------- /tests/passing/small/if_dead_code.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(arg: int) { 3 | zero: int = const 0; 4 | isless: bool = lt arg zero; 5 | br isless .less .greater; 6 | .less: 7 | result: int = const 1; 8 | result_predicate: bool = const true; 9 | jmp .done; 10 | .greater: 11 | result: int = const 0; 12 | result_predicate: bool = const false; 13 | .done: 14 | print result; 15 | print result_predicate; 16 | } 17 | -------------------------------------------------------------------------------- /tests/passing/small/if_in_loop.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(arg: int) { 3 | minus_one: int = const -1; 4 | zero: int = const 0; 5 | one: int = const 1; 6 | two: int = const 2; 7 | three: int = const 3; 8 | ten: int = const 10; 9 | 10 | i: int = id zero; 11 | .loop_top: 12 | loop_pred: bool = lt i ten; 13 | 14 | isless: bool = le arg zero; 15 | br isless .less .greater; 16 | .less: 17 | result: int = const 1; 18 | result_predicate: bool = const true; 19 | jmp .done; 20 | .greater: 21 | result: int = const 0; 22 | result_predicate: bool = const false; 23 | 24 | .done: 25 | print result; 26 | print result_predicate; 27 | 28 | i: int = add i one; 29 | br loop_pred .loop_top .loop_bottom; 30 | .loop_bottom: 31 | } 32 | -------------------------------------------------------------------------------- /tests/passing/small/if_interval.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(input: int) { 3 | zero: int = const 0; 4 | cond: bool = le input zero; 5 | br cond .then .else; 6 | .then: 7 | x: int = id zero; 8 | jmp .end; 9 | .else: 10 | x: int = const 3; 11 | jmp .end; 12 | .end: 13 | ten: int = const 10; 14 | z: bool = lt x ten; 15 | print z; 16 | } 17 | -------------------------------------------------------------------------------- /tests/passing/small/if_invariant_do_pull_out.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 20 2 | fn unrelated_fn(input: i64) -> i64 { 3 | return input / 4; 4 | } 5 | 6 | fn other_unrelated_fn(input: i64) -> i64 { 7 | return (input * 3) / 5; 8 | } 9 | 10 | fn main(input: i64) { 11 | let mut res: i64 = abs(input) * 2; 12 | 13 | if (input > 0) { 14 | res = res + abs(input); 15 | res = res + unrelated_fn(input); 16 | } else { 17 | res = res + abs(input); 18 | res = res + other_unrelated_fn(input); 19 | } 20 | 21 | println!("{}", res); 22 | } 23 | -------------------------------------------------------------------------------- /tests/passing/small/if_invariant_dont_pull_out.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 20 2 | fn unrelated_fn(input: i64, res: i64) -> i64 { 3 | return input / (res / 3); 4 | } 5 | 6 | fn other_unrelated_fn(input: i64, res: i64) -> i64 { 7 | return res / (input / 5); 8 | } 9 | 10 | fn main(input: i64) { 11 | let mut res: i64 = abs(input) * 2; 12 | 13 | if (input > 0) { 14 | res = res + abs(input) - input; 15 | res = unrelated_fn(input, res); 16 | } else { 17 | res = res + abs(input) + input; 18 | res = other_unrelated_fn(input, res); 19 | } 20 | 21 | println!("{}", res); 22 | } 23 | -------------------------------------------------------------------------------- /tests/passing/small/if_push_in.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 20 2 | fn main(input: i64) { 3 | let a: i64 = input * 2; 4 | if (input > 0) { 5 | let x: i64 = a * 5; 6 | } else { 7 | let x: i64 = a * -3; 8 | } 9 | 10 | if (x >= 0) { 11 | let res: i64 = x * 10; 12 | } else { 13 | let res: i64 = x * 37; 14 | } 15 | 16 | println!("{}", res); 17 | } 18 | -------------------------------------------------------------------------------- /tests/passing/small/implicit-return.bril: -------------------------------------------------------------------------------- 1 | # exerpted from the 'pow' benchmark 2 | @main { 3 | # use integers instead of floats 4 | v0: int = const 4; 5 | x: int = id v0; 6 | v1: int = const 15; 7 | n: int = id v1; 8 | v2: int = id x; 9 | v3: int = id n; 10 | call @pow v2 v3; 11 | v4: int = const 0; 12 | } 13 | 14 | @pow(x: int, n: int) { 15 | v0: int = id x; 16 | res: int = id v0; 17 | v2: int = const 0; 18 | _i: int = id v2; 19 | .for.cond.1: 20 | v3: int = id _i; 21 | v4: int = id n; 22 | v5: int = const 1; 23 | v6: int = sub v4 v5; 24 | v7: bool = lt v3 v6; 25 | br v7 .for.body.1 .for.end.1; 26 | .for.body.1: 27 | v8: int = id res; 28 | v9: int = id x; 29 | v10: int = mul v8 v9; 30 | res: int = id v10; 31 | v11: int = id _i; 32 | v12: int = const 1; 33 | v13: int = add v11 v12; 34 | _i: int = id v13; 35 | jmp .for.cond.1; 36 | .for.end.1: 37 | v14: int = id res; 38 | print v14; 39 | v15: int = const 0; 40 | } 41 | -------------------------------------------------------------------------------- /tests/passing/small/impossible_if.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(arg: int) { 3 | one: int = const 1; 4 | two: int = const 2; 5 | outer_cond: bool = lt arg two; 6 | br outer_cond .THEN .ELSE; 7 | .THEN: 8 | inner_cond: bool = lt arg two; 9 | br inner_cond .A .B; 10 | .A: 11 | print one; 12 | jmp .END; 13 | .B: 14 | print two; 15 | jmp .END; 16 | .ELSE: 17 | print one; 18 | jmp .END; 19 | .END: 20 | print one; 21 | ret; 22 | } 23 | -------------------------------------------------------------------------------- /tests/passing/small/ivt.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 20 2 | 3 | fn main(max: i64) { 4 | let mut i: i64 = 0; 5 | let unrelated: i64 = 20; 6 | while (i < max) { 7 | println!("{}", i); 8 | i += 1; 9 | } 10 | println!("{}", unrelated); 11 | } 12 | -------------------------------------------------------------------------------- /tests/passing/small/jumping_loop.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | jump: int = const 4; 3 | i: int = const 0; 4 | n: int = const 18; 5 | 6 | .loop: 7 | i: int = add jump i; 8 | pred: bool = lt i n; 9 | br pred .loop .end; 10 | 11 | .end: 12 | } -------------------------------------------------------------------------------- /tests/passing/small/loop_hoist.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 3 4 2 | @main(arg1 : int, arg2 : int, arg3 : int, arg4 : int) { 3 | .entry: 4 | zero: int = const 0; 5 | sub: int = sub arg3 arg2; 6 | inv: int = add sub zero; 7 | arg1: int = add arg1 inv; 8 | print inv; 9 | pred : bool = lt arg1 arg4; 10 | br pred .done .entry; 11 | .done: 12 | print arg1; 13 | } -------------------------------------------------------------------------------- /tests/passing/small/loop_if.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | y: int = const 0; 3 | x: int = const 0; 4 | .entry: 5 | iseq: bool = eq y x; 6 | br iseq .else .then; 7 | .then: 8 | one: int = const 1; 9 | x: int = add x one; 10 | y: int = add y one; 11 | jmp .tail; 12 | .else: 13 | two: int = const 2; 14 | jmp .tail; 15 | .tail: 16 | br iseq .done .entry; 17 | .done: 18 | print x; 19 | } -------------------------------------------------------------------------------- /tests/passing/small/loop_pass_through.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 5 2 | @main(input: int) { 3 | i: int = const 1; 4 | jmp .loop; 5 | .loop: 6 | max: int = const 10; 7 | cond: bool = lt i max; 8 | i: int = add i i; 9 | br cond .loop .exit; 10 | .exit: 11 | res: int = add i input; 12 | print res; 13 | } 14 | -------------------------------------------------------------------------------- /tests/passing/small/loop_with_mul_by_inv.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 4 2 | @main (n: int) { 3 | accum: int = const 0; 4 | x: int = const 5; 5 | i: int = const 0; 6 | 7 | .loop: 8 | one: int = const 1; 9 | 10 | cond: bool = lt i n; 11 | g: int = mul i x; 12 | accum: int = add g accum; 13 | 14 | i: int = add one i; 15 | br cond .loop .end; 16 | 17 | .end: 18 | print accum; 19 | } -------------------------------------------------------------------------------- /tests/passing/small/lowbit.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 21324 2 | // Compute the lowest 1 bit of an integer 3 | fn main(n:i64) { 4 | let mut lb : i64 = n & (-n); 5 | println!("{}", lb); 6 | } -------------------------------------------------------------------------------- /tests/passing/small/lowbit_br.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 21324 2 | 3 | @main (a: int) { 4 | t: int = neg a; 5 | lb: int = bitand a t; 6 | print lb; 7 | } -------------------------------------------------------------------------------- /tests/passing/small/lowbit_naive.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 21324 2 | // Compute the lowest 1 bit of an integer in the naive way 3 | fn main(a:i64) { 4 | let mut n : i64 = a; 5 | let mut lb : i64 = 1; 6 | while (n == n / 2 * 2) { 7 | n = n / 2; 8 | lb = lb * 2; 9 | } 10 | println!("{}", lb); 11 | } 12 | -------------------------------------------------------------------------------- /tests/passing/small/lowbit_naive_br.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 21324 2 | 3 | @main (a: int) { 4 | lb: int = const 1; 5 | two: int = const 2; 6 | 7 | .loop: 8 | t0: int = div a two; 9 | t1: int = mul t0 two; 10 | cond: bool = eq t1 a; 11 | br cond .cont .end; 12 | 13 | .cont: 14 | a: int = div a two; 15 | lb: int = mul lb two; 16 | jmp .loop; 17 | 18 | .end: 19 | print lb; 20 | } 21 | -------------------------------------------------------------------------------- /tests/passing/small/lowbit_naive_extra.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 21324 2 | // Compute the lowest 1 bit of an integer in the naive way 3 | // Added x to test the state-edge passthrough 4 | fn main(a:i64) { 5 | let mut n : i64 = a; 6 | let mut lb : i64 = 1; 7 | let mut x : i64 = 0; 8 | while (n == n / 2 * 2) { 9 | n = n / 2; 10 | lb = lb * 2; 11 | x = x + 1; 12 | } 13 | println!("{}", lb); 14 | println!("{}", x); 15 | } 16 | -------------------------------------------------------------------------------- /tests/passing/small/max.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 20 30 2 | @main(x: int, y: int) { 3 | cmp: bool = gt x y; 4 | one: int = const 1; 5 | br cmp .then .else; 6 | .then: 7 | res: int = id x; 8 | jmp .done; 9 | .else: 10 | res: int = id y; 11 | jmp .done; 12 | .done: 13 | print res; 14 | } -------------------------------------------------------------------------------- /tests/passing/small/mem_loop_store_forwarding.bril: -------------------------------------------------------------------------------- 1 | # ARGS: false 2 | @main(cond: bool) { 3 | one: int = const 1; 4 | two: int = const 2; 5 | three: int = const 3; 6 | p: ptr = alloc three; 7 | q: ptr = ptradd p one; 8 | r: ptr = ptradd p two; 9 | jmp .loop; 10 | .loop: 11 | tmp: ptr = id p; 12 | p: ptr = id q; 13 | q: ptr = id tmp; 14 | br cond .loop .done; 15 | .done: 16 | ten: int = const 10; 17 | twenty: int = const 20; 18 | store p ten; 19 | store r twenty; 20 | res: int = load p; 21 | print res; 22 | free q; 23 | ret; 24 | } 25 | -------------------------------------------------------------------------------- /tests/passing/small/mem_simple_redundant_load.bril: -------------------------------------------------------------------------------- 1 | # ARGS: false 2 | @main(cond: bool) { 3 | one: int = const 1; 4 | p: ptr = alloc one; 5 | br cond .t .f; 6 | .t: 7 | two: int = const 2; 8 | store p two; 9 | jmp .done; 10 | .f: 11 | three: int = const 3; 12 | store p three; 13 | .done: 14 | load1: int = load p; 15 | load2: int = load p; 16 | print load2; 17 | free p; 18 | ret; 19 | } 20 | -------------------------------------------------------------------------------- /tests/passing/small/mem_simple_store_forwarding.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | one: int = const 1; 3 | two: int = const 2; 4 | ten: int = const 10; 5 | twenty: int = const 20; 6 | p: ptr = alloc two; 7 | q: ptr = ptradd p one; 8 | store p ten; 9 | store q twenty; 10 | res: int = load p; 11 | print res; 12 | free p; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /tests/passing/small/min.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 20 30 2 | @main(x: int, y: int) { 3 | cmp: bool = lt x y; 4 | res: int = id y; 5 | br cmp .then .else; 6 | .then: 7 | res: int = id x; 8 | .else: 9 | .done: 10 | print res; 11 | } -------------------------------------------------------------------------------- /tests/passing/small/nested_call.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 0; 3 | b: int = call @inc a; 4 | print b; 5 | 6 | c: int = const 1; 7 | c: int = call @double c; 8 | print c; 9 | } 10 | 11 | @inc (x: int): int { 12 | one: int = const 1; 13 | x: int = add one x; 14 | x: int = call @double x; 15 | ret x; 16 | } 17 | 18 | @double (x: int): int { 19 | two: int = const 2; 20 | res: int = mul two x; 21 | ret res; 22 | } 23 | -------------------------------------------------------------------------------- /tests/passing/small/peel_twice.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | i: int = const 0; 3 | one: int = const 1; 4 | two: int = const 2; 5 | 6 | .loop: 7 | i: int = add one i; 8 | cond: bool = lt i two; 9 | br cond .loop .loop_end; 10 | 11 | .loop_end: 12 | print i; 13 | } 14 | -------------------------------------------------------------------------------- /tests/passing/small/peel_twice_precalc_pred.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | i: int = const 0; 3 | one: int = const 1; 4 | 5 | .loop: 6 | cond: bool = lt i one; 7 | i: int = add one i; 8 | br cond .loop .loop_end; 9 | 10 | .loop_end: 11 | print i; 12 | } -------------------------------------------------------------------------------- /tests/passing/small/peggy_comparison/branch_hoisting.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 0 2 | @main(n: int) { 3 | zero: int = const 0; 4 | x: int = id zero; 5 | y: int = id zero; 6 | fivehundred: int = const 500; 7 | 8 | .pred: 9 | whilecond: bool = lt y fivehundred; 10 | br whilecond .loopbody .end; 11 | 12 | .loopbody: 13 | two: int = const 2; 14 | ifcond: bool = eq n zero; 15 | br ifcond .thn .els; 16 | 17 | .thn: 18 | x: int = mul y two; 19 | jmp .ifend; 20 | 21 | .els: 22 | three: int = const 3; 23 | x: int = mul y three; 24 | 25 | .ifend: 26 | one: int = const 1; 27 | y: int = add one y; 28 | 29 | jmp .pred; 30 | 31 | .end: 32 | print x; 33 | } -------------------------------------------------------------------------------- /tests/passing/small/peggy_comparison/conditional_constant_folding.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 4 2 | @main(x: int) { 3 | five: int = const 5; 4 | four: int = const 4; 5 | twenty: int = const 20; 6 | cond: bool = eq x five; 7 | br cond .if .else_if_check; 8 | 9 | .if: 10 | res: int = mul four x; 11 | jmp .end; 12 | 13 | .else_if_check: 14 | cond: bool = eq x four; 15 | br cond .else_if .else; 16 | jmp .end; 17 | 18 | .else_if: 19 | res: int = mul five x; 20 | jmp .end; 21 | 22 | .else: 23 | res: int = id twenty; 24 | jmp .end; 25 | 26 | .end: 27 | print res; 28 | } -------------------------------------------------------------------------------- /tests/passing/small/peggy_comparison/dead_loop_deletion.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | j: int = const 3; 3 | i: int = const 0; 4 | forty: int = const 40; 5 | one: int = const 1; 6 | 7 | .loop_test: 8 | cond: bool = lt i forty; 9 | br cond .loop_body .loop_end; 10 | 11 | .loop_body: 12 | j: int = add j one; 13 | i: int = add i one; 14 | jmp .loop_test; 15 | 16 | .loop_end: 17 | j: int = const 2; 18 | 19 | print j; 20 | } -------------------------------------------------------------------------------- /tests/passing/small/peggy_comparison/if_true.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 20 2 | @main(x: int) { 3 | cond: bool = const true; 4 | br cond .thn .els; 5 | 6 | .thn: 7 | print x; 8 | 9 | .els: 10 | one: int = const 1; 11 | res: int = sub x one; 12 | print res; 13 | } -------------------------------------------------------------------------------- /tests/passing/small/peggy_comparison/loop_based_code_motion.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | x: int = const 0; 3 | three: int = const 3; 4 | 5 | .loop_test: 6 | cond: bool = lt x three; 7 | br cond .loop_body .loop_end; 8 | 9 | .loop_body: 10 | one: int = const 1; 11 | x: int = add x one; 12 | jmp .loop_test; 13 | 14 | .loop_end: 15 | five: int = const 5; 16 | x: int = mul x five; 17 | 18 | print x; 19 | } -------------------------------------------------------------------------------- /tests/passing/small/peggy_comparison/loop_invariant_code_motion.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 30 10 2 | @main(n: int, m: int) { 3 | i: int = const 0; 4 | twenty: int = const 20; 5 | one: int = const 1; 6 | 7 | .loop_test: 8 | cond: bool = lt i twenty; 9 | br cond .loop_body .loop_end; 10 | 11 | .loop_body: 12 | j: int = mul n twenty; 13 | if_cond: bool = lt j m; 14 | br if_cond .thn .end_if; 15 | 16 | .thn: 17 | j: int = add j one; 18 | 19 | .end_if: 20 | output: int = mul i j; 21 | print output; 22 | i: int = add i one; 23 | jmp .loop_test; 24 | 25 | .loop_end: 26 | } -------------------------------------------------------------------------------- /tests/passing/small/peggy_comparison/loop_peeling.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 5 2 | @main(n: int) { 3 | x: int = const 0; 4 | i: int = const 0; 5 | 6 | .loop_test: 7 | cond: bool = lt i n; 8 | br cond .loop_body .loop_end; 9 | 10 | .loop_body: 11 | five: int = const 5; 12 | one: int = const 1; 13 | x: int = add x five; 14 | i: int = add i one; 15 | jmp .loop_test; 16 | 17 | .loop_end: 18 | print x; 19 | } -------------------------------------------------------------------------------- /tests/passing/small/peggy_comparison/loop_strength_reduction.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | i: int = const 0; 3 | d: int = const 0; 4 | three_hundred: int = const 300; 5 | five: int = const 5; 6 | one: int = const 1; 7 | 8 | .loop_test: 9 | cond: bool = lt d three_hundred; 10 | br cond .loop_body .loop_end; 11 | 12 | .loop_body: 13 | out: int = mul i five; 14 | print out; 15 | 16 | i: int = add i one; 17 | d: int = add d one; 18 | jmp .loop_test; 19 | 20 | .loop_end: 21 | } -------------------------------------------------------------------------------- /tests/passing/small/peggy_comparison/loop_strength_reduction_modified.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | i: int = const 0; 3 | d: int = const 0; 4 | three_hundred: int = const 300; 5 | three: int = const 3; 6 | five: int = const 5; 7 | one: int = const 1; 8 | one_hundred_fifty: int = const 150; 9 | 10 | .loop_test: 11 | cond: bool = lt d three_hundred; 12 | br cond .loop_body .loop_end; 13 | 14 | .loop_body: 15 | out: int = mul i five; 16 | print out; 17 | 18 | i: int = add i one; 19 | if_cond: bool = eq d one_hundred_fifty; 20 | br if_cond .if_then .end_if; 21 | 22 | .if_then: 23 | i: int = add i three; 24 | 25 | .end_if: 26 | d: int = add d one; 27 | 28 | jmp .loop_test; 29 | 30 | .loop_end: 31 | } -------------------------------------------------------------------------------- /tests/passing/small/peggy_comparison/loop_unroll.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | i: int = const 0; 3 | one: int = const 1; 4 | 5 | .loop_test: 6 | cond: bool = lt i one; 7 | br cond .loop_body .loop_end; 8 | 9 | .loop_body: 10 | i: int = add one i; 11 | jmp .loop_test; 12 | 13 | .loop_end: 14 | print i; 15 | } -------------------------------------------------------------------------------- /tests/passing/small/peggy_comparison/simple_loop_unswitch.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 40 2 | @main(n: int) { 3 | one: int = const 1; 4 | zero: int = const 0; 5 | i: int = id zero; 6 | j: int = id zero; 7 | 8 | .loop_test: 9 | cond: bool = lt i n; 10 | br cond .loop_body .loop_end; 11 | 12 | .loop_body: 13 | print i; 14 | 15 | cond: bool = lt n zero; 16 | br cond .thn .ifend; 17 | 18 | .thn: 19 | j: int = const 2; 20 | 21 | .ifend: 22 | j: int = add one j; 23 | i: int = add one i; 24 | jmp .loop_test; 25 | 26 | .loop_end: 27 | print j; 28 | } -------------------------------------------------------------------------------- /tests/passing/small/pull_out_small.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 20 2 | fn main(x: i64) { 3 | let a: i64 = x * 5; 4 | if (x > 0) { 5 | let r: i64 = x * 5; 6 | let z: i64 = 20; 7 | println!("{}", z); 8 | } else { 9 | let r: i64 = x * 5; 10 | let z: i64 = 20; 11 | println!("{}", z); 12 | } 13 | println!("{}", r); 14 | } 15 | -------------------------------------------------------------------------------- /tests/passing/small/range_check.bril: -------------------------------------------------------------------------------- 1 | # i = 0 2 | # do: 3 | # if i < 5: 4 | # print 1 5 | # else: 6 | # print 2 7 | # while (i < 10) 8 | # print i 9 | # -------------- 10 | # i = 0 11 | # do: 12 | # print 1 13 | # while (i < 5) 14 | # if (i < 10): 15 | # do: 16 | # print 2 17 | # while (i < 10) 18 | # print i 19 | 20 | @main() { 21 | i: int = const 0; 22 | 23 | .top: 24 | five: int = const 5; 25 | if_cond: bool = lt i five; 26 | br if_cond .then_if .else_if; 27 | .then_if: 28 | one: int = const 1; 29 | print one; 30 | jmp .end_if; 31 | .else_if: 32 | two: int = const 2; 33 | print two; 34 | .end_if: 35 | 36 | six: int = const 6; 37 | loop_cond: bool = lt i six; 38 | one: int = const 1; 39 | i: int = add i one; 40 | br loop_cond .top .end; 41 | .end: 42 | 43 | print i; 44 | } -------------------------------------------------------------------------------- /tests/passing/small/range_splitting.bril: -------------------------------------------------------------------------------- 1 | # i = 0 2 | # do: 3 | # if i < 5: 4 | # print 1 5 | # else: 6 | # print 2 7 | # i = i + 1 8 | # while (i < 5) 9 | # print i 10 | # -------------- 11 | # i = 0 12 | # do: 13 | # print 1 14 | # i = i + 1 15 | # while (i < 5) 16 | # if (5 < 5): 17 | # do: 18 | # print 2 19 | # i = i + 1 20 | # while (i < 5) 21 | # print i 22 | # -------------- 23 | # i = 0 24 | # do: 25 | # print 1 26 | # i = i + 1 27 | # while (i < 5) 28 | # print i 29 | 30 | @main() { 31 | i: int = const 0; 32 | 33 | .top: 34 | a: int = const 5; 35 | if_cond: bool = lt i a; 36 | br if_cond .then_if .else_if; 37 | .then_if: 38 | one: int = const 1; 39 | print one; 40 | jmp .end_if; 41 | .else_if: 42 | two: int = const 2; 43 | print two; 44 | .end_if: 45 | 46 | one: int = const 1; 47 | i: int = add i one; 48 | 49 | b: int = const 5; 50 | loop_cond: bool = lt i b; 51 | br loop_cond .top .end; 52 | .end: 53 | 54 | print i; 55 | } 56 | -------------------------------------------------------------------------------- /tests/passing/small/reassoc.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 2 4 2 | @main(a: int, b: int) { 3 | one: int = const 1; 4 | two: int = const 2; 5 | three: int = const 3; 6 | four: int = const 4; 7 | 8 | 9 | # a + 3 10 | a2: int = add a three; 11 | # b + 4 12 | b4: int = add b four; 13 | # (a + 3) + (b + 4) 14 | a2b4: int = add a2 b4; 15 | 16 | # 1 + a2b4 17 | onea2b4: int = add one a2b4; 18 | 19 | print onea2b4; 20 | } -------------------------------------------------------------------------------- /tests/passing/small/rec_to_loop.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 20 2 | @main(n : int) { 3 | zero: int = const 0; 4 | output: int = call @recPrint n; 5 | } 6 | 7 | @recPrint(n: int): int { 8 | zero: int = const 0; 9 | cond: bool = eq n zero; 10 | br cond .end .rec; 11 | .rec: 12 | print n; 13 | one: int = const 1; 14 | next: int = sub n one; 15 | sum: int = call @recPrint next; 16 | .end: 17 | ret sum; 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/passing/small/rec_to_loop_sub.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 20 2 | @main(n : int) { 3 | zero: int = const 0; 4 | output: int = call @recPrint n; 5 | print output; 6 | } 7 | 8 | @recPrint(n: int): int { 9 | zero: int = const 0; 10 | cond: bool = eq n zero; 11 | br cond .basecase .rec; 12 | .rec: 13 | one: int = const 1; 14 | next: int = sub n one; 15 | sum: int = call @recPrint next; 16 | res: int = sub sum one; 17 | ret res; 18 | .basecase: 19 | ret n; 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/passing/small/recurse_once.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | one: int = const 1; 3 | result: int = call @to_zero one; 4 | print result; 5 | } 6 | 7 | @to_zero (x: int): int { 8 | zero: int = const 0; 9 | cond: bool = lt zero x; 10 | br cond .recurse .done; 11 | 12 | .recurse: 13 | one: int = const 1; 14 | x: int = sub x one; 15 | x: int = call @to_zero x; 16 | .done: 17 | ret x; 18 | } -------------------------------------------------------------------------------- /tests/passing/small/select.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 20 2 | fn main(x: i64) { 3 | let ten: i64 = 10; 4 | let done: i64 = ten; 5 | let i: i64 = 0; 6 | let res: i64 = 0; 7 | while !(done == 5) { 8 | i += 1; 9 | res += i; 10 | if i == x { 11 | done = 5; 12 | } 13 | } 14 | println!("{}", res); 15 | } 16 | -------------------------------------------------------------------------------- /tests/passing/small/select_simple.rs: -------------------------------------------------------------------------------- 1 | // ARGS: 20 30 2 | fn main(x: i64, y: i64) { 3 | let res: i64 = 0; 4 | if (x * y < 20) { 5 | res = x; 6 | } else { 7 | res = y; 8 | } 9 | println!("{}", res); 10 | } 11 | -------------------------------------------------------------------------------- /tests/passing/small/simple-call.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 0; 3 | c: int = call @inc a; 4 | print c; 5 | } 6 | 7 | @inc (x: int): int { 8 | one: int = const 1; 9 | res: int = add one x; 10 | ret res; 11 | } 12 | -------------------------------------------------------------------------------- /tests/passing/small/simple_branch.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(arg: int) { 3 | zero: int = const 0; 4 | isless: bool = lt arg zero; 5 | br isless .less .greater; 6 | .less: 7 | result: int = const 1; 8 | jmp .done; 9 | .greater: 10 | result: int = const 0; 11 | .done: 12 | print result; 13 | } 14 | -------------------------------------------------------------------------------- /tests/passing/small/simple_call.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 0; 3 | call @inc a; 4 | } 5 | 6 | @inc (x: int) { 7 | one: int = const 1; 8 | res: int = add one x; 9 | print res; 10 | } -------------------------------------------------------------------------------- /tests/passing/small/simple_loop.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | .loop: 3 | i: int = const 0; 4 | cond: bool = lt i i; 5 | br cond .loop .done; 6 | .done: 7 | print i; 8 | } 9 | -------------------------------------------------------------------------------- /tests/passing/small/simple_loop_swap.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | one: int = const 1; 3 | two: int = const 2; 4 | ten: int = const 10; 5 | twenty: int = const 20; 6 | p: ptr = alloc two; 7 | q: ptr = ptradd p one; 8 | store p ten; 9 | store q twenty; 10 | res: int = load p; 11 | print res; 12 | free p; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /tests/passing/small/simple_recursive.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | a: int = const 0; 3 | c: int = call @inc a; 4 | print c; 5 | } 6 | 7 | @inc (x: int): int { 8 | max: int = const 2; 9 | cond: bool = lt x max; 10 | br cond .recurse .done; 11 | 12 | .recurse: 13 | one: int = const 1; 14 | x: int = add one x; 15 | print x; 16 | x: int = call @inc x; 17 | .done: 18 | ret x; 19 | } 20 | -------------------------------------------------------------------------------- /tests/passing/small/simple_select_after_block_diamond.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 1 2 | @main(v0: int) { 3 | c1_: int = const 1; 4 | c2_: int = const 2; 5 | v3_: bool = lt v0 c2_; 6 | c4_: int = const 4; 7 | v5_: int = select v3_ c4_ c1_; 8 | v6_: int = id v5_; 9 | v7_: int = id c1_; 10 | br v3_ .b8_ .b9_; 11 | .b9_: 12 | v10_: int = add c2_ v5_; 13 | v6_: int = id v10_; 14 | v7_: int = id c1_; 15 | .b8_: 16 | v11_: int = add c1_ v6_; 17 | print v11_; 18 | ret; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /tests/passing/small/simplest_loop.bril: -------------------------------------------------------------------------------- 1 | @main { 2 | one: int = const 1; 3 | i: int = const 0; 4 | n: int = const 5; 5 | 6 | .loop: 7 | i: int = add i one; 8 | cond: bool = lt i n; 9 | br cond .loop .end; 10 | 11 | .end: 12 | } -------------------------------------------------------------------------------- /tests/passing/small/small-collatz.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 8888 2 | @main (arg : int) { 3 | three : int = const 3; 4 | two : int = const 2; 5 | one : int = const 1; 6 | zero : int = const 0; 7 | var : int = id arg; 8 | counter: int = id zero; 9 | .cond: 10 | cond : bool = eq var one; 11 | br cond .break .body; 12 | .body: 13 | counter : int = add counter one; 14 | d : int = div var two; 15 | m : int = mul d two; 16 | mod : int = sub var m; 17 | cond : bool = eq mod zero; 18 | br cond .then .else; 19 | .then: 20 | var : int = div var two; 21 | jmp .cond; 22 | .else: 23 | v1 : int = mul three var; 24 | var : int = add one v1; 25 | jmp .cond; 26 | .break: 27 | print counter; 28 | } 29 | -------------------------------------------------------------------------------- /tests/passing/small/small-fib.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 2 2 | @main(n: int) { 3 | curr: int = const 1; 4 | prev: int = const 1; 5 | zero: int = const 0; 6 | i: int = const 1; 7 | 8 | print prev; 9 | 10 | is_zero: bool = eq n zero; 11 | br is_zero .for.done .fencepost; 12 | 13 | .fencepost: 14 | print curr; 15 | 16 | .for.cond: 17 | less: bool = lt i n; 18 | br less .for.body .for.done; 19 | 20 | .for.body: 21 | tmp: int = add curr prev; 22 | print tmp; 23 | prev: int = id curr; 24 | curr: int = id tmp; 25 | 26 | one: int = const 1; 27 | i: int = add i one; 28 | jmp .for.cond; 29 | 30 | .for.done: 31 | 32 | } -------------------------------------------------------------------------------- /tests/passing/small/strong_loop.bril: -------------------------------------------------------------------------------- 1 | # ARGS: 3 2 | @main(n: int) { 3 | i: int = const 3; 4 | x: int = add n i; 5 | total: int = const 0; 6 | .loop: 7 | c: int = const 7; 8 | one: int = const 1; 9 | 10 | cond: bool = lt i n; 11 | y: int = mul c i; 12 | print y; 13 | total: int = add total y; 14 | i: int = add i one; 15 | br cond .loop .done; 16 | .done: 17 | print total; 18 | print x; 19 | print i; 20 | } -------------------------------------------------------------------------------- /tests/passing/small/two_fns.bril: -------------------------------------------------------------------------------- 1 | @sub() : int { 2 | v0: int = const 1; 3 | v1: int = const 2; 4 | v2: int = sub v0 v1; 5 | ret v2; 6 | } 7 | 8 | @main() { 9 | v0: int = const 1; 10 | v1: int = const 2; 11 | v2: int = add v0 v1; 12 | print v2; 13 | } 14 | -------------------------------------------------------------------------------- /tests/passing/small/unroll_and_constant_fold.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | i: int = const 0; 3 | one: int = const 1; 4 | .loop: 5 | i: int = add i one; 6 | cond: bool = lt i one; 7 | br cond .loop .done; 8 | .done: 9 | print i; 10 | } 11 | -------------------------------------------------------------------------------- /tests/passing/small/unroll_multiple_4.bril: -------------------------------------------------------------------------------- 1 | @main() { 2 | i: int = const 0; 3 | one: int = const 1; 4 | N: int = const 16; 5 | .loop: 6 | i: int = add i one; 7 | cond: bool = lt i N; 8 | br cond .loop .done; 9 | .done: 10 | print i; 11 | } 12 | -------------------------------------------------------------------------------- /tests/slow/polybench/README.md: -------------------------------------------------------------------------------- 1 | # Polybench/Bril 2 | 3 | A port of Polybench/C 4.2.1 benchmarks to Bril. Original source [here](https://github.com/MatthiasJReisinger/PolyBenchC-4.2.1). -------------------------------------------------------------------------------- /tests/snapshots/files__add-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 3; 8 | print c0_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__add-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 3; 8 | print c0_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__add_block_indirection-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 3; 8 | print c0_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__add_block_indirection-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 3; 8 | print c0_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__block-diamond-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 1 7 | @main(v0: int) { 8 | c1_: int = const 1; 9 | c2_: int = const 2; 10 | v3_: bool = lt v0 c2_; 11 | v4_: int = id c1_; 12 | v5_: int = id c1_; 13 | v6_: int = id c2_; 14 | br v3_ .b7_ .b8_; 15 | .b7_: 16 | c9_: bool = const true; 17 | c10_: int = const 4; 18 | v11_: int = select c9_ c10_ c2_; 19 | v4_: int = id v11_; 20 | v5_: int = id c1_; 21 | v6_: int = id c2_; 22 | v12_: int = add c2_ v4_; 23 | v13_: int = select v3_ v4_ v12_; 24 | v14_: int = add c1_ v13_; 25 | print v14_; 26 | ret; 27 | jmp .b15_; 28 | .b8_: 29 | v12_: int = add c2_ v4_; 30 | v13_: int = select v3_ v4_ v12_; 31 | v14_: int = add c1_ v13_; 32 | print v14_; 33 | ret; 34 | .b15_: 35 | } 36 | -------------------------------------------------------------------------------- /tests/snapshots/files__block-diamond-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 2; 8 | v2_: bool = lt v0 c1_; 9 | c3_: int = const 4; 10 | c4_: int = const 1; 11 | v5_: int = select v2_ c3_ c4_; 12 | v6_: int = add c1_ v5_; 13 | v7_: int = select v2_ v5_ v6_; 14 | v8_: int = add c4_ v7_; 15 | print v8_; 16 | ret; 17 | } 18 | -------------------------------------------------------------------------------- /tests/snapshots/files__bool-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: bool = const true; 8 | print c0_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__bool-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: bool = const true; 8 | print c0_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__branch_duplicate_work-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 2; 8 | v2_: bool = lt v0 c1_; 9 | v3_: int = add v0 v0; 10 | v4_: int = mul c1_ v3_; 11 | v5_: int = select v2_ v3_ v4_; 12 | print v5_; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /tests/snapshots/files__branch_duplicate_work-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 2; 8 | v2_: bool = lt v0 c1_; 9 | v3_: int = add v0 v0; 10 | v4_: int = mul c1_ v3_; 11 | v5_: int = select v2_ v3_ v4_; 12 | print v5_; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /tests/snapshots/files__branch_hoisting-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 0 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | c2_: int = const 500; 9 | v3_: bool = eq c1_ v0; 10 | v4_: int = id c1_; 11 | v5_: int = id c1_; 12 | v6_: int = id v0; 13 | v7_: int = id c1_; 14 | v8_: int = id c2_; 15 | v9_: bool = id v3_; 16 | .b10_: 17 | c11_: int = const 1; 18 | c12_: int = const 2; 19 | v13_: int = add c12_ v5_; 20 | v14_: int = add c11_ v13_; 21 | v15_: int = mul c12_ v14_; 22 | c16_: int = const 3; 23 | v17_: int = mul c16_ v14_; 24 | v18_: int = select v9_ v15_ v17_; 25 | v19_: int = add c12_ v13_; 26 | v20_: bool = lt v19_ v8_; 27 | v4_: int = id v18_; 28 | v5_: int = id v19_; 29 | v6_: int = id v6_; 30 | v7_: int = id v7_; 31 | v8_: int = id v8_; 32 | v9_: bool = id v9_; 33 | br v20_ .b10_ .b21_; 34 | .b21_: 35 | print v4_; 36 | ret; 37 | } 38 | -------------------------------------------------------------------------------- /tests/snapshots/files__conditional_constant_folding-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 4 6 | @main(v0: int) { 7 | c1_: int = const 20; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__conditional_constant_folding-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 4 6 | @main(v0: int) { 7 | c1_: int = const 20; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__constant_fold_simple-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 3; 8 | c1_: int = const 2; 9 | v2_: int = div c0_ c1_; 10 | print v2_; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/snapshots/files__constant_fold_simple-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 3; 8 | c1_: int = const 2; 9 | v2_: int = div c0_ c1_; 10 | print v2_; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/snapshots/files__dead_loop_deletion-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 2; 8 | c1_: int = const 3; 9 | c2_: int = const 0; 10 | c3_: int = const 1; 11 | c4_: int = const 40; 12 | v5_: int = id c1_; 13 | v6_: int = id c2_; 14 | v7_: int = id c3_; 15 | v8_: int = id c4_; 16 | .b9_: 17 | c10_: int = const 2; 18 | v11_: int = add c10_ v5_; 19 | v12_: int = add c10_ v11_; 20 | v13_: int = add c10_ v6_; 21 | v14_: int = add c10_ v13_; 22 | v15_: bool = lt v14_ v8_; 23 | v5_: int = id v12_; 24 | v6_: int = id v14_; 25 | v7_: int = id v7_; 26 | v8_: int = id v8_; 27 | br v15_ .b9_ .b16_; 28 | .b16_: 29 | print c0_; 30 | ret; 31 | } 32 | -------------------------------------------------------------------------------- /tests/snapshots/files__dead_loop_deletion-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 2; 8 | c1_: int = const 3; 9 | c2_: int = const 0; 10 | c3_: int = const 1; 11 | c4_: int = const 40; 12 | v5_: int = id c1_; 13 | v6_: int = id c2_; 14 | v7_: int = id c3_; 15 | v8_: int = id c4_; 16 | .b9_: 17 | c10_: int = const 4; 18 | v11_: int = add c10_ v5_; 19 | v12_: int = add c10_ v6_; 20 | v13_: bool = lt v12_ v8_; 21 | v5_: int = id v11_; 22 | v6_: int = id v12_; 23 | v7_: int = id v7_; 24 | v8_: int = id v8_; 25 | br v13_ .b9_ .b14_; 26 | .b14_: 27 | print c0_; 28 | ret; 29 | } 30 | -------------------------------------------------------------------------------- /tests/snapshots/files__diamond-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 3 6 | @main(v0: int) { 7 | v1_: bool = lt v0 v0; 8 | br v1_ .b2_ .b3_; 9 | .b2_: 10 | c4_: int = const 1; 11 | print c4_; 12 | ret; 13 | jmp .b5_; 14 | .b3_: 15 | c6_: int = const 2; 16 | print c6_; 17 | ret; 18 | .b5_: 19 | } 20 | -------------------------------------------------------------------------------- /tests/snapshots/files__diamond-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 3 6 | @main(v0: int) { 7 | v1_: bool = lt v0 v0; 8 | br v1_ .b2_ .b3_; 9 | .b2_: 10 | c4_: int = const 1; 11 | print c4_; 12 | ret; 13 | jmp .b5_; 14 | .b3_: 15 | c6_: int = const 2; 16 | print c6_; 17 | ret; 18 | .b5_: 19 | } 20 | -------------------------------------------------------------------------------- /tests/snapshots/files__duplicate_branch-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 5 6 | @main(v0: int) { 7 | c1_: int = const 4; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__duplicate_branch-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 5 6 | @main(v0: int) { 7 | c1_: int = const 4; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__eliminate_gamma-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 1; 8 | print c0_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__eliminate_gamma-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 1; 8 | print c0_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__eliminate_gamma_interval-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: bool = const false; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__eliminate_gamma_interval-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: bool = const false; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__eliminate_loop-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 1; 8 | c1_: bool = const false; 9 | print c0_; 10 | ret; 11 | } 12 | -------------------------------------------------------------------------------- /tests/snapshots/files__eliminate_loop-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 1; 8 | c1_: bool = const false; 9 | print c0_; 10 | ret; 11 | } 12 | -------------------------------------------------------------------------------- /tests/snapshots/files__fib_shape-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 10 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = lt c1_ v0; 9 | c3_: int = const 1; 10 | v4_: int = id c1_; 11 | v5_: int = id c3_; 12 | v6_: int = id v0; 13 | br v2_ .b7_ .b8_; 14 | .b7_: 15 | v9_: int = id c1_; 16 | v10_: int = id c3_; 17 | v11_: int = id v0; 18 | .b12_: 19 | v13_: int = add v10_ v9_; 20 | v14_: bool = lt v13_ v11_; 21 | v9_: int = id v13_; 22 | v10_: int = id v10_; 23 | v11_: int = id v11_; 24 | br v14_ .b12_ .b15_; 25 | .b15_: 26 | v4_: int = id v9_; 27 | v5_: int = id v10_; 28 | v6_: int = id v11_; 29 | print v4_; 30 | ret; 31 | jmp .b16_; 32 | .b8_: 33 | print v4_; 34 | ret; 35 | .b16_: 36 | } 37 | -------------------------------------------------------------------------------- /tests/snapshots/files__fib_shape-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 10 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = lt c1_ v0; 9 | c3_: int = const 1; 10 | v4_: int = id c1_; 11 | v5_: int = id c3_; 12 | v6_: int = id v0; 13 | br v2_ .b7_ .b8_; 14 | .b7_: 15 | v9_: int = id c1_; 16 | v10_: int = id c3_; 17 | v11_: int = id v0; 18 | .b12_: 19 | v13_: int = add v10_ v9_; 20 | v14_: bool = lt v13_ v11_; 21 | v9_: int = id v13_; 22 | v10_: int = id v10_; 23 | v11_: int = id v11_; 24 | br v14_ .b12_ .b15_; 25 | .b15_: 26 | v4_: int = id v9_; 27 | v5_: int = id v10_; 28 | v6_: int = id v11_; 29 | print v4_; 30 | ret; 31 | jmp .b16_; 32 | .b8_: 33 | print v4_; 34 | ret; 35 | .b16_: 36 | } 37 | -------------------------------------------------------------------------------- /tests/snapshots/files__five_call_nestings-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @one { 7 | call @four; 8 | ret; 9 | } 10 | @two { 11 | c0_: int = const 4; 12 | print c0_; 13 | ret; 14 | } 15 | @three { 16 | c0_: int = const 4; 17 | print c0_; 18 | ret; 19 | } 20 | @four { 21 | c0_: int = const 4; 22 | print c0_; 23 | ret; 24 | } 25 | @main { 26 | call @three; 27 | ret; 28 | } 29 | -------------------------------------------------------------------------------- /tests/snapshots/files__five_call_nestings-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @one { 7 | call @four; 8 | ret; 9 | } 10 | @two { 11 | c0_: int = const 4; 12 | print c0_; 13 | ret; 14 | } 15 | @three { 16 | c0_: int = const 4; 17 | print c0_; 18 | ret; 19 | } 20 | @four { 21 | c0_: int = const 4; 22 | print c0_; 23 | ret; 24 | } 25 | @main { 26 | call @three; 27 | ret; 28 | } 29 | -------------------------------------------------------------------------------- /tests/snapshots/files__four_call_nestings-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @one { 7 | c0_: int = const 3; 8 | print c0_; 9 | ret; 10 | } 11 | @two { 12 | c0_: int = const 3; 13 | print c0_; 14 | ret; 15 | } 16 | @three { 17 | c0_: int = const 3; 18 | print c0_; 19 | ret; 20 | } 21 | @main { 22 | call @three; 23 | ret; 24 | } 25 | -------------------------------------------------------------------------------- /tests/snapshots/files__four_call_nestings-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @one { 7 | c0_: int = const 3; 8 | print c0_; 9 | ret; 10 | } 11 | @two { 12 | c0_: int = const 3; 13 | print c0_; 14 | ret; 15 | } 16 | @three { 17 | c0_: int = const 3; 18 | print c0_; 19 | ret; 20 | } 21 | @main { 22 | call @three; 23 | ret; 24 | } 25 | -------------------------------------------------------------------------------- /tests/snapshots/files__gamma_condition_and-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = lt v0 c1_; 9 | v3_: bool = lt c1_ v0; 10 | v4_: bool = and v2_ v3_; 11 | c5_: int = const 1; 12 | v6_: int = id c5_; 13 | br v4_ .b7_ .b8_; 14 | .b7_: 15 | print v6_; 16 | ret; 17 | jmp .b9_; 18 | .b8_: 19 | v10_: bool = lt v0 c1_; 20 | v11_: bool = lt c1_ v0; 21 | v12_: bool = and v10_ v11_; 22 | c13_: int = const 3; 23 | v14_: int = id c13_; 24 | br v12_ .b15_ .b16_; 25 | .b15_: 26 | c17_: int = const 2; 27 | v18_: int = id c17_; 28 | v19_: int = id c1_; 29 | v20_: int = id c5_; 30 | .b21_: 31 | v22_: int = add v18_ v20_; 32 | v23_: bool = lt v19_ v22_; 33 | v24_: bool = not v23_; 34 | v18_: int = id v22_; 35 | v19_: int = id v19_; 36 | v20_: int = id v20_; 37 | br v24_ .b21_ .b25_; 38 | .b25_: 39 | v14_: int = id v18_; 40 | v6_: int = id v14_; 41 | print v6_; 42 | ret; 43 | jmp .b9_; 44 | .b16_: 45 | v6_: int = id v14_; 46 | print v6_; 47 | ret; 48 | .b9_: 49 | } 50 | -------------------------------------------------------------------------------- /tests/snapshots/files__gamma_condition_and-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 3; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__gamma_pull_in-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 10; 8 | v2_: bool = lt v0 c1_; 9 | c3_: int = const 2; 10 | c4_: int = const 3; 11 | v5_: int = select v2_ c3_ c4_; 12 | v6_: int = add v5_ v5_; 13 | print v6_; 14 | ret; 15 | } 16 | -------------------------------------------------------------------------------- /tests/snapshots/files__gamma_pull_in-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 10; 8 | v2_: bool = lt v0 c1_; 9 | c3_: int = const 2; 10 | c4_: int = const 3; 11 | v5_: int = select v2_ c3_ c4_; 12 | v6_: int = add v5_ v5_; 13 | print v6_; 14 | ret; 15 | } 16 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_constant_fold-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: bool = const false; 8 | c2_: int = const 5; 9 | c3_: int = const 6; 10 | v4_: int = select c1_ c2_ c3_; 11 | c5_: bool = const true; 12 | c6_: int = const 3; 13 | c7_: int = const 4; 14 | v8_: int = select c5_ c6_ c7_; 15 | print v8_; 16 | print v4_; 17 | ret; 18 | } 19 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_constant_fold-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 6; 8 | c2_: int = const 3; 9 | print c2_; 10 | print c1_; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_constant_fold2-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 20; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_constant_fold2-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 20; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_context-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @main(v0: int) { 7 | c1_: int = const 3; 8 | v2_: bool = eq c1_ v0; 9 | v3_: int = mul c1_ v0; 10 | v4_: int = select v2_ c1_ v3_; 11 | print v4_; 12 | ret; 13 | } 14 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_context-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @main(v0: int) { 7 | c1_: int = const 3; 8 | v2_: bool = eq c1_ v0; 9 | v3_: int = mul c1_ v0; 10 | v4_: int = select v2_ c1_ v3_; 11 | print v4_; 12 | ret; 13 | } 14 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_context2-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: bool = const true; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_context2-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: bool = const true; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_dead_code-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = lt v0 c1_; 9 | c3_: int = const 1; 10 | v4_: int = select v2_ c3_ c1_; 11 | print v4_; 12 | print v2_; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_dead_code-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = lt v0 c1_; 9 | c3_: int = const 1; 10 | v4_: int = select v2_ c3_ c1_; 11 | print v4_; 12 | print v2_; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_dead_code_nested-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 1; 8 | v2_: bool = lt v0 c1_; 9 | c3_: int = const 0; 10 | c4_: int = const 3; 11 | c5_: int = const 2; 12 | br v2_ .b6_ .b7_; 13 | .b6_: 14 | v8_: bool = lt v0 c3_; 15 | c9_: int = const 1; 16 | v10_: int = select v8_ c9_ c5_; 17 | v11_: int = id v10_; 18 | v12_: int = id c9_; 19 | v13_: int = select v2_ c1_ c3_; 20 | print v13_; 21 | print v2_; 22 | print v11_; 23 | ret; 24 | jmp .b14_; 25 | .b7_: 26 | v15_: bool = lt c5_ v0; 27 | v16_: bool = lt c4_ v0; 28 | c17_: int = const 4; 29 | v18_: int = select v16_ c4_ c17_; 30 | v19_: int = select v15_ v18_ c5_; 31 | v11_: int = id v19_; 32 | v12_: int = id c3_; 33 | v13_: int = select v2_ c1_ c3_; 34 | print v13_; 35 | print v2_; 36 | print v11_; 37 | ret; 38 | .b14_: 39 | } 40 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_in_loop-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | c2_: int = const 1; 9 | c3_: int = const 10; 10 | v4_: int = id c1_; 11 | v5_: int = id c2_; 12 | v6_: int = id v0; 13 | v7_: int = id c1_; 14 | v8_: int = id c3_; 15 | .b9_: 16 | v10_: bool = lt v6_ v5_; 17 | v11_: int = select v10_ v5_ v7_; 18 | print v11_; 19 | print v10_; 20 | v12_: int = add v4_ v5_; 21 | v13_: bool = lt v4_ v8_; 22 | v4_: int = id v12_; 23 | v5_: int = id v5_; 24 | v6_: int = id v6_; 25 | v7_: int = id v7_; 26 | v8_: int = id v8_; 27 | br v13_ .b9_ .b14_; 28 | .b14_: 29 | ret; 30 | } 31 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_in_loop-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | c2_: int = const 1; 9 | c3_: int = const 10; 10 | v4_: bool = lt v0 c2_; 11 | v5_: int = id c1_; 12 | v6_: int = id c2_; 13 | v7_: int = id v0; 14 | v8_: int = id c1_; 15 | v9_: int = id c3_; 16 | v10_: bool = id v4_; 17 | .b11_: 18 | v12_: int = select v10_ v6_ v8_; 19 | print v12_; 20 | print v10_; 21 | v13_: int = add v5_ v6_; 22 | v14_: bool = lt v5_ v9_; 23 | v5_: int = id v13_; 24 | v6_: int = id v6_; 25 | v7_: int = id v7_; 26 | v8_: int = id v8_; 27 | v9_: int = id v9_; 28 | v10_: bool = id v10_; 29 | br v14_ .b11_ .b15_; 30 | .b15_: 31 | ret; 32 | } 33 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_interval-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: bool = const true; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_interval-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: bool = const true; 8 | print c1_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_invariant_do_pull_out-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @unrelated_fn(v0: int): int { 7 | c1_: int = const 4; 8 | v2_: int = div v0 c1_; 9 | ret v2_; 10 | } 11 | @other_unrelated_fn(v0: int): int { 12 | c1_: int = const 3; 13 | v2_: int = mul c1_ v0; 14 | c3_: int = const 5; 15 | v4_: int = div v2_ c3_; 16 | ret v4_; 17 | } 18 | @main(v0: int) { 19 | c1_: int = const 0; 20 | v2_: bool = gt v0 c1_; 21 | v3_: int = abs v0; 22 | c4_: int = const 3; 23 | v5_: int = mul c4_ v3_; 24 | br v2_ .b6_ .b7_; 25 | .b6_: 26 | c8_: int = const 4; 27 | v9_: int = div v0 c8_; 28 | v10_: int = add v5_ v9_; 29 | v11_: int = id v10_; 30 | print v11_; 31 | ret; 32 | jmp .b12_; 33 | .b7_: 34 | c13_: int = const 3; 35 | v14_: int = mul c13_ v0; 36 | c15_: int = const 5; 37 | v16_: int = div v14_ c15_; 38 | v17_: int = add v16_ v5_; 39 | v11_: int = id v17_; 40 | print v11_; 41 | ret; 42 | .b12_: 43 | } 44 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_invariant_do_pull_out-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 20 7 | @unrelated_fn(v0: int): int { 8 | c1_: int = const 4; 9 | v2_: int = div v0 c1_; 10 | ret v2_; 11 | } 12 | @other_unrelated_fn(v0: int): int { 13 | c1_: int = const 3; 14 | v2_: int = mul c1_ v0; 15 | c3_: int = const 5; 16 | v4_: int = div v2_ c3_; 17 | ret v4_; 18 | } 19 | @main(v0: int) { 20 | c1_: int = const 0; 21 | v2_: bool = gt v0 c1_; 22 | v3_: int = abs v0; 23 | c4_: int = const 3; 24 | v5_: int = mul c4_ v3_; 25 | br v2_ .b6_ .b7_; 26 | .b6_: 27 | c8_: int = const 4; 28 | v9_: int = div v0 c8_; 29 | v10_: int = add v5_ v9_; 30 | v11_: int = id v10_; 31 | print v11_; 32 | ret; 33 | jmp .b12_; 34 | .b7_: 35 | c13_: int = const 3; 36 | v14_: int = mul c13_ v0; 37 | c15_: int = const 5; 38 | v16_: int = div v14_ c15_; 39 | v17_: int = add v16_ v5_; 40 | v11_: int = id v17_; 41 | print v11_; 42 | ret; 43 | .b12_: 44 | } 45 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_invariant_dont_pull_out-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @unrelated_fn(v0: int, v1: int): int { 7 | c2_: int = const 3; 8 | v3_: int = div v1 c2_; 9 | v4_: int = div v0 v3_; 10 | ret v4_; 11 | } 12 | @other_unrelated_fn(v0: int, v1: int): int { 13 | c2_: int = const 5; 14 | v3_: int = div v0 c2_; 15 | v4_: int = div v1 v3_; 16 | ret v4_; 17 | } 18 | @main(v0: int) { 19 | c1_: int = const 0; 20 | v2_: bool = gt v0 c1_; 21 | v3_: int = abs v0; 22 | c4_: int = const 3; 23 | v5_: int = mul c4_ v3_; 24 | br v2_ .b6_ .b7_; 25 | .b6_: 26 | v8_: int = sub v5_ v0; 27 | c9_: int = const 3; 28 | v10_: int = div v8_ c9_; 29 | v11_: int = div v0 v10_; 30 | v12_: int = id v11_; 31 | print v12_; 32 | ret; 33 | jmp .b13_; 34 | .b7_: 35 | v14_: int = add v0 v5_; 36 | c15_: int = const 5; 37 | v16_: int = div v0 c15_; 38 | v17_: int = div v14_ v16_; 39 | v12_: int = id v17_; 40 | print v12_; 41 | ret; 42 | .b13_: 43 | } 44 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_invariant_dont_pull_out-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @unrelated_fn(v0: int, v1: int): int { 7 | c2_: int = const 3; 8 | v3_: int = div v1 c2_; 9 | v4_: int = div v0 v3_; 10 | ret v4_; 11 | } 12 | @other_unrelated_fn(v0: int, v1: int): int { 13 | c2_: int = const 5; 14 | v3_: int = div v0 c2_; 15 | v4_: int = div v1 v3_; 16 | ret v4_; 17 | } 18 | @main(v0: int) { 19 | c1_: int = const 0; 20 | v2_: bool = lt c1_ v0; 21 | c3_: int = const 2; 22 | v4_: int = abs v0; 23 | v5_: int = mul c3_ v4_; 24 | br v2_ .b6_ .b7_; 25 | .b6_: 26 | c8_: int = const 3; 27 | v9_: int = div v5_ c8_; 28 | v10_: int = div v0 v9_; 29 | v11_: int = id v10_; 30 | print v11_; 31 | ret; 32 | jmp .b12_; 33 | .b7_: 34 | c13_: int = const 5; 35 | v14_: int = div v0 c13_; 36 | v15_: int = div v5_ v14_; 37 | v11_: int = id v15_; 38 | print v11_; 39 | ret; 40 | .b12_: 41 | } 42 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_push_in-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 20 7 | @main(v0: int) { 8 | c1_: int = const 0; 9 | v2_: bool = lt c1_ v0; 10 | c3_: int = const 2; 11 | v4_: int = mul c3_ v0; 12 | c5_: int = const 5; 13 | v6_: int = mul c5_ v4_; 14 | c7_: int = const 3; 15 | v8_: int = neg c7_; 16 | v9_: int = mul v4_ v8_; 17 | v10_: int = select v2_ v6_ v9_; 18 | v11_: bool = ge v10_ c1_; 19 | c12_: int = const 10; 20 | v13_: int = mul c12_ v10_; 21 | c14_: int = const 37; 22 | v15_: int = mul c14_ v10_; 23 | v16_: int = select v11_ v13_ v15_; 24 | print v16_; 25 | ret; 26 | } 27 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_push_in-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 20 7 | @main(v0: int) { 8 | c1_: int = const 0; 9 | v2_: bool = gt v0 c1_; 10 | c3_: int = const 2; 11 | v4_: int = mul c3_ v0; 12 | c5_: int = const 5; 13 | v6_: int = mul c5_ v4_; 14 | c7_: int = const 3; 15 | v8_: int = neg c7_; 16 | v9_: int = mul v4_ v8_; 17 | v10_: int = select v2_ v6_ v9_; 18 | v11_: bool = ge v10_ c1_; 19 | c12_: int = const 10; 20 | v13_: int = mul c12_ v10_; 21 | c14_: int = const 37; 22 | v15_: int = mul c14_ v10_; 23 | v16_: int = select v11_ v13_ v15_; 24 | print v16_; 25 | ret; 26 | } 27 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_true-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @main(v0: int) { 7 | c1_: int = const 1; 8 | v2_: int = sub v0 c1_; 9 | print v0; 10 | print v2_; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/snapshots/files__if_true-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @main(v0: int) { 7 | c1_: int = const 1; 8 | v2_: int = sub v0 c1_; 9 | print v0; 10 | print v2_; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/snapshots/files__impossible_if-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 1; 8 | c2_: int = const 2; 9 | v3_: bool = lt v0 c2_; 10 | br v3_ .b4_ .b5_; 11 | .b4_: 12 | print c1_; 13 | v6_: int = id c1_; 14 | print c1_; 15 | ret; 16 | jmp .b7_; 17 | .b5_: 18 | print c1_; 19 | v6_: int = id c1_; 20 | print c1_; 21 | ret; 22 | .b7_: 23 | } 24 | -------------------------------------------------------------------------------- /tests/snapshots/files__impossible_if-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 1; 8 | c2_: int = const 2; 9 | v3_: bool = lt v0 c2_; 10 | br v3_ .b4_ .b5_; 11 | .b4_: 12 | print c1_; 13 | v6_: int = id c1_; 14 | print c1_; 15 | ret; 16 | jmp .b7_; 17 | .b5_: 18 | print c1_; 19 | v6_: int = id c1_; 20 | print c1_; 21 | ret; 22 | .b7_: 23 | } 24 | -------------------------------------------------------------------------------- /tests/snapshots/files__ivt-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @main(v0: int) { 7 | c1_: int = const 20; 8 | c2_: int = const 0; 9 | v3_: bool = lt c2_ v0; 10 | v4_: int = id c1_; 11 | v5_: int = id c2_; 12 | v6_: int = id v0; 13 | br v3_ .b7_ .b8_; 14 | .b7_: 15 | v9_: int = id c1_; 16 | v10_: int = id c2_; 17 | v11_: int = id v0; 18 | .b12_: 19 | print v10_; 20 | c13_: int = const 1; 21 | v14_: int = add c13_ v10_; 22 | v15_: bool = lt v14_ v11_; 23 | v9_: int = id v9_; 24 | v10_: int = id v14_; 25 | v11_: int = id v11_; 26 | br v15_ .b12_ .b16_; 27 | .b16_: 28 | v4_: int = id v9_; 29 | v5_: int = id v10_; 30 | v6_: int = id v11_; 31 | print c1_; 32 | ret; 33 | jmp .b17_; 34 | .b8_: 35 | print c1_; 36 | ret; 37 | .b17_: 38 | } 39 | -------------------------------------------------------------------------------- /tests/snapshots/files__ivt-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @main(v0: int) { 7 | c1_: int = const 20; 8 | c2_: int = const 0; 9 | v3_: bool = lt c2_ v0; 10 | v4_: int = id c1_; 11 | v5_: int = id c2_; 12 | v6_: int = id v0; 13 | br v3_ .b7_ .b8_; 14 | .b7_: 15 | v9_: int = id c1_; 16 | v10_: int = id c2_; 17 | v11_: int = id v0; 18 | .b12_: 19 | print v10_; 20 | c13_: int = const 1; 21 | v14_: int = add c13_ v10_; 22 | v15_: bool = lt v14_ v11_; 23 | v9_: int = id v9_; 24 | v10_: int = id v14_; 25 | v11_: int = id v11_; 26 | br v15_ .b12_ .b16_; 27 | .b16_: 28 | v4_: int = id v9_; 29 | v5_: int = id v10_; 30 | v6_: int = id v11_; 31 | print c1_; 32 | ret; 33 | jmp .b17_; 34 | .b8_: 35 | print c1_; 36 | ret; 37 | .b17_: 38 | } 39 | -------------------------------------------------------------------------------- /tests/snapshots/files__jumping_loop-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 18; 9 | c2_: int = const 4; 10 | v3_: int = id c0_; 11 | v4_: int = id c1_; 12 | v5_: int = id c2_; 13 | .b6_: 14 | v7_: int = add v3_ v5_; 15 | v8_: bool = lt v7_ v4_; 16 | v3_: int = id v7_; 17 | v4_: int = id v4_; 18 | v5_: int = id v5_; 19 | br v8_ .b6_ .b9_; 20 | .b9_: 21 | ret; 22 | } 23 | -------------------------------------------------------------------------------- /tests/snapshots/files__jumping_loop-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 18; 9 | c2_: int = const 4; 10 | v3_: int = id c0_; 11 | v4_: int = id c1_; 12 | v5_: int = id c2_; 13 | .b6_: 14 | v7_: int = add v3_ v5_; 15 | v8_: bool = lt v7_ v4_; 16 | v3_: int = id v7_; 17 | v4_: int = id v4_; 18 | v5_: int = id v5_; 19 | br v8_ .b6_ .b9_; 20 | .b9_: 21 | ret; 22 | } 23 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_based_code_motion-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 3; 9 | v2_: int = id c0_; 10 | v3_: int = id c1_; 11 | .b4_: 12 | c5_: int = const 1; 13 | v6_: int = add c5_ v2_; 14 | v7_: bool = lt v6_ v3_; 15 | v2_: int = id v6_; 16 | v3_: int = id v3_; 17 | br v7_ .b4_ .b8_; 18 | .b8_: 19 | c9_: int = const 5; 20 | v10_: int = mul c9_ v2_; 21 | print v10_; 22 | ret; 23 | } 24 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_based_code_motion-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 3; 9 | v2_: int = id c0_; 10 | v3_: int = id c1_; 11 | .b4_: 12 | c5_: int = const 1; 13 | v6_: int = add c5_ v2_; 14 | v7_: bool = lt v6_ v3_; 15 | v2_: int = id v6_; 16 | v3_: int = id v3_; 17 | br v7_ .b4_ .b8_; 18 | .b8_: 19 | c9_: int = const 5; 20 | v10_: int = mul c9_ v2_; 21 | print v10_; 22 | ret; 23 | } 24 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_hoist-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 2 3 4 6 | @main(v0: int, v1: int, v2: int, v3: int) { 7 | v4_: int = sub v2 v1; 8 | v5_: int = id v0; 9 | v6_: int = id v3; 10 | v7_: int = id v2; 11 | v8_: int = id v1; 12 | v9_: int = id v4_; 13 | .b10_: 14 | print v9_; 15 | v11_: int = add v5_ v9_; 16 | v12_: bool = lt v11_ v6_; 17 | v13_: bool = not v12_; 18 | v5_: int = id v11_; 19 | v6_: int = id v6_; 20 | v7_: int = id v7_; 21 | v8_: int = id v8_; 22 | v9_: int = id v9_; 23 | br v13_ .b10_ .b14_; 24 | .b14_: 25 | print v5_; 26 | ret; 27 | } 28 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_hoist-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 2 3 4 6 | @main(v0: int, v1: int, v2: int, v3: int) { 7 | v4_: int = sub v2 v1; 8 | v5_: int = id v0; 9 | v6_: int = id v3; 10 | v7_: int = id v2; 11 | v8_: int = id v1; 12 | v9_: int = id v4_; 13 | .b10_: 14 | print v9_; 15 | v11_: int = add v5_ v9_; 16 | v12_: bool = lt v11_ v6_; 17 | v13_: bool = not v12_; 18 | v5_: int = id v11_; 19 | v6_: int = id v6_; 20 | v7_: int = id v7_; 21 | v8_: int = id v8_; 22 | v9_: int = id v9_; 23 | br v13_ .b10_ .b14_; 24 | .b14_: 25 | print v5_; 26 | ret; 27 | } 28 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_if-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | v1_: int = id c0_; 9 | v2_: int = id c0_; 10 | .b3_: 11 | v4_: bool = eq v1_ v2_; 12 | c5_: int = const 1; 13 | v6_: int = add c5_ v1_; 14 | v7_: int = select v4_ v1_ v6_; 15 | v8_: int = add c5_ v2_; 16 | v9_: int = select v4_ v2_ v8_; 17 | v10_: bool = not v4_; 18 | v1_: int = id v7_; 19 | v2_: int = id v9_; 20 | br v10_ .b3_ .b11_; 21 | .b11_: 22 | print v1_; 23 | ret; 24 | } 25 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_if-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | v1_: int = id c0_; 9 | v2_: int = id c0_; 10 | .b3_: 11 | v4_: bool = eq v1_ v2_; 12 | c5_: int = const 1; 13 | v6_: int = add c5_ v1_; 14 | v7_: int = select v4_ v1_ v6_; 15 | v8_: int = add c5_ v2_; 16 | v9_: int = select v4_ v2_ v8_; 17 | v10_: bool = not v4_; 18 | v1_: int = id v7_; 19 | v2_: int = id v9_; 20 | br v10_ .b3_ .b11_; 21 | .b11_: 22 | print v1_; 23 | ret; 24 | } 25 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_pass_through-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 5 6 | @main(v0: int) { 7 | c1_: int = const 1; 8 | v2_: int = id c1_; 9 | v3_: int = id v0; 10 | .b4_: 11 | v5_: int = add v2_ v2_; 12 | c6_: int = const 10; 13 | v7_: bool = lt v2_ c6_; 14 | v2_: int = id v5_; 15 | v3_: int = id v3_; 16 | br v7_ .b4_ .b8_; 17 | .b8_: 18 | v9_: int = add v0 v2_; 19 | print v9_; 20 | ret; 21 | } 22 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_pass_through-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 5 6 | @main(v0: int) { 7 | c1_: int = const 1; 8 | v2_: int = id c1_; 9 | v3_: int = id v0; 10 | .b4_: 11 | v5_: int = add v2_ v2_; 12 | c6_: int = const 10; 13 | v7_: bool = lt v2_ c6_; 14 | v2_: int = id v5_; 15 | v3_: int = id v3_; 16 | br v7_ .b4_ .b8_; 17 | .b8_: 18 | v9_: int = add v0 v2_; 19 | print v9_; 20 | ret; 21 | } 22 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_peeling-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 5 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = lt c1_ v0; 9 | v3_: int = id c1_; 10 | v4_: int = id c1_; 11 | v5_: int = id v0; 12 | br v2_ .b6_ .b7_; 13 | .b6_: 14 | v8_: int = id c1_; 15 | v9_: int = id c1_; 16 | v10_: int = id v0; 17 | .b11_: 18 | c12_: int = const 5; 19 | v13_: int = add c12_ v8_; 20 | c14_: int = const 1; 21 | v15_: int = add c14_ v9_; 22 | v16_: bool = lt v15_ v10_; 23 | v8_: int = id v13_; 24 | v9_: int = id v15_; 25 | v10_: int = id v10_; 26 | br v16_ .b11_ .b17_; 27 | .b17_: 28 | v3_: int = id v8_; 29 | v4_: int = id v9_; 30 | v5_: int = id v10_; 31 | print v3_; 32 | ret; 33 | jmp .b18_; 34 | .b7_: 35 | print v3_; 36 | ret; 37 | .b18_: 38 | } 39 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_peeling-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 5 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = lt c1_ v0; 9 | v3_: int = id c1_; 10 | v4_: int = id c1_; 11 | v5_: int = id v0; 12 | br v2_ .b6_ .b7_; 13 | .b6_: 14 | v8_: int = id c1_; 15 | v9_: int = id c1_; 16 | v10_: int = id v0; 17 | .b11_: 18 | c12_: int = const 5; 19 | v13_: int = add c12_ v8_; 20 | c14_: int = const 1; 21 | v15_: int = add c14_ v9_; 22 | v16_: bool = lt v15_ v10_; 23 | v8_: int = id v13_; 24 | v9_: int = id v15_; 25 | v10_: int = id v10_; 26 | br v16_ .b11_ .b17_; 27 | .b17_: 28 | v3_: int = id v8_; 29 | v4_: int = id v9_; 30 | v5_: int = id v10_; 31 | print v3_; 32 | ret; 33 | jmp .b18_; 34 | .b7_: 35 | print v3_; 36 | ret; 37 | .b18_: 38 | } 39 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_strength_reduction-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 1; 9 | c2_: int = const 5; 10 | c3_: int = const 300; 11 | v4_: int = id c0_; 12 | v5_: int = id c1_; 13 | v6_: int = id c0_; 14 | v7_: int = id c2_; 15 | v8_: int = id c3_; 16 | .b9_: 17 | c10_: int = const 2; 18 | v11_: int = add c10_ v6_; 19 | v12_: int = add v11_ v5_; 20 | v13_: int = mul v12_ v7_; 21 | v14_: int = mul v11_ v7_; 22 | v15_: int = add v5_ v6_; 23 | v16_: int = mul v15_ v7_; 24 | v17_: int = mul v6_ v7_; 25 | print v17_; 26 | print v16_; 27 | print v14_; 28 | print v13_; 29 | v18_: int = add c10_ v4_; 30 | v19_: int = add c10_ v18_; 31 | v20_: int = add c10_ v11_; 32 | v21_: bool = lt v19_ v8_; 33 | v4_: int = id v19_; 34 | v5_: int = id v5_; 35 | v6_: int = id v20_; 36 | v7_: int = id v7_; 37 | v8_: int = id v8_; 38 | br v21_ .b9_ .b22_; 39 | .b22_: 40 | ret; 41 | } 42 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_strength_reduction-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 1; 9 | c2_: int = const 5; 10 | c3_: int = const 300; 11 | v4_: int = id c0_; 12 | v5_: int = id c1_; 13 | v6_: int = id c0_; 14 | v7_: int = id c2_; 15 | v8_: int = id c3_; 16 | v9_: int = id c0_; 17 | .b10_: 18 | print v9_; 19 | v11_: int = add v4_ v5_; 20 | v12_: int = add v5_ v6_; 21 | v13_: int = add v7_ v9_; 22 | v14_: bool = lt v11_ v8_; 23 | v4_: int = id v11_; 24 | v5_: int = id v5_; 25 | v6_: int = id v12_; 26 | v7_: int = id v7_; 27 | v8_: int = id v8_; 28 | v9_: int = id v13_; 29 | br v14_ .b10_ .b15_; 30 | .b15_: 31 | ret; 32 | } 33 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_unroll-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 1; 9 | v2_: int = id c0_; 10 | v3_: int = id c1_; 11 | .b4_: 12 | v5_: int = add v2_ v3_; 13 | v6_: bool = lt v5_ v3_; 14 | v2_: int = id v5_; 15 | v3_: int = id v3_; 16 | br v6_ .b4_ .b7_; 17 | .b7_: 18 | print v2_; 19 | ret; 20 | } 21 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_unroll-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 1; 9 | v2_: int = id c0_; 10 | v3_: int = id c1_; 11 | .b4_: 12 | v5_: int = add v2_ v3_; 13 | v6_: bool = lt v5_ v3_; 14 | v2_: int = id v5_; 15 | v3_: int = id v3_; 16 | br v6_ .b4_ .b7_; 17 | .b7_: 18 | print v2_; 19 | ret; 20 | } 21 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_with_mul_by_inv-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 4 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | c2_: int = const 5; 9 | v3_: int = id c1_; 10 | v4_: int = id c1_; 11 | v5_: int = id c2_; 12 | v6_: int = id v0; 13 | .b7_: 14 | v8_: int = mul v4_ v5_; 15 | v9_: int = add v3_ v8_; 16 | c10_: int = const 1; 17 | v11_: int = add c10_ v4_; 18 | v12_: bool = lt v4_ v6_; 19 | v3_: int = id v9_; 20 | v4_: int = id v11_; 21 | v5_: int = id v5_; 22 | v6_: int = id v6_; 23 | br v12_ .b7_ .b13_; 24 | .b13_: 25 | print v3_; 26 | ret; 27 | } 28 | -------------------------------------------------------------------------------- /tests/snapshots/files__loop_with_mul_by_inv-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 4 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | c2_: int = const 5; 9 | v3_: int = id c1_; 10 | v4_: int = id c1_; 11 | v5_: int = id c2_; 12 | v6_: int = id v0; 13 | v7_: int = id c1_; 14 | .b8_: 15 | v9_: int = add v3_ v7_; 16 | c10_: int = const 1; 17 | v11_: int = add c10_ v4_; 18 | v12_: int = add v5_ v7_; 19 | v13_: bool = lt v4_ v6_; 20 | v3_: int = id v9_; 21 | v4_: int = id v11_; 22 | v5_: int = id v5_; 23 | v6_: int = id v6_; 24 | v7_: int = id v12_; 25 | br v13_ .b8_ .b14_; 26 | .b14_: 27 | print v3_; 28 | ret; 29 | } 30 | -------------------------------------------------------------------------------- /tests/snapshots/files__lowbit-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 21324 7 | @main(v0: int) { 8 | v1_: int = neg v0; 9 | v2_: int = bitand v0 v1_; 10 | print v2_; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/snapshots/files__lowbit-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 21324 7 | @main(v0: int) { 8 | v1_: int = neg v0; 9 | v2_: int = bitand v0 v1_; 10 | print v2_; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/snapshots/files__lowbit_br-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 21324 7 | @main(v0: int) { 8 | v1_: int = neg v0; 9 | v2_: int = bitand v0 v1_; 10 | print v2_; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/snapshots/files__lowbit_br-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 21324 7 | @main(v0: int) { 8 | v1_: int = neg v0; 9 | v2_: int = bitand v0 v1_; 10 | print v2_; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/snapshots/files__lowbit_naive-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 21324 7 | @main(v0: int) { 8 | c1_: int = const 2; 9 | v2_: int = div v0 c1_; 10 | v3_: int = mul c1_ v2_; 11 | v4_: bool = eq v0 v3_; 12 | c5_: int = const 1; 13 | v6_: int = id c5_; 14 | v7_: int = id v0; 15 | br v4_ .b8_ .b9_; 16 | .b8_: 17 | v10_: int = id c5_; 18 | v11_: int = id v0; 19 | .b12_: 20 | c13_: int = const 2; 21 | v14_: int = mul c13_ v10_; 22 | v15_: int = div v11_ c13_; 23 | v16_: int = div v15_ c13_; 24 | v17_: int = mul c13_ v16_; 25 | v18_: bool = eq v15_ v17_; 26 | v10_: int = id v14_; 27 | v11_: int = id v15_; 28 | br v18_ .b12_ .b19_; 29 | .b19_: 30 | v6_: int = id v10_; 31 | v7_: int = id v11_; 32 | print v6_; 33 | ret; 34 | jmp .b20_; 35 | .b9_: 36 | print v6_; 37 | ret; 38 | .b20_: 39 | } 40 | -------------------------------------------------------------------------------- /tests/snapshots/files__lowbit_naive-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 21324 7 | @main(v0: int) { 8 | v1_: int = neg v0; 9 | v2_: int = bitand v0 v1_; 10 | print v2_; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/snapshots/files__lowbit_naive_br-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 21324 7 | @main(v0: int) { 8 | c1_: int = const 2; 9 | v2_: int = div v0 c1_; 10 | v3_: int = mul c1_ v2_; 11 | v4_: bool = eq v0 v3_; 12 | c5_: int = const 1; 13 | v6_: int = id c5_; 14 | v7_: int = id c1_; 15 | v8_: int = id v0; 16 | br v4_ .b9_ .b10_; 17 | .b9_: 18 | v11_: int = id c5_; 19 | v12_: int = id c1_; 20 | v13_: int = id v0; 21 | .b14_: 22 | v15_: int = mul v11_ v12_; 23 | v16_: int = div v13_ v12_; 24 | v17_: int = div v16_ v12_; 25 | v18_: int = mul v12_ v17_; 26 | v19_: bool = eq v16_ v18_; 27 | v11_: int = id v15_; 28 | v12_: int = id v12_; 29 | v13_: int = id v16_; 30 | br v19_ .b14_ .b20_; 31 | .b20_: 32 | v6_: int = id v11_; 33 | v7_: int = id v12_; 34 | v8_: int = id v13_; 35 | print v6_; 36 | ret; 37 | jmp .b21_; 38 | .b10_: 39 | print v6_; 40 | ret; 41 | .b21_: 42 | } 43 | -------------------------------------------------------------------------------- /tests/snapshots/files__lowbit_naive_br-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | snapshot_kind: text 5 | --- 6 | # ARGS: 21324 7 | @main(v0: int) { 8 | v1_: int = neg v0; 9 | v2_: int = bitand v0 v1_; 10 | print v2_; 11 | ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/snapshots/files__max-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 30 6 | @main(v0: int, v1: int) { 7 | v2_: bool = gt v0 v1; 8 | v3_: int = select v2_ v0 v1; 9 | print v3_; 10 | ret; 11 | } 12 | -------------------------------------------------------------------------------- /tests/snapshots/files__max-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 30 6 | @main(v0: int, v1: int) { 7 | v2_: int = smax v1 v0; 8 | print v2_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__mem_loop_store_forwarding-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: false 6 | @main(v0: bool) { 7 | c1_: int = const 3; 8 | v2_: ptr = alloc c1_; 9 | c3_: int = const 1; 10 | v4_: ptr = ptradd v2_ c3_; 11 | c5_: int = const 2; 12 | v6_: ptr = ptradd v2_ c5_; 13 | v7_: ptr = id v4_; 14 | v8_: ptr = id v2_; 15 | v9_: ptr = id v6_; 16 | v10_: bool = id v0; 17 | v7_: ptr = id v8_; 18 | v8_: ptr = id v7_; 19 | v9_: ptr = id v9_; 20 | v10_: bool = id v10_; 21 | .b11_: 22 | br v10_ .b12_ .b13_; 23 | .b12_: 24 | v7_: ptr = id v8_; 25 | v8_: ptr = id v7_; 26 | v9_: ptr = id v9_; 27 | v10_: bool = id v10_; 28 | jmp .b11_; 29 | .b13_: 30 | c14_: int = const 20; 31 | c15_: int = const 10; 32 | store v8_ c15_; 33 | store v9_ c14_; 34 | v16_: int = load v8_; 35 | print v16_; 36 | free v7_; 37 | ret; 38 | } 39 | -------------------------------------------------------------------------------- /tests/snapshots/files__mem_loop_store_forwarding-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: false 6 | @main(v0: bool) { 7 | c1_: int = const 3; 8 | v2_: ptr = alloc c1_; 9 | c3_: int = const 1; 10 | v4_: ptr = ptradd v2_ c3_; 11 | c5_: int = const 2; 12 | v6_: ptr = ptradd v2_ c5_; 13 | v7_: ptr = id v4_; 14 | v8_: ptr = id v2_; 15 | v9_: ptr = id v6_; 16 | v10_: bool = id v0; 17 | v7_: ptr = id v8_; 18 | v8_: ptr = id v7_; 19 | v9_: ptr = id v9_; 20 | v10_: bool = id v10_; 21 | .b11_: 22 | br v10_ .b12_ .b13_; 23 | .b12_: 24 | v7_: ptr = id v8_; 25 | v8_: ptr = id v7_; 26 | v9_: ptr = id v9_; 27 | v10_: bool = id v10_; 28 | jmp .b11_; 29 | .b13_: 30 | c14_: int = const 20; 31 | c15_: int = const 10; 32 | store v8_ c15_; 33 | store v9_ c14_; 34 | v16_: int = load v8_; 35 | print v16_; 36 | free v7_; 37 | ret; 38 | } 39 | -------------------------------------------------------------------------------- /tests/snapshots/files__mem_simple_redundant_load-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: false 6 | @main(v0: bool) { 7 | c1_: int = const 1; 8 | v2_: ptr = alloc c1_; 9 | br v0 .b3_ .b4_; 10 | .b3_: 11 | c5_: int = const 2; 12 | store v2_ c5_; 13 | v6_: ptr = id v2_; 14 | v7_: int = load v2_; 15 | v8_: int = load v2_; 16 | print v8_; 17 | free v2_; 18 | ret; 19 | jmp .b9_; 20 | .b4_: 21 | c10_: int = const 3; 22 | store v2_ c10_; 23 | v6_: ptr = id v2_; 24 | v7_: int = load v2_; 25 | v8_: int = load v2_; 26 | print v8_; 27 | free v2_; 28 | ret; 29 | .b9_: 30 | } 31 | -------------------------------------------------------------------------------- /tests/snapshots/files__mem_simple_redundant_load-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: false 6 | @main(v0: bool) { 7 | c1_: int = const 1; 8 | v2_: ptr = alloc c1_; 9 | br v0 .b3_ .b4_; 10 | .b3_: 11 | c5_: int = const 2; 12 | store v2_ c5_; 13 | v6_: ptr = id v2_; 14 | v7_: int = load v2_; 15 | v8_: int = load v2_; 16 | print v8_; 17 | free v2_; 18 | ret; 19 | jmp .b9_; 20 | .b4_: 21 | c10_: int = const 3; 22 | store v2_ c10_; 23 | v6_: ptr = id v2_; 24 | v7_: int = load v2_; 25 | v8_: int = load v2_; 26 | print v8_; 27 | free v2_; 28 | ret; 29 | .b9_: 30 | } 31 | -------------------------------------------------------------------------------- /tests/snapshots/files__mem_simple_store_forwarding-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 2; 8 | v1_: ptr = alloc c0_; 9 | c2_: int = const 10; 10 | c3_: int = const 1; 11 | v4_: ptr = ptradd v1_ c3_; 12 | c5_: int = const 20; 13 | store v1_ c2_; 14 | store v4_ c5_; 15 | print c2_; 16 | free v1_; 17 | ret; 18 | } 19 | -------------------------------------------------------------------------------- /tests/snapshots/files__mem_simple_store_forwarding-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 2; 8 | v1_: ptr = alloc c0_; 9 | c2_: int = const 10; 10 | c3_: int = const 1; 11 | v4_: ptr = ptradd v1_ c3_; 12 | c5_: int = const 20; 13 | store v1_ c2_; 14 | store v4_ c5_; 15 | print c2_; 16 | free v1_; 17 | ret; 18 | } 19 | -------------------------------------------------------------------------------- /tests/snapshots/files__min-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 30 6 | @main(v0: int, v1: int) { 7 | v2_: bool = lt v0 v1; 8 | v3_: int = select v2_ v0 v1; 9 | print v3_; 10 | ret; 11 | } 12 | -------------------------------------------------------------------------------- /tests/snapshots/files__min-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 30 6 | @main(v0: int, v1: int) { 7 | v2_: int = smin v0 v1; 8 | print v2_; 9 | ret; 10 | } 11 | -------------------------------------------------------------------------------- /tests/snapshots/files__nested_call-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @inc(v0: int): int { 7 | c1_: int = const 2; 8 | c2_: int = const 1; 9 | v3_: int = add c2_ v0; 10 | v4_: int = mul c1_ v3_; 11 | ret v4_; 12 | } 13 | @double(v0: int): int { 14 | c1_: int = const 2; 15 | v2_: int = mul c1_ v0; 16 | ret v2_; 17 | } 18 | @main { 19 | c0_: int = const 2; 20 | print c0_; 21 | print c0_; 22 | ret; 23 | } 24 | -------------------------------------------------------------------------------- /tests/snapshots/files__nested_call-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @inc(v0: int): int { 7 | c1_: int = const 2; 8 | c2_: int = const 1; 9 | v3_: int = add c2_ v0; 10 | v4_: int = mul c1_ v3_; 11 | ret v4_; 12 | } 13 | @double(v0: int): int { 14 | c1_: int = const 2; 15 | v2_: int = mul c1_ v0; 16 | ret v2_; 17 | } 18 | @main { 19 | c0_: int = const 2; 20 | print c0_; 21 | print c0_; 22 | ret; 23 | } 24 | -------------------------------------------------------------------------------- /tests/snapshots/files__peel_twice-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 2; 9 | c2_: int = const 1; 10 | v3_: int = id c0_; 11 | v4_: int = id c1_; 12 | v5_: int = id c2_; 13 | .b6_: 14 | v7_: int = add v3_ v5_; 15 | v8_: bool = lt v7_ v4_; 16 | v3_: int = id v7_; 17 | v4_: int = id v4_; 18 | v5_: int = id v5_; 19 | br v8_ .b6_ .b9_; 20 | .b9_: 21 | print v3_; 22 | ret; 23 | } 24 | -------------------------------------------------------------------------------- /tests/snapshots/files__peel_twice-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 2; 9 | c2_: int = const 1; 10 | v3_: int = id c0_; 11 | v4_: int = id c1_; 12 | v5_: int = id c2_; 13 | .b6_: 14 | v7_: int = add v3_ v5_; 15 | v8_: bool = lt v7_ v4_; 16 | v3_: int = id v7_; 17 | v4_: int = id v4_; 18 | v5_: int = id v5_; 19 | br v8_ .b6_ .b9_; 20 | .b9_: 21 | print v3_; 22 | ret; 23 | } 24 | -------------------------------------------------------------------------------- /tests/snapshots/files__peel_twice_precalc_pred-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 1; 9 | v2_: int = id c0_; 10 | v3_: int = id c1_; 11 | .b4_: 12 | v5_: int = add v2_ v3_; 13 | v6_: bool = lt v2_ v3_; 14 | v2_: int = id v5_; 15 | v3_: int = id v3_; 16 | br v6_ .b4_ .b7_; 17 | .b7_: 18 | print v2_; 19 | ret; 20 | } 21 | -------------------------------------------------------------------------------- /tests/snapshots/files__peel_twice_precalc_pred-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 1; 9 | v2_: int = id c0_; 10 | v3_: int = id c1_; 11 | .b4_: 12 | v5_: int = add v2_ v3_; 13 | v6_: bool = lt v2_ v3_; 14 | v2_: int = id v5_; 15 | v3_: int = id v3_; 16 | br v6_ .b4_ .b7_; 17 | .b7_: 18 | print v2_; 19 | ret; 20 | } 21 | -------------------------------------------------------------------------------- /tests/snapshots/files__pull_out_small-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @main(v0: int) { 7 | c1_: int = const 5; 8 | v2_: int = mul c1_ v0; 9 | c3_: int = const 0; 10 | v4_: bool = lt c3_ v0; 11 | br v4_ .b5_ .b6_; 12 | .b5_: 13 | c7_: int = const 20; 14 | print c7_; 15 | v8_: int = id v2_; 16 | print v2_; 17 | ret; 18 | jmp .b9_; 19 | .b6_: 20 | c10_: int = const 20; 21 | print c10_; 22 | v8_: int = id v2_; 23 | print v2_; 24 | ret; 25 | .b9_: 26 | } 27 | -------------------------------------------------------------------------------- /tests/snapshots/files__pull_out_small-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @main(v0: int) { 7 | c1_: int = const 5; 8 | v2_: int = mul c1_ v0; 9 | c3_: int = const 0; 10 | v4_: bool = lt c3_ v0; 11 | br v4_ .b5_ .b6_; 12 | .b5_: 13 | c7_: int = const 20; 14 | print c7_; 15 | v8_: int = id v2_; 16 | print v2_; 17 | ret; 18 | jmp .b9_; 19 | .b6_: 20 | c10_: int = const 20; 21 | print c10_; 22 | v8_: int = id v2_; 23 | print v2_; 24 | ret; 25 | .b9_: 26 | } 27 | -------------------------------------------------------------------------------- /tests/snapshots/files__range_check-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | v1_: int = id c0_; 9 | .b2_: 10 | c3_: int = const 5; 11 | v4_: bool = lt v1_ c3_; 12 | br v4_ .b5_ .b6_; 13 | .b5_: 14 | c7_: int = const 1; 15 | print c7_; 16 | v8_: int = id v1_; 17 | .b9_: 18 | c10_: int = const 1; 19 | v11_: int = add c10_ v1_; 20 | c12_: int = const 6; 21 | v13_: bool = lt v1_ c12_; 22 | v1_: int = id v11_; 23 | br v13_ .b2_ .b14_; 24 | .b6_: 25 | c15_: int = const 2; 26 | print c15_; 27 | v8_: int = id v1_; 28 | jmp .b9_; 29 | .b14_: 30 | print v1_; 31 | ret; 32 | } 33 | -------------------------------------------------------------------------------- /tests/snapshots/files__range_check-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | v1_: int = id c0_; 9 | .b2_: 10 | c3_: int = const 5; 11 | v4_: bool = lt v1_ c3_; 12 | br v4_ .b5_ .b6_; 13 | .b5_: 14 | c7_: int = const 1; 15 | print c7_; 16 | v8_: int = id v1_; 17 | .b9_: 18 | c10_: int = const 1; 19 | v11_: int = add c10_ v1_; 20 | c12_: int = const 6; 21 | v13_: bool = lt v1_ c12_; 22 | v1_: int = id v11_; 23 | br v13_ .b2_ .b14_; 24 | .b6_: 25 | c15_: int = const 2; 26 | print c15_; 27 | v8_: int = id v1_; 28 | jmp .b9_; 29 | .b14_: 30 | print v1_; 31 | ret; 32 | } 33 | -------------------------------------------------------------------------------- /tests/snapshots/files__range_splitting-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | v1_: int = id c0_; 9 | .b2_: 10 | c3_: int = const 5; 11 | v4_: bool = lt v1_ c3_; 12 | br v4_ .b5_ .b6_; 13 | .b5_: 14 | c7_: int = const 1; 15 | print c7_; 16 | v8_: int = id v1_; 17 | .b9_: 18 | c10_: int = const 1; 19 | v11_: int = add c10_ v1_; 20 | v12_: bool = lt v11_ c3_; 21 | v1_: int = id v11_; 22 | br v12_ .b2_ .b13_; 23 | .b6_: 24 | c14_: int = const 2; 25 | print c14_; 26 | v8_: int = id v1_; 27 | jmp .b9_; 28 | .b13_: 29 | print v1_; 30 | ret; 31 | } 32 | -------------------------------------------------------------------------------- /tests/snapshots/files__range_splitting-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | v1_: int = id c0_; 9 | .b2_: 10 | c3_: int = const 5; 11 | v4_: bool = lt v1_ c3_; 12 | br v4_ .b5_ .b6_; 13 | .b5_: 14 | c7_: int = const 1; 15 | print c7_; 16 | v8_: int = id v1_; 17 | .b9_: 18 | c10_: int = const 1; 19 | v11_: int = add c10_ v1_; 20 | v12_: bool = lt v11_ c3_; 21 | v1_: int = id v11_; 22 | br v12_ .b2_ .b13_; 23 | .b6_: 24 | c14_: int = const 2; 25 | print c14_; 26 | v8_: int = id v1_; 27 | jmp .b9_; 28 | .b13_: 29 | print v1_; 30 | ret; 31 | } 32 | -------------------------------------------------------------------------------- /tests/snapshots/files__reassoc-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 2 4 6 | @main(v0: int, v1: int) { 7 | c2_: int = const 4; 8 | v3_: int = add c2_ v1; 9 | c4_: int = const 3; 10 | v5_: int = add c4_ v0; 11 | v6_: int = add v3_ v5_; 12 | c7_: int = const 1; 13 | v8_: int = add c7_ v6_; 14 | print v8_; 15 | ret; 16 | } 17 | -------------------------------------------------------------------------------- /tests/snapshots/files__reassoc-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 2 4 6 | @main(v0: int, v1: int) { 7 | c2_: int = const 4; 8 | v3_: int = add c2_ v1; 9 | c4_: int = const 3; 10 | v5_: int = add c4_ v0; 11 | v6_: int = add v3_ v5_; 12 | c7_: int = const 1; 13 | v8_: int = add c7_ v6_; 14 | print v8_; 15 | ret; 16 | } 17 | -------------------------------------------------------------------------------- /tests/snapshots/files__recurse_once-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @to_zero(v0: int): int { 7 | c1_: int = const 0; 8 | v2_: bool = lt c1_ v0; 9 | v3_: int = id v0; 10 | br v2_ .b4_ .b5_; 11 | .b4_: 12 | v6_: int = id v0; 13 | .b7_: 14 | c8_: int = const 1; 15 | v9_: int = sub v6_ c8_; 16 | c10_: int = const 0; 17 | v11_: bool = lt c10_ v9_; 18 | v6_: int = id v9_; 19 | br v11_ .b7_ .b12_; 20 | .b12_: 21 | v3_: int = id v6_; 22 | ret v3_; 23 | jmp .b13_; 24 | .b5_: 25 | ret v3_; 26 | .b13_: 27 | } 28 | @main { 29 | c0_: int = const 1; 30 | v1_: int = id c0_; 31 | .b2_: 32 | c3_: int = const 1; 33 | v4_: int = sub v1_ c3_; 34 | c5_: int = const 0; 35 | v6_: bool = lt c5_ v4_; 36 | v1_: int = id v4_; 37 | br v6_ .b2_ .b7_; 38 | .b7_: 39 | print v1_; 40 | ret; 41 | } 42 | -------------------------------------------------------------------------------- /tests/snapshots/files__recurse_once-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @to_zero(v0: int): int { 7 | c1_: int = const 0; 8 | v2_: bool = lt c1_ v0; 9 | v3_: int = id v0; 10 | br v2_ .b4_ .b5_; 11 | .b4_: 12 | v6_: int = id v0; 13 | .b7_: 14 | c8_: int = const 1; 15 | v9_: int = sub v6_ c8_; 16 | c10_: int = const 0; 17 | v11_: bool = lt c10_ v9_; 18 | v6_: int = id v9_; 19 | br v11_ .b7_ .b12_; 20 | .b12_: 21 | v3_: int = id v6_; 22 | ret v3_; 23 | jmp .b13_; 24 | .b5_: 25 | ret v3_; 26 | .b13_: 27 | } 28 | @main { 29 | c0_: int = const 1; 30 | v1_: int = id c0_; 31 | .b2_: 32 | c3_: int = const 1; 33 | v4_: int = sub v1_ c3_; 34 | c5_: int = const 0; 35 | v6_: bool = lt c5_ v4_; 36 | v1_: int = id v4_; 37 | br v6_ .b2_ .b7_; 38 | .b7_: 39 | print v1_; 40 | ret; 41 | } 42 | -------------------------------------------------------------------------------- /tests/snapshots/files__select-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 6 | @main(v0: int) { 7 | c1_: int = const 5; 8 | c2_: int = const 10; 9 | v3_: bool = eq c1_ c2_; 10 | v4_: bool = not v3_; 11 | c5_: int = const 0; 12 | v6_: int = id c5_; 13 | v7_: int = id c2_; 14 | v8_: int = id c5_; 15 | v9_: int = id v0; 16 | br v4_ .b10_ .b11_; 17 | .b10_: 18 | v12_: int = id c5_; 19 | v13_: int = id c2_; 20 | v14_: int = id c5_; 21 | v15_: int = id v0; 22 | .b16_: 23 | c17_: int = const 1; 24 | v18_: int = add c17_ v14_; 25 | v19_: int = add v12_ v18_; 26 | v20_: bool = eq v15_ v18_; 27 | c21_: int = const 5; 28 | v22_: int = select v20_ c21_ v13_; 29 | v23_: bool = eq c21_ v22_; 30 | v24_: bool = not v23_; 31 | v12_: int = id v19_; 32 | v13_: int = id v22_; 33 | v14_: int = id v18_; 34 | v15_: int = id v15_; 35 | br v24_ .b16_ .b25_; 36 | .b25_: 37 | v6_: int = id v12_; 38 | v7_: int = id v13_; 39 | v8_: int = id v14_; 40 | v9_: int = id v15_; 41 | print v6_; 42 | ret; 43 | jmp .b26_; 44 | .b11_: 45 | print v6_; 46 | ret; 47 | .b26_: 48 | } 49 | -------------------------------------------------------------------------------- /tests/snapshots/files__select_simple-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 30 6 | @main(v0: int, v1: int) { 7 | v2_: int = mul v0 v1; 8 | c3_: int = const 20; 9 | v4_: bool = lt v2_ c3_; 10 | v5_: int = select v4_ v0 v1; 11 | print v5_; 12 | ret; 13 | } 14 | -------------------------------------------------------------------------------- /tests/snapshots/files__select_simple-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 20 30 6 | @main(v0: int, v1: int) { 7 | v2_: int = mul v0 v1; 8 | c3_: int = const 20; 9 | v4_: bool = lt v2_ c3_; 10 | v5_: int = select v4_ v0 v1; 11 | print v5_; 12 | ret; 13 | } 14 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple-call-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @inc(v0: int): int { 7 | c1_: int = const 1; 8 | v2_: int = add c1_ v0; 9 | ret v2_; 10 | } 11 | @main { 12 | c0_: int = const 1; 13 | print c0_; 14 | ret; 15 | } 16 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple-call-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @inc(v0: int): int { 7 | c1_: int = const 1; 8 | v2_: int = add c1_ v0; 9 | ret v2_; 10 | } 11 | @main { 12 | c0_: int = const 1; 13 | print c0_; 14 | ret; 15 | } 16 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_branch-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = lt v0 c1_; 9 | c3_: int = const 1; 10 | v4_: int = select v2_ c3_ c1_; 11 | print v4_; 12 | ret; 13 | } 14 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_branch-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = lt v0 c1_; 9 | c3_: int = const 1; 10 | v4_: int = select v2_ c3_ c1_; 11 | print v4_; 12 | ret; 13 | } 14 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_call-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @inc(v0: int) { 7 | c1_: int = const 1; 8 | v2_: int = add c1_ v0; 9 | print v2_; 10 | ret; 11 | } 12 | @main { 13 | c0_: int = const 1; 14 | print c0_; 15 | ret; 16 | } 17 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_call-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @inc(v0: int) { 7 | c1_: int = const 1; 8 | v2_: int = add c1_ v0; 9 | print v2_; 10 | ret; 11 | } 12 | @main { 13 | c0_: int = const 1; 14 | print c0_; 15 | ret; 16 | } 17 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_loop-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: bool = const false; 9 | print c0_; 10 | ret; 11 | } 12 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_loop-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: bool = const false; 9 | print c0_; 10 | ret; 11 | } 12 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_loop_swap-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 2; 8 | v1_: ptr = alloc c0_; 9 | c2_: int = const 10; 10 | c3_: int = const 1; 11 | v4_: ptr = ptradd v1_ c3_; 12 | c5_: int = const 20; 13 | store v1_ c2_; 14 | store v4_ c5_; 15 | print c2_; 16 | free v1_; 17 | ret; 18 | } 19 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_loop_swap-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 2; 8 | v1_: ptr = alloc c0_; 9 | c2_: int = const 10; 10 | c3_: int = const 1; 11 | v4_: ptr = ptradd v1_ c3_; 12 | c5_: int = const 20; 13 | store v1_ c2_; 14 | store v4_ c5_; 15 | print c2_; 16 | free v1_; 17 | ret; 18 | } 19 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_loop_unswitch-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 40 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = lt c1_ v0; 9 | c3_: int = const 1; 10 | v4_: int = id c1_; 11 | v5_: int = id c1_; 12 | v6_: int = id c3_; 13 | v7_: int = id v0; 14 | v8_: int = id c1_; 15 | br v2_ .b9_ .b10_; 16 | .b9_: 17 | v11_: int = id c1_; 18 | v12_: int = id c1_; 19 | v13_: int = id c3_; 20 | v14_: int = id v0; 21 | v15_: int = id c1_; 22 | .b16_: 23 | print v12_; 24 | v17_: int = add v11_ v13_; 25 | v18_: int = add v12_ v13_; 26 | v19_: bool = lt v18_ v14_; 27 | v11_: int = id v17_; 28 | v12_: int = id v18_; 29 | v13_: int = id v13_; 30 | v14_: int = id v14_; 31 | v15_: int = id v15_; 32 | br v19_ .b16_ .b20_; 33 | .b20_: 34 | v4_: int = id v11_; 35 | v5_: int = id v12_; 36 | v6_: int = id v13_; 37 | v7_: int = id v14_; 38 | v8_: int = id v15_; 39 | print v4_; 40 | ret; 41 | jmp .b21_; 42 | .b10_: 43 | print v4_; 44 | ret; 45 | .b21_: 46 | } 47 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_recursive-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @inc(v0: int): int { 7 | c1_: int = const 2; 8 | v2_: bool = lt v0 c1_; 9 | v3_: int = id v0; 10 | br v2_ .b4_ .b5_; 11 | .b4_: 12 | v6_: int = id v0; 13 | .b7_: 14 | c8_: int = const 1; 15 | v9_: int = add c8_ v6_; 16 | print v9_; 17 | c10_: int = const 2; 18 | v11_: bool = lt v9_ c10_; 19 | v6_: int = id v9_; 20 | br v11_ .b7_ .b12_; 21 | .b12_: 22 | v3_: int = id v6_; 23 | ret v3_; 24 | jmp .b13_; 25 | .b5_: 26 | ret v3_; 27 | .b13_: 28 | } 29 | @main { 30 | c0_: int = const 0; 31 | v1_: int = id c0_; 32 | .b2_: 33 | c3_: int = const 1; 34 | v4_: int = add c3_ v1_; 35 | print v4_; 36 | c5_: int = const 2; 37 | v6_: bool = lt v4_ c5_; 38 | v1_: int = id v4_; 39 | br v6_ .b2_ .b7_; 40 | .b7_: 41 | print v1_; 42 | ret; 43 | } 44 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_recursive-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @inc(v0: int): int { 7 | c1_: int = const 2; 8 | v2_: bool = lt v0 c1_; 9 | v3_: int = id v0; 10 | br v2_ .b4_ .b5_; 11 | .b4_: 12 | v6_: int = id v0; 13 | .b7_: 14 | c8_: int = const 1; 15 | v9_: int = add c8_ v6_; 16 | print v9_; 17 | c10_: int = const 2; 18 | v11_: bool = lt v9_ c10_; 19 | v6_: int = id v9_; 20 | br v11_ .b7_ .b12_; 21 | .b12_: 22 | v3_: int = id v6_; 23 | ret v3_; 24 | jmp .b13_; 25 | .b5_: 26 | ret v3_; 27 | .b13_: 28 | } 29 | @main { 30 | c0_: int = const 0; 31 | v1_: int = id c0_; 32 | .b2_: 33 | c3_: int = const 1; 34 | v4_: int = add c3_ v1_; 35 | print v4_; 36 | c5_: int = const 2; 37 | v6_: bool = lt v4_ c5_; 38 | v1_: int = id v4_; 39 | br v6_ .b2_ .b7_; 40 | .b7_: 41 | print v1_; 42 | ret; 43 | } 44 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_select_after_block_diamond-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 2; 8 | v2_: bool = lt v0 c1_; 9 | c3_: int = const 4; 10 | c4_: int = const 1; 11 | v5_: int = select v2_ c3_ c4_; 12 | v6_: int = add c1_ v5_; 13 | v7_: int = select v2_ v5_ v6_; 14 | v8_: int = add c4_ v7_; 15 | print v8_; 16 | ret; 17 | } 18 | -------------------------------------------------------------------------------- /tests/snapshots/files__simple_select_after_block_diamond-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 1 6 | @main(v0: int) { 7 | c1_: int = const 2; 8 | v2_: bool = lt v0 c1_; 9 | c3_: int = const 4; 10 | c4_: int = const 1; 11 | v5_: int = select v2_ c3_ c4_; 12 | v6_: int = add c1_ v5_; 13 | v7_: int = select v2_ v5_ v6_; 14 | v8_: int = add c4_ v7_; 15 | print v8_; 16 | ret; 17 | } 18 | -------------------------------------------------------------------------------- /tests/snapshots/files__simplest_loop-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 5; 9 | c2_: int = const 1; 10 | v3_: int = id c0_; 11 | v4_: int = id c1_; 12 | v5_: int = id c2_; 13 | .b6_: 14 | v7_: int = add v3_ v5_; 15 | v8_: bool = lt v7_ v4_; 16 | v3_: int = id v7_; 17 | v4_: int = id v4_; 18 | v5_: int = id v5_; 19 | br v8_ .b6_ .b9_; 20 | .b9_: 21 | ret; 22 | } 23 | -------------------------------------------------------------------------------- /tests/snapshots/files__simplest_loop-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 5; 9 | c2_: int = const 1; 10 | v3_: int = id c0_; 11 | v4_: int = id c1_; 12 | v5_: int = id c2_; 13 | .b6_: 14 | v7_: int = add v3_ v5_; 15 | v8_: bool = lt v7_ v4_; 16 | v3_: int = id v7_; 17 | v4_: int = id v4_; 18 | v5_: int = id v5_; 19 | br v8_ .b6_ .b9_; 20 | .b9_: 21 | ret; 22 | } 23 | -------------------------------------------------------------------------------- /tests/snapshots/files__small-fib-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 2 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = eq c1_ v0; 9 | c3_: int = const 1; 10 | print c3_; 11 | br v2_ .b4_ .b5_; 12 | .b4_: 13 | ret; 14 | jmp .b6_; 15 | .b5_: 16 | v7_: bool = lt c3_ v0; 17 | print c3_; 18 | v8_: int = id c3_; 19 | v9_: int = id c3_; 20 | v10_: int = id c3_; 21 | v11_: int = id v0; 22 | br v7_ .b12_ .b13_; 23 | .b12_: 24 | v14_: int = id c3_; 25 | v15_: int = id c3_; 26 | v16_: int = id c3_; 27 | v17_: int = id v0; 28 | .b18_: 29 | v19_: int = add v15_ v16_; 30 | print v19_; 31 | c20_: int = const 1; 32 | v21_: int = add c20_ v14_; 33 | v22_: bool = lt v21_ v17_; 34 | v14_: int = id v21_; 35 | v15_: int = id v19_; 36 | v16_: int = id v15_; 37 | v17_: int = id v17_; 38 | br v22_ .b18_ .b23_; 39 | .b23_: 40 | v8_: int = id v14_; 41 | v9_: int = id v15_; 42 | v10_: int = id v16_; 43 | v11_: int = id v17_; 44 | ret; 45 | jmp .b6_; 46 | .b13_: 47 | ret; 48 | .b6_: 49 | } 50 | -------------------------------------------------------------------------------- /tests/snapshots/files__small-fib-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 2 6 | @main(v0: int) { 7 | c1_: int = const 0; 8 | v2_: bool = eq c1_ v0; 9 | c3_: int = const 1; 10 | print c3_; 11 | br v2_ .b4_ .b5_; 12 | .b4_: 13 | ret; 14 | jmp .b6_; 15 | .b5_: 16 | v7_: bool = lt c3_ v0; 17 | print c3_; 18 | v8_: int = id c3_; 19 | v9_: int = id c3_; 20 | v10_: int = id c3_; 21 | v11_: int = id v0; 22 | br v7_ .b12_ .b13_; 23 | .b12_: 24 | v14_: int = id c3_; 25 | v15_: int = id c3_; 26 | v16_: int = id c3_; 27 | v17_: int = id v0; 28 | .b18_: 29 | v19_: int = add v15_ v16_; 30 | print v19_; 31 | c20_: int = const 1; 32 | v21_: int = add c20_ v14_; 33 | v22_: bool = lt v21_ v17_; 34 | v14_: int = id v21_; 35 | v15_: int = id v19_; 36 | v16_: int = id v15_; 37 | v17_: int = id v17_; 38 | br v22_ .b18_ .b23_; 39 | .b23_: 40 | v8_: int = id v14_; 41 | v9_: int = id v15_; 42 | v10_: int = id v16_; 43 | v11_: int = id v17_; 44 | ret; 45 | jmp .b6_; 46 | .b13_: 47 | ret; 48 | .b6_: 49 | } 50 | -------------------------------------------------------------------------------- /tests/snapshots/files__strong_loop-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 3 6 | @main(v0: int) { 7 | c1_: int = const 3; 8 | v2_: int = add c1_ v0; 9 | c3_: int = const 0; 10 | c4_: int = const 21; 11 | v5_: int = id c1_; 12 | v6_: int = id v2_; 13 | v7_: int = id c3_; 14 | v8_: int = id v0; 15 | v9_: int = id c4_; 16 | .b10_: 17 | print v9_; 18 | c11_: int = const 1; 19 | v12_: int = add c11_ v5_; 20 | v13_: int = add v7_ v9_; 21 | c14_: int = const 7; 22 | v15_: int = add c14_ v9_; 23 | v16_: bool = lt v5_ v8_; 24 | v5_: int = id v12_; 25 | v6_: int = id v6_; 26 | v7_: int = id v13_; 27 | v8_: int = id v8_; 28 | v9_: int = id v15_; 29 | br v16_ .b10_ .b17_; 30 | .b17_: 31 | print v7_; 32 | print v2_; 33 | print v5_; 34 | ret; 35 | } 36 | -------------------------------------------------------------------------------- /tests/snapshots/files__strong_loop-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 3 6 | @main(v0: int) { 7 | c1_: int = const 3; 8 | v2_: int = add c1_ v0; 9 | c3_: int = const 0; 10 | c4_: int = const 21; 11 | v5_: int = id c1_; 12 | v6_: int = id v2_; 13 | v7_: int = id c3_; 14 | v8_: int = id v0; 15 | v9_: int = id c4_; 16 | .b10_: 17 | print v9_; 18 | c11_: int = const 1; 19 | v12_: int = add c11_ v5_; 20 | v13_: int = add v7_ v9_; 21 | c14_: int = const 7; 22 | v15_: int = add c14_ v9_; 23 | v16_: bool = lt v5_ v8_; 24 | v5_: int = id v12_; 25 | v6_: int = id v6_; 26 | v7_: int = id v13_; 27 | v8_: int = id v8_; 28 | v9_: int = id v15_; 29 | br v16_ .b10_ .b17_; 30 | .b17_: 31 | print v7_; 32 | print v2_; 33 | print v5_; 34 | ret; 35 | } 36 | -------------------------------------------------------------------------------- /tests/snapshots/files__two_fns-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @sub: int { 7 | c0_: int = const -1; 8 | ret c0_; 9 | } 10 | @main { 11 | c0_: int = const 3; 12 | print c0_; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /tests/snapshots/files__two_fns-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @sub: int { 7 | c0_: int = const -1; 8 | ret c0_; 9 | } 10 | @main { 11 | c0_: int = const 3; 12 | print c0_; 13 | ret; 14 | } 15 | -------------------------------------------------------------------------------- /tests/snapshots/files__unroll_and_constant_fold-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 1; 9 | v2_: int = id c0_; 10 | v3_: int = id c1_; 11 | .b4_: 12 | v5_: int = add v2_ v3_; 13 | v6_: bool = lt v5_ v3_; 14 | v2_: int = id v5_; 15 | v3_: int = id v3_; 16 | br v6_ .b4_ .b7_; 17 | .b7_: 18 | print v2_; 19 | ret; 20 | } 21 | -------------------------------------------------------------------------------- /tests/snapshots/files__unroll_and_constant_fold-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 1; 9 | v2_: int = id c0_; 10 | v3_: int = id c1_; 11 | .b4_: 12 | v5_: int = add v2_ v3_; 13 | v6_: bool = lt v5_ v3_; 14 | v2_: int = id v5_; 15 | v3_: int = id v3_; 16 | br v6_ .b4_ .b7_; 17 | .b7_: 18 | print v2_; 19 | ret; 20 | } 21 | -------------------------------------------------------------------------------- /tests/snapshots/files__unroll_multiple_4-optimize-sequential.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 16; 9 | c2_: int = const 1; 10 | v3_: int = id c0_; 11 | v4_: int = id c1_; 12 | v5_: int = id c2_; 13 | .b6_: 14 | c7_: int = const 2; 15 | v8_: int = add c7_ v3_; 16 | v9_: int = add c7_ v8_; 17 | v10_: bool = lt v9_ v4_; 18 | v3_: int = id v9_; 19 | v4_: int = id v4_; 20 | v5_: int = id v5_; 21 | br v10_ .b6_ .b11_; 22 | .b11_: 23 | print v3_; 24 | ret; 25 | } 26 | -------------------------------------------------------------------------------- /tests/snapshots/files__unroll_multiple_4-optimize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/files.rs 3 | expression: visualization.result 4 | --- 5 | # ARGS: 6 | @main { 7 | c0_: int = const 0; 8 | c1_: int = const 16; 9 | c2_: int = const 1; 10 | v3_: int = id c0_; 11 | v4_: int = id c1_; 12 | v5_: int = id c2_; 13 | .b6_: 14 | c7_: int = const 4; 15 | v8_: int = add c7_ v3_; 16 | v9_: bool = lt v8_ v4_; 17 | v3_: int = id v8_; 18 | v4_: int = id v4_; 19 | v5_: int = id v5_; 20 | br v9_ .b6_ .b10_; 21 | .b10_: 22 | print v3_; 23 | ret; 24 | } 25 | -------------------------------------------------------------------------------- /writing/.gitignore: -------------------------------------------------------------------------------- 1 | # latex stuff 2 | 3 | *.aux 4 | *.log 5 | *.out 6 | *.synctex.gz 7 | *.fls 8 | *.fdb_latexmk 9 | *.bbl 10 | *.blg 11 | *.pdf 12 | 13 | # mac trash 14 | .DS_Store 15 | 16 | _build/ 17 | *.drawio.bkp 18 | -------------------------------------------------------------------------------- /writing/Makefile: -------------------------------------------------------------------------------- 1 | BUILD_MAIN_TEX := pdflatex -file-line-error -interaction=nonstopmode main.tex 2 | 3 | main.pdf: main.tex semantics.tex macros.tex bcprules.sty 4 | $(BUILD_MAIN_TEX) 5 | 6 | force: .FORCE 7 | $(BUILD_MAIN_TEX) 8 | 9 | .PHONY: force .FORCE 10 | .FORCE: 11 | 12 | --------------------------------------------------------------------------------