llvm.org GIT mirror llvm / 624c5ed
ocaml bindings: add llvm_ipo based on IPO.h git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141284 91177308-0d34-0410-b5e6-96231b3b80d8 Torok Edwin 8 years ago
6 changed file(s) with 328 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
77 ##===----------------------------------------------------------------------===##
88
99 LEVEL := ../../..
10 DIRS = scalar
10 DIRS = scalar ipo
1111
1212 ocamldoc:
1313 $(Verb) for i in $(DIRS) ; do \
0 ##===- bindings/ocaml/transforms/scalar/Makefile -----------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 #
9 # This is the makefile for the Objective Caml Llvm_scalar_opts interface.
10 #
11 ##===----------------------------------------------------------------------===##
12
13 LEVEL := ../../../..
14 LIBRARYNAME := llvm_ipo
15 DONT_BUILD_RELINKED := 1
16 UsedComponents := ipo
17 UsedOcamlInterfaces := llvm
18
19 include ../../Makefile.ocaml
0 /*===-- ipo_ocaml.c - LLVM Ocaml Glue -------------------*- C++ -*-===*\
1 |* *|
2 |* The LLVM Compiler Infrastructure *|
3 |* *|
4 |* This file is distributed under the University of Illinois Open Source *|
5 |* License. See LICENSE.TXT for details. *|
6 |* *|
7 |*===----------------------------------------------------------------------===*|
8 |* *|
9 |* This file glues LLVM's ocaml interface to its C interface. These functions *|
10 |* are by and large transparent wrappers to the corresponding C functions. *|
11 |* *|
12 |* Note that these functions intentionally take liberties with the CAMLparamX *|
13 |* macros, since most of the parameters are not GC heap objects. *|
14 |* *|
15 \*===----------------------------------------------------------------------===*/
16
17 #include "llvm-c/Transforms/IPO.h"
18 #include "caml/mlvalues.h"
19 #include "caml/misc.h"
20
21 /* [`Module] Llvm.PassManager.t -> unit */
22 CAMLprim value llvm_add_argument_promotion(LLVMPassManagerRef PM) {
23 LLVMAddArgumentPromotionPass(PM);
24 return Val_unit;
25 }
26
27 /* [`Module] Llvm.PassManager.t -> unit */
28 CAMLprim value llvm_add_constant_merge(LLVMPassManagerRef PM) {
29 LLVMAddConstantMergePass(PM);
30 return Val_unit;
31 }
32
33 /* [`Module] Llvm.PassManager.t -> unit */
34 CAMLprim value llvm_add_dead_arg_elimination(LLVMPassManagerRef PM) {
35 LLVMAddDeadArgEliminationPass(PM);
36 return Val_unit;
37 }
38
39 /* [`Module] Llvm.PassManager.t -> unit */
40 CAMLprim value llvm_add_function_attrs(LLVMPassManagerRef PM) {
41 LLVMAddFunctionAttrsPass(PM);
42 return Val_unit;
43 }
44
45 /* [`Module] Llvm.PassManager.t -> unit */
46 CAMLprim value llvm_add_function_inlining(LLVMPassManagerRef PM) {
47 LLVMAddFunctionInliningPass(PM);
48 return Val_unit;
49 }
50
51 /* [`Module] Llvm.PassManager.t -> unit */
52 CAMLprim value llvm_add_always_inliner_pass(LLVMPassManagerRef PM) {
53 LLVMAddAlwaysInlinerPass(PM);
54 return Val_unit;
55 }
56
57 /* [`Module] Llvm.PassManager.t -> unit */
58 CAMLprim value llvm_add_global_dce(LLVMPassManagerRef PM) {
59 LLVMAddGlobalDCEPass(PM);
60 return Val_unit;
61 }
62
63 /* [`Module] Llvm.PassManager.t -> unit */
64 CAMLprim value llvm_add_global_optimizer(LLVMPassManagerRef PM) {
65 LLVMAddGlobalOptimizerPass(PM);
66 return Val_unit;
67 }
68
69 /* [`Module] Llvm.PassManager.t -> unit */
70 CAMLprim value llvm_add_ipc_propagation(LLVMPassManagerRef PM) {
71 LLVMAddIPConstantPropagationPass(PM);
72 return Val_unit;
73 }
74
75 /* [`Module] Llvm.PassManager.t -> unit */
76 CAMLprim value llvm_add_prune_eh(LLVMPassManagerRef PM) {
77 LLVMAddPruneEHPass(PM);
78 return Val_unit;
79 }
80
81 /* [`Module] Llvm.PassManager.t -> unit */
82 CAMLprim value llvm_add_ipsccp(LLVMPassManagerRef PM) {
83 LLVMAddIPSCCPPass(PM);
84 return Val_unit;
85 }
86
87 /* [`Module] Llvm.PassManager.t -> bool -> unit */
88 CAMLprim value llvm_add_internalize(LLVMPassManagerRef PM, value AllButMain) {
89 LLVMAddInternalizePass(PM, Bool_val(AllButMain));
90 return Val_unit;
91 }
92
93 /* [`Module] Llvm.PassManager.t -> unit */
94 CAMLprim value llvm_add_strip_dead_prototypes(LLVMPassManagerRef PM) {
95 LLVMAddStripDeadPrototypesPass(PM);
96 return Val_unit;
97 }
98
99 /* [`Module] Llvm.PassManager.t -> unit */
100 CAMLprim value llvm_add_strip_symbols(LLVMPassManagerRef PM) {
101 LLVMAddStripSymbolsPass(PM);
102 return Val_unit;
103 }
0 (*===-- llvm_ipo.mli - LLVM Ocaml Interface ------------*- OCaml -*-===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file is distributed under the University of Illinois Open Source
5 * License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===*)
8
9 (** IPO Transforms.
10
11 This interface provides an ocaml API for LLVM interprocedural optimizations, the
12 classes in the [LLVMIPO] library. *)
13
14 (** See llvm::createAddArgumentPromotionPass *)
15 external add_argument_promotion : [ | `Module ] Llvm.PassManager.t -> unit =
16 "llvm_add_argument_promotion"
17
18 (** See llvm::createConstantMergePass function. *)
19 external add_constant_merge : [ | `Module ] Llvm.PassManager.t -> unit =
20 "llvm_add_constant_merge"
21
22 (** See llvm::createDeadArgEliminationPass function. *)
23 external add_dead_arg_elimination :
24 [ | `Module ] Llvm.PassManager.t -> unit = "llvm_add_dead_arg_elimination"
25
26 (** See llvm::createFunctionAttrsPass function. *)
27 external add_function_attrs : [ | `Module ] Llvm.PassManager.t -> unit =
28 "llvm_add_function_attrs"
29
30 (** See llvm::createFunctionInliningPass function. *)
31 external add_function_inlining : [ | `Module ] Llvm.PassManager.t -> unit =
32 "llvm_add_function_inlining"
33
34 (** See llvm::createGlobalDCEPass function. *)
35 external add_global_dce : [ | `Module ] Llvm.PassManager.t -> unit =
36 "llvm_add_global_dce"
37
38 (** See llvm::createGlobalOptimizerPass function. *)
39 external add_global_optimizer : [ | `Module ] Llvm.PassManager.t -> unit =
40 "llvm_add_global_optimizer"
41
42 (** See llvm::createIPConstantPropagationPass function. *)
43 external add_ipc_propagation : [ | `Module ] Llvm.PassManager.t -> unit =
44 "llvm_add_ipc_propagation"
45
46 (** See llvm::createPruneEHPass function. *)
47 external add_prune_eh : [ | `Module ] Llvm.PassManager.t -> unit =
48 "llvm_add_prune_eh"
49
50 (** See llvm::createIPSCCPPass function. *)
51 external add_ipsccp : [ | `Module ] Llvm.PassManager.t -> unit =
52 "llvm_add_ipsccp"
53
54 (** See llvm::createInternalizePass function. *)
55 external add_internalize : [ | `Module ] Llvm.PassManager.t -> bool -> unit =
56 "llvm_add_internalize"
57
58 (** See llvm::createStripDeadPrototypesPass function. *)
59 external add_strip_dead_prototypes :
60 [ | `Module ] Llvm.PassManager.t -> unit = "llvm_add_strip_dead_prototypes"
61
62 (** See llvm::createStripSymbolsPass function. *)
63 external add_strip_symbols : [ | `Module ] Llvm.PassManager.t -> unit =
64 "llvm_add_strip_symbols"
0 (*===-- llvm_ipo.mli - LLVM Ocaml Interface ------------*- OCaml -*-===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file is distributed under the University of Illinois Open Source
5 * License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===*)
8
9 (** IPO Transforms.
10
11 This interface provides an ocaml API for LLVM interprocedural optimizations, the
12 classes in the [LLVMIPO] library. *)
13
14 (** See llvm::createAddArgumentPromotionPass *)
15 external add_argument_promotion : [ | `Module ] Llvm.PassManager.t -> unit =
16
17 "llvm_add_argument_promotion"
18 (** See llvm::createConstantMergePass function. *)
19 external add_constant_merge : [ | `Module ] Llvm.PassManager.t -> unit =
20 "llvm_add_constant_merge"
21
22 (** See llvm::createDeadArgEliminationPass function. *)
23 external add_dead_arg_elimination :
24 [ | `Module ] Llvm.PassManager.t -> unit = "llvm_add_dead_arg_elimination"
25
26 (** See llvm::createFunctionAttrsPass function. *)
27 external add_function_attrs : [ | `Module ] Llvm.PassManager.t -> unit =
28 "llvm_add_function_attrs"
29
30 (** See llvm::createFunctionInliningPass function. *)
31 external add_function_inlining : [ | `Module ] Llvm.PassManager.t -> unit =
32 "llvm_add_function_inlining"
33
34 (** See llvm::createGlobalDCEPass function. *)
35 external add_global_dce : [ | `Module ] Llvm.PassManager.t -> unit =
36 "llvm_add_global_dce"
37
38 (** See llvm::createGlobalOptimizerPass function. *)
39 external add_global_optimizer : [ | `Module ] Llvm.PassManager.t -> unit =
40 "llvm_add_global_optimizer"
41
42 (** See llvm::createIPConstantPropagationPass function. *)
43 external add_ipc_propagation : [ | `Module ] Llvm.PassManager.t -> unit =
44 "llvm_add_ipc_propagation"
45
46 (** See llvm::createPruneEHPass function. *)
47 external add_prune_eh : [ | `Module ] Llvm.PassManager.t -> unit =
48 "llvm_add_prune_eh"
49
50 (** See llvm::createIPSCCPPass function. *)
51 external add_ipsccp : [ | `Module ] Llvm.PassManager.t -> unit =
52 "llvm_add_ipsccp"
53
54 (** See llvm::createInternalizePass function. *)
55 external add_internalize : [ | `Module ] Llvm.PassManager.t -> bool -> unit =
56 "llvm_add_internalize"
57
58 (** See llvm::createStripDeadPrototypesPass function. *)
59 external add_strip_dead_prototypes :
60 [ | `Module ] Llvm.PassManager.t -> unit = "llvm_add_strip_dead_prototypes"
61
62 (** See llvm::createStripSymbolsPass function. *)
63 external add_strip_symbols : [ | `Module ] Llvm.PassManager.t -> unit =
64 "llvm_add_strip_symbols"
0 (* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_ipo.cmxa llvm_target.cmxa %s -o %t
1 * RUN: %t %t.bc
2 * XFAIL: vg_leak
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_ipo
11 open Llvm_target
12
13 let context = global_context ()
14 let void_type = Llvm.void_type context
15 let i8_type = Llvm.i8_type context
16
17 (* Tiny unit test framework - really just to help find which line is busted *)
18 let print_checkpoints = false
19
20 let suite name f =
21 if print_checkpoints then
22 prerr_endline (name ^ ":");
23 f ()
24
25
26 (*===-- Fixture -----------------------------------------------------------===*)
27
28 let filename = Sys.argv.(1)
29 let m = create_module context filename
30
31
32 (*===-- Transforms --------------------------------------------------------===*)
33
34 let test_transforms () =
35 let (++) x f = ignore (f x); x in
36
37 let fty = function_type i8_type [| |] in
38 let fn = define_function "fn" fty m in
39 let fn2 = define_function "fn2" fty m in begin
40 ignore (build_ret (const_int i8_type 4) (builder_at_end context (entry_block fn)));
41 let b = builder_at_end context (entry_block fn2) in
42 ignore (build_ret (build_call fn [| |] "" b) b);
43 end;
44
45 let td = TargetData.create (target_triple m) in
46
47 ignore (PassManager.create ()
48 ++ TargetData.add td
49 ++ add_argument_promotion
50 ++ add_constant_merge
51 ++ add_dead_arg_elimination
52 ++ add_function_attrs
53 ++ add_function_inlining
54 ++ add_global_dce
55 ++ add_global_optimizer
56 ++ add_ipc_propagation
57 ++ add_prune_eh
58 ++ add_ipsccp
59 ++ add_internalize
60 ++ add_strip_dead_prototypes
61 ++ add_strip_symbols
62 ++ PassManager.run_module m
63 ++ PassManager.dispose);
64
65 TargetData.dispose td
66
67
68 (*===-- Driver ------------------------------------------------------------===*)
69
70 let _ =
71 suite "transforms" test_transforms;
72 dispose_module m