• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_constant_propagation(LLVMPassManagerRef PM)23 CAMLprim value llvm_add_constant_propagation(LLVMPassManagerRef PM) {
24   LLVMAddConstantPropagationPass(PM);
25   return Val_unit;
26 }
27 
28 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_sccp(LLVMPassManagerRef PM)29 CAMLprim value llvm_add_sccp(LLVMPassManagerRef PM) {
30   LLVMAddSCCPPass(PM);
31   return Val_unit;
32 }
33 
34 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_dead_store_elimination(LLVMPassManagerRef PM)35 CAMLprim value llvm_add_dead_store_elimination(LLVMPassManagerRef PM) {
36   LLVMAddDeadStoreEliminationPass(PM);
37   return Val_unit;
38 }
39 
40 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_aggressive_dce(LLVMPassManagerRef PM)41 CAMLprim value llvm_add_aggressive_dce(LLVMPassManagerRef PM) {
42   LLVMAddAggressiveDCEPass(PM);
43   return Val_unit;
44 }
45 
46 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_scalar_repl_aggregation(LLVMPassManagerRef PM)47 CAMLprim value llvm_add_scalar_repl_aggregation(LLVMPassManagerRef PM) {
48   LLVMAddScalarReplAggregatesPass(PM);
49   return Val_unit;
50 }
51 
52 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_scalar_repl_aggregation_ssa(LLVMPassManagerRef PM)53 CAMLprim value llvm_add_scalar_repl_aggregation_ssa(LLVMPassManagerRef PM) {
54   LLVMAddScalarReplAggregatesPassSSA(PM);
55   return Val_unit;
56 }
57 
58 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> int -> unit */
llvm_add_scalar_repl_aggregation_with_threshold(value threshold,LLVMPassManagerRef PM)59 CAMLprim value llvm_add_scalar_repl_aggregation_with_threshold(value threshold,
60                                                                LLVMPassManagerRef PM) {
61   LLVMAddScalarReplAggregatesPassWithThreshold(PM, Int_val(threshold));
62   return Val_unit;
63 }
64 
65 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_ind_var_simplification(LLVMPassManagerRef PM)66 CAMLprim value llvm_add_ind_var_simplification(LLVMPassManagerRef PM) {
67   LLVMAddIndVarSimplifyPass(PM);
68   return Val_unit;
69 }
70 
71 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_instruction_combination(LLVMPassManagerRef PM)72 CAMLprim value llvm_add_instruction_combination(LLVMPassManagerRef PM) {
73   LLVMAddInstructionCombiningPass(PM);
74   return Val_unit;
75 }
76 
77 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_licm(LLVMPassManagerRef PM)78 CAMLprim value llvm_add_licm(LLVMPassManagerRef PM) {
79   LLVMAddLICMPass(PM);
80   return Val_unit;
81 }
82 
83 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_loop_unswitch(LLVMPassManagerRef PM)84 CAMLprim value llvm_add_loop_unswitch(LLVMPassManagerRef PM) {
85   LLVMAddLoopUnswitchPass(PM);
86   return Val_unit;
87 }
88 
89 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_loop_unroll(LLVMPassManagerRef PM)90 CAMLprim value llvm_add_loop_unroll(LLVMPassManagerRef PM) {
91   LLVMAddLoopUnrollPass(PM);
92   return Val_unit;
93 }
94 
95 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_loop_rotation(LLVMPassManagerRef PM)96 CAMLprim value llvm_add_loop_rotation(LLVMPassManagerRef PM) {
97   LLVMAddLoopRotatePass(PM);
98   return Val_unit;
99 }
100 
101 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_memory_to_register_promotion(LLVMPassManagerRef PM)102 CAMLprim value llvm_add_memory_to_register_promotion(LLVMPassManagerRef PM) {
103   LLVMAddPromoteMemoryToRegisterPass(PM);
104   return Val_unit;
105 }
106 
107 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_memory_to_register_demotion(LLVMPassManagerRef PM)108 CAMLprim value llvm_add_memory_to_register_demotion(LLVMPassManagerRef PM) {
109   LLVMAddDemoteMemoryToRegisterPass(PM);
110   return Val_unit;
111 }
112 
113 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_reassociation(LLVMPassManagerRef PM)114 CAMLprim value llvm_add_reassociation(LLVMPassManagerRef PM) {
115   LLVMAddReassociatePass(PM);
116   return Val_unit;
117 }
118 
119 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_jump_threading(LLVMPassManagerRef PM)120 CAMLprim value llvm_add_jump_threading(LLVMPassManagerRef PM) {
121   LLVMAddJumpThreadingPass(PM);
122   return Val_unit;
123 }
124 
125 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_cfg_simplification(LLVMPassManagerRef PM)126 CAMLprim value llvm_add_cfg_simplification(LLVMPassManagerRef PM) {
127   LLVMAddCFGSimplificationPass(PM);
128   return Val_unit;
129 }
130 
131 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_tail_call_elimination(LLVMPassManagerRef PM)132 CAMLprim value llvm_add_tail_call_elimination(LLVMPassManagerRef PM) {
133   LLVMAddTailCallEliminationPass(PM);
134   return Val_unit;
135 }
136 
137 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_gvn(LLVMPassManagerRef PM)138 CAMLprim value llvm_add_gvn(LLVMPassManagerRef PM) {
139   LLVMAddGVNPass(PM);
140   return Val_unit;
141 }
142 
143 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_memcpy_opt(LLVMPassManagerRef PM)144 CAMLprim value llvm_add_memcpy_opt(LLVMPassManagerRef PM) {
145   LLVMAddMemCpyOptPass(PM);
146   return Val_unit;
147 }
148 
149 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_loop_deletion(LLVMPassManagerRef PM)150 CAMLprim value llvm_add_loop_deletion(LLVMPassManagerRef PM) {
151   LLVMAddLoopDeletionPass(PM);
152   return Val_unit;
153 }
154 
155 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_loop_idiom(LLVMPassManagerRef PM)156 CAMLprim value llvm_add_loop_idiom(LLVMPassManagerRef PM) {
157   LLVMAddLoopIdiomPass(PM);
158   return Val_unit;
159 }
160 
161 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_lib_call_simplification(LLVMPassManagerRef PM)162 CAMLprim value llvm_add_lib_call_simplification(LLVMPassManagerRef PM) {
163   LLVMAddSimplifyLibCallsPass(PM);
164   return Val_unit;
165 }
166 
167 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_verifier(LLVMPassManagerRef PM)168 CAMLprim value llvm_add_verifier(LLVMPassManagerRef PM) {
169   LLVMAddVerifierPass(PM);
170   return Val_unit;
171 }
172 
173 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_correlated_value_propagation(LLVMPassManagerRef PM)174 CAMLprim value llvm_add_correlated_value_propagation(LLVMPassManagerRef PM) {
175   LLVMAddCorrelatedValuePropagationPass(PM);
176   return Val_unit;
177 }
178 
179 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_early_cse(LLVMPassManagerRef PM)180 CAMLprim value llvm_add_early_cse(LLVMPassManagerRef PM) {
181   LLVMAddEarlyCSEPass(PM);
182   return Val_unit;
183 }
184 
185 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_lower_expect_intrinsic(LLVMPassManagerRef PM)186 CAMLprim value llvm_add_lower_expect_intrinsic(LLVMPassManagerRef PM) {
187   LLVMAddLowerExpectIntrinsicPass(PM);
188   return Val_unit;
189 }
190 
191 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_type_based_alias_analysis(LLVMPassManagerRef PM)192 CAMLprim value llvm_add_type_based_alias_analysis(LLVMPassManagerRef PM) {
193   LLVMAddTypeBasedAliasAnalysisPass(PM);
194   return Val_unit;
195 }
196 
197 /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
llvm_add_basic_alias_analysis(LLVMPassManagerRef PM)198 CAMLprim value llvm_add_basic_alias_analysis(LLVMPassManagerRef PM) {
199   LLVMAddBasicAliasAnalysisPass(PM);
200   return Val_unit;
201 }
202