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