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