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