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