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
329 | ConstantPointerNull
336 | Instruction of Opcode.t
342 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
343 of [a]. [llpos] is used to specify positions in and for forward iteration
344 through the various value lists maintained by the LLVM IR. *)
345 type ('a, 'b) llpos =
349 (** [After b] and [At_start a] specify positions from the end of the ['b] list
350 of [a]. [llrev_pos] is used for reverse iteration through the various value
351 lists maintained by the LLVM IR. *)
352 type ('a, 'b) llrev_pos =
357 (** {6 Exceptions} *)
359 exception IoError of string
364 (** [create_context ()] creates a context for storing the "global" state in
365 LLVM. See the constructor [llvm::LLVMContext]. *)
366 val create_context : unit -> llcontext
368 (** [destroy_context ()] destroys a context. See the destructor
369 [llvm::LLVMContext::~LLVMContext]. *)
370 val dispose_context : llcontext -> unit
372 (** See the function [llvm::getGlobalContext]. *)
373 val global_context : unit -> llcontext
375 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
376 name [name] in the context [context]. See the function
377 [llvm::LLVMContext::getMDKindID]. *)
378 val mdkind_id : llcontext -> string -> int
383 (** [create_module context id] creates a module with the supplied module ID in
384 the context [context]. Modules are not garbage collected; it is mandatory
385 to call {!dispose_module} to free memory. See the constructor
386 [llvm::Module::Module]. *)
387 val create_module : llcontext -> string -> llmodule
389 (** [dispose_module m] destroys a module [m] and all of the IR objects it
390 contained. All references to subordinate objects are invalidated;
391 referencing them will invoke undefined behavior. See the destructor
392 [llvm::Module::~Module]. *)
393 val dispose_module : llmodule -> unit
395 (** [target_triple m] is the target specifier for the module [m], something like
396 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
397 val target_triple: llmodule -> string
399 (** [target_triple triple m] changes the target specifier for the module [m] to
400 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
401 val set_target_triple: string -> llmodule -> unit
403 (** [data_layout m] is the data layout specifier for the module [m], something
404 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
405 method [llvm::Module::getDataLayout]. *)
406 val data_layout: llmodule -> string
408 (** [set_data_layout s m] changes the data layout specifier for the module [m]
409 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
410 val set_data_layout: string -> llmodule -> unit
412 (** [dump_module m] prints the .ll representation of the module [m] to standard
413 error. See the method [llvm::Module::dump]. *)
414 val dump_module : llmodule -> unit
416 (** [print_module f m] prints the .ll representation of the module [m]
417 to file [f]. See the method [llvm::Module::print]. *)
418 val print_module : string -> llmodule -> unit
420 (** [string_of_llmodule m] returns the .ll representation of the module [m]
421 as a string. See the method [llvm::Module::print]. *)
422 val string_of_llmodule : llmodule -> string
424 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
425 the method [llvm::Module::setModuleInlineAsm]. *)
426 val set_module_inline_asm : llmodule -> string -> unit
428 (** [module_context m] returns the context of the specified module.
429 See the method [llvm::Module::getContext] *)
430 val module_context : llmodule -> llcontext
435 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
436 See the method [llvm::Type::getTypeID]. *)
437 val classify_type : lltype -> TypeKind.t
439 (** [type_is_sized ty] returns whether the type has a size or not.
440 If it doesn't then it is not safe to call the [DataLayout::] methods on it.
442 val type_is_sized : lltype -> bool
444 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
445 See the method [llvm::Type::getContext]. *)
446 val type_context : lltype -> llcontext
448 (** [dump_type ty] prints the .ll representation of the type [ty] to standard
449 error. See the method [llvm::Type::dump]. *)
450 val dump_type : lltype -> unit
452 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
453 val string_of_lltype : lltype -> string
456 (** {7 Operations on integer types} *)
458 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
459 [llvm::Type::Int1Ty]. *)
460 val i1_type : llcontext -> lltype
462 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
463 [llvm::Type::Int8Ty]. *)
464 val i8_type : llcontext -> lltype
466 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
467 [llvm::Type::Int16Ty]. *)
468 val i16_type : llcontext -> lltype
470 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
471 [llvm::Type::Int32Ty]. *)
472 val i32_type : llcontext -> lltype
474 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
475 [llvm::Type::Int64Ty]. *)
476 val i64_type : llcontext -> lltype
478 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
479 [c]. See the method [llvm::IntegerType::get]. *)
480 val integer_type : llcontext -> int -> lltype
482 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
483 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
484 val integer_bitwidth : lltype -> int
487 (** {7 Operations on real types} *)
489 (** [float_type c] returns the IEEE 32-bit floating point type in the context
490 [c]. See [llvm::Type::FloatTy]. *)
491 val float_type : llcontext -> lltype
493 (** [double_type c] returns the IEEE 64-bit floating point type in the context
494 [c]. See [llvm::Type::DoubleTy]. *)
495 val double_type : llcontext -> lltype
497 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
498 [c]. See [llvm::Type::X86_FP80Ty]. *)
499 val x86fp80_type : llcontext -> lltype
501 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
502 [c]. See [llvm::Type::FP128Ty]. *)
503 val fp128_type : llcontext -> lltype
505 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
506 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
507 val ppc_fp128_type : llcontext -> lltype
510 (** {7 Operations on function types} *)
512 (** [function_type ret_ty param_tys] returns the function type returning
513 [ret_ty] and taking [param_tys] as parameters.
514 See the method [llvm::FunctionType::get]. *)
515 val function_type : lltype -> lltype array -> lltype
517 (** [var_arg_function_type ret_ty param_tys] is just like
518 [function_type ret_ty param_tys] except that it returns the function type
519 which also takes a variable number of arguments.
520 See the method [llvm::FunctionType::get]. *)
521 val var_arg_function_type : lltype -> lltype array -> lltype
523 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
524 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
525 val is_var_arg : lltype -> bool
527 (** [return_type fty] gets the return type of the function type [fty].
528 See the method [llvm::FunctionType::getReturnType]. *)
529 val return_type : lltype -> lltype
531 (** [param_types fty] gets the parameter types of the function type [fty].
532 See the method [llvm::FunctionType::getParamType]. *)
533 val param_types : lltype -> lltype array
536 (** {7 Operations on struct types} *)
538 (** [struct_type context tys] returns the structure type in the context
539 [context] containing in the types in the array [tys]. See the method
540 [llvm::StructType::get]. *)
541 val struct_type : llcontext -> lltype array -> lltype
543 (** [packed_struct_type context ys] returns the packed structure type in the
544 context [context] containing in the types in the array [tys]. See the method
545 [llvm::StructType::get]. *)
546 val packed_struct_type : llcontext -> lltype array -> lltype
548 (** [struct_name ty] returns the name of the named structure type [ty],
549 or None if the structure type is not named *)
550 val struct_name : lltype -> string option
552 (** [named_struct_type context name] returns the named structure type [name]
553 in the context [context].
554 See the method [llvm::StructType::get]. *)
555 val named_struct_type : llcontext -> string -> lltype
557 (** [struct_set_body ty elts ispacked] sets the body of the named struct [ty]
558 to the [elts] elements.
559 See the moethd [llvm::StructType::setBody]. *)
560 val struct_set_body : lltype -> lltype array -> bool -> unit
562 (** [struct_element_types sty] returns the constituent types of the struct type
563 [sty]. See the method [llvm::StructType::getElementType]. *)
564 val struct_element_types : lltype -> lltype array
566 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
567 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
568 val is_packed : lltype -> bool
570 (** [is_opaque sty] returns [true] if the structure type [sty] is opaque.
571 [false] otherwise. See the method [llvm::StructType::isOpaque]. *)
572 val is_opaque : lltype -> bool
575 (** {7 Operations on pointer, vector, and array types} *)
577 (** [array_type ty n] returns the array type containing [n] elements of type
578 [ty]. See the method [llvm::ArrayType::get]. *)
579 val array_type : lltype -> int -> lltype
581 (** [pointer_type ty] returns the pointer type referencing objects of type
582 [ty] in the default address space (0).
583 See the method [llvm::PointerType::getUnqual]. *)
584 val pointer_type : lltype -> lltype
586 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
587 of type [ty] in address space [as].
588 See the method [llvm::PointerType::get]. *)
589 val qualified_pointer_type : lltype -> int -> lltype
591 (** [vector_type ty n] returns the array type containing [n] elements of the
592 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
593 val vector_type : lltype -> int -> lltype
595 (** [element_type ty] returns the element type of the pointer, vector, or array
596 type [ty]. See the method [llvm::SequentialType::get]. *)
597 val element_type : lltype -> lltype
599 (** [element_type aty] returns the element count of the array type [aty].
600 See the method [llvm::ArrayType::getNumElements]. *)
601 val array_length : lltype -> int
603 (** [address_space pty] returns the address space qualifier of the pointer type
604 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
605 val address_space : lltype -> int
607 (** [element_type ty] returns the element count of the vector type [ty].
608 See the method [llvm::VectorType::getNumElements]. *)
609 val vector_size : lltype -> int
612 (** {7 Operations on other types} *)
614 (** [void_type c] creates a type of a function which does not return any
615 value in the context [c]. See [llvm::Type::VoidTy]. *)
616 val void_type : llcontext -> lltype
618 (** [label_type c] creates a type of a basic block in the context [c]. See
619 [llvm::Type::LabelTy]. *)
620 val label_type : llcontext -> lltype
622 (** [x86_mmx_type c] returns the x86 64-bit MMX register type in the
623 context [c]. See [llvm::Type::X86_MMXTy]. *)
624 val x86_mmx_type : llcontext -> lltype
626 (** [type_by_name m name] returns the specified type from the current module
628 See the method [llvm::Module::getTypeByName] *)
629 val type_by_name : llmodule -> string -> lltype option
634 (** [type_of v] returns the type of the value [v].
635 See the method [llvm::Value::getType]. *)
636 val type_of : llvalue -> lltype
638 (** [classify_value v] returns the kind of the value [v]. *)
639 val classify_value : llvalue -> ValueKind.t
641 (** [value_name v] returns the name of the value [v]. For global values, this is
642 the symbol name. For instructions and basic blocks, it is the SSA register
643 name. It is meaningless for constants.
644 See the method [llvm::Value::getName]. *)
645 val value_name : llvalue -> string
647 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
648 [llvm::Value::setName]. *)
649 val set_value_name : string -> llvalue -> unit
651 (** [dump_value v] prints the .ll representation of the value [v] to standard
652 error. See the method [llvm::Value::dump]. *)
653 val dump_value : llvalue -> unit
655 (** [replace_all_uses_with old new] replaces all uses of the value [old]
656 with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
657 val replace_all_uses_with : llvalue -> llvalue -> unit
662 (** [use_begin v] returns the first position in the use list for the value [v].
663 [use_begin] and [use_succ] can e used to iterate over the use list in order.
664 See the method [llvm::Value::use_begin]. *)
665 val use_begin : llvalue -> lluse option
667 (** [use_succ u] returns the use list position succeeding [u].
668 See the method [llvm::use_value_iterator::operator++]. *)
669 val use_succ : lluse -> lluse option
671 (** [user u] returns the user of the use [u].
672 See the method [llvm::Use::getUser]. *)
673 val user : lluse -> llvalue
675 (** [used_value u] returns the usee of the use [u].
676 See the method [llvm::Use::getUsedValue]. *)
677 val used_value : lluse -> llvalue
679 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
680 in order. Tail recursive. *)
681 val iter_uses : (lluse -> unit) -> llvalue -> unit
683 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
684 [u1,...,uN] are the users of the value [v]. Tail recursive. *)
685 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
687 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
688 [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
689 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
694 (** [operand v i] returns the operand at index [i] for the value [v]. See the
695 method [llvm::User::getOperand]. *)
696 val operand : llvalue -> int -> llvalue
698 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
700 See the method [llvm::User::setOperand]. *)
701 val set_operand : llvalue -> int -> llvalue -> unit
703 (** [num_operands v] returns the number of operands for the value [v].
704 See the method [llvm::User::getNumOperands]. *)
705 val num_operands : llvalue -> int
708 (** {7 Operations on constants of (mostly) any type} *)
710 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
711 otherwise. Similar to [llvm::isa<Constant>]. *)
712 val is_constant : llvalue -> bool
714 (** [const_null ty] returns the constant null (zero) of the type [ty].
715 See the method [llvm::Constant::getNullValue]. *)
716 val const_null : lltype -> llvalue
718 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
719 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
720 val const_all_ones : (*int|vec*)lltype -> llvalue
722 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
723 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
724 val const_pointer_null : lltype -> llvalue
726 (** [undef ty] returns the undefined value of the type [ty].
727 See the method [llvm::UndefValue::get]. *)
728 val undef : lltype -> llvalue
730 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
731 See the method [llvm::Constant::isNullValue]. *)
732 val is_null : llvalue -> bool
734 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
735 otherwise. Similar to [llvm::isa<UndefValue>]. *)
736 val is_undef : llvalue -> bool
738 (** [constexpr_opcode v] returns an [Opcode.t] corresponding to constexpr
739 value [v], or [Opcode.Invalid] if [v] is not a constexpr. *)
740 val constexpr_opcode : llvalue -> Opcode.t
743 (** {7 Operations on instructions} *)
745 (** [has_metadata i] returns whether or not the instruction [i] has any
746 metadata attached to it. See the function
747 [llvm::Instruction::hasMetadata]. *)
748 val has_metadata : llvalue -> bool
750 (** [metadata i kind] optionally returns the metadata associated with the
751 kind [kind] in the instruction [i] See the function
752 [llvm::Instruction::getMetadata]. *)
753 val metadata : llvalue -> int -> llvalue option
755 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
756 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
757 val set_metadata : llvalue -> int -> llvalue -> unit
759 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
760 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
761 val clear_metadata : llvalue -> int -> unit
764 (** {7 Operations on metadata} *)
766 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
767 See the method [llvm::MDNode::get]. *)
768 val mdstring : llcontext -> string -> llvalue
770 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
772 See the method [llvm::MDNode::get]. *)
773 val mdnode : llcontext -> llvalue array -> llvalue
775 (** [get_mdstring v] returns the MDString.
776 See the method [llvm::MDString::getString] *)
777 val get_mdstring : llvalue -> string option
779 (** [get_named_metadata m name] returns all the MDNodes belonging to the named
781 See the method [llvm::NamedMDNode::getOperand]. *)
782 val get_named_metadata : llmodule -> string -> llvalue array
784 (** [add_named_metadata_operand m name v] adds [v] as the last operand of
785 metadata named [name] in module [m]. If the metadata does not exist,
787 See the methods [llvm::Module::getNamedMetadata()] and
788 [llvm::MDNode::addOperand()]. *)
789 val add_named_metadata_operand : llmodule -> string -> llvalue -> unit
792 (** {7 Operations on scalar constants} *)
794 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
795 See the method [llvm::ConstantInt::get]. *)
796 val const_int : lltype -> int -> llvalue
798 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
799 [i]. See the method [llvm::ConstantInt::get]. *)
800 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
802 (** [int64_of_const c] returns the int64 value of the [c] constant integer.
803 None is returned if this is not an integer constant, or bitwidth exceeds 64.
804 See the method [llvm::ConstantInt::getSExtValue].*)
805 val int64_of_const : llvalue -> Int64.t option
807 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
808 value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
809 val const_int_of_string : lltype -> string -> int -> llvalue
811 (** [const_float ty n] returns the floating point constant of type [ty] and
812 value [n]. See the method [llvm::ConstantFP::get]. *)
813 val const_float : lltype -> float -> llvalue
815 (** [const_float_of_string ty s] returns the floating point constant of type
816 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
817 val const_float_of_string : lltype -> string -> llvalue
820 (** {7 Operations on composite constants} *)
822 (** [const_string c s] returns the constant [i8] array with the values of the
823 characters in the string [s] in the context [c]. The array is not
824 null-terminated (but see {!const_stringz}). This value can in turn be used
825 as the initializer for a global variable. See the method
826 [llvm::ConstantArray::get]. *)
827 val const_string : llcontext -> string -> llvalue
829 (** [const_stringz c s] returns the constant [i8] array with the values of the
830 characters in the string [s] and a null terminator in the context [c]. This
831 value can in turn be used as the initializer for a global variable.
832 See the method [llvm::ConstantArray::get]. *)
833 val const_stringz : llcontext -> string -> llvalue
835 (** [const_array ty elts] returns the constant array of type
836 [array_type ty (Array.length elts)] and containing the values [elts].
837 This value can in turn be used as the initializer for a global variable.
838 See the method [llvm::ConstantArray::get]. *)
839 val const_array : lltype -> llvalue array -> llvalue
841 (** [const_struct context elts] returns the structured constant of type
842 [struct_type (Array.map type_of elts)] and containing the values [elts]
843 in the context [context]. This value can in turn be used as the initializer
844 for a global variable. See the method [llvm::ConstantStruct::getAnon]. *)
845 val const_struct : llcontext -> llvalue array -> llvalue
847 (** [const_named_struct namedty elts] returns the structured constant of type
848 [namedty] (which must be a named structure type) and containing the values [elts].
849 This value can in turn be used as the initializer
850 for a global variable. See the method [llvm::ConstantStruct::get]. *)
851 val const_named_struct : lltype -> llvalue array -> llvalue
853 (** [const_packed_struct context elts] returns the structured constant of
854 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
855 values [elts] in the context [context]. This value can in turn be used as
856 the initializer for a global variable. See the method
857 [llvm::ConstantStruct::get]. *)
858 val const_packed_struct : llcontext -> llvalue array -> llvalue
860 (** [const_vector elts] returns the vector constant of type
861 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
862 values [elts]. See the method [llvm::ConstantVector::get]. *)
863 val const_vector : llvalue array -> llvalue
866 (** {7 Constant expressions} *)
868 (** [align_of ty] returns the alignof constant for the type [ty]. This is
869 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
870 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
871 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
872 val align_of : lltype -> llvalue
874 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
875 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
876 (const_int i32_type 1)) i64_type], but considerably more readable.
877 See the method [llvm::ConstantExpr::getSizeOf]. *)
878 val size_of : lltype -> llvalue
880 (** [const_neg c] returns the arithmetic negation of the constant [c].
881 See the method [llvm::ConstantExpr::getNeg]. *)
882 val const_neg : llvalue -> llvalue
884 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
885 no signed wrapping. The result is undefined if the negation overflows.
886 See the method [llvm::ConstantExpr::getNSWNeg]. *)
887 val const_nsw_neg : llvalue -> llvalue
889 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
890 no unsigned wrapping. The result is undefined if the negation overflows.
891 See the method [llvm::ConstantExpr::getNUWNeg]. *)
892 val const_nuw_neg : llvalue -> llvalue
894 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
895 See the method [llvm::ConstantExpr::getFNeg]. *)
896 val const_fneg : llvalue -> llvalue
898 (** [const_not c] returns the bitwise inverse of the constant [c].
899 See the method [llvm::ConstantExpr::getNot]. *)
900 val const_not : llvalue -> llvalue
902 (** [const_add c1 c2] returns the constant sum of two constants.
903 See the method [llvm::ConstantExpr::getAdd]. *)
904 val const_add : llvalue -> llvalue -> llvalue
906 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
907 signed wrapping. The result is undefined if the sum overflows.
908 See the method [llvm::ConstantExpr::getNSWAdd]. *)
909 val const_nsw_add : llvalue -> llvalue -> llvalue
911 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
912 unsigned wrapping. The result is undefined if the sum overflows.
913 See the method [llvm::ConstantExpr::getNSWAdd]. *)
914 val const_nuw_add : llvalue -> llvalue -> llvalue
916 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
917 See the method [llvm::ConstantExpr::getFAdd]. *)
918 val const_fadd : llvalue -> llvalue -> llvalue
920 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
921 constants. See the method [llvm::ConstantExpr::getSub]. *)
922 val const_sub : llvalue -> llvalue -> llvalue
924 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
925 no signed wrapping. The result is undefined if the sum overflows.
926 See the method [llvm::ConstantExpr::getNSWSub]. *)
927 val const_nsw_sub : llvalue -> llvalue -> llvalue
929 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
930 no unsigned wrapping. The result is undefined if the sum overflows.
931 See the method [llvm::ConstantExpr::getNSWSub]. *)
932 val const_nuw_sub : llvalue -> llvalue -> llvalue
934 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
935 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
936 val const_fsub : llvalue -> llvalue -> llvalue
938 (** [const_mul c1 c2] returns the constant product of two constants.
939 See the method [llvm::ConstantExpr::getMul]. *)
940 val const_mul : llvalue -> llvalue -> llvalue
942 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
943 no signed wrapping. The result is undefined if the sum overflows.
944 See the method [llvm::ConstantExpr::getNSWMul]. *)
945 val const_nsw_mul : llvalue -> llvalue -> llvalue
947 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
948 no unsigned wrapping. The result is undefined if the sum overflows.
949 See the method [llvm::ConstantExpr::getNSWMul]. *)
950 val const_nuw_mul : llvalue -> llvalue -> llvalue
952 (** [const_fmul c1 c2] returns the constant product of two constants floats.
953 See the method [llvm::ConstantExpr::getFMul]. *)
954 val const_fmul : llvalue -> llvalue -> llvalue
956 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
958 See the method [llvm::ConstantExpr::getUDiv]. *)
959 val const_udiv : llvalue -> llvalue -> llvalue
961 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
963 See the method [llvm::ConstantExpr::getSDiv]. *)
964 val const_sdiv : llvalue -> llvalue -> llvalue
966 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
967 signed integer constants. The result is undefined if the result is rounded
968 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
969 val const_exact_sdiv : llvalue -> llvalue -> llvalue
971 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
973 See the method [llvm::ConstantExpr::getFDiv]. *)
974 val const_fdiv : llvalue -> llvalue -> llvalue
976 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
977 unsigned integer constants.
978 See the method [llvm::ConstantExpr::getURem]. *)
979 val const_urem : llvalue -> llvalue -> llvalue
981 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
982 signed integer constants.
983 See the method [llvm::ConstantExpr::getSRem]. *)
984 val const_srem : llvalue -> llvalue -> llvalue
986 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
987 signed floating point constants.
988 See the method [llvm::ConstantExpr::getFRem]. *)
989 val const_frem : llvalue -> llvalue -> llvalue
991 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
993 See the method [llvm::ConstantExpr::getAnd]. *)
994 val const_and : llvalue -> llvalue -> llvalue
996 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
998 See the method [llvm::ConstantExpr::getOr]. *)
999 val const_or : llvalue -> llvalue -> llvalue
1001 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
1003 See the method [llvm::ConstantExpr::getXor]. *)
1004 val const_xor : llvalue -> llvalue -> llvalue
1006 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
1007 constants, [c1 pred c2].
1008 See the method [llvm::ConstantExpr::getICmp]. *)
1009 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
1011 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
1012 point constants, [c1 pred c2].
1013 See the method [llvm::ConstantExpr::getFCmp]. *)
1014 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
1016 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
1017 constant integer [c2].
1018 See the method [llvm::ConstantExpr::getShl]. *)
1019 val const_shl : llvalue -> llvalue -> llvalue
1021 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
1022 constant integer [c2] with zero extension.
1023 See the method [llvm::ConstantExpr::getLShr]. *)
1024 val const_lshr : llvalue -> llvalue -> llvalue
1026 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
1027 constant integer [c2] with sign extension.
1028 See the method [llvm::ConstantExpr::getAShr]. *)
1029 val const_ashr : llvalue -> llvalue -> llvalue
1031 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
1032 constant integers indices from the array [indices].
1033 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
1034 val const_gep : llvalue -> llvalue array -> llvalue
1036 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
1037 with the constant integers indices from the array [indices].
1038 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
1039 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
1041 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
1042 to the smaller integer type [ty].
1043 See the method [llvm::ConstantExpr::getTrunc]. *)
1044 val const_trunc : llvalue -> lltype -> llvalue
1046 (** [const_sext c ty] returns the constant sign extension of integer constant
1047 [c] to the larger integer type [ty].
1048 See the method [llvm::ConstantExpr::getSExt]. *)
1049 val const_sext : llvalue -> lltype -> llvalue
1051 (** [const_zext c ty] returns the constant zero extension of integer constant
1052 [c] to the larger integer type [ty].
1053 See the method [llvm::ConstantExpr::getZExt]. *)
1054 val const_zext : llvalue -> lltype -> llvalue
1056 (** [const_fptrunc c ty] returns the constant truncation of floating point
1057 constant [c] to the smaller floating point type [ty].
1058 See the method [llvm::ConstantExpr::getFPTrunc]. *)
1059 val const_fptrunc : llvalue -> lltype -> llvalue
1061 (** [const_fpext c ty] returns the constant extension of floating point constant
1062 [c] to the larger floating point type [ty].
1063 See the method [llvm::ConstantExpr::getFPExt]. *)
1064 val const_fpext : llvalue -> lltype -> llvalue
1066 (** [const_uitofp c ty] returns the constant floating point conversion of
1067 unsigned integer constant [c] to the floating point type [ty].
1068 See the method [llvm::ConstantExpr::getUIToFP]. *)
1069 val const_uitofp : llvalue -> lltype -> llvalue
1071 (** [const_sitofp c ty] returns the constant floating point conversion of
1072 signed integer constant [c] to the floating point type [ty].
1073 See the method [llvm::ConstantExpr::getSIToFP]. *)
1074 val const_sitofp : llvalue -> lltype -> llvalue
1076 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
1077 floating point constant [c] to integer type [ty].
1078 See the method [llvm::ConstantExpr::getFPToUI]. *)
1079 val const_fptoui : 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::getFPToSI]. *)
1084 val const_fptosi : llvalue -> lltype -> llvalue
1086 (** [const_ptrtoint c ty] returns the constant integer conversion of
1087 pointer constant [c] to integer type [ty].
1088 See the method [llvm::ConstantExpr::getPtrToInt]. *)
1089 val const_ptrtoint : llvalue -> lltype -> llvalue
1091 (** [const_inttoptr c ty] returns the constant pointer conversion of
1092 integer constant [c] to pointer type [ty].
1093 See the method [llvm::ConstantExpr::getIntToPtr]. *)
1094 val const_inttoptr : llvalue -> lltype -> llvalue
1096 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
1097 to type [ty] of equal size.
1098 See the method [llvm::ConstantExpr::getBitCast]. *)
1099 val const_bitcast : llvalue -> lltype -> llvalue
1101 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
1102 conversion of constant [c] to type [ty].
1103 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
1104 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
1106 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
1107 conversion of constant [c] to type [ty].
1108 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
1109 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
1111 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
1112 conversion of constant [c] to type [ty].
1113 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
1114 val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
1116 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
1117 cast conversion of constant [c] to type [ty] of equal size.
1118 See the method [llvm::ConstantExpr::getPointerCast]. *)
1119 val const_pointercast : llvalue -> lltype -> llvalue
1121 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
1122 -> integer casts of constant [c] to type [ty].
1123 See the method [llvm::ConstantExpr::getIntCast]. *)
1124 val const_intcast : llvalue -> lltype -> llvalue
1126 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
1127 fp casts of constant [c] to type [ty].
1128 See the method [llvm::ConstantExpr::getFPCast]. *)
1129 val const_fpcast : llvalue -> lltype -> llvalue
1131 (** [const_select cond t f] returns the constant conditional which returns value
1132 [t] if the boolean constant [cond] is true and the value [f] otherwise.
1133 See the method [llvm::ConstantExpr::getSelect]. *)
1134 val const_select : llvalue -> llvalue -> llvalue -> llvalue
1136 (** [const_extractelement vec i] returns the constant [i]th element of
1137 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
1138 the size of the vector.
1139 See the method [llvm::ConstantExpr::getExtractElement]. *)
1140 val const_extractelement : llvalue -> llvalue -> llvalue
1142 (** [const_insertelement vec v i] returns the constant vector with the same
1143 elements as constant vector [v] but the [i]th element replaced by the
1144 constant [v]. [v] must be a constant value with the type of the vector
1145 elements. [i] must be a constant [i32] value unsigned less than the size
1147 See the method [llvm::ConstantExpr::getInsertElement]. *)
1148 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
1150 (** [const_shufflevector a b mask] returns a constant [shufflevector].
1151 See the LLVM Language Reference for details on the [shufflevector]
1153 See the method [llvm::ConstantExpr::getShuffleVector]. *)
1154 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
1156 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
1157 constant aggregate [agg]. Each [idxs] must be less than the size of the
1158 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
1159 val const_extractvalue : llvalue -> int array -> llvalue
1161 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
1162 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
1163 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
1164 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
1166 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
1167 See the method [llvm::InlineAsm::get]. *)
1168 val const_inline_asm : lltype -> string -> string -> bool -> bool -> llvalue
1170 (** [block_address f bb] returns the address of the basic block [bb] in the
1171 function [f]. See the method [llvm::BasicBlock::get]. *)
1172 val block_address : llvalue -> llbasicblock -> llvalue
1175 (** {7 Operations on global variables, functions, and aliases (globals)} *)
1177 (** [global_parent g] is the enclosing module of the global value [g].
1178 See the method [llvm::GlobalValue::getParent]. *)
1179 val global_parent : llvalue -> llmodule
1181 (** [is_declaration g] returns [true] if the global value [g] is a declaration
1182 only. Returns [false] otherwise.
1183 See the method [llvm::GlobalValue::isDeclaration]. *)
1184 val is_declaration : llvalue -> bool
1186 (** [linkage g] returns the linkage of the global value [g].
1187 See the method [llvm::GlobalValue::getLinkage]. *)
1188 val linkage : llvalue -> Linkage.t
1190 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
1191 See the method [llvm::GlobalValue::setLinkage]. *)
1192 val set_linkage : Linkage.t -> llvalue -> unit
1194 (** [section g] returns the linker section of the global value [g].
1195 See the method [llvm::GlobalValue::getSection]. *)
1196 val section : llvalue -> string
1198 (** [set_section s g] sets the linker section of the global value [g] to [s].
1199 See the method [llvm::GlobalValue::setSection]. *)
1200 val set_section : string -> llvalue -> unit
1202 (** [visibility g] returns the linker visibility of the global value [g].
1203 See the method [llvm::GlobalValue::getVisibility]. *)
1204 val visibility : llvalue -> Visibility.t
1206 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1207 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1208 val set_visibility : Visibility.t -> llvalue -> unit
1210 (** [alignment g] returns the required alignment of the global value [g].
1211 See the method [llvm::GlobalValue::getAlignment]. *)
1212 val alignment : llvalue -> int
1214 (** [set_alignment n g] sets the required alignment of the global value [g] to
1215 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1216 val set_alignment : int -> llvalue -> unit
1219 (** {7 Operations on global variables} *)
1221 (** [declare_global ty name m] returns a new global variable of type [ty] and
1222 with name [name] in module [m] in the default address space (0). If such a
1223 global variable already exists, it is returned. If the type of the existing
1224 global differs, then a bitcast to [ty] is returned. *)
1225 val declare_global : lltype -> string -> llmodule -> llvalue
1227 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1228 of type [ty] and with name [name] in module [m] in the address space
1229 [addrspace]. If such a global variable already exists, it is returned. If
1230 the type of the existing global differs, then a bitcast to [ty] is
1232 val declare_qualified_global : lltype -> string -> int -> llmodule -> llvalue
1234 (** [define_global name init m] returns a new global with name [name] and
1235 initializer [init] in module [m] in the default address space (0). If the
1236 named global already exists, it is renamed.
1237 See the constructor of [llvm::GlobalVariable]. *)
1238 val define_global : string -> llvalue -> llmodule -> llvalue
1240 (** [define_qualified_global name init addrspace m] returns a new global with
1241 name [name] and initializer [init] in module [m] in the address space
1242 [addrspace]. If the named global already exists, it is renamed.
1243 See the constructor of [llvm::GlobalVariable]. *)
1244 val define_qualified_global : string -> llvalue -> int -> llmodule -> llvalue
1246 (** [lookup_global name m] returns [Some g] if a global variable with name
1247 [name] exists in module [m]. If no such global exists, returns [None].
1248 See the [llvm::GlobalVariable] constructor. *)
1249 val lookup_global : string -> llmodule -> llvalue option
1251 (** [delete_global gv] destroys the global variable [gv].
1252 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1253 val delete_global : llvalue -> unit
1255 (** [global_begin m] returns the first position in the global variable list of
1256 the module [m]. [global_begin] and [global_succ] can be used to iterate
1257 over the global list in order.
1258 See the method [llvm::Module::global_begin]. *)
1259 val global_begin : llmodule -> (llmodule, llvalue) llpos
1261 (** [global_succ gv] returns the global variable list position succeeding
1263 See the method [llvm::Module::global_iterator::operator++]. *)
1264 val global_succ : llvalue -> (llmodule, llvalue) llpos
1266 (** [iter_globals f m] applies function [f] to each of the global variables of
1267 module [m] in order. Tail recursive. *)
1268 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1270 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1271 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1272 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1274 (** [global_end m] returns the last position in the global variable list of the
1275 module [m]. [global_end] and [global_pred] can be used to iterate over the
1276 global list in reverse.
1277 See the method [llvm::Module::global_end]. *)
1278 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1280 (** [global_pred gv] returns the global variable list position preceding
1282 See the method [llvm::Module::global_iterator::operator--]. *)
1283 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1285 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1286 of module [m] in reverse order. Tail recursive. *)
1287 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1289 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1290 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1291 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1293 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1294 constant. Returns [false] otherwise.
1295 See the method [llvm::GlobalVariable::isConstant]. *)
1296 val is_global_constant : llvalue -> bool
1298 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1299 [c] is [true] and not if [c] is [false].
1300 See the method [llvm::GlobalVariable::setConstant]. *)
1301 val set_global_constant : bool -> llvalue -> unit
1303 (** [global_initializer gv] returns the initializer for the global variable
1304 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1305 val global_initializer : llvalue -> llvalue
1307 (** [set_initializer c gv] sets the initializer for the global variable
1308 [gv] to the constant [c].
1309 See the method [llvm::GlobalVariable::setInitializer]. *)
1310 val set_initializer : llvalue -> llvalue -> unit
1312 (** [remove_initializer gv] unsets the initializer for the global variable
1314 See the method [llvm::GlobalVariable::setInitializer]. *)
1315 val remove_initializer : llvalue -> unit
1317 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1318 thread-local and [false] otherwise.
1319 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1320 val is_thread_local : llvalue -> bool
1322 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1323 [c] is [true] and not otherwise.
1324 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1325 val set_thread_local : bool -> llvalue -> unit
1327 (** [is_thread_local gv] returns the thread local mode of the global
1329 See the method [llvm::GlobalVariable::getThreadLocalMode]. *)
1330 val thread_local_mode : llvalue -> ThreadLocalMode.t
1332 (** [set_thread_local c gv] sets the thread local mode of the global
1334 See the method [llvm::GlobalVariable::setThreadLocalMode]. *)
1335 val set_thread_local_mode : ThreadLocalMode.t -> llvalue -> unit
1337 (** [is_externally_initialized gv] returns [true] if the global
1338 variable [gv] is externally initialized and [false] otherwise.
1339 See the method [llvm::GlobalVariable::isExternallyInitialized]. *)
1340 val is_externally_initialized : llvalue -> bool
1342 (** [set_externally_initialized c gv] sets the global variable [gv] to be
1343 externally initialized if [c] is [true] and not otherwise.
1344 See the method [llvm::GlobalVariable::setExternallyInitialized]. *)
1345 val set_externally_initialized : bool -> llvalue -> unit
1348 (** {7 Operations on aliases} *)
1350 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1351 the aliasee [a] with the name [n].
1352 See the constructor for [llvm::GlobalAlias]. *)
1353 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1356 (** {7 Operations on functions} *)
1358 (** [declare_function name ty m] returns a new function of type [ty] and
1359 with name [name] in module [m]. If such a function already exists,
1360 it is returned. If the type of the existing function differs, then a bitcast
1361 to [ty] is returned. *)
1362 val declare_function : string -> lltype -> llmodule -> llvalue
1364 (** [define_function name ty m] creates a new function with name [name] and
1365 type [ty] in module [m]. If the named function already exists, it is
1366 renamed. An entry basic block is created in the function.
1367 See the constructor of [llvm::GlobalVariable]. *)
1368 val define_function : string -> lltype -> llmodule -> llvalue
1370 (** [lookup_function name m] returns [Some f] if a function with name
1371 [name] exists in module [m]. If no such function exists, returns [None].
1372 See the method [llvm::Module] constructor. *)
1373 val lookup_function : string -> llmodule -> llvalue option
1375 (** [delete_function f] destroys the function [f].
1376 See the method [llvm::Function::eraseFromParent]. *)
1377 val delete_function : llvalue -> unit
1379 (** [function_begin m] returns the first position in the function list of the
1380 module [m]. [function_begin] and [function_succ] can be used to iterate over
1381 the function list in order.
1382 See the method [llvm::Module::begin]. *)
1383 val function_begin : llmodule -> (llmodule, llvalue) llpos
1385 (** [function_succ gv] returns the function list position succeeding
1387 See the method [llvm::Module::iterator::operator++]. *)
1388 val function_succ : llvalue -> (llmodule, llvalue) llpos
1390 (** [iter_functions f m] applies function [f] to each of the functions of module
1391 [m] in order. Tail recursive. *)
1392 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1394 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1395 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1396 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1398 (** [function_end m] returns the last position in the function list of
1399 the module [m]. [function_end] and [function_pred] can be used to iterate
1400 over the function list in reverse.
1401 See the method [llvm::Module::end]. *)
1402 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1404 (** [function_pred gv] returns the function list position preceding [After gv].
1405 See the method [llvm::Module::iterator::operator--]. *)
1406 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1408 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1409 module [m] in reverse order. Tail recursive. *)
1410 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1412 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1413 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1414 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1416 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1417 See the method [llvm::Function::isIntrinsic]. *)
1418 val is_intrinsic : llvalue -> bool
1420 (** [function_call_conv f] returns the calling convention of the function [f].
1421 See the method [llvm::Function::getCallingConv]. *)
1422 val function_call_conv : llvalue -> int
1424 (** [set_function_call_conv cc f] sets the calling convention of the function
1425 [f] to the calling convention numbered [cc].
1426 See the method [llvm::Function::setCallingConv]. *)
1427 val set_function_call_conv : int -> llvalue -> unit
1429 (** [gc f] returns [Some name] if the function [f] has a garbage
1430 collection algorithm specified and [None] otherwise.
1431 See the method [llvm::Function::getGC]. *)
1432 val gc : llvalue -> string option
1434 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1435 [gc]. See the method [llvm::Function::setGC]. *)
1436 val set_gc : string option -> llvalue -> unit
1438 (** [add_function_attr f a] adds attribute [a] to the return type of function
1440 val add_function_attr : llvalue -> Attribute.t -> unit
1442 (** [add_target_dependent_function_attr f a] adds target-dependent attribute
1443 [a] to function [f]. *)
1444 val add_target_dependent_function_attr : llvalue -> string -> string -> unit
1446 (** [function_attr f] returns the function attribute for the function [f].
1447 See the method [llvm::Function::getAttributes] *)
1448 val function_attr : llvalue -> Attribute.t list
1450 (** [remove_function_attr f a] removes attribute [a] from the return type of
1452 val remove_function_attr : llvalue -> Attribute.t -> unit
1455 (** {7 Operations on params} *)
1457 (** [params f] returns the parameters of function [f].
1458 See the method [llvm::Function::getArgumentList]. *)
1459 val params : llvalue -> llvalue array
1461 (** [param f n] returns the [n]th parameter of function [f].
1462 See the method [llvm::Function::getArgumentList]. *)
1463 val param : llvalue -> int -> llvalue
1465 (** [param_attr p] returns the attributes of parameter [p].
1466 See the methods [llvm::Function::getAttributes] and
1467 [llvm::Attributes::getParamAttributes] *)
1468 val param_attr : llvalue -> Attribute.t list
1470 (** [param_parent p] returns the parent function that owns the parameter.
1471 See the method [llvm::Argument::getParent]. *)
1472 val param_parent : llvalue -> llvalue
1474 (** [param_begin f] returns the first position in the parameter list of the
1475 function [f]. [param_begin] and [param_succ] can be used to iterate over
1476 the parameter list in order.
1477 See the method [llvm::Function::arg_begin]. *)
1478 val param_begin : llvalue -> (llvalue, llvalue) llpos
1480 (** [param_succ bb] returns the parameter list position succeeding
1482 See the method [llvm::Function::arg_iterator::operator++]. *)
1483 val param_succ : llvalue -> (llvalue, llvalue) llpos
1485 (** [iter_params f fn] applies function [f] to each of the parameters
1486 of function [fn] in order. Tail recursive. *)
1487 val iter_params : (llvalue -> unit) -> llvalue -> unit
1489 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1490 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1491 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1493 (** [param_end f] returns the last position in the parameter list of
1494 the function [f]. [param_end] and [param_pred] can be used to iterate
1495 over the parameter list in reverse.
1496 See the method [llvm::Function::arg_end]. *)
1497 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1499 (** [param_pred gv] returns the function list position preceding [After gv].
1500 See the method [llvm::Function::arg_iterator::operator--]. *)
1501 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1503 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1504 of function [fn] in reverse order. Tail recursive. *)
1505 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1507 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1508 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1509 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1511 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1512 val add_param_attr : llvalue -> Attribute.t -> unit
1514 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1515 val remove_param_attr : llvalue -> Attribute.t -> unit
1517 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1518 val set_param_alignment : llvalue -> int -> unit
1521 (** {7 Operations on basic blocks} *)
1523 (** [basic_blocks fn] returns the basic blocks of the function [f].
1524 See the method [llvm::Function::getBasicBlockList]. *)
1525 val basic_blocks : llvalue -> llbasicblock array
1527 (** [entry_block fn] returns the entry basic block of the function [f].
1528 See the method [llvm::Function::getEntryBlock]. *)
1529 val entry_block : llvalue -> llbasicblock
1531 (** [delete_block bb] deletes the basic block [bb].
1532 See the method [llvm::BasicBlock::eraseFromParent]. *)
1533 val delete_block : llbasicblock -> unit
1535 (** [remove_block bb] removes the basic block [bb] from its parent function.
1536 See the method [llvm::BasicBlock::removeFromParent]. *)
1537 val remove_block : llbasicblock -> unit
1539 (** [move_block_before pos bb] moves the basic block [bb] before [pos].
1540 See the method [llvm::BasicBlock::moveBefore]. *)
1541 val move_block_before : llbasicblock -> llbasicblock -> unit
1543 (** [move_block_after pos bb] moves the basic block [bb] after [pos].
1544 See the method [llvm::BasicBlock::moveAfter]. *)
1545 val move_block_after : llbasicblock -> llbasicblock -> unit
1547 (** [append_block c name f] creates a new basic block named [name] at the end of
1548 function [f] in the context [c].
1549 See the constructor of [llvm::BasicBlock]. *)
1550 val append_block : llcontext -> string -> llvalue -> llbasicblock
1552 (** [insert_block c name bb] creates a new basic block named [name] before the
1553 basic block [bb] in the context [c].
1554 See the constructor of [llvm::BasicBlock]. *)
1555 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1557 (** [block_parent bb] returns the parent function that owns the basic block.
1558 See the method [llvm::BasicBlock::getParent]. *)
1559 val block_parent : llbasicblock -> llvalue
1561 (** [block_begin f] returns the first position in the basic block list of the
1562 function [f]. [block_begin] and [block_succ] can be used to iterate over
1563 the basic block list in order.
1564 See the method [llvm::Function::begin]. *)
1565 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1567 (** [block_succ bb] returns the basic block list position succeeding
1569 See the method [llvm::Function::iterator::operator++]. *)
1570 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1572 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1573 of function [fn] in order. Tail recursive. *)
1574 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1576 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1577 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1578 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1580 (** [block_end f] returns the last position in the basic block list of
1581 the function [f]. [block_end] and [block_pred] can be used to iterate
1582 over the basic block list in reverse.
1583 See the method [llvm::Function::end]. *)
1584 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1586 (** [block_pred bb] returns the basic block list position preceding [After bb].
1587 See the method [llvm::Function::iterator::operator--]. *)
1588 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1590 (** [block_terminator bb] returns the terminator of the basic block [bb]. *)
1591 val block_terminator : llbasicblock -> llvalue option
1593 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1594 of function [fn] in reverse order. Tail recursive. *)
1595 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1597 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1598 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1599 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1601 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1602 val value_of_block : llbasicblock -> llvalue
1604 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1606 Similar to [llvm::isa<BasicBlock>]. *)
1607 val value_is_block : llvalue -> bool
1609 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1610 val block_of_value : llvalue -> llbasicblock
1613 (** {7 Operations on instructions} *)
1615 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1616 See the method [llvm::Instruction::getParent]. *)
1617 val instr_parent : llvalue -> llbasicblock
1619 (** [delete_instruction i] deletes the instruction [i].
1620 * See the method [llvm::Instruction::eraseFromParent]. *)
1621 val delete_instruction : llvalue -> unit
1623 (** [instr_begin bb] returns the first position in the instruction list of the
1624 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1625 the instruction list in order.
1626 See the method [llvm::BasicBlock::begin]. *)
1627 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1629 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1630 See the method [llvm::BasicBlock::iterator::operator++]. *)
1631 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1633 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1634 block [bb] in order. Tail recursive. *)
1635 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1637 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1638 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1639 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1641 (** [instr_end bb] returns the last position in the instruction list of the
1642 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1643 the instruction list in reverse.
1644 See the method [llvm::BasicBlock::end]. *)
1645 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1647 (** [instr_pred i] returns the instruction list position preceding [After i].
1648 See the method [llvm::BasicBlock::iterator::operator--]. *)
1649 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1651 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1652 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1653 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1655 (** [inst_opcode i] returns the [Opcode.t] corresponding to instruction [i],
1656 or [Opcode.Invalid] if [i] is not an instruction. *)
1657 val instr_opcode : llvalue -> Opcode.t
1659 (** [icmp_predicate i] returns the [Icmp.t] corresponding to an [icmp]
1661 val icmp_predicate : llvalue -> Icmp.t option
1664 (** {7 Operations on call sites} *)
1666 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1667 instruction [ci], which may be one of the values from the module
1668 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1669 [llvm::InvokeInst::getCallingConv]. *)
1670 val instruction_call_conv: llvalue -> int
1672 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1673 or invoke instruction [ci] to the integer [cc], which can be one of the
1674 values from the module {!CallConv}.
1675 See the method [llvm::CallInst::setCallingConv]
1676 and [llvm::InvokeInst::setCallingConv]. *)
1677 val set_instruction_call_conv: int -> llvalue -> unit
1679 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1680 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1682 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1684 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1685 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1687 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1690 (** {7 Operations on call instructions (only)} *)
1692 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1693 eligible for tail call optimization, [false] otherwise.
1694 See the method [llvm::CallInst::isTailCall]. *)
1695 val is_tail_call : llvalue -> bool
1697 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1698 call optimization if [tc] is [true], clears otherwise.
1699 See the method [llvm::CallInst::setTailCall]. *)
1700 val set_tail_call : bool -> llvalue -> unit
1703 (** {7 Operations on load/store instructions (only)} *)
1705 (** [is_volatile i] is [true] if the load or store instruction [i] is marked
1707 See the methods [llvm::LoadInst::isVolatile] and
1708 [llvm::StoreInst::isVolatile]. *)
1709 val is_volatile : llvalue -> bool
1711 (** [set_volatile v i] marks the load or store instruction [i] as volatile
1712 if [v] is [true], unmarks otherwise.
1713 See the methods [llvm::LoadInst::setVolatile] and
1714 [llvm::StoreInst::setVolatile]. *)
1715 val set_volatile : bool -> llvalue -> unit
1718 (** {7 Operations on phi nodes} *)
1720 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1721 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1722 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1724 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1725 See the method [llvm::PHINode::getIncomingValue]. *)
1726 val incoming : llvalue -> (llvalue * llbasicblock) list
1730 (** {6 Instruction builders} *)
1732 (** [builder context] creates an instruction builder with no position in
1733 the context [context]. It is invalid to use this builder until its position
1734 is set with {!position_before} or {!position_at_end}. See the constructor
1735 for [llvm::LLVMBuilder]. *)
1736 val builder : llcontext -> llbuilder
1738 (** [builder_at ip] creates an instruction builder positioned at [ip].
1739 See the constructor for [llvm::LLVMBuilder]. *)
1740 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1742 (** [builder_before ins] creates an instruction builder positioned before the
1743 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1744 val builder_before : llcontext -> llvalue -> llbuilder
1746 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1747 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1748 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1750 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1752 See the constructor for [llvm::LLVMBuilder]. *)
1753 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1755 (** [position_before ins b] moves the instruction builder [b] to before the
1756 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1757 val position_before : llvalue -> llbuilder -> unit
1759 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1760 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1761 val position_at_end : llbasicblock -> llbuilder -> unit
1763 (** [insertion_block b] returns the basic block that the builder [b] is
1764 positioned to insert into. Raises [Not_Found] if the instruction builder is
1766 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1767 val insertion_block : llbuilder -> llbasicblock
1769 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1770 position specified by the instruction builder [b].
1771 See the method [llvm::LLVMBuilder::Insert]. *)
1772 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1777 (** [set_current_debug_location b md] sets the current debug location [md] in
1779 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1780 val set_current_debug_location : llbuilder -> llvalue -> unit
1782 (** [clear_current_debug_location b] clears the current debug location in the
1784 val clear_current_debug_location : llbuilder -> unit
1786 (** [current_debug_location b] returns the current debug location, or None
1787 if none is currently set.
1788 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1789 val current_debug_location : llbuilder -> llvalue option
1791 (** [set_inst_debug_location b i] sets the current debug location of the builder
1792 [b] to the instruction [i].
1793 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1794 val set_inst_debug_location : llbuilder -> llvalue -> unit
1797 (** {7 Terminators} *)
1799 (** [build_ret_void b] creates a
1801 instruction at the position specified by the instruction builder [b].
1802 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1803 val build_ret_void : llbuilder -> llvalue
1805 (** [build_ret v b] creates a
1807 instruction at the position specified by the instruction builder [b].
1808 See the method [llvm::LLVMBuilder::CreateRet]. *)
1809 val build_ret : llvalue -> llbuilder -> llvalue
1811 (** [build_aggregate_ret vs b] creates a
1812 [ret {...} { %v1, %v2, ... } ]
1813 instruction at the position specified by the instruction builder [b].
1814 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1815 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1817 (** [build_br bb b] creates a
1819 instruction at the position specified by the instruction builder [b].
1820 See the method [llvm::LLVMBuilder::CreateBr]. *)
1821 val build_br : llbasicblock -> llbuilder -> llvalue
1823 (** [build_cond_br cond tbb fbb b] creates a
1824 [br %cond, %tbb, %fbb]
1825 instruction at the position specified by the instruction builder [b].
1826 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1827 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1830 (** [build_switch case elsebb count b] creates an empty
1831 [switch %case, %elsebb]
1832 instruction at the position specified by the instruction builder [b] with
1833 space reserved for [count] cases.
1834 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1835 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1837 (** [build_malloc ty name b] creates an [malloc]
1838 instruction at the position specified by the instruction builder [b].
1839 See the method [llvm::CallInst::CreateMalloc]. *)
1840 val build_malloc : lltype -> string -> llbuilder -> llvalue
1842 (** [build_array_malloc ty val name b] creates an [array malloc]
1843 instruction at the position specified by the instruction builder [b].
1844 See the method [llvm::CallInst::CreateArrayMalloc]. *)
1845 val build_array_malloc : lltype -> llvalue -> string -> llbuilder -> llvalue
1847 (** [build_free p b] creates a [free]
1848 instruction at the position specified by the instruction builder [b].
1849 See the method [llvm::LLVMBuilder::CreateFree]. *)
1850 val build_free : llvalue -> llbuilder -> llvalue
1852 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1853 when its input matches the constant [onval].
1854 See the method [llvm::SwitchInst::addCase]. **)
1855 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1857 (** [switch_default_dest sw] returns the default destination of the [switch]
1859 See the method [llvm:;SwitchInst::getDefaultDest]. **)
1860 val switch_default_dest : llvalue -> llbasicblock
1862 (** [build_indirect_br addr count b] creates a
1864 instruction at the position specified by the instruction builder [b] with
1865 space reserved for [count] destinations.
1866 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1867 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1869 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1870 location for the indirectbr instruction [br].
1871 See the method [llvm::IndirectBrInst::addDestination]. **)
1872 val add_destination : llvalue -> llbasicblock -> unit
1874 (** [build_invoke fn args tobb unwindbb name b] creates an
1875 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1876 instruction at the position specified by the instruction builder [b].
1877 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1878 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1879 llbasicblock -> string -> llbuilder -> llvalue
1881 (** [build_landingpad ty persfn numclauses name b] creates an
1883 instruction at the position specified by the instruction builder [b].
1884 See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
1885 val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
1888 (** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
1889 See the method [llvm::LandingPadInst::setCleanup]. *)
1890 val set_cleanup : llvalue -> bool -> unit
1892 (** [add_clause lp clause] adds the clause to the [landingpad]instruction.
1893 See the method [llvm::LandingPadInst::addClause]. *)
1894 val add_clause : llvalue -> llvalue -> unit
1896 (** [build_resume exn b] builds a [resume exn] instruction
1897 at the position specified by the instruction builder [b].
1898 See the method [llvm::LLVMBuilder::CreateResume] *)
1899 val build_resume : llvalue -> llbuilder -> llvalue
1901 (** [build_unreachable b] creates an
1903 instruction at the position specified by the instruction builder [b].
1904 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1905 val build_unreachable : llbuilder -> llvalue
1908 (** {7 Arithmetic} *)
1910 (** [build_add x y name b] creates a
1911 [%name = add %x, %y]
1912 instruction at the position specified by the instruction builder [b].
1913 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1914 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1916 (** [build_nsw_add x y name b] creates a
1917 [%name = nsw add %x, %y]
1918 instruction at the position specified by the instruction builder [b].
1919 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1920 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1922 (** [build_nuw_add x y name b] creates a
1923 [%name = nuw add %x, %y]
1924 instruction at the position specified by the instruction builder [b].
1925 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1926 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1928 (** [build_fadd x y name b] creates a
1929 [%name = fadd %x, %y]
1930 instruction at the position specified by the instruction builder [b].
1931 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1932 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1934 (** [build_sub x y name b] creates a
1935 [%name = sub %x, %y]
1936 instruction at the position specified by the instruction builder [b].
1937 See the method [llvm::LLVMBuilder::CreateSub]. *)
1938 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1940 (** [build_nsw_sub x y name b] creates a
1941 [%name = nsw sub %x, %y]
1942 instruction at the position specified by the instruction builder [b].
1943 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1944 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1946 (** [build_nuw_sub x y name b] creates a
1947 [%name = nuw sub %x, %y]
1948 instruction at the position specified by the instruction builder [b].
1949 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1950 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1952 (** [build_fsub x y name b] creates a
1953 [%name = fsub %x, %y]
1954 instruction at the position specified by the instruction builder [b].
1955 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1956 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1958 (** [build_mul x y name b] creates a
1959 [%name = mul %x, %y]
1960 instruction at the position specified by the instruction builder [b].
1961 See the method [llvm::LLVMBuilder::CreateMul]. *)
1962 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1964 (** [build_nsw_mul x y name b] creates a
1965 [%name = nsw mul %x, %y]
1966 instruction at the position specified by the instruction builder [b].
1967 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1968 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1970 (** [build_nuw_mul x y name b] creates a
1971 [%name = nuw mul %x, %y]
1972 instruction at the position specified by the instruction builder [b].
1973 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1974 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1976 (** [build_fmul x y name b] creates a
1977 [%name = fmul %x, %y]
1978 instruction at the position specified by the instruction builder [b].
1979 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1980 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1982 (** [build_udiv x y name b] creates a
1983 [%name = udiv %x, %y]
1984 instruction at the position specified by the instruction builder [b].
1985 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1986 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1988 (** [build_sdiv x y name b] creates a
1989 [%name = sdiv %x, %y]
1990 instruction at the position specified by the instruction builder [b].
1991 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1992 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1994 (** [build_exact_sdiv x y name b] creates a
1995 [%name = exact sdiv %x, %y]
1996 instruction at the position specified by the instruction builder [b].
1997 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1998 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2000 (** [build_fdiv x y name b] creates a
2001 [%name = fdiv %x, %y]
2002 instruction at the position specified by the instruction builder [b].
2003 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
2004 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2006 (** [build_urem x y name b] creates a
2007 [%name = urem %x, %y]
2008 instruction at the position specified by the instruction builder [b].
2009 See the method [llvm::LLVMBuilder::CreateURem]. *)
2010 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2012 (** [build_SRem x y name b] creates a
2013 [%name = srem %x, %y]
2014 instruction at the position specified by the instruction builder [b].
2015 See the method [llvm::LLVMBuilder::CreateSRem]. *)
2016 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2018 (** [build_frem x y name b] creates a
2019 [%name = frem %x, %y]
2020 instruction at the position specified by the instruction builder [b].
2021 See the method [llvm::LLVMBuilder::CreateFRem]. *)
2022 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2024 (** [build_shl x y name b] creates a
2025 [%name = shl %x, %y]
2026 instruction at the position specified by the instruction builder [b].
2027 See the method [llvm::LLVMBuilder::CreateShl]. *)
2028 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
2030 (** [build_lshr x y name b] creates a
2031 [%name = lshr %x, %y]
2032 instruction at the position specified by the instruction builder [b].
2033 See the method [llvm::LLVMBuilder::CreateLShr]. *)
2034 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
2036 (** [build_ashr x y name b] creates a
2037 [%name = ashr %x, %y]
2038 instruction at the position specified by the instruction builder [b].
2039 See the method [llvm::LLVMBuilder::CreateAShr]. *)
2040 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
2042 (** [build_and x y name b] creates a
2043 [%name = and %x, %y]
2044 instruction at the position specified by the instruction builder [b].
2045 See the method [llvm::LLVMBuilder::CreateAnd]. *)
2046 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
2048 (** [build_or x y name b] creates a
2050 instruction at the position specified by the instruction builder [b].
2051 See the method [llvm::LLVMBuilder::CreateOr]. *)
2052 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
2054 (** [build_xor x y name b] creates a
2055 [%name = xor %x, %y]
2056 instruction at the position specified by the instruction builder [b].
2057 See the method [llvm::LLVMBuilder::CreateXor]. *)
2058 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
2060 (** [build_neg x name b] creates a
2062 instruction at the position specified by the instruction builder [b].
2063 [-0.0] is used for floating point types to compute the correct sign.
2064 See the method [llvm::LLVMBuilder::CreateNeg]. *)
2065 val build_neg : llvalue -> string -> llbuilder -> llvalue
2067 (** [build_nsw_neg x name b] creates a
2068 [%name = nsw sub 0, %x]
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_nsw_neg : llvalue -> string -> llbuilder -> llvalue
2074 (** [build_nuw_neg x name b] creates a
2075 [%name = nuw 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_nuw_neg : llvalue -> string -> llbuilder -> llvalue
2081 (** [build_fneg x name b] creates a
2082 [%name = fsub 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::CreateFNeg]. *)
2086 val build_fneg : llvalue -> string -> llbuilder -> llvalue
2088 (** [build_xor x name b] creates a
2089 [%name = xor %x, -1]
2090 instruction at the position specified by the instruction builder [b].
2091 [-1] is the correct "all ones" value for the type of [x].
2092 See the method [llvm::LLVMBuilder::CreateXor]. *)
2093 val build_not : llvalue -> string -> llbuilder -> llvalue
2098 (** [build_alloca ty name b] creates a
2099 [%name = alloca %ty]
2100 instruction at the position specified by the instruction builder [b].
2101 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2102 val build_alloca : lltype -> string -> llbuilder -> llvalue
2104 (** [build_array_alloca ty n name b] creates a
2105 [%name = alloca %ty, %n]
2106 instruction at the position specified by the instruction builder [b].
2107 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2108 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
2111 (** [build_load v name b] creates a
2113 instruction at the position specified by the instruction builder [b].
2114 See the method [llvm::LLVMBuilder::CreateLoad]. *)
2115 val build_load : llvalue -> string -> llbuilder -> llvalue
2117 (** [build_store v p b] creates a
2119 instruction at the position specified by the instruction builder [b].
2120 See the method [llvm::LLVMBuilder::CreateStore]. *)
2121 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
2123 (** [build_atomicrmw op ptr val o st b] creates an [atomicrmw] instruction with
2124 operation [op] performed on pointer [ptr] and value [val] with ordering [o]
2125 and singlethread flag set to [st] at the position specified by
2126 the instruction builder [b].
2127 See the method [llvm::IRBuilder::CreateAtomicRMW]. *)
2128 val build_atomicrmw : AtomicRMWBinOp.t -> llvalue -> llvalue ->
2129 AtomicOrdering.t -> bool -> string -> llbuilder -> llvalue
2131 (** [build_gep p indices name b] creates a
2132 [%name = getelementptr %p, indices...]
2133 instruction at the position specified by the instruction builder [b].
2134 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
2135 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2137 (** [build_in_bounds_gep p indices name b] creates a
2138 [%name = gelementptr inbounds %p, indices...]
2139 instruction at the position specified by the instruction builder [b].
2140 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
2141 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
2144 (** [build_struct_gep p idx name b] creates a
2145 [%name = getelementptr %p, 0, idx]
2146 instruction at the position specified by the instruction builder [b].
2147 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
2148 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
2151 (** [build_global_string str name b] creates a series of instructions that adds
2152 a global string at the position specified by the instruction builder [b].
2153 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
2154 val build_global_string : string -> string -> llbuilder -> llvalue
2156 (** [build_global_stringptr str name b] creates a series of instructions that
2157 adds a global string pointer at the position specified by the instruction
2159 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
2160 val build_global_stringptr : string -> string -> llbuilder -> llvalue
2165 (** [build_trunc v ty name b] creates a
2166 [%name = trunc %p to %ty]
2167 instruction at the position specified by the instruction builder [b].
2168 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
2169 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2171 (** [build_zext v ty name b] creates a
2172 [%name = zext %p to %ty]
2173 instruction at the position specified by the instruction builder [b].
2174 See the method [llvm::LLVMBuilder::CreateZExt]. *)
2175 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
2177 (** [build_sext v ty name b] creates a
2178 [%name = sext %p to %ty]
2179 instruction at the position specified by the instruction builder [b].
2180 See the method [llvm::LLVMBuilder::CreateSExt]. *)
2181 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
2183 (** [build_fptoui v ty name b] creates a
2184 [%name = fptoui %p to %ty]
2185 instruction at the position specified by the instruction builder [b].
2186 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
2187 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
2189 (** [build_fptosi v ty name b] creates a
2190 [%name = fptosi %p to %ty]
2191 instruction at the position specified by the instruction builder [b].
2192 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
2193 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
2195 (** [build_uitofp v ty name b] creates a
2196 [%name = uitofp %p to %ty]
2197 instruction at the position specified by the instruction builder [b].
2198 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
2199 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2201 (** [build_sitofp v ty name b] creates a
2202 [%name = sitofp %p to %ty]
2203 instruction at the position specified by the instruction builder [b].
2204 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
2205 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2207 (** [build_fptrunc v ty name b] creates a
2208 [%name = fptrunc %p to %ty]
2209 instruction at the position specified by the instruction builder [b].
2210 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
2211 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2213 (** [build_fpext v ty name b] creates a
2214 [%name = fpext %p to %ty]
2215 instruction at the position specified by the instruction builder [b].
2216 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
2217 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
2219 (** [build_ptrtoint v ty name b] creates a
2220 [%name = prtotint %p to %ty]
2221 instruction at the position specified by the instruction builder [b].
2222 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2223 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2225 (** [build_inttoptr v ty name b] creates a
2226 [%name = inttoptr %p to %ty]
2227 instruction at the position specified by the instruction builder [b].
2228 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2229 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2231 (** [build_bitcast v ty name b] creates a
2232 [%name = bitcast %p to %ty]
2233 instruction at the position specified by the instruction builder [b].
2234 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2235 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2237 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2238 instruction at the position specified by the instruction builder [b].
2239 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2240 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2243 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2244 instruction at the position specified by the instruction builder [b].
2245 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2246 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2249 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2250 instruction at the position specified by the instruction builder [b].
2251 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2252 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2255 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2256 instruction at the position specified by the instruction builder [b].
2257 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2258 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2260 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2261 instruction at the position specified by the instruction builder [b].
2262 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2263 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2265 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2266 instruction at the position specified by the instruction builder [b].
2267 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2268 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2271 (** {7 Comparisons} *)
2273 (** [build_icmp pred x y name b] creates a
2274 [%name = icmp %pred %x, %y]
2275 instruction at the position specified by the instruction builder [b].
2276 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2277 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2278 llbuilder -> llvalue
2280 (** [build_fcmp pred x y name b] creates a
2281 [%name = fcmp %pred %x, %y]
2282 instruction at the position specified by the instruction builder [b].
2283 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2284 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2285 llbuilder -> llvalue
2288 (** {7 Miscellaneous instructions} *)
2290 (** [build_phi incoming name b] creates a
2291 [%name = phi %incoming]
2292 instruction at the position specified by the instruction builder [b].
2293 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2294 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2295 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2298 (** [build_call fn args name b] creates a
2299 [%name = call %fn(args...)]
2300 instruction at the position specified by the instruction builder [b].
2301 See the method [llvm::LLVMBuilder::CreateCall]. *)
2302 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2304 (** [build_select cond thenv elsev name b] creates a
2305 [%name = select %cond, %thenv, %elsev]
2306 instruction at the position specified by the instruction builder [b].
2307 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2308 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2311 (** [build_va_arg valist argty name b] creates a
2312 [%name = va_arg %valist, %argty]
2313 instruction at the position specified by the instruction builder [b].
2314 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2315 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2317 (** [build_extractelement vec i name b] creates a
2318 [%name = extractelement %vec, %i]
2319 instruction at the position specified by the instruction builder [b].
2320 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2321 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2324 (** [build_insertelement vec elt i name b] creates a
2325 [%name = insertelement %vec, %elt, %i]
2326 instruction at the position specified by the instruction builder [b].
2327 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2328 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2329 llbuilder -> llvalue
2331 (** [build_shufflevector veca vecb mask name b] creates a
2332 [%name = shufflevector %veca, %vecb, %mask]
2333 instruction at the position specified by the instruction builder [b].
2334 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2335 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2336 llbuilder -> llvalue
2338 (** [build_insertvalue agg idx name b] creates a
2339 [%name = extractvalue %agg, %idx]
2340 instruction at the position specified by the instruction builder [b].
2341 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2342 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2345 (** [build_insertvalue agg val idx name b] creates a
2346 [%name = insertvalue %agg, %val, %idx]
2347 instruction at the position specified by the instruction builder [b].
2348 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2349 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2352 (** [build_is_null val name b] creates a
2353 [%name = icmp eq %val, null]
2354 instruction at the position specified by the instruction builder [b].
2355 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2356 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2358 (** [build_is_not_null val name b] creates a
2359 [%name = icmp ne %val, null]
2360 instruction at the position specified by the instruction builder [b].
2361 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2362 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2364 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2365 the difference between two pointer values at the position specified by the
2366 instruction builder [b].
2367 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2368 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2371 (** {6 Memory buffers} *)
2373 module MemoryBuffer : sig
2374 (** [of_file p] is the memory buffer containing the contents of the file at
2375 path [p]. If the file could not be read, then [IoError msg] is
2377 val of_file : string -> llmemorybuffer
2379 (** [of_stdin ()] is the memory buffer containing the contents of standard input.
2380 If standard input is empty, then [IoError msg] is raised. *)
2381 val of_stdin : unit -> llmemorybuffer
2383 (** [of_string ~name s] is the memory buffer containing the contents of string [s].
2384 The name of memory buffer is set to [name] if it is provided. *)
2385 val of_string : ?name:string -> string -> llmemorybuffer
2387 (** [as_string mb] is the string containing the contents of memory buffer [mb]. *)
2388 val as_string : llmemorybuffer -> string
2390 (** Disposes of a memory buffer. *)
2391 val dispose : llmemorybuffer -> unit
2395 (** {6 Pass Managers} *)
2397 module PassManager : sig
2400 type any = [ `Module | `Function ]
2402 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2403 type of pipeline is suitable for link-time optimization and whole-module
2405 See the constructor of [llvm::PassManager]. *)
2406 val create : unit -> [ `Module ] t
2408 (** [PassManager.create_function m] constructs a new function-by-function
2409 pass pipeline over the module [m]. It does not take ownership of [m].
2410 This type of pipeline is suitable for code generation and JIT compilation
2412 See the constructor of [llvm::FunctionPassManager]. *)
2413 val create_function : llmodule -> [ `Function ] t
2415 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2416 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2417 any of the passes modified the module, [false] otherwise.
2418 See the [llvm::PassManager::run] method. *)
2419 val run_module : llmodule -> [ `Module ] t -> bool
2421 (** [initialize fpm] initializes all of the function passes scheduled in the
2422 function pass manager [fpm]. Returns [true] if any of the passes modified
2423 the module, [false] otherwise.
2424 See the [llvm::FunctionPassManager::doInitialization] method. *)
2425 val initialize : [ `Function ] t -> bool
2427 (** [run_function f fpm] executes all of the function passes scheduled in the
2428 function pass manager [fpm] over the function [f]. Returns [true] if any
2429 of the passes modified [f], [false] otherwise.
2430 See the [llvm::FunctionPassManager::run] method. *)
2431 val run_function : llvalue -> [ `Function ] t -> bool
2433 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2434 function pass manager [fpm]. Returns [true] if any of the passes
2435 modified the module, [false] otherwise.
2436 See the [llvm::FunctionPassManager::doFinalization] method. *)
2437 val finalize : [ `Function ] t -> bool
2439 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2441 See the destructor of [llvm::BasePassManager]. *)
2442 val dispose : [< any ] t -> unit