[OCaml] Llvm_scalar_opts: add missing transforms
[oota-llvm.git] / test / Bindings / Ocaml / scalar_opts.ml
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_scalar_opts.cmxa llvm_target.cmxa %t.builddir/scalar_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
13 open Llvm
14 open Llvm_scalar_opts
15 open Llvm_target
16
17 let context = global_context ()
18 let void_type = Llvm.void_type context
19
20 (* Tiny unit test framework - really just to help find which line is busted *)
21 let print_checkpoints = false
22
23 let suite name f =
24   if print_checkpoints then
25     prerr_endline (name ^ ":");
26   f ()
27
28
29 (*===-- Fixture -----------------------------------------------------------===*)
30
31 let filename = Sys.argv.(1)
32 let m = create_module context filename
33
34
35 (*===-- Transforms --------------------------------------------------------===*)
36
37 let test_transforms () =
38   let (++) x f = ignore (f x); x in
39
40   let fty = function_type void_type [| |] in
41   let fn = define_function "fn" fty m in
42   ignore (build_ret_void (builder_at_end context (entry_block fn)));
43   
44   let td = DataLayout.create (target_triple m) in
45   
46   ignore (PassManager.create_function m
47            ++ DataLayout.add td
48            ++ add_verifier
49            ++ add_constant_propagation
50            ++ add_sccp
51            ++ add_dead_store_elimination
52            ++ add_aggressive_dce
53            ++ add_scalar_repl_aggregation
54            ++ add_scalar_repl_aggregation_ssa
55            ++ add_scalar_repl_aggregation_with_threshold 4
56            ++ add_ind_var_simplification
57            ++ add_instruction_combination
58            ++ add_licm
59            ++ add_loop_unswitch
60            ++ add_loop_unroll
61            ++ add_loop_rotation
62            ++ add_memory_to_register_promotion
63            ++ add_memory_to_register_demotion
64            ++ add_reassociation
65            ++ add_jump_threading
66            ++ add_cfg_simplification
67            ++ add_tail_call_elimination
68            ++ add_gvn
69            ++ add_memcpy_opt
70            ++ add_loop_deletion
71            ++ add_loop_idiom
72            ++ add_lib_call_simplification
73            ++ add_correlated_value_propagation
74            ++ add_early_cse
75            ++ add_lower_expect_intrinsic
76            ++ add_type_based_alias_analysis
77            ++ add_basic_alias_analysis
78            ++ add_partially_inline_lib_calls
79            ++ add_verifier
80            ++ PassManager.initialize
81            ++ PassManager.run_function fn
82            ++ PassManager.finalize
83            ++ PassManager.dispose);
84   
85   DataLayout.dispose td
86
87
88 (*===-- Driver ------------------------------------------------------------===*)
89
90 let _ =
91   suite "transforms" test_transforms;
92   dispose_module m