[Frontend] Remove unused includes (NFC) (#116927)
[llvm-project.git] / llvm / test / Bindings / OCaml / passbuilder.ml
blob180cc3a0240a145e8328a3ea64f3b9dc97d7ae86
1 (* RUN: rm -rf %t && mkdir -p %t && cp %s %t/passbuilder.ml
2 * RUN: %ocamlc -g -w +A -package llvm.passbuilder -package llvm.all_backends -linkpkg %t/passbuilder.ml -o %t/executable
3 * RUN: %t/executable
4 * RUN: %ocamlopt -g -w +A -package llvm.passbuilder -package llvm.all_backends -linkpkg %t/passbuilder.ml -o %t/executable
5 * RUN: %t/executable
6 * XFAIL: vg_leak
7 *)
9 let () = Llvm_all_backends.initialize ()
11 (*===-- Fixture -----------------------------------------------------------===*)
13 let context = Llvm.global_context ()
15 let m = Llvm.create_module context "mymodule"
17 let () =
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 |]
24 let foo = Llvm.define_function "foo" ty m in
25 let entry = Llvm.entry_block foo in
26 let builder = Llvm.builder_at_end context entry in
27 ignore
28 (Llvm.build_store
29 (Llvm.const_int (Llvm.i8_type context) 42) (Llvm.param foo 1) builder);
30 let loop = Llvm.append_block context "loop" foo in
31 Llvm.position_at_end loop builder;
32 ignore
33 (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 in
36 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)
41 let target =
42 Llvm_target.Target.by_triple (Llvm_target.Target.default_triple ())
44 let machine =
45 Llvm_target.TargetMachine.create
46 ~triple:(Llvm_target.Target.default_triple ()) target
48 let options = Llvm_passbuilder.create_passbuilder_options ()
50 (*===-- PassBuilder -------------------------------------------------------===*)
51 let () =
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_unroll
59 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_cap
62 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 with
67 | Error e ->
68 prerr_endline e;
69 assert false
70 | Ok () -> ()
72 let () =
73 Llvm_passbuilder.dispose_passbuilder_options options;
74 Llvm.dispose_module m