source: parabix-LLVM/llvm_git/bindings/ocaml/transforms/passmgr_builder/passmgr_builder_ocaml.c

Last change on this file was 4078, checked in by linmengl, 5 years ago

checkin llvm-meng source

File size: 4.4 KB
Line 
1/*===-- passmgr_builder_ocaml.c - LLVM OCaml Glue ---------------*- C++ -*-===*\
2|*                                                                            *|
3|*                     The LLVM Compiler Infrastructure                       *|
4|*                                                                            *|
5|* This file is distributed under the University of Illinois Open Source      *|
6|* License. See LICENSE.TXT for details.                                      *|
7|*                                                                            *|
8|*===----------------------------------------------------------------------===*|
9|*                                                                            *|
10|* This file glues LLVM's OCaml interface to its C interface. These functions *|
11|* are by and large transparent wrappers to the corresponding C functions.    *|
12|*                                                                            *|
13|* Note that these functions intentionally take liberties with the CAMLparamX *|
14|* macros, since most of the parameters are not GC heap objects.              *|
15|*                                                                            *|
16\*===----------------------------------------------------------------------===*/
17
18#include "llvm-c/Transforms/PassManagerBuilder.h"
19#include "caml/mlvalues.h"
20#include "caml/custom.h"
21#include "caml/misc.h"
22
23#define PMBuilder_val(v)  (*(LLVMPassManagerBuilderRef *)(Data_custom_val(v)))
24
25static void llvm_finalize_pmbuilder(value PMB) {
26  LLVMPassManagerBuilderDispose(PMBuilder_val(PMB));
27}
28
29static struct custom_operations pmbuilder_ops = {
30  (char *) "LLVMPassManagerBuilder",
31  llvm_finalize_pmbuilder,
32  custom_compare_default,
33  custom_hash_default,
34  custom_serialize_default,
35  custom_deserialize_default
36#ifdef custom_compare_ext_default
37  , custom_compare_ext_default
38#endif
39};
40
41static value alloc_pmbuilder(LLVMPassManagerBuilderRef Ref) {
42  value Val = alloc_custom(&pmbuilder_ops,
43                           sizeof(LLVMPassManagerBuilderRef), 0, 1);
44  PMBuilder_val(Val) = Ref;
45  return Val;
46}
47
48/* t -> unit */
49CAMLprim value llvm_pmbuilder_create(value Unit) {
50  return alloc_pmbuilder(LLVMPassManagerBuilderCreate());
51}
52
53/* int -> t -> unit */
54CAMLprim value llvm_pmbuilder_set_opt_level(value OptLevel, value PMB) {
55  LLVMPassManagerBuilderSetOptLevel(PMBuilder_val(PMB), Int_val(OptLevel));
56  return Val_unit;
57}
58
59/* int -> t -> unit */
60CAMLprim value llvm_pmbuilder_set_size_level(value SizeLevel, value PMB) {
61  LLVMPassManagerBuilderSetSizeLevel(PMBuilder_val(PMB), Int_val(SizeLevel));
62  return Val_unit;
63}
64
65/* int -> t -> unit */
66CAMLprim value llvm_pmbuilder_use_inliner_with_threshold(
67                      value Threshold, value PMB) {
68  LLVMPassManagerBuilderSetOptLevel(PMBuilder_val(PMB), Int_val(Threshold));
69  return Val_unit;
70}
71
72/* bool -> t -> unit */
73CAMLprim value llvm_pmbuilder_set_disable_unit_at_a_time(
74                      value DisableUnitAtATime, value PMB) {
75  LLVMPassManagerBuilderSetDisableUnitAtATime(
76                      PMBuilder_val(PMB), Bool_val(DisableUnitAtATime));
77  return Val_unit;
78}
79
80/* bool -> t -> unit */
81CAMLprim value llvm_pmbuilder_set_disable_unroll_loops(
82                      value DisableUnroll, value PMB) {
83  LLVMPassManagerBuilderSetDisableUnrollLoops(
84                      PMBuilder_val(PMB), Bool_val(DisableUnroll));
85  return Val_unit;
86}
87
88/* [ `Function ] Llvm.PassManager.t -> t -> unit */
89CAMLprim value llvm_pmbuilder_populate_function_pass_manager(
90                      LLVMPassManagerRef PM, value PMB) {
91  LLVMPassManagerBuilderPopulateFunctionPassManager(
92                      PMBuilder_val(PMB), PM);
93  return Val_unit;
94}
95
96/* [ `Module ] Llvm.PassManager.t -> t -> unit */
97CAMLprim value llvm_pmbuilder_populate_module_pass_manager(
98                      LLVMPassManagerRef PM, value PMB) {
99  LLVMPassManagerBuilderPopulateModulePassManager(
100                      PMBuilder_val(PMB), PM);
101  return Val_unit;
102}
103
104/* [ `Module ] Llvm.PassManager.t ->
105   internalize:bool -> run_inliner:bool -> t -> unit */
106CAMLprim value llvm_pmbuilder_populate_lto_pass_manager(
107                      LLVMPassManagerRef PM, value Internalize, value RunInliner,
108                      value PMB) {
109  LLVMPassManagerBuilderPopulateLTOPassManager(
110                      PMBuilder_val(PMB), PM,
111                      Bool_val(Internalize), Bool_val(RunInliner));
112  return Val_unit;
113}
Note: See TracBrowser for help on using the repository browser.