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