75 lines · plain
1(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/passbuilder.ml2 * RUN: %ocamlc -g -w +A -package llvm.passbuilder -package llvm.all_backends -linkpkg %t/passbuilder.ml -o %t/executable3 * RUN: %t/executable4 * RUN: %ocamlopt -g -w +A -package llvm.passbuilder -package llvm.all_backends -linkpkg %t/passbuilder.ml -o %t/executable5 * RUN: %t/executable6 * XFAIL: vg_leak7 *)8 9let () = Llvm_all_backends.initialize ()10 11(*===-- Fixture -----------------------------------------------------------===*)12 13let context = Llvm.global_context ()14 15let m = Llvm.create_module context "mymodule"16 17let () =18 let ty =19 Llvm.function_type (Llvm.void_type context)20 [| Llvm.i1_type context;21 Llvm.pointer_type context;22 Llvm.pointer_type context |]23 in24 let foo = Llvm.define_function "foo" ty m in25 let entry = Llvm.entry_block foo in26 let builder = Llvm.builder_at_end context entry in27 ignore28 (Llvm.build_store29 (Llvm.const_int (Llvm.i8_type context) 42) (Llvm.param foo 1) builder);30 let loop = Llvm.append_block context "loop" foo in31 Llvm.position_at_end loop builder;32 ignore33 (Llvm.build_load (Llvm.i8_type context) (Llvm.param foo 2) "tmp1" builder);34 ignore (Llvm.build_br loop builder);35 let exit = Llvm.append_block context "exit" foo in36 Llvm.position_at_end exit builder;37 ignore (Llvm.build_ret_void builder);38 Llvm.position_at_end entry builder;39 ignore (Llvm.build_cond_br (Llvm.param foo 0) loop exit builder)40 41let target =42 Llvm_target.Target.by_triple (Llvm_target.Target.default_triple ())43 44let machine =45 Llvm_target.TargetMachine.create46 ~triple:(Llvm_target.Target.default_triple ()) target47 48let options = Llvm_passbuilder.create_passbuilder_options ()49 50(*===-- PassBuilder -------------------------------------------------------===*)51let () =52 Llvm_passbuilder.passbuilder_options_set_verify_each options true;53 Llvm_passbuilder.passbuilder_options_set_debug_logging options true;54 Llvm_passbuilder.passbuilder_options_set_loop_interleaving options true;55 Llvm_passbuilder.passbuilder_options_set_loop_vectorization options true;56 Llvm_passbuilder.passbuilder_options_set_slp_vectorization options true;57 Llvm_passbuilder.passbuilder_options_set_loop_unrolling options true;58 Llvm_passbuilder.passbuilder_options_set_forget_all_scev_in_loop_unroll59 options true;60 Llvm_passbuilder.passbuilder_options_set_licm_mssa_opt_cap options 2;61 Llvm_passbuilder.passbuilder_options_set_licm_mssa_no_acc_for_promotion_cap62 options 2;63 Llvm_passbuilder.passbuilder_options_set_call_graph_profile options true;64 Llvm_passbuilder.passbuilder_options_set_merge_functions options true;65 Llvm_passbuilder.passbuilder_options_set_inliner_threshold options 2;66 match Llvm_passbuilder.run_passes m "no-op-module" machine options with67 | Error e ->68 prerr_endline e;69 assert false70 | Ok () -> ()71 72let () =73 Llvm_passbuilder.dispose_passbuilder_options options;74 Llvm.dispose_module m75