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 */ 23 CAMLprim value llvm_add_aggressive_dce(LLVMPassManagerRef PM) { 24 LLVMAddAggressiveDCEPass(PM); 25 return Val_unit; 26 } 27 28 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 29 CAMLprim 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 */ 35 CAMLprim value llvm_add_cfg_simplification(LLVMPassManagerRef PM) { 36 LLVMAddCFGSimplificationPass(PM); 37 return Val_unit; 38 } 39 40 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 41 CAMLprim 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 */ 47 CAMLprim value llvm_add_scalarizer(LLVMPassManagerRef PM) { 48 LLVMAddScalarizerPass(PM); 49 return Val_unit; 50 } 51 52 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 53 CAMLprim 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 */ 59 CAMLprim value llvm_add_gvn(LLVMPassManagerRef PM) { 60 LLVMAddGVNPass(PM); 61 return Val_unit; 62 } 63 64 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 65 CAMLprim 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 */ 71 CAMLprim value llvm_add_instruction_combining(LLVMPassManagerRef PM) { 72 LLVMAddInstructionCombiningPass(PM); 73 return Val_unit; 74 } 75 76 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 77 CAMLprim value llvm_add_jump_threading(LLVMPassManagerRef PM) { 78 LLVMAddJumpThreadingPass(PM); 79 return Val_unit; 80 } 81 82 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 83 CAMLprim value llvm_add_licm(LLVMPassManagerRef PM) { 84 LLVMAddLICMPass(PM); 85 return Val_unit; 86 } 87 88 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 89 CAMLprim value llvm_add_loop_deletion(LLVMPassManagerRef PM) { 90 LLVMAddLoopDeletionPass(PM); 91 return Val_unit; 92 } 93 94 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 95 CAMLprim value llvm_add_loop_idiom(LLVMPassManagerRef PM) { 96 LLVMAddLoopIdiomPass(PM); 97 return Val_unit; 98 } 99 100 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 101 CAMLprim value llvm_add_loop_rotate(LLVMPassManagerRef PM) { 102 LLVMAddLoopRotatePass(PM); 103 return Val_unit; 104 } 105 106 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 107 CAMLprim value llvm_add_loop_reroll(LLVMPassManagerRef PM) { 108 LLVMAddLoopRerollPass(PM); 109 return Val_unit; 110 } 111 112 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 113 CAMLprim value llvm_add_loop_unroll(LLVMPassManagerRef PM) { 114 LLVMAddLoopUnrollPass(PM); 115 return Val_unit; 116 } 117 118 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 119 CAMLprim value llvm_add_loop_unswitch(LLVMPassManagerRef PM) { 120 LLVMAddLoopUnswitchPass(PM); 121 return Val_unit; 122 } 123 124 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 125 CAMLprim value llvm_add_memcpy_opt(LLVMPassManagerRef PM) { 126 LLVMAddMemCpyOptPass(PM); 127 return Val_unit; 128 } 129 130 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 131 CAMLprim 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 */ 137 CAMLprim value llvm_add_lower_switch(LLVMPassManagerRef PM) { 138 LLVMAddLowerSwitchPass(PM); 139 return Val_unit; 140 } 141 142 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 143 CAMLprim 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 */ 149 CAMLprim value llvm_add_reassociation(LLVMPassManagerRef PM) { 150 LLVMAddReassociatePass(PM); 151 return Val_unit; 152 } 153 154 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 155 CAMLprim value llvm_add_sccp(LLVMPassManagerRef PM) { 156 LLVMAddSCCPPass(PM); 157 return Val_unit; 158 } 159 160 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 161 CAMLprim 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 */ 167 CAMLprim 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 */ 173 CAMLprim 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 */ 180 CAMLprim 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 */ 186 CAMLprim 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 */ 192 CAMLprim value llvm_add_constant_propagation(LLVMPassManagerRef PM) { 193 LLVMAddConstantPropagationPass(PM); 194 return Val_unit; 195 } 196 197 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 198 CAMLprim 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 */ 204 CAMLprim value llvm_add_verifier(LLVMPassManagerRef PM) { 205 LLVMAddVerifierPass(PM); 206 return Val_unit; 207 } 208 209 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 210 CAMLprim 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 */ 216 CAMLprim value llvm_add_early_cse(LLVMPassManagerRef PM) { 217 LLVMAddEarlyCSEPass(PM); 218 return Val_unit; 219 } 220 221 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ 222 CAMLprim 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 */ 228 CAMLprim 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 */ 234 CAMLprim 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 */ 240 CAMLprim value llvm_add_basic_alias_analysis(LLVMPassManagerRef PM) { 241 LLVMAddBasicAliasAnalysisPass(PM); 242 return Val_unit; 243 } 244