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