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
4 * RUN: %ocamlopt -g -w +A -package llvm.passbuilder -package llvm.all_backends -linkpkg %t/passbuilder.ml -o %t/executable
9 let () = Llvm_all_backends.initialize
()
11 (*===-- Fixture -----------------------------------------------------------===*)
13 let context = Llvm.global_context
()
15 let m = Llvm.create_module
context "mymodule"
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
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;
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)
42 Llvm_target.Target.by_triple
(Llvm_target.Target.default_triple
())
45 Llvm_target.TargetMachine.create
46 ~triple
:(Llvm_target.Target.default_triple
()) target
48 let options = Llvm_passbuilder.create_passbuilder_options
()
50 (*===-- PassBuilder -------------------------------------------------------===*)
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
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
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
73 Llvm_passbuilder.dispose_passbuilder_options
options;