llvm.mli revision 1b42cfd1ca03e48835e8e4c91c5dbb598030257f
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_float ty n] returns the floating point constant of type [ty] and
473    value [n]. See the method [llvm::ConstantFP::get]. *)
474external const_float : lltype -> float -> llvalue = "llvm_const_float"
475
476
477(** {7 Operations on composite constants} *)
478
479(** [const_string s] returns the constant [i8] array with the values of the
480    characters in the string [s]. The array is not null-terminated (but see
481    {!const_stringz}). This value can in turn be used as the initializer for a
482    global variable. See the method [llvm::ConstantArray::get]. *)
483external const_string : string -> llvalue = "llvm_const_string"
484
485(** [const_stringz s] returns the constant [i8] array with the values of the
486    characters in the string [s] and a null terminator. This value can in turn
487    be used as the initializer for a global variable.
488    See the method [llvm::ConstantArray::get]. *)
489external const_stringz : string -> llvalue = "llvm_const_stringz"
490
491(** [const_array ty elts] returns the constant array of type
492    [array_type ty (Array.length elts)] and containing the values [elts].
493    This value can in turn be used as the initializer for a global variable.
494    See the method [llvm::ConstantArray::get]. *)
495external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
496
497(** [const_struct elts] returns the structured constant of type
498    [struct_type (Array.map type_of elts)] and containing the values [elts].
499    This value can in turn be used as the initializer for a global variable.
500    See the method [llvm::ConstantStruct::get]. *)
501external const_struct : llvalue array -> llvalue = "llvm_const_struct"
502
503(** [const_packed_struct elts] returns the structured constant of type
504    {!packed_struct_type} [(Array.map type_of elts)] and containing the values
505    [elts]. This value can in turn be used as the initializer for a global
506    variable. See the method [llvm::ConstantStruct::get]. *)
507external const_packed_struct : llvalue array -> llvalue
508                             = "llvm_const_packed_struct"
509
510(** [const_vector elts] returns the vector constant of type
511    [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
512    values [elts]. See the method [llvm::ConstantVector::get]. *)
513external const_vector : llvalue array -> llvalue = "llvm_const_vector"
514
515
516(** {7 Constant expressions} *)
517
518(** [align_of ty] returns the alignof constant for the type [ty]. This is
519    equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
520    (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
521    more readable.  See the method [llvm::ConstantExpr::getAlignOf]. *)
522external align_of : lltype -> llvalue = "LLVMAlignOf"
523
524(** [size_of ty] returns the sizeof constant for the type [ty]. This is
525    equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
526    (const_int i32_type 1)) i64_type], but considerably more readable.
527    See the method [llvm::ConstantExpr::getSizeOf]. *)
528external size_of : lltype -> llvalue = "LLVMSizeOf"
529
530(** [const_neg c] returns the arithmetic negation of the constant [c].
531    See the method [llvm::ConstantExpr::getNeg]. *)
532external const_neg : llvalue -> llvalue = "LLVMConstNeg"
533
534(** [const_fneg c] returns the arithmetic negation of the constant float [c].
535    See the method [llvm::ConstantExpr::getFNeg]. *)
536external const_fneg : llvalue -> llvalue = "LLVMConstFNeg"
537
538(** [const_not c] returns the bitwise inverse of the constant [c].
539    See the method [llvm::ConstantExpr::getNot]. *)
540external const_not : llvalue -> llvalue = "LLVMConstNot"
541
542(** [const_add c1 c2] returns the constant sum of two constants.
543    See the method [llvm::ConstantExpr::getAdd]. *)
544external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
545
546(** [const_nsw_add c1 c2] returns the constant sum of two constants with no
547    signed wrapping. The result is undefined if the sum overflows.
548    See the method [llvm::ConstantExpr::getNSWAdd]. *)
549external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd"
550
551(** [const_fadd c1 c2] returns the constant sum of two constant floats.
552    See the method [llvm::ConstantExpr::getFAdd]. *)
553external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd"
554
555(** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
556    constants. See the method [llvm::ConstantExpr::getSub]. *)
557external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
558
559(** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
560    constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
561external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub"
562
563(** [const_mul c1 c2] returns the constant product of two constants.
564    See the method [llvm::ConstantExpr::getMul]. *)
565external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
566
567(** [const_fmul c1 c2] returns the constant product of two constants floats.
568    See the method [llvm::ConstantExpr::getFMul]. *)
569external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul"
570
571(** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
572    integer constants.
573    See the method [llvm::ConstantExpr::getUDiv]. *)
574external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
575
576(** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
577    integer constants.
578    See the method [llvm::ConstantExpr::getSDiv]. *)
579external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
580
581(** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
582    signed integer constants. The result is undefined if the result is rounded
583		or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
584external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv"
585
586(** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
587    point constants.
588    See the method [llvm::ConstantExpr::getFDiv]. *)
589external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
590
591(** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
592    unsigned integer constants.
593    See the method [llvm::ConstantExpr::getURem]. *)
594external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
595
596(** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
597    signed integer constants.
598    See the method [llvm::ConstantExpr::getSRem]. *)
599external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
600
601(** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
602    signed floating point constants.
603    See the method [llvm::ConstantExpr::getFRem]. *)
604external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
605
606(** [const_and c1 c2] returns the constant bitwise [AND] of two integer
607    constants.
608    See the method [llvm::ConstantExpr::getAnd]. *)
609external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
610
611(** [const_or c1 c2] returns the constant bitwise [OR] of two integer
612    constants.
613    See the method [llvm::ConstantExpr::getOr]. *)
614external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
615
616(** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
617    constants.
618    See the method [llvm::ConstantExpr::getXor]. *)
619external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
620
621(** [const_icmp pred c1 c2] returns the constant comparison of two integer
622    constants, [c1 pred c2].
623    See the method [llvm::ConstantExpr::getICmp]. *)
624external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
625                    = "llvm_const_icmp"
626
627(** [const_fcmp pred c1 c2] returns the constant comparison of two floating
628    point constants, [c1 pred c2].
629    See the method [llvm::ConstantExpr::getFCmp]. *)
630external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
631                    = "llvm_const_fcmp"
632
633(** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
634    constant integer [c2].
635    See the method [llvm::ConstantExpr::getShl]. *)
636external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
637
638(** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
639    constant integer [c2] with zero extension.
640    See the method [llvm::ConstantExpr::getLShr]. *)
641external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
642
643(** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
644    constant integer [c2] with sign extension.
645    See the method [llvm::ConstantExpr::getAShr]. *)
646external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
647
648(** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
649    constant integers indices from the array [indices].
650    See the method [llvm::ConstantExpr::getGetElementPtr]. *)
651external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
652
653(** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
654    with the constant integers indices from the array [indices].
655    See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
656external const_in_bounds_gep : llvalue -> llvalue array -> llvalue
657                            = "llvm_const_in_bounds_gep"
658
659(** [const_trunc c ty] returns the constant truncation of integer constant [c]
660    to the smaller integer type [ty].
661    See the method [llvm::ConstantExpr::getTrunc]. *)
662external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
663
664(** [const_sext c ty] returns the constant sign extension of integer constant
665    [c] to the larger integer type [ty].
666    See the method [llvm::ConstantExpr::getSExt]. *)
667external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
668
669(** [const_zext c ty] returns the constant zero extension of integer constant
670    [c] to the larger integer type [ty].
671    See the method [llvm::ConstantExpr::getZExt]. *)
672external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
673
674(** [const_fptrunc c ty] returns the constant truncation of floating point
675    constant [c] to the smaller floating point type [ty].
676    See the method [llvm::ConstantExpr::getFPTrunc]. *)
677external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
678
679(** [const_fpext c ty] returns the constant extension of floating point constant
680    [c] to the larger floating point type [ty].
681    See the method [llvm::ConstantExpr::getFPExt]. *)
682external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
683
684(** [const_uitofp c ty] returns the constant floating point conversion of
685    unsigned integer constant [c] to the floating point type [ty].
686    See the method [llvm::ConstantExpr::getUIToFP]. *)
687external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
688
689(** [const_sitofp c ty] returns the constant floating point conversion of
690    signed integer constant [c] to the floating point type [ty].
691    See the method [llvm::ConstantExpr::getSIToFP]. *)
692external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
693
694(** [const_fptoui c ty] returns the constant unsigned integer conversion of
695    floating point constant [c] to integer type [ty].
696    See the method [llvm::ConstantExpr::getFPToUI]. *)
697external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
698
699(** [const_fptoui c ty] returns the constant unsigned integer conversion of
700    floating point constant [c] to integer type [ty].
701    See the method [llvm::ConstantExpr::getFPToSI]. *)
702external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
703
704(** [const_ptrtoint c ty] returns the constant integer conversion of
705    pointer constant [c] to integer type [ty].
706    See the method [llvm::ConstantExpr::getPtrToInt]. *)
707external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
708
709(** [const_inttoptr c ty] returns the constant pointer conversion of
710    integer constant [c] to pointer type [ty].
711    See the method [llvm::ConstantExpr::getIntToPtr]. *)
712external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
713
714(** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
715    to type [ty] of equal size.
716    See the method [llvm::ConstantExpr::getBitCast]. *)
717external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
718
719(** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
720    conversion of constant [c] to type [ty].
721    See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
722external const_zext_or_bitcast : llvalue -> lltype -> llvalue
723                               = "LLVMConstZExtOrBitCast"
724
725(** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
726    conversion of constant [c] to type [ty].
727    See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
728external const_sext_or_bitcast : llvalue -> lltype -> llvalue
729                               = "LLVMConstSExtOrBitCast"
730
731(** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
732    conversion of constant [c] to type [ty].
733    See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
734external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
735                                = "LLVMConstTruncOrBitCast"
736
737(** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
738    cast conversion of constant [c] to type [ty] of equal size.
739    See the method [llvm::ConstantExpr::getPointerCast]. *)
740external const_pointercast : llvalue -> lltype -> llvalue
741                           = "LLVMConstPointerCast"
742
743(** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
744    -> integer casts of constant [c] to type [ty].
745    See the method [llvm::ConstantExpr::getIntCast]. *)
746external const_intcast : llvalue -> lltype -> llvalue
747                       = "LLVMConstIntCast"
748
749(** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
750	  fp casts of constant [c] to type [ty].
751    See the method [llvm::ConstantExpr::getFPCast]. *)
752external const_fpcast : llvalue -> lltype -> llvalue
753                      = "LLVMConstFPCast"
754
755(** [const_select cond t f] returns the constant conditional which returns value
756    [t] if the boolean constant [cond] is true and the value [f] otherwise.
757    See the method [llvm::ConstantExpr::getSelect]. *)
758external const_select : llvalue -> llvalue -> llvalue -> llvalue
759                      = "LLVMConstSelect"
760
761(** [const_extractelement vec i] returns the constant [i]th element of
762    constant vector [vec]. [i] must be a constant [i32] value unsigned less than
763    the size of the vector.
764    See the method [llvm::ConstantExpr::getExtractElement]. *)
765external const_extractelement : llvalue -> llvalue -> llvalue
766                              = "LLVMConstExtractElement"
767
768(** [const_insertelement vec v i] returns the constant vector with the same
769    elements as constant vector [v] but the [i]th element replaced by the
770    constant [v]. [v] must be a constant value with the type of the vector
771    elements. [i] must be a constant [i32] value unsigned less than the size
772    of the vector.
773    See the method [llvm::ConstantExpr::getInsertElement]. *)
774external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
775                             = "LLVMConstInsertElement"
776
777(** [const_shufflevector a b mask] returns a constant [shufflevector].
778    See the LLVM Language Reference for details on the [sufflevector]
779    instruction.
780    See the method [llvm::ConstantExpr::getShuffleVector]. *)
781external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
782                             = "LLVMConstShuffleVector"
783
784(** [const_extractvalue agg idxs] returns the constant [idxs]th value of
785    constant aggregate [agg]. Each [idxs] must be less than the size of the
786    aggregate.  See the method [llvm::ConstantExpr::getExtractValue]. *)
787external const_extractvalue : llvalue -> int array -> llvalue
788                            = "llvm_const_extractvalue"
789
790(** [const_insertvalue agg val idxs] inserts the value [val] in the specified
791    indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
792    of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
793external const_insertvalue : llvalue -> llvalue -> int array -> llvalue
794                           = "llvm_const_insertvalue"
795
796
797(** {7 Operations on global variables, functions, and aliases (globals)} *)
798
799(** [global_parent g] is the enclosing module of the global value [g].
800    See the method [llvm::GlobalValue::getParent]. *)
801external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
802
803(** [is_declaration g] returns [true] if the global value [g] is a declaration
804    only. Returns [false] otherwise.
805    See the method [llvm::GlobalValue::isDeclaration]. *)
806external is_declaration : llvalue -> bool = "llvm_is_declaration"
807
808(** [linkage g] returns the linkage of the global value [g].
809    See the method [llvm::GlobalValue::getLinkage]. *)
810external linkage : llvalue -> Linkage.t = "llvm_linkage"
811
812(** [set_linkage l g] sets the linkage of the global value [g] to [l].
813    See the method [llvm::GlobalValue::setLinkage]. *)
814external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
815
816(** [section g] returns the linker section of the global value [g].
817    See the method [llvm::GlobalValue::getSection]. *)
818external section : llvalue -> string = "llvm_section"
819
820(** [set_section s g] sets the linker section of the global value [g] to [s].
821    See the method [llvm::GlobalValue::setSection]. *)
822external set_section : string -> llvalue -> unit = "llvm_set_section"
823
824(** [visibility g] returns the linker visibility of the global value [g].
825    See the method [llvm::GlobalValue::getVisibility]. *)
826external visibility : llvalue -> Visibility.t = "llvm_visibility"
827
828(** [set_visibility v g] sets the linker visibility of the global value [g] to
829    [v]. See the method [llvm::GlobalValue::setVisibility]. *)
830external set_visibility : Visibility.t -> llvalue -> unit
831                        = "llvm_set_visibility"
832
833(** [alignment g] returns the required alignment of the global value [g].
834    See the method [llvm::GlobalValue::getAlignment]. *)
835external alignment : llvalue -> int = "llvm_alignment"
836
837(** [set_alignment n g] sets the required alignment of the global value [g] to
838    [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
839external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
840
841
842(** {7 Operations on global variables} *)
843
844(** [declare_global ty name m] returns a new global variable of type [ty] and
845    with name [name] in module [m]. If such a global variable already exists,
846    it is returned. If the type of the existing global differs, then a bitcast
847    to [ty] is returned. *)
848external declare_global : lltype -> string -> llmodule -> llvalue
849                        = "llvm_declare_global"
850
851(** [define_global name init m] returns a new global with name [name] and
852    initializer [init] in module [m]. If the named global already exists, it is
853    renamed.
854    See the constructor of [llvm::GlobalVariable]. *)
855external define_global : string -> llvalue -> llmodule -> llvalue
856                       = "llvm_define_global"
857
858(** [lookup_global name m] returns [Some g] if a global variable with name
859    [name] exists in module [m]. If no such global exists, returns [None].
860    See the [llvm::GlobalVariable] constructor. *)
861external lookup_global : string -> llmodule -> llvalue option
862                       = "llvm_lookup_global"
863
864(** [delete_global gv] destroys the global variable [gv].
865    See the method [llvm::GlobalVariable::eraseFromParent]. *)
866external delete_global : llvalue -> unit = "llvm_delete_global"
867
868(** [global_begin m] returns the first position in the global variable list of
869    the module [m]. [global_begin] and [global_succ] can be used to iterate
870    over the global list in order.
871    See the method [llvm::Module::global_begin]. *)
872external global_begin : llmodule -> (llmodule, llvalue) llpos
873                      = "llvm_global_begin"
874
875(** [global_succ gv] returns the global variable list position succeeding
876    [Before gv].
877    See the method [llvm::Module::global_iterator::operator++]. *)
878external global_succ : llvalue -> (llmodule, llvalue) llpos
879                     = "llvm_global_succ"
880
881(** [iter_globals f m] applies function [f] to each of the global variables of
882    module [m] in order. Tail recursive. *)
883val iter_globals : (llvalue -> unit) -> llmodule -> unit
884
885(** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
886    [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
887val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
888
889(** [global_end m] returns the last position in the global variable list of the
890    module [m]. [global_end] and [global_pred] can be used to iterate over the
891    global list in reverse.
892    See the method [llvm::Module::global_end]. *)
893external global_end : llmodule -> (llmodule, llvalue) llrev_pos
894                    = "llvm_global_end"
895
896(** [global_pred gv] returns the global variable list position preceding
897    [After gv].
898    See the method [llvm::Module::global_iterator::operator--]. *)
899external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
900                     = "llvm_global_pred"
901
902(** [rev_iter_globals f m] applies function [f] to each of the global variables
903    of module [m] in reverse order. Tail recursive. *)
904val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
905
906(** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
907    [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
908val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
909
910(** [is_global_constant gv] returns [true] if the global variabile [gv] is a
911    constant. Returns [false] otherwise.
912    See the method [llvm::GlobalVariable::isConstant]. *)
913external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
914
915(** [set_global_constant c gv] sets the global variable [gv] to be a constant if
916    [c] is [true] and not if [c] is [false].
917    See the method [llvm::GlobalVariable::setConstant]. *)
918external set_global_constant : bool -> llvalue -> unit
919                             = "llvm_set_global_constant"
920
921(** [global_initializer gv] returns the initializer for the global variable
922    [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
923external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
924
925(** [set_initializer c gv] sets the initializer for the global variable
926    [gv] to the constant [c].
927    See the method [llvm::GlobalVariable::setInitializer]. *)
928external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
929
930(** [remove_initializer gv] unsets the initializer for the global variable
931    [gv].
932    See the method [llvm::GlobalVariable::setInitializer]. *)
933external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
934
935(** [is_thread_local gv] returns [true] if the global variable [gv] is
936    thread-local and [false] otherwise.
937    See the method [llvm::GlobalVariable::isThreadLocal]. *)
938external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
939
940(** [set_thread_local c gv] sets the global variable [gv] to be thread local if
941    [c] is [true] and not otherwise.
942    See the method [llvm::GlobalVariable::setThreadLocal]. *)
943external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
944
945
946(** {7 Operations on functions} *)
947
948(** [declare_function name ty m] returns a new function of type [ty] and
949    with name [name] in module [m]. If such a function already exists,
950    it is returned. If the type of the existing function differs, then a bitcast
951    to [ty] is returned. *)
952external declare_function : string -> lltype -> llmodule -> llvalue
953                          = "llvm_declare_function"
954
955(** [define_function name ty m] creates a new function with name [name] and
956    type [ty] in module [m]. If the named function already exists, it is
957    renamed. An entry basic block is created in the function.
958    See the constructor of [llvm::GlobalVariable]. *)
959external define_function : string -> lltype -> llmodule -> llvalue
960                         = "llvm_define_function"
961
962(** [lookup_function name m] returns [Some f] if a function with name
963    [name] exists in module [m]. If no such function exists, returns [None].
964    See the method [llvm::Module] constructor. *)
965external lookup_function : string -> llmodule -> llvalue option
966                         = "llvm_lookup_function"
967
968(** [delete_function f] destroys the function [f].
969    See the method [llvm::Function::eraseFromParent]. *)
970external delete_function : llvalue -> unit = "llvm_delete_function"
971
972(** [function_begin m] returns the first position in the function list of the
973    module [m]. [function_begin] and [function_succ] can be used to iterate over
974    the function list in order.
975    See the method [llvm::Module::begin]. *)
976external function_begin : llmodule -> (llmodule, llvalue) llpos
977                        = "llvm_function_begin"
978
979(** [function_succ gv] returns the function list position succeeding
980    [Before gv].
981    See the method [llvm::Module::iterator::operator++]. *)
982external function_succ : llvalue -> (llmodule, llvalue) llpos
983                       = "llvm_function_succ"
984
985(** [iter_functions f m] applies function [f] to each of the functions of module
986    [m] in order. Tail recursive. *)
987val iter_functions : (llvalue -> unit) -> llmodule -> unit
988
989(** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
990    [f1,...,fN] are the functions of module [m]. Tail recursive. *)
991val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
992
993(** [function_end m] returns the last position in the function list of
994    the module [m]. [function_end] and [function_pred] can be used to iterate
995    over the function list in reverse.
996    See the method [llvm::Module::end]. *)
997external function_end : llmodule -> (llmodule, llvalue) llrev_pos
998                      = "llvm_function_end"
999
1000(** [function_pred gv] returns the function list position preceding [After gv].
1001    See the method [llvm::Module::iterator::operator--]. *)
1002external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1003                       = "llvm_function_pred"
1004
1005(** [rev_iter_functions f fn] applies function [f] to each of the functions of
1006    module [m] in reverse order. Tail recursive. *)
1007val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1008
1009(** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1010    [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1011val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1012
1013(** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1014    See the method [llvm::Function::isIntrinsic]. *)
1015external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
1016
1017(** [function_call_conv f] returns the calling convention of the function [f].
1018    See the method [llvm::Function::getCallingConv]. *)
1019external function_call_conv : llvalue -> int = "llvm_function_call_conv"
1020
1021(** [set_function_call_conv cc f] sets the calling convention of the function
1022    [f] to the calling convention numbered [cc].
1023    See the method [llvm::Function::setCallingConv]. *)
1024external set_function_call_conv : int -> llvalue -> unit
1025                                = "llvm_set_function_call_conv"
1026
1027(** [gc f] returns [Some name] if the function [f] has a garbage
1028    collection algorithm specified and [None] otherwise.
1029    See the method [llvm::Function::getGC]. *)
1030external gc : llvalue -> string option = "llvm_gc"
1031
1032(** [set_gc gc f] sets the collection algorithm for the function [f] to
1033    [gc]. See the method [llvm::Function::setGC]. *)
1034external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
1035
1036(** [add_function_attr f a] adds attribute [a] to the return type of function
1037    [f]. *)
1038external add_function_attr : llvalue -> Attribute.t -> unit
1039                           = "llvm_add_function_attr"
1040
1041(** [remove_function_attr f a] removes attribute [a] from the return type of
1042    function [f]. *)
1043external remove_function_attr : llvalue -> Attribute.t -> unit
1044                              = "llvm_remove_function_attr"
1045
1046(** {7 Operations on params} *)
1047
1048(** [params f] returns the parameters of function [f].
1049    See the method [llvm::Function::getArgumentList]. *)
1050external params : llvalue -> llvalue array = "llvm_params"
1051
1052(** [param f n] returns the [n]th parameter of function [f].
1053    See the method [llvm::Function::getArgumentList]. *)
1054external param : llvalue -> int -> llvalue = "llvm_param"
1055
1056(** [param_parent p] returns the parent function that owns the parameter.
1057    See the method [llvm::Argument::getParent]. *)
1058external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
1059
1060(** [param_begin f] returns the first position in the parameter list of the
1061    function [f]. [param_begin] and [param_succ] can be used to iterate over
1062    the parameter list in order.
1063    See the method [llvm::Function::arg_begin]. *)
1064external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
1065
1066(** [param_succ bb] returns the parameter list position succeeding
1067    [Before bb].
1068    See the method [llvm::Function::arg_iterator::operator++]. *)
1069external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
1070
1071(** [iter_params f fn] applies function [f] to each of the parameters
1072    of function [fn] in order. Tail recursive. *)
1073val iter_params : (llvalue -> unit) -> llvalue -> unit
1074
1075(** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1076    [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1077val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1078
1079(** [param_end f] returns the last position in the parameter list of
1080    the function [f]. [param_end] and [param_pred] can be used to iterate
1081    over the parameter list in reverse.
1082    See the method [llvm::Function::arg_end]. *)
1083external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
1084
1085(** [param_pred gv] returns the function list position preceding [After gv].
1086    See the method [llvm::Function::arg_iterator::operator--]. *)
1087external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1088                    = "llvm_param_pred"
1089
1090(** [rev_iter_params f fn] applies function [f] to each of the parameters
1091    of function [fn] in reverse order. Tail recursive. *)
1092val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1093
1094(** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1095    [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1096val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1097
1098(** [add_param p a] adds attribute [a] to parameter [p]. *)
1099external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1100
1101(** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1102external remove_param_attr : llvalue -> Attribute.t -> unit
1103                           = "llvm_remove_param_attr"
1104
1105(** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1106external set_param_alignment : llvalue -> int -> unit
1107                             = "llvm_set_param_alignment"
1108
1109(** {7 Operations on basic blocks} *)
1110
1111(** [basic_blocks fn] returns the basic blocks of the function [f].
1112    See the method [llvm::Function::getBasicBlockList]. *)
1113external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
1114
1115(** [entry_block fn] returns the entry basic block of the function [f].
1116    See the method [llvm::Function::getEntryBlock]. *)
1117external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1118
1119(** [delete_block bb] deletes the basic block [bb].
1120    See the method [llvm::BasicBlock::eraseFromParent]. *)
1121external delete_block : llbasicblock -> unit = "llvm_delete_block"
1122
1123(** [append_block name f] creates a new basic block named [name] at the end of
1124    function [f].
1125    See the constructor of [llvm::BasicBlock]. *)
1126external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
1127
1128(** [insert_block name bb] creates a new basic block named [name] before the
1129    basic block [bb].
1130    See the constructor of [llvm::BasicBlock]. *)
1131external insert_block : string -> llbasicblock -> llbasicblock
1132                      = "llvm_insert_block"
1133
1134(** [block_parent bb] returns the parent function that owns the basic block.
1135    See the method [llvm::BasicBlock::getParent]. *)
1136external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1137
1138(** [block_begin f] returns the first position in the basic block list of the
1139    function [f]. [block_begin] and [block_succ] can be used to iterate over
1140    the basic block list in order.
1141    See the method [llvm::Function::begin]. *)
1142external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1143                     = "llvm_block_begin"
1144
1145(** [block_succ bb] returns the basic block list position succeeding
1146    [Before bb].
1147    See the method [llvm::Function::iterator::operator++]. *)
1148external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1149                    = "llvm_block_succ"
1150
1151(** [iter_blocks f fn] applies function [f] to each of the basic blocks
1152    of function [fn] in order. Tail recursive. *)
1153val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1154
1155(** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1156    [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1157val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1158
1159(** [block_end f] returns the last position in the basic block list of
1160    the function [f]. [block_end] and [block_pred] can be used to iterate
1161    over the basic block list in reverse.
1162    See the method [llvm::Function::end]. *)
1163external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1164                   = "llvm_block_end"
1165
1166(** [block_pred gv] returns the function list position preceding [After gv].
1167    See the method [llvm::Function::iterator::operator--]. *)
1168external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1169                    = "llvm_block_pred"
1170
1171(** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1172    of function [fn] in reverse order. Tail recursive. *)
1173val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1174
1175(** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1176    [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1177val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1178
1179(** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1180external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1181
1182(** [value_is_block v] returns [true] if the value [v] is a basic block and
1183    [false] otherwise.
1184    Similar to [llvm::isa<BasicBlock>]. *)
1185external value_is_block : llvalue -> bool = "llvm_value_is_block"
1186
1187(** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1188external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1189
1190
1191(** {7 Operations on instructions} *)
1192
1193(** [instr_parent i] is the enclosing basic block of the instruction [i].
1194    See the method [llvm::Instruction::getParent]. *)
1195external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1196
1197(** [instr_begin bb] returns the first position in the instruction list of the
1198    basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1199    the instruction list in order.
1200    See the method [llvm::BasicBlock::begin]. *)
1201external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1202                     = "llvm_instr_begin"
1203
1204(** [instr_succ i] returns the instruction list position succeeding [Before i].
1205    See the method [llvm::BasicBlock::iterator::operator++]. *)
1206external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1207                     = "llvm_instr_succ"
1208
1209(** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1210    block [bb] in order. Tail recursive. *)
1211val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1212
1213(** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1214    [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1215val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1216
1217(** [instr_end bb] returns the last position in the instruction list of the
1218    basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1219    the instruction list in reverse.
1220    See the method [llvm::BasicBlock::end]. *)
1221external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1222                     = "llvm_instr_end"
1223
1224(** [instr_pred i] returns the instruction list position preceding [After i].
1225    See the method [llvm::BasicBlock::iterator::operator--]. *)
1226external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1227                     = "llvm_instr_pred"
1228
1229(** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1230    [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1231val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1232
1233
1234(** {7 Operations on call sites} *)
1235
1236(** [instruction_call_conv ci] is the calling convention for the call or invoke
1237    instruction [ci], which may be one of the values from the module
1238    {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1239    [llvm::InvokeInst::getCallingConv]. *)
1240external instruction_call_conv: llvalue -> int
1241                              = "llvm_instruction_call_conv"
1242
1243(** [set_instruction_call_conv cc ci] sets the calling convention for the call
1244    or invoke instruction [ci] to the integer [cc], which can be one of the
1245    values from the module {!CallConv}.
1246    See the method [llvm::CallInst::setCallingConv]
1247    and [llvm::InvokeInst::setCallingConv]. *)
1248external set_instruction_call_conv: int -> llvalue -> unit
1249                                  = "llvm_set_instruction_call_conv"
1250
1251(** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1252    parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1253    value. *)
1254external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1255  = "llvm_add_instruction_param_attr"
1256
1257(** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1258    [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1259    return value. *)
1260external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1261  = "llvm_remove_instruction_param_attr"
1262
1263(** {Operations on call instructions (only)} *)
1264
1265(** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1266    eligible for tail call optimization, [false] otherwise.
1267    See the method [llvm::CallInst::isTailCall]. *)
1268external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
1269
1270(** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1271    call optimization if [tc] is [true], clears otherwise.
1272    See the method [llvm::CallInst::setTailCall]. *)
1273external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call"
1274
1275(** {7 Operations on phi nodes} *)
1276
1277(** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1278    with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1279external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1280                      = "llvm_add_incoming"
1281
1282(** [incoming pn] returns the list of value-block pairs for phi node [pn].
1283    See the method [llvm::PHINode::getIncomingValue]. *)
1284external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1285
1286
1287
1288(** {6 Instruction builders} *)
1289
1290(** [builder ()] creates an instruction builder with no position. It is invalid
1291    to use this builder until its position is set with {!position_before} or
1292    {!position_at_end}. See the constructor for [llvm::LLVMBuilder]. *)
1293external builder : unit -> llbuilder = "llvm_builder"
1294
1295(** [builder_at ip] creates an instruction builder positioned at [ip].
1296    See the constructor for [llvm::LLVMBuilder]. *)
1297val builder_at : (llbasicblock, llvalue) llpos -> llbuilder
1298
1299(** [builder_before ins] creates an instruction builder positioned before the
1300    instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1301val builder_before : llvalue -> llbuilder
1302
1303(** [builder_at_end bb] creates an instruction builder positioned at the end of
1304    the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1305val builder_at_end : llbasicblock -> llbuilder
1306
1307(** [position_builder ip bb] moves the instruction builder [bb] to the position
1308    [ip].
1309    See the constructor for [llvm::LLVMBuilder]. *)
1310external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1311                          = "llvm_position_builder"
1312
1313(** [position_before ins b] moves the instruction builder [b] to before the
1314    instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1315val position_before : llvalue -> llbuilder -> unit
1316
1317(** [position_at_end bb b] moves the instruction builder [b] to the end of the
1318    basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1319val position_at_end : llbasicblock -> llbuilder -> unit
1320
1321(** [insertion_block b] returns the basic block that the builder [b] is
1322    positioned to insert into. Raises [Not_Found] if the instruction builder is
1323    uninitialized.
1324    See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1325external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1326
1327
1328(** {7 Terminators} *)
1329
1330(** [build_ret_void b] creates a
1331    [ret void]
1332    instruction at the position specified by the instruction builder [b].
1333    See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1334external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1335
1336(** [build_ret v b] creates a
1337    [ret %v]
1338    instruction at the position specified by the instruction builder [b].
1339    See the method [llvm::LLVMBuilder::CreateRet]. *)
1340external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1341
1342(** [build_aggregate_ret vs b] creates a
1343    [ret {...} { %v1, %v2, ... } ]
1344    instruction at the position specified by the instruction builder [b].
1345    See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1346external build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1347                             = "llvm_build_aggregate_ret"
1348
1349(** [build_br bb b] creates a
1350    [b %bb]
1351    instruction at the position specified by the instruction builder [b].
1352    See the method [llvm::LLVMBuilder::CreateBr]. *)
1353external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1354
1355(** [build_cond_br cond tbb fbb b] creates a
1356    [b %cond, %tbb, %fbb]
1357    instruction at the position specified by the instruction builder [b].
1358    See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1359external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1360                         llvalue = "llvm_build_cond_br"
1361
1362(** [build_switch case elsebb count b] creates an empty
1363    [switch %case, %elsebb]
1364    instruction at the position specified by the instruction builder [b] with
1365    space reserved for [count] cases.
1366    See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1367external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1368                      = "llvm_build_switch"
1369
1370(** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1371    when its input matches the constant [onval].
1372    See the method [llvm::SwitchInst::addCase]. **)
1373external add_case : llvalue -> llvalue -> llbasicblock -> unit
1374                  = "llvm_add_case"
1375
1376(** [build_invoke fn args tobb unwindbb name b] creates an
1377    [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1378    instruction at the position specified by the instruction builder [b].
1379    See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1380external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1381                        llbasicblock -> string -> llbuilder -> llvalue
1382                      = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1383
1384(** [build_unwind b] creates an
1385    [unwind]
1386    instruction at the position specified by the instruction builder [b].
1387    See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1388external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1389
1390(** [build_unreachable b] creates an
1391    [unreachable]
1392    instruction at the position specified by the instruction builder [b].
1393    See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1394external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1395
1396
1397(** {7 Arithmetic} *)
1398
1399(** [build_add x y name b] creates a
1400    [%name = add %x, %y]
1401    instruction at the position specified by the instruction builder [b].
1402    See the method [llvm::LLVMBuilder::CreateAdd]. *)
1403external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1404                   = "llvm_build_add"
1405
1406(** [build_nswadd x y name b] creates a
1407    [%name = nsw add %x, %y]
1408    instruction at the position specified by the instruction builder [b].
1409    See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1410external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1411                      = "llvm_build_nsw_add"
1412
1413(** [build_fadd x y name b] creates a
1414    [%name = fadd %x, %y]
1415    instruction at the position specified by the instruction builder [b].
1416    See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1417external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1418                    = "llvm_build_fadd"
1419
1420(** [build_sub x y name b] creates a
1421    [%name = sub %x, %y]
1422    instruction at the position specified by the instruction builder [b].
1423    See the method [llvm::LLVMBuilder::CreateSub]. *)
1424external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1425                   = "llvm_build_sub"
1426
1427(** [build_fsub x y name b] creates a
1428    [%name = fsub %x, %y]
1429    instruction at the position specified by the instruction builder [b].
1430    See the method [llvm::LLVMBuilder::CreateFSub]. *)
1431external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1432                    = "llvm_build_fsub"
1433
1434(** [build_mul x y name b] creates a
1435    [%name = mul %x, %y]
1436    instruction at the position specified by the instruction builder [b].
1437    See the method [llvm::LLVMBuilder::CreateMul]. *)
1438external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1439                   = "llvm_build_mul"
1440
1441(** [build_fmul x y name b] creates a
1442    [%name = fmul %x, %y]
1443    instruction at the position specified by the instruction builder [b].
1444    See the method [llvm::LLVMBuilder::CreateFMul]. *)
1445external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1446                    = "llvm_build_fmul"
1447
1448(** [build_udiv x y name b] creates a
1449    [%name = udiv %x, %y]
1450    instruction at the position specified by the instruction builder [b].
1451    See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1452external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1453                    = "llvm_build_udiv"
1454
1455(** [build_sdiv x y name b] creates a
1456    [%name = sdiv %x, %y]
1457    instruction at the position specified by the instruction builder [b].
1458    See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1459external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1460                    = "llvm_build_sdiv"
1461
1462(** [build_exact_sdiv x y name b] creates a
1463    [%name = exact sdiv %x, %y]
1464    instruction at the position specified by the instruction builder [b].
1465    See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1466external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1467                          = "llvm_build_exact_sdiv"
1468
1469(** [build_fdiv x y name b] creates a
1470    [%name = fdiv %x, %y]
1471    instruction at the position specified by the instruction builder [b].
1472    See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1473external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1474                    = "llvm_build_fdiv"
1475
1476(** [build_urem x y name b] creates a
1477    [%name = urem %x, %y]
1478    instruction at the position specified by the instruction builder [b].
1479    See the method [llvm::LLVMBuilder::CreateURem]. *)
1480external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1481                    = "llvm_build_urem"
1482
1483(** [build_SRem x y name b] creates a
1484    [%name = srem %x, %y]
1485    instruction at the position specified by the instruction builder [b].
1486    See the method [llvm::LLVMBuilder::CreateSRem]. *)
1487external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1488                    = "llvm_build_srem"
1489
1490(** [build_frem x y name b] creates a
1491    [%name = frem %x, %y]
1492    instruction at the position specified by the instruction builder [b].
1493    See the method [llvm::LLVMBuilder::CreateFRem]. *)
1494external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1495                    = "llvm_build_frem"
1496
1497(** [build_shl x y name b] creates a
1498    [%name = shl %x, %y]
1499    instruction at the position specified by the instruction builder [b].
1500    See the method [llvm::LLVMBuilder::CreateShl]. *)
1501external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1502                   = "llvm_build_shl"
1503
1504(** [build_lshr x y name b] creates a
1505    [%name = lshr %x, %y]
1506    instruction at the position specified by the instruction builder [b].
1507    See the method [llvm::LLVMBuilder::CreateLShr]. *)
1508external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1509                    = "llvm_build_lshr"
1510
1511(** [build_ashr x y name b] creates a
1512    [%name = ashr %x, %y]
1513    instruction at the position specified by the instruction builder [b].
1514    See the method [llvm::LLVMBuilder::CreateAShr]. *)
1515external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1516                    = "llvm_build_ashr"
1517
1518(** [build_and x y name b] creates a
1519    [%name = and %x, %y]
1520    instruction at the position specified by the instruction builder [b].
1521    See the method [llvm::LLVMBuilder::CreateAnd]. *)
1522external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1523                   = "llvm_build_and"
1524
1525(** [build_or x y name b] creates a
1526    [%name = or %x, %y]
1527    instruction at the position specified by the instruction builder [b].
1528    See the method [llvm::LLVMBuilder::CreateOr]. *)
1529external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1530                  = "llvm_build_or"
1531
1532(** [build_xor x y name b] creates a
1533    [%name = xor %x, %y]
1534    instruction at the position specified by the instruction builder [b].
1535    See the method [llvm::LLVMBuilder::CreateXor]. *)
1536external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1537                   = "llvm_build_xor"
1538
1539(** [build_neg x name b] creates a
1540    [%name = sub 0, %x]
1541    instruction at the position specified by the instruction builder [b].
1542    [-0.0] is used for floating point types to compute the correct sign.
1543    See the method [llvm::LLVMBuilder::CreateNeg]. *)
1544external build_neg : llvalue -> string -> llbuilder -> llvalue
1545                   = "llvm_build_neg"
1546
1547(** [build_xor x name b] creates a
1548    [%name = xor %x, -1]
1549    instruction at the position specified by the instruction builder [b].
1550    [-1] is the correct "all ones" value for the type of [x].
1551    See the method [llvm::LLVMBuilder::CreateXor]. *)
1552external build_not : llvalue -> string -> llbuilder -> llvalue
1553                   = "llvm_build_not"
1554
1555
1556(** {7 Memory} *)
1557
1558(** [build_malloc ty name b] creates a
1559    [%name = malloc %ty]
1560    instruction at the position specified by the instruction builder [b].
1561    See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1562external build_malloc : lltype -> string -> llbuilder -> llvalue
1563                      = "llvm_build_malloc"
1564
1565(** [build_array_malloc ty n name b] creates a
1566    [%name = malloc %ty, %n]
1567    instruction at the position specified by the instruction builder [b].
1568    See the method [llvm::LLVMBuilder::CreateMalloc]. *)
1569external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1570                              llvalue = "llvm_build_array_malloc"
1571
1572(** [build_alloca ty name b] creates a
1573    [%name = alloca %ty]
1574    instruction at the position specified by the instruction builder [b].
1575    See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1576external build_alloca : lltype -> string -> llbuilder -> llvalue
1577                      = "llvm_build_alloca"
1578
1579(** [build_array_alloca ty n name b] creates a
1580    [%name = alloca %ty, %n]
1581    instruction at the position specified by the instruction builder [b].
1582    See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1583external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1584                              llvalue = "llvm_build_array_alloca"
1585
1586(** [build_free v b] creates a
1587    [free %v]
1588    instruction at the position specified by the instruction builder [b].
1589    See the method [llvm::LLVMBuilder::CreateFree]. *)
1590external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1591
1592(** [build_load v name b] creates a
1593    [%name = load %v]
1594    instruction at the position specified by the instruction builder [b].
1595    See the method [llvm::LLVMBuilder::CreateLoad]. *)
1596external build_load : llvalue -> string -> llbuilder -> llvalue
1597                    = "llvm_build_load"
1598
1599(** [build_store v p b] creates a
1600    [store %v, %p]
1601    instruction at the position specified by the instruction builder [b].
1602    See the method [llvm::LLVMBuilder::CreateStore]. *)
1603external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1604                     = "llvm_build_store"
1605
1606(** [build_gep p indices name b] creates a
1607    [%name = getelementptr %p, indices...]
1608    instruction at the position specified by the instruction builder [b].
1609    See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1610external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1611                   = "llvm_build_gep"
1612
1613(** [build_in_bounds_gep p indices name b] creates a
1614    [%name = gelementptr inbounds %p, indices...]
1615    instruction at the position specified by the instruction builder [b].
1616    See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1617external build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1618                               llvalue = "llvm_build_in_bounds_gep"
1619
1620(** [build_struct_gep p idx name b] creates a
1621    [%name = getelementptr %p, 0, idx]
1622    instruction at the position specified by the instruction builder [b].
1623    See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1624external build_struct_gep : llvalue -> int -> string -> llbuilder ->
1625                            llvalue = "llvm_build_struct_gep"
1626
1627(** [build_global_string str name b] creates a series of instructions that adds
1628    a global string at the position specified by the instruction builder [b].
1629    See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1630external build_global_string : string -> string -> llbuilder -> llvalue
1631                             = "llvm_build_global_string"
1632
1633(** [build_global_stringptr str name b] creates a series of instructions that
1634    adds a global string pointer at the position specified by the instruction
1635	 	builder [b].
1636    See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1637external build_global_stringptr : string -> string -> llbuilder -> llvalue
1638                                = "llvm_build_global_stringptr"
1639
1640
1641(** {7 Casts} *)
1642
1643(** [build_trunc v ty name b] creates a
1644    [%name = trunc %p to %ty]
1645    instruction at the position specified by the instruction builder [b].
1646    See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1647external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1648                     = "llvm_build_trunc"
1649
1650(** [build_zext v ty name b] creates a
1651    [%name = zext %p to %ty]
1652    instruction at the position specified by the instruction builder [b].
1653    See the method [llvm::LLVMBuilder::CreateZExt]. *)
1654external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1655                    = "llvm_build_zext"
1656
1657(** [build_sext v ty name b] creates a
1658    [%name = sext %p to %ty]
1659    instruction at the position specified by the instruction builder [b].
1660    See the method [llvm::LLVMBuilder::CreateSExt]. *)
1661external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1662                    = "llvm_build_sext"
1663
1664(** [build_fptoui v ty name b] creates a
1665    [%name = fptoui %p to %ty]
1666    instruction at the position specified by the instruction builder [b].
1667    See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1668external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1669                      = "llvm_build_fptoui"
1670
1671(** [build_fptosi v ty name b] creates a
1672    [%name = fptosi %p to %ty]
1673    instruction at the position specified by the instruction builder [b].
1674    See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1675external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1676                      = "llvm_build_fptosi"
1677
1678(** [build_uitofp v ty name b] creates a
1679    [%name = uitofp %p to %ty]
1680    instruction at the position specified by the instruction builder [b].
1681    See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1682external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1683                      = "llvm_build_uitofp"
1684
1685(** [build_sitofp v ty name b] creates a
1686    [%name = sitofp %p to %ty]
1687    instruction at the position specified by the instruction builder [b].
1688    See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1689external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1690                      = "llvm_build_sitofp"
1691
1692(** [build_fptrunc v ty name b] creates a
1693    [%name = fptrunc %p to %ty]
1694    instruction at the position specified by the instruction builder [b].
1695    See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1696external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1697                       = "llvm_build_fptrunc"
1698
1699(** [build_fpext v ty name b] creates a
1700    [%name = fpext %p to %ty]
1701    instruction at the position specified by the instruction builder [b].
1702    See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1703external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1704                     = "llvm_build_fpext"
1705
1706(** [build_ptrtoint v ty name b] creates a
1707    [%name = prtotint %p to %ty]
1708    instruction at the position specified by the instruction builder [b].
1709    See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1710external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1711                        = "llvm_build_prttoint"
1712
1713(** [build_inttoptr v ty name b] creates a
1714    [%name = inttoptr %p to %ty]
1715    instruction at the position specified by the instruction builder [b].
1716    See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1717external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1718                        = "llvm_build_inttoptr"
1719
1720(** [build_bitcast v ty name b] creates a
1721    [%name = bitcast %p to %ty]
1722    instruction at the position specified by the instruction builder [b].
1723    See the method [llvm::LLVMBuilder::CreateBitCast]. *)
1724external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1725                       = "llvm_build_bitcast"
1726
1727(** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
1728    instruction at the position specified by the instruction builder [b].
1729    See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1730external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1731                                 llvalue = "llvm_build_zext_or_bitcast"
1732
1733(** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
1734    instruction at the position specified by the instruction builder [b].
1735    See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
1736external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1737                                 llvalue = "llvm_build_sext_or_bitcast"
1738
1739(** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
1740    instruction at the position specified by the instruction builder [b].
1741    See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1742external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1743                                  llvalue = "llvm_build_trunc_or_bitcast"
1744
1745(** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
1746    instruction at the position specified by the instruction builder [b].
1747    See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
1748external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
1749                           = "llvm_build_pointercast"
1750
1751(** [build_intcast v ty name b] creates a zext, bitcast, or trunc
1752    instruction at the position specified by the instruction builder [b].
1753    See the method [llvm::LLVMBuilder::CreateIntCast]. *)
1754external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1755                       = "llvm_build_intcast"
1756
1757(** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
1758    instruction at the position specified by the instruction builder [b].
1759    See the method [llvm::LLVMBuilder::CreateFPCast]. *)
1760external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1761                      = "llvm_build_fpcast"
1762
1763
1764(** {7 Comparisons} *)
1765
1766(** [build_icmp pred x y name b] creates a
1767    [%name = icmp %pred %x, %y]
1768    instruction at the position specified by the instruction builder [b].
1769    See the method [llvm::LLVMBuilder::CreateICmp]. *)
1770external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1771                      llbuilder -> llvalue = "llvm_build_icmp"
1772
1773(** [build_fcmp pred x y name b] creates a
1774    [%name = fcmp %pred %x, %y]
1775    instruction at the position specified by the instruction builder [b].
1776    See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1777external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1778                      llbuilder -> llvalue = "llvm_build_fcmp"
1779
1780
1781(** {7 Miscellaneous instructions} *)
1782
1783(** [build_phi incoming name b] creates a
1784    [%name = phi %incoming]
1785    instruction at the position specified by the instruction builder [b].
1786    [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1787    See the method [llvm::LLVMBuilder::CreatePHI]. *)
1788external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1789                     llvalue = "llvm_build_phi"
1790
1791(** [build_call fn args name b] creates a
1792    [%name = call %fn(args...)]
1793    instruction at the position specified by the instruction builder [b].
1794    See the method [llvm::LLVMBuilder::CreateCall]. *)
1795external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1796                    = "llvm_build_call"
1797
1798(** [build_select cond thenv elsev name b] creates a
1799    [%name = select %cond, %thenv, %elsev]
1800    instruction at the position specified by the instruction builder [b].
1801    See the method [llvm::LLVMBuilder::CreateSelect]. *)
1802external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1803                        llvalue = "llvm_build_select"
1804
1805(** [build_va_arg valist argty name b] creates a
1806    [%name = va_arg %valist, %argty]
1807    instruction at the position specified by the instruction builder [b].
1808    See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1809external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1810                      = "llvm_build_va_arg"
1811
1812(** [build_extractelement vec i name b] creates a
1813    [%name = extractelement %vec, %i]
1814    instruction at the position specified by the instruction builder [b].
1815    See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1816external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1817                                llvalue = "llvm_build_extractelement"
1818
1819(** [build_insertelement vec elt i name b] creates a
1820    [%name = insertelement %vec, %elt, %i]
1821    instruction at the position specified by the instruction builder [b].
1822    See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1823external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1824                               llbuilder -> llvalue = "llvm_build_insertelement"
1825
1826(** [build_shufflevector veca vecb mask name b] creates a
1827    [%name = shufflevector %veca, %vecb, %mask]
1828    instruction at the position specified by the instruction builder [b].
1829    See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1830external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1831                               llbuilder -> llvalue = "llvm_build_shufflevector"
1832
1833(** [build_insertvalue agg idx name b] creates a
1834    [%name = extractvalue %agg, %idx]
1835    instruction at the position specified by the instruction builder [b].
1836    See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
1837external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
1838                            = "llvm_build_extractvalue"
1839
1840(** [build_insertvalue agg val idx name b] creates a
1841    [%name = insertvalue %agg, %val, %idx]
1842    instruction at the position specified by the instruction builder [b].
1843    See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
1844external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
1845                             llvalue = "llvm_build_insertvalue"
1846
1847(** [build_is_null val name b] creates a
1848    [%name = icmp eq %val, null]
1849    instruction at the position specified by the instruction builder [b].
1850    See the method [llvm::LLVMBuilder::CreateIsNull]. *)
1851external build_is_null : llvalue -> string -> llbuilder -> llvalue
1852                       = "llvm_build_is_null"
1853
1854(** [build_is_not_null val name b] creates a
1855    [%name = icmp ne %val, null]
1856    instruction at the position specified by the instruction builder [b].
1857    See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
1858external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
1859                           = "llvm_build_is_not_null"
1860
1861(** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
1862    the difference between two pointer values at the position specified by the
1863	 	instruction builder [b].
1864    See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
1865external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
1866                       = "llvm_build_ptrdiff"
1867
1868(** {6 Module providers} *)
1869
1870module ModuleProvider : sig
1871  (** [create_module_provider m] encapsulates [m] in a module provider and takes
1872      ownership of the module. See the constructor
1873      [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
1874  external create : llmodule -> llmoduleprovider
1875                  = "LLVMCreateModuleProviderForExistingModule"
1876  
1877  (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1878      the contained module. *)
1879  external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1880end
1881
1882
1883(** {6 Memory buffers} *)
1884
1885module MemoryBuffer : sig
1886  (** [of_file p] is the memory buffer containing the contents of the file at
1887      path [p]. If the file could not be read, then [IoError msg] is
1888      raised. *)
1889  external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1890  
1891  (** [stdin ()] is the memory buffer containing the contents of standard input.
1892      If standard input is empty, then [IoError msg] is raised. *)
1893  external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1894  
1895  (** Disposes of a memory buffer. *)
1896  external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
1897end
1898
1899
1900(** {6 Pass Managers} *)
1901
1902module PassManager : sig
1903  (**  *)
1904  type 'a t
1905  type any = [ `Module | `Function ]
1906  
1907  (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
1908      type of pipeline is suitable for link-time optimization and whole-module
1909      transformations.
1910      See the constructor of [llvm::PassManager]. *)
1911  external create : unit -> [ `Module ] t = "llvm_passmanager_create"
1912  
1913  (** [PassManager.create_function mp] constructs a new function-by-function
1914      pass pipeline over the module provider [mp]. It does not take ownership of
1915      [mp]. This type of pipeline is suitable for code generation and JIT
1916      compilation tasks.
1917      See the constructor of [llvm::FunctionPassManager]. *)
1918  external create_function : llmoduleprovider -> [ `Function ] t
1919                           = "LLVMCreateFunctionPassManager"
1920  
1921  (** [run_module m pm] initializes, executes on the module [m], and finalizes
1922      all of the passes scheduled in the pass manager [pm]. Returns [true] if
1923      any of the passes modified the module, [false] otherwise.
1924      See the [llvm::PassManager::run] method. *)
1925  external run_module : llmodule -> [ `Module ] t -> bool
1926                      = "llvm_passmanager_run_module"
1927  
1928  (** [initialize fpm] initializes all of the function passes scheduled in the
1929      function pass manager [fpm]. Returns [true] if any of the passes modified
1930      the module, [false] otherwise.
1931      See the [llvm::FunctionPassManager::doInitialization] method. *)
1932  external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
1933  
1934  (** [run_function f fpm] executes all of the function passes scheduled in the
1935      function pass manager [fpm] over the function [f]. Returns [true] if any
1936      of the passes modified [f], [false] otherwise.
1937      See the [llvm::FunctionPassManager::run] method. *)
1938  external run_function : llvalue -> [ `Function ] t -> bool
1939                        = "llvm_passmanager_run_function"
1940  
1941  (** [finalize fpm] finalizes all of the function passes scheduled in in the
1942      function pass manager [fpm]. Returns [true] if any of the passes
1943      modified the module, [false] otherwise.
1944      See the [llvm::FunctionPassManager::doFinalization] method. *)
1945  external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
1946  
1947  (** Frees the memory of a pass pipeline. For function pipelines, does not free
1948      the module provider.
1949      See the destructor of [llvm::BasePassManager]. *)
1950  external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"
1951end
1952