1 /*===-- scalar_opts_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/Scalar.h" 19 #include "caml/mlvalues.h" 20 #include "caml/misc.h" 21 22 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_aggressive_dce(LLVMPassManagerRef PM)23CAMLprim value llvm_add_aggressive_dce(LLVMPassManagerRef PM) { 24 LLVMAddAggressiveDCEPass(PM); 25 return Val_unit; 26 } 27 28 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_alignment_from_assumptions(LLVMPassManagerRef PM)29CAMLprim value llvm_add_alignment_from_assumptions(LLVMPassManagerRef PM) { 30 LLVMAddAlignmentFromAssumptionsPass(PM); 31 return Val_unit; 32 } 33 34 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_cfg_simplification(LLVMPassManagerRef PM)35CAMLprim value llvm_add_cfg_simplification(LLVMPassManagerRef PM) { 36 LLVMAddCFGSimplificationPass(PM); 37 return Val_unit; 38 } 39 40 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_dead_store_elimination(LLVMPassManagerRef PM)41CAMLprim value llvm_add_dead_store_elimination(LLVMPassManagerRef PM) { 42 LLVMAddDeadStoreEliminationPass(PM); 43 return Val_unit; 44 } 45 46 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_scalarizer(LLVMPassManagerRef PM)47CAMLprim value llvm_add_scalarizer(LLVMPassManagerRef PM) { 48 LLVMAddScalarizerPass(PM); 49 return Val_unit; 50 } 51 52 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_merged_load_store_motion(LLVMPassManagerRef PM)53CAMLprim value llvm_add_merged_load_store_motion(LLVMPassManagerRef PM) { 54 LLVMAddMergedLoadStoreMotionPass(PM); 55 return Val_unit; 56 } 57 58 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_gvn(LLVMPassManagerRef PM)59CAMLprim value llvm_add_gvn(LLVMPassManagerRef PM) { 60 LLVMAddGVNPass(PM); 61 return Val_unit; 62 } 63 64 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_ind_var_simplify(LLVMPassManagerRef PM)65CAMLprim value llvm_add_ind_var_simplify(LLVMPassManagerRef PM) { 66 LLVMAddIndVarSimplifyPass(PM); 67 return Val_unit; 68 } 69 70 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_instruction_combining(LLVMPassManagerRef PM)71CAMLprim value llvm_add_instruction_combining(LLVMPassManagerRef PM) { 72 LLVMAddInstructionCombiningPass(PM); 73 return Val_unit; 74 } 75 76 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_jump_threading(LLVMPassManagerRef PM)77CAMLprim value llvm_add_jump_threading(LLVMPassManagerRef PM) { 78 LLVMAddJumpThreadingPass(PM); 79 return Val_unit; 80 } 81 82 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_licm(LLVMPassManagerRef PM)83CAMLprim value llvm_add_licm(LLVMPassManagerRef PM) { 84 LLVMAddLICMPass(PM); 85 return Val_unit; 86 } 87 88 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_loop_deletion(LLVMPassManagerRef PM)89CAMLprim value llvm_add_loop_deletion(LLVMPassManagerRef PM) { 90 LLVMAddLoopDeletionPass(PM); 91 return Val_unit; 92 } 93 94 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_loop_idiom(LLVMPassManagerRef PM)95CAMLprim value llvm_add_loop_idiom(LLVMPassManagerRef PM) { 96 LLVMAddLoopIdiomPass(PM); 97 return Val_unit; 98 } 99 100 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_loop_rotate(LLVMPassManagerRef PM)101CAMLprim value llvm_add_loop_rotate(LLVMPassManagerRef PM) { 102 LLVMAddLoopRotatePass(PM); 103 return Val_unit; 104 } 105 106 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_loop_reroll(LLVMPassManagerRef PM)107CAMLprim value llvm_add_loop_reroll(LLVMPassManagerRef PM) { 108 LLVMAddLoopRerollPass(PM); 109 return Val_unit; 110 } 111 112 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_loop_unroll(LLVMPassManagerRef PM)113CAMLprim value llvm_add_loop_unroll(LLVMPassManagerRef PM) { 114 LLVMAddLoopUnrollPass(PM); 115 return Val_unit; 116 } 117 118 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_loop_unswitch(LLVMPassManagerRef PM)119CAMLprim value llvm_add_loop_unswitch(LLVMPassManagerRef PM) { 120 LLVMAddLoopUnswitchPass(PM); 121 return Val_unit; 122 } 123 124 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_memcpy_opt(LLVMPassManagerRef PM)125CAMLprim value llvm_add_memcpy_opt(LLVMPassManagerRef PM) { 126 LLVMAddMemCpyOptPass(PM); 127 return Val_unit; 128 } 129 130 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_partially_inline_lib_calls(LLVMPassManagerRef PM)131CAMLprim value llvm_add_partially_inline_lib_calls(LLVMPassManagerRef PM) { 132 LLVMAddPartiallyInlineLibCallsPass(PM); 133 return Val_unit; 134 } 135 136 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_lower_switch(LLVMPassManagerRef PM)137CAMLprim value llvm_add_lower_switch(LLVMPassManagerRef PM) { 138 LLVMAddLowerSwitchPass(PM); 139 return Val_unit; 140 } 141 142 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_promote_memory_to_register(LLVMPassManagerRef PM)143CAMLprim value llvm_add_promote_memory_to_register(LLVMPassManagerRef PM) { 144 LLVMAddPromoteMemoryToRegisterPass(PM); 145 return Val_unit; 146 } 147 148 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_reassociation(LLVMPassManagerRef PM)149CAMLprim value llvm_add_reassociation(LLVMPassManagerRef PM) { 150 LLVMAddReassociatePass(PM); 151 return Val_unit; 152 } 153 154 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_sccp(LLVMPassManagerRef PM)155CAMLprim value llvm_add_sccp(LLVMPassManagerRef PM) { 156 LLVMAddSCCPPass(PM); 157 return Val_unit; 158 } 159 160 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_scalar_repl_aggregates(LLVMPassManagerRef PM)161CAMLprim value llvm_add_scalar_repl_aggregates(LLVMPassManagerRef PM) { 162 LLVMAddScalarReplAggregatesPass(PM); 163 return Val_unit; 164 } 165 166 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_scalar_repl_aggregates_ssa(LLVMPassManagerRef PM)167CAMLprim value llvm_add_scalar_repl_aggregates_ssa(LLVMPassManagerRef PM) { 168 LLVMAddScalarReplAggregatesPassSSA(PM); 169 return Val_unit; 170 } 171 172 /* int -> [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_scalar_repl_aggregates_with_threshold(value threshold,LLVMPassManagerRef PM)173CAMLprim value llvm_add_scalar_repl_aggregates_with_threshold(value threshold, 174 LLVMPassManagerRef PM) { 175 LLVMAddScalarReplAggregatesPassWithThreshold(PM, Int_val(threshold)); 176 return Val_unit; 177 } 178 179 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_simplify_lib_calls(LLVMPassManagerRef PM)180CAMLprim value llvm_add_simplify_lib_calls(LLVMPassManagerRef PM) { 181 LLVMAddSimplifyLibCallsPass(PM); 182 return Val_unit; 183 } 184 185 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_tail_call_elimination(LLVMPassManagerRef PM)186CAMLprim value llvm_add_tail_call_elimination(LLVMPassManagerRef PM) { 187 LLVMAddTailCallEliminationPass(PM); 188 return Val_unit; 189 } 190 191 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_constant_propagation(LLVMPassManagerRef PM)192CAMLprim value llvm_add_constant_propagation(LLVMPassManagerRef PM) { 193 LLVMAddConstantPropagationPass(PM); 194 return Val_unit; 195 } 196 197 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_demote_memory_to_register(LLVMPassManagerRef PM)198CAMLprim value llvm_add_demote_memory_to_register(LLVMPassManagerRef PM) { 199 LLVMAddDemoteMemoryToRegisterPass(PM); 200 return Val_unit; 201 } 202 203 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_verifier(LLVMPassManagerRef PM)204CAMLprim value llvm_add_verifier(LLVMPassManagerRef PM) { 205 LLVMAddVerifierPass(PM); 206 return Val_unit; 207 } 208 209 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_correlated_value_propagation(LLVMPassManagerRef PM)210CAMLprim value llvm_add_correlated_value_propagation(LLVMPassManagerRef PM) { 211 LLVMAddCorrelatedValuePropagationPass(PM); 212 return Val_unit; 213 } 214 215 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_early_cse(LLVMPassManagerRef PM)216CAMLprim value llvm_add_early_cse(LLVMPassManagerRef PM) { 217 LLVMAddEarlyCSEPass(PM); 218 return Val_unit; 219 } 220 221 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_lower_expect_intrinsic(LLVMPassManagerRef PM)222CAMLprim value llvm_add_lower_expect_intrinsic(LLVMPassManagerRef PM) { 223 LLVMAddLowerExpectIntrinsicPass(PM); 224 return Val_unit; 225 } 226 227 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_type_based_alias_analysis(LLVMPassManagerRef PM)228CAMLprim value llvm_add_type_based_alias_analysis(LLVMPassManagerRef PM) { 229 LLVMAddTypeBasedAliasAnalysisPass(PM); 230 return Val_unit; 231 } 232 233 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_scoped_no_alias_aa(LLVMPassManagerRef PM)234CAMLprim value llvm_add_scoped_no_alias_aa(LLVMPassManagerRef PM) { 235 LLVMAddScopedNoAliasAAPass(PM); 236 return Val_unit; 237 } 238 239 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ llvm_add_basic_alias_analysis(LLVMPassManagerRef PM)240CAMLprim value llvm_add_basic_alias_analysis(LLVMPassManagerRef PM) { 241 LLVMAddBasicAliasAnalysisPass(PM); 242 return Val_unit; 243 } 244