1 (*===-- llvm/llvm.mli - LLVM OCaml Interface ------------------------------===*
3 * The LLVM Compiler Infrastructure
5 * This file is distributed under the University of Illinois Open Source
6 * License. See LICENSE.TXT for details.
8 *===----------------------------------------------------------------------===*)
12 This interface provides an OCaml API for the LLVM intermediate
13 representation, the classes in the VMCore library. *)
16 (** {6 Abstract types}
18 These abstract types correlate directly to the LLVM VMCore classes. *)
20 (** The top-level container for all LLVM global data. See the
21 [llvm::LLVMContext] class. *)
24 (** The top-level container for all other LLVM Intermediate Representation (IR)
25 objects. See the [llvm::Module] class. *)
28 (** Each value in the LLVM IR has a type, an instance of [lltype]. See the
29 [llvm::Type] class. *)
32 (** Any value in the LLVM IR. Functions, instructions, global variables,
33 constants, and much more are all [llvalues]. See the [llvm::Value] class.
34 This type covers a wide range of subclasses. *)
37 (** Used to store users and usees of values. See the [llvm::Use] class. *)
40 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *)
43 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
47 (** Used to efficiently handle large buffers of read-only binary data.
48 See the [llvm::MemoryBuffer] class. *)
51 (** The kind id of metadata attached to an instruction. *)
54 (** The kind of an [lltype], the result of [classify_type ty]. See the
55 [llvm::Type::TypeID] enumeration. *)
76 (** The linkage of a global value, accessed with {!linkage} and
77 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
81 | Available_externally
84 | Link_once_odr_auto_hide
99 (** The linker visibility of a global value, accessed with {!visibility} and
100 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
101 module Visibility : sig
108 (** The following calling convention values may be accessed with
109 {!function_call_conv} and {!set_function_call_conv}. Calling
110 conventions are open-ended. *)
111 module CallConv : sig
112 val c : int (** [c] is the C calling convention. *)
113 val fast : int (** [fast] is the calling convention to allow LLVM
114 maximum optimization opportunities. Use only with
116 val cold : int (** [cold] is the calling convention for
118 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling
119 convention from C. *)
120 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
121 convention from C. *)
124 (** The attribute kind of a function parameter, result or the function itself.
125 See [llvm::Attribute::AttrKind]. *)
126 module Attribute : sig
150 | Stackalignment of int
156 (** The predicate for an integer comparison ([icmp]) instruction.
157 See the [llvm::ICmpInst::Predicate] enumeration. *)
161 | Ne (** Not equal *)
162 | Ugt (** Unsigned greater than *)
163 | Uge (** Unsigned greater or equal *)
164 | Ult (** Unsigned less than *)
165 | Ule (** Unsigned less or equal *)
166 | Sgt (** Signed greater than *)
167 | Sge (** Signed greater or equal *)
168 | Slt (** Signed less than *)
169 | Sle (** Signed less or equal *)
172 (** The predicate for a floating-point comparison ([fcmp]) instruction.
173 Ordered means that neither operand is a QNAN while unordered means
174 that either operand may be a QNAN.
175 See the [llvm::FCmpInst::Predicate] enumeration. *)
178 | False (** Always false *)
179 | Oeq (** Ordered and equal *)
180 | Ogt (** Ordered and greater than *)
181 | Oge (** Ordered and greater or equal *)
182 | Olt (** Ordered and less than *)
183 | Ole (** Ordered and less or equal *)
184 | One (** Ordered and not equal *)
185 | Ord (** Ordered (no operand is NaN) *)
186 | Uno (** Unordered (one operand at least is NaN) *)
187 | Ueq (** Unordered and equal *)
188 | Ugt (** Unordered and greater than *)
189 | Uge (** Unordered and greater or equal *)
190 | Ult (** Unordered and less than *)
191 | Ule (** Unordered and less or equal *)
192 | Une (** Unordered and not equal *)
193 | True (** Always true *)
196 (** The opcodes for LLVM instructions and constant expressions. *)
199 | Invalid (** Not an instruction *)
201 | Ret (** Terminator Instructions *)
209 | Add (** Standard Binary Operators *)
222 | Shl (** Logical Operators *)
229 | Alloca (** Memory Operators *)
234 | Trunc (** Cast Operators *)
247 | ICmp (** Other Operators *)
267 (** The type of a clause of a [landingpad] instruction.
268 See [llvm::LandingPadInst::ClauseType]. *)
269 module LandingPadClauseTy : sig
275 (** The thread local mode of a global value, accessed with {!thread_local_mode}
276 and {!set_thread_local_mode}.
277 See [llvm::GlobalVariable::ThreadLocalMode]. *)
278 module ThreadLocalMode : sig
287 (** The ordering of an atomic [load], [store], [cmpxchg], [atomicrmw] or
288 [fence] instruction. See [llvm::AtomicOrdering]. *)
289 module AtomicOrdering : sig
294 | Invalid (** removed due to API changes *)
298 | SequentiallyConsistent
301 (** The opcode of an [atomicrmw] instruction.
302 See [llvm::AtomicRMWInst::BinOp]. *)
303 module AtomicRMWBinOp : sig
318 (** The kind of an [llvalue], the result of [classify_value v].
319 See the various [LLVMIsA*] functions. *)
320 module ValueKind : sig
329 | ConstantAggregateZero
336 | ConstantPointerNull
343 | Instruction of Opcode.t
349 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
350 of [a]. [llpos] is used to specify positions in and for forward iteration
351 through the various value lists maintained by the LLVM IR. *)
352 type ('a, 'b) llpos =
356 (** [After b] and [At_start a] specify positions from the end of the ['b] list
357 of [a]. [llrev_pos] is used for reverse iteration through the various value
358 lists maintained by the LLVM IR. *)
359 type ('a, 'b) llrev_pos =
364 (** {6 Exceptions} *)
366 exception IoError of string
369 (** {6 Global configuration} *)
371 (** [enable_pretty_stacktraces ()] enables LLVM's built-in stack trace code.
372 This intercepts the OS's crash signals and prints which component of LLVM
373 you were in at the time of the crash. *)
374 val enable_pretty_stacktrace : unit -> unit
376 (** [install_fatal_error_handler f] installs [f] as LLVM's fatal error handler.
377 The handler will receive the reason for termination as a string. After
378 the handler has been executed, LLVM calls [exit(1)]. *)
379 val install_fatal_error_handler : (string -> unit) -> unit
381 (** [reset_fatal_error_handler ()] resets LLVM's fatal error handler. *)
382 val reset_fatal_error_handler : unit -> unit
384 (** [parse_command_line_options ?overview args] parses [args] using
385 the LLVM command line parser. Note that the only stable thing about this
386 function is its signature; you cannot rely on any particular set of command
387 line arguments being interpreted the same way across LLVM versions.
389 See the function [llvm::cl::ParseCommandLineOptions()]. *)
390 val parse_command_line_options : ?overview:string -> string array -> unit
394 (** [create_context ()] creates a context for storing the "global" state in
395 LLVM. See the constructor [llvm::LLVMContext]. *)
396 val create_context : unit -> llcontext
398 (** [destroy_context ()] destroys a context. See the destructor
399 [llvm::LLVMContext::~LLVMContext]. *)
400 val dispose_context : llcontext -> unit
402 (** See the function [llvm::getGlobalContext]. *)
403 val global_context : unit -> llcontext
405 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
406 name [name] in the context [context]. See the function
407 [llvm::LLVMContext::getMDKindID]. *)
408 val mdkind_id : llcontext -> string -> llmdkind
413 (** [create_module context id] creates a module with the supplied module ID in
414 the context [context]. Modules are not garbage collected; it is mandatory
415 to call {!dispose_module} to free memory. See the constructor
416 [llvm::Module::Module]. *)
417 val create_module : llcontext -> string -> llmodule
419 (** [dispose_module m] destroys a module [m] and all of the IR objects it
420 contained. All references to subordinate objects are invalidated;
421 referencing them will invoke undefined behavior. See the destructor
422 [llvm::Module::~Module]. *)
423 val dispose_module : llmodule -> unit
425 (** [target_triple m] is the target specifier for the module [m], something like
426 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
427 val target_triple: llmodule -> string
429 (** [target_triple triple m] changes the target specifier for the module [m] to
430 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
431 val set_target_triple: string -> llmodule -> unit
433 (** [data_layout m] is the data layout specifier for the module [m], something
434 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
435 method [llvm::Module::getDataLayout]. *)
436 val data_layout: llmodule -> string
438 (** [set_data_layout s m] changes the data layout specifier for the module [m]
439 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
440 val set_data_layout: string -> llmodule -> unit
442 (** [dump_module m] prints the .ll representation of the module [m] to standard
443 error. See the method [llvm::Module::dump]. *)
444 val dump_module : llmodule -> unit
446 (** [print_module f m] prints the .ll representation of the module [m]
447 to file [f]. See the method [llvm::Module::print]. *)
448 val print_module : string -> llmodule -> unit
450 (** [string_of_llmodule m] returns the .ll representation of the module [m]
451 as a string. See the method [llvm::Module::print]. *)
452 val string_of_llmodule : llmodule -> string
454 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
455 the method [llvm::Module::setModuleInlineAsm]. *)
456 val set_module_inline_asm : llmodule -> string -> unit
458 (** [module_context m] returns the context of the specified module.
459 See the method [llvm::Module::getContext] *)
460 val module_context : llmodule -> llcontext
465 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
466 See the method [llvm::Type::getTypeID]. *)
467 val classify_type : lltype -> TypeKind.t
469 (** [type_is_sized ty] returns whether the type has a size or not.
470 If it doesn't then it is not safe to call the [DataLayout::] methods on it.
472 val type_is_sized : lltype -> bool
474 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
475 See the method [llvm::Type::getContext]. *)
476 val type_context : lltype -> llcontext
478 (** [dump_type ty] prints the .ll representation of the type [ty] to standard
479 error. See the method [llvm::Type::dump]. *)
480 val dump_type : lltype -> unit
482 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
483 val string_of_lltype : lltype -> string
486 (** {7 Operations on integer types} *)
488 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
489 [llvm::Type::Int1Ty]. *)
490 val i1_type : llcontext -> lltype
492 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
493 [llvm::Type::Int8Ty]. *)
494 val i8_type : llcontext -> lltype
496 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
497 [llvm::Type::Int16Ty]. *)
498 val i16_type : llcontext -> lltype
500 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
501 [llvm::Type::Int32Ty]. *)
502 val i32_type : llcontext -> lltype
504 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
505 [llvm::Type::Int64Ty]. *)
506 val i64_type : llcontext -> lltype
508 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
509 [c]. See the method [llvm::IntegerType::get]. *)
510 val integer_type : llcontext -> int -> lltype
512 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
513 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
514 val integer_bitwidth : lltype -> int
517 (** {7 Operations on real types} *)
519 (** [float_type c] returns the IEEE 32-bit floating point type in the context
520 [c]. See [llvm::Type::FloatTy]. *)
521 val float_type : llcontext -> lltype
523 (** [double_type c] returns the IEEE 64-bit floating point type in the context
524 [c]. See [llvm::Type::DoubleTy]. *)
525 val double_type : llcontext -> lltype
527 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
528 [c]. See [llvm::Type::X86_FP80Ty]. *)
529 val x86fp80_type : llcontext -> lltype
531 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
532 [c]. See [llvm::Type::FP128Ty]. *)
533 val fp128_type : llcontext -> lltype
535 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
536 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
537 val ppc_fp128_type : llcontext -> lltype
540 (** {7 Operations on function types} *)
542 (** [function_type ret_ty param_tys] returns the function type returning
543 [ret_ty] and taking [param_tys] as parameters.
544 See the method [llvm::FunctionType::get]. *)
545 val function_type : lltype -> lltype array -> lltype
547 (** [var_arg_function_type ret_ty param_tys] is just like
548 [function_type ret_ty param_tys] except that it returns the function type
549 which also takes a variable number of arguments.
550 See the method [llvm::FunctionType::get]. *)
551 val var_arg_function_type : lltype -> lltype array -> lltype
553 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
554 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
555 val is_var_arg : lltype -> bool
557 (** [return_type fty] gets the return type of the function type [fty].
558 See the method [llvm::FunctionType::getReturnType]. *)
559 val return_type : lltype -> lltype
561 (** [param_types fty] gets the parameter types of the function type [fty].
562 See the method [llvm::FunctionType::getParamType]. *)
563 val param_types : lltype -> lltype array
566 (** {7 Operations on struct types} *)
568 (** [struct_type context tys] returns the structure type in the context
569 [context] containing in the types in the array [tys]. See the method
570 [llvm::StructType::get]. *)
571 val struct_type : llcontext -> lltype array -> lltype
573 (** [packed_struct_type context ys] returns the packed structure type in the
574 context [context] containing in the types in the array [tys]. See the method
575 [llvm::StructType::get]. *)
576 val packed_struct_type : llcontext -> lltype array -> lltype
578 (** [struct_name ty] returns the name of the named structure type [ty],
579 or None if the structure type is not named *)
580 val struct_name : lltype -> string option
582 (** [named_struct_type context name] returns the named structure type [name]
583 in the context [context].
584 See the method [llvm::StructType::get]. *)
585 val named_struct_type : llcontext -> string -> lltype
587 (** [struct_set_body ty elts ispacked] sets the body of the named struct [ty]
588 to the [elts] elements.
589 See the moethd [llvm::StructType::setBody]. *)
590 val struct_set_body : lltype -> lltype array -> bool -> unit
592 (** [struct_element_types sty] returns the constituent types of the struct type
593 [sty]. See the method [llvm::StructType::getElementType]. *)
594 val struct_element_types : lltype -> lltype array
596 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
597 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
598 val is_packed : lltype -> bool
600 (** [is_opaque sty] returns [true] if the structure type [sty] is opaque.
601 [false] otherwise. See the method [llvm::StructType::isOpaque]. *)
602 val is_opaque : lltype -> bool
605 (** {7 Operations on pointer, vector, and array types} *)
607 (** [array_type ty n] returns the array type containing [n] elements of type
608 [ty]. See the method [llvm::ArrayType::get]. *)
609 val array_type : lltype -> int -> lltype
611 (** [pointer_type ty] returns the pointer type referencing objects of type
612 [ty] in the default address space (0).
613 See the method [llvm::PointerType::getUnqual]. *)
614 val pointer_type : lltype -> lltype
616 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
617 of type [ty] in address space [as].
618 See the method [llvm::PointerType::get]. *)
619 val qualified_pointer_type : lltype -> int -> lltype
621 (** [vector_type ty n] returns the array type containing [n] elements of the
622 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
623 val vector_type : lltype -> int -> lltype
625 (** [element_type ty] returns the element type of the pointer, vector, or array
626 type [ty]. See the method [llvm::SequentialType::get]. *)
627 val element_type : lltype -> lltype
629 (** [element_type aty] returns the element count of the array type [aty].
630 See the method [llvm::ArrayType::getNumElements]. *)
631 val array_length : lltype -> int
633 (** [address_space pty] returns the address space qualifier of the pointer type
634 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
635 val address_space : lltype -> int
637 (** [element_type ty] returns the element count of the vector type [ty].
638 See the method [llvm::VectorType::getNumElements]. *)
639 val vector_size : lltype -> int
642 (** {7 Operations on other types} *)
644 (** [void_type c] creates a type of a function which does not return any
645 value in the context [c]. See [llvm::Type::VoidTy]. *)
646 val void_type : llcontext -> lltype
648 (** [label_type c] creates a type of a basic block in the context [c]. See
649 [llvm::Type::LabelTy]. *)
650 val label_type : llcontext -> lltype
652 (** [x86_mmx_type c] returns the x86 64-bit MMX register type in the
653 context [c]. See [llvm::Type::X86_MMXTy]. *)
654 val x86_mmx_type : llcontext -> lltype
656 (** [type_by_name m name] returns the specified type from the current module
658 See the method [llvm::Module::getTypeByName] *)
659 val type_by_name : llmodule -> string -> lltype option
664 (** [type_of v] returns the type of the value [v].
665 See the method [llvm::Value::getType]. *)
666 val type_of : llvalue -> lltype
668 (** [classify_value v] returns the kind of the value [v]. *)
669 val classify_value : llvalue -> ValueKind.t
671 (** [value_name v] returns the name of the value [v]. For global values, this is
672 the symbol name. For instructions and basic blocks, it is the SSA register
673 name. It is meaningless for constants.
674 See the method [llvm::Value::getName]. *)
675 val value_name : llvalue -> string
677 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
678 [llvm::Value::setName]. *)
679 val set_value_name : string -> llvalue -> unit
681 (** [dump_value v] prints the .ll representation of the value [v] to standard
682 error. See the method [llvm::Value::dump]. *)
683 val dump_value : llvalue -> unit
685 (** [string_of_llvalue v] returns a string describing the value [v]. *)
686 val string_of_llvalue : llvalue -> string
688 (** [replace_all_uses_with old new] replaces all uses of the value [old]
689 with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
690 val replace_all_uses_with : llvalue -> llvalue -> unit
695 (** [use_begin v] returns the first position in the use list for the value [v].
696 [use_begin] and [use_succ] can e used to iterate over the use list in order.
697 See the method [llvm::Value::use_begin]. *)
698 val use_begin : llvalue -> lluse option
700 (** [use_succ u] returns the use list position succeeding [u].
701 See the method [llvm::use_value_iterator::operator++]. *)
702 val use_succ : lluse -> lluse option
704 (** [user u] returns the user of the use [u].
705 See the method [llvm::Use::getUser]. *)
706 val user : lluse -> llvalue
708 (** [used_value u] returns the usee of the use [u].
709 See the method [llvm::Use::getUsedValue]. *)
710 val used_value : lluse -> llvalue
712 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
713 in order. Tail recursive. *)
714 val iter_uses : (lluse -> unit) -> llvalue -> unit
716 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
717 [u1,...,uN] are the users of the value [v]. Tail recursive. *)
718 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
720 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
721 [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
722 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
727 (** [operand v i] returns the operand at index [i] for the value [v]. See the
728 method [llvm::User::getOperand]. *)
729 val operand : llvalue -> int -> llvalue
731 (** [operand_use v i] returns the use of the operand at index [i] for the value [v]. See the
732 method [llvm::User::getOperandUse]. *)
733 val operand_use : llvalue -> int -> lluse
736 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
738 See the method [llvm::User::setOperand]. *)
739 val set_operand : llvalue -> int -> llvalue -> unit
741 (** [num_operands v] returns the number of operands for the value [v].
742 See the method [llvm::User::getNumOperands]. *)
743 val num_operands : llvalue -> int
746 (** {7 Operations on constants of (mostly) any type} *)
748 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
749 otherwise. Similar to [llvm::isa<Constant>]. *)
750 val is_constant : llvalue -> bool
752 (** [const_null ty] returns the constant null (zero) of the type [ty].
753 See the method [llvm::Constant::getNullValue]. *)
754 val const_null : lltype -> llvalue
756 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
757 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
758 val const_all_ones : (*int|vec*)lltype -> llvalue
760 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
761 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
762 val const_pointer_null : lltype -> llvalue
764 (** [undef ty] returns the undefined value of the type [ty].
765 See the method [llvm::UndefValue::get]. *)
766 val undef : lltype -> llvalue
768 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
769 See the method [llvm::Constant::isNullValue]. *)
770 val is_null : llvalue -> bool
772 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
773 otherwise. Similar to [llvm::isa<UndefValue>]. *)
774 val is_undef : llvalue -> bool
776 (** [constexpr_opcode v] returns an [Opcode.t] corresponding to constexpr
777 value [v], or [Opcode.Invalid] if [v] is not a constexpr. *)
778 val constexpr_opcode : llvalue -> Opcode.t
781 (** {7 Operations on instructions} *)
783 (** [has_metadata i] returns whether or not the instruction [i] has any
784 metadata attached to it. See the function
785 [llvm::Instruction::hasMetadata]. *)
786 val has_metadata : llvalue -> bool
788 (** [metadata i kind] optionally returns the metadata associated with the
789 kind [kind] in the instruction [i] See the function
790 [llvm::Instruction::getMetadata]. *)
791 val metadata : llvalue -> llmdkind -> llvalue option
793 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
794 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
795 val set_metadata : llvalue -> llmdkind -> llvalue -> unit
797 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
798 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
799 val clear_metadata : llvalue -> llmdkind -> unit
802 (** {7 Operations on metadata} *)
804 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
805 See the method [llvm::MDNode::get]. *)
806 val mdstring : llcontext -> string -> llvalue
808 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
810 See the method [llvm::MDNode::get]. *)
811 val mdnode : llcontext -> llvalue array -> llvalue
813 (** [get_mdstring v] returns the MDString.
814 See the method [llvm::MDString::getString] *)
815 val get_mdstring : llvalue -> string option
817 (** [get_named_metadata m name] returns all the MDNodes belonging to the named
819 See the method [llvm::NamedMDNode::getOperand]. *)
820 val get_named_metadata : llmodule -> string -> llvalue array
822 (** [add_named_metadata_operand m name v] adds [v] as the last operand of
823 metadata named [name] in module [m]. If the metadata does not exist,
825 See the methods [llvm::Module::getNamedMetadata()] and
826 [llvm::MDNode::addOperand()]. *)
827 val add_named_metadata_operand : llmodule -> string -> llvalue -> unit
830 (** {7 Operations on scalar constants} *)
832 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
833 See the method [llvm::ConstantInt::get]. *)
834 val const_int : lltype -> int -> llvalue
836 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
837 [i]. See the method [llvm::ConstantInt::get]. *)
838 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
840 (** [int64_of_const c] returns the int64 value of the [c] constant integer.
841 None is returned if this is not an integer constant, or bitwidth exceeds 64.
842 See the method [llvm::ConstantInt::getSExtValue].*)
843 val int64_of_const : llvalue -> Int64.t option
845 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
846 value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
847 val const_int_of_string : lltype -> string -> int -> llvalue
849 (** [const_float ty n] returns the floating point constant of type [ty] and
850 value [n]. See the method [llvm::ConstantFP::get]. *)
851 val const_float : lltype -> float -> llvalue
853 (** [float_of_const c] returns the float value of the [c] constant float.
854 None is returned if this is not an float constant.
855 See the method [llvm::ConstantFP::getDoubleValue].*)
856 val float_of_const : llvalue -> float option
858 (** [const_float_of_string ty s] returns the floating point constant of type
859 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
860 val const_float_of_string : lltype -> string -> llvalue
862 (** {7 Operations on composite constants} *)
864 (** [const_string c s] returns the constant [i8] array with the values of the
865 characters in the string [s] in the context [c]. The array is not
866 null-terminated (but see {!const_stringz}). This value can in turn be used
867 as the initializer for a global variable. See the method
868 [llvm::ConstantArray::get]. *)
869 val const_string : llcontext -> string -> llvalue
871 (** [const_stringz c s] returns the constant [i8] array with the values of the
872 characters in the string [s] and a null terminator in the context [c]. This
873 value can in turn be used as the initializer for a global variable.
874 See the method [llvm::ConstantArray::get]. *)
875 val const_stringz : llcontext -> string -> llvalue
877 (** [const_array ty elts] returns the constant array of type
878 [array_type ty (Array.length elts)] and containing the values [elts].
879 This value can in turn be used as the initializer for a global variable.
880 See the method [llvm::ConstantArray::get]. *)
881 val const_array : lltype -> llvalue array -> llvalue
883 (** [const_struct context elts] returns the structured constant of type
884 [struct_type (Array.map type_of elts)] and containing the values [elts]
885 in the context [context]. This value can in turn be used as the initializer
886 for a global variable. See the method [llvm::ConstantStruct::getAnon]. *)
887 val const_struct : llcontext -> llvalue array -> llvalue
889 (** [const_named_struct namedty elts] returns the structured constant of type
890 [namedty] (which must be a named structure type) and containing the values [elts].
891 This value can in turn be used as the initializer
892 for a global variable. See the method [llvm::ConstantStruct::get]. *)
893 val const_named_struct : lltype -> llvalue array -> llvalue
895 (** [const_packed_struct context elts] returns the structured constant of
896 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
897 values [elts] in the context [context]. This value can in turn be used as
898 the initializer for a global variable. See the method
899 [llvm::ConstantStruct::get]. *)
900 val const_packed_struct : llcontext -> llvalue array -> llvalue
902 (** [const_vector elts] returns the vector constant of type
903 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
904 values [elts]. See the method [llvm::ConstantVector::get]. *)
905 val const_vector : llvalue array -> llvalue
907 (** [string_of_const c] returns [Some str] if [c] is a string constant,
908 or [None] if this is not a string constant. *)
909 val string_of_const : llvalue -> string option
911 (** [const_element c] returns a constant for a specified index's element.
912 See the method ConstantDataSequential::getElementAsConstant. *)
913 val const_element : llvalue -> int -> llvalue
916 (** {7 Constant expressions} *)
918 (** [align_of ty] returns the alignof constant for the type [ty]. This is
919 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
920 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
921 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
922 val align_of : lltype -> llvalue
924 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
925 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
926 (const_int i32_type 1)) i64_type], but considerably more readable.
927 See the method [llvm::ConstantExpr::getSizeOf]. *)
928 val size_of : lltype -> llvalue
930 (** [const_neg c] returns the arithmetic negation of the constant [c].
931 See the method [llvm::ConstantExpr::getNeg]. *)
932 val const_neg : llvalue -> llvalue
934 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
935 no signed wrapping. The result is undefined if the negation overflows.
936 See the method [llvm::ConstantExpr::getNSWNeg]. *)
937 val const_nsw_neg : llvalue -> llvalue
939 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
940 no unsigned wrapping. The result is undefined if the negation overflows.
941 See the method [llvm::ConstantExpr::getNUWNeg]. *)
942 val const_nuw_neg : llvalue -> llvalue
944 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
945 See the method [llvm::ConstantExpr::getFNeg]. *)
946 val const_fneg : llvalue -> llvalue
948 (** [const_not c] returns the bitwise inverse of the constant [c].
949 See the method [llvm::ConstantExpr::getNot]. *)
950 val const_not : llvalue -> llvalue
952 (** [const_add c1 c2] returns the constant sum of two constants.
953 See the method [llvm::ConstantExpr::getAdd]. *)
954 val const_add : llvalue -> llvalue -> llvalue
956 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
957 signed wrapping. The result is undefined if the sum overflows.
958 See the method [llvm::ConstantExpr::getNSWAdd]. *)
959 val const_nsw_add : llvalue -> llvalue -> llvalue
961 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
962 unsigned wrapping. The result is undefined if the sum overflows.
963 See the method [llvm::ConstantExpr::getNSWAdd]. *)
964 val const_nuw_add : llvalue -> llvalue -> llvalue
966 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
967 See the method [llvm::ConstantExpr::getFAdd]. *)
968 val const_fadd : llvalue -> llvalue -> llvalue
970 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
971 constants. See the method [llvm::ConstantExpr::getSub]. *)
972 val const_sub : llvalue -> llvalue -> llvalue
974 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
975 no signed wrapping. The result is undefined if the sum overflows.
976 See the method [llvm::ConstantExpr::getNSWSub]. *)
977 val const_nsw_sub : llvalue -> llvalue -> llvalue
979 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
980 no unsigned wrapping. The result is undefined if the sum overflows.
981 See the method [llvm::ConstantExpr::getNSWSub]. *)
982 val const_nuw_sub : llvalue -> llvalue -> llvalue
984 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
985 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
986 val const_fsub : llvalue -> llvalue -> llvalue
988 (** [const_mul c1 c2] returns the constant product of two constants.
989 See the method [llvm::ConstantExpr::getMul]. *)
990 val const_mul : llvalue -> llvalue -> llvalue
992 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
993 no signed wrapping. The result is undefined if the sum overflows.
994 See the method [llvm::ConstantExpr::getNSWMul]. *)
995 val const_nsw_mul : llvalue -> llvalue -> llvalue
997 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
998 no unsigned wrapping. The result is undefined if the sum overflows.
999 See the method [llvm::ConstantExpr::getNSWMul]. *)
1000 val const_nuw_mul : llvalue -> llvalue -> llvalue
1002 (** [const_fmul c1 c2] returns the constant product of two constants floats.
1003 See the method [llvm::ConstantExpr::getFMul]. *)
1004 val const_fmul : llvalue -> llvalue -> llvalue
1006 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
1008 See the method [llvm::ConstantExpr::getUDiv]. *)
1009 val const_udiv : llvalue -> llvalue -> llvalue
1011 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
1013 See the method [llvm::ConstantExpr::getSDiv]. *)
1014 val const_sdiv : llvalue -> llvalue -> llvalue
1016 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
1017 signed integer constants. The result is undefined if the result is rounded
1018 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
1019 val const_exact_sdiv : llvalue -> llvalue -> llvalue
1021 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
1023 See the method [llvm::ConstantExpr::getFDiv]. *)
1024 val const_fdiv : llvalue -> llvalue -> llvalue
1026 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
1027 unsigned integer constants.
1028 See the method [llvm::ConstantExpr::getURem]. *)
1029 val const_urem : llvalue -> llvalue -> llvalue
1031 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
1032 signed integer constants.
1033 See the method [llvm::ConstantExpr::getSRem]. *)
1034 val const_srem : llvalue -> llvalue -> llvalue
1036 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
1037 signed floating point constants.
1038 See the method [llvm::ConstantExpr::getFRem]. *)
1039 val const_frem : llvalue -> llvalue -> llvalue
1041 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
1043 See the method [llvm::ConstantExpr::getAnd]. *)
1044 val const_and : llvalue -> llvalue -> llvalue
1046 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
1048 See the method [llvm::ConstantExpr::getOr]. *)
1049 val const_or : llvalue -> llvalue -> llvalue
1051 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
1053 See the method [llvm::ConstantExpr::getXor]. *)
1054 val const_xor : llvalue -> llvalue -> llvalue
1056 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
1057 constants, [c1 pred c2].
1058 See the method [llvm::ConstantExpr::getICmp]. *)
1059 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
1061 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
1062 point constants, [c1 pred c2].
1063 See the method [llvm::ConstantExpr::getFCmp]. *)
1064 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
1066 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
1067 constant integer [c2].
1068 See the method [llvm::ConstantExpr::getShl]. *)
1069 val const_shl : llvalue -> llvalue -> llvalue
1071 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
1072 constant integer [c2] with zero extension.
1073 See the method [llvm::ConstantExpr::getLShr]. *)
1074 val const_lshr : llvalue -> llvalue -> llvalue
1076 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
1077 constant integer [c2] with sign extension.
1078 See the method [llvm::ConstantExpr::getAShr]. *)
1079 val const_ashr : llvalue -> llvalue -> llvalue
1081 (** [const_gep pc indices] returns the constant [getElementPtr] of [pc] with the
1082 constant integers indices from the array [indices].
1083 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
1084 val const_gep : llvalue -> llvalue array -> llvalue
1086 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [pc]
1087 with the constant integers indices from the array [indices].
1088 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
1089 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
1091 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
1092 to the smaller integer type [ty].
1093 See the method [llvm::ConstantExpr::getTrunc]. *)
1094 val const_trunc : llvalue -> lltype -> llvalue
1096 (** [const_sext c ty] returns the constant sign extension of integer constant
1097 [c] to the larger integer type [ty].
1098 See the method [llvm::ConstantExpr::getSExt]. *)
1099 val const_sext : llvalue -> lltype -> llvalue
1101 (** [const_zext c ty] returns the constant zero extension of integer constant
1102 [c] to the larger integer type [ty].
1103 See the method [llvm::ConstantExpr::getZExt]. *)
1104 val const_zext : llvalue -> lltype -> llvalue
1106 (** [const_fptrunc c ty] returns the constant truncation of floating point
1107 constant [c] to the smaller floating point type [ty].
1108 See the method [llvm::ConstantExpr::getFPTrunc]. *)
1109 val const_fptrunc : llvalue -> lltype -> llvalue
1111 (** [const_fpext c ty] returns the constant extension of floating point constant
1112 [c] to the larger floating point type [ty].
1113 See the method [llvm::ConstantExpr::getFPExt]. *)
1114 val const_fpext : llvalue -> lltype -> llvalue
1116 (** [const_uitofp c ty] returns the constant floating point conversion of
1117 unsigned integer constant [c] to the floating point type [ty].
1118 See the method [llvm::ConstantExpr::getUIToFP]. *)
1119 val const_uitofp : llvalue -> lltype -> llvalue
1121 (** [const_sitofp c ty] returns the constant floating point conversion of
1122 signed integer constant [c] to the floating point type [ty].
1123 See the method [llvm::ConstantExpr::getSIToFP]. *)
1124 val const_sitofp : llvalue -> lltype -> llvalue
1126 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
1127 floating point constant [c] to integer type [ty].
1128 See the method [llvm::ConstantExpr::getFPToUI]. *)
1129 val const_fptoui : llvalue -> lltype -> llvalue
1131 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
1132 floating point constant [c] to integer type [ty].
1133 See the method [llvm::ConstantExpr::getFPToSI]. *)
1134 val const_fptosi : llvalue -> lltype -> llvalue
1136 (** [const_ptrtoint c ty] returns the constant integer conversion of
1137 pointer constant [c] to integer type [ty].
1138 See the method [llvm::ConstantExpr::getPtrToInt]. *)
1139 val const_ptrtoint : llvalue -> lltype -> llvalue
1141 (** [const_inttoptr c ty] returns the constant pointer conversion of
1142 integer constant [c] to pointer type [ty].
1143 See the method [llvm::ConstantExpr::getIntToPtr]. *)
1144 val const_inttoptr : llvalue -> lltype -> llvalue
1146 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
1147 to type [ty] of equal size.
1148 See the method [llvm::ConstantExpr::getBitCast]. *)
1149 val const_bitcast : llvalue -> lltype -> llvalue
1151 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
1152 conversion of constant [c] to type [ty].
1153 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
1154 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
1156 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
1157 conversion of constant [c] to type [ty].
1158 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
1159 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
1161 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
1162 conversion of constant [c] to type [ty].
1163 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
1164 val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
1166 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
1167 cast conversion of constant [c] to type [ty] of equal size.
1168 See the method [llvm::ConstantExpr::getPointerCast]. *)
1169 val const_pointercast : llvalue -> lltype -> llvalue
1171 (** [const_intcast c ty ~is_signed] returns a constant sext/zext, bitcast,
1172 or trunc for integer -> integer casts of constant [c] to type [ty].
1173 When converting a narrower value to a wider one, whether sext or zext
1174 will be used is controlled by [is_signed].
1175 See the method [llvm::ConstantExpr::getIntegerCast]. *)
1176 val const_intcast : llvalue -> lltype -> is_signed:bool -> llvalue
1178 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
1179 fp casts of constant [c] to type [ty].
1180 See the method [llvm::ConstantExpr::getFPCast]. *)
1181 val const_fpcast : llvalue -> lltype -> llvalue
1183 (** [const_select cond t f] returns the constant conditional which returns value
1184 [t] if the boolean constant [cond] is true and the value [f] otherwise.
1185 See the method [llvm::ConstantExpr::getSelect]. *)
1186 val const_select : llvalue -> llvalue -> llvalue -> llvalue
1188 (** [const_extractelement vec i] returns the constant [i]th element of
1189 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
1190 the size of the vector.
1191 See the method [llvm::ConstantExpr::getExtractElement]. *)
1192 val const_extractelement : llvalue -> llvalue -> llvalue
1194 (** [const_insertelement vec v i] returns the constant vector with the same
1195 elements as constant vector [v] but the [i]th element replaced by the
1196 constant [v]. [v] must be a constant value with the type of the vector
1197 elements. [i] must be a constant [i32] value unsigned less than the size
1199 See the method [llvm::ConstantExpr::getInsertElement]. *)
1200 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
1202 (** [const_shufflevector a b mask] returns a constant [shufflevector].
1203 See the LLVM Language Reference for details on the [shufflevector]
1205 See the method [llvm::ConstantExpr::getShuffleVector]. *)
1206 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
1208 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
1209 constant aggregate [agg]. Each [idxs] must be less than the size of the
1210 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
1211 val const_extractvalue : llvalue -> int array -> llvalue
1213 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
1214 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
1215 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
1216 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
1218 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
1219 See the method [llvm::InlineAsm::get]. *)
1220 val const_inline_asm : lltype -> string -> string -> bool -> bool -> llvalue
1222 (** [block_address f bb] returns the address of the basic block [bb] in the
1223 function [f]. See the method [llvm::BasicBlock::get]. *)
1224 val block_address : llvalue -> llbasicblock -> llvalue
1227 (** {7 Operations on global variables, functions, and aliases (globals)} *)
1229 (** [global_parent g] is the enclosing module of the global value [g].
1230 See the method [llvm::GlobalValue::getParent]. *)
1231 val global_parent : llvalue -> llmodule
1233 (** [is_declaration g] returns [true] if the global value [g] is a declaration
1234 only. Returns [false] otherwise.
1235 See the method [llvm::GlobalValue::isDeclaration]. *)
1236 val is_declaration : llvalue -> bool
1238 (** [linkage g] returns the linkage of the global value [g].
1239 See the method [llvm::GlobalValue::getLinkage]. *)
1240 val linkage : llvalue -> Linkage.t
1242 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
1243 See the method [llvm::GlobalValue::setLinkage]. *)
1244 val set_linkage : Linkage.t -> llvalue -> unit
1246 (** [section g] returns the linker section of the global value [g].
1247 See the method [llvm::GlobalValue::getSection]. *)
1248 val section : llvalue -> string
1250 (** [set_section s g] sets the linker section of the global value [g] to [s].
1251 See the method [llvm::GlobalValue::setSection]. *)
1252 val set_section : string -> llvalue -> unit
1254 (** [visibility g] returns the linker visibility of the global value [g].
1255 See the method [llvm::GlobalValue::getVisibility]. *)
1256 val visibility : llvalue -> Visibility.t
1258 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1259 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1260 val set_visibility : Visibility.t -> llvalue -> unit
1262 (** [alignment g] returns the required alignment of the global value [g].
1263 See the method [llvm::GlobalValue::getAlignment]. *)
1264 val alignment : llvalue -> int
1266 (** [set_alignment n g] sets the required alignment of the global value [g] to
1267 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1268 val set_alignment : int -> llvalue -> unit
1271 (** {7 Operations on global variables} *)
1273 (** [declare_global ty name m] returns a new global variable of type [ty] and
1274 with name [name] in module [m] in the default address space (0). If such a
1275 global variable already exists, it is returned. If the type of the existing
1276 global differs, then a bitcast to [ty] is returned. *)
1277 val declare_global : lltype -> string -> llmodule -> llvalue
1279 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1280 of type [ty] and with name [name] in module [m] in the address space
1281 [addrspace]. If such a global variable already exists, it is returned. If
1282 the type of the existing global differs, then a bitcast to [ty] is
1284 val declare_qualified_global : lltype -> string -> int -> llmodule -> llvalue
1286 (** [define_global name init m] returns a new global with name [name] and
1287 initializer [init] in module [m] in the default address space (0). If the
1288 named global already exists, it is renamed.
1289 See the constructor of [llvm::GlobalVariable]. *)
1290 val define_global : string -> llvalue -> llmodule -> llvalue
1292 (** [define_qualified_global name init addrspace m] returns a new global with
1293 name [name] and initializer [init] in module [m] in the address space
1294 [addrspace]. If the named global already exists, it is renamed.
1295 See the constructor of [llvm::GlobalVariable]. *)
1296 val define_qualified_global : string -> llvalue -> int -> llmodule -> llvalue
1298 (** [lookup_global name m] returns [Some g] if a global variable with name
1299 [name] exists in module [m]. If no such global exists, returns [None].
1300 See the [llvm::GlobalVariable] constructor. *)
1301 val lookup_global : string -> llmodule -> llvalue option
1303 (** [delete_global gv] destroys the global variable [gv].
1304 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1305 val delete_global : llvalue -> unit
1307 (** [global_begin m] returns the first position in the global variable list of
1308 the module [m]. [global_begin] and [global_succ] can be used to iterate
1309 over the global list in order.
1310 See the method [llvm::Module::global_begin]. *)
1311 val global_begin : llmodule -> (llmodule, llvalue) llpos
1313 (** [global_succ gv] returns the global variable list position succeeding
1315 See the method [llvm::Module::global_iterator::operator++]. *)
1316 val global_succ : llvalue -> (llmodule, llvalue) llpos
1318 (** [iter_globals f m] applies function [f] to each of the global variables of
1319 module [m] in order. Tail recursive. *)
1320 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1322 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1323 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1324 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1326 (** [global_end m] returns the last position in the global variable list of the
1327 module [m]. [global_end] and [global_pred] can be used to iterate over the
1328 global list in reverse.
1329 See the method [llvm::Module::global_end]. *)
1330 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1332 (** [global_pred gv] returns the global variable list position preceding
1334 See the method [llvm::Module::global_iterator::operator--]. *)
1335 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1337 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1338 of module [m] in reverse order. Tail recursive. *)
1339 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1341 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1342 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1343 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1345 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1346 constant. Returns [false] otherwise.
1347 See the method [llvm::GlobalVariable::isConstant]. *)
1348 val is_global_constant : llvalue -> bool
1350 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1351 [c] is [true] and not if [c] is [false].
1352 See the method [llvm::GlobalVariable::setConstant]. *)
1353 val set_global_constant : bool -> llvalue -> unit
1355 (** [global_initializer gv] returns the initializer for the global variable
1356 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1357 val global_initializer : llvalue -> llvalue
1359 (** [set_initializer c gv] sets the initializer for the global variable
1360 [gv] to the constant [c].
1361 See the method [llvm::GlobalVariable::setInitializer]. *)
1362 val set_initializer : llvalue -> llvalue -> unit
1364 (** [remove_initializer gv] unsets the initializer for the global variable
1366 See the method [llvm::GlobalVariable::setInitializer]. *)
1367 val remove_initializer : llvalue -> unit
1369 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1370 thread-local and [false] otherwise.
1371 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1372 val is_thread_local : llvalue -> bool
1374 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1375 [c] is [true] and not otherwise.
1376 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1377 val set_thread_local : bool -> llvalue -> unit
1379 (** [is_thread_local gv] returns the thread local mode of the global
1381 See the method [llvm::GlobalVariable::getThreadLocalMode]. *)
1382 val thread_local_mode : llvalue -> ThreadLocalMode.t
1384 (** [set_thread_local c gv] sets the thread local mode of the global
1386 See the method [llvm::GlobalVariable::setThreadLocalMode]. *)
1387 val set_thread_local_mode : ThreadLocalMode.t -> llvalue -> unit
1389 (** [is_externally_initialized gv] returns [true] if the global
1390 variable [gv] is externally initialized and [false] otherwise.
1391 See the method [llvm::GlobalVariable::isExternallyInitialized]. *)
1392 val is_externally_initialized : llvalue -> bool
1394 (** [set_externally_initialized c gv] sets the global variable [gv] to be
1395 externally initialized if [c] is [true] and not otherwise.
1396 See the method [llvm::GlobalVariable::setExternallyInitialized]. *)
1397 val set_externally_initialized : bool -> llvalue -> unit
1400 (** {7 Operations on aliases} *)
1402 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1403 the aliasee [a] with the name [n].
1404 See the constructor for [llvm::GlobalAlias]. *)
1405 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1408 (** {7 Operations on functions} *)
1410 (** [declare_function name ty m] returns a new function of type [ty] and
1411 with name [name] in module [m]. If such a function already exists,
1412 it is returned. If the type of the existing function differs, then a bitcast
1413 to [ty] is returned. *)
1414 val declare_function : string -> lltype -> llmodule -> llvalue
1416 (** [define_function name ty m] creates a new function with name [name] and
1417 type [ty] in module [m]. If the named function already exists, it is
1418 renamed. An entry basic block is created in the function.
1419 See the constructor of [llvm::GlobalVariable]. *)
1420 val define_function : string -> lltype -> llmodule -> llvalue
1422 (** [lookup_function name m] returns [Some f] if a function with name
1423 [name] exists in module [m]. If no such function exists, returns [None].
1424 See the method [llvm::Module] constructor. *)
1425 val lookup_function : string -> llmodule -> llvalue option
1427 (** [delete_function f] destroys the function [f].
1428 See the method [llvm::Function::eraseFromParent]. *)
1429 val delete_function : llvalue -> unit
1431 (** [function_begin m] returns the first position in the function list of the
1432 module [m]. [function_begin] and [function_succ] can be used to iterate over
1433 the function list in order.
1434 See the method [llvm::Module::begin]. *)
1435 val function_begin : llmodule -> (llmodule, llvalue) llpos
1437 (** [function_succ gv] returns the function list position succeeding
1439 See the method [llvm::Module::iterator::operator++]. *)
1440 val function_succ : llvalue -> (llmodule, llvalue) llpos
1442 (** [iter_functions f m] applies function [f] to each of the functions of module
1443 [m] in order. Tail recursive. *)
1444 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1446 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1447 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1448 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1450 (** [function_end m] returns the last position in the function list of
1451 the module [m]. [function_end] and [function_pred] can be used to iterate
1452 over the function list in reverse.
1453 See the method [llvm::Module::end]. *)
1454 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1456 (** [function_pred gv] returns the function list position preceding [After gv].
1457 See the method [llvm::Module::iterator::operator--]. *)
1458 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1460 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1461 module [m] in reverse order. Tail recursive. *)
1462 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1464 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1465 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1466 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1468 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1469 See the method [llvm::Function::isIntrinsic]. *)
1470 val is_intrinsic : llvalue -> bool
1472 (** [function_call_conv f] returns the calling convention of the function [f].
1473 See the method [llvm::Function::getCallingConv]. *)
1474 val function_call_conv : llvalue -> int
1476 (** [set_function_call_conv cc f] sets the calling convention of the function
1477 [f] to the calling convention numbered [cc].
1478 See the method [llvm::Function::setCallingConv]. *)
1479 val set_function_call_conv : int -> llvalue -> unit
1481 (** [gc f] returns [Some name] if the function [f] has a garbage
1482 collection algorithm specified and [None] otherwise.
1483 See the method [llvm::Function::getGC]. *)
1484 val gc : llvalue -> string option
1486 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1487 [gc]. See the method [llvm::Function::setGC]. *)
1488 val set_gc : string option -> llvalue -> unit
1490 (** [add_function_attr f a] adds attribute [a] to the return type of function
1492 val add_function_attr : llvalue -> Attribute.t -> unit
1494 (** [add_target_dependent_function_attr f a] adds target-dependent attribute
1495 [a] to function [f]. *)
1496 val add_target_dependent_function_attr : llvalue -> string -> string -> unit
1498 (** [function_attr f] returns the function attribute for the function [f].
1499 See the method [llvm::Function::getAttributes] *)
1500 val function_attr : llvalue -> Attribute.t list
1502 (** [remove_function_attr f a] removes attribute [a] from the return type of
1504 val remove_function_attr : llvalue -> Attribute.t -> unit
1507 (** {7 Operations on params} *)
1509 (** [params f] returns the parameters of function [f].
1510 See the method [llvm::Function::getArgumentList]. *)
1511 val params : llvalue -> llvalue array
1513 (** [param f n] returns the [n]th parameter of function [f].
1514 See the method [llvm::Function::getArgumentList]. *)
1515 val param : llvalue -> int -> llvalue
1517 (** [param_attr p] returns the attributes of parameter [p].
1518 See the methods [llvm::Function::getAttributes] and
1519 [llvm::Attributes::getParamAttributes] *)
1520 val param_attr : llvalue -> Attribute.t list
1522 (** [param_parent p] returns the parent function that owns the parameter.
1523 See the method [llvm::Argument::getParent]. *)
1524 val param_parent : llvalue -> llvalue
1526 (** [param_begin f] returns the first position in the parameter list of the
1527 function [f]. [param_begin] and [param_succ] can be used to iterate over
1528 the parameter list in order.
1529 See the method [llvm::Function::arg_begin]. *)
1530 val param_begin : llvalue -> (llvalue, llvalue) llpos
1532 (** [param_succ bb] returns the parameter list position succeeding
1534 See the method [llvm::Function::arg_iterator::operator++]. *)
1535 val param_succ : llvalue -> (llvalue, llvalue) llpos
1537 (** [iter_params f fn] applies function [f] to each of the parameters
1538 of function [fn] in order. Tail recursive. *)
1539 val iter_params : (llvalue -> unit) -> llvalue -> unit
1541 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1542 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1543 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1545 (** [param_end f] returns the last position in the parameter list of
1546 the function [f]. [param_end] and [param_pred] can be used to iterate
1547 over the parameter list in reverse.
1548 See the method [llvm::Function::arg_end]. *)
1549 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1551 (** [param_pred gv] returns the function list position preceding [After gv].
1552 See the method [llvm::Function::arg_iterator::operator--]. *)
1553 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1555 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1556 of function [fn] in reverse order. Tail recursive. *)
1557 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1559 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1560 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1561 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1563 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1564 val add_param_attr : llvalue -> Attribute.t -> unit
1566 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1567 val remove_param_attr : llvalue -> Attribute.t -> unit
1569 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1570 val set_param_alignment : llvalue -> int -> unit
1573 (** {7 Operations on basic blocks} *)
1575 (** [basic_blocks fn] returns the basic blocks of the function [f].
1576 See the method [llvm::Function::getBasicBlockList]. *)
1577 val basic_blocks : llvalue -> llbasicblock array
1579 (** [entry_block fn] returns the entry basic block of the function [f].
1580 See the method [llvm::Function::getEntryBlock]. *)
1581 val entry_block : llvalue -> llbasicblock
1583 (** [delete_block bb] deletes the basic block [bb].
1584 See the method [llvm::BasicBlock::eraseFromParent]. *)
1585 val delete_block : llbasicblock -> unit
1587 (** [remove_block bb] removes the basic block [bb] from its parent function.
1588 See the method [llvm::BasicBlock::removeFromParent]. *)
1589 val remove_block : llbasicblock -> unit
1591 (** [move_block_before pos bb] moves the basic block [bb] before [pos].
1592 See the method [llvm::BasicBlock::moveBefore]. *)
1593 val move_block_before : llbasicblock -> llbasicblock -> unit
1595 (** [move_block_after pos bb] moves the basic block [bb] after [pos].
1596 See the method [llvm::BasicBlock::moveAfter]. *)
1597 val move_block_after : llbasicblock -> llbasicblock -> unit
1599 (** [append_block c name f] creates a new basic block named [name] at the end of
1600 function [f] in the context [c].
1601 See the constructor of [llvm::BasicBlock]. *)
1602 val append_block : llcontext -> string -> llvalue -> llbasicblock
1604 (** [insert_block c name bb] creates a new basic block named [name] before the
1605 basic block [bb] in the context [c].
1606 See the constructor of [llvm::BasicBlock]. *)
1607 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1609 (** [block_parent bb] returns the parent function that owns the basic block.
1610 See the method [llvm::BasicBlock::getParent]. *)
1611 val block_parent : llbasicblock -> llvalue
1613 (** [block_begin f] returns the first position in the basic block list of the
1614 function [f]. [block_begin] and [block_succ] can be used to iterate over
1615 the basic block list in order.
1616 See the method [llvm::Function::begin]. *)
1617 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1619 (** [block_succ bb] returns the basic block list position succeeding
1621 See the method [llvm::Function::iterator::operator++]. *)
1622 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1624 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1625 of function [fn] in order. Tail recursive. *)
1626 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1628 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1629 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1630 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1632 (** [block_end f] returns the last position in the basic block list of
1633 the function [f]. [block_end] and [block_pred] can be used to iterate
1634 over the basic block list in reverse.
1635 See the method [llvm::Function::end]. *)
1636 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1638 (** [block_pred bb] returns the basic block list position preceding [After bb].
1639 See the method [llvm::Function::iterator::operator--]. *)
1640 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1642 (** [block_terminator bb] returns the terminator of the basic block [bb]. *)
1643 val block_terminator : llbasicblock -> llvalue option
1645 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1646 of function [fn] in reverse order. Tail recursive. *)
1647 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1649 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1650 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1651 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1653 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1654 val value_of_block : llbasicblock -> llvalue
1656 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1658 Similar to [llvm::isa<BasicBlock>]. *)
1659 val value_is_block : llvalue -> bool
1661 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1662 val block_of_value : llvalue -> llbasicblock
1665 (** {7 Operations on instructions} *)
1667 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1668 See the method [llvm::Instruction::getParent]. *)
1669 val instr_parent : llvalue -> llbasicblock
1671 (** [delete_instruction i] deletes the instruction [i].
1672 * See the method [llvm::Instruction::eraseFromParent]. *)
1673 val delete_instruction : llvalue -> unit
1675 (** [instr_begin bb] returns the first position in the instruction list of the
1676 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1677 the instruction list in order.
1678 See the method [llvm::BasicBlock::begin]. *)
1679 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1681 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1682 See the method [llvm::BasicBlock::iterator::operator++]. *)
1683 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1685 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1686 block [bb] in order. Tail recursive. *)
1687 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1689 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1690 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1691 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1693 (** [instr_end bb] returns the last position in the instruction list of the
1694 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1695 the instruction list in reverse.
1696 See the method [llvm::BasicBlock::end]. *)
1697 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1699 (** [instr_pred i] returns the instruction list position preceding [After i].
1700 See the method [llvm::BasicBlock::iterator::operator--]. *)
1701 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1703 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1704 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1705 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1707 (** [inst_opcode i] returns the [Opcode.t] corresponding to instruction [i],
1708 or [Opcode.Invalid] if [i] is not an instruction. *)
1709 val instr_opcode : llvalue -> Opcode.t
1711 (** [icmp_predicate i] returns the [Icmp.t] corresponding to an [icmp]
1713 val icmp_predicate : llvalue -> Icmp.t option
1715 (** [fcmp_predicate i] returns the [fcmp.t] corresponding to an [fcmp]
1717 val fcmp_predicate : llvalue -> Fcmp.t option
1719 (** [inst_clone i] returns a copy of instruction [i],
1720 The instruction has no parent, and no name.
1721 See the method [llvm::Instruction::clone]. *)
1722 val instr_clone : llvalue -> llvalue
1725 (** {7 Operations on call sites} *)
1727 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1728 instruction [ci], which may be one of the values from the module
1729 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1730 [llvm::InvokeInst::getCallingConv]. *)
1731 val instruction_call_conv: llvalue -> int
1733 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1734 or invoke instruction [ci] to the integer [cc], which can be one of the
1735 values from the module {!CallConv}.
1736 See the method [llvm::CallInst::setCallingConv]
1737 and [llvm::InvokeInst::setCallingConv]. *)
1738 val set_instruction_call_conv: int -> llvalue -> unit
1740 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1741 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1743 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1745 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1746 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1748 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1751 (** {7 Operations on call instructions (only)} *)
1753 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1754 eligible for tail call optimization, [false] otherwise.
1755 See the method [llvm::CallInst::isTailCall]. *)
1756 val is_tail_call : llvalue -> bool
1758 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1759 call optimization if [tc] is [true], clears otherwise.
1760 See the method [llvm::CallInst::setTailCall]. *)
1761 val set_tail_call : bool -> llvalue -> unit
1764 (** {7 Operations on load/store instructions (only)} *)
1766 (** [is_volatile i] is [true] if the load or store instruction [i] is marked
1768 See the methods [llvm::LoadInst::isVolatile] and
1769 [llvm::StoreInst::isVolatile]. *)
1770 val is_volatile : llvalue -> bool
1772 (** [set_volatile v i] marks the load or store instruction [i] as volatile
1773 if [v] is [true], unmarks otherwise.
1774 See the methods [llvm::LoadInst::setVolatile] and
1775 [llvm::StoreInst::setVolatile]. *)
1776 val set_volatile : bool -> llvalue -> unit
1778 (** {7 Operations on terminators} *)
1780 (** [is_terminator v] returns true if the instruction [v] is a terminator. *)
1781 val is_terminator : llvalue -> bool
1783 (** [successor v i] returns the successor at index [i] for the value [v].
1784 See the method [llvm::TerminatorInst::getSuccessor]. *)
1785 val successor : llvalue -> int -> llbasicblock
1787 (** [set_successor v i o] sets the successor of the value [v] at the index [i] to
1789 See the method [llvm::TerminatorInst::setSuccessor]. *)
1790 val set_successor : llvalue -> int -> llbasicblock -> unit
1792 (** [num_successors v] returns the number of successors for the value [v].
1793 See the method [llvm::TerminatorInst::getNumSuccessors]. *)
1794 val num_successors : llvalue -> int
1796 (** [successors v] returns the successors of [v]. *)
1797 val successors : llvalue -> llbasicblock array
1799 (** [iter_successors f v] applies function f to each successor [v] in order. Tail recursive. *)
1800 val iter_successors : (llbasicblock -> unit) -> llvalue -> unit
1802 (** [fold_successors f v init] is [f (... (f init vN) ...) v1] where [v1,...,vN] are the successors of [v]. Tail recursive. *)
1803 val fold_successors : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1805 (** {7 Operations on branches} *)
1807 (** [is_conditional v] returns true if the branch instruction [v] is conditional.
1808 See the method [llvm::BranchInst::isConditional]. *)
1809 val is_conditional : llvalue -> bool
1811 (** [condition v] return the condition of the branch instruction [v].
1812 See the method [llvm::BranchInst::getCondition]. *)
1813 val condition : llvalue -> llvalue
1815 (** [set_condition v c] sets the condition of the branch instruction [v] to the value [c].
1816 See the method [llvm::BranchInst::setCondition]. *)
1817 val set_condition : llvalue -> llvalue -> unit
1819 (** [get_branch c] returns a description of the branch instruction [c]. *)
1820 val get_branch : llvalue ->
1821 [ `Conditional of llvalue * llbasicblock * llbasicblock
1822 | `Unconditional of llbasicblock ]
1825 (** {7 Operations on phi nodes} *)
1827 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1828 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1829 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1831 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1832 See the method [llvm::PHINode::getIncomingValue]. *)
1833 val incoming : llvalue -> (llvalue * llbasicblock) list
1837 (** {6 Instruction builders} *)
1839 (** [builder context] creates an instruction builder with no position in
1840 the context [context]. It is invalid to use this builder until its position
1841 is set with {!position_before} or {!position_at_end}. See the constructor
1842 for [llvm::LLVMBuilder]. *)
1843 val builder : llcontext -> llbuilder
1845 (** [builder_at ip] creates an instruction builder positioned at [ip].
1846 See the constructor for [llvm::LLVMBuilder]. *)
1847 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1849 (** [builder_before ins] creates an instruction builder positioned before the
1850 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1851 val builder_before : llcontext -> llvalue -> llbuilder
1853 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1854 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1855 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1857 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1859 See the constructor for [llvm::LLVMBuilder]. *)
1860 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1862 (** [position_before ins b] moves the instruction builder [b] to before the
1863 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1864 val position_before : llvalue -> llbuilder -> unit
1866 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1867 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1868 val position_at_end : llbasicblock -> llbuilder -> unit
1870 (** [insertion_block b] returns the basic block that the builder [b] is
1871 positioned to insert into. Raises [Not_Found] if the instruction builder is
1873 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1874 val insertion_block : llbuilder -> llbasicblock
1876 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1877 position specified by the instruction builder [b].
1878 See the method [llvm::LLVMBuilder::Insert]. *)
1879 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1884 (** [set_current_debug_location b md] sets the current debug location [md] in
1886 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1887 val set_current_debug_location : llbuilder -> llvalue -> unit
1889 (** [clear_current_debug_location b] clears the current debug location in the
1891 val clear_current_debug_location : llbuilder -> unit
1893 (** [current_debug_location b] returns the current debug location, or None
1894 if none is currently set.
1895 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1896 val current_debug_location : llbuilder -> llvalue option
1898 (** [set_inst_debug_location b i] sets the current debug location of the builder
1899 [b] to the instruction [i].
1900 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1901 val set_inst_debug_location : llbuilder -> llvalue -> unit
1904 (** {7 Terminators} *)
1906 (** [build_ret_void b] creates a
1908 instruction at the position specified by the instruction builder [b].
1909 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1910 val build_ret_void : llbuilder -> llvalue
1912 (** [build_ret v b] creates a
1914 instruction at the position specified by the instruction builder [b].
1915 See the method [llvm::LLVMBuilder::CreateRet]. *)
1916 val build_ret : llvalue -> llbuilder -> llvalue
1918 (** [build_aggregate_ret vs b] creates a
1919 [ret {...} { %v1, %v2, ... } ]
1920 instruction at the position specified by the instruction builder [b].
1921 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1922 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1924 (** [build_br bb b] creates a
1926 instruction at the position specified by the instruction builder [b].
1927 See the method [llvm::LLVMBuilder::CreateBr]. *)
1928 val build_br : llbasicblock -> llbuilder -> llvalue
1930 (** [build_cond_br cond tbb fbb b] creates a
1931 [br %cond, %tbb, %fbb]
1932 instruction at the position specified by the instruction builder [b].
1933 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1934 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1937 (** [build_switch case elsebb count b] creates an empty
1938 [switch %case, %elsebb]
1939 instruction at the position specified by the instruction builder [b] with
1940 space reserved for [count] cases.
1941 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1942 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1944 (** [build_malloc ty name b] creates an [malloc]
1945 instruction at the position specified by the instruction builder [b].
1946 See the method [llvm::CallInst::CreateMalloc]. *)
1947 val build_malloc : lltype -> string -> llbuilder -> llvalue
1949 (** [build_array_malloc ty val name b] creates an [array malloc]
1950 instruction at the position specified by the instruction builder [b].
1951 See the method [llvm::CallInst::CreateArrayMalloc]. *)
1952 val build_array_malloc : lltype -> llvalue -> string -> llbuilder -> llvalue
1954 (** [build_free p b] creates a [free]
1955 instruction at the position specified by the instruction builder [b].
1956 See the method [llvm::LLVMBuilder::CreateFree]. *)
1957 val build_free : llvalue -> llbuilder -> llvalue
1959 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1960 when its input matches the constant [onval].
1961 See the method [llvm::SwitchInst::addCase]. **)
1962 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1964 (** [switch_default_dest sw] returns the default destination of the [switch]
1966 See the method [llvm:;SwitchInst::getDefaultDest]. **)
1967 val switch_default_dest : llvalue -> llbasicblock
1969 (** [build_indirect_br addr count b] creates a
1971 instruction at the position specified by the instruction builder [b] with
1972 space reserved for [count] destinations.
1973 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1974 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1976 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1977 location for the indirectbr instruction [br].
1978 See the method [llvm::IndirectBrInst::addDestination]. **)
1979 val add_destination : llvalue -> llbasicblock -> unit
1981 (** [build_invoke fn args tobb unwindbb name b] creates an
1982 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1983 instruction at the position specified by the instruction builder [b].
1984 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1985 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1986 llbasicblock -> string -> llbuilder -> llvalue
1988 (** [build_landingpad ty persfn numclauses name b] creates an
1990 instruction at the position specified by the instruction builder [b].
1991 See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
1992 val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
1995 (** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
1996 See the method [llvm::LandingPadInst::setCleanup]. *)
1997 val set_cleanup : llvalue -> bool -> unit
1999 (** [add_clause lp clause] adds the clause to the [landingpad]instruction.
2000 See the method [llvm::LandingPadInst::addClause]. *)
2001 val add_clause : llvalue -> llvalue -> unit
2003 (** [build_resume exn b] builds a [resume exn] instruction
2004 at the position specified by the instruction builder [b].
2005 See the method [llvm::LLVMBuilder::CreateResume] *)
2006 val build_resume : llvalue -> llbuilder -> llvalue
2008 (** [build_unreachable b] creates an
2010 instruction at the position specified by the instruction builder [b].
2011 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
2012 val build_unreachable : llbuilder -> llvalue
2015 (** {7 Arithmetic} *)
2017 (** [build_add x y name b] creates a
2018 [%name = add %x, %y]
2019 instruction at the position specified by the instruction builder [b].
2020 See the method [llvm::LLVMBuilder::CreateAdd]. *)
2021 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
2023 (** [build_nsw_add x y name b] creates a
2024 [%name = nsw add %x, %y]
2025 instruction at the position specified by the instruction builder [b].
2026 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
2027 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
2029 (** [build_nuw_add x y name b] creates a
2030 [%name = nuw add %x, %y]
2031 instruction at the position specified by the instruction builder [b].
2032 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
2033 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
2035 (** [build_fadd x y name b] creates a
2036 [%name = fadd %x, %y]
2037 instruction at the position specified by the instruction builder [b].
2038 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
2039 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
2041 (** [build_sub x y name b] creates a
2042 [%name = sub %x, %y]
2043 instruction at the position specified by the instruction builder [b].
2044 See the method [llvm::LLVMBuilder::CreateSub]. *)
2045 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
2047 (** [build_nsw_sub x y name b] creates a
2048 [%name = nsw sub %x, %y]
2049 instruction at the position specified by the instruction builder [b].
2050 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
2051 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
2053 (** [build_nuw_sub x y name b] creates a
2054 [%name = nuw sub %x, %y]
2055 instruction at the position specified by the instruction builder [b].
2056 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
2057 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
2059 (** [build_fsub x y name b] creates a
2060 [%name = fsub %x, %y]
2061 instruction at the position specified by the instruction builder [b].
2062 See the method [llvm::LLVMBuilder::CreateFSub]. *)
2063 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
2065 (** [build_mul x y name b] creates a
2066 [%name = mul %x, %y]
2067 instruction at the position specified by the instruction builder [b].
2068 See the method [llvm::LLVMBuilder::CreateMul]. *)
2069 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
2071 (** [build_nsw_mul x y name b] creates a
2072 [%name = nsw mul %x, %y]
2073 instruction at the position specified by the instruction builder [b].
2074 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
2075 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
2077 (** [build_nuw_mul x y name b] creates a
2078 [%name = nuw mul %x, %y]
2079 instruction at the position specified by the instruction builder [b].
2080 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
2081 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
2083 (** [build_fmul x y name b] creates a
2084 [%name = fmul %x, %y]
2085 instruction at the position specified by the instruction builder [b].
2086 See the method [llvm::LLVMBuilder::CreateFMul]. *)
2087 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
2089 (** [build_udiv x y name b] creates a
2090 [%name = udiv %x, %y]
2091 instruction at the position specified by the instruction builder [b].
2092 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
2093 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2095 (** [build_sdiv x y name b] creates a
2096 [%name = sdiv %x, %y]
2097 instruction at the position specified by the instruction builder [b].
2098 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
2099 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2101 (** [build_exact_sdiv x y name b] creates a
2102 [%name = exact sdiv %x, %y]
2103 instruction at the position specified by the instruction builder [b].
2104 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
2105 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2107 (** [build_fdiv x y name b] creates a
2108 [%name = fdiv %x, %y]
2109 instruction at the position specified by the instruction builder [b].
2110 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
2111 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2113 (** [build_urem x y name b] creates a
2114 [%name = urem %x, %y]
2115 instruction at the position specified by the instruction builder [b].
2116 See the method [llvm::LLVMBuilder::CreateURem]. *)
2117 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2119 (** [build_SRem x y name b] creates a
2120 [%name = srem %x, %y]
2121 instruction at the position specified by the instruction builder [b].
2122 See the method [llvm::LLVMBuilder::CreateSRem]. *)
2123 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2125 (** [build_frem x y name b] creates a
2126 [%name = frem %x, %y]
2127 instruction at the position specified by the instruction builder [b].
2128 See the method [llvm::LLVMBuilder::CreateFRem]. *)
2129 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2131 (** [build_shl x y name b] creates a
2132 [%name = shl %x, %y]
2133 instruction at the position specified by the instruction builder [b].
2134 See the method [llvm::LLVMBuilder::CreateShl]. *)
2135 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
2137 (** [build_lshr x y name b] creates a
2138 [%name = lshr %x, %y]
2139 instruction at the position specified by the instruction builder [b].
2140 See the method [llvm::LLVMBuilder::CreateLShr]. *)
2141 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
2143 (** [build_ashr x y name b] creates a
2144 [%name = ashr %x, %y]
2145 instruction at the position specified by the instruction builder [b].
2146 See the method [llvm::LLVMBuilder::CreateAShr]. *)
2147 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
2149 (** [build_and x y name b] creates a
2150 [%name = and %x, %y]
2151 instruction at the position specified by the instruction builder [b].
2152 See the method [llvm::LLVMBuilder::CreateAnd]. *)
2153 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
2155 (** [build_or x y name b] creates a
2157 instruction at the position specified by the instruction builder [b].
2158 See the method [llvm::LLVMBuilder::CreateOr]. *)
2159 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
2161 (** [build_xor x y name b] creates a
2162 [%name = xor %x, %y]
2163 instruction at the position specified by the instruction builder [b].
2164 See the method [llvm::LLVMBuilder::CreateXor]. *)
2165 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
2167 (** [build_neg x name b] creates a
2169 instruction at the position specified by the instruction builder [b].
2170 [-0.0] is used for floating point types to compute the correct sign.
2171 See the method [llvm::LLVMBuilder::CreateNeg]. *)
2172 val build_neg : llvalue -> string -> llbuilder -> llvalue
2174 (** [build_nsw_neg x name b] creates a
2175 [%name = nsw sub 0, %x]
2176 instruction at the position specified by the instruction builder [b].
2177 [-0.0] is used for floating point types to compute the correct sign.
2178 See the method [llvm::LLVMBuilder::CreateNeg]. *)
2179 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
2181 (** [build_nuw_neg x name b] creates a
2182 [%name = nuw sub 0, %x]
2183 instruction at the position specified by the instruction builder [b].
2184 [-0.0] is used for floating point types to compute the correct sign.
2185 See the method [llvm::LLVMBuilder::CreateNeg]. *)
2186 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
2188 (** [build_fneg x name b] creates a
2189 [%name = fsub 0, %x]
2190 instruction at the position specified by the instruction builder [b].
2191 [-0.0] is used for floating point types to compute the correct sign.
2192 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
2193 val build_fneg : llvalue -> string -> llbuilder -> llvalue
2195 (** [build_xor x name b] creates a
2196 [%name = xor %x, -1]
2197 instruction at the position specified by the instruction builder [b].
2198 [-1] is the correct "all ones" value for the type of [x].
2199 See the method [llvm::LLVMBuilder::CreateXor]. *)
2200 val build_not : llvalue -> string -> llbuilder -> llvalue
2205 (** [build_alloca ty name b] creates a
2206 [%name = alloca %ty]
2207 instruction at the position specified by the instruction builder [b].
2208 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2209 val build_alloca : lltype -> string -> llbuilder -> llvalue
2211 (** [build_array_alloca ty n name b] creates a
2212 [%name = alloca %ty, %n]
2213 instruction at the position specified by the instruction builder [b].
2214 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2215 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
2218 (** [build_load v name b] creates a
2220 instruction at the position specified by the instruction builder [b].
2221 See the method [llvm::LLVMBuilder::CreateLoad]. *)
2222 val build_load : llvalue -> string -> llbuilder -> llvalue
2224 (** [build_store v p b] creates a
2226 instruction at the position specified by the instruction builder [b].
2227 See the method [llvm::LLVMBuilder::CreateStore]. *)
2228 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
2230 (** [build_atomicrmw op ptr val o st b] creates an [atomicrmw] instruction with
2231 operation [op] performed on pointer [ptr] and value [val] with ordering [o]
2232 and singlethread flag set to [st] at the position specified by
2233 the instruction builder [b].
2234 See the method [llvm::IRBuilder::CreateAtomicRMW]. *)
2235 val build_atomicrmw : AtomicRMWBinOp.t -> llvalue -> llvalue ->
2236 AtomicOrdering.t -> bool -> string -> llbuilder -> llvalue
2238 (** [build_gep p indices name b] creates a
2239 [%name = getelementptr %p, indices...]
2240 instruction at the position specified by the instruction builder [b].
2241 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
2242 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2244 (** [build_in_bounds_gep p indices name b] creates a
2245 [%name = gelementptr inbounds %p, indices...]
2246 instruction at the position specified by the instruction builder [b].
2247 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
2248 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
2251 (** [build_struct_gep p idx name b] creates a
2252 [%name = getelementptr %p, 0, idx]
2253 instruction at the position specified by the instruction builder [b].
2254 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
2255 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
2258 (** [build_global_string str name b] creates a series of instructions that adds
2259 a global string at the position specified by the instruction builder [b].
2260 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
2261 val build_global_string : string -> string -> llbuilder -> llvalue
2263 (** [build_global_stringptr str name b] creates a series of instructions that
2264 adds a global string pointer at the position specified by the instruction
2266 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
2267 val build_global_stringptr : string -> string -> llbuilder -> llvalue
2272 (** [build_trunc v ty name b] creates a
2273 [%name = trunc %p to %ty]
2274 instruction at the position specified by the instruction builder [b].
2275 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
2276 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2278 (** [build_zext v ty name b] creates a
2279 [%name = zext %p to %ty]
2280 instruction at the position specified by the instruction builder [b].
2281 See the method [llvm::LLVMBuilder::CreateZExt]. *)
2282 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
2284 (** [build_sext v ty name b] creates a
2285 [%name = sext %p to %ty]
2286 instruction at the position specified by the instruction builder [b].
2287 See the method [llvm::LLVMBuilder::CreateSExt]. *)
2288 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
2290 (** [build_fptoui v ty name b] creates a
2291 [%name = fptoui %p to %ty]
2292 instruction at the position specified by the instruction builder [b].
2293 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
2294 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
2296 (** [build_fptosi v ty name b] creates a
2297 [%name = fptosi %p to %ty]
2298 instruction at the position specified by the instruction builder [b].
2299 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
2300 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
2302 (** [build_uitofp v ty name b] creates a
2303 [%name = uitofp %p to %ty]
2304 instruction at the position specified by the instruction builder [b].
2305 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
2306 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2308 (** [build_sitofp v ty name b] creates a
2309 [%name = sitofp %p to %ty]
2310 instruction at the position specified by the instruction builder [b].
2311 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
2312 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2314 (** [build_fptrunc v ty name b] creates a
2315 [%name = fptrunc %p to %ty]
2316 instruction at the position specified by the instruction builder [b].
2317 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
2318 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2320 (** [build_fpext v ty name b] creates a
2321 [%name = fpext %p to %ty]
2322 instruction at the position specified by the instruction builder [b].
2323 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
2324 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
2326 (** [build_ptrtoint v ty name b] creates a
2327 [%name = prtotint %p to %ty]
2328 instruction at the position specified by the instruction builder [b].
2329 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2330 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2332 (** [build_inttoptr v ty name b] creates a
2333 [%name = inttoptr %p to %ty]
2334 instruction at the position specified by the instruction builder [b].
2335 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2336 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2338 (** [build_bitcast v ty name b] creates a
2339 [%name = bitcast %p to %ty]
2340 instruction at the position specified by the instruction builder [b].
2341 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2342 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2344 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2345 instruction at the position specified by the instruction builder [b].
2346 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2347 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2350 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2351 instruction at the position specified by the instruction builder [b].
2352 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2353 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2356 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2357 instruction at the position specified by the instruction builder [b].
2358 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2359 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2362 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2363 instruction at the position specified by the instruction builder [b].
2364 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2365 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2367 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2368 instruction at the position specified by the instruction builder [b].
2369 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2370 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2372 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2373 instruction at the position specified by the instruction builder [b].
2374 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2375 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2378 (** {7 Comparisons} *)
2380 (** [build_icmp pred x y name b] creates a
2381 [%name = icmp %pred %x, %y]
2382 instruction at the position specified by the instruction builder [b].
2383 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2384 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2385 llbuilder -> llvalue
2387 (** [build_fcmp pred x y name b] creates a
2388 [%name = fcmp %pred %x, %y]
2389 instruction at the position specified by the instruction builder [b].
2390 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2391 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2392 llbuilder -> llvalue
2395 (** {7 Miscellaneous instructions} *)
2397 (** [build_phi incoming name b] creates a
2398 [%name = phi %incoming]
2399 instruction at the position specified by the instruction builder [b].
2400 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2401 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2402 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2405 (** [build_call fn args name b] creates a
2406 [%name = call %fn(args...)]
2407 instruction at the position specified by the instruction builder [b].
2408 See the method [llvm::LLVMBuilder::CreateCall]. *)
2409 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2411 (** [build_select cond thenv elsev name b] creates a
2412 [%name = select %cond, %thenv, %elsev]
2413 instruction at the position specified by the instruction builder [b].
2414 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2415 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2418 (** [build_va_arg valist argty name b] creates a
2419 [%name = va_arg %valist, %argty]
2420 instruction at the position specified by the instruction builder [b].
2421 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2422 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2424 (** [build_extractelement vec i name b] creates a
2425 [%name = extractelement %vec, %i]
2426 instruction at the position specified by the instruction builder [b].
2427 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2428 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2431 (** [build_insertelement vec elt i name b] creates a
2432 [%name = insertelement %vec, %elt, %i]
2433 instruction at the position specified by the instruction builder [b].
2434 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2435 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2436 llbuilder -> llvalue
2438 (** [build_shufflevector veca vecb mask name b] creates a
2439 [%name = shufflevector %veca, %vecb, %mask]
2440 instruction at the position specified by the instruction builder [b].
2441 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2442 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2443 llbuilder -> llvalue
2445 (** [build_extractvalue agg idx name b] creates a
2446 [%name = extractvalue %agg, %idx]
2447 instruction at the position specified by the instruction builder [b].
2448 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2449 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2452 (** [build_insertvalue agg val idx name b] creates a
2453 [%name = insertvalue %agg, %val, %idx]
2454 instruction at the position specified by the instruction builder [b].
2455 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2456 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2459 (** [build_is_null val name b] creates a
2460 [%name = icmp eq %val, null]
2461 instruction at the position specified by the instruction builder [b].
2462 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2463 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2465 (** [build_is_not_null val name b] creates a
2466 [%name = icmp ne %val, null]
2467 instruction at the position specified by the instruction builder [b].
2468 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2469 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2471 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2472 the difference between two pointer values at the position specified by the
2473 instruction builder [b].
2474 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2475 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2478 (** {6 Memory buffers} *)
2480 module MemoryBuffer : sig
2481 (** [of_file p] is the memory buffer containing the contents of the file at
2482 path [p]. If the file could not be read, then [IoError msg] is
2484 val of_file : string -> llmemorybuffer
2486 (** [of_stdin ()] is the memory buffer containing the contents of standard input.
2487 If standard input is empty, then [IoError msg] is raised. *)
2488 val of_stdin : unit -> llmemorybuffer
2490 (** [of_string ~name s] is the memory buffer containing the contents of string [s].
2491 The name of memory buffer is set to [name] if it is provided. *)
2492 val of_string : ?name:string -> string -> llmemorybuffer
2494 (** [as_string mb] is the string containing the contents of memory buffer [mb]. *)
2495 val as_string : llmemorybuffer -> string
2497 (** Disposes of a memory buffer. *)
2498 val dispose : llmemorybuffer -> unit
2502 (** {6 Pass Managers} *)
2504 module PassManager : sig
2507 type any = [ `Module | `Function ]
2509 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2510 type of pipeline is suitable for link-time optimization and whole-module
2512 See the constructor of [llvm::PassManager]. *)
2513 val create : unit -> [ `Module ] t
2515 (** [PassManager.create_function m] constructs a new function-by-function
2516 pass pipeline over the module [m]. It does not take ownership of [m].
2517 This type of pipeline is suitable for code generation and JIT compilation
2519 See the constructor of [llvm::FunctionPassManager]. *)
2520 val create_function : llmodule -> [ `Function ] t
2522 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2523 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2524 any of the passes modified the module, [false] otherwise.
2525 See the [llvm::PassManager::run] method. *)
2526 val run_module : llmodule -> [ `Module ] t -> bool
2528 (** [initialize fpm] initializes all of the function passes scheduled in the
2529 function pass manager [fpm]. Returns [true] if any of the passes modified
2530 the module, [false] otherwise.
2531 See the [llvm::FunctionPassManager::doInitialization] method. *)
2532 val initialize : [ `Function ] t -> bool
2534 (** [run_function f fpm] executes all of the function passes scheduled in the
2535 function pass manager [fpm] over the function [f]. Returns [true] if any
2536 of the passes modified [f], [false] otherwise.
2537 See the [llvm::FunctionPassManager::run] method. *)
2538 val run_function : llvalue -> [ `Function ] t -> bool
2540 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2541 function pass manager [fpm]. Returns [true] if any of the passes
2542 modified the module, [false] otherwise.
2543 See the [llvm::FunctionPassManager::doFinalization] method. *)
2544 val finalize : [ `Function ] t -> bool
2546 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2548 See the destructor of [llvm::BasePassManager]. *)
2549 val dispose : [< any ] t -> unit