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