Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Differential D136400 Diff 496489 llvm/bindings/ocaml/transforms/passmgr_builder/passmgr_builder_ocaml.c
Changeset View
Changeset View
Standalone View
Standalone View
llvm/bindings/ocaml/transforms/passmgr_builder/passmgr_builder_ocaml.c
/*===-- passmgr_builder_ocaml.c - LLVM OCaml Glue ---------------*- C++ -*-===*\ | /*===-- passmgr_builder_ocaml.c - LLVM OCaml Glue ---------------*- C++ -*-===*\ | ||||
|* *| | |* *| | ||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| | ||||
|* Exceptions. *| | |* Exceptions. *| | ||||
|* See https://llvm.org/LICENSE.txt for license information. *| | |* See https://llvm.org/LICENSE.txt for license information. *| | ||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| | ||||
|* *| | |* *| | ||||
|*===----------------------------------------------------------------------===*| | |*===----------------------------------------------------------------------===*| | ||||
|* *| | |* *| | ||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *| | |* This file glues LLVM's OCaml interface to its C interface. These functions *| | ||||
|* are by and large transparent wrappers to the corresponding C functions. *| | |* are by and large transparent wrappers to the corresponding C functions. *| | ||||
|* *| | |* *| | ||||
|* Note that these functions intentionally take liberties with the CAMLparamX *| | |||||
|* macros, since most of the parameters are not GC heap objects. *| | |||||
|* *| | |||||
\*===----------------------------------------------------------------------===*/ | \*===----------------------------------------------------------------------===*/ | ||||
#include "llvm-c/Transforms/PassManagerBuilder.h" | |||||
#include "caml/mlvalues.h" | |||||
#include "caml/custom.h" | #include "caml/custom.h" | ||||
#include "caml/memory.h" | |||||
#include "caml/misc.h" | #include "caml/misc.h" | ||||
#include "caml/mlvalues.h" | |||||
#include "llvm_ocaml.h" | |||||
#include "llvm-c/Transforms/PassManagerBuilder.h" | |||||
#define PMBuilder_val(v) (*(LLVMPassManagerBuilderRef *)(Data_custom_val(v))) | #define PMBuilder_val(v) (*(LLVMPassManagerBuilderRef *)(Data_custom_val(v))) | ||||
static void llvm_finalize_pmbuilder(value PMB) { | static void llvm_finalize_pmbuilder(value PMB) { | ||||
LLVMPassManagerBuilderDispose(PMBuilder_val(PMB)); | LLVMPassManagerBuilderDispose(PMBuilder_val(PMB)); | ||||
} | } | ||||
static struct custom_operations pmbuilder_ops = { | static struct custom_operations pmbuilder_ops = { | ||||
(char *)"Llvm_passmgr_builder.t", llvm_finalize_pmbuilder, | (char *)"Llvm_passmgr_builder.t", llvm_finalize_pmbuilder, | ||||
custom_compare_default, custom_hash_default, | custom_compare_default, custom_hash_default, | ||||
custom_serialize_default, custom_deserialize_default, | custom_serialize_default, custom_deserialize_default, | ||||
custom_compare_ext_default}; | custom_compare_ext_default}; | ||||
static value alloc_pmbuilder(LLVMPassManagerBuilderRef Ref) { | static value alloc_pmbuilder(LLVMPassManagerBuilderRef Ref) { | ||||
value Val = | value Val = caml_alloc_custom(&pmbuilder_ops, | ||||
alloc_custom(&pmbuilder_ops, sizeof(LLVMPassManagerBuilderRef), 0, 1); | sizeof(LLVMPassManagerBuilderRef), 0, 1); | ||||
PMBuilder_val(Val) = Ref; | PMBuilder_val(Val) = Ref; | ||||
return Val; | return Val; | ||||
} | } | ||||
/* t -> unit */ | /* t -> unit */ | ||||
value llvm_pmbuilder_create(value Unit) { | value llvm_pmbuilder_create(value Unit) { | ||||
return alloc_pmbuilder(LLVMPassManagerBuilderCreate()); | CAMLparam1(Unit); | ||||
CAMLreturn(alloc_pmbuilder(LLVMPassManagerBuilderCreate())); | |||||
} | } | ||||
/* int -> t -> unit */ | /* int -> t -> unit */ | ||||
value llvm_pmbuilder_set_opt_level(value OptLevel, value PMB) { | value llvm_pmbuilder_set_opt_level(value OptLevel, value PMB) { | ||||
CAMLparam2(OptLevel, PMB); | |||||
LLVMPassManagerBuilderSetOptLevel(PMBuilder_val(PMB), Int_val(OptLevel)); | LLVMPassManagerBuilderSetOptLevel(PMBuilder_val(PMB), Int_val(OptLevel)); | ||||
return Val_unit; | CAMLreturn(Val_unit); | ||||
} | } | ||||
/* int -> t -> unit */ | /* int -> t -> unit */ | ||||
value llvm_pmbuilder_set_size_level(value SizeLevel, value PMB) { | value llvm_pmbuilder_set_size_level(value SizeLevel, value PMB) { | ||||
CAMLparam2(SizeLevel, PMB); | |||||
LLVMPassManagerBuilderSetSizeLevel(PMBuilder_val(PMB), Int_val(SizeLevel)); | LLVMPassManagerBuilderSetSizeLevel(PMBuilder_val(PMB), Int_val(SizeLevel)); | ||||
return Val_unit; | CAMLreturn(Val_unit); | ||||
} | } | ||||
/* int -> t -> unit */ | /* int -> t -> unit */ | ||||
value llvm_pmbuilder_use_inliner_with_threshold(value Threshold, value PMB) { | value llvm_pmbuilder_use_inliner_with_threshold(value Threshold, value PMB) { | ||||
CAMLparam2(Threshold, PMB); | |||||
LLVMPassManagerBuilderSetOptLevel(PMBuilder_val(PMB), Int_val(Threshold)); | LLVMPassManagerBuilderSetOptLevel(PMBuilder_val(PMB), Int_val(Threshold)); | ||||
return Val_unit; | CAMLreturn(Val_unit); | ||||
} | } | ||||
/* bool -> t -> unit */ | /* bool -> t -> unit */ | ||||
value llvm_pmbuilder_set_disable_unit_at_a_time(value DisableUnitAtATime, | value llvm_pmbuilder_set_disable_unit_at_a_time(value DisableUnitAtATime, | ||||
value PMB) { | value PMB) { | ||||
CAMLparam2(DisableUnitAtATime, PMB); | |||||
LLVMPassManagerBuilderSetDisableUnitAtATime(PMBuilder_val(PMB), | LLVMPassManagerBuilderSetDisableUnitAtATime(PMBuilder_val(PMB), | ||||
Bool_val(DisableUnitAtATime)); | Bool_val(DisableUnitAtATime)); | ||||
return Val_unit; | CAMLreturn(Val_unit); | ||||
} | } | ||||
/* bool -> t -> unit */ | /* bool -> t -> unit */ | ||||
value llvm_pmbuilder_set_disable_unroll_loops(value DisableUnroll, value PMB) { | value llvm_pmbuilder_set_disable_unroll_loops(value DisableUnroll, value PMB) { | ||||
CAMLparam2(DisableUnroll, PMB); | |||||
LLVMPassManagerBuilderSetDisableUnrollLoops(PMBuilder_val(PMB), | LLVMPassManagerBuilderSetDisableUnrollLoops(PMBuilder_val(PMB), | ||||
Bool_val(DisableUnroll)); | Bool_val(DisableUnroll)); | ||||
return Val_unit; | CAMLreturn(Val_unit); | ||||
} | } | ||||
/* [ `Function ] Llvm.PassManager.t -> t -> unit */ | /* [ `Function ] Llvm.PassManager.t -> t -> unit */ | ||||
value llvm_pmbuilder_populate_function_pass_manager(LLVMPassManagerRef PM, | value llvm_pmbuilder_populate_function_pass_manager(value PM, value PMB) { | ||||
value PMB) { | CAMLparam2(PM, PMB); | ||||
LLVMPassManagerBuilderPopulateFunctionPassManager(PMBuilder_val(PMB), PM); | LLVMPassManagerBuilderPopulateFunctionPassManager(PMBuilder_val(PMB), | ||||
return Val_unit; | PassManager_val(PM)); | ||||
CAMLreturn(Val_unit); | |||||
} | } | ||||
/* [ `Module ] Llvm.PassManager.t -> t -> unit */ | /* [ `Module ] Llvm.PassManager.t -> t -> unit */ | ||||
value llvm_pmbuilder_populate_module_pass_manager(LLVMPassManagerRef PM, | value llvm_pmbuilder_populate_module_pass_manager(value PM, value PMB) { | ||||
value PMB) { | CAMLparam2(PM, PMB); | ||||
LLVMPassManagerBuilderPopulateModulePassManager(PMBuilder_val(PMB), PM); | LLVMPassManagerBuilderPopulateModulePassManager(PMBuilder_val(PMB), | ||||
return Val_unit; | PassManager_val(PM)); | ||||
CAMLreturn(Val_unit); | |||||
} | } |