26037f2fd938d2fda5418319a909031d91f3e6ec
[oota-llvm.git] / test / Bindings / Ocaml / ipo_opts.ml
1 (* RUN: cp %s %T/ipo_opts.ml
2  * RUN: %ocamlcomp -warn-error A -package llvm.ipo -linkpkg %T/ipo_opts.ml -o %t
3  * RUN: %t %t.bc
4  * XFAIL: vg_leak
5  *)
6
7 (* Note: It takes several seconds for ocamlopt to link an executable with
8          libLLVMCore.a, so it's better to write a big test than a bunch of
9          little ones. *)
10
11 open Llvm
12 open Llvm_ipo
13 open Llvm_target
14
15 let context = global_context ()
16 let void_type = Llvm.void_type context
17 let i8_type = Llvm.i8_type context
18
19 (* Tiny unit test framework - really just to help find which line is busted *)
20 let print_checkpoints = false
21
22 let suite name f =
23   if print_checkpoints then
24     prerr_endline (name ^ ":");
25   f ()
26
27
28 (*===-- Fixture -----------------------------------------------------------===*)
29
30 let filename = Sys.argv.(1)
31 let m = create_module context filename
32
33
34 (*===-- Transforms --------------------------------------------------------===*)
35
36 let test_transforms () =
37   let (++) x f = f x; x in
38
39   let fty = function_type i8_type [| |] in
40   let fn = define_function "fn" fty m in
41   let fn2 = define_function "fn2" fty m in begin
42       ignore (build_ret (const_int i8_type 4) (builder_at_end context (entry_block fn)));
43       let b = builder_at_end context  (entry_block fn2) in
44       ignore (build_ret (build_call fn [| |] "" b) b);
45   end;
46
47   ignore (PassManager.create ()
48            ++ add_argument_promotion
49            ++ add_constant_merge
50            ++ add_dead_arg_elimination
51            ++ add_function_attrs
52            ++ add_function_inlining
53            ++ add_always_inliner
54            ++ add_global_dce
55            ++ add_global_optimizer
56            ++ add_ipc_propagation
57            ++ add_prune_eh
58            ++ add_ipsccp
59            ++ add_internalize ~all_but_main:true
60            ++ add_strip_dead_prototypes
61            ++ add_strip_symbols
62            ++ PassManager.run_module m
63            ++ PassManager.dispose)
64
65
66 (*===-- Driver ------------------------------------------------------------===*)
67
68 let _ =
69   suite "transforms" test_transforms;
70   dispose_module m