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