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