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_sub c1 c2] returns the constant difference, [c1 - c2], of two
1103    constants. See the method [llvm::ConstantExpr::getSub]. *)
1104val const_sub : llvalue -> llvalue -> llvalue
1105
1106(** [const_nsw_sub c1 c2] returns the constant difference of two constants with
1107    no signed wrapping. The result is undefined if the sum overflows.
1108    See the method [llvm::ConstantExpr::getNSWSub]. *)
1109val const_nsw_sub : llvalue -> llvalue -> llvalue
1110
1111(** [const_nuw_sub c1 c2] returns the constant difference of two constants with
1112    no unsigned wrapping. The result is undefined if the sum overflows.
1113    See the method [llvm::ConstantExpr::getNSWSub]. *)
1114val const_nuw_sub : llvalue -> llvalue -> llvalue
1115
1116(** [const_mul c1 c2] returns the constant product of two constants.
1117    See the method [llvm::ConstantExpr::getMul]. *)
1118val const_mul : llvalue -> llvalue -> llvalue
1119
1120(** [const_nsw_mul c1 c2] returns the constant product of two constants with
1121    no signed wrapping. The result is undefined if the sum overflows.
1122    See the method [llvm::ConstantExpr::getNSWMul]. *)
1123val const_nsw_mul : llvalue -> llvalue -> llvalue
1124
1125(** [const_nuw_mul c1 c2] returns the constant product of two constants with
1126    no unsigned wrapping. The result is undefined if the sum overflows.
1127    See the method [llvm::ConstantExpr::getNSWMul]. *)
1128val const_nuw_mul : llvalue -> llvalue -> llvalue
1129
1130(** [const_and c1 c2] returns the constant bitwise [AND] of two integer
1131    constants.
1132    See the method [llvm::ConstantExpr::getAnd]. *)
1133val const_and : llvalue -> llvalue -> llvalue
1134
1135(** [const_or c1 c2] returns the constant bitwise [OR] of two integer
1136    constants.
1137    See the method [llvm::ConstantExpr::getOr]. *)
1138val const_or : llvalue -> llvalue -> llvalue
1139
1140(** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
1141    constants.
1142    See the method [llvm::ConstantExpr::getXor]. *)
1143val const_xor : llvalue -> llvalue -> llvalue
1144
1145(** [const_icmp pred c1 c2] returns the constant comparison of two integer
1146    constants, [c1 pred c2].
1147    See the method [llvm::ConstantExpr::getICmp]. *)
1148val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
1149
1150(** [const_fcmp pred c1 c2] returns the constant comparison of two floating
1151    point constants, [c1 pred c2].
1152    See the method [llvm::ConstantExpr::getFCmp]. *)
1153val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
1154
1155(** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
1156    constant integer [c2].
1157    See the method [llvm::ConstantExpr::getShl]. *)
1158val const_shl : llvalue -> llvalue -> llvalue
1159
1160(** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
1161    constant integer [c2] with zero extension.
1162    See the method [llvm::ConstantExpr::getLShr]. *)
1163val const_lshr : llvalue -> llvalue -> llvalue
1164
1165(** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
1166    constant integer [c2] with sign extension.
1167    See the method [llvm::ConstantExpr::getAShr]. *)
1168val const_ashr : llvalue -> llvalue -> llvalue
1169
1170(** [const_gep pc indices] returns the constant [getElementPtr] of [pc] with the
1171    constant integers indices from the array [indices].
1172    See the method [llvm::ConstantExpr::getGetElementPtr]. *)
1173val const_gep : llvalue -> llvalue array -> llvalue
1174
1175(** [const_gep2 srcty pc indices] returns the constant [getElementPtr] of [pc]
1176    with source element type [srcty] and the constant integers indices from the
1177    array [indices].
1178    See the method [llvm::ConstantExpr::getGetElementPtr]. *)
1179val const_gep2 : lltype -> llvalue -> llvalue array -> llvalue
1180
1181(** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [pc]
1182    with the constant integers indices from the array [indices].
1183    See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
1184val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
1185
1186(** [const_trunc c ty] returns the constant truncation of integer constant [c]
1187    to the smaller integer type [ty].
1188    See the method [llvm::ConstantExpr::getTrunc]. *)
1189val const_trunc : llvalue -> lltype -> llvalue
1190
1191(** [const_sext c ty] returns the constant sign extension of integer constant
1192    [c] to the larger integer type [ty].
1193    See the method [llvm::ConstantExpr::getSExt]. *)
1194val const_sext : llvalue -> lltype -> llvalue
1195
1196(** [const_zext c ty] returns the constant zero extension of integer constant
1197    [c] to the larger integer type [ty].
1198    See the method [llvm::ConstantExpr::getZExt]. *)
1199val const_zext : llvalue -> lltype -> llvalue
1200
1201(** [const_fptrunc c ty] returns the constant truncation of floating point
1202    constant [c] to the smaller floating point type [ty].
1203    See the method [llvm::ConstantExpr::getFPTrunc]. *)
1204val const_fptrunc : llvalue -> lltype -> llvalue
1205
1206(** [const_fpext c ty] returns the constant extension of floating point constant
1207    [c] to the larger floating point type [ty].
1208    See the method [llvm::ConstantExpr::getFPExt]. *)
1209val const_fpext : llvalue -> lltype -> llvalue
1210
1211(** [const_uitofp c ty] returns the constant floating point conversion of
1212    unsigned integer constant [c] to the floating point type [ty].
1213    See the method [llvm::ConstantExpr::getUIToFP]. *)
1214val const_uitofp : llvalue -> lltype -> llvalue
1215
1216(** [const_sitofp c ty] returns the constant floating point conversion of
1217    signed integer constant [c] to the floating point type [ty].
1218    See the method [llvm::ConstantExpr::getSIToFP]. *)
1219val const_sitofp : llvalue -> lltype -> llvalue
1220
1221(** [const_fptoui c ty] returns the constant unsigned integer conversion of
1222    floating point constant [c] to integer type [ty].
1223    See the method [llvm::ConstantExpr::getFPToUI]. *)
1224val const_fptoui : llvalue -> lltype -> llvalue
1225
1226(** [const_fptoui c ty] returns the constant unsigned integer conversion of
1227    floating point constant [c] to integer type [ty].
1228    See the method [llvm::ConstantExpr::getFPToSI]. *)
1229val const_fptosi : llvalue -> lltype -> llvalue
1230
1231(** [const_ptrtoint c ty] returns the constant integer conversion of
1232    pointer constant [c] to integer type [ty].
1233    See the method [llvm::ConstantExpr::getPtrToInt]. *)
1234val const_ptrtoint : llvalue -> lltype -> llvalue
1235
1236(** [const_inttoptr c ty] returns the constant pointer conversion of
1237    integer constant [c] to pointer type [ty].
1238    See the method [llvm::ConstantExpr::getIntToPtr]. *)
1239val const_inttoptr : llvalue -> lltype -> llvalue
1240
1241(** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
1242    to type [ty] of equal size.
1243    See the method [llvm::ConstantExpr::getBitCast]. *)
1244val const_bitcast : llvalue -> lltype -> llvalue
1245
1246(** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
1247    conversion of constant [c] to type [ty].
1248    See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
1249val const_zext_or_bitcast : llvalue -> lltype -> llvalue
1250
1251(** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
1252    conversion of constant [c] to type [ty].
1253    See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
1254val const_sext_or_bitcast : llvalue -> lltype -> llvalue
1255
1256(** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
1257    conversion of constant [c] to type [ty].
1258    See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
1259val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
1260
1261(** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
1262    cast conversion of constant [c] to type [ty] of equal size.
1263    See the method [llvm::ConstantExpr::getPointerCast]. *)
1264val const_pointercast : llvalue -> lltype -> llvalue
1265
1266(** [const_intcast c ty ~is_signed] returns a constant sext/zext, bitcast,
1267    or trunc for integer -> integer casts of constant [c] to type [ty].
1268    When converting a narrower value to a wider one, whether sext or zext
1269    will be used is controlled by [is_signed].
1270    See the method [llvm::ConstantExpr::getIntegerCast]. *)
1271val const_intcast : llvalue -> lltype -> is_signed:bool -> llvalue
1272
1273(** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
1274    fp casts of constant [c] to type [ty].
1275    See the method [llvm::ConstantExpr::getFPCast]. *)
1276val const_fpcast : llvalue -> lltype -> llvalue
1277
1278(** [const_select cond t f] returns the constant conditional which returns value
1279    [t] if the boolean constant [cond] is true and the value [f] otherwise.
1280    See the method [llvm::ConstantExpr::getSelect]. *)
1281val const_select : llvalue -> llvalue -> llvalue -> llvalue
1282
1283(** [const_extractelement vec i] returns the constant [i]th element of
1284    constant vector [vec]. [i] must be a constant [i32] value unsigned less than
1285    the size of the vector.
1286    See the method [llvm::ConstantExpr::getExtractElement]. *)
1287val const_extractelement : llvalue -> llvalue -> llvalue
1288
1289(** [const_insertelement vec v i] returns the constant vector with the same
1290    elements as constant vector [v] but the [i]th element replaced by the
1291    constant [v]. [v] must be a constant value with the type of the vector
1292    elements. [i] must be a constant [i32] value unsigned less than the size
1293    of the vector.
1294    See the method [llvm::ConstantExpr::getInsertElement]. *)
1295val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
1296
1297(** [const_shufflevector a b mask] returns a constant [shufflevector].
1298    See the LLVM Language Reference for details on the [shufflevector]
1299    instruction.
1300    See the method [llvm::ConstantExpr::getShuffleVector]. *)
1301val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
1302
1303(** [const_inline_asm ty asm con side align] inserts a inline assembly string.
1304    See the method [llvm::InlineAsm::get]. *)
1305val const_inline_asm : lltype -> string -> string -> bool -> bool -> llvalue
1306
1307(** [block_address f bb] returns the address of the basic block [bb] in the
1308    function [f]. See the method [llvm::BasicBlock::get]. *)
1309val block_address : llvalue -> llbasicblock -> llvalue
1310
1311
1312(** {7 Operations on global variables, functions, and aliases (globals)} *)
1313
1314(** [global_parent g] is the enclosing module of the global value [g].
1315    See the method [llvm::GlobalValue::getParent]. *)
1316val global_parent : llvalue -> llmodule
1317
1318(** [is_declaration g] returns [true] if the global value [g] is a declaration
1319    only. Returns [false] otherwise.
1320    See the method [llvm::GlobalValue::isDeclaration]. *)
1321val is_declaration : llvalue -> bool
1322
1323(** [linkage g] returns the linkage of the global value [g].
1324    See the method [llvm::GlobalValue::getLinkage]. *)
1325val linkage : llvalue -> Linkage.t
1326
1327(** [set_linkage l g] sets the linkage of the global value [g] to [l].
1328    See the method [llvm::GlobalValue::setLinkage]. *)
1329val set_linkage : Linkage.t -> llvalue -> unit
1330
1331(** [unnamed_addr g] returns [true] if the global value [g] has the unnamed_addr
1332    attribute. Returns [false] otherwise.
1333    See the method [llvm::GlobalValue::getUnnamedAddr]. *)
1334val unnamed_addr : llvalue -> bool
1335
1336(** [set_unnamed_addr b g] if [b] is [true], sets the unnamed_addr attribute of
1337    the global value [g]. Unset it otherwise.
1338    See the method [llvm::GlobalValue::setUnnamedAddr]. *)
1339val set_unnamed_addr : bool -> llvalue -> unit
1340
1341(** [section g] returns the linker section of the global value [g].
1342    See the method [llvm::GlobalValue::getSection]. *)
1343val section : llvalue -> string
1344
1345(** [set_section s g] sets the linker section of the global value [g] to [s].
1346    See the method [llvm::GlobalValue::setSection]. *)
1347val set_section : string -> llvalue -> unit
1348
1349(** [visibility g] returns the linker visibility of the global value [g].
1350    See the method [llvm::GlobalValue::getVisibility]. *)
1351val visibility : llvalue -> Visibility.t
1352
1353(** [set_visibility v g] sets the linker visibility of the global value [g] to
1354    [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1355val set_visibility : Visibility.t -> llvalue -> unit
1356
1357(** [dll_storage_class g] returns the DLL storage class of the global value [g].
1358    See the method [llvm::GlobalValue::getDLLStorageClass]. *)
1359val dll_storage_class : llvalue -> DLLStorageClass.t
1360
1361(** [set_dll_storage_class v g] sets the DLL storage class of the global value [g] to
1362    [v]. See the method [llvm::GlobalValue::setDLLStorageClass]. *)
1363val set_dll_storage_class : DLLStorageClass.t -> llvalue -> unit
1364
1365(** [alignment g] returns the required alignment of the global value [g].
1366    See the method [llvm::GlobalValue::getAlignment]. *)
1367val alignment : llvalue -> int
1368
1369(** [set_alignment n g] sets the required alignment of the global value [g] to
1370    [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1371val set_alignment : int -> llvalue -> unit
1372
1373(** [global_copy_all_metadata g] returns all the metadata associated with [g],
1374    which must be an [Instruction] or [GlobalObject].
1375    See the [llvm::Instruction::getAllMetadata()] and
1376    [llvm::GlobalObject::getAllMetadata()] methods. *)
1377val global_copy_all_metadata : llvalue -> (llmdkind * llmetadata) array
1378
1379
1380(** {7 Operations on global variables} *)
1381
1382(** [declare_global ty name m] returns a new global variable of type [ty] and
1383    with name [name] in module [m] in the default address space (0). If such a
1384    global variable already exists, it is returned. If the type of the existing
1385    global differs, then a bitcast to [ty] is returned. *)
1386val declare_global : lltype -> string -> llmodule -> llvalue
1387
1388(** [declare_qualified_global ty name addrspace m] returns a new global variable
1389    of type [ty] and with name [name] in module [m] in the address space
1390    [addrspace]. If such a global variable already exists, it is returned. If
1391    the type of the existing global differs, then a bitcast to [ty] is
1392    returned. *)
1393val declare_qualified_global : lltype -> string -> int -> llmodule -> llvalue
1394
1395(** [define_global name init m] returns a new global with name [name] and
1396    initializer [init] in module [m] in the default address space (0). If the
1397    named global already exists, it is renamed.
1398    See the constructor of [llvm::GlobalVariable]. *)
1399val define_global : string -> llvalue -> llmodule -> llvalue
1400
1401(** [define_qualified_global name init addrspace m] returns a new global with
1402    name [name] and initializer [init] in module [m] in the address space
1403    [addrspace]. If the named global already exists, it is renamed.
1404    See the constructor of [llvm::GlobalVariable]. *)
1405val define_qualified_global : string -> llvalue -> int -> llmodule -> llvalue
1406
1407(** [lookup_global name m] returns [Some g] if a global variable with name
1408    [name] exists in module [m]. If no such global exists, returns [None].
1409    See the [llvm::GlobalVariable] constructor. *)
1410val lookup_global : string -> llmodule -> llvalue option
1411
1412(** [delete_global gv] destroys the global variable [gv].
1413    See the method [llvm::GlobalVariable::eraseFromParent]. *)
1414val delete_global : llvalue -> unit
1415
1416(** [global_begin m] returns the first position in the global variable list of
1417    the module [m]. [global_begin] and [global_succ] can be used to iterate
1418    over the global list in order.
1419    See the method [llvm::Module::global_begin]. *)
1420val global_begin : llmodule -> (llmodule, llvalue) llpos
1421
1422(** [global_succ gv] returns the global variable list position succeeding
1423    [Before gv].
1424    See the method [llvm::Module::global_iterator::operator++]. *)
1425val global_succ : llvalue -> (llmodule, llvalue) llpos
1426
1427(** [iter_globals f m] applies function [f] to each of the global variables of
1428    module [m] in order. Tail recursive. *)
1429val iter_globals : (llvalue -> unit) -> llmodule -> unit
1430
1431(** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1432    [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1433val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1434
1435(** [global_end m] returns the last position in the global variable list of the
1436    module [m]. [global_end] and [global_pred] can be used to iterate over the
1437    global list in reverse.
1438    See the method [llvm::Module::global_end]. *)
1439val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1440
1441(** [global_pred gv] returns the global variable list position preceding
1442    [After gv].
1443    See the method [llvm::Module::global_iterator::operator--]. *)
1444val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1445
1446(** [rev_iter_globals f m] applies function [f] to each of the global variables
1447    of module [m] in reverse order. Tail recursive. *)
1448val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1449
1450(** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1451    [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1452val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1453
1454(** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1455    constant. Returns [false] otherwise.
1456    See the method [llvm::GlobalVariable::isConstant]. *)
1457val is_global_constant : llvalue -> bool
1458
1459(** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1460    [c] is [true] and not if [c] is [false].
1461    See the method [llvm::GlobalVariable::setConstant]. *)
1462val set_global_constant : bool -> llvalue -> unit
1463
1464(** [global_initializer gv] If global variable [gv] has an initializer it is returned,
1465    otherwise returns [None]. See the method [llvm::GlobalVariable::getInitializer]. *)
1466val global_initializer : llvalue -> llvalue option
1467
1468(** [set_initializer c gv] sets the initializer for the global variable
1469    [gv] to the constant [c].
1470    See the method [llvm::GlobalVariable::setInitializer]. *)
1471val set_initializer : llvalue -> llvalue -> unit
1472
1473(** [remove_initializer gv] unsets the initializer for the global variable
1474    [gv].
1475    See the method [llvm::GlobalVariable::setInitializer]. *)
1476val remove_initializer : llvalue -> unit
1477
1478(** [is_thread_local gv] returns [true] if the global variable [gv] is
1479    thread-local and [false] otherwise.
1480    See the method [llvm::GlobalVariable::isThreadLocal]. *)
1481val is_thread_local : llvalue -> bool
1482
1483(** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1484    [c] is [true] and not otherwise.
1485    See the method [llvm::GlobalVariable::setThreadLocal]. *)
1486val set_thread_local : bool -> llvalue -> unit
1487
1488(** [is_thread_local gv] returns the thread local mode of the global
1489    variable [gv].
1490    See the method [llvm::GlobalVariable::getThreadLocalMode]. *)
1491val thread_local_mode : llvalue -> ThreadLocalMode.t
1492
1493(** [set_thread_local c gv] sets the thread local mode of the global
1494    variable [gv].
1495    See the method [llvm::GlobalVariable::setThreadLocalMode]. *)
1496val set_thread_local_mode : ThreadLocalMode.t -> llvalue -> unit
1497
1498(** [is_externally_initialized gv] returns [true] if the global
1499    variable [gv] is externally initialized and [false] otherwise.
1500    See the method [llvm::GlobalVariable::isExternallyInitialized]. *)
1501val is_externally_initialized : llvalue -> bool
1502
1503(** [set_externally_initialized c gv] sets the global variable [gv] to be
1504    externally initialized if [c] is [true] and not otherwise.
1505    See the method [llvm::GlobalVariable::setExternallyInitialized]. *)
1506val set_externally_initialized : bool -> llvalue -> unit
1507
1508
1509(** {7 Operations on aliases} *)
1510
1511(** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1512    the aliasee [a] with the name [n].
1513    See the constructor for [llvm::GlobalAlias]. *)
1514val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1515
1516(** [add_alias m vt as a n] inserts an alias in the module [m] with the value
1517    type [vt] the address space [as] the aliasee [a] with the name [n].
1518    See the constructor for [llvm::GlobalAlias]. *)
1519val add_alias2 : llmodule -> lltype -> int -> llvalue -> string -> llvalue
1520
1521(** {7 Operations on functions} *)
1522
1523(** [declare_function name ty m] returns a new function of type [ty] and
1524    with name [name] in module [m]. If such a function already exists,
1525    it is returned. If the type of the existing function differs, then a bitcast
1526    to [ty] is returned. *)
1527val declare_function : string -> lltype -> llmodule -> llvalue
1528
1529(** [define_function name ty m] creates a new function with name [name] and
1530    type [ty] in module [m]. If the named function already exists, it is
1531    renamed. An entry basic block is created in the function.
1532    See the constructor of [llvm::GlobalVariable]. *)
1533val define_function : string -> lltype -> llmodule -> llvalue
1534
1535(** [lookup_function name m] returns [Some f] if a function with name
1536    [name] exists in module [m]. If no such function exists, returns [None].
1537    See the method [llvm::Module] constructor. *)
1538val lookup_function : string -> llmodule -> llvalue option
1539
1540(** [delete_function f] destroys the function [f].
1541    See the method [llvm::Function::eraseFromParent]. *)
1542val delete_function : llvalue -> unit
1543
1544(** [function_begin m] returns the first position in the function list of the
1545    module [m]. [function_begin] and [function_succ] can be used to iterate over
1546    the function list in order.
1547    See the method [llvm::Module::begin]. *)
1548val function_begin : llmodule -> (llmodule, llvalue) llpos
1549
1550(** [function_succ gv] returns the function list position succeeding
1551    [Before gv].
1552    See the method [llvm::Module::iterator::operator++]. *)
1553val function_succ : llvalue -> (llmodule, llvalue) llpos
1554
1555(** [iter_functions f m] applies function [f] to each of the functions of module
1556    [m] in order. Tail recursive. *)
1557val iter_functions : (llvalue -> unit) -> llmodule -> unit
1558
1559(** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1560    [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1561val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1562
1563(** [function_end m] returns the last position in the function list of
1564    the module [m]. [function_end] and [function_pred] can be used to iterate
1565    over the function list in reverse.
1566    See the method [llvm::Module::end]. *)
1567val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1568
1569(** [function_pred gv] returns the function list position preceding [After gv].
1570    See the method [llvm::Module::iterator::operator--]. *)
1571val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1572
1573(** [rev_iter_functions f fn] applies function [f] to each of the functions of
1574    module [m] in reverse order. Tail recursive. *)
1575val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1576
1577(** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1578    [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1579val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1580
1581(** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1582    See the method [llvm::Function::isIntrinsic]. *)
1583val is_intrinsic : llvalue -> bool
1584
1585(** [function_call_conv f] returns the calling convention of the function [f].
1586    See the method [llvm::Function::getCallingConv]. *)
1587val function_call_conv : llvalue -> int
1588
1589(** [set_function_call_conv cc f] sets the calling convention of the function
1590    [f] to the calling convention numbered [cc].
1591    See the method [llvm::Function::setCallingConv]. *)
1592val set_function_call_conv : int -> llvalue -> unit
1593
1594(** [gc f] returns [Some name] if the function [f] has a garbage
1595    collection algorithm specified and [None] otherwise.
1596    See the method [llvm::Function::getGC]. *)
1597val gc : llvalue -> string option
1598
1599(** [set_gc gc f] sets the collection algorithm for the function [f] to
1600    [gc]. See the method [llvm::Function::setGC]. *)
1601val set_gc : string option -> llvalue -> unit
1602
1603(** [add_function_attr f a i] adds attribute [a] to the function [f]
1604    at position [i]. *)
1605val add_function_attr : llvalue -> llattribute -> AttrIndex.t -> unit
1606
1607(** [function_attrs f i] returns the attributes for the function [f]
1608    at position [i]. *)
1609val function_attrs : llvalue -> AttrIndex.t -> llattribute array
1610
1611(** [remove_enum_function_attr f k i] removes enum attribute with kind [k]
1612    from the function [f] at position [i]. *)
1613val remove_enum_function_attr : llvalue -> llattrkind -> AttrIndex.t -> unit
1614
1615(** [remove_string_function_attr f k i] removes string attribute with kind [k]
1616    from the function [f] at position [i]. *)
1617val remove_string_function_attr : llvalue -> string -> AttrIndex.t -> unit
1618
1619
1620(** {7 Operations on params} *)
1621
1622(** [params f] returns the parameters of function [f].
1623    See the method [llvm::Function::getArgumentList]. *)
1624val params : llvalue -> llvalue array
1625
1626(** [param f n] returns the [n]th parameter of function [f].
1627    See the method [llvm::Function::getArgumentList]. *)
1628val param : llvalue -> int -> llvalue
1629
1630(** [param_parent p] returns the parent function that owns the parameter.
1631    See the method [llvm::Argument::getParent]. *)
1632val param_parent : llvalue -> llvalue
1633
1634(** [param_begin f] returns the first position in the parameter list of the
1635    function [f]. [param_begin] and [param_succ] can be used to iterate over
1636    the parameter list in order.
1637    See the method [llvm::Function::arg_begin]. *)
1638val param_begin : llvalue -> (llvalue, llvalue) llpos
1639
1640(** [param_succ bb] returns the parameter list position succeeding
1641    [Before bb].
1642    See the method [llvm::Function::arg_iterator::operator++]. *)
1643val param_succ : llvalue -> (llvalue, llvalue) llpos
1644
1645(** [iter_params f fn] applies function [f] to each of the parameters
1646    of function [fn] in order. Tail recursive. *)
1647val iter_params : (llvalue -> unit) -> llvalue -> unit
1648
1649(** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1650    [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1651val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1652
1653(** [param_end f] returns the last position in the parameter list of
1654    the function [f]. [param_end] and [param_pred] can be used to iterate
1655    over the parameter list in reverse.
1656    See the method [llvm::Function::arg_end]. *)
1657val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1658
1659(** [param_pred gv] returns the function list position preceding [After gv].
1660    See the method [llvm::Function::arg_iterator::operator--]. *)
1661val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1662
1663(** [rev_iter_params f fn] applies function [f] to each of the parameters
1664    of function [fn] in reverse order. Tail recursive. *)
1665val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1666
1667(** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1668    [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1669val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1670
1671
1672(** {7 Operations on basic blocks} *)
1673
1674(** [basic_blocks fn] returns the basic blocks of the function [f].
1675    See the method [llvm::Function::getBasicBlockList]. *)
1676val basic_blocks : llvalue -> llbasicblock array
1677
1678(** [entry_block fn] returns the entry basic block of the function [f].
1679    See the method [llvm::Function::getEntryBlock]. *)
1680val entry_block : llvalue -> llbasicblock
1681
1682(** [delete_block bb] deletes the basic block [bb].
1683    See the method [llvm::BasicBlock::eraseFromParent]. *)
1684val delete_block : llbasicblock -> unit
1685
1686(** [remove_block bb] removes the basic block [bb] from its parent function.
1687    See the method [llvm::BasicBlock::removeFromParent]. *)
1688val remove_block : llbasicblock -> unit
1689
1690(** [move_block_before pos bb] moves the basic block [bb] before [pos].
1691    See the method [llvm::BasicBlock::moveBefore]. *)
1692val move_block_before : llbasicblock -> llbasicblock -> unit
1693
1694(** [move_block_after pos bb] moves the basic block [bb] after [pos].
1695    See the method [llvm::BasicBlock::moveAfter]. *)
1696val move_block_after : llbasicblock -> llbasicblock -> unit
1697
1698(** [append_block c name f] creates a new basic block named [name] at the end of
1699    function [f] in the context [c].
1700    See the constructor of [llvm::BasicBlock]. *)
1701val append_block : llcontext -> string -> llvalue -> llbasicblock
1702
1703(** [insert_block c name bb] creates a new basic block named [name] before the
1704    basic block [bb] in the context [c].
1705    See the constructor of [llvm::BasicBlock]. *)
1706val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1707
1708(** [block_parent bb] returns the parent function that owns the basic block.
1709    See the method [llvm::BasicBlock::getParent]. *)
1710val block_parent : llbasicblock -> llvalue
1711
1712(** [block_begin f] returns the first position in the basic block list of the
1713    function [f]. [block_begin] and [block_succ] can be used to iterate over
1714    the basic block list in order.
1715    See the method [llvm::Function::begin]. *)
1716val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1717
1718(** [block_succ bb] returns the basic block list position succeeding
1719    [Before bb].
1720    See the method [llvm::Function::iterator::operator++]. *)
1721val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1722
1723(** [iter_blocks f fn] applies function [f] to each of the basic blocks
1724    of function [fn] in order. Tail recursive. *)
1725val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1726
1727(** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1728    [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1729val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1730
1731(** [block_end f] returns the last position in the basic block list of
1732    the function [f]. [block_end] and [block_pred] can be used to iterate
1733    over the basic block list in reverse.
1734    See the method [llvm::Function::end]. *)
1735val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1736
1737(** [block_pred bb] returns the basic block list position preceding [After bb].
1738    See the method [llvm::Function::iterator::operator--]. *)
1739val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1740
1741(** [block_terminator bb] returns the terminator of the basic block [bb]. *)
1742val block_terminator : llbasicblock -> llvalue option
1743
1744(** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1745    of function [fn] in reverse order. Tail recursive. *)
1746val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1747
1748(** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1749    [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1750val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1751
1752(** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1753val value_of_block : llbasicblock -> llvalue
1754
1755(** [value_is_block v] returns [true] if the value [v] is a basic block and
1756    [false] otherwise.
1757    Similar to [llvm::isa<BasicBlock>]. *)
1758val value_is_block : llvalue -> bool
1759
1760(** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1761val block_of_value : llvalue -> llbasicblock
1762
1763
1764(** {7 Operations on instructions} *)
1765
1766(** [instr_parent i] is the enclosing basic block of the instruction [i].
1767    See the method [llvm::Instruction::getParent]. *)
1768val instr_parent : llvalue -> llbasicblock
1769
1770(** [delete_instruction i] deletes the instruction [i].
1771 * See the method [llvm::Instruction::eraseFromParent]. *)
1772val delete_instruction : llvalue -> unit
1773
1774(** [instr_begin bb] returns the first position in the instruction list of the
1775    basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1776    the instruction list in order.
1777    See the method [llvm::BasicBlock::begin]. *)
1778val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1779
1780(** [instr_succ i] returns the instruction list position succeeding [Before i].
1781    See the method [llvm::BasicBlock::iterator::operator++]. *)
1782val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1783
1784(** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1785    block [bb] in order. Tail recursive. *)
1786val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1787
1788(** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1789    [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1790val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1791
1792(** [instr_end bb] returns the last position in the instruction list of the
1793    basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1794    the instruction list in reverse.
1795    See the method [llvm::BasicBlock::end]. *)
1796val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1797
1798(** [instr_pred i] returns the instruction list position preceding [After i].
1799    See the method [llvm::BasicBlock::iterator::operator--]. *)
1800val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1801
1802(** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1803    [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1804val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1805
1806(** [inst_opcode i] returns the [Opcode.t] corresponding to instruction [i],
1807    or [Opcode.Invalid] if [i] is not an instruction. *)
1808val instr_opcode : llvalue -> Opcode.t
1809
1810(** [icmp_predicate i] returns the [Icmp.t] corresponding to an [icmp]
1811    instruction [i]. *)
1812val icmp_predicate : llvalue -> Icmp.t option
1813
1814(** [fcmp_predicate i] returns the [fcmp.t] corresponding to an [fcmp]
1815    instruction [i]. *)
1816val fcmp_predicate : llvalue -> Fcmp.t option
1817
1818(** [inst_clone i] returns a copy of instruction [i],
1819    The instruction has no parent, and no name.
1820    See the method [llvm::Instruction::clone]. *)
1821val instr_clone : llvalue -> llvalue
1822
1823
1824(** {7 Operations on call sites} *)
1825
1826(** [instruction_call_conv ci] is the calling convention for the call or invoke
1827    instruction [ci], which may be one of the values from the module
1828    {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1829    [llvm::InvokeInst::getCallingConv]. *)
1830val instruction_call_conv: llvalue -> int
1831
1832(** [set_instruction_call_conv cc ci] sets the calling convention for the call
1833    or invoke instruction [ci] to the integer [cc], which can be one of the
1834    values from the module {!CallConv}.
1835    See the method [llvm::CallInst::setCallingConv]
1836    and [llvm::InvokeInst::setCallingConv]. *)
1837val set_instruction_call_conv: int -> llvalue -> unit
1838
1839(** [add_call_site_attr f a i] adds attribute [a] to the call instruction [ci]
1840    at position [i]. *)
1841val add_call_site_attr : llvalue -> llattribute -> AttrIndex.t -> unit
1842
1843(** [call_site_attr f i] returns the attributes for the call instruction [ci]
1844    at position [i]. *)
1845val call_site_attrs : llvalue -> AttrIndex.t -> llattribute array
1846
1847(** [remove_enum_call_site_attr f k i] removes enum attribute with kind [k]
1848    from the call instruction [ci] at position [i]. *)
1849val remove_enum_call_site_attr : llvalue -> llattrkind -> AttrIndex.t -> unit
1850
1851(** [remove_string_call_site_attr f k i] removes string attribute with kind [k]
1852    from the call instruction [ci] at position [i]. *)
1853val remove_string_call_site_attr : llvalue -> string -> AttrIndex.t -> unit
1854
1855
1856(** {7 Operations on call and invoke instructions (only)} *)
1857
1858(** [num_arg_operands ci] returns the number of arguments for the call or
1859    invoke instruction [ci].  See the method
1860    [llvm::CallInst::getNumArgOperands]. *)
1861val num_arg_operands : llvalue -> int
1862
1863(** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1864    eligible for tail call optimization, [false] otherwise.
1865    See the method [llvm::CallInst::isTailCall]. *)
1866val is_tail_call : llvalue -> bool
1867
1868(** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1869    call optimization if [tc] is [true], clears otherwise.
1870    See the method [llvm::CallInst::setTailCall]. *)
1871val set_tail_call : bool -> llvalue -> unit
1872
1873(** [get_normal_dest ii] is the normal destination basic block of an invoke
1874    instruction. See the method [llvm::InvokeInst::getNormalDest()]. *)
1875val get_normal_dest : llvalue -> llbasicblock
1876
1877(** [get_unwind_dest ii] is the unwind destination basic block of an invoke
1878    instruction. See the method [llvm::InvokeInst::getUnwindDest()]. *)
1879val get_unwind_dest : llvalue -> llbasicblock
1880
1881
1882(** {7 Operations on load/store instructions (only)} *)
1883
1884(** [is_volatile i] is [true] if the load or store instruction [i] is marked
1885    as volatile.
1886    See the methods [llvm::LoadInst::isVolatile] and
1887    [llvm::StoreInst::isVolatile]. *)
1888val is_volatile : llvalue -> bool
1889
1890(** [set_volatile v i] marks the load or store instruction [i] as volatile
1891    if [v] is [true], unmarks otherwise.
1892    See the methods [llvm::LoadInst::setVolatile] and
1893    [llvm::StoreInst::setVolatile]. *)
1894val set_volatile : bool -> llvalue -> unit
1895
1896(** {7 Operations on terminators} *)
1897
1898(** [is_terminator v] returns true if the instruction [v] is a terminator. *)
1899val is_terminator : llvalue -> bool
1900
1901(** [successor v i] returns the successor at index [i] for the value [v].
1902    See the method [llvm::Instruction::getSuccessor]. *)
1903val successor : llvalue -> int -> llbasicblock
1904
1905(** [set_successor v i o] sets the successor of the value [v] at the index [i] to
1906    the value [o].
1907    See the method [llvm::Instruction::setSuccessor]. *)
1908val set_successor : llvalue -> int -> llbasicblock -> unit
1909
1910(** [num_successors v] returns the number of successors for the value [v].
1911    See the method [llvm::Instruction::getNumSuccessors]. *)
1912val num_successors : llvalue -> int
1913
1914(** [successors v] returns the successors of [v]. *)
1915val successors : llvalue -> llbasicblock array
1916
1917(** [iter_successors f v] applies function f to each successor [v] in order. Tail recursive. *)
1918val iter_successors : (llbasicblock -> unit) -> llvalue -> unit
1919
1920(** [fold_successors f v init] is [f (... (f init vN) ...) v1] where [v1,...,vN] are the successors of [v]. Tail recursive. *)
1921val fold_successors : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1922
1923(** {7 Operations on branches} *)
1924
1925(** [is_conditional v] returns true if the branch instruction [v] is conditional.
1926    See the method [llvm::BranchInst::isConditional]. *)
1927val is_conditional : llvalue -> bool
1928
1929(** [condition v] return the condition of the branch instruction [v].
1930    See the method [llvm::BranchInst::getCondition]. *)
1931val condition : llvalue -> llvalue
1932
1933(** [set_condition v c] sets the condition of the branch instruction [v] to the value [c].
1934    See the method [llvm::BranchInst::setCondition]. *)
1935val set_condition : llvalue -> llvalue -> unit
1936
1937(** [get_branch c] returns a description of the branch instruction [c]. *)
1938val get_branch : llvalue ->
1939  [ `Conditional of llvalue * llbasicblock * llbasicblock
1940  | `Unconditional of llbasicblock ]
1941    option
1942
1943(** {7 Operations on phi nodes} *)
1944
1945(** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1946    with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1947val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1948
1949(** [incoming pn] returns the list of value-block pairs for phi node [pn].
1950    See the method [llvm::PHINode::getIncomingValue]. *)
1951val incoming : llvalue -> (llvalue * llbasicblock) list
1952
1953
1954
1955(** {6 Instruction builders} *)
1956
1957(** [builder context] creates an instruction builder with no position in
1958    the context [context]. It is invalid to use this builder until its position
1959    is set with {!position_before} or {!position_at_end}. See the constructor
1960    for [llvm::LLVMBuilder]. *)
1961val builder : llcontext -> llbuilder
1962
1963(** [builder_at ip] creates an instruction builder positioned at [ip].
1964    See the constructor for [llvm::LLVMBuilder]. *)
1965val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1966
1967(** [builder_before ins] creates an instruction builder positioned before the
1968    instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1969val builder_before : llcontext -> llvalue -> llbuilder
1970
1971(** [builder_at_end bb] creates an instruction builder positioned at the end of
1972    the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1973val builder_at_end : llcontext -> llbasicblock -> llbuilder
1974
1975(** [position_builder ip bb] moves the instruction builder [bb] to the position
1976    [ip].
1977    See the constructor for [llvm::LLVMBuilder]. *)
1978val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1979
1980(** [position_before ins b] moves the instruction builder [b] to before the
1981    instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1982val position_before : llvalue -> llbuilder -> unit
1983
1984(** [position_at_end bb b] moves the instruction builder [b] to the end of the
1985    basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1986val position_at_end : llbasicblock -> llbuilder -> unit
1987
1988(** [insertion_block b] returns the basic block that the builder [b] is
1989    positioned to insert into. Raises [Not_Found] if the instruction builder is
1990    uninitialized.
1991    See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1992val insertion_block : llbuilder -> llbasicblock
1993
1994(** [insert_into_builder i name b] inserts the specified instruction [i] at the
1995    position specified by the instruction builder [b].
1996    See the method [llvm::LLVMBuilder::Insert]. *)
1997val insert_into_builder : llvalue -> string -> llbuilder -> unit
1998
1999
2000(** {7 Metadata} *)
2001
2002(** [set_current_debug_location b md] sets the current debug location [md] in
2003    the builder [b].
2004    See the method [llvm::IRBuilder::SetDebugLocation]. *)
2005val set_current_debug_location : llbuilder -> llvalue -> unit
2006
2007(** [clear_current_debug_location b] clears the current debug location in the
2008    builder [b]. *)
2009val clear_current_debug_location : llbuilder -> unit
2010
2011(** [current_debug_location b] returns the current debug location, or None
2012    if none is currently set.
2013    See the method [llvm::IRBuilder::GetDebugLocation]. *)
2014val current_debug_location : llbuilder -> llvalue option
2015
2016(** [set_inst_debug_location b i] sets the current debug location of the builder
2017    [b] to the instruction [i].
2018    See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
2019val set_inst_debug_location : llbuilder -> llvalue -> unit
2020
2021
2022(** {7 Terminators} *)
2023
2024(** [build_ret_void b] creates a
2025    [ret void]
2026    instruction at the position specified by the instruction builder [b].
2027    See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
2028val build_ret_void : llbuilder -> llvalue
2029
2030(** [build_ret v b] creates a
2031    [ret %v]
2032    instruction at the position specified by the instruction builder [b].
2033    See the method [llvm::LLVMBuilder::CreateRet]. *)
2034val build_ret : llvalue -> llbuilder -> llvalue
2035
2036(** [build_aggregate_ret vs b] creates a
2037    [ret {...} { %v1, %v2, ... } ]
2038    instruction at the position specified by the instruction builder [b].
2039    See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
2040val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
2041
2042(** [build_br bb b] creates a
2043    [br %bb]
2044    instruction at the position specified by the instruction builder [b].
2045    See the method [llvm::LLVMBuilder::CreateBr]. *)
2046val build_br : llbasicblock -> llbuilder -> llvalue
2047
2048(** [build_cond_br cond tbb fbb b] creates a
2049    [br %cond, %tbb, %fbb]
2050    instruction at the position specified by the instruction builder [b].
2051    See the method [llvm::LLVMBuilder::CreateCondBr]. *)
2052val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
2053                         llvalue
2054
2055(** [build_switch case elsebb count b] creates an empty
2056    [switch %case, %elsebb]
2057    instruction at the position specified by the instruction builder [b] with
2058    space reserved for [count] cases.
2059    See the method [llvm::LLVMBuilder::CreateSwitch]. *)
2060val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
2061
2062(** [build_malloc ty name b] creates an [malloc]
2063    instruction at the position specified by the instruction builder [b].
2064    See the method [llvm::CallInst::CreateMalloc]. *)
2065val build_malloc : lltype -> string -> llbuilder -> llvalue
2066
2067(** [build_array_malloc ty val name b] creates an [array malloc]
2068    instruction at the position specified by the instruction builder [b].
2069    See the method [llvm::CallInst::CreateArrayMalloc]. *)
2070val build_array_malloc : lltype -> llvalue -> string -> llbuilder -> llvalue
2071
2072(** [build_free p b] creates a [free]
2073    instruction at the position specified by the instruction builder [b].
2074    See the method [llvm::LLVMBuilder::CreateFree]. *)
2075val build_free : llvalue -> llbuilder -> llvalue
2076
2077(** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
2078    when its input matches the constant [onval].
2079    See the method [llvm::SwitchInst::addCase]. **)
2080val add_case : llvalue -> llvalue -> llbasicblock -> unit
2081
2082(** [switch_default_dest sw] returns the default destination of the [switch]
2083    instruction.
2084    See the method [llvm:;SwitchInst::getDefaultDest]. **)
2085val switch_default_dest : llvalue -> llbasicblock
2086
2087(** [build_indirect_br addr count b] creates a
2088    [indirectbr %addr]
2089    instruction at the position specified by the instruction builder [b] with
2090    space reserved for [count] destinations.
2091    See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
2092val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
2093
2094(** [add_destination br bb] adds the basic block [bb] as a possible branch
2095    location for the indirectbr instruction [br].
2096    See the method [llvm::IndirectBrInst::addDestination]. **)
2097val add_destination : llvalue -> llbasicblock -> unit
2098
2099(** [build_invoke fn args tobb unwindbb name b] creates an
2100    [%name = invoke %fn(args) to %tobb unwind %unwindbb]
2101    instruction at the position specified by the instruction builder [b].
2102    See the method [llvm::LLVMBuilder::CreateInvoke]. *)
2103val build_invoke : llvalue -> llvalue array -> llbasicblock ->
2104                        llbasicblock -> string -> llbuilder -> llvalue
2105
2106(** [build_invoke2 fnty fn args tobb unwindbb name b] creates an
2107    [%name = invoke %fn(args) to %tobb unwind %unwindbb]
2108    instruction at the position specified by the instruction builder [b].
2109    See the method [llvm::LLVMBuilder::CreateInvoke]. *)
2110val build_invoke2 : lltype -> llvalue -> llvalue array -> llbasicblock ->
2111                        llbasicblock -> string -> llbuilder -> llvalue
2112
2113(** [build_landingpad ty persfn numclauses name b] creates an
2114    [landingpad]
2115    instruction at the position specified by the instruction builder [b].
2116    See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
2117val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
2118                         llvalue
2119
2120(** [is_cleanup lp] returns [true] if [landingpad] instruction lp is a cleanup.
2121    See the method [llvm::LandingPadInst::isCleanup]. *)
2122val is_cleanup : llvalue -> bool
2123
2124(** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
2125    See the method [llvm::LandingPadInst::setCleanup]. *)
2126val set_cleanup : llvalue -> bool -> unit
2127
2128(** [add_clause lp clause] adds the clause to the [landingpad]instruction.
2129    See the method [llvm::LandingPadInst::addClause]. *)
2130val add_clause : llvalue -> llvalue -> unit
2131
2132(** [build_resume exn b] builds a [resume exn] instruction
2133    at the position specified by the instruction builder [b].
2134    See the method [llvm::LLVMBuilder::CreateResume] *)
2135val build_resume : llvalue -> llbuilder -> llvalue
2136
2137(** [build_unreachable b] creates an
2138    [unreachable]
2139    instruction at the position specified by the instruction builder [b].
2140    See the method [llvm::LLVMBuilder::CreateUnwind]. *)
2141val build_unreachable : llbuilder -> llvalue
2142
2143
2144(** {7 Arithmetic} *)
2145
2146(** [build_add x y name b] creates a
2147    [%name = add %x, %y]
2148    instruction at the position specified by the instruction builder [b].
2149    See the method [llvm::LLVMBuilder::CreateAdd]. *)
2150val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
2151
2152(** [build_nsw_add x y name b] creates a
2153    [%name = nsw add %x, %y]
2154    instruction at the position specified by the instruction builder [b].
2155    See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
2156val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
2157
2158(** [build_nuw_add x y name b] creates a
2159    [%name = nuw add %x, %y]
2160    instruction at the position specified by the instruction builder [b].
2161    See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
2162val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
2163
2164(** [build_fadd x y name b] creates a
2165    [%name = fadd %x, %y]
2166    instruction at the position specified by the instruction builder [b].
2167    See the method [llvm::LLVMBuilder::CreateFAdd]. *)
2168val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
2169
2170(** [build_sub x y name b] creates a
2171    [%name = sub %x, %y]
2172    instruction at the position specified by the instruction builder [b].
2173    See the method [llvm::LLVMBuilder::CreateSub]. *)
2174val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
2175
2176(** [build_nsw_sub x y name b] creates a
2177    [%name = nsw sub %x, %y]
2178    instruction at the position specified by the instruction builder [b].
2179    See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
2180val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
2181
2182(** [build_nuw_sub x y name b] creates a
2183    [%name = nuw sub %x, %y]
2184    instruction at the position specified by the instruction builder [b].
2185    See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
2186val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
2187
2188(** [build_fsub x y name b] creates a
2189    [%name = fsub %x, %y]
2190    instruction at the position specified by the instruction builder [b].
2191    See the method [llvm::LLVMBuilder::CreateFSub]. *)
2192val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
2193
2194(** [build_mul x y name b] creates a
2195    [%name = mul %x, %y]
2196    instruction at the position specified by the instruction builder [b].
2197    See the method [llvm::LLVMBuilder::CreateMul]. *)
2198val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
2199
2200(** [build_nsw_mul x y name b] creates a
2201    [%name = nsw mul %x, %y]
2202    instruction at the position specified by the instruction builder [b].
2203    See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
2204val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
2205
2206(** [build_nuw_mul x y name b] creates a
2207    [%name = nuw mul %x, %y]
2208    instruction at the position specified by the instruction builder [b].
2209    See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
2210val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
2211
2212(** [build_fmul x y name b] creates a
2213    [%name = fmul %x, %y]
2214    instruction at the position specified by the instruction builder [b].
2215    See the method [llvm::LLVMBuilder::CreateFMul]. *)
2216val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
2217
2218(** [build_udiv x y name b] creates a
2219    [%name = udiv %x, %y]
2220    instruction at the position specified by the instruction builder [b].
2221    See the method [llvm::LLVMBuilder::CreateUDiv]. *)
2222val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2223
2224(** [build_sdiv x y name b] creates a
2225    [%name = sdiv %x, %y]
2226    instruction at the position specified by the instruction builder [b].
2227    See the method [llvm::LLVMBuilder::CreateSDiv]. *)
2228val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2229
2230(** [build_exact_sdiv x y name b] creates a
2231    [%name = exact sdiv %x, %y]
2232    instruction at the position specified by the instruction builder [b].
2233    See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
2234val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2235
2236(** [build_fdiv x y name b] creates a
2237    [%name = fdiv %x, %y]
2238    instruction at the position specified by the instruction builder [b].
2239    See the method [llvm::LLVMBuilder::CreateFDiv]. *)
2240val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2241
2242(** [build_urem x y name b] creates a
2243    [%name = urem %x, %y]
2244    instruction at the position specified by the instruction builder [b].
2245    See the method [llvm::LLVMBuilder::CreateURem]. *)
2246val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2247
2248(** [build_SRem x y name b] creates a
2249    [%name = srem %x, %y]
2250    instruction at the position specified by the instruction builder [b].
2251    See the method [llvm::LLVMBuilder::CreateSRem]. *)
2252val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2253
2254(** [build_frem x y name b] creates a
2255    [%name = frem %x, %y]
2256    instruction at the position specified by the instruction builder [b].
2257    See the method [llvm::LLVMBuilder::CreateFRem]. *)
2258val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2259
2260(** [build_shl x y name b] creates a
2261    [%name = shl %x, %y]
2262    instruction at the position specified by the instruction builder [b].
2263    See the method [llvm::LLVMBuilder::CreateShl]. *)
2264val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
2265
2266(** [build_lshr x y name b] creates a
2267    [%name = lshr %x, %y]
2268    instruction at the position specified by the instruction builder [b].
2269    See the method [llvm::LLVMBuilder::CreateLShr]. *)
2270val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
2271
2272(** [build_ashr x y name b] creates a
2273    [%name = ashr %x, %y]
2274    instruction at the position specified by the instruction builder [b].
2275    See the method [llvm::LLVMBuilder::CreateAShr]. *)
2276val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
2277
2278(** [build_and x y name b] creates a
2279    [%name = and %x, %y]
2280    instruction at the position specified by the instruction builder [b].
2281    See the method [llvm::LLVMBuilder::CreateAnd]. *)
2282val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
2283
2284(** [build_or x y name b] creates a
2285    [%name = or %x, %y]
2286    instruction at the position specified by the instruction builder [b].
2287    See the method [llvm::LLVMBuilder::CreateOr]. *)
2288val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
2289
2290(** [build_xor x y name b] creates a
2291    [%name = xor %x, %y]
2292    instruction at the position specified by the instruction builder [b].
2293    See the method [llvm::LLVMBuilder::CreateXor]. *)
2294val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
2295
2296(** [build_neg x name b] creates a
2297    [%name = sub 0, %x]
2298    instruction at the position specified by the instruction builder [b].
2299    [-0.0] is used for floating point types to compute the correct sign.
2300    See the method [llvm::LLVMBuilder::CreateNeg]. *)
2301val build_neg : llvalue -> string -> llbuilder -> llvalue
2302
2303(** [build_nsw_neg x name b] creates a
2304    [%name = nsw sub 0, %x]
2305    instruction at the position specified by the instruction builder [b].
2306    [-0.0] is used for floating point types to compute the correct sign.
2307    See the method [llvm::LLVMBuilder::CreateNeg]. *)
2308val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
2309
2310(** [build_nuw_neg x name b] creates a
2311    [%name = nuw sub 0, %x]
2312    instruction at the position specified by the instruction builder [b].
2313    [-0.0] is used for floating point types to compute the correct sign.
2314    See the method [llvm::LLVMBuilder::CreateNeg]. *)
2315val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
2316
2317(** [build_fneg x name b] creates a
2318    [%name = fsub 0, %x]
2319    instruction at the position specified by the instruction builder [b].
2320    [-0.0] is used for floating point types to compute the correct sign.
2321    See the method [llvm::LLVMBuilder::CreateFNeg]. *)
2322val build_fneg : llvalue -> string -> llbuilder -> llvalue
2323
2324(** [build_xor x name b] creates a
2325    [%name = xor %x, -1]
2326    instruction at the position specified by the instruction builder [b].
2327    [-1] is the correct "all ones" value for the type of [x].
2328    See the method [llvm::LLVMBuilder::CreateXor]. *)
2329val build_not : llvalue -> string -> llbuilder -> llvalue
2330
2331
2332(** {7 Memory} *)
2333
2334(** [build_alloca ty name b] creates a
2335    [%name = alloca %ty]
2336    instruction at the position specified by the instruction builder [b].
2337    See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2338val build_alloca : lltype -> string -> llbuilder -> llvalue
2339
2340(** [build_array_alloca ty n name b] creates a
2341    [%name = alloca %ty, %n]
2342    instruction at the position specified by the instruction builder [b].
2343    See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2344val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
2345                              llvalue
2346
2347(** [build_load v name b] creates a
2348    [%name = load %v]
2349    instruction at the position specified by the instruction builder [b].
2350    See the method [llvm::LLVMBuilder::CreateLoad]. *)
2351val build_load : llvalue -> string -> llbuilder -> llvalue
2352
2353(** [build_load2 ty v name b] creates a
2354    [%name = load %ty, %v]
2355    instruction at the position specified by the instruction builder [b].
2356    See the method [llvm::LLVMBuilder::CreateLoad]. *)
2357val build_load2 : lltype -> llvalue -> string -> llbuilder -> llvalue
2358
2359(** [build_store v p b] creates a
2360    [store %v, %p]
2361    instruction at the position specified by the instruction builder [b].
2362    See the method [llvm::LLVMBuilder::CreateStore]. *)
2363val build_store : llvalue -> llvalue -> llbuilder -> llvalue
2364
2365(** [build_atomicrmw op ptr val o st b] creates an [atomicrmw] instruction with
2366    operation [op] performed on pointer [ptr] and value [val] with ordering [o]
2367    and singlethread flag set to [st] at the position specified by
2368    the instruction builder [b].
2369    See the method [llvm::IRBuilder::CreateAtomicRMW]. *)
2370val build_atomicrmw : AtomicRMWBinOp.t -> llvalue -> llvalue ->
2371                      AtomicOrdering.t -> bool -> string -> llbuilder -> llvalue
2372
2373(** [build_gep p indices name b] creates a
2374    [%name = getelementptr %p, indices...]
2375    instruction at the position specified by the instruction builder [b].
2376    See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
2377val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2378
2379(** [build_gep2 srcty p indices name b] creates a
2380    [%name = getelementptr srcty, %p, indices...]
2381    instruction at the position specified by the instruction builder [b].
2382    See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
2383val build_gep2 : lltype -> llvalue -> llvalue array -> string -> llbuilder ->
2384                       llvalue
2385
2386(** [build_in_bounds_gep p indices name b] creates a
2387    [%name = gelementptr inbounds %p, indices...]
2388    instruction at the position specified by the instruction builder [b].
2389    See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
2390val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
2391                               llvalue
2392
2393(** [build_in_bounds_gep2 srcty p indices name b] creates a
2394    [%name = gelementptr inbounds srcty, %p, indices...]
2395    instruction at the position specified by the instruction builder [b].
2396    See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
2397val build_in_bounds_gep2 : lltype -> llvalue -> llvalue array -> string ->
2398                                llbuilder -> llvalue
2399
2400(** [build_struct_gep p idx name b] creates a
2401    [%name = getelementptr %p, 0, idx]
2402    instruction at the position specified by the instruction builder [b].
2403    See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
2404val build_struct_gep : llvalue -> int -> string -> llbuilder ->
2405                            llvalue
2406
2407(** [build_struct_gep2 srcty p idx name b] creates a
2408    [%name = getelementptr srcty, %p, 0, idx]
2409    instruction at the position specified by the instruction builder [b].
2410    See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
2411val build_struct_gep2 : lltype -> llvalue -> int -> string -> llbuilder ->
2412                            llvalue
2413
2414(** [build_global_string str name b] creates a series of instructions that adds
2415    a global string at the position specified by the instruction builder [b].
2416    See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
2417val build_global_string : string -> string -> llbuilder -> llvalue
2418
2419(** [build_global_stringptr str name b] creates a series of instructions that
2420    adds a global string pointer at the position specified by the instruction
2421    builder [b].
2422    See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
2423val build_global_stringptr : string -> string -> llbuilder -> llvalue
2424
2425
2426(** {7 Casts} *)
2427
2428(** [build_trunc v ty name b] creates a
2429    [%name = trunc %p to %ty]
2430    instruction at the position specified by the instruction builder [b].
2431    See the method [llvm::LLVMBuilder::CreateTrunc]. *)
2432val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2433
2434(** [build_zext v ty name b] creates a
2435    [%name = zext %p to %ty]
2436    instruction at the position specified by the instruction builder [b].
2437    See the method [llvm::LLVMBuilder::CreateZExt]. *)
2438val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
2439
2440(** [build_sext v ty name b] creates a
2441    [%name = sext %p to %ty]
2442    instruction at the position specified by the instruction builder [b].
2443    See the method [llvm::LLVMBuilder::CreateSExt]. *)
2444val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
2445
2446(** [build_fptoui v ty name b] creates a
2447    [%name = fptoui %p to %ty]
2448    instruction at the position specified by the instruction builder [b].
2449    See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
2450val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
2451
2452(** [build_fptosi v ty name b] creates a
2453    [%name = fptosi %p to %ty]
2454    instruction at the position specified by the instruction builder [b].
2455    See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
2456val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
2457
2458(** [build_uitofp v ty name b] creates a
2459    [%name = uitofp %p to %ty]
2460    instruction at the position specified by the instruction builder [b].
2461    See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
2462val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2463
2464(** [build_sitofp v ty name b] creates a
2465    [%name = sitofp %p to %ty]
2466    instruction at the position specified by the instruction builder [b].
2467    See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
2468val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2469
2470(** [build_fptrunc v ty name b] creates a
2471    [%name = fptrunc %p to %ty]
2472    instruction at the position specified by the instruction builder [b].
2473    See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
2474val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2475
2476(** [build_fpext v ty name b] creates a
2477    [%name = fpext %p to %ty]
2478    instruction at the position specified by the instruction builder [b].
2479    See the method [llvm::LLVMBuilder::CreateFPExt]. *)
2480val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
2481
2482(** [build_ptrtoint v ty name b] creates a
2483    [%name = prtotint %p to %ty]
2484    instruction at the position specified by the instruction builder [b].
2485    See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2486val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2487
2488(** [build_inttoptr v ty name b] creates a
2489    [%name = inttoptr %p to %ty]
2490    instruction at the position specified by the instruction builder [b].
2491    See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2492val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2493
2494(** [build_bitcast v ty name b] creates a
2495    [%name = bitcast %p to %ty]
2496    instruction at the position specified by the instruction builder [b].
2497    See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2498val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2499
2500(** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2501    instruction at the position specified by the instruction builder [b].
2502    See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2503val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2504                                 llvalue
2505
2506(** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2507    instruction at the position specified by the instruction builder [b].
2508    See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2509val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2510                                 llvalue
2511
2512(** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2513    instruction at the position specified by the instruction builder [b].
2514    See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2515val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2516                                  llvalue
2517
2518(** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2519    instruction at the position specified by the instruction builder [b].
2520    See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2521val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2522
2523(** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2524    instruction at the position specified by the instruction builder [b].
2525    See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2526val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2527
2528(** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2529    instruction at the position specified by the instruction builder [b].
2530    See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2531val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2532
2533
2534(** {7 Comparisons} *)
2535
2536(** [build_icmp pred x y name b] creates a
2537    [%name = icmp %pred %x, %y]
2538    instruction at the position specified by the instruction builder [b].
2539    See the method [llvm::LLVMBuilder::CreateICmp]. *)
2540val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2541                      llbuilder -> llvalue
2542
2543(** [build_fcmp pred x y name b] creates a
2544    [%name = fcmp %pred %x, %y]
2545    instruction at the position specified by the instruction builder [b].
2546    See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2547val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2548                      llbuilder -> llvalue
2549
2550
2551(** {7 Miscellaneous instructions} *)
2552
2553(** [build_phi incoming name b] creates a
2554    [%name = phi %incoming]
2555    instruction at the position specified by the instruction builder [b].
2556    [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2557    See the method [llvm::LLVMBuilder::CreatePHI]. *)
2558val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2559                     llvalue
2560
2561(** [build_empty_phi ty name b] creates a
2562    [%name = phi %ty] instruction at the position specified by
2563    the instruction builder [b]. [ty] is the type of the instruction.
2564    See the method [llvm::LLVMBuilder::CreatePHI]. *)
2565val build_empty_phi : lltype -> string -> llbuilder -> llvalue
2566
2567(** [build_call fn args name b] creates a
2568    [%name = call %fn(args...)]
2569    instruction at the position specified by the instruction builder [b].
2570    See the method [llvm::LLVMBuilder::CreateCall]. *)
2571val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2572
2573(** [build_call2 fnty fn args name b] creates a
2574    [%name = call %fn(args...)]
2575    instruction at the position specified by the instruction builder [b].
2576    See the method [llvm::LLVMBuilder::CreateCall]. *)
2577val build_call2 : lltype -> llvalue -> llvalue array -> string -> llbuilder ->
2578                        llvalue
2579
2580(** [build_select cond thenv elsev name b] creates a
2581    [%name = select %cond, %thenv, %elsev]
2582    instruction at the position specified by the instruction builder [b].
2583    See the method [llvm::LLVMBuilder::CreateSelect]. *)
2584val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2585                        llvalue
2586
2587(** [build_va_arg valist argty name b] creates a
2588    [%name = va_arg %valist, %argty]
2589    instruction at the position specified by the instruction builder [b].
2590    See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2591val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2592
2593(** [build_extractelement vec i name b] creates a
2594    [%name = extractelement %vec, %i]
2595    instruction at the position specified by the instruction builder [b].
2596    See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2597val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2598                                llvalue
2599
2600(** [build_insertelement vec elt i name b] creates a
2601    [%name = insertelement %vec, %elt, %i]
2602    instruction at the position specified by the instruction builder [b].
2603    See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2604val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2605                               llbuilder -> llvalue
2606
2607(** [build_shufflevector veca vecb mask name b] creates a
2608    [%name = shufflevector %veca, %vecb, %mask]
2609    instruction at the position specified by the instruction builder [b].
2610    See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2611val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2612                               llbuilder -> llvalue
2613
2614(** [build_extractvalue agg idx name b] creates a
2615    [%name = extractvalue %agg, %idx]
2616    instruction at the position specified by the instruction builder [b].
2617    See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2618val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2619
2620
2621(** [build_insertvalue agg val idx name b] creates a
2622    [%name = insertvalue %agg, %val, %idx]
2623    instruction at the position specified by the instruction builder [b].
2624    See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2625val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2626                             llvalue
2627
2628(** [build_is_null val name b] creates a
2629    [%name = icmp eq %val, null]
2630    instruction at the position specified by the instruction builder [b].
2631    See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2632val build_is_null : llvalue -> string -> llbuilder -> llvalue
2633
2634(** [build_is_not_null val name b] creates a
2635    [%name = icmp ne %val, null]
2636    instruction at the position specified by the instruction builder [b].
2637    See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2638val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2639
2640(** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2641    the difference between two pointer values at the position specified by the
2642    instruction builder [b].
2643    See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2644val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2645
2646(** [build_ptrdiff2 elemty lhs rhs name b] creates a series of instructions
2647    that measure the difference between two pointer values in multiples of
2648    [elemty] at the position specified by the instruction builder [b].
2649    See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2650val build_ptrdiff2 : lltype -> llvalue -> llvalue -> string -> llbuilder ->
2651                     llvalue
2652
2653(** [build_freeze x name b] creates a
2654    [%name = freeze %x]
2655    instruction at the position specified by the instruction builder [b].
2656    See the method [llvm::LLVMBuilder::CreateFreeze]. *)
2657val build_freeze : llvalue -> string -> llbuilder -> llvalue
2658
2659
2660(** {6 Memory buffers} *)
2661
2662module MemoryBuffer : sig
2663  (** [of_file p] is the memory buffer containing the contents of the file at
2664      path [p]. If the file could not be read, then [IoError msg] is
2665      raised. *)
2666  val of_file : string -> llmemorybuffer
2667
2668  (** [of_stdin ()] is the memory buffer containing the contents of standard input.
2669      If standard input is empty, then [IoError msg] is raised. *)
2670  val of_stdin : unit -> llmemorybuffer
2671
2672  (** [of_string ~name s] is the memory buffer containing the contents of string [s].
2673      The name of memory buffer is set to [name] if it is provided. *)
2674  val of_string : ?name:string -> string -> llmemorybuffer
2675
2676  (** [as_string mb] is the string containing the contents of memory buffer [mb]. *)
2677  val as_string : llmemorybuffer -> string
2678
2679  (** Disposes of a memory buffer. *)
2680  val dispose : llmemorybuffer -> unit
2681end
2682
2683
2684(** {6 Pass Managers} *)
2685
2686module PassManager : sig
2687  (**  *)
2688  type 'a t
2689  type any = [ `Module | `Function ]
2690
2691  (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2692      type of pipeline is suitable for link-time optimization and whole-module
2693      transformations.
2694      See the constructor of [llvm::PassManager]. *)
2695  val create : unit -> [ `Module ] t
2696
2697  (** [PassManager.create_function m] constructs a new function-by-function
2698      pass pipeline over the module [m]. It does not take ownership of [m].
2699      This type of pipeline is suitable for code generation and JIT compilation
2700      tasks.
2701      See the constructor of [llvm::FunctionPassManager]. *)
2702  val create_function : llmodule -> [ `Function ] t
2703
2704  (** [run_module m pm] initializes, executes on the module [m], and finalizes
2705      all of the passes scheduled in the pass manager [pm]. Returns [true] if
2706      any of the passes modified the module, [false] otherwise.
2707      See the [llvm::PassManager::run] method. *)
2708  val run_module : llmodule -> [ `Module ] t -> bool
2709
2710  (** [initialize fpm] initializes all of the function passes scheduled in the
2711      function pass manager [fpm]. Returns [true] if any of the passes modified
2712      the module, [false] otherwise.
2713      See the [llvm::FunctionPassManager::doInitialization] method. *)
2714  val initialize : [ `Function ] t -> bool
2715
2716  (** [run_function f fpm] executes all of the function passes scheduled in the
2717      function pass manager [fpm] over the function [f]. Returns [true] if any
2718      of the passes modified [f], [false] otherwise.
2719      See the [llvm::FunctionPassManager::run] method. *)
2720  val run_function : llvalue -> [ `Function ] t -> bool
2721
2722  (** [finalize fpm] finalizes all of the function passes scheduled in the
2723      function pass manager [fpm]. Returns [true] if any of the passes
2724      modified the module, [false] otherwise.
2725      See the [llvm::FunctionPassManager::doFinalization] method. *)
2726  val finalize : [ `Function ] t -> bool
2727
2728  (** Frees the memory of a pass pipeline. For function pipelines, does not free
2729      the module.
2730      See the destructor of [llvm::BasePassManager]. *)
2731  val dispose : [< any ] t -> unit
2732end
2733