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