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 of an [lltype], the result of [classify_type ty]. See the
52 [llvm::Type::TypeID] enumeration. *)
73 (** The linkage of a global value, accessed with {!linkage} and
74 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
78 | Available_externally
81 | Link_once_odr_auto_hide
96 (** The linker visibility of a global value, accessed with {!visibility} and
97 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
98 module Visibility : sig
105 (** The following calling convention values may be accessed with
106 {!function_call_conv} and {!set_function_call_conv}. Calling
107 conventions are open-ended. *)
108 module CallConv : sig
109 val c : int (** [c] is the C calling convention. *)
110 val fast : int (** [fast] is the calling convention to allow LLVM
111 maximum optimization opportunities. Use only with
113 val cold : int (** [cold] is the calling convention for
115 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling
116 convention from C. *)
117 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
118 convention from C. *)
121 (** The attribute kind of a function parameter, result or the function itself.
122 See [llvm::Attribute::AttrKind]. *)
123 module Attribute : sig
147 | Stackalignment of int
153 (** The predicate for an integer comparison ([icmp]) instruction.
154 See the [llvm::ICmpInst::Predicate] enumeration. *)
169 (** The predicate for a floating-point comparison ([fcmp]) instruction.
170 See the [llvm::FCmpInst::Predicate] enumeration. *)
191 (** The opcodes for LLVM instructions and constant expressions. *)
194 | Invalid (* not an instruction *)
195 (* Terminator Instructions *)
203 (* Standard Binary Operators *)
216 (* Logical Operators *)
223 (* Memory Operators *)
241 (* Other Operators *)
262 (** The type of a clause of a [landingpad] instruction.
263 See [llvm::LandingPadInst::ClauseType]. *)
264 module LandingPadClauseTy : sig
270 (** The thread local mode of a global value, accessed with {!thread_local_mode}
271 and {!set_thread_local_mode}.
272 See [llvm::GlobalVariable::ThreadLocalMode]. *)
273 module ThreadLocalMode : sig
282 (** The ordering of an atomic [load], [store], [cmpxchg], [atomicrmw] or
283 [fence] instruction. See [llvm::AtomicOrdering]. *)
284 module AtomicOrdering : sig
289 | Invalid (* removed due to API changes *)
293 | SequentiallyConsistent
296 (** The opcode of an [atomicrmw] instruction.
297 See [llvm::AtomicRMWInst::BinOp]. *)
298 module AtomicRMWBinOp : sig
313 (** The kind of an [llvalue], the result of [classify_value v].
314 See the various [LLVMIsA*] functions. *)
315 module ValueKind : sig
324 | ConstantAggregateZero
331 | ConstantPointerNull
338 | Instruction of Opcode.t
344 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
345 of [a]. [llpos] is used to specify positions in and for forward iteration
346 through the various value lists maintained by the LLVM IR. *)
347 type ('a, 'b) llpos =
351 (** [After b] and [At_start a] specify positions from the end of the ['b] list
352 of [a]. [llrev_pos] is used for reverse iteration through the various value
353 lists maintained by the LLVM IR. *)
354 type ('a, 'b) llrev_pos =
359 (** {6 Exceptions} *)
361 exception IoError of string
366 (** [create_context ()] creates a context for storing the "global" state in
367 LLVM. See the constructor [llvm::LLVMContext]. *)
368 val create_context : unit -> llcontext
370 (** [destroy_context ()] destroys a context. See the destructor
371 [llvm::LLVMContext::~LLVMContext]. *)
372 val dispose_context : llcontext -> unit
374 (** See the function [llvm::getGlobalContext]. *)
375 val global_context : unit -> llcontext
377 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
378 name [name] in the context [context]. See the function
379 [llvm::LLVMContext::getMDKindID]. *)
380 val mdkind_id : llcontext -> string -> int
385 (** [create_module context id] creates a module with the supplied module ID in
386 the context [context]. Modules are not garbage collected; it is mandatory
387 to call {!dispose_module} to free memory. See the constructor
388 [llvm::Module::Module]. *)
389 val create_module : llcontext -> string -> llmodule
391 (** [dispose_module m] destroys a module [m] and all of the IR objects it
392 contained. All references to subordinate objects are invalidated;
393 referencing them will invoke undefined behavior. See the destructor
394 [llvm::Module::~Module]. *)
395 val dispose_module : llmodule -> unit
397 (** [target_triple m] is the target specifier for the module [m], something like
398 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
399 val target_triple: llmodule -> string
401 (** [target_triple triple m] changes the target specifier for the module [m] to
402 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
403 val set_target_triple: string -> llmodule -> unit
405 (** [data_layout m] is the data layout specifier for the module [m], something
406 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
407 method [llvm::Module::getDataLayout]. *)
408 val data_layout: llmodule -> string
410 (** [set_data_layout s m] changes the data layout specifier for the module [m]
411 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
412 val set_data_layout: string -> llmodule -> unit
414 (** [dump_module m] prints the .ll representation of the module [m] to standard
415 error. See the method [llvm::Module::dump]. *)
416 val dump_module : llmodule -> unit
418 (** [print_module f m] prints the .ll representation of the module [m]
419 to file [f]. See the method [llvm::Module::print]. *)
420 val print_module : string -> llmodule -> unit
422 (** [string_of_llmodule m] returns the .ll representation of the module [m]
423 as a string. See the method [llvm::Module::print]. *)
424 val string_of_llmodule : llmodule -> string
426 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
427 the method [llvm::Module::setModuleInlineAsm]. *)
428 val set_module_inline_asm : llmodule -> string -> unit
430 (** [module_context m] returns the context of the specified module.
431 See the method [llvm::Module::getContext] *)
432 val module_context : llmodule -> llcontext
437 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
438 See the method [llvm::Type::getTypeID]. *)
439 val classify_type : lltype -> TypeKind.t
441 (** [type_is_sized ty] returns whether the type has a size or not.
442 If it doesn't then it is not safe to call the [DataLayout::] methods on it.
444 val type_is_sized : lltype -> bool
446 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
447 See the method [llvm::Type::getContext]. *)
448 val type_context : lltype -> llcontext
450 (** [dump_type ty] prints the .ll representation of the type [ty] to standard
451 error. See the method [llvm::Type::dump]. *)
452 val dump_type : lltype -> unit
454 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
455 val string_of_lltype : lltype -> string
458 (** {7 Operations on integer types} *)
460 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
461 [llvm::Type::Int1Ty]. *)
462 val i1_type : llcontext -> lltype
464 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
465 [llvm::Type::Int8Ty]. *)
466 val i8_type : llcontext -> lltype
468 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
469 [llvm::Type::Int16Ty]. *)
470 val i16_type : llcontext -> lltype
472 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
473 [llvm::Type::Int32Ty]. *)
474 val i32_type : llcontext -> lltype
476 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
477 [llvm::Type::Int64Ty]. *)
478 val i64_type : llcontext -> lltype
480 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
481 [c]. See the method [llvm::IntegerType::get]. *)
482 val integer_type : llcontext -> int -> lltype
484 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
485 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
486 val integer_bitwidth : lltype -> int
489 (** {7 Operations on real types} *)
491 (** [float_type c] returns the IEEE 32-bit floating point type in the context
492 [c]. See [llvm::Type::FloatTy]. *)
493 val float_type : llcontext -> lltype
495 (** [double_type c] returns the IEEE 64-bit floating point type in the context
496 [c]. See [llvm::Type::DoubleTy]. *)
497 val double_type : llcontext -> lltype
499 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
500 [c]. See [llvm::Type::X86_FP80Ty]. *)
501 val x86fp80_type : llcontext -> lltype
503 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
504 [c]. See [llvm::Type::FP128Ty]. *)
505 val fp128_type : llcontext -> lltype
507 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
508 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
509 val ppc_fp128_type : llcontext -> lltype
512 (** {7 Operations on function types} *)
514 (** [function_type ret_ty param_tys] returns the function type returning
515 [ret_ty] and taking [param_tys] as parameters.
516 See the method [llvm::FunctionType::get]. *)
517 val function_type : lltype -> lltype array -> lltype
519 (** [var_arg_function_type ret_ty param_tys] is just like
520 [function_type ret_ty param_tys] except that it returns the function type
521 which also takes a variable number of arguments.
522 See the method [llvm::FunctionType::get]. *)
523 val var_arg_function_type : lltype -> lltype array -> lltype
525 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
526 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
527 val is_var_arg : lltype -> bool
529 (** [return_type fty] gets the return type of the function type [fty].
530 See the method [llvm::FunctionType::getReturnType]. *)
531 val return_type : lltype -> lltype
533 (** [param_types fty] gets the parameter types of the function type [fty].
534 See the method [llvm::FunctionType::getParamType]. *)
535 val param_types : lltype -> lltype array
538 (** {7 Operations on struct types} *)
540 (** [struct_type context tys] returns the structure type in the context
541 [context] containing in the types in the array [tys]. See the method
542 [llvm::StructType::get]. *)
543 val struct_type : llcontext -> lltype array -> lltype
545 (** [packed_struct_type context ys] returns the packed structure type in the
546 context [context] containing in the types in the array [tys]. See the method
547 [llvm::StructType::get]. *)
548 val packed_struct_type : llcontext -> lltype array -> lltype
550 (** [struct_name ty] returns the name of the named structure type [ty],
551 or None if the structure type is not named *)
552 val struct_name : lltype -> string option
554 (** [named_struct_type context name] returns the named structure type [name]
555 in the context [context].
556 See the method [llvm::StructType::get]. *)
557 val named_struct_type : llcontext -> string -> lltype
559 (** [struct_set_body ty elts ispacked] sets the body of the named struct [ty]
560 to the [elts] elements.
561 See the moethd [llvm::StructType::setBody]. *)
562 val struct_set_body : lltype -> lltype array -> bool -> unit
564 (** [struct_element_types sty] returns the constituent types of the struct type
565 [sty]. See the method [llvm::StructType::getElementType]. *)
566 val struct_element_types : lltype -> lltype array
568 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
569 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
570 val is_packed : lltype -> bool
572 (** [is_opaque sty] returns [true] if the structure type [sty] is opaque.
573 [false] otherwise. See the method [llvm::StructType::isOpaque]. *)
574 val is_opaque : lltype -> bool
577 (** {7 Operations on pointer, vector, and array types} *)
579 (** [array_type ty n] returns the array type containing [n] elements of type
580 [ty]. See the method [llvm::ArrayType::get]. *)
581 val array_type : lltype -> int -> lltype
583 (** [pointer_type ty] returns the pointer type referencing objects of type
584 [ty] in the default address space (0).
585 See the method [llvm::PointerType::getUnqual]. *)
586 val pointer_type : lltype -> lltype
588 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
589 of type [ty] in address space [as].
590 See the method [llvm::PointerType::get]. *)
591 val qualified_pointer_type : lltype -> int -> lltype
593 (** [vector_type ty n] returns the array type containing [n] elements of the
594 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
595 val vector_type : lltype -> int -> lltype
597 (** [element_type ty] returns the element type of the pointer, vector, or array
598 type [ty]. See the method [llvm::SequentialType::get]. *)
599 val element_type : lltype -> lltype
601 (** [element_type aty] returns the element count of the array type [aty].
602 See the method [llvm::ArrayType::getNumElements]. *)
603 val array_length : lltype -> int
605 (** [address_space pty] returns the address space qualifier of the pointer type
606 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
607 val address_space : lltype -> int
609 (** [element_type ty] returns the element count of the vector type [ty].
610 See the method [llvm::VectorType::getNumElements]. *)
611 val vector_size : lltype -> int
614 (** {7 Operations on other types} *)
616 (** [void_type c] creates a type of a function which does not return any
617 value in the context [c]. See [llvm::Type::VoidTy]. *)
618 val void_type : llcontext -> lltype
620 (** [label_type c] creates a type of a basic block in the context [c]. See
621 [llvm::Type::LabelTy]. *)
622 val label_type : llcontext -> lltype
624 (** [x86_mmx_type c] returns the x86 64-bit MMX register type in the
625 context [c]. See [llvm::Type::X86_MMXTy]. *)
626 val x86_mmx_type : llcontext -> lltype
628 (** [type_by_name m name] returns the specified type from the current module
630 See the method [llvm::Module::getTypeByName] *)
631 val type_by_name : llmodule -> string -> lltype option
636 (** [type_of v] returns the type of the value [v].
637 See the method [llvm::Value::getType]. *)
638 val type_of : llvalue -> lltype
640 (** [classify_value v] returns the kind of the value [v]. *)
641 val classify_value : llvalue -> ValueKind.t
643 (** [value_name v] returns the name of the value [v]. For global values, this is
644 the symbol name. For instructions and basic blocks, it is the SSA register
645 name. It is meaningless for constants.
646 See the method [llvm::Value::getName]. *)
647 val value_name : llvalue -> string
649 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
650 [llvm::Value::setName]. *)
651 val set_value_name : string -> llvalue -> unit
653 (** [dump_value v] prints the .ll representation of the value [v] to standard
654 error. See the method [llvm::Value::dump]. *)
655 val dump_value : llvalue -> unit
657 (** [string_of_llvalue v] returns a string describing the value [v]. *)
658 val string_of_llvalue : llvalue -> string
660 (** [replace_all_uses_with old new] replaces all uses of the value [old]
661 with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
662 val replace_all_uses_with : llvalue -> llvalue -> unit
667 (** [use_begin v] returns the first position in the use list for the value [v].
668 [use_begin] and [use_succ] can e used to iterate over the use list in order.
669 See the method [llvm::Value::use_begin]. *)
670 val use_begin : llvalue -> lluse option
672 (** [use_succ u] returns the use list position succeeding [u].
673 See the method [llvm::use_value_iterator::operator++]. *)
674 val use_succ : lluse -> lluse option
676 (** [user u] returns the user of the use [u].
677 See the method [llvm::Use::getUser]. *)
678 val user : lluse -> llvalue
680 (** [used_value u] returns the usee of the use [u].
681 See the method [llvm::Use::getUsedValue]. *)
682 val used_value : lluse -> llvalue
684 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
685 in order. Tail recursive. *)
686 val iter_uses : (lluse -> unit) -> llvalue -> unit
688 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
689 [u1,...,uN] are the users of the value [v]. Tail recursive. *)
690 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
692 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
693 [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
694 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
699 (** [operand v i] returns the operand at index [i] for the value [v]. See the
700 method [llvm::User::getOperand]. *)
701 val operand : llvalue -> int -> llvalue
703 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
705 See the method [llvm::User::setOperand]. *)
706 val set_operand : llvalue -> int -> llvalue -> unit
708 (** [num_operands v] returns the number of operands for the value [v].
709 See the method [llvm::User::getNumOperands]. *)
710 val num_operands : llvalue -> int
713 (** {7 Operations on constants of (mostly) any type} *)
715 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
716 otherwise. Similar to [llvm::isa<Constant>]. *)
717 val is_constant : llvalue -> bool
719 (** [const_null ty] returns the constant null (zero) of the type [ty].
720 See the method [llvm::Constant::getNullValue]. *)
721 val const_null : lltype -> llvalue
723 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
724 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
725 val const_all_ones : (*int|vec*)lltype -> llvalue
727 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
728 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
729 val const_pointer_null : lltype -> llvalue
731 (** [undef ty] returns the undefined value of the type [ty].
732 See the method [llvm::UndefValue::get]. *)
733 val undef : lltype -> llvalue
735 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
736 See the method [llvm::Constant::isNullValue]. *)
737 val is_null : llvalue -> bool
739 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
740 otherwise. Similar to [llvm::isa<UndefValue>]. *)
741 val is_undef : llvalue -> bool
743 (** [constexpr_opcode v] returns an [Opcode.t] corresponding to constexpr
744 value [v], or [Opcode.Invalid] if [v] is not a constexpr. *)
745 val constexpr_opcode : llvalue -> Opcode.t
748 (** {7 Operations on instructions} *)
750 (** [has_metadata i] returns whether or not the instruction [i] has any
751 metadata attached to it. See the function
752 [llvm::Instruction::hasMetadata]. *)
753 val has_metadata : llvalue -> bool
755 (** [metadata i kind] optionally returns the metadata associated with the
756 kind [kind] in the instruction [i] See the function
757 [llvm::Instruction::getMetadata]. *)
758 val metadata : llvalue -> int -> llvalue option
760 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
761 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
762 val set_metadata : llvalue -> int -> llvalue -> unit
764 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
765 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
766 val clear_metadata : llvalue -> int -> unit
769 (** {7 Operations on metadata} *)
771 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
772 See the method [llvm::MDNode::get]. *)
773 val mdstring : llcontext -> string -> llvalue
775 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
777 See the method [llvm::MDNode::get]. *)
778 val mdnode : llcontext -> llvalue array -> llvalue
780 (** [get_mdstring v] returns the MDString.
781 See the method [llvm::MDString::getString] *)
782 val get_mdstring : llvalue -> string option
784 (** [get_named_metadata m name] returns all the MDNodes belonging to the named
786 See the method [llvm::NamedMDNode::getOperand]. *)
787 val get_named_metadata : llmodule -> string -> llvalue array
789 (** [add_named_metadata_operand m name v] adds [v] as the last operand of
790 metadata named [name] in module [m]. If the metadata does not exist,
792 See the methods [llvm::Module::getNamedMetadata()] and
793 [llvm::MDNode::addOperand()]. *)
794 val add_named_metadata_operand : llmodule -> string -> llvalue -> unit
797 (** {7 Operations on scalar constants} *)
799 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
800 See the method [llvm::ConstantInt::get]. *)
801 val const_int : lltype -> int -> llvalue
803 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
804 [i]. See the method [llvm::ConstantInt::get]. *)
805 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
807 (** [int64_of_const c] returns the int64 value of the [c] constant integer.
808 None is returned if this is not an integer constant, or bitwidth exceeds 64.
809 See the method [llvm::ConstantInt::getSExtValue].*)
810 val int64_of_const : llvalue -> Int64.t option
812 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
813 value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
814 val const_int_of_string : lltype -> string -> int -> llvalue
816 (** [const_float ty n] returns the floating point constant of type [ty] and
817 value [n]. See the method [llvm::ConstantFP::get]. *)
818 val const_float : lltype -> float -> llvalue
820 (** [const_float_of_string ty s] returns the floating point constant of type
821 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
822 val const_float_of_string : lltype -> string -> llvalue
825 (** {7 Operations on composite constants} *)
827 (** [const_string c s] returns the constant [i8] array with the values of the
828 characters in the string [s] in the context [c]. The array is not
829 null-terminated (but see {!const_stringz}). This value can in turn be used
830 as the initializer for a global variable. See the method
831 [llvm::ConstantArray::get]. *)
832 val const_string : llcontext -> string -> llvalue
834 (** [const_stringz c s] returns the constant [i8] array with the values of the
835 characters in the string [s] and a null terminator in the context [c]. This
836 value can in turn be used as the initializer for a global variable.
837 See the method [llvm::ConstantArray::get]. *)
838 val const_stringz : llcontext -> string -> llvalue
840 (** [const_array ty elts] returns the constant array of type
841 [array_type ty (Array.length elts)] and containing the values [elts].
842 This value can in turn be used as the initializer for a global variable.
843 See the method [llvm::ConstantArray::get]. *)
844 val const_array : lltype -> llvalue array -> llvalue
846 (** [const_struct context elts] returns the structured constant of type
847 [struct_type (Array.map type_of elts)] and containing the values [elts]
848 in the context [context]. This value can in turn be used as the initializer
849 for a global variable. See the method [llvm::ConstantStruct::getAnon]. *)
850 val const_struct : llcontext -> llvalue array -> llvalue
852 (** [const_named_struct namedty elts] returns the structured constant of type
853 [namedty] (which must be a named structure type) and containing the values [elts].
854 This value can in turn be used as the initializer
855 for a global variable. See the method [llvm::ConstantStruct::get]. *)
856 val const_named_struct : lltype -> llvalue array -> llvalue
858 (** [const_packed_struct context elts] returns the structured constant of
859 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
860 values [elts] in the context [context]. This value can in turn be used as
861 the initializer for a global variable. See the method
862 [llvm::ConstantStruct::get]. *)
863 val const_packed_struct : llcontext -> llvalue array -> llvalue
865 (** [const_vector elts] returns the vector constant of type
866 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
867 values [elts]. See the method [llvm::ConstantVector::get]. *)
868 val const_vector : llvalue array -> llvalue
871 (** {7 Constant expressions} *)
873 (** [align_of ty] returns the alignof constant for the type [ty]. This is
874 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
875 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
876 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
877 val align_of : lltype -> llvalue
879 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
880 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
881 (const_int i32_type 1)) i64_type], but considerably more readable.
882 See the method [llvm::ConstantExpr::getSizeOf]. *)
883 val size_of : lltype -> llvalue
885 (** [const_neg c] returns the arithmetic negation of the constant [c].
886 See the method [llvm::ConstantExpr::getNeg]. *)
887 val const_neg : llvalue -> llvalue
889 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
890 no signed wrapping. The result is undefined if the negation overflows.
891 See the method [llvm::ConstantExpr::getNSWNeg]. *)
892 val const_nsw_neg : llvalue -> llvalue
894 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
895 no unsigned wrapping. The result is undefined if the negation overflows.
896 See the method [llvm::ConstantExpr::getNUWNeg]. *)
897 val const_nuw_neg : llvalue -> llvalue
899 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
900 See the method [llvm::ConstantExpr::getFNeg]. *)
901 val const_fneg : llvalue -> llvalue
903 (** [const_not c] returns the bitwise inverse of the constant [c].
904 See the method [llvm::ConstantExpr::getNot]. *)
905 val const_not : llvalue -> llvalue
907 (** [const_add c1 c2] returns the constant sum of two constants.
908 See the method [llvm::ConstantExpr::getAdd]. *)
909 val const_add : llvalue -> llvalue -> llvalue
911 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
912 signed wrapping. The result is undefined if the sum overflows.
913 See the method [llvm::ConstantExpr::getNSWAdd]. *)
914 val const_nsw_add : llvalue -> llvalue -> llvalue
916 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
917 unsigned wrapping. The result is undefined if the sum overflows.
918 See the method [llvm::ConstantExpr::getNSWAdd]. *)
919 val const_nuw_add : llvalue -> llvalue -> llvalue
921 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
922 See the method [llvm::ConstantExpr::getFAdd]. *)
923 val const_fadd : llvalue -> llvalue -> llvalue
925 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
926 constants. See the method [llvm::ConstantExpr::getSub]. *)
927 val const_sub : llvalue -> llvalue -> llvalue
929 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
930 no signed wrapping. The result is undefined if the sum overflows.
931 See the method [llvm::ConstantExpr::getNSWSub]. *)
932 val const_nsw_sub : llvalue -> llvalue -> llvalue
934 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
935 no unsigned wrapping. The result is undefined if the sum overflows.
936 See the method [llvm::ConstantExpr::getNSWSub]. *)
937 val const_nuw_sub : llvalue -> llvalue -> llvalue
939 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
940 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
941 val const_fsub : llvalue -> llvalue -> llvalue
943 (** [const_mul c1 c2] returns the constant product of two constants.
944 See the method [llvm::ConstantExpr::getMul]. *)
945 val const_mul : llvalue -> llvalue -> llvalue
947 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
948 no signed wrapping. The result is undefined if the sum overflows.
949 See the method [llvm::ConstantExpr::getNSWMul]. *)
950 val const_nsw_mul : llvalue -> llvalue -> llvalue
952 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
953 no unsigned wrapping. The result is undefined if the sum overflows.
954 See the method [llvm::ConstantExpr::getNSWMul]. *)
955 val const_nuw_mul : llvalue -> llvalue -> llvalue
957 (** [const_fmul c1 c2] returns the constant product of two constants floats.
958 See the method [llvm::ConstantExpr::getFMul]. *)
959 val const_fmul : llvalue -> llvalue -> llvalue
961 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
963 See the method [llvm::ConstantExpr::getUDiv]. *)
964 val const_udiv : llvalue -> llvalue -> llvalue
966 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
968 See the method [llvm::ConstantExpr::getSDiv]. *)
969 val const_sdiv : llvalue -> llvalue -> llvalue
971 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
972 signed integer constants. The result is undefined if the result is rounded
973 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
974 val const_exact_sdiv : llvalue -> llvalue -> llvalue
976 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
978 See the method [llvm::ConstantExpr::getFDiv]. *)
979 val const_fdiv : llvalue -> llvalue -> llvalue
981 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
982 unsigned integer constants.
983 See the method [llvm::ConstantExpr::getURem]. *)
984 val const_urem : llvalue -> llvalue -> llvalue
986 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
987 signed integer constants.
988 See the method [llvm::ConstantExpr::getSRem]. *)
989 val const_srem : llvalue -> llvalue -> llvalue
991 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
992 signed floating point constants.
993 See the method [llvm::ConstantExpr::getFRem]. *)
994 val const_frem : llvalue -> llvalue -> llvalue
996 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
998 See the method [llvm::ConstantExpr::getAnd]. *)
999 val const_and : llvalue -> llvalue -> llvalue
1001 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
1003 See the method [llvm::ConstantExpr::getOr]. *)
1004 val const_or : llvalue -> llvalue -> llvalue
1006 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
1008 See the method [llvm::ConstantExpr::getXor]. *)
1009 val const_xor : llvalue -> llvalue -> llvalue
1011 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
1012 constants, [c1 pred c2].
1013 See the method [llvm::ConstantExpr::getICmp]. *)
1014 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
1016 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
1017 point constants, [c1 pred c2].
1018 See the method [llvm::ConstantExpr::getFCmp]. *)
1019 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
1021 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
1022 constant integer [c2].
1023 See the method [llvm::ConstantExpr::getShl]. *)
1024 val const_shl : llvalue -> llvalue -> llvalue
1026 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
1027 constant integer [c2] with zero extension.
1028 See the method [llvm::ConstantExpr::getLShr]. *)
1029 val const_lshr : llvalue -> llvalue -> llvalue
1031 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
1032 constant integer [c2] with sign extension.
1033 See the method [llvm::ConstantExpr::getAShr]. *)
1034 val const_ashr : llvalue -> llvalue -> llvalue
1036 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
1037 constant integers indices from the array [indices].
1038 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
1039 val const_gep : llvalue -> llvalue array -> llvalue
1041 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
1042 with the constant integers indices from the array [indices].
1043 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
1044 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
1046 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
1047 to the smaller integer type [ty].
1048 See the method [llvm::ConstantExpr::getTrunc]. *)
1049 val const_trunc : llvalue -> lltype -> llvalue
1051 (** [const_sext c ty] returns the constant sign extension of integer constant
1052 [c] to the larger integer type [ty].
1053 See the method [llvm::ConstantExpr::getSExt]. *)
1054 val const_sext : llvalue -> lltype -> llvalue
1056 (** [const_zext c ty] returns the constant zero extension of integer constant
1057 [c] to the larger integer type [ty].
1058 See the method [llvm::ConstantExpr::getZExt]. *)
1059 val const_zext : llvalue -> lltype -> llvalue
1061 (** [const_fptrunc c ty] returns the constant truncation of floating point
1062 constant [c] to the smaller floating point type [ty].
1063 See the method [llvm::ConstantExpr::getFPTrunc]. *)
1064 val const_fptrunc : llvalue -> lltype -> llvalue
1066 (** [const_fpext c ty] returns the constant extension of floating point constant
1067 [c] to the larger floating point type [ty].
1068 See the method [llvm::ConstantExpr::getFPExt]. *)
1069 val const_fpext : llvalue -> lltype -> llvalue
1071 (** [const_uitofp c ty] returns the constant floating point conversion of
1072 unsigned integer constant [c] to the floating point type [ty].
1073 See the method [llvm::ConstantExpr::getUIToFP]. *)
1074 val const_uitofp : llvalue -> lltype -> llvalue
1076 (** [const_sitofp c ty] returns the constant floating point conversion of
1077 signed integer constant [c] to the floating point type [ty].
1078 See the method [llvm::ConstantExpr::getSIToFP]. *)
1079 val const_sitofp : llvalue -> lltype -> llvalue
1081 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
1082 floating point constant [c] to integer type [ty].
1083 See the method [llvm::ConstantExpr::getFPToUI]. *)
1084 val const_fptoui : llvalue -> lltype -> llvalue
1086 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
1087 floating point constant [c] to integer type [ty].
1088 See the method [llvm::ConstantExpr::getFPToSI]. *)
1089 val const_fptosi : llvalue -> lltype -> llvalue
1091 (** [const_ptrtoint c ty] returns the constant integer conversion of
1092 pointer constant [c] to integer type [ty].
1093 See the method [llvm::ConstantExpr::getPtrToInt]. *)
1094 val const_ptrtoint : llvalue -> lltype -> llvalue
1096 (** [const_inttoptr c ty] returns the constant pointer conversion of
1097 integer constant [c] to pointer type [ty].
1098 See the method [llvm::ConstantExpr::getIntToPtr]. *)
1099 val const_inttoptr : llvalue -> lltype -> llvalue
1101 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
1102 to type [ty] of equal size.
1103 See the method [llvm::ConstantExpr::getBitCast]. *)
1104 val const_bitcast : llvalue -> lltype -> llvalue
1106 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
1107 conversion of constant [c] to type [ty].
1108 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
1109 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
1111 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
1112 conversion of constant [c] to type [ty].
1113 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
1114 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
1116 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
1117 conversion of constant [c] to type [ty].
1118 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
1119 val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
1121 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
1122 cast conversion of constant [c] to type [ty] of equal size.
1123 See the method [llvm::ConstantExpr::getPointerCast]. *)
1124 val const_pointercast : llvalue -> lltype -> llvalue
1126 (** [const_intcast c ty ~is_signed] returns a constant sext/zext, bitcast,
1127 or trunc for integer -> integer casts of constant [c] to type [ty].
1128 When converting a narrower value to a wider one, whether sext or zext
1129 will be used is controlled by [is_signed].
1130 See the method [llvm::ConstantExpr::getIntegerCast]. *)
1131 val const_intcast : llvalue -> lltype -> is_signed:bool -> llvalue
1133 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
1134 fp casts of constant [c] to type [ty].
1135 See the method [llvm::ConstantExpr::getFPCast]. *)
1136 val const_fpcast : llvalue -> lltype -> llvalue
1138 (** [const_select cond t f] returns the constant conditional which returns value
1139 [t] if the boolean constant [cond] is true and the value [f] otherwise.
1140 See the method [llvm::ConstantExpr::getSelect]. *)
1141 val const_select : llvalue -> llvalue -> llvalue -> llvalue
1143 (** [const_extractelement vec i] returns the constant [i]th element of
1144 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
1145 the size of the vector.
1146 See the method [llvm::ConstantExpr::getExtractElement]. *)
1147 val const_extractelement : llvalue -> llvalue -> llvalue
1149 (** [const_insertelement vec v i] returns the constant vector with the same
1150 elements as constant vector [v] but the [i]th element replaced by the
1151 constant [v]. [v] must be a constant value with the type of the vector
1152 elements. [i] must be a constant [i32] value unsigned less than the size
1154 See the method [llvm::ConstantExpr::getInsertElement]. *)
1155 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
1157 (** [const_shufflevector a b mask] returns a constant [shufflevector].
1158 See the LLVM Language Reference for details on the [shufflevector]
1160 See the method [llvm::ConstantExpr::getShuffleVector]. *)
1161 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
1163 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
1164 constant aggregate [agg]. Each [idxs] must be less than the size of the
1165 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
1166 val const_extractvalue : llvalue -> int array -> llvalue
1168 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
1169 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
1170 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
1171 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
1173 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
1174 See the method [llvm::InlineAsm::get]. *)
1175 val const_inline_asm : lltype -> string -> string -> bool -> bool -> llvalue
1177 (** [block_address f bb] returns the address of the basic block [bb] in the
1178 function [f]. See the method [llvm::BasicBlock::get]. *)
1179 val block_address : llvalue -> llbasicblock -> llvalue
1182 (** {7 Operations on global variables, functions, and aliases (globals)} *)
1184 (** [global_parent g] is the enclosing module of the global value [g].
1185 See the method [llvm::GlobalValue::getParent]. *)
1186 val global_parent : llvalue -> llmodule
1188 (** [is_declaration g] returns [true] if the global value [g] is a declaration
1189 only. Returns [false] otherwise.
1190 See the method [llvm::GlobalValue::isDeclaration]. *)
1191 val is_declaration : llvalue -> bool
1193 (** [linkage g] returns the linkage of the global value [g].
1194 See the method [llvm::GlobalValue::getLinkage]. *)
1195 val linkage : llvalue -> Linkage.t
1197 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
1198 See the method [llvm::GlobalValue::setLinkage]. *)
1199 val set_linkage : Linkage.t -> llvalue -> unit
1201 (** [section g] returns the linker section of the global value [g].
1202 See the method [llvm::GlobalValue::getSection]. *)
1203 val section : llvalue -> string
1205 (** [set_section s g] sets the linker section of the global value [g] to [s].
1206 See the method [llvm::GlobalValue::setSection]. *)
1207 val set_section : string -> llvalue -> unit
1209 (** [visibility g] returns the linker visibility of the global value [g].
1210 See the method [llvm::GlobalValue::getVisibility]. *)
1211 val visibility : llvalue -> Visibility.t
1213 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1214 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1215 val set_visibility : Visibility.t -> llvalue -> unit
1217 (** [alignment g] returns the required alignment of the global value [g].
1218 See the method [llvm::GlobalValue::getAlignment]. *)
1219 val alignment : llvalue -> int
1221 (** [set_alignment n g] sets the required alignment of the global value [g] to
1222 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1223 val set_alignment : int -> llvalue -> unit
1226 (** {7 Operations on global variables} *)
1228 (** [declare_global ty name m] returns a new global variable of type [ty] and
1229 with name [name] in module [m] in the default address space (0). If such a
1230 global variable already exists, it is returned. If the type of the existing
1231 global differs, then a bitcast to [ty] is returned. *)
1232 val declare_global : lltype -> string -> llmodule -> llvalue
1234 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1235 of type [ty] and with name [name] in module [m] in the address space
1236 [addrspace]. If such a global variable already exists, it is returned. If
1237 the type of the existing global differs, then a bitcast to [ty] is
1239 val declare_qualified_global : lltype -> string -> int -> llmodule -> llvalue
1241 (** [define_global name init m] returns a new global with name [name] and
1242 initializer [init] in module [m] in the default address space (0). If the
1243 named global already exists, it is renamed.
1244 See the constructor of [llvm::GlobalVariable]. *)
1245 val define_global : string -> llvalue -> llmodule -> llvalue
1247 (** [define_qualified_global name init addrspace m] returns a new global with
1248 name [name] and initializer [init] in module [m] in the address space
1249 [addrspace]. If the named global already exists, it is renamed.
1250 See the constructor of [llvm::GlobalVariable]. *)
1251 val define_qualified_global : string -> llvalue -> int -> llmodule -> llvalue
1253 (** [lookup_global name m] returns [Some g] if a global variable with name
1254 [name] exists in module [m]. If no such global exists, returns [None].
1255 See the [llvm::GlobalVariable] constructor. *)
1256 val lookup_global : string -> llmodule -> llvalue option
1258 (** [delete_global gv] destroys the global variable [gv].
1259 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1260 val delete_global : llvalue -> unit
1262 (** [global_begin m] returns the first position in the global variable list of
1263 the module [m]. [global_begin] and [global_succ] can be used to iterate
1264 over the global list in order.
1265 See the method [llvm::Module::global_begin]. *)
1266 val global_begin : llmodule -> (llmodule, llvalue) llpos
1268 (** [global_succ gv] returns the global variable list position succeeding
1270 See the method [llvm::Module::global_iterator::operator++]. *)
1271 val global_succ : llvalue -> (llmodule, llvalue) llpos
1273 (** [iter_globals f m] applies function [f] to each of the global variables of
1274 module [m] in order. Tail recursive. *)
1275 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1277 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1278 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1279 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1281 (** [global_end m] returns the last position in the global variable list of the
1282 module [m]. [global_end] and [global_pred] can be used to iterate over the
1283 global list in reverse.
1284 See the method [llvm::Module::global_end]. *)
1285 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1287 (** [global_pred gv] returns the global variable list position preceding
1289 See the method [llvm::Module::global_iterator::operator--]. *)
1290 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1292 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1293 of module [m] in reverse order. Tail recursive. *)
1294 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1296 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1297 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1298 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1300 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1301 constant. Returns [false] otherwise.
1302 See the method [llvm::GlobalVariable::isConstant]. *)
1303 val is_global_constant : llvalue -> bool
1305 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1306 [c] is [true] and not if [c] is [false].
1307 See the method [llvm::GlobalVariable::setConstant]. *)
1308 val set_global_constant : bool -> llvalue -> unit
1310 (** [global_initializer gv] returns the initializer for the global variable
1311 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1312 val global_initializer : llvalue -> llvalue
1314 (** [set_initializer c gv] sets the initializer for the global variable
1315 [gv] to the constant [c].
1316 See the method [llvm::GlobalVariable::setInitializer]. *)
1317 val set_initializer : llvalue -> llvalue -> unit
1319 (** [remove_initializer gv] unsets the initializer for the global variable
1321 See the method [llvm::GlobalVariable::setInitializer]. *)
1322 val remove_initializer : llvalue -> unit
1324 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1325 thread-local and [false] otherwise.
1326 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1327 val is_thread_local : llvalue -> bool
1329 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1330 [c] is [true] and not otherwise.
1331 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1332 val set_thread_local : bool -> llvalue -> unit
1334 (** [is_thread_local gv] returns the thread local mode of the global
1336 See the method [llvm::GlobalVariable::getThreadLocalMode]. *)
1337 val thread_local_mode : llvalue -> ThreadLocalMode.t
1339 (** [set_thread_local c gv] sets the thread local mode of the global
1341 See the method [llvm::GlobalVariable::setThreadLocalMode]. *)
1342 val set_thread_local_mode : ThreadLocalMode.t -> llvalue -> unit
1344 (** [is_externally_initialized gv] returns [true] if the global
1345 variable [gv] is externally initialized and [false] otherwise.
1346 See the method [llvm::GlobalVariable::isExternallyInitialized]. *)
1347 val is_externally_initialized : llvalue -> bool
1349 (** [set_externally_initialized c gv] sets the global variable [gv] to be
1350 externally initialized if [c] is [true] and not otherwise.
1351 See the method [llvm::GlobalVariable::setExternallyInitialized]. *)
1352 val set_externally_initialized : bool -> llvalue -> unit
1355 (** {7 Operations on aliases} *)
1357 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1358 the aliasee [a] with the name [n].
1359 See the constructor for [llvm::GlobalAlias]. *)
1360 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1363 (** {7 Operations on functions} *)
1365 (** [declare_function name ty m] returns a new function of type [ty] and
1366 with name [name] in module [m]. If such a function already exists,
1367 it is returned. If the type of the existing function differs, then a bitcast
1368 to [ty] is returned. *)
1369 val declare_function : string -> lltype -> llmodule -> llvalue
1371 (** [define_function name ty m] creates a new function with name [name] and
1372 type [ty] in module [m]. If the named function already exists, it is
1373 renamed. An entry basic block is created in the function.
1374 See the constructor of [llvm::GlobalVariable]. *)
1375 val define_function : string -> lltype -> llmodule -> llvalue
1377 (** [lookup_function name m] returns [Some f] if a function with name
1378 [name] exists in module [m]. If no such function exists, returns [None].
1379 See the method [llvm::Module] constructor. *)
1380 val lookup_function : string -> llmodule -> llvalue option
1382 (** [delete_function f] destroys the function [f].
1383 See the method [llvm::Function::eraseFromParent]. *)
1384 val delete_function : llvalue -> unit
1386 (** [function_begin m] returns the first position in the function list of the
1387 module [m]. [function_begin] and [function_succ] can be used to iterate over
1388 the function list in order.
1389 See the method [llvm::Module::begin]. *)
1390 val function_begin : llmodule -> (llmodule, llvalue) llpos
1392 (** [function_succ gv] returns the function list position succeeding
1394 See the method [llvm::Module::iterator::operator++]. *)
1395 val function_succ : llvalue -> (llmodule, llvalue) llpos
1397 (** [iter_functions f m] applies function [f] to each of the functions of module
1398 [m] in order. Tail recursive. *)
1399 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1401 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1402 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1403 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1405 (** [function_end m] returns the last position in the function list of
1406 the module [m]. [function_end] and [function_pred] can be used to iterate
1407 over the function list in reverse.
1408 See the method [llvm::Module::end]. *)
1409 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1411 (** [function_pred gv] returns the function list position preceding [After gv].
1412 See the method [llvm::Module::iterator::operator--]. *)
1413 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1415 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1416 module [m] in reverse order. Tail recursive. *)
1417 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1419 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1420 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1421 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1423 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1424 See the method [llvm::Function::isIntrinsic]. *)
1425 val is_intrinsic : llvalue -> bool
1427 (** [function_call_conv f] returns the calling convention of the function [f].
1428 See the method [llvm::Function::getCallingConv]. *)
1429 val function_call_conv : llvalue -> int
1431 (** [set_function_call_conv cc f] sets the calling convention of the function
1432 [f] to the calling convention numbered [cc].
1433 See the method [llvm::Function::setCallingConv]. *)
1434 val set_function_call_conv : int -> llvalue -> unit
1436 (** [gc f] returns [Some name] if the function [f] has a garbage
1437 collection algorithm specified and [None] otherwise.
1438 See the method [llvm::Function::getGC]. *)
1439 val gc : llvalue -> string option
1441 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1442 [gc]. See the method [llvm::Function::setGC]. *)
1443 val set_gc : string option -> llvalue -> unit
1445 (** [add_function_attr f a] adds attribute [a] to the return type of function
1447 val add_function_attr : llvalue -> Attribute.t -> unit
1449 (** [add_target_dependent_function_attr f a] adds target-dependent attribute
1450 [a] to function [f]. *)
1451 val add_target_dependent_function_attr : llvalue -> string -> string -> unit
1453 (** [function_attr f] returns the function attribute for the function [f].
1454 See the method [llvm::Function::getAttributes] *)
1455 val function_attr : llvalue -> Attribute.t list
1457 (** [remove_function_attr f a] removes attribute [a] from the return type of
1459 val remove_function_attr : llvalue -> Attribute.t -> unit
1462 (** {7 Operations on params} *)
1464 (** [params f] returns the parameters of function [f].
1465 See the method [llvm::Function::getArgumentList]. *)
1466 val params : llvalue -> llvalue array
1468 (** [param f n] returns the [n]th parameter of function [f].
1469 See the method [llvm::Function::getArgumentList]. *)
1470 val param : llvalue -> int -> llvalue
1472 (** [param_attr p] returns the attributes of parameter [p].
1473 See the methods [llvm::Function::getAttributes] and
1474 [llvm::Attributes::getParamAttributes] *)
1475 val param_attr : llvalue -> Attribute.t list
1477 (** [param_parent p] returns the parent function that owns the parameter.
1478 See the method [llvm::Argument::getParent]. *)
1479 val param_parent : llvalue -> llvalue
1481 (** [param_begin f] returns the first position in the parameter list of the
1482 function [f]. [param_begin] and [param_succ] can be used to iterate over
1483 the parameter list in order.
1484 See the method [llvm::Function::arg_begin]. *)
1485 val param_begin : llvalue -> (llvalue, llvalue) llpos
1487 (** [param_succ bb] returns the parameter list position succeeding
1489 See the method [llvm::Function::arg_iterator::operator++]. *)
1490 val param_succ : llvalue -> (llvalue, llvalue) llpos
1492 (** [iter_params f fn] applies function [f] to each of the parameters
1493 of function [fn] in order. Tail recursive. *)
1494 val iter_params : (llvalue -> unit) -> llvalue -> unit
1496 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1497 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1498 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1500 (** [param_end f] returns the last position in the parameter list of
1501 the function [f]. [param_end] and [param_pred] can be used to iterate
1502 over the parameter list in reverse.
1503 See the method [llvm::Function::arg_end]. *)
1504 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1506 (** [param_pred gv] returns the function list position preceding [After gv].
1507 See the method [llvm::Function::arg_iterator::operator--]. *)
1508 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1510 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1511 of function [fn] in reverse order. Tail recursive. *)
1512 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1514 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1515 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1516 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1518 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1519 val add_param_attr : llvalue -> Attribute.t -> unit
1521 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1522 val remove_param_attr : llvalue -> Attribute.t -> unit
1524 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1525 val set_param_alignment : llvalue -> int -> unit
1528 (** {7 Operations on basic blocks} *)
1530 (** [basic_blocks fn] returns the basic blocks of the function [f].
1531 See the method [llvm::Function::getBasicBlockList]. *)
1532 val basic_blocks : llvalue -> llbasicblock array
1534 (** [entry_block fn] returns the entry basic block of the function [f].
1535 See the method [llvm::Function::getEntryBlock]. *)
1536 val entry_block : llvalue -> llbasicblock
1538 (** [delete_block bb] deletes the basic block [bb].
1539 See the method [llvm::BasicBlock::eraseFromParent]. *)
1540 val delete_block : llbasicblock -> unit
1542 (** [remove_block bb] removes the basic block [bb] from its parent function.
1543 See the method [llvm::BasicBlock::removeFromParent]. *)
1544 val remove_block : llbasicblock -> unit
1546 (** [move_block_before pos bb] moves the basic block [bb] before [pos].
1547 See the method [llvm::BasicBlock::moveBefore]. *)
1548 val move_block_before : llbasicblock -> llbasicblock -> unit
1550 (** [move_block_after pos bb] moves the basic block [bb] after [pos].
1551 See the method [llvm::BasicBlock::moveAfter]. *)
1552 val move_block_after : llbasicblock -> llbasicblock -> unit
1554 (** [append_block c name f] creates a new basic block named [name] at the end of
1555 function [f] in the context [c].
1556 See the constructor of [llvm::BasicBlock]. *)
1557 val append_block : llcontext -> string -> llvalue -> llbasicblock
1559 (** [insert_block c name bb] creates a new basic block named [name] before the
1560 basic block [bb] in the context [c].
1561 See the constructor of [llvm::BasicBlock]. *)
1562 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1564 (** [block_parent bb] returns the parent function that owns the basic block.
1565 See the method [llvm::BasicBlock::getParent]. *)
1566 val block_parent : llbasicblock -> llvalue
1568 (** [block_begin f] returns the first position in the basic block list of the
1569 function [f]. [block_begin] and [block_succ] can be used to iterate over
1570 the basic block list in order.
1571 See the method [llvm::Function::begin]. *)
1572 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1574 (** [block_succ bb] returns the basic block list position succeeding
1576 See the method [llvm::Function::iterator::operator++]. *)
1577 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1579 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1580 of function [fn] in order. Tail recursive. *)
1581 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1583 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1584 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1585 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1587 (** [block_end f] returns the last position in the basic block list of
1588 the function [f]. [block_end] and [block_pred] can be used to iterate
1589 over the basic block list in reverse.
1590 See the method [llvm::Function::end]. *)
1591 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1593 (** [block_pred bb] returns the basic block list position preceding [After bb].
1594 See the method [llvm::Function::iterator::operator--]. *)
1595 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1597 (** [block_terminator bb] returns the terminator of the basic block [bb]. *)
1598 val block_terminator : llbasicblock -> llvalue option
1600 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1601 of function [fn] in reverse order. Tail recursive. *)
1602 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1604 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1605 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1606 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1608 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1609 val value_of_block : llbasicblock -> llvalue
1611 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1613 Similar to [llvm::isa<BasicBlock>]. *)
1614 val value_is_block : llvalue -> bool
1616 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1617 val block_of_value : llvalue -> llbasicblock
1620 (** {7 Operations on instructions} *)
1622 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1623 See the method [llvm::Instruction::getParent]. *)
1624 val instr_parent : llvalue -> llbasicblock
1626 (** [delete_instruction i] deletes the instruction [i].
1627 * See the method [llvm::Instruction::eraseFromParent]. *)
1628 val delete_instruction : llvalue -> unit
1630 (** [instr_begin bb] returns the first position in the instruction list of the
1631 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1632 the instruction list in order.
1633 See the method [llvm::BasicBlock::begin]. *)
1634 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1636 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1637 See the method [llvm::BasicBlock::iterator::operator++]. *)
1638 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1640 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1641 block [bb] in order. Tail recursive. *)
1642 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1644 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1645 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1646 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1648 (** [instr_end bb] returns the last position in the instruction list of the
1649 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1650 the instruction list in reverse.
1651 See the method [llvm::BasicBlock::end]. *)
1652 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1654 (** [instr_pred i] returns the instruction list position preceding [After i].
1655 See the method [llvm::BasicBlock::iterator::operator--]. *)
1656 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1658 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1659 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1660 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1662 (** [inst_opcode i] returns the [Opcode.t] corresponding to instruction [i],
1663 or [Opcode.Invalid] if [i] is not an instruction. *)
1664 val instr_opcode : llvalue -> Opcode.t
1666 (** [icmp_predicate i] returns the [Icmp.t] corresponding to an [icmp]
1668 val icmp_predicate : llvalue -> Icmp.t option
1671 (** {7 Operations on call sites} *)
1673 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1674 instruction [ci], which may be one of the values from the module
1675 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1676 [llvm::InvokeInst::getCallingConv]. *)
1677 val instruction_call_conv: llvalue -> int
1679 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1680 or invoke instruction [ci] to the integer [cc], which can be one of the
1681 values from the module {!CallConv}.
1682 See the method [llvm::CallInst::setCallingConv]
1683 and [llvm::InvokeInst::setCallingConv]. *)
1684 val set_instruction_call_conv: int -> llvalue -> unit
1686 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1687 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1689 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1691 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1692 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1694 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1697 (** {7 Operations on call instructions (only)} *)
1699 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1700 eligible for tail call optimization, [false] otherwise.
1701 See the method [llvm::CallInst::isTailCall]. *)
1702 val is_tail_call : llvalue -> bool
1704 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1705 call optimization if [tc] is [true], clears otherwise.
1706 See the method [llvm::CallInst::setTailCall]. *)
1707 val set_tail_call : bool -> llvalue -> unit
1710 (** {7 Operations on load/store instructions (only)} *)
1712 (** [is_volatile i] is [true] if the load or store instruction [i] is marked
1714 See the methods [llvm::LoadInst::isVolatile] and
1715 [llvm::StoreInst::isVolatile]. *)
1716 val is_volatile : llvalue -> bool
1718 (** [set_volatile v i] marks the load or store instruction [i] as volatile
1719 if [v] is [true], unmarks otherwise.
1720 See the methods [llvm::LoadInst::setVolatile] and
1721 [llvm::StoreInst::setVolatile]. *)
1722 val set_volatile : bool -> llvalue -> unit
1725 (** {7 Operations on phi nodes} *)
1727 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1728 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1729 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1731 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1732 See the method [llvm::PHINode::getIncomingValue]. *)
1733 val incoming : llvalue -> (llvalue * llbasicblock) list
1737 (** {6 Instruction builders} *)
1739 (** [builder context] creates an instruction builder with no position in
1740 the context [context]. It is invalid to use this builder until its position
1741 is set with {!position_before} or {!position_at_end}. See the constructor
1742 for [llvm::LLVMBuilder]. *)
1743 val builder : llcontext -> llbuilder
1745 (** [builder_at ip] creates an instruction builder positioned at [ip].
1746 See the constructor for [llvm::LLVMBuilder]. *)
1747 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1749 (** [builder_before ins] creates an instruction builder positioned before the
1750 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1751 val builder_before : llcontext -> llvalue -> llbuilder
1753 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1754 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1755 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1757 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1759 See the constructor for [llvm::LLVMBuilder]. *)
1760 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1762 (** [position_before ins b] moves the instruction builder [b] to before the
1763 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1764 val position_before : llvalue -> llbuilder -> unit
1766 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1767 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1768 val position_at_end : llbasicblock -> llbuilder -> unit
1770 (** [insertion_block b] returns the basic block that the builder [b] is
1771 positioned to insert into. Raises [Not_Found] if the instruction builder is
1773 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1774 val insertion_block : llbuilder -> llbasicblock
1776 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1777 position specified by the instruction builder [b].
1778 See the method [llvm::LLVMBuilder::Insert]. *)
1779 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1784 (** [set_current_debug_location b md] sets the current debug location [md] in
1786 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1787 val set_current_debug_location : llbuilder -> llvalue -> unit
1789 (** [clear_current_debug_location b] clears the current debug location in the
1791 val clear_current_debug_location : llbuilder -> unit
1793 (** [current_debug_location b] returns the current debug location, or None
1794 if none is currently set.
1795 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1796 val current_debug_location : llbuilder -> llvalue option
1798 (** [set_inst_debug_location b i] sets the current debug location of the builder
1799 [b] to the instruction [i].
1800 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1801 val set_inst_debug_location : llbuilder -> llvalue -> unit
1804 (** {7 Terminators} *)
1806 (** [build_ret_void b] creates a
1808 instruction at the position specified by the instruction builder [b].
1809 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1810 val build_ret_void : llbuilder -> llvalue
1812 (** [build_ret v b] creates a
1814 instruction at the position specified by the instruction builder [b].
1815 See the method [llvm::LLVMBuilder::CreateRet]. *)
1816 val build_ret : llvalue -> llbuilder -> llvalue
1818 (** [build_aggregate_ret vs b] creates a
1819 [ret {...} { %v1, %v2, ... } ]
1820 instruction at the position specified by the instruction builder [b].
1821 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1822 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1824 (** [build_br bb b] creates a
1826 instruction at the position specified by the instruction builder [b].
1827 See the method [llvm::LLVMBuilder::CreateBr]. *)
1828 val build_br : llbasicblock -> llbuilder -> llvalue
1830 (** [build_cond_br cond tbb fbb b] creates a
1831 [br %cond, %tbb, %fbb]
1832 instruction at the position specified by the instruction builder [b].
1833 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1834 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1837 (** [build_switch case elsebb count b] creates an empty
1838 [switch %case, %elsebb]
1839 instruction at the position specified by the instruction builder [b] with
1840 space reserved for [count] cases.
1841 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1842 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1844 (** [build_malloc ty name b] creates an [malloc]
1845 instruction at the position specified by the instruction builder [b].
1846 See the method [llvm::CallInst::CreateMalloc]. *)
1847 val build_malloc : lltype -> string -> llbuilder -> llvalue
1849 (** [build_array_malloc ty val name b] creates an [array malloc]
1850 instruction at the position specified by the instruction builder [b].
1851 See the method [llvm::CallInst::CreateArrayMalloc]. *)
1852 val build_array_malloc : lltype -> llvalue -> string -> llbuilder -> llvalue
1854 (** [build_free p b] creates a [free]
1855 instruction at the position specified by the instruction builder [b].
1856 See the method [llvm::LLVMBuilder::CreateFree]. *)
1857 val build_free : llvalue -> llbuilder -> llvalue
1859 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1860 when its input matches the constant [onval].
1861 See the method [llvm::SwitchInst::addCase]. **)
1862 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1864 (** [switch_default_dest sw] returns the default destination of the [switch]
1866 See the method [llvm:;SwitchInst::getDefaultDest]. **)
1867 val switch_default_dest : llvalue -> llbasicblock
1869 (** [build_indirect_br addr count b] creates a
1871 instruction at the position specified by the instruction builder [b] with
1872 space reserved for [count] destinations.
1873 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1874 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1876 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1877 location for the indirectbr instruction [br].
1878 See the method [llvm::IndirectBrInst::addDestination]. **)
1879 val add_destination : llvalue -> llbasicblock -> unit
1881 (** [build_invoke fn args tobb unwindbb name b] creates an
1882 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1883 instruction at the position specified by the instruction builder [b].
1884 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1885 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1886 llbasicblock -> string -> llbuilder -> llvalue
1888 (** [build_landingpad ty persfn numclauses name b] creates an
1890 instruction at the position specified by the instruction builder [b].
1891 See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
1892 val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
1895 (** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
1896 See the method [llvm::LandingPadInst::setCleanup]. *)
1897 val set_cleanup : llvalue -> bool -> unit
1899 (** [add_clause lp clause] adds the clause to the [landingpad]instruction.
1900 See the method [llvm::LandingPadInst::addClause]. *)
1901 val add_clause : llvalue -> llvalue -> unit
1903 (** [build_resume exn b] builds a [resume exn] instruction
1904 at the position specified by the instruction builder [b].
1905 See the method [llvm::LLVMBuilder::CreateResume] *)
1906 val build_resume : llvalue -> llbuilder -> llvalue
1908 (** [build_unreachable b] creates an
1910 instruction at the position specified by the instruction builder [b].
1911 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1912 val build_unreachable : llbuilder -> llvalue
1915 (** {7 Arithmetic} *)
1917 (** [build_add x y name b] creates a
1918 [%name = add %x, %y]
1919 instruction at the position specified by the instruction builder [b].
1920 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1921 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1923 (** [build_nsw_add x y name b] creates a
1924 [%name = nsw add %x, %y]
1925 instruction at the position specified by the instruction builder [b].
1926 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1927 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1929 (** [build_nuw_add x y name b] creates a
1930 [%name = nuw add %x, %y]
1931 instruction at the position specified by the instruction builder [b].
1932 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1933 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1935 (** [build_fadd x y name b] creates a
1936 [%name = fadd %x, %y]
1937 instruction at the position specified by the instruction builder [b].
1938 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1939 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1941 (** [build_sub x y name b] creates a
1942 [%name = sub %x, %y]
1943 instruction at the position specified by the instruction builder [b].
1944 See the method [llvm::LLVMBuilder::CreateSub]. *)
1945 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1947 (** [build_nsw_sub x y name b] creates a
1948 [%name = nsw sub %x, %y]
1949 instruction at the position specified by the instruction builder [b].
1950 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1951 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1953 (** [build_nuw_sub x y name b] creates a
1954 [%name = nuw sub %x, %y]
1955 instruction at the position specified by the instruction builder [b].
1956 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1957 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1959 (** [build_fsub x y name b] creates a
1960 [%name = fsub %x, %y]
1961 instruction at the position specified by the instruction builder [b].
1962 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1963 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1965 (** [build_mul x y name b] creates a
1966 [%name = mul %x, %y]
1967 instruction at the position specified by the instruction builder [b].
1968 See the method [llvm::LLVMBuilder::CreateMul]. *)
1969 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1971 (** [build_nsw_mul x y name b] creates a
1972 [%name = nsw mul %x, %y]
1973 instruction at the position specified by the instruction builder [b].
1974 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1975 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1977 (** [build_nuw_mul x y name b] creates a
1978 [%name = nuw mul %x, %y]
1979 instruction at the position specified by the instruction builder [b].
1980 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1981 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1983 (** [build_fmul x y name b] creates a
1984 [%name = fmul %x, %y]
1985 instruction at the position specified by the instruction builder [b].
1986 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1987 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1989 (** [build_udiv x y name b] creates a
1990 [%name = udiv %x, %y]
1991 instruction at the position specified by the instruction builder [b].
1992 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1993 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1995 (** [build_sdiv x y name b] creates a
1996 [%name = sdiv %x, %y]
1997 instruction at the position specified by the instruction builder [b].
1998 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1999 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2001 (** [build_exact_sdiv x y name b] creates a
2002 [%name = exact sdiv %x, %y]
2003 instruction at the position specified by the instruction builder [b].
2004 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
2005 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2007 (** [build_fdiv x y name b] creates a
2008 [%name = fdiv %x, %y]
2009 instruction at the position specified by the instruction builder [b].
2010 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
2011 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2013 (** [build_urem x y name b] creates a
2014 [%name = urem %x, %y]
2015 instruction at the position specified by the instruction builder [b].
2016 See the method [llvm::LLVMBuilder::CreateURem]. *)
2017 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2019 (** [build_SRem x y name b] creates a
2020 [%name = srem %x, %y]
2021 instruction at the position specified by the instruction builder [b].
2022 See the method [llvm::LLVMBuilder::CreateSRem]. *)
2023 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2025 (** [build_frem x y name b] creates a
2026 [%name = frem %x, %y]
2027 instruction at the position specified by the instruction builder [b].
2028 See the method [llvm::LLVMBuilder::CreateFRem]. *)
2029 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2031 (** [build_shl x y name b] creates a
2032 [%name = shl %x, %y]
2033 instruction at the position specified by the instruction builder [b].
2034 See the method [llvm::LLVMBuilder::CreateShl]. *)
2035 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
2037 (** [build_lshr x y name b] creates a
2038 [%name = lshr %x, %y]
2039 instruction at the position specified by the instruction builder [b].
2040 See the method [llvm::LLVMBuilder::CreateLShr]. *)
2041 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
2043 (** [build_ashr x y name b] creates a
2044 [%name = ashr %x, %y]
2045 instruction at the position specified by the instruction builder [b].
2046 See the method [llvm::LLVMBuilder::CreateAShr]. *)
2047 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
2049 (** [build_and x y name b] creates a
2050 [%name = and %x, %y]
2051 instruction at the position specified by the instruction builder [b].
2052 See the method [llvm::LLVMBuilder::CreateAnd]. *)
2053 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
2055 (** [build_or x y name b] creates a
2057 instruction at the position specified by the instruction builder [b].
2058 See the method [llvm::LLVMBuilder::CreateOr]. *)
2059 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
2061 (** [build_xor x y name b] creates a
2062 [%name = xor %x, %y]
2063 instruction at the position specified by the instruction builder [b].
2064 See the method [llvm::LLVMBuilder::CreateXor]. *)
2065 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
2067 (** [build_neg x name b] creates a
2069 instruction at the position specified by the instruction builder [b].
2070 [-0.0] is used for floating point types to compute the correct sign.
2071 See the method [llvm::LLVMBuilder::CreateNeg]. *)
2072 val build_neg : llvalue -> string -> llbuilder -> llvalue
2074 (** [build_nsw_neg x name b] creates a
2075 [%name = nsw sub 0, %x]
2076 instruction at the position specified by the instruction builder [b].
2077 [-0.0] is used for floating point types to compute the correct sign.
2078 See the method [llvm::LLVMBuilder::CreateNeg]. *)
2079 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
2081 (** [build_nuw_neg x name b] creates a
2082 [%name = nuw sub 0, %x]
2083 instruction at the position specified by the instruction builder [b].
2084 [-0.0] is used for floating point types to compute the correct sign.
2085 See the method [llvm::LLVMBuilder::CreateNeg]. *)
2086 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
2088 (** [build_fneg x name b] creates a
2089 [%name = fsub 0, %x]
2090 instruction at the position specified by the instruction builder [b].
2091 [-0.0] is used for floating point types to compute the correct sign.
2092 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
2093 val build_fneg : llvalue -> string -> llbuilder -> llvalue
2095 (** [build_xor x name b] creates a
2096 [%name = xor %x, -1]
2097 instruction at the position specified by the instruction builder [b].
2098 [-1] is the correct "all ones" value for the type of [x].
2099 See the method [llvm::LLVMBuilder::CreateXor]. *)
2100 val build_not : llvalue -> string -> llbuilder -> llvalue
2105 (** [build_alloca ty name b] creates a
2106 [%name = alloca %ty]
2107 instruction at the position specified by the instruction builder [b].
2108 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2109 val build_alloca : lltype -> string -> llbuilder -> llvalue
2111 (** [build_array_alloca ty n name b] creates a
2112 [%name = alloca %ty, %n]
2113 instruction at the position specified by the instruction builder [b].
2114 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2115 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
2118 (** [build_load v name b] creates a
2120 instruction at the position specified by the instruction builder [b].
2121 See the method [llvm::LLVMBuilder::CreateLoad]. *)
2122 val build_load : llvalue -> string -> llbuilder -> llvalue
2124 (** [build_store v p b] creates a
2126 instruction at the position specified by the instruction builder [b].
2127 See the method [llvm::LLVMBuilder::CreateStore]. *)
2128 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
2130 (** [build_atomicrmw op ptr val o st b] creates an [atomicrmw] instruction with
2131 operation [op] performed on pointer [ptr] and value [val] with ordering [o]
2132 and singlethread flag set to [st] at the position specified by
2133 the instruction builder [b].
2134 See the method [llvm::IRBuilder::CreateAtomicRMW]. *)
2135 val build_atomicrmw : AtomicRMWBinOp.t -> llvalue -> llvalue ->
2136 AtomicOrdering.t -> bool -> string -> llbuilder -> llvalue
2138 (** [build_gep p indices name b] creates a
2139 [%name = getelementptr %p, indices...]
2140 instruction at the position specified by the instruction builder [b].
2141 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
2142 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2144 (** [build_in_bounds_gep p indices name b] creates a
2145 [%name = gelementptr inbounds %p, indices...]
2146 instruction at the position specified by the instruction builder [b].
2147 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
2148 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
2151 (** [build_struct_gep p idx name b] creates a
2152 [%name = getelementptr %p, 0, idx]
2153 instruction at the position specified by the instruction builder [b].
2154 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
2155 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
2158 (** [build_global_string str name b] creates a series of instructions that adds
2159 a global string at the position specified by the instruction builder [b].
2160 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
2161 val build_global_string : string -> string -> llbuilder -> llvalue
2163 (** [build_global_stringptr str name b] creates a series of instructions that
2164 adds a global string pointer at the position specified by the instruction
2166 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
2167 val build_global_stringptr : string -> string -> llbuilder -> llvalue
2172 (** [build_trunc v ty name b] creates a
2173 [%name = trunc %p to %ty]
2174 instruction at the position specified by the instruction builder [b].
2175 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
2176 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2178 (** [build_zext v ty name b] creates a
2179 [%name = zext %p to %ty]
2180 instruction at the position specified by the instruction builder [b].
2181 See the method [llvm::LLVMBuilder::CreateZExt]. *)
2182 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
2184 (** [build_sext v ty name b] creates a
2185 [%name = sext %p to %ty]
2186 instruction at the position specified by the instruction builder [b].
2187 See the method [llvm::LLVMBuilder::CreateSExt]. *)
2188 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
2190 (** [build_fptoui v ty name b] creates a
2191 [%name = fptoui %p to %ty]
2192 instruction at the position specified by the instruction builder [b].
2193 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
2194 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
2196 (** [build_fptosi v ty name b] creates a
2197 [%name = fptosi %p to %ty]
2198 instruction at the position specified by the instruction builder [b].
2199 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
2200 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
2202 (** [build_uitofp v ty name b] creates a
2203 [%name = uitofp %p to %ty]
2204 instruction at the position specified by the instruction builder [b].
2205 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
2206 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2208 (** [build_sitofp v ty name b] creates a
2209 [%name = sitofp %p to %ty]
2210 instruction at the position specified by the instruction builder [b].
2211 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
2212 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2214 (** [build_fptrunc v ty name b] creates a
2215 [%name = fptrunc %p to %ty]
2216 instruction at the position specified by the instruction builder [b].
2217 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
2218 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2220 (** [build_fpext v ty name b] creates a
2221 [%name = fpext %p to %ty]
2222 instruction at the position specified by the instruction builder [b].
2223 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
2224 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
2226 (** [build_ptrtoint v ty name b] creates a
2227 [%name = prtotint %p to %ty]
2228 instruction at the position specified by the instruction builder [b].
2229 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2230 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2232 (** [build_inttoptr v ty name b] creates a
2233 [%name = inttoptr %p to %ty]
2234 instruction at the position specified by the instruction builder [b].
2235 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2236 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2238 (** [build_bitcast v ty name b] creates a
2239 [%name = bitcast %p to %ty]
2240 instruction at the position specified by the instruction builder [b].
2241 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2242 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2244 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2245 instruction at the position specified by the instruction builder [b].
2246 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2247 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2250 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2251 instruction at the position specified by the instruction builder [b].
2252 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2253 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2256 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2257 instruction at the position specified by the instruction builder [b].
2258 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2259 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2262 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2263 instruction at the position specified by the instruction builder [b].
2264 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2265 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2267 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2268 instruction at the position specified by the instruction builder [b].
2269 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2270 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2272 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2273 instruction at the position specified by the instruction builder [b].
2274 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2275 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2278 (** {7 Comparisons} *)
2280 (** [build_icmp pred x y name b] creates a
2281 [%name = icmp %pred %x, %y]
2282 instruction at the position specified by the instruction builder [b].
2283 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2284 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2285 llbuilder -> llvalue
2287 (** [build_fcmp pred x y name b] creates a
2288 [%name = fcmp %pred %x, %y]
2289 instruction at the position specified by the instruction builder [b].
2290 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2291 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2292 llbuilder -> llvalue
2295 (** {7 Miscellaneous instructions} *)
2297 (** [build_phi incoming name b] creates a
2298 [%name = phi %incoming]
2299 instruction at the position specified by the instruction builder [b].
2300 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2301 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2302 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2305 (** [build_call fn args name b] creates a
2306 [%name = call %fn(args...)]
2307 instruction at the position specified by the instruction builder [b].
2308 See the method [llvm::LLVMBuilder::CreateCall]. *)
2309 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2311 (** [build_select cond thenv elsev name b] creates a
2312 [%name = select %cond, %thenv, %elsev]
2313 instruction at the position specified by the instruction builder [b].
2314 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2315 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2318 (** [build_va_arg valist argty name b] creates a
2319 [%name = va_arg %valist, %argty]
2320 instruction at the position specified by the instruction builder [b].
2321 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2322 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2324 (** [build_extractelement vec i name b] creates a
2325 [%name = extractelement %vec, %i]
2326 instruction at the position specified by the instruction builder [b].
2327 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2328 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2331 (** [build_insertelement vec elt i name b] creates a
2332 [%name = insertelement %vec, %elt, %i]
2333 instruction at the position specified by the instruction builder [b].
2334 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2335 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2336 llbuilder -> llvalue
2338 (** [build_shufflevector veca vecb mask name b] creates a
2339 [%name = shufflevector %veca, %vecb, %mask]
2340 instruction at the position specified by the instruction builder [b].
2341 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2342 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2343 llbuilder -> llvalue
2345 (** [build_insertvalue agg idx name b] creates a
2346 [%name = extractvalue %agg, %idx]
2347 instruction at the position specified by the instruction builder [b].
2348 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2349 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2352 (** [build_insertvalue agg val idx name b] creates a
2353 [%name = insertvalue %agg, %val, %idx]
2354 instruction at the position specified by the instruction builder [b].
2355 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2356 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2359 (** [build_is_null val name b] creates a
2360 [%name = icmp eq %val, null]
2361 instruction at the position specified by the instruction builder [b].
2362 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2363 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2365 (** [build_is_not_null val name b] creates a
2366 [%name = icmp ne %val, null]
2367 instruction at the position specified by the instruction builder [b].
2368 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2369 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2371 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2372 the difference between two pointer values at the position specified by the
2373 instruction builder [b].
2374 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2375 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2378 (** {6 Memory buffers} *)
2380 module MemoryBuffer : sig
2381 (** [of_file p] is the memory buffer containing the contents of the file at
2382 path [p]. If the file could not be read, then [IoError msg] is
2384 val of_file : string -> llmemorybuffer
2386 (** [of_stdin ()] is the memory buffer containing the contents of standard input.
2387 If standard input is empty, then [IoError msg] is raised. *)
2388 val of_stdin : unit -> llmemorybuffer
2390 (** [of_string ~name s] is the memory buffer containing the contents of string [s].
2391 The name of memory buffer is set to [name] if it is provided. *)
2392 val of_string : ?name:string -> string -> llmemorybuffer
2394 (** [as_string mb] is the string containing the contents of memory buffer [mb]. *)
2395 val as_string : llmemorybuffer -> string
2397 (** Disposes of a memory buffer. *)
2398 val dispose : llmemorybuffer -> unit
2402 (** {6 Pass Managers} *)
2404 module PassManager : sig
2407 type any = [ `Module | `Function ]
2409 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2410 type of pipeline is suitable for link-time optimization and whole-module
2412 See the constructor of [llvm::PassManager]. *)
2413 val create : unit -> [ `Module ] t
2415 (** [PassManager.create_function m] constructs a new function-by-function
2416 pass pipeline over the module [m]. It does not take ownership of [m].
2417 This type of pipeline is suitable for code generation and JIT compilation
2419 See the constructor of [llvm::FunctionPassManager]. *)
2420 val create_function : llmodule -> [ `Function ] t
2422 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2423 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2424 any of the passes modified the module, [false] otherwise.
2425 See the [llvm::PassManager::run] method. *)
2426 val run_module : llmodule -> [ `Module ] t -> bool
2428 (** [initialize fpm] initializes all of the function passes scheduled in the
2429 function pass manager [fpm]. Returns [true] if any of the passes modified
2430 the module, [false] otherwise.
2431 See the [llvm::FunctionPassManager::doInitialization] method. *)
2432 val initialize : [ `Function ] t -> bool
2434 (** [run_function f fpm] executes all of the function passes scheduled in the
2435 function pass manager [fpm] over the function [f]. Returns [true] if any
2436 of the passes modified [f], [false] otherwise.
2437 See the [llvm::FunctionPassManager::run] method. *)
2438 val run_function : llvalue -> [ `Function ] t -> bool
2440 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2441 function pass manager [fpm]. Returns [true] if any of the passes
2442 modified the module, [false] otherwise.
2443 See the [llvm::FunctionPassManager::doFinalization] method. *)
2444 val finalize : [ `Function ] t -> bool
2446 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2448 See the destructor of [llvm::BasePassManager]. *)
2449 val dispose : [< any ] t -> unit