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