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