Fix the running of ocaml tests.
[oota-llvm.git] / test / Bindings / Ocaml / scalar_opts.ml
1 (* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_scalar_opts.cmxa llvm_target.cmxa %s -o %t
2  * RUN: %t %t.bc
3  *)
4
5 (* Note: It takes several seconds for ocamlopt to link an executable with
6          libLLVMCore.a, so it's better to write a big test than a bunch of
7          little ones. *)
8
9 open Llvm
10 open Llvm_scalar_opts
11 open Llvm_target
12
13 let context = global_context ()
14 let void_type = Llvm.void_type context
15
16 (* Tiny unit test framework - really just to help find which line is busted *)
17 let print_checkpoints = false
18
19 let suite name f =
20   if print_checkpoints then
21     prerr_endline (name ^ ":");
22   f ()
23
24
25 (*===-- Fixture -----------------------------------------------------------===*)
26
27 let filename = Sys.argv.(1)
28 let m = create_module context filename
29
30
31 (*===-- Transforms --------------------------------------------------------===*)
32
33 let test_transforms () =
34   let (++) x f = ignore (f x); x in
35
36   let fty = function_type void_type [| |] in
37   let fn = define_function "fn" fty m in
38   ignore (build_ret_void (builder_at_end context (entry_block fn)));
39   
40   let td = TargetData.create (target_triple m) in
41   
42   ignore (PassManager.create_function m
43            ++ TargetData.add td
44            ++ add_constant_propagation
45                                          ++ add_sccp
46            ++ add_dead_store_elimination
47            ++ add_aggressive_dce
48            ++ add_scalar_repl_aggregation
49            ++ add_ind_var_simplification
50            ++ add_instruction_combination
51            ++ add_licm
52            ++ add_loop_unswitch
53            ++ add_loop_unroll
54            ++ add_loop_rotation
55            ++ add_loop_index_split
56            ++ add_memory_to_register_promotion
57            ++ add_memory_to_register_demotion
58            ++ add_reassociation
59            ++ add_jump_threading
60            ++ add_cfg_simplification
61            ++ add_tail_call_elimination
62            ++ add_gvn
63            ++ add_memcpy_opt
64            ++ add_loop_deletion
65            ++ add_lib_call_simplification
66            ++ PassManager.initialize
67            ++ PassManager.run_function fn
68            ++ PassManager.finalize
69            ++ PassManager.dispose);
70   
71   TargetData.dispose td
72
73
74 (*===-- Driver ------------------------------------------------------------===*)
75
76 let _ =
77   suite "transforms" test_transforms;
78   dispose_module m