c0701701344d98027a36d087c436c4ee5c81c984
[oota-llvm.git] / bindings / ocaml / llvm / llvm.mli
1 (*===-- llvm/llvm.mli - LLVM Ocaml Interface -------------------------------===*
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 (** Core API.
11
12     This interface provides an ocaml API for the LLVM intermediate
13     representation, the classes in the VMCore library. *)
14
15
16 (** {6 Abstract types}
17
18     These abstract types correlate directly to the LLVM VMCore classes. *)
19
20 (** The top-level container for all LLVM global data. See the
21     [llvm::LLVMContext] class. *)
22 type llcontext
23
24 (** The top-level container for all other LLVM Intermediate Representation (IR)
25     objects. See the [llvm::Module] class. *)
26 type llmodule
27
28 (** Each value in the LLVM IR has a type, an instance of [lltype]. See the
29     [llvm::Type] class. *)
30 type lltype
31
32 (** Any value in the LLVM IR. Functions, instructions, global variables,
33     constants, and much more are all [llvalues]. See the [llvm::Value] class.
34     This type covers a wide range of subclasses. *)
35 type llvalue
36
37 (** Used to store users and usees of values. See the [llvm::Use] class. *)
38 type lluse
39
40 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *)
41 type llbasicblock
42
43 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
44     class. *)
45 type llbuilder
46
47 (** Used to efficiently handle large buffers of read-only binary data.
48     See the [llvm::MemoryBuffer] class. *)
49 type llmemorybuffer
50
51 (** The kind of an [lltype], the result of [classify_type ty]. See the
52     [llvm::Type::TypeID] enumeration. *)
53 module TypeKind : sig
54   type t =
55     Void
56   | Float
57   | Double
58   | X86fp80
59   | Fp128
60   | Ppc_fp128
61   | Label
62   | Integer
63   | Function
64   | Struct
65   | Array
66   | Pointer
67   | Vector
68   | Metadata
69 end
70
71 (** The linkage of a global value, accessed with {!linkage} and
72     {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
73 module Linkage : sig
74   type t =
75     External
76   | Available_externally
77   | Link_once
78   | Link_once_odr
79   | Weak
80   | Weak_odr
81   | Appending
82   | Internal
83   | Private
84   | Dllimport
85   | Dllexport
86   | External_weak
87   | Ghost
88   | Common
89   | Linker_private
90 end
91
92 (** The linker visibility of a global value, accessed with {!visibility} and
93     {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
94 module Visibility : sig
95   type t =
96     Default
97   | Hidden
98   | Protected
99 end
100
101 (** The following calling convention values may be accessed with
102     {!function_call_conv} and {!set_function_call_conv}. Calling
103     conventions are open-ended. *)
104 module CallConv : sig
105   val c : int             (** [c] is the C calling convention. *)
106   val fast : int          (** [fast] is the calling convention to allow LLVM
107                               maximum optimization opportunities. Use only with
108                               internal linkage. *)
109   val cold : int          (** [cold] is the calling convention for
110                               callee-save. *)
111   val x86_stdcall : int   (** [x86_stdcall] is the familiar stdcall calling
112                               convention from C. *)
113   val x86_fastcall : int  (** [x86_fastcall] is the familiar fastcall calling
114                               convention from C. *)
115 end
116
117 module Attribute : sig
118   type t =
119   | Zext
120   | Sext
121   | Noreturn
122   | Inreg
123   | Structret
124   | Nounwind
125   | Noalias
126   | Byval
127   | Nest
128   | Readnone
129   | Readonly
130   | Noinline
131   | Alwaysinline
132   | Optsize
133   | Ssp
134   | Sspreq
135   | Alignment of int
136   | Nocapture
137   | Noredzone
138   | Noimplicitfloat
139   | Naked
140   | Inlinehint
141   | Stackalignment of int
142 end
143
144 (** The predicate for an integer comparison ([icmp]) instruction.
145     See the [llvm::ICmpInst::Predicate] enumeration. *)
146 module Icmp : sig
147   type t =
148   | Eq
149   | Ne
150   | Ugt
151   | Uge
152   | Ult
153   | Ule
154   | Sgt
155   | Sge
156   | Slt
157   | Sle
158 end
159
160 (** The predicate for a floating-point comparison ([fcmp]) instruction.
161     See the [llvm::FCmpInst::Predicate] enumeration. *)
162 module Fcmp : sig
163   type t =
164   | False
165   | Oeq
166   | Ogt
167   | Oge
168   | Olt
169   | Ole
170   | One
171   | Ord
172   | Uno
173   | Ueq
174   | Ugt
175   | Uge
176   | Ult
177   | Ule
178   | Une
179   | True
180 end
181
182
183 (** {6 Iteration} *)
184
185 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
186     of [a]. [llpos] is used to specify positions in and for forward iteration
187     through the various value lists maintained by the LLVM IR. *)
188 type ('a, 'b) llpos =
189 | At_end of 'a
190 | Before of 'b
191
192 (** [After b] and [At_start a] specify positions from the end of the ['b] list
193     of [a]. [llrev_pos] is used for reverse iteration through the various value
194     lists maintained by the LLVM IR. *)
195 type ('a, 'b) llrev_pos =
196 | At_start of 'a
197 | After of 'b
198
199
200 (** {6 Exceptions} *)
201
202 exception IoError of string
203
204
205 (** {6 Contexts} *)
206
207 (** [create_context ()] creates a context for storing the "global" state in
208     LLVM. See the constructor [llvm::LLVMContext]. *)
209 val create_context : unit -> llcontext
210
211 (** [destroy_context ()] destroys a context. See the destructor
212     [llvm::LLVMContext::~LLVMContext]. *)
213 val dispose_context : llcontext -> unit
214
215 (** See the function [llvm::getGlobalContext]. *)
216 val global_context : unit -> llcontext
217
218 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
219     name [name] in the context [context].  See the function
220     [llvm::LLVMContext::getMDKindID]. *)
221 val mdkind_id : llcontext -> string -> int
222
223
224 (** {6 Modules} *)
225
226 (** [create_module context id] creates a module with the supplied module ID in
227     the context [context].  Modules are not garbage collected; it is mandatory
228     to call {!dispose_module} to free memory. See the constructor
229     [llvm::Module::Module]. *)
230 val create_module : llcontext -> string -> llmodule
231
232 (** [dispose_module m] destroys a module [m] and all of the IR objects it
233     contained. All references to subordinate objects are invalidated;
234     referencing them will invoke undefined behavior. See the destructor
235     [llvm::Module::~Module]. *)
236 val dispose_module : llmodule -> unit
237
238 (** [target_triple m] is the target specifier for the module [m], something like
239     [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
240 val target_triple: llmodule -> string
241
242
243 (** [target_triple triple m] changes the target specifier for the module [m] to
244     the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
245 val set_target_triple: string -> llmodule -> unit
246
247
248 (** [data_layout m] is the data layout specifier for the module [m], something
249     like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
250     method [llvm::Module::getDataLayout]. *)
251 val data_layout: llmodule -> string
252
253
254 (** [set_data_layout s m] changes the data layout specifier for the module [m]
255     to the string [s]. See the method [llvm::Module::setDataLayout]. *)
256 val set_data_layout: string -> llmodule -> unit
257
258 (** [dump_module m] prints the .ll representation of the module [m] to standard
259     error. See the method [llvm::Module::dump]. *)
260 val dump_module : llmodule -> unit
261
262 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
263     the method [llvm::Module::setModuleInlineAsm]. *)
264 val set_module_inline_asm : llmodule -> string -> unit
265
266
267
268 (** {6 Types} *)
269
270 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
271     See the method [llvm::Type::getTypeID]. *)
272 val classify_type : lltype -> TypeKind.t
273
274 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
275     See the method [llvm::Type::getContext]. *)
276 val type_context : lltype -> llcontext
277
278 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
279 val string_of_lltype : lltype -> string
280
281 (** {7 Operations on integer types} *)
282
283 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
284     [llvm::Type::Int1Ty]. *)
285 val i1_type : llcontext -> lltype
286
287 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
288     [llvm::Type::Int8Ty]. *)
289 val i8_type : llcontext -> lltype
290
291 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
292     [llvm::Type::Int16Ty]. *)
293 val i16_type : llcontext -> lltype
294
295 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
296     [llvm::Type::Int32Ty]. *)
297 val i32_type : llcontext -> lltype
298
299 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
300     [llvm::Type::Int64Ty]. *)
301 val i64_type : llcontext -> lltype
302
303 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
304     [c]. See the method [llvm::IntegerType::get]. *)
305 val integer_type : llcontext -> int -> lltype
306
307 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
308     in the context [c].  See the method [llvm::IntegerType::getBitWidth]. *)
309 val integer_bitwidth : lltype -> int
310
311
312 (** {7 Operations on real types} *)
313
314 (** [float_type c] returns the IEEE 32-bit floating point type in the context
315     [c]. See [llvm::Type::FloatTy]. *)
316 val float_type : llcontext -> lltype
317
318 (** [double_type c] returns the IEEE 64-bit floating point type in the context
319     [c]. See [llvm::Type::DoubleTy]. *)
320 val double_type : llcontext -> lltype
321
322 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
323     [c]. See [llvm::Type::X86_FP80Ty]. *)
324 val x86fp80_type : llcontext -> lltype
325
326 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
327     [c]. See [llvm::Type::FP128Ty]. *)
328 val fp128_type : llcontext -> lltype
329
330 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
331     context [c]. See [llvm::Type::PPC_FP128Ty]. *)
332 val ppc_fp128_type : llcontext -> lltype
333
334
335 (** {7 Operations on function types} *)
336
337 (** [function_type ret_ty param_tys] returns the function type returning
338     [ret_ty] and taking [param_tys] as parameters.
339     See the method [llvm::FunctionType::get]. *)
340 val function_type : lltype -> lltype array -> lltype
341
342 (** [var_arg_function_type ret_ty param_tys] is just like
343     [function_type ret_ty param_tys] except that it returns the function type
344     which also takes a variable number of arguments.
345     See the method [llvm::FunctionType::get]. *)
346 val var_arg_function_type : lltype -> lltype array -> lltype
347
348
349 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
350     otherwise. See the method [llvm::FunctionType::isVarArg]. *)
351 val is_var_arg : lltype -> bool
352
353 (** [return_type fty] gets the return type of the function type [fty].
354     See the method [llvm::FunctionType::getReturnType]. *)
355 val return_type : lltype -> lltype
356
357 (** [param_types fty] gets the parameter types of the function type [fty].
358     See the method [llvm::FunctionType::getParamType]. *)
359 val param_types : lltype -> lltype array
360
361
362 (** {7 Operations on struct types} *)
363
364 (** [struct_type context tys] returns the structure type in the context
365     [context] containing in the types in the array [tys]. See the method
366     [llvm::StructType::get]. *)
367 val struct_type : llcontext -> lltype array -> lltype
368
369
370 (** [packed_struct_type context ys] returns the packed structure type in the
371     context [context] containing in the types in the array [tys]. See the method
372     [llvm::StructType::get]. *)
373 val packed_struct_type : llcontext -> lltype array -> lltype
374
375 (** [struct_name ty] returns the name of the named structure type [ty],
376  * or None if the structure type is not named *)
377 val struct_name : lltype -> string option
378
379
380 (** [struct_element_types sty] returns the constituent types of the struct type
381     [sty]. See the method [llvm::StructType::getElementType]. *)
382 val struct_element_types : lltype -> lltype array
383
384
385 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
386     [false] otherwise. See the method [llvm::StructType::isPacked]. *)
387 val is_packed : lltype -> bool
388
389
390 (** {7 Operations on pointer, vector, and array types} *)
391
392 (** [array_type ty n] returns the array type containing [n] elements of type
393     [ty]. See the method [llvm::ArrayType::get]. *)
394 val array_type : lltype -> int -> lltype
395
396 (** [pointer_type ty] returns the pointer type referencing objects of type
397     [ty] in the default address space (0).
398     See the method [llvm::PointerType::getUnqual]. *)
399 val pointer_type : lltype -> lltype
400
401 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
402     of type [ty] in address space [as].
403     See the method [llvm::PointerType::get]. *)
404 val qualified_pointer_type : lltype -> int -> lltype
405
406
407 (** [vector_type ty n] returns the array type containing [n] elements of the
408     primitive type [ty]. See the method [llvm::ArrayType::get]. *)
409 val vector_type : lltype -> int -> lltype
410
411 (** [element_type ty] returns the element type of the pointer, vector, or array
412     type [ty]. See the method [llvm::SequentialType::get]. *)
413 val element_type : lltype -> lltype
414
415 (** [element_type aty] returns the element count of the array type [aty].
416     See the method [llvm::ArrayType::getNumElements]. *)
417 val array_length : lltype -> int
418
419 (** [address_space pty] returns the address space qualifier of the pointer type
420     [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
421 val address_space : lltype -> int
422
423 (** [element_type ty] returns the element count of the vector type [ty].
424     See the method [llvm::VectorType::getNumElements]. *)
425 val vector_size : lltype -> int
426
427
428 (** {7 Operations on other types} *)
429
430 (** [void_type c] creates a type of a function which does not return any
431     value in the context [c]. See [llvm::Type::VoidTy]. *)
432 val void_type : llcontext -> lltype
433
434 (** [label_type c] creates a type of a basic block in the context [c]. See
435     [llvm::Type::LabelTy]. *)
436 val label_type : llcontext -> lltype
437
438 (* {6 Values} *)
439
440 (** [type_of v] returns the type of the value [v].
441     See the method [llvm::Value::getType]. *)
442 val type_of : llvalue -> lltype
443
444 (** [value_name v] returns the name of the value [v]. For global values, this is
445     the symbol name. For instructions and basic blocks, it is the SSA register
446     name. It is meaningless for constants.
447     See the method [llvm::Value::getName]. *)
448 val value_name : llvalue -> string
449
450 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
451     [llvm::Value::setName]. *)
452 val set_value_name : string -> llvalue -> unit
453
454 (** [dump_value v] prints the .ll representation of the value [v] to standard
455     error. See the method [llvm::Value::dump]. *)
456 val dump_value : llvalue -> unit
457
458 (** [replace_all_uses_with old new] replaces all uses of the value [old]
459  * with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
460 val replace_all_uses_with : llvalue -> llvalue -> unit
461
462
463
464 (* {6 Uses} *)
465
466 (** [use_begin v] returns the first position in the use list for the value [v].
467     [use_begin] and [use_succ] can e used to iterate over the use list in order.
468     See the method [llvm::Value::use_begin]. *)
469 val use_begin : llvalue -> lluse option
470
471 (** [use_succ u] returns the use list position succeeding [u].
472     See the method [llvm::use_value_iterator::operator++]. *)
473 val use_succ : lluse -> lluse option
474
475 (** [user u] returns the user of the use [u].
476     See the method [llvm::Use::getUser]. *)
477 val user : lluse -> llvalue
478
479 (** [used_value u] returns the usee of the use [u].
480     See the method [llvm::Use::getUsedValue]. *)
481 val used_value : lluse -> llvalue
482
483 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
484     in order. Tail recursive. *)
485 val iter_uses : (lluse -> unit) -> llvalue -> unit
486
487 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
488     [u1,...,uN] are the users of the value [v]. Tail recursive. *)
489 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
490
491 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
492     [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
493 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
494
495
496 (* {6 Users} *)
497
498 (** [operand v i] returns the operand at index [i] for the value [v]. See the
499     method [llvm::User::getOperand]. *)
500 val operand : llvalue -> int -> llvalue
501
502 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
503     the value [o].
504     See the method [llvm::User::setOperand]. *)
505 val set_operand : llvalue -> int -> llvalue -> unit
506
507 (** [num_operands v] returns the number of operands for the value [v].
508     See the method [llvm::User::getNumOperands]. *)
509 val num_operands : llvalue -> int
510
511 (** {7 Operations on constants of (mostly) any type} *)
512
513 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
514     otherwise. Similar to [llvm::isa<Constant>]. *)
515 val is_constant : llvalue -> bool
516
517 (** [const_null ty] returns the constant null (zero) of the type [ty].
518     See the method [llvm::Constant::getNullValue]. *)
519 val const_null : lltype -> llvalue
520
521 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
522     [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
523 val const_all_ones : (*int|vec*)lltype -> llvalue
524
525 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
526     [ty]. See the method [llvm::ConstantPointerNull::get]. *)
527 val const_pointer_null : lltype -> llvalue
528
529 (** [undef ty] returns the undefined value of the type [ty].
530     See the method [llvm::UndefValue::get]. *)
531 val undef : lltype -> llvalue
532
533 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
534     See the method [llvm::Constant::isNullValue]. *)
535 val is_null : llvalue -> bool
536
537 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
538     otherwise. Similar to [llvm::isa<UndefValue>]. *)
539 val is_undef : llvalue -> bool
540
541
542 (** {7 Operations on instructions} *)
543
544 (** [has_metadata i] returns whether or not the instruction [i] has any
545     metadata attached to it. See the function
546     [llvm::Instruction::hasMetadata]. *)
547 val has_metadata : llvalue -> bool
548
549 (** [metadata i kind] optionally returns the metadata associated with the
550     kind [kind] in the instruction [i] See the function
551     [llvm::Instruction::getMetadata]. *)
552 val metadata : llvalue -> int -> llvalue option
553
554 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
555     instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
556 val set_metadata : llvalue -> int -> llvalue -> unit
557
558 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
559     instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
560 val clear_metadata : llvalue -> int -> unit
561
562
563 (** {7 Operations on metadata} *)
564
565 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
566     See the method [llvm::MDNode::get]. *)
567 val mdstring : llcontext -> string -> llvalue
568
569 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
570     context [c].
571     See the method [llvm::MDNode::get]. *)
572 val mdnode : llcontext -> llvalue array -> llvalue
573
574
575 (** {7 Operations on scalar constants} *)
576
577 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
578     See the method [llvm::ConstantInt::get]. *)
579 val const_int : lltype -> int -> llvalue
580
581 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
582     [i]. See the method [llvm::ConstantInt::get]. *)
583 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
584
585
586 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
587  * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
588 val const_int_of_string : lltype -> string -> int -> llvalue
589
590
591 (** [const_float ty n] returns the floating point constant of type [ty] and
592     value [n]. See the method [llvm::ConstantFP::get]. *)
593 val const_float : lltype -> float -> llvalue
594
595 (** [const_float_of_string ty s] returns the floating point constant of type
596     [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
597 val const_float_of_string : lltype -> string -> llvalue
598
599
600
601 (** {7 Operations on composite constants} *)
602
603 (** [const_string c s] returns the constant [i8] array with the values of the
604     characters in the string [s] in the context [c]. The array is not 
605     null-terminated (but see {!const_stringz}). This value can in turn be used
606     as the initializer for a global variable. See the method
607     [llvm::ConstantArray::get]. *)
608 val const_string : llcontext -> string -> llvalue
609
610 (** [const_stringz c s] returns the constant [i8] array with the values of the
611     characters in the string [s] and a null terminator in the context [c]. This
612     value can in turn be used as the initializer for a global variable.
613     See the method [llvm::ConstantArray::get]. *)
614 val const_stringz : llcontext -> string -> llvalue
615
616 (** [const_array ty elts] returns the constant array of type
617     [array_type ty (Array.length elts)] and containing the values [elts].
618     This value can in turn be used as the initializer for a global variable.
619     See the method [llvm::ConstantArray::get]. *)
620 val const_array : lltype -> llvalue array -> llvalue
621
622 (** [const_struct context elts] returns the structured constant of type
623     [struct_type (Array.map type_of elts)] and containing the values [elts]
624     in the context [context]. This value can in turn be used as the initializer
625     for a global variable. See the method [llvm::ConstantStruct::get]. *)
626 val const_struct : llcontext -> llvalue array -> llvalue
627
628
629 (** [const_packed_struct context elts] returns the structured constant of
630     type {!packed_struct_type} [(Array.map type_of elts)] and containing the
631     values [elts] in the context [context]. This value can in turn be used as
632     the initializer for a global variable. See the method
633     [llvm::ConstantStruct::get]. *)
634 val const_packed_struct : llcontext -> llvalue array -> llvalue
635
636
637 (** [const_vector elts] returns the vector constant of type
638     [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
639     values [elts]. See the method [llvm::ConstantVector::get]. *)
640 val const_vector : llvalue array -> llvalue
641
642
643 (** {7 Constant expressions} *)
644
645 (** [align_of ty] returns the alignof constant for the type [ty]. This is
646     equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
647     (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
648     more readable.  See the method [llvm::ConstantExpr::getAlignOf]. *)
649 val align_of : lltype -> llvalue
650
651 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
652     equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
653     (const_int i32_type 1)) i64_type], but considerably more readable.
654     See the method [llvm::ConstantExpr::getSizeOf]. *)
655 val size_of : lltype -> llvalue
656
657 (** [const_neg c] returns the arithmetic negation of the constant [c].
658     See the method [llvm::ConstantExpr::getNeg]. *)
659 val const_neg : llvalue -> llvalue
660
661 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
662     no signed wrapping. The result is undefined if the negation overflows.
663     See the method [llvm::ConstantExpr::getNSWNeg]. *)
664 val const_nsw_neg : llvalue -> llvalue
665
666 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
667     no unsigned wrapping. The result is undefined if the negation overflows.
668     See the method [llvm::ConstantExpr::getNUWNeg]. *)
669 val const_nuw_neg : llvalue -> llvalue
670
671 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
672     See the method [llvm::ConstantExpr::getFNeg]. *)
673 val const_fneg : llvalue -> llvalue
674
675 (** [const_not c] returns the bitwise inverse of the constant [c].
676     See the method [llvm::ConstantExpr::getNot]. *)
677 val const_not : llvalue -> llvalue
678
679 (** [const_add c1 c2] returns the constant sum of two constants.
680     See the method [llvm::ConstantExpr::getAdd]. *)
681 val const_add : llvalue -> llvalue -> llvalue
682
683 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
684     signed wrapping. The result is undefined if the sum overflows.
685     See the method [llvm::ConstantExpr::getNSWAdd]. *)
686 val const_nsw_add : llvalue -> llvalue -> llvalue
687
688 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
689     unsigned wrapping. The result is undefined if the sum overflows.
690     See the method [llvm::ConstantExpr::getNSWAdd]. *)
691 val const_nuw_add : llvalue -> llvalue -> llvalue
692
693 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
694     See the method [llvm::ConstantExpr::getFAdd]. *)
695 val const_fadd : llvalue -> llvalue -> llvalue
696
697 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
698     constants. See the method [llvm::ConstantExpr::getSub]. *)
699 val const_sub : llvalue -> llvalue -> llvalue
700
701 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
702     no signed wrapping. The result is undefined if the sum overflows.
703     See the method [llvm::ConstantExpr::getNSWSub]. *)
704 val const_nsw_sub : llvalue -> llvalue -> llvalue
705
706 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
707     no unsigned wrapping. The result is undefined if the sum overflows.
708     See the method [llvm::ConstantExpr::getNSWSub]. *)
709 val const_nuw_sub : llvalue -> llvalue -> llvalue
710
711 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
712     constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
713 val const_fsub : llvalue -> llvalue -> llvalue
714
715 (** [const_mul c1 c2] returns the constant product of two constants.
716     See the method [llvm::ConstantExpr::getMul]. *)
717 val const_mul : llvalue -> llvalue -> llvalue
718
719 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
720     no signed wrapping. The result is undefined if the sum overflows.
721     See the method [llvm::ConstantExpr::getNSWMul]. *)
722 val const_nsw_mul : llvalue -> llvalue -> llvalue
723
724 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
725     no unsigned wrapping. The result is undefined if the sum overflows.
726     See the method [llvm::ConstantExpr::getNSWMul]. *)
727 val const_nuw_mul : llvalue -> llvalue -> llvalue
728
729 (** [const_fmul c1 c2] returns the constant product of two constants floats.
730     See the method [llvm::ConstantExpr::getFMul]. *)
731 val const_fmul : llvalue -> llvalue -> llvalue
732
733 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
734     integer constants.
735     See the method [llvm::ConstantExpr::getUDiv]. *)
736 val const_udiv : llvalue -> llvalue -> llvalue
737
738 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
739     integer constants.
740     See the method [llvm::ConstantExpr::getSDiv]. *)
741 val const_sdiv : llvalue -> llvalue -> llvalue
742
743 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
744     signed integer constants. The result is undefined if the result is rounded
745     or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
746 val const_exact_sdiv : llvalue -> llvalue -> llvalue
747
748 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
749     point constants.
750     See the method [llvm::ConstantExpr::getFDiv]. *)
751 val const_fdiv : llvalue -> llvalue -> llvalue
752
753 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
754     unsigned integer constants.
755     See the method [llvm::ConstantExpr::getURem]. *)
756 val const_urem : llvalue -> llvalue -> llvalue
757
758 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
759     signed integer constants.
760     See the method [llvm::ConstantExpr::getSRem]. *)
761 val const_srem : llvalue -> llvalue -> llvalue
762
763 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
764     signed floating point constants.
765     See the method [llvm::ConstantExpr::getFRem]. *)
766 val const_frem : llvalue -> llvalue -> llvalue
767
768 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
769     constants.
770     See the method [llvm::ConstantExpr::getAnd]. *)
771 val const_and : llvalue -> llvalue -> llvalue
772
773 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
774     constants.
775     See the method [llvm::ConstantExpr::getOr]. *)
776 val const_or : llvalue -> llvalue -> llvalue
777
778 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
779     constants.
780     See the method [llvm::ConstantExpr::getXor]. *)
781 val const_xor : llvalue -> llvalue -> llvalue
782
783 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
784     constants, [c1 pred c2].
785     See the method [llvm::ConstantExpr::getICmp]. *)
786 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
787
788
789 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
790     point constants, [c1 pred c2].
791     See the method [llvm::ConstantExpr::getFCmp]. *)
792 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
793
794
795 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
796     constant integer [c2].
797     See the method [llvm::ConstantExpr::getShl]. *)
798 val const_shl : llvalue -> llvalue -> llvalue
799
800 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
801     constant integer [c2] with zero extension.
802     See the method [llvm::ConstantExpr::getLShr]. *)
803 val const_lshr : llvalue -> llvalue -> llvalue
804
805 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
806     constant integer [c2] with sign extension.
807     See the method [llvm::ConstantExpr::getAShr]. *)
808 val const_ashr : llvalue -> llvalue -> llvalue
809
810 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
811     constant integers indices from the array [indices].
812     See the method [llvm::ConstantExpr::getGetElementPtr]. *)
813 val const_gep : llvalue -> llvalue array -> llvalue
814
815 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
816     with the constant integers indices from the array [indices].
817     See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
818 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
819
820
821 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
822     to the smaller integer type [ty].
823     See the method [llvm::ConstantExpr::getTrunc]. *)
824 val const_trunc : llvalue -> lltype -> llvalue
825
826 (** [const_sext c ty] returns the constant sign extension of integer constant
827     [c] to the larger integer type [ty].
828     See the method [llvm::ConstantExpr::getSExt]. *)
829 val const_sext : llvalue -> lltype -> llvalue
830
831 (** [const_zext c ty] returns the constant zero extension of integer constant
832     [c] to the larger integer type [ty].
833     See the method [llvm::ConstantExpr::getZExt]. *)
834 val const_zext : llvalue -> lltype -> llvalue
835
836 (** [const_fptrunc c ty] returns the constant truncation of floating point
837     constant [c] to the smaller floating point type [ty].
838     See the method [llvm::ConstantExpr::getFPTrunc]. *)
839 val const_fptrunc : llvalue -> lltype -> llvalue
840
841 (** [const_fpext c ty] returns the constant extension of floating point constant
842     [c] to the larger floating point type [ty].
843     See the method [llvm::ConstantExpr::getFPExt]. *)
844 val const_fpext : llvalue -> lltype -> llvalue
845
846 (** [const_uitofp c ty] returns the constant floating point conversion of
847     unsigned integer constant [c] to the floating point type [ty].
848     See the method [llvm::ConstantExpr::getUIToFP]. *)
849 val const_uitofp : llvalue -> lltype -> llvalue
850
851 (** [const_sitofp c ty] returns the constant floating point conversion of
852     signed integer constant [c] to the floating point type [ty].
853     See the method [llvm::ConstantExpr::getSIToFP]. *)
854 val const_sitofp : llvalue -> lltype -> llvalue
855
856 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
857     floating point constant [c] to integer type [ty].
858     See the method [llvm::ConstantExpr::getFPToUI]. *)
859 val const_fptoui : llvalue -> lltype -> llvalue
860
861 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
862     floating point constant [c] to integer type [ty].
863     See the method [llvm::ConstantExpr::getFPToSI]. *)
864 val const_fptosi : llvalue -> lltype -> llvalue
865
866 (** [const_ptrtoint c ty] returns the constant integer conversion of
867     pointer constant [c] to integer type [ty].
868     See the method [llvm::ConstantExpr::getPtrToInt]. *)
869 val const_ptrtoint : llvalue -> lltype -> llvalue
870
871 (** [const_inttoptr c ty] returns the constant pointer conversion of
872     integer constant [c] to pointer type [ty].
873     See the method [llvm::ConstantExpr::getIntToPtr]. *)
874 val const_inttoptr : llvalue -> lltype -> llvalue
875
876 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
877     to type [ty] of equal size.
878     See the method [llvm::ConstantExpr::getBitCast]. *)
879 val const_bitcast : llvalue -> lltype -> llvalue
880
881 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
882     conversion of constant [c] to type [ty].
883     See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
884 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
885
886
887 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
888     conversion of constant [c] to type [ty].
889     See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
890 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
891
892
893 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
894     conversion of constant [c] to type [ty].
895     See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
896 val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
897
898
899 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
900     cast conversion of constant [c] to type [ty] of equal size.
901     See the method [llvm::ConstantExpr::getPointerCast]. *)
902 val const_pointercast : llvalue -> lltype -> llvalue
903
904
905 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
906     -> integer casts of constant [c] to type [ty].
907     See the method [llvm::ConstantExpr::getIntCast]. *)
908 val const_intcast : llvalue -> lltype -> llvalue
909
910
911 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
912     fp casts of constant [c] to type [ty].
913     See the method [llvm::ConstantExpr::getFPCast]. *)
914 val const_fpcast : llvalue -> lltype -> llvalue
915
916
917 (** [const_select cond t f] returns the constant conditional which returns value
918     [t] if the boolean constant [cond] is true and the value [f] otherwise.
919     See the method [llvm::ConstantExpr::getSelect]. *)
920 val const_select : llvalue -> llvalue -> llvalue -> llvalue
921
922
923 (** [const_extractelement vec i] returns the constant [i]th element of
924     constant vector [vec]. [i] must be a constant [i32] value unsigned less than
925     the size of the vector.
926     See the method [llvm::ConstantExpr::getExtractElement]. *)
927 val const_extractelement : llvalue -> llvalue -> llvalue
928
929
930 (** [const_insertelement vec v i] returns the constant vector with the same
931     elements as constant vector [v] but the [i]th element replaced by the
932     constant [v]. [v] must be a constant value with the type of the vector
933     elements. [i] must be a constant [i32] value unsigned less than the size
934     of the vector.
935     See the method [llvm::ConstantExpr::getInsertElement]. *)
936 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
937
938
939 (** [const_shufflevector a b mask] returns a constant [shufflevector].
940     See the LLVM Language Reference for details on the [shufflevector]
941     instruction.
942     See the method [llvm::ConstantExpr::getShuffleVector]. *)
943 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
944
945
946 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
947     constant aggregate [agg]. Each [idxs] must be less than the size of the
948     aggregate.  See the method [llvm::ConstantExpr::getExtractValue]. *)
949 val const_extractvalue : llvalue -> int array -> llvalue
950
951
952 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
953     indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
954     of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
955 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
956
957
958 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
959     See the method [llvm::InlineAsm::get]. *)
960 val const_inline_asm : lltype -> string -> string -> bool -> bool ->
961                             llvalue
962
963
964 (** [block_address f bb] returns the address of the basic block [bb] in the
965     function [f]. See the method [llvm::BasicBlock::get]. *)
966 val block_address : llvalue -> llbasicblock -> llvalue
967
968
969 (** {7 Operations on global variables, functions, and aliases (globals)} *)
970
971 (** [global_parent g] is the enclosing module of the global value [g].
972     See the method [llvm::GlobalValue::getParent]. *)
973 val global_parent : llvalue -> llmodule
974
975 (** [is_declaration g] returns [true] if the global value [g] is a declaration
976     only. Returns [false] otherwise.
977     See the method [llvm::GlobalValue::isDeclaration]. *)
978 val is_declaration : llvalue -> bool
979
980 (** [linkage g] returns the linkage of the global value [g].
981     See the method [llvm::GlobalValue::getLinkage]. *)
982 val linkage : llvalue -> Linkage.t
983
984 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
985     See the method [llvm::GlobalValue::setLinkage]. *)
986 val set_linkage : Linkage.t -> llvalue -> unit
987
988 (** [section g] returns the linker section of the global value [g].
989     See the method [llvm::GlobalValue::getSection]. *)
990 val section : llvalue -> string
991
992 (** [set_section s g] sets the linker section of the global value [g] to [s].
993     See the method [llvm::GlobalValue::setSection]. *)
994 val set_section : string -> llvalue -> unit
995
996 (** [visibility g] returns the linker visibility of the global value [g].
997     See the method [llvm::GlobalValue::getVisibility]. *)
998 val visibility : llvalue -> Visibility.t
999
1000 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1001     [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1002 val set_visibility : Visibility.t -> llvalue -> unit
1003
1004
1005 (** [alignment g] returns the required alignment of the global value [g].
1006     See the method [llvm::GlobalValue::getAlignment]. *)
1007 val alignment : llvalue -> int
1008
1009 (** [set_alignment n g] sets the required alignment of the global value [g] to
1010     [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1011 val set_alignment : int -> llvalue -> unit
1012
1013
1014 (** {7 Operations on global variables} *)
1015
1016 (** [declare_global ty name m] returns a new global variable of type [ty] and
1017     with name [name] in module [m] in the default address space (0). If such a
1018     global variable already exists, it is returned. If the type of the existing
1019     global differs, then a bitcast to [ty] is returned. *)
1020 val declare_global : lltype -> string -> llmodule -> llvalue
1021
1022
1023 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1024     of type [ty] and with name [name] in module [m] in the address space
1025     [addrspace]. If such a global variable already exists, it is returned. If
1026     the type of the existing global differs, then a bitcast to [ty] is
1027     returned. *)
1028 val declare_qualified_global : lltype -> string -> int -> llmodule ->
1029                                     llvalue
1030
1031
1032 (** [define_global name init m] returns a new global with name [name] and
1033     initializer [init] in module [m] in the default address space (0). If the
1034     named global already exists, it is renamed.
1035     See the constructor of [llvm::GlobalVariable]. *)
1036 val define_global : string -> llvalue -> llmodule -> llvalue
1037
1038
1039 (** [define_qualified_global name init addrspace m] returns a new global with
1040     name [name] and initializer [init] in module [m] in the address space
1041     [addrspace]. If the named global already exists, it is renamed.
1042     See the constructor of [llvm::GlobalVariable]. *)
1043 val define_qualified_global : string -> llvalue -> int -> llmodule ->
1044                                    llvalue
1045
1046
1047 (** [lookup_global name m] returns [Some g] if a global variable with name
1048     [name] exists in module [m]. If no such global exists, returns [None].
1049     See the [llvm::GlobalVariable] constructor. *)
1050 val lookup_global : string -> llmodule -> llvalue option
1051
1052
1053 (** [delete_global gv] destroys the global variable [gv].
1054     See the method [llvm::GlobalVariable::eraseFromParent]. *)
1055 val delete_global : llvalue -> unit
1056
1057 (** [global_begin m] returns the first position in the global variable list of
1058     the module [m]. [global_begin] and [global_succ] can be used to iterate
1059     over the global list in order.
1060     See the method [llvm::Module::global_begin]. *)
1061 val global_begin : llmodule -> (llmodule, llvalue) llpos
1062
1063
1064 (** [global_succ gv] returns the global variable list position succeeding
1065     [Before gv].
1066     See the method [llvm::Module::global_iterator::operator++]. *)
1067 val global_succ : llvalue -> (llmodule, llvalue) llpos
1068
1069
1070 (** [iter_globals f m] applies function [f] to each of the global variables of
1071     module [m] in order. Tail recursive. *)
1072 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1073
1074 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1075     [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1076 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1077
1078 (** [global_end m] returns the last position in the global variable list of the
1079     module [m]. [global_end] and [global_pred] can be used to iterate over the
1080     global list in reverse.
1081     See the method [llvm::Module::global_end]. *)
1082 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1083
1084
1085 (** [global_pred gv] returns the global variable list position preceding
1086     [After gv].
1087     See the method [llvm::Module::global_iterator::operator--]. *)
1088 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1089
1090
1091 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1092     of module [m] in reverse order. Tail recursive. *)
1093 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1094
1095 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1096     [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1097 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1098
1099 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1100     constant. Returns [false] otherwise.
1101     See the method [llvm::GlobalVariable::isConstant]. *)
1102 val is_global_constant : llvalue -> bool
1103
1104 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1105     [c] is [true] and not if [c] is [false].
1106     See the method [llvm::GlobalVariable::setConstant]. *)
1107 val set_global_constant : bool -> llvalue -> unit
1108
1109
1110 (** [global_initializer gv] returns the initializer for the global variable
1111     [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1112 val global_initializer : llvalue -> llvalue
1113
1114 (** [set_initializer c gv] sets the initializer for the global variable
1115     [gv] to the constant [c].
1116     See the method [llvm::GlobalVariable::setInitializer]. *)
1117 val set_initializer : llvalue -> llvalue -> unit
1118
1119 (** [remove_initializer gv] unsets the initializer for the global variable
1120     [gv].
1121     See the method [llvm::GlobalVariable::setInitializer]. *)
1122 val remove_initializer : llvalue -> unit
1123
1124 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1125     thread-local and [false] otherwise.
1126     See the method [llvm::GlobalVariable::isThreadLocal]. *)
1127 val is_thread_local : llvalue -> bool
1128
1129 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1130     [c] is [true] and not otherwise.
1131     See the method [llvm::GlobalVariable::setThreadLocal]. *)
1132 val set_thread_local : bool -> llvalue -> unit
1133
1134
1135 (** {7 Operations on aliases} *)
1136
1137 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1138     the aliasee [a] with the name [n].
1139     See the constructor for [llvm::GlobalAlias]. *)
1140 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1141
1142
1143
1144 (** {7 Operations on functions} *)
1145
1146 (** [declare_function name ty m] returns a new function of type [ty] and
1147     with name [name] in module [m]. If such a function already exists,
1148     it is returned. If the type of the existing function differs, then a bitcast
1149     to [ty] is returned. *)
1150 val declare_function : string -> lltype -> llmodule -> llvalue
1151
1152
1153 (** [define_function name ty m] creates a new function with name [name] and
1154     type [ty] in module [m]. If the named function already exists, it is
1155     renamed. An entry basic block is created in the function.
1156     See the constructor of [llvm::GlobalVariable]. *)
1157 val define_function : string -> lltype -> llmodule -> llvalue
1158
1159
1160 (** [lookup_function name m] returns [Some f] if a function with name
1161     [name] exists in module [m]. If no such function exists, returns [None].
1162     See the method [llvm::Module] constructor. *)
1163 val lookup_function : string -> llmodule -> llvalue option
1164
1165
1166 (** [delete_function f] destroys the function [f].
1167     See the method [llvm::Function::eraseFromParent]. *)
1168 val delete_function : llvalue -> unit
1169
1170 (** [function_begin m] returns the first position in the function list of the
1171     module [m]. [function_begin] and [function_succ] can be used to iterate over
1172     the function list in order.
1173     See the method [llvm::Module::begin]. *)
1174 val function_begin : llmodule -> (llmodule, llvalue) llpos
1175
1176
1177 (** [function_succ gv] returns the function list position succeeding
1178     [Before gv].
1179     See the method [llvm::Module::iterator::operator++]. *)
1180 val function_succ : llvalue -> (llmodule, llvalue) llpos
1181
1182
1183 (** [iter_functions f m] applies function [f] to each of the functions of module
1184     [m] in order. Tail recursive. *)
1185 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1186
1187 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1188     [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1189 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1190
1191 (** [function_end m] returns the last position in the function list of
1192     the module [m]. [function_end] and [function_pred] can be used to iterate
1193     over the function list in reverse.
1194     See the method [llvm::Module::end]. *)
1195 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1196
1197
1198 (** [function_pred gv] returns the function list position preceding [After gv].
1199     See the method [llvm::Module::iterator::operator--]. *)
1200 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1201
1202
1203 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1204     module [m] in reverse order. Tail recursive. *)
1205 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1206
1207 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1208     [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1209 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1210
1211 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1212     See the method [llvm::Function::isIntrinsic]. *)
1213 val is_intrinsic : llvalue -> bool
1214
1215 (** [function_call_conv f] returns the calling convention of the function [f].
1216     See the method [llvm::Function::getCallingConv]. *)
1217 val function_call_conv : llvalue -> int
1218
1219 (** [set_function_call_conv cc f] sets the calling convention of the function
1220     [f] to the calling convention numbered [cc].
1221     See the method [llvm::Function::setCallingConv]. *)
1222 val set_function_call_conv : int -> llvalue -> unit
1223
1224
1225 (** [gc f] returns [Some name] if the function [f] has a garbage
1226     collection algorithm specified and [None] otherwise.
1227     See the method [llvm::Function::getGC]. *)
1228 val gc : llvalue -> string option
1229
1230 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1231     [gc]. See the method [llvm::Function::setGC]. *)
1232 val set_gc : string option -> llvalue -> unit
1233
1234 (** [add_function_attr f a] adds attribute [a] to the return type of function
1235     [f]. *)
1236 val add_function_attr : llvalue -> Attribute.t -> unit
1237
1238 (** [remove_function_attr f a] removes attribute [a] from the return type of
1239     function [f]. *)
1240 val remove_function_attr : llvalue -> Attribute.t -> unit
1241
1242 (** {7 Operations on params} *)
1243
1244 (** [params f] returns the parameters of function [f].
1245     See the method [llvm::Function::getArgumentList]. *)
1246 val params : llvalue -> llvalue array
1247
1248 (** [param f n] returns the [n]th parameter of function [f].
1249     See the method [llvm::Function::getArgumentList]. *)
1250 val param : llvalue -> int -> llvalue
1251
1252 (** [param_parent p] returns the parent function that owns the parameter.
1253     See the method [llvm::Argument::getParent]. *)
1254 val param_parent : llvalue -> llvalue
1255
1256 (** [param_begin f] returns the first position in the parameter list of the
1257     function [f]. [param_begin] and [param_succ] can be used to iterate over
1258     the parameter list in order.
1259     See the method [llvm::Function::arg_begin]. *)
1260 val param_begin : llvalue -> (llvalue, llvalue) llpos
1261
1262 (** [param_succ bb] returns the parameter list position succeeding
1263     [Before bb].
1264     See the method [llvm::Function::arg_iterator::operator++]. *)
1265 val param_succ : llvalue -> (llvalue, llvalue) llpos
1266
1267 (** [iter_params f fn] applies function [f] to each of the parameters
1268     of function [fn] in order. Tail recursive. *)
1269 val iter_params : (llvalue -> unit) -> llvalue -> unit
1270
1271 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1272     [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1273 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1274
1275 (** [param_end f] returns the last position in the parameter list of
1276     the function [f]. [param_end] and [param_pred] can be used to iterate
1277     over the parameter list in reverse.
1278     See the method [llvm::Function::arg_end]. *)
1279 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1280
1281 (** [param_pred gv] returns the function list position preceding [After gv].
1282     See the method [llvm::Function::arg_iterator::operator--]. *)
1283 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1284
1285
1286 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1287     of function [fn] in reverse order. Tail recursive. *)
1288 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1289
1290 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1291     [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1292 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1293
1294 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1295 val add_param_attr : llvalue -> Attribute.t -> unit
1296
1297 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1298 val remove_param_attr : llvalue -> Attribute.t -> unit
1299
1300 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1301 val set_param_alignment : llvalue -> int -> unit
1302
1303
1304 (** {7 Operations on basic blocks} *)
1305
1306 (** [basic_blocks fn] returns the basic blocks of the function [f].
1307     See the method [llvm::Function::getBasicBlockList]. *)
1308 val basic_blocks : llvalue -> llbasicblock array
1309
1310 (** [entry_block fn] returns the entry basic block of the function [f].
1311     See the method [llvm::Function::getEntryBlock]. *)
1312 val entry_block : llvalue -> llbasicblock
1313
1314 (** [delete_block bb] deletes the basic block [bb].
1315     See the method [llvm::BasicBlock::eraseFromParent]. *)
1316 val delete_block : llbasicblock -> unit
1317
1318 (** [append_block c name f] creates a new basic block named [name] at the end of
1319     function [f] in the context [c].
1320     See the constructor of [llvm::BasicBlock]. *)
1321 val append_block : llcontext -> string -> llvalue -> llbasicblock
1322
1323
1324 (** [insert_block c name bb] creates a new basic block named [name] before the
1325     basic block [bb] in the context [c].
1326     See the constructor of [llvm::BasicBlock]. *)
1327 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1328
1329
1330 (** [block_parent bb] returns the parent function that owns the basic block.
1331     See the method [llvm::BasicBlock::getParent]. *)
1332 val block_parent : llbasicblock -> llvalue
1333
1334 (** [block_begin f] returns the first position in the basic block list of the
1335     function [f]. [block_begin] and [block_succ] can be used to iterate over
1336     the basic block list in order.
1337     See the method [llvm::Function::begin]. *)
1338 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1339
1340
1341 (** [block_succ bb] returns the basic block list position succeeding
1342     [Before bb].
1343     See the method [llvm::Function::iterator::operator++]. *)
1344 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1345
1346
1347 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1348     of function [fn] in order. Tail recursive. *)
1349 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1350
1351 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1352     [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1353 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1354
1355 (** [block_end f] returns the last position in the basic block list of
1356     the function [f]. [block_end] and [block_pred] can be used to iterate
1357     over the basic block list in reverse.
1358     See the method [llvm::Function::end]. *)
1359 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1360
1361
1362 (** [block_pred gv] returns the function list position preceding [After gv].
1363     See the method [llvm::Function::iterator::operator--]. *)
1364 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1365
1366
1367 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1368     of function [fn] in reverse order. Tail recursive. *)
1369 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1370
1371 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1372     [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1373 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1374
1375 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1376 val value_of_block : llbasicblock -> llvalue
1377
1378 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1379     [false] otherwise.
1380     Similar to [llvm::isa<BasicBlock>]. *)
1381 val value_is_block : llvalue -> bool
1382
1383 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1384 val block_of_value : llvalue -> llbasicblock
1385
1386
1387 (** {7 Operations on instructions} *)
1388
1389 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1390     See the method [llvm::Instruction::getParent]. *)
1391 val instr_parent : llvalue -> llbasicblock
1392
1393 (** [instr_begin bb] returns the first position in the instruction list of the
1394     basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1395     the instruction list in order.
1396     See the method [llvm::BasicBlock::begin]. *)
1397 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1398
1399
1400 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1401     See the method [llvm::BasicBlock::iterator::operator++]. *)
1402 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1403
1404
1405 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1406     block [bb] in order. Tail recursive. *)
1407 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1408
1409 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1410     [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1411 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1412
1413 (** [instr_end bb] returns the last position in the instruction list of the
1414     basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1415     the instruction list in reverse.
1416     See the method [llvm::BasicBlock::end]. *)
1417 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1418
1419
1420 (** [instr_pred i] returns the instruction list position preceding [After i].
1421     See the method [llvm::BasicBlock::iterator::operator--]. *)
1422 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1423
1424
1425 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1426     [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1427 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1428
1429
1430 (** {7 Operations on call sites} *)
1431
1432 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1433     instruction [ci], which may be one of the values from the module
1434     {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1435     [llvm::InvokeInst::getCallingConv]. *)
1436 val instruction_call_conv: llvalue -> int
1437
1438
1439 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1440     or invoke instruction [ci] to the integer [cc], which can be one of the
1441     values from the module {!CallConv}.
1442     See the method [llvm::CallInst::setCallingConv]
1443     and [llvm::InvokeInst::setCallingConv]. *)
1444 val set_instruction_call_conv: int -> llvalue -> unit
1445
1446
1447 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1448     parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1449     value. *)
1450 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1451
1452 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1453     [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1454     return value. *)
1455 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1456
1457 (** {Operations on call instructions (only)} *)
1458
1459 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1460     eligible for tail call optimization, [false] otherwise.
1461     See the method [llvm::CallInst::isTailCall]. *)
1462 val is_tail_call : llvalue -> bool
1463
1464 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1465     call optimization if [tc] is [true], clears otherwise.
1466     See the method [llvm::CallInst::setTailCall]. *)
1467 val set_tail_call : bool -> llvalue -> unit
1468
1469 (** {7 Operations on phi nodes} *)
1470
1471 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1472     with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1473 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1474
1475
1476 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1477     See the method [llvm::PHINode::getIncomingValue]. *)
1478 val incoming : llvalue -> (llvalue * llbasicblock) list
1479
1480
1481
1482 (** {6 Instruction builders} *)
1483
1484 (** [builder context] creates an instruction builder with no position in
1485     the context [context]. It is invalid to use this builder until its position
1486     is set with {!position_before} or {!position_at_end}. See the constructor
1487     for [llvm::LLVMBuilder]. *)
1488 val builder : llcontext -> llbuilder
1489
1490 (** [builder_at ip] creates an instruction builder positioned at [ip].
1491     See the constructor for [llvm::LLVMBuilder]. *)
1492 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1493
1494 (** [builder_before ins] creates an instruction builder positioned before the
1495     instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1496 val builder_before : llcontext -> llvalue -> llbuilder
1497
1498 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1499     the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1500 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1501
1502 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1503     [ip].
1504     See the constructor for [llvm::LLVMBuilder]. *)
1505 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1506
1507
1508 (** [position_before ins b] moves the instruction builder [b] to before the
1509     instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1510 val position_before : llvalue -> llbuilder -> unit
1511
1512 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1513     basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1514 val position_at_end : llbasicblock -> llbuilder -> unit
1515
1516 (** [insertion_block b] returns the basic block that the builder [b] is
1517     positioned to insert into. Raises [Not_Found] if the instruction builder is
1518     uninitialized.
1519     See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1520 val insertion_block : llbuilder -> llbasicblock
1521
1522 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1523     position specified by the instruction builder [b].
1524     See the method [llvm::LLVMBuilder::Insert]. *)
1525 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1526
1527
1528 (** {7 Metadata} *)
1529
1530 (** [set_current_debug_location b md] sets the current debug location [md] in
1531     the builder [b].
1532     See the method [llvm::IRBuilder::SetDebugLocation]. *)
1533 val set_current_debug_location : llbuilder -> llvalue -> unit
1534
1535
1536 (** [clear_current_debug_location b] clears the current debug location in the
1537     builder [b]. *)
1538 val clear_current_debug_location : llbuilder -> unit
1539
1540
1541 (** [current_debug_location b] returns the current debug location, or None
1542     if none is currently set.
1543     See the method [llvm::IRBuilder::GetDebugLocation]. *)
1544 val current_debug_location : llbuilder -> llvalue option
1545
1546
1547 (** [set_inst_debug_location b i] sets the current debug location of the builder
1548     [b] to the instruction [i].
1549     See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1550 val set_inst_debug_location : llbuilder -> llvalue -> unit
1551
1552
1553 (** {7 Terminators} *)
1554
1555 (** [build_ret_void b] creates a
1556     [ret void]
1557     instruction at the position specified by the instruction builder [b].
1558     See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1559 val build_ret_void : llbuilder -> llvalue
1560
1561 (** [build_ret v b] creates a
1562     [ret %v]
1563     instruction at the position specified by the instruction builder [b].
1564     See the method [llvm::LLVMBuilder::CreateRet]. *)
1565 val build_ret : llvalue -> llbuilder -> llvalue
1566
1567 (** [build_aggregate_ret vs b] creates a
1568     [ret {...} { %v1, %v2, ... } ]
1569     instruction at the position specified by the instruction builder [b].
1570     See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1571 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1572
1573
1574 (** [build_br bb b] creates a
1575     [br %bb]
1576     instruction at the position specified by the instruction builder [b].
1577     See the method [llvm::LLVMBuilder::CreateBr]. *)
1578 val build_br : llbasicblock -> llbuilder -> llvalue
1579
1580 (** [build_cond_br cond tbb fbb b] creates a
1581     [br %cond, %tbb, %fbb]
1582     instruction at the position specified by the instruction builder [b].
1583     See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1584 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1585                          llvalue
1586
1587 (** [build_switch case elsebb count b] creates an empty
1588     [switch %case, %elsebb]
1589     instruction at the position specified by the instruction builder [b] with
1590     space reserved for [count] cases.
1591     See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1592 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1593
1594
1595 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1596     when its input matches the constant [onval].
1597     See the method [llvm::SwitchInst::addCase]. **)
1598 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1599
1600
1601 (** [build_indirect_br addr count b] creates a
1602     [indirectbr %addr]
1603     instruction at the position specified by the instruction builder [b] with
1604     space reserved for [count] destinations.
1605     See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1606 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1607
1608
1609 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1610     location for the indirectbr instruction [br].
1611     See the method [llvm::IndirectBrInst::addDestination]. **)
1612 val add_destination : llvalue -> llbasicblock -> unit
1613
1614
1615 (** [build_invoke fn args tobb unwindbb name b] creates an
1616     [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1617     instruction at the position specified by the instruction builder [b].
1618     See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1619 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1620                         llbasicblock -> string -> llbuilder -> llvalue
1621
1622 (** [build_landingpad ty persfn numclauses name b] creates an
1623     [landingpad]
1624     instruction at the position specified by the instruction builder [b].
1625     See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
1626 val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
1627                          llvalue
1628
1629 (** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
1630     See the method [llvm::LandingPadInst::setCleanup]. *)
1631 val set_cleanup : llvalue -> bool -> unit
1632
1633 (** [build_unreachable b] creates an
1634     [unreachable]
1635     instruction at the position specified by the instruction builder [b].
1636     See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1637 val build_unreachable : llbuilder -> llvalue
1638
1639
1640 (** {7 Arithmetic} *)
1641
1642 (** [build_add x y name b] creates a
1643     [%name = add %x, %y]
1644     instruction at the position specified by the instruction builder [b].
1645     See the method [llvm::LLVMBuilder::CreateAdd]. *)
1646 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1647
1648
1649 (** [build_nsw_add x y name b] creates a
1650     [%name = nsw add %x, %y]
1651     instruction at the position specified by the instruction builder [b].
1652     See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1653 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1654
1655
1656 (** [build_nuw_add x y name b] creates a
1657     [%name = nuw add %x, %y]
1658     instruction at the position specified by the instruction builder [b].
1659     See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1660 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1661
1662
1663 (** [build_fadd x y name b] creates a
1664     [%name = fadd %x, %y]
1665     instruction at the position specified by the instruction builder [b].
1666     See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1667 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1668
1669
1670 (** [build_sub x y name b] creates a
1671     [%name = sub %x, %y]
1672     instruction at the position specified by the instruction builder [b].
1673     See the method [llvm::LLVMBuilder::CreateSub]. *)
1674 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1675
1676
1677 (** [build_nsw_sub x y name b] creates a
1678     [%name = nsw sub %x, %y]
1679     instruction at the position specified by the instruction builder [b].
1680     See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1681 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1682
1683
1684 (** [build_nuw_sub x y name b] creates a
1685     [%name = nuw sub %x, %y]
1686     instruction at the position specified by the instruction builder [b].
1687     See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1688 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1689
1690
1691 (** [build_fsub x y name b] creates a
1692     [%name = fsub %x, %y]
1693     instruction at the position specified by the instruction builder [b].
1694     See the method [llvm::LLVMBuilder::CreateFSub]. *)
1695 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1696
1697
1698 (** [build_mul x y name b] creates a
1699     [%name = mul %x, %y]
1700     instruction at the position specified by the instruction builder [b].
1701     See the method [llvm::LLVMBuilder::CreateMul]. *)
1702 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1703
1704
1705 (** [build_nsw_mul x y name b] creates a
1706     [%name = nsw mul %x, %y]
1707     instruction at the position specified by the instruction builder [b].
1708     See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1709 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1710
1711
1712 (** [build_nuw_mul x y name b] creates a
1713     [%name = nuw mul %x, %y]
1714     instruction at the position specified by the instruction builder [b].
1715     See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1716 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1717
1718
1719 (** [build_fmul x y name b] creates a
1720     [%name = fmul %x, %y]
1721     instruction at the position specified by the instruction builder [b].
1722     See the method [llvm::LLVMBuilder::CreateFMul]. *)
1723 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1724
1725
1726 (** [build_udiv x y name b] creates a
1727     [%name = udiv %x, %y]
1728     instruction at the position specified by the instruction builder [b].
1729     See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1730 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1731
1732
1733 (** [build_sdiv x y name b] creates a
1734     [%name = sdiv %x, %y]
1735     instruction at the position specified by the instruction builder [b].
1736     See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1737 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1738
1739
1740 (** [build_exact_sdiv x y name b] creates a
1741     [%name = exact sdiv %x, %y]
1742     instruction at the position specified by the instruction builder [b].
1743     See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1744 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1745
1746
1747 (** [build_fdiv x y name b] creates a
1748     [%name = fdiv %x, %y]
1749     instruction at the position specified by the instruction builder [b].
1750     See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1751 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1752
1753
1754 (** [build_urem x y name b] creates a
1755     [%name = urem %x, %y]
1756     instruction at the position specified by the instruction builder [b].
1757     See the method [llvm::LLVMBuilder::CreateURem]. *)
1758 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1759
1760
1761 (** [build_SRem x y name b] creates a
1762     [%name = srem %x, %y]
1763     instruction at the position specified by the instruction builder [b].
1764     See the method [llvm::LLVMBuilder::CreateSRem]. *)
1765 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1766
1767
1768 (** [build_frem x y name b] creates a
1769     [%name = frem %x, %y]
1770     instruction at the position specified by the instruction builder [b].
1771     See the method [llvm::LLVMBuilder::CreateFRem]. *)
1772 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1773
1774
1775 (** [build_shl x y name b] creates a
1776     [%name = shl %x, %y]
1777     instruction at the position specified by the instruction builder [b].
1778     See the method [llvm::LLVMBuilder::CreateShl]. *)
1779 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1780
1781
1782 (** [build_lshr x y name b] creates a
1783     [%name = lshr %x, %y]
1784     instruction at the position specified by the instruction builder [b].
1785     See the method [llvm::LLVMBuilder::CreateLShr]. *)
1786 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1787
1788
1789 (** [build_ashr x y name b] creates a
1790     [%name = ashr %x, %y]
1791     instruction at the position specified by the instruction builder [b].
1792     See the method [llvm::LLVMBuilder::CreateAShr]. *)
1793 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1794
1795
1796 (** [build_and x y name b] creates a
1797     [%name = and %x, %y]
1798     instruction at the position specified by the instruction builder [b].
1799     See the method [llvm::LLVMBuilder::CreateAnd]. *)
1800 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1801
1802
1803 (** [build_or x y name b] creates a
1804     [%name = or %x, %y]
1805     instruction at the position specified by the instruction builder [b].
1806     See the method [llvm::LLVMBuilder::CreateOr]. *)
1807 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1808
1809
1810 (** [build_xor x y name b] creates a
1811     [%name = xor %x, %y]
1812     instruction at the position specified by the instruction builder [b].
1813     See the method [llvm::LLVMBuilder::CreateXor]. *)
1814 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1815
1816
1817 (** [build_neg x name b] creates a
1818     [%name = sub 0, %x]
1819     instruction at the position specified by the instruction builder [b].
1820     [-0.0] is used for floating point types to compute the correct sign.
1821     See the method [llvm::LLVMBuilder::CreateNeg]. *)
1822 val build_neg : llvalue -> string -> llbuilder -> llvalue
1823
1824
1825 (** [build_nsw_neg x name b] creates a
1826     [%name = nsw sub 0, %x]
1827     instruction at the position specified by the instruction builder [b].
1828     [-0.0] is used for floating point types to compute the correct sign.
1829     See the method [llvm::LLVMBuilder::CreateNeg]. *)
1830 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1831
1832
1833 (** [build_nuw_neg x name b] creates a
1834     [%name = nuw sub 0, %x]
1835     instruction at the position specified by the instruction builder [b].
1836     [-0.0] is used for floating point types to compute the correct sign.
1837     See the method [llvm::LLVMBuilder::CreateNeg]. *)
1838 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1839
1840
1841 (** [build_fneg x name b] creates a
1842     [%name = fsub 0, %x]
1843     instruction at the position specified by the instruction builder [b].
1844     [-0.0] is used for floating point types to compute the correct sign.
1845     See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1846 val build_fneg : llvalue -> string -> llbuilder -> llvalue
1847
1848
1849 (** [build_xor x name b] creates a
1850     [%name = xor %x, -1]
1851     instruction at the position specified by the instruction builder [b].
1852     [-1] is the correct "all ones" value for the type of [x].
1853     See the method [llvm::LLVMBuilder::CreateXor]. *)
1854 val build_not : llvalue -> string -> llbuilder -> llvalue
1855
1856
1857
1858 (** {7 Memory} *)
1859
1860 (** [build_alloca ty name b] creates a
1861     [%name = alloca %ty]
1862     instruction at the position specified by the instruction builder [b].
1863     See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1864 val build_alloca : lltype -> string -> llbuilder -> llvalue
1865
1866
1867 (** [build_array_alloca ty n name b] creates a
1868     [%name = alloca %ty, %n]
1869     instruction at the position specified by the instruction builder [b].
1870     See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1871 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1872                               llvalue
1873
1874 (** [build_load v name b] creates a
1875     [%name = load %v]
1876     instruction at the position specified by the instruction builder [b].
1877     See the method [llvm::LLVMBuilder::CreateLoad]. *)
1878 val build_load : llvalue -> string -> llbuilder -> llvalue
1879
1880
1881 (** [build_store v p b] creates a
1882     [store %v, %p]
1883     instruction at the position specified by the instruction builder [b].
1884     See the method [llvm::LLVMBuilder::CreateStore]. *)
1885 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
1886
1887
1888 (** [build_gep p indices name b] creates a
1889     [%name = getelementptr %p, indices...]
1890     instruction at the position specified by the instruction builder [b].
1891     See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1892 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1893
1894
1895 (** [build_in_bounds_gep p indices name b] creates a
1896     [%name = gelementptr inbounds %p, indices...]
1897     instruction at the position specified by the instruction builder [b].
1898     See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1899 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1900                                llvalue
1901
1902 (** [build_struct_gep p idx name b] creates a
1903     [%name = getelementptr %p, 0, idx]
1904     instruction at the position specified by the instruction builder [b].
1905     See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1906 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
1907                             llvalue
1908
1909 (** [build_global_string str name b] creates a series of instructions that adds
1910     a global string at the position specified by the instruction builder [b].
1911     See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1912 val build_global_string : string -> string -> llbuilder -> llvalue
1913
1914
1915 (** [build_global_stringptr str name b] creates a series of instructions that
1916     adds a global string pointer at the position specified by the instruction
1917     builder [b].
1918     See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1919 val build_global_stringptr : string -> string -> llbuilder -> llvalue
1920
1921
1922
1923 (** {7 Casts} *)
1924
1925 (** [build_trunc v ty name b] creates a
1926     [%name = trunc %p to %ty]
1927     instruction at the position specified by the instruction builder [b].
1928     See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1929 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1930
1931
1932 (** [build_zext v ty name b] creates a
1933     [%name = zext %p to %ty]
1934     instruction at the position specified by the instruction builder [b].
1935     See the method [llvm::LLVMBuilder::CreateZExt]. *)
1936 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1937
1938
1939 (** [build_sext v ty name b] creates a
1940     [%name = sext %p to %ty]
1941     instruction at the position specified by the instruction builder [b].
1942     See the method [llvm::LLVMBuilder::CreateSExt]. *)
1943 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1944
1945
1946 (** [build_fptoui v ty name b] creates a
1947     [%name = fptoui %p to %ty]
1948     instruction at the position specified by the instruction builder [b].
1949     See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1950 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1951
1952
1953 (** [build_fptosi v ty name b] creates a
1954     [%name = fptosi %p to %ty]
1955     instruction at the position specified by the instruction builder [b].
1956     See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1957 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1958
1959
1960 (** [build_uitofp v ty name b] creates a
1961     [%name = uitofp %p to %ty]
1962     instruction at the position specified by the instruction builder [b].
1963     See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1964 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1965
1966
1967 (** [build_sitofp v ty name b] creates a
1968     [%name = sitofp %p to %ty]
1969     instruction at the position specified by the instruction builder [b].
1970     See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1971 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1972
1973
1974 (** [build_fptrunc v ty name b] creates a
1975     [%name = fptrunc %p to %ty]
1976     instruction at the position specified by the instruction builder [b].
1977     See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1978 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1979
1980
1981 (** [build_fpext v ty name b] creates a
1982     [%name = fpext %p to %ty]
1983     instruction at the position specified by the instruction builder [b].
1984     See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1985 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1986
1987
1988 (** [build_ptrtoint v ty name b] creates a
1989     [%name = prtotint %p to %ty]
1990     instruction at the position specified by the instruction builder [b].
1991     See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1992 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1993
1994
1995 (** [build_inttoptr v ty name b] creates a
1996     [%name = inttoptr %p to %ty]
1997     instruction at the position specified by the instruction builder [b].
1998     See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1999 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2000
2001
2002 (** [build_bitcast v ty name b] creates a
2003     [%name = bitcast %p to %ty]
2004     instruction at the position specified by the instruction builder [b].
2005     See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2006 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2007
2008
2009 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2010     instruction at the position specified by the instruction builder [b].
2011     See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2012 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2013                                  llvalue
2014
2015 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2016     instruction at the position specified by the instruction builder [b].
2017     See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2018 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2019                                  llvalue
2020
2021 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2022     instruction at the position specified by the instruction builder [b].
2023     See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2024 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2025                                   llvalue
2026
2027 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2028     instruction at the position specified by the instruction builder [b].
2029     See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2030 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2031
2032
2033 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2034     instruction at the position specified by the instruction builder [b].
2035     See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2036 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2037
2038
2039 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2040     instruction at the position specified by the instruction builder [b].
2041     See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2042 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2043
2044
2045
2046 (** {7 Comparisons} *)
2047
2048 (** [build_icmp pred x y name b] creates a
2049     [%name = icmp %pred %x, %y]
2050     instruction at the position specified by the instruction builder [b].
2051     See the method [llvm::LLVMBuilder::CreateICmp]. *)
2052 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2053                       llbuilder -> llvalue
2054
2055 (** [build_fcmp pred x y name b] creates a
2056     [%name = fcmp %pred %x, %y]
2057     instruction at the position specified by the instruction builder [b].
2058     See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2059 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2060                       llbuilder -> llvalue
2061
2062
2063 (** {7 Miscellaneous instructions} *)
2064
2065 (** [build_phi incoming name b] creates a
2066     [%name = phi %incoming]
2067     instruction at the position specified by the instruction builder [b].
2068     [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2069     See the method [llvm::LLVMBuilder::CreatePHI]. *)
2070 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2071                      llvalue
2072
2073 (** [build_call fn args name b] creates a
2074     [%name = call %fn(args...)]
2075     instruction at the position specified by the instruction builder [b].
2076     See the method [llvm::LLVMBuilder::CreateCall]. *)
2077 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2078
2079
2080 (** [build_select cond thenv elsev name b] creates a
2081     [%name = select %cond, %thenv, %elsev]
2082     instruction at the position specified by the instruction builder [b].
2083     See the method [llvm::LLVMBuilder::CreateSelect]. *)
2084 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2085                         llvalue
2086
2087 (** [build_va_arg valist argty name b] creates a
2088     [%name = va_arg %valist, %argty]
2089     instruction at the position specified by the instruction builder [b].
2090     See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2091 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2092
2093
2094 (** [build_extractelement vec i name b] creates a
2095     [%name = extractelement %vec, %i]
2096     instruction at the position specified by the instruction builder [b].
2097     See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2098 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2099                                 llvalue
2100
2101 (** [build_insertelement vec elt i name b] creates a
2102     [%name = insertelement %vec, %elt, %i]
2103     instruction at the position specified by the instruction builder [b].
2104     See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2105 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2106                                llbuilder -> llvalue
2107
2108 (** [build_shufflevector veca vecb mask name b] creates a
2109     [%name = shufflevector %veca, %vecb, %mask]
2110     instruction at the position specified by the instruction builder [b].
2111     See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2112 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2113                                llbuilder -> llvalue
2114
2115 (** [build_insertvalue agg idx name b] creates a
2116     [%name = extractvalue %agg, %idx]
2117     instruction at the position specified by the instruction builder [b].
2118     See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2119 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2120
2121
2122 (** [build_insertvalue agg val idx name b] creates a
2123     [%name = insertvalue %agg, %val, %idx]
2124     instruction at the position specified by the instruction builder [b].
2125     See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2126 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2127                              llvalue
2128
2129 (** [build_is_null val name b] creates a
2130     [%name = icmp eq %val, null]
2131     instruction at the position specified by the instruction builder [b].
2132     See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2133 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2134
2135
2136 (** [build_is_not_null val name b] creates a
2137     [%name = icmp ne %val, null]
2138     instruction at the position specified by the instruction builder [b].
2139     See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2140 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2141
2142
2143 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2144     the difference between two pointer values at the position specified by the
2145     instruction builder [b].
2146     See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2147 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2148
2149
2150
2151 (** {6 Memory buffers} *)
2152
2153 module MemoryBuffer : sig
2154   (** [of_file p] is the memory buffer containing the contents of the file at
2155       path [p]. If the file could not be read, then [IoError msg] is
2156       raised. *)
2157   val of_file : string -> llmemorybuffer
2158   
2159   (** [stdin ()] is the memory buffer containing the contents of standard input.
2160       If standard input is empty, then [IoError msg] is raised. *)
2161   val of_stdin : unit -> llmemorybuffer
2162   
2163   (** Disposes of a memory buffer. *)
2164   val dispose : llmemorybuffer -> unit
2165 end
2166
2167
2168 (** {6 Pass Managers} *)
2169
2170 module PassManager : sig
2171   (**  *)
2172   type 'a t
2173   type any = [ `Module | `Function ]
2174   
2175   (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2176       type of pipeline is suitable for link-time optimization and whole-module
2177       transformations.
2178       See the constructor of [llvm::PassManager]. *)
2179   val create : unit -> [ `Module ] t
2180   
2181   (** [PassManager.create_function m] constructs a new function-by-function
2182       pass pipeline over the module [m]. It does not take ownership of [m].
2183       This type of pipeline is suitable for code generation and JIT compilation
2184       tasks.
2185       See the constructor of [llvm::FunctionPassManager]. *)
2186   val create_function : llmodule -> [ `Function ] t
2187
2188   
2189   (** [run_module m pm] initializes, executes on the module [m], and finalizes
2190       all of the passes scheduled in the pass manager [pm]. Returns [true] if
2191       any of the passes modified the module, [false] otherwise.
2192       See the [llvm::PassManager::run] method. *)
2193   val run_module : llmodule -> [ `Module ] t -> bool
2194
2195   
2196   (** [initialize fpm] initializes all of the function passes scheduled in the
2197       function pass manager [fpm]. Returns [true] if any of the passes modified
2198       the module, [false] otherwise.
2199       See the [llvm::FunctionPassManager::doInitialization] method. *)
2200   val initialize : [ `Function ] t -> bool
2201   
2202   (** [run_function f fpm] executes all of the function passes scheduled in the
2203       function pass manager [fpm] over the function [f]. Returns [true] if any
2204       of the passes modified [f], [false] otherwise.
2205       See the [llvm::FunctionPassManager::run] method. *)
2206   val run_function : llvalue -> [ `Function ] t -> bool
2207
2208   
2209   (** [finalize fpm] finalizes all of the function passes scheduled in in the
2210       function pass manager [fpm]. Returns [true] if any of the passes
2211       modified the module, [false] otherwise.
2212       See the [llvm::FunctionPassManager::doFinalization] method. *)
2213   val finalize : [ `Function ] t -> bool
2214   
2215   (** Frees the memory of a pass pipeline. For function pipelines, does not free
2216       the module.
2217       See the destructor of [llvm::BasePassManager]. *)
2218   val dispose : [< any ] t -> unit
2219 end