1 (*===-- llvm/llvm.mli - LLVM OCaml Interface ------------------------------===*
3 * The LLVM Compiler Infrastructure
5 * This file is distributed under the University of Illinois Open Source
6 * License. See LICENSE.TXT for details.
8 *===----------------------------------------------------------------------===*)
12 This interface provides an OCaml API for the LLVM intermediate
13 representation, the classes in the VMCore library. *)
16 (** {6 Abstract types}
18 These abstract types correlate directly to the LLVM VMCore classes. *)
20 (** The top-level container for all LLVM global data. See the
21 [llvm::LLVMContext] class. *)
24 (** The top-level container for all other LLVM Intermediate Representation (IR)
25 objects. See the [llvm::Module] class. *)
28 (** Each value in the LLVM IR has a type, an instance of [lltype]. See the
29 [llvm::Type] class. *)
32 (** Any value in the LLVM IR. Functions, instructions, global variables,
33 constants, and much more are all [llvalues]. See the [llvm::Value] class.
34 This type covers a wide range of subclasses. *)
37 (** Used to store users and usees of values. See the [llvm::Use] class. *)
40 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *)
43 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
47 (** Used to efficiently handle large buffers of read-only binary data.
48 See the [llvm::MemoryBuffer] class. *)
51 (** The kind id of metadata attached to an instruction. *)
54 (** The kind of an [lltype], the result of [classify_type ty]. See the
55 [llvm::Type::TypeID] enumeration. *)
76 (** The linkage of a global value, accessed with {!linkage} and
77 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
81 | Available_externally
84 | Link_once_odr_auto_hide
99 (** The linker visibility of a global value, accessed with {!visibility} and
100 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
101 module Visibility : sig
108 (** The following calling convention values may be accessed with
109 {!function_call_conv} and {!set_function_call_conv}. Calling
110 conventions are open-ended. *)
111 module CallConv : sig
112 val c : int (** [c] is the C calling convention. *)
113 val fast : int (** [fast] is the calling convention to allow LLVM
114 maximum optimization opportunities. Use only with
116 val cold : int (** [cold] is the calling convention for
118 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling
119 convention from C. *)
120 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
121 convention from C. *)
124 (** The attribute kind of a function parameter, result or the function itself.
125 See [llvm::Attribute::AttrKind]. *)
126 module Attribute : sig
150 | Stackalignment of int
156 (** The predicate for an integer comparison ([icmp]) instruction.
157 See the [llvm::ICmpInst::Predicate] enumeration. *)
172 (** The predicate for a floating-point comparison ([fcmp]) instruction.
173 See the [llvm::FCmpInst::Predicate] enumeration. *)
194 (** The opcodes for LLVM instructions and constant expressions. *)
197 | Invalid (* not an instruction *)
198 (* Terminator Instructions *)
206 (* Standard Binary Operators *)
219 (* Logical Operators *)
226 (* Memory Operators *)
244 (* Other Operators *)
265 (** The type of a clause of a [landingpad] instruction.
266 See [llvm::LandingPadInst::ClauseType]. *)
267 module LandingPadClauseTy : sig
273 (** The thread local mode of a global value, accessed with {!thread_local_mode}
274 and {!set_thread_local_mode}.
275 See [llvm::GlobalVariable::ThreadLocalMode]. *)
276 module ThreadLocalMode : sig
285 (** The ordering of an atomic [load], [store], [cmpxchg], [atomicrmw] or
286 [fence] instruction. See [llvm::AtomicOrdering]. *)
287 module AtomicOrdering : sig
292 | Invalid (* removed due to API changes *)
296 | SequentiallyConsistent
299 (** The opcode of an [atomicrmw] instruction.
300 See [llvm::AtomicRMWInst::BinOp]. *)
301 module AtomicRMWBinOp : sig
316 (** The kind of an [llvalue], the result of [classify_value v].
317 See the various [LLVMIsA*] functions. *)
318 module ValueKind : sig
327 | ConstantAggregateZero
334 | ConstantPointerNull
341 | Instruction of Opcode.t
347 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
348 of [a]. [llpos] is used to specify positions in and for forward iteration
349 through the various value lists maintained by the LLVM IR. *)
350 type ('a, 'b) llpos =
354 (** [After b] and [At_start a] specify positions from the end of the ['b] list
355 of [a]. [llrev_pos] is used for reverse iteration through the various value
356 lists maintained by the LLVM IR. *)
357 type ('a, 'b) llrev_pos =
362 (** {6 Exceptions} *)
364 exception IoError of string
367 (** {6 Global configuration} *)
369 (** [enable_pretty_stacktraces ()] enables LLVM's built-in stack trace code.
370 This intercepts the OS's crash signals and prints which component of LLVM
371 you were in at the time of the crash. *)
372 val enable_pretty_stacktrace : unit -> unit
374 (** [install_fatal_error_handler f] installs [f] as LLVM's fatal error handler.
375 The handler will receive the reason for termination as a string. After
376 the handler has been executed, LLVM calls [exit(1)]. *)
377 val install_fatal_error_handler : (string -> unit) -> unit
379 (** [reset_fatal_error_handler ()] resets LLVM's fatal error handler. *)
380 val reset_fatal_error_handler : unit -> unit
384 (** [create_context ()] creates a context for storing the "global" state in
385 LLVM. See the constructor [llvm::LLVMContext]. *)
386 val create_context : unit -> llcontext
388 (** [destroy_context ()] destroys a context. See the destructor
389 [llvm::LLVMContext::~LLVMContext]. *)
390 val dispose_context : llcontext -> unit
392 (** See the function [llvm::getGlobalContext]. *)
393 val global_context : unit -> llcontext
395 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
396 name [name] in the context [context]. See the function
397 [llvm::LLVMContext::getMDKindID]. *)
398 val mdkind_id : llcontext -> string -> llmdkind
403 (** [create_module context id] creates a module with the supplied module ID in
404 the context [context]. Modules are not garbage collected; it is mandatory
405 to call {!dispose_module} to free memory. See the constructor
406 [llvm::Module::Module]. *)
407 val create_module : llcontext -> string -> llmodule
409 (** [dispose_module m] destroys a module [m] and all of the IR objects it
410 contained. All references to subordinate objects are invalidated;
411 referencing them will invoke undefined behavior. See the destructor
412 [llvm::Module::~Module]. *)
413 val dispose_module : llmodule -> unit
415 (** [target_triple m] is the target specifier for the module [m], something like
416 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
417 val target_triple: llmodule -> string
419 (** [target_triple triple m] changes the target specifier for the module [m] to
420 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
421 val set_target_triple: string -> llmodule -> unit
423 (** [data_layout m] is the data layout specifier for the module [m], something
424 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
425 method [llvm::Module::getDataLayout]. *)
426 val data_layout: llmodule -> string
428 (** [set_data_layout s m] changes the data layout specifier for the module [m]
429 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
430 val set_data_layout: string -> llmodule -> unit
432 (** [dump_module m] prints the .ll representation of the module [m] to standard
433 error. See the method [llvm::Module::dump]. *)
434 val dump_module : llmodule -> unit
436 (** [print_module f m] prints the .ll representation of the module [m]
437 to file [f]. See the method [llvm::Module::print]. *)
438 val print_module : string -> llmodule -> unit
440 (** [string_of_llmodule m] returns the .ll representation of the module [m]
441 as a string. See the method [llvm::Module::print]. *)
442 val string_of_llmodule : llmodule -> string
444 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
445 the method [llvm::Module::setModuleInlineAsm]. *)
446 val set_module_inline_asm : llmodule -> string -> unit
448 (** [module_context m] returns the context of the specified module.
449 See the method [llvm::Module::getContext] *)
450 val module_context : llmodule -> llcontext
455 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
456 See the method [llvm::Type::getTypeID]. *)
457 val classify_type : lltype -> TypeKind.t
459 (** [type_is_sized ty] returns whether the type has a size or not.
460 If it doesn't then it is not safe to call the [DataLayout::] methods on it.
462 val type_is_sized : lltype -> bool
464 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
465 See the method [llvm::Type::getContext]. *)
466 val type_context : lltype -> llcontext
468 (** [dump_type ty] prints the .ll representation of the type [ty] to standard
469 error. See the method [llvm::Type::dump]. *)
470 val dump_type : lltype -> unit
472 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
473 val string_of_lltype : lltype -> string
476 (** {7 Operations on integer types} *)
478 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
479 [llvm::Type::Int1Ty]. *)
480 val i1_type : llcontext -> lltype
482 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
483 [llvm::Type::Int8Ty]. *)
484 val i8_type : llcontext -> lltype
486 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
487 [llvm::Type::Int16Ty]. *)
488 val i16_type : llcontext -> lltype
490 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
491 [llvm::Type::Int32Ty]. *)
492 val i32_type : llcontext -> lltype
494 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
495 [llvm::Type::Int64Ty]. *)
496 val i64_type : llcontext -> lltype
498 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
499 [c]. See the method [llvm::IntegerType::get]. *)
500 val integer_type : llcontext -> int -> lltype
502 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
503 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
504 val integer_bitwidth : lltype -> int
507 (** {7 Operations on real types} *)
509 (** [float_type c] returns the IEEE 32-bit floating point type in the context
510 [c]. See [llvm::Type::FloatTy]. *)
511 val float_type : llcontext -> lltype
513 (** [double_type c] returns the IEEE 64-bit floating point type in the context
514 [c]. See [llvm::Type::DoubleTy]. *)
515 val double_type : llcontext -> lltype
517 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
518 [c]. See [llvm::Type::X86_FP80Ty]. *)
519 val x86fp80_type : llcontext -> lltype
521 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
522 [c]. See [llvm::Type::FP128Ty]. *)
523 val fp128_type : llcontext -> lltype
525 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
526 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
527 val ppc_fp128_type : llcontext -> lltype
530 (** {7 Operations on function types} *)
532 (** [function_type ret_ty param_tys] returns the function type returning
533 [ret_ty] and taking [param_tys] as parameters.
534 See the method [llvm::FunctionType::get]. *)
535 val function_type : lltype -> lltype array -> lltype
537 (** [var_arg_function_type ret_ty param_tys] is just like
538 [function_type ret_ty param_tys] except that it returns the function type
539 which also takes a variable number of arguments.
540 See the method [llvm::FunctionType::get]. *)
541 val var_arg_function_type : lltype -> lltype array -> lltype
543 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
544 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
545 val is_var_arg : lltype -> bool
547 (** [return_type fty] gets the return type of the function type [fty].
548 See the method [llvm::FunctionType::getReturnType]. *)
549 val return_type : lltype -> lltype
551 (** [param_types fty] gets the parameter types of the function type [fty].
552 See the method [llvm::FunctionType::getParamType]. *)
553 val param_types : lltype -> lltype array
556 (** {7 Operations on struct types} *)
558 (** [struct_type context tys] returns the structure type in the context
559 [context] containing in the types in the array [tys]. See the method
560 [llvm::StructType::get]. *)
561 val struct_type : llcontext -> lltype array -> lltype
563 (** [packed_struct_type context ys] returns the packed structure type in the
564 context [context] containing in the types in the array [tys]. See the method
565 [llvm::StructType::get]. *)
566 val packed_struct_type : llcontext -> lltype array -> lltype
568 (** [struct_name ty] returns the name of the named structure type [ty],
569 or None if the structure type is not named *)
570 val struct_name : lltype -> string option
572 (** [named_struct_type context name] returns the named structure type [name]
573 in the context [context].
574 See the method [llvm::StructType::get]. *)
575 val named_struct_type : llcontext -> string -> lltype
577 (** [struct_set_body ty elts ispacked] sets the body of the named struct [ty]
578 to the [elts] elements.
579 See the moethd [llvm::StructType::setBody]. *)
580 val struct_set_body : lltype -> lltype array -> bool -> unit
582 (** [struct_element_types sty] returns the constituent types of the struct type
583 [sty]. See the method [llvm::StructType::getElementType]. *)
584 val struct_element_types : lltype -> lltype array
586 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
587 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
588 val is_packed : lltype -> bool
590 (** [is_opaque sty] returns [true] if the structure type [sty] is opaque.
591 [false] otherwise. See the method [llvm::StructType::isOpaque]. *)
592 val is_opaque : lltype -> bool
595 (** {7 Operations on pointer, vector, and array types} *)
597 (** [array_type ty n] returns the array type containing [n] elements of type
598 [ty]. See the method [llvm::ArrayType::get]. *)
599 val array_type : lltype -> int -> lltype
601 (** [pointer_type ty] returns the pointer type referencing objects of type
602 [ty] in the default address space (0).
603 See the method [llvm::PointerType::getUnqual]. *)
604 val pointer_type : lltype -> lltype
606 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
607 of type [ty] in address space [as].
608 See the method [llvm::PointerType::get]. *)
609 val qualified_pointer_type : lltype -> int -> lltype
611 (** [vector_type ty n] returns the array type containing [n] elements of the
612 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
613 val vector_type : lltype -> int -> lltype
615 (** [element_type ty] returns the element type of the pointer, vector, or array
616 type [ty]. See the method [llvm::SequentialType::get]. *)
617 val element_type : lltype -> lltype
619 (** [element_type aty] returns the element count of the array type [aty].
620 See the method [llvm::ArrayType::getNumElements]. *)
621 val array_length : lltype -> int
623 (** [address_space pty] returns the address space qualifier of the pointer type
624 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
625 val address_space : lltype -> int
627 (** [element_type ty] returns the element count of the vector type [ty].
628 See the method [llvm::VectorType::getNumElements]. *)
629 val vector_size : lltype -> int
632 (** {7 Operations on other types} *)
634 (** [void_type c] creates a type of a function which does not return any
635 value in the context [c]. See [llvm::Type::VoidTy]. *)
636 val void_type : llcontext -> lltype
638 (** [label_type c] creates a type of a basic block in the context [c]. See
639 [llvm::Type::LabelTy]. *)
640 val label_type : llcontext -> lltype
642 (** [x86_mmx_type c] returns the x86 64-bit MMX register type in the
643 context [c]. See [llvm::Type::X86_MMXTy]. *)
644 val x86_mmx_type : llcontext -> lltype
646 (** [type_by_name m name] returns the specified type from the current module
648 See the method [llvm::Module::getTypeByName] *)
649 val type_by_name : llmodule -> string -> lltype option
654 (** [type_of v] returns the type of the value [v].
655 See the method [llvm::Value::getType]. *)
656 val type_of : llvalue -> lltype
658 (** [classify_value v] returns the kind of the value [v]. *)
659 val classify_value : llvalue -> ValueKind.t
661 (** [value_name v] returns the name of the value [v]. For global values, this is
662 the symbol name. For instructions and basic blocks, it is the SSA register
663 name. It is meaningless for constants.
664 See the method [llvm::Value::getName]. *)
665 val value_name : llvalue -> string
667 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
668 [llvm::Value::setName]. *)
669 val set_value_name : string -> llvalue -> unit
671 (** [dump_value v] prints the .ll representation of the value [v] to standard
672 error. See the method [llvm::Value::dump]. *)
673 val dump_value : llvalue -> unit
675 (** [string_of_llvalue v] returns a string describing the value [v]. *)
676 val string_of_llvalue : llvalue -> string
678 (** [replace_all_uses_with old new] replaces all uses of the value [old]
679 with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
680 val replace_all_uses_with : llvalue -> llvalue -> unit
685 (** [use_begin v] returns the first position in the use list for the value [v].
686 [use_begin] and [use_succ] can e used to iterate over the use list in order.
687 See the method [llvm::Value::use_begin]. *)
688 val use_begin : llvalue -> lluse option
690 (** [use_succ u] returns the use list position succeeding [u].
691 See the method [llvm::use_value_iterator::operator++]. *)
692 val use_succ : lluse -> lluse option
694 (** [user u] returns the user of the use [u].
695 See the method [llvm::Use::getUser]. *)
696 val user : lluse -> llvalue
698 (** [used_value u] returns the usee of the use [u].
699 See the method [llvm::Use::getUsedValue]. *)
700 val used_value : lluse -> llvalue
702 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
703 in order. Tail recursive. *)
704 val iter_uses : (lluse -> unit) -> llvalue -> unit
706 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
707 [u1,...,uN] are the users of the value [v]. Tail recursive. *)
708 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
710 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
711 [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
712 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
717 (** [operand v i] returns the operand at index [i] for the value [v]. See the
718 method [llvm::User::getOperand]. *)
719 val operand : llvalue -> int -> llvalue
721 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
723 See the method [llvm::User::setOperand]. *)
724 val set_operand : llvalue -> int -> llvalue -> unit
726 (** [num_operands v] returns the number of operands for the value [v].
727 See the method [llvm::User::getNumOperands]. *)
728 val num_operands : llvalue -> int
731 (** {7 Operations on constants of (mostly) any type} *)
733 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
734 otherwise. Similar to [llvm::isa<Constant>]. *)
735 val is_constant : llvalue -> bool
737 (** [const_null ty] returns the constant null (zero) of the type [ty].
738 See the method [llvm::Constant::getNullValue]. *)
739 val const_null : lltype -> llvalue
741 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
742 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
743 val const_all_ones : (*int|vec*)lltype -> llvalue
745 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
746 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
747 val const_pointer_null : lltype -> llvalue
749 (** [undef ty] returns the undefined value of the type [ty].
750 See the method [llvm::UndefValue::get]. *)
751 val undef : lltype -> llvalue
753 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
754 See the method [llvm::Constant::isNullValue]. *)
755 val is_null : llvalue -> bool
757 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
758 otherwise. Similar to [llvm::isa<UndefValue>]. *)
759 val is_undef : llvalue -> bool
761 (** [constexpr_opcode v] returns an [Opcode.t] corresponding to constexpr
762 value [v], or [Opcode.Invalid] if [v] is not a constexpr. *)
763 val constexpr_opcode : llvalue -> Opcode.t
766 (** {7 Operations on instructions} *)
768 (** [has_metadata i] returns whether or not the instruction [i] has any
769 metadata attached to it. See the function
770 [llvm::Instruction::hasMetadata]. *)
771 val has_metadata : llvalue -> bool
773 (** [metadata i kind] optionally returns the metadata associated with the
774 kind [kind] in the instruction [i] See the function
775 [llvm::Instruction::getMetadata]. *)
776 val metadata : llvalue -> llmdkind -> llvalue option
778 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
779 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
780 val set_metadata : llvalue -> llmdkind -> llvalue -> unit
782 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
783 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
784 val clear_metadata : llvalue -> llmdkind -> unit
787 (** {7 Operations on metadata} *)
789 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
790 See the method [llvm::MDNode::get]. *)
791 val mdstring : llcontext -> string -> llvalue
793 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
795 See the method [llvm::MDNode::get]. *)
796 val mdnode : llcontext -> llvalue array -> llvalue
798 (** [get_mdstring v] returns the MDString.
799 See the method [llvm::MDString::getString] *)
800 val get_mdstring : llvalue -> string option
802 (** [get_named_metadata m name] returns all the MDNodes belonging to the named
804 See the method [llvm::NamedMDNode::getOperand]. *)
805 val get_named_metadata : llmodule -> string -> llvalue array
807 (** [add_named_metadata_operand m name v] adds [v] as the last operand of
808 metadata named [name] in module [m]. If the metadata does not exist,
810 See the methods [llvm::Module::getNamedMetadata()] and
811 [llvm::MDNode::addOperand()]. *)
812 val add_named_metadata_operand : llmodule -> string -> llvalue -> unit
815 (** {7 Operations on scalar constants} *)
817 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
818 See the method [llvm::ConstantInt::get]. *)
819 val const_int : lltype -> int -> llvalue
821 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
822 [i]. See the method [llvm::ConstantInt::get]. *)
823 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
825 (** [int64_of_const c] returns the int64 value of the [c] constant integer.
826 None is returned if this is not an integer constant, or bitwidth exceeds 64.
827 See the method [llvm::ConstantInt::getSExtValue].*)
828 val int64_of_const : llvalue -> Int64.t option
830 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
831 value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
832 val const_int_of_string : lltype -> string -> int -> llvalue
834 (** [const_float ty n] returns the floating point constant of type [ty] and
835 value [n]. See the method [llvm::ConstantFP::get]. *)
836 val const_float : lltype -> float -> llvalue
838 (** [const_float_of_string ty s] returns the floating point constant of type
839 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
840 val const_float_of_string : lltype -> string -> llvalue
843 (** {7 Operations on composite constants} *)
845 (** [const_string c s] returns the constant [i8] array with the values of the
846 characters in the string [s] in the context [c]. The array is not
847 null-terminated (but see {!const_stringz}). This value can in turn be used
848 as the initializer for a global variable. See the method
849 [llvm::ConstantArray::get]. *)
850 val const_string : llcontext -> string -> llvalue
852 (** [const_stringz c s] returns the constant [i8] array with the values of the
853 characters in the string [s] and a null terminator in the context [c]. This
854 value can in turn be used as the initializer for a global variable.
855 See the method [llvm::ConstantArray::get]. *)
856 val const_stringz : llcontext -> string -> llvalue
858 (** [const_array ty elts] returns the constant array of type
859 [array_type ty (Array.length elts)] and containing the values [elts].
860 This value can in turn be used as the initializer for a global variable.
861 See the method [llvm::ConstantArray::get]. *)
862 val const_array : lltype -> llvalue array -> llvalue
864 (** [const_struct context elts] returns the structured constant of type
865 [struct_type (Array.map type_of elts)] and containing the values [elts]
866 in the context [context]. This value can in turn be used as the initializer
867 for a global variable. See the method [llvm::ConstantStruct::getAnon]. *)
868 val const_struct : llcontext -> llvalue array -> llvalue
870 (** [const_named_struct namedty elts] returns the structured constant of type
871 [namedty] (which must be a named structure type) and containing the values [elts].
872 This value can in turn be used as the initializer
873 for a global variable. See the method [llvm::ConstantStruct::get]. *)
874 val const_named_struct : lltype -> llvalue array -> llvalue
876 (** [const_packed_struct context elts] returns the structured constant of
877 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
878 values [elts] in the context [context]. This value can in turn be used as
879 the initializer for a global variable. See the method
880 [llvm::ConstantStruct::get]. *)
881 val const_packed_struct : llcontext -> llvalue array -> llvalue
883 (** [const_vector elts] returns the vector constant of type
884 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
885 values [elts]. See the method [llvm::ConstantVector::get]. *)
886 val const_vector : llvalue array -> llvalue
889 (** {7 Constant expressions} *)
891 (** [align_of ty] returns the alignof constant for the type [ty]. This is
892 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
893 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
894 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
895 val align_of : lltype -> llvalue
897 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
898 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
899 (const_int i32_type 1)) i64_type], but considerably more readable.
900 See the method [llvm::ConstantExpr::getSizeOf]. *)
901 val size_of : lltype -> llvalue
903 (** [const_neg c] returns the arithmetic negation of the constant [c].
904 See the method [llvm::ConstantExpr::getNeg]. *)
905 val const_neg : llvalue -> llvalue
907 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
908 no signed wrapping. The result is undefined if the negation overflows.
909 See the method [llvm::ConstantExpr::getNSWNeg]. *)
910 val const_nsw_neg : llvalue -> llvalue
912 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
913 no unsigned wrapping. The result is undefined if the negation overflows.
914 See the method [llvm::ConstantExpr::getNUWNeg]. *)
915 val const_nuw_neg : llvalue -> llvalue
917 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
918 See the method [llvm::ConstantExpr::getFNeg]. *)
919 val const_fneg : llvalue -> llvalue
921 (** [const_not c] returns the bitwise inverse of the constant [c].
922 See the method [llvm::ConstantExpr::getNot]. *)
923 val const_not : llvalue -> llvalue
925 (** [const_add c1 c2] returns the constant sum of two constants.
926 See the method [llvm::ConstantExpr::getAdd]. *)
927 val const_add : llvalue -> llvalue -> llvalue
929 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
930 signed wrapping. The result is undefined if the sum overflows.
931 See the method [llvm::ConstantExpr::getNSWAdd]. *)
932 val const_nsw_add : llvalue -> llvalue -> llvalue
934 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
935 unsigned wrapping. The result is undefined if the sum overflows.
936 See the method [llvm::ConstantExpr::getNSWAdd]. *)
937 val const_nuw_add : llvalue -> llvalue -> llvalue
939 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
940 See the method [llvm::ConstantExpr::getFAdd]. *)
941 val const_fadd : llvalue -> llvalue -> llvalue
943 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
944 constants. See the method [llvm::ConstantExpr::getSub]. *)
945 val const_sub : llvalue -> llvalue -> llvalue
947 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
948 no signed wrapping. The result is undefined if the sum overflows.
949 See the method [llvm::ConstantExpr::getNSWSub]. *)
950 val const_nsw_sub : llvalue -> llvalue -> llvalue
952 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
953 no unsigned wrapping. The result is undefined if the sum overflows.
954 See the method [llvm::ConstantExpr::getNSWSub]. *)
955 val const_nuw_sub : llvalue -> llvalue -> llvalue
957 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
958 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
959 val const_fsub : llvalue -> llvalue -> llvalue
961 (** [const_mul c1 c2] returns the constant product of two constants.
962 See the method [llvm::ConstantExpr::getMul]. *)
963 val const_mul : llvalue -> llvalue -> llvalue
965 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
966 no signed wrapping. The result is undefined if the sum overflows.
967 See the method [llvm::ConstantExpr::getNSWMul]. *)
968 val const_nsw_mul : llvalue -> llvalue -> llvalue
970 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
971 no unsigned wrapping. The result is undefined if the sum overflows.
972 See the method [llvm::ConstantExpr::getNSWMul]. *)
973 val const_nuw_mul : llvalue -> llvalue -> llvalue
975 (** [const_fmul c1 c2] returns the constant product of two constants floats.
976 See the method [llvm::ConstantExpr::getFMul]. *)
977 val const_fmul : llvalue -> llvalue -> llvalue
979 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
981 See the method [llvm::ConstantExpr::getUDiv]. *)
982 val const_udiv : llvalue -> llvalue -> llvalue
984 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
986 See the method [llvm::ConstantExpr::getSDiv]. *)
987 val const_sdiv : llvalue -> llvalue -> llvalue
989 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
990 signed integer constants. The result is undefined if the result is rounded
991 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
992 val const_exact_sdiv : llvalue -> llvalue -> llvalue
994 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
996 See the method [llvm::ConstantExpr::getFDiv]. *)
997 val const_fdiv : llvalue -> llvalue -> llvalue
999 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
1000 unsigned integer constants.
1001 See the method [llvm::ConstantExpr::getURem]. *)
1002 val const_urem : llvalue -> llvalue -> llvalue
1004 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
1005 signed integer constants.
1006 See the method [llvm::ConstantExpr::getSRem]. *)
1007 val const_srem : llvalue -> llvalue -> llvalue
1009 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
1010 signed floating point constants.
1011 See the method [llvm::ConstantExpr::getFRem]. *)
1012 val const_frem : llvalue -> llvalue -> llvalue
1014 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
1016 See the method [llvm::ConstantExpr::getAnd]. *)
1017 val const_and : llvalue -> llvalue -> llvalue
1019 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
1021 See the method [llvm::ConstantExpr::getOr]. *)
1022 val const_or : llvalue -> llvalue -> llvalue
1024 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
1026 See the method [llvm::ConstantExpr::getXor]. *)
1027 val const_xor : llvalue -> llvalue -> llvalue
1029 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
1030 constants, [c1 pred c2].
1031 See the method [llvm::ConstantExpr::getICmp]. *)
1032 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
1034 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
1035 point constants, [c1 pred c2].
1036 See the method [llvm::ConstantExpr::getFCmp]. *)
1037 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
1039 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
1040 constant integer [c2].
1041 See the method [llvm::ConstantExpr::getShl]. *)
1042 val const_shl : llvalue -> llvalue -> llvalue
1044 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
1045 constant integer [c2] with zero extension.
1046 See the method [llvm::ConstantExpr::getLShr]. *)
1047 val const_lshr : llvalue -> llvalue -> llvalue
1049 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
1050 constant integer [c2] with sign extension.
1051 See the method [llvm::ConstantExpr::getAShr]. *)
1052 val const_ashr : llvalue -> llvalue -> llvalue
1054 (** [const_gep pc indices] returns the constant [getElementPtr] of [pc] with the
1055 constant integers indices from the array [indices].
1056 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
1057 val const_gep : llvalue -> llvalue array -> llvalue
1059 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [pc]
1060 with the constant integers indices from the array [indices].
1061 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
1062 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
1064 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
1065 to the smaller integer type [ty].
1066 See the method [llvm::ConstantExpr::getTrunc]. *)
1067 val const_trunc : llvalue -> lltype -> llvalue
1069 (** [const_sext c ty] returns the constant sign extension of integer constant
1070 [c] to the larger integer type [ty].
1071 See the method [llvm::ConstantExpr::getSExt]. *)
1072 val const_sext : llvalue -> lltype -> llvalue
1074 (** [const_zext c ty] returns the constant zero extension of integer constant
1075 [c] to the larger integer type [ty].
1076 See the method [llvm::ConstantExpr::getZExt]. *)
1077 val const_zext : llvalue -> lltype -> llvalue
1079 (** [const_fptrunc c ty] returns the constant truncation of floating point
1080 constant [c] to the smaller floating point type [ty].
1081 See the method [llvm::ConstantExpr::getFPTrunc]. *)
1082 val const_fptrunc : llvalue -> lltype -> llvalue
1084 (** [const_fpext c ty] returns the constant extension of floating point constant
1085 [c] to the larger floating point type [ty].
1086 See the method [llvm::ConstantExpr::getFPExt]. *)
1087 val const_fpext : llvalue -> lltype -> llvalue
1089 (** [const_uitofp c ty] returns the constant floating point conversion of
1090 unsigned integer constant [c] to the floating point type [ty].
1091 See the method [llvm::ConstantExpr::getUIToFP]. *)
1092 val const_uitofp : llvalue -> lltype -> llvalue
1094 (** [const_sitofp c ty] returns the constant floating point conversion of
1095 signed integer constant [c] to the floating point type [ty].
1096 See the method [llvm::ConstantExpr::getSIToFP]. *)
1097 val const_sitofp : llvalue -> lltype -> llvalue
1099 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
1100 floating point constant [c] to integer type [ty].
1101 See the method [llvm::ConstantExpr::getFPToUI]. *)
1102 val const_fptoui : llvalue -> lltype -> llvalue
1104 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
1105 floating point constant [c] to integer type [ty].
1106 See the method [llvm::ConstantExpr::getFPToSI]. *)
1107 val const_fptosi : llvalue -> lltype -> llvalue
1109 (** [const_ptrtoint c ty] returns the constant integer conversion of
1110 pointer constant [c] to integer type [ty].
1111 See the method [llvm::ConstantExpr::getPtrToInt]. *)
1112 val const_ptrtoint : llvalue -> lltype -> llvalue
1114 (** [const_inttoptr c ty] returns the constant pointer conversion of
1115 integer constant [c] to pointer type [ty].
1116 See the method [llvm::ConstantExpr::getIntToPtr]. *)
1117 val const_inttoptr : llvalue -> lltype -> llvalue
1119 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
1120 to type [ty] of equal size.
1121 See the method [llvm::ConstantExpr::getBitCast]. *)
1122 val const_bitcast : llvalue -> lltype -> llvalue
1124 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
1125 conversion of constant [c] to type [ty].
1126 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
1127 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
1129 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
1130 conversion of constant [c] to type [ty].
1131 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
1132 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
1134 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
1135 conversion of constant [c] to type [ty].
1136 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
1137 val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
1139 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
1140 cast conversion of constant [c] to type [ty] of equal size.
1141 See the method [llvm::ConstantExpr::getPointerCast]. *)
1142 val const_pointercast : llvalue -> lltype -> llvalue
1144 (** [const_intcast c ty ~is_signed] returns a constant sext/zext, bitcast,
1145 or trunc for integer -> integer casts of constant [c] to type [ty].
1146 When converting a narrower value to a wider one, whether sext or zext
1147 will be used is controlled by [is_signed].
1148 See the method [llvm::ConstantExpr::getIntegerCast]. *)
1149 val const_intcast : llvalue -> lltype -> is_signed:bool -> llvalue
1151 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
1152 fp casts of constant [c] to type [ty].
1153 See the method [llvm::ConstantExpr::getFPCast]. *)
1154 val const_fpcast : llvalue -> lltype -> llvalue
1156 (** [const_select cond t f] returns the constant conditional which returns value
1157 [t] if the boolean constant [cond] is true and the value [f] otherwise.
1158 See the method [llvm::ConstantExpr::getSelect]. *)
1159 val const_select : llvalue -> llvalue -> llvalue -> llvalue
1161 (** [const_extractelement vec i] returns the constant [i]th element of
1162 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
1163 the size of the vector.
1164 See the method [llvm::ConstantExpr::getExtractElement]. *)
1165 val const_extractelement : llvalue -> llvalue -> llvalue
1167 (** [const_insertelement vec v i] returns the constant vector with the same
1168 elements as constant vector [v] but the [i]th element replaced by the
1169 constant [v]. [v] must be a constant value with the type of the vector
1170 elements. [i] must be a constant [i32] value unsigned less than the size
1172 See the method [llvm::ConstantExpr::getInsertElement]. *)
1173 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
1175 (** [const_shufflevector a b mask] returns a constant [shufflevector].
1176 See the LLVM Language Reference for details on the [shufflevector]
1178 See the method [llvm::ConstantExpr::getShuffleVector]. *)
1179 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
1181 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
1182 constant aggregate [agg]. Each [idxs] must be less than the size of the
1183 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
1184 val const_extractvalue : llvalue -> int array -> llvalue
1186 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
1187 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
1188 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
1189 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
1191 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
1192 See the method [llvm::InlineAsm::get]. *)
1193 val const_inline_asm : lltype -> string -> string -> bool -> bool -> llvalue
1195 (** [block_address f bb] returns the address of the basic block [bb] in the
1196 function [f]. See the method [llvm::BasicBlock::get]. *)
1197 val block_address : llvalue -> llbasicblock -> llvalue
1200 (** {7 Operations on global variables, functions, and aliases (globals)} *)
1202 (** [global_parent g] is the enclosing module of the global value [g].
1203 See the method [llvm::GlobalValue::getParent]. *)
1204 val global_parent : llvalue -> llmodule
1206 (** [is_declaration g] returns [true] if the global value [g] is a declaration
1207 only. Returns [false] otherwise.
1208 See the method [llvm::GlobalValue::isDeclaration]. *)
1209 val is_declaration : llvalue -> bool
1211 (** [linkage g] returns the linkage of the global value [g].
1212 See the method [llvm::GlobalValue::getLinkage]. *)
1213 val linkage : llvalue -> Linkage.t
1215 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
1216 See the method [llvm::GlobalValue::setLinkage]. *)
1217 val set_linkage : Linkage.t -> llvalue -> unit
1219 (** [section g] returns the linker section of the global value [g].
1220 See the method [llvm::GlobalValue::getSection]. *)
1221 val section : llvalue -> string
1223 (** [set_section s g] sets the linker section of the global value [g] to [s].
1224 See the method [llvm::GlobalValue::setSection]. *)
1225 val set_section : string -> llvalue -> unit
1227 (** [visibility g] returns the linker visibility of the global value [g].
1228 See the method [llvm::GlobalValue::getVisibility]. *)
1229 val visibility : llvalue -> Visibility.t
1231 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1232 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1233 val set_visibility : Visibility.t -> llvalue -> unit
1235 (** [alignment g] returns the required alignment of the global value [g].
1236 See the method [llvm::GlobalValue::getAlignment]. *)
1237 val alignment : llvalue -> int
1239 (** [set_alignment n g] sets the required alignment of the global value [g] to
1240 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1241 val set_alignment : int -> llvalue -> unit
1244 (** {7 Operations on global variables} *)
1246 (** [declare_global ty name m] returns a new global variable of type [ty] and
1247 with name [name] in module [m] in the default address space (0). If such a
1248 global variable already exists, it is returned. If the type of the existing
1249 global differs, then a bitcast to [ty] is returned. *)
1250 val declare_global : lltype -> string -> llmodule -> llvalue
1252 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1253 of type [ty] and with name [name] in module [m] in the address space
1254 [addrspace]. If such a global variable already exists, it is returned. If
1255 the type of the existing global differs, then a bitcast to [ty] is
1257 val declare_qualified_global : lltype -> string -> int -> llmodule -> llvalue
1259 (** [define_global name init m] returns a new global with name [name] and
1260 initializer [init] in module [m] in the default address space (0). If the
1261 named global already exists, it is renamed.
1262 See the constructor of [llvm::GlobalVariable]. *)
1263 val define_global : string -> llvalue -> llmodule -> llvalue
1265 (** [define_qualified_global name init addrspace m] returns a new global with
1266 name [name] and initializer [init] in module [m] in the address space
1267 [addrspace]. If the named global already exists, it is renamed.
1268 See the constructor of [llvm::GlobalVariable]. *)
1269 val define_qualified_global : string -> llvalue -> int -> llmodule -> llvalue
1271 (** [lookup_global name m] returns [Some g] if a global variable with name
1272 [name] exists in module [m]. If no such global exists, returns [None].
1273 See the [llvm::GlobalVariable] constructor. *)
1274 val lookup_global : string -> llmodule -> llvalue option
1276 (** [delete_global gv] destroys the global variable [gv].
1277 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1278 val delete_global : llvalue -> unit
1280 (** [global_begin m] returns the first position in the global variable list of
1281 the module [m]. [global_begin] and [global_succ] can be used to iterate
1282 over the global list in order.
1283 See the method [llvm::Module::global_begin]. *)
1284 val global_begin : llmodule -> (llmodule, llvalue) llpos
1286 (** [global_succ gv] returns the global variable list position succeeding
1288 See the method [llvm::Module::global_iterator::operator++]. *)
1289 val global_succ : llvalue -> (llmodule, llvalue) llpos
1291 (** [iter_globals f m] applies function [f] to each of the global variables of
1292 module [m] in order. Tail recursive. *)
1293 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1295 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1296 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1297 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1299 (** [global_end m] returns the last position in the global variable list of the
1300 module [m]. [global_end] and [global_pred] can be used to iterate over the
1301 global list in reverse.
1302 See the method [llvm::Module::global_end]. *)
1303 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1305 (** [global_pred gv] returns the global variable list position preceding
1307 See the method [llvm::Module::global_iterator::operator--]. *)
1308 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1310 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1311 of module [m] in reverse order. Tail recursive. *)
1312 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1314 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1315 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1316 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1318 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1319 constant. Returns [false] otherwise.
1320 See the method [llvm::GlobalVariable::isConstant]. *)
1321 val is_global_constant : llvalue -> bool
1323 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1324 [c] is [true] and not if [c] is [false].
1325 See the method [llvm::GlobalVariable::setConstant]. *)
1326 val set_global_constant : bool -> llvalue -> unit
1328 (** [global_initializer gv] returns the initializer for the global variable
1329 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1330 val global_initializer : llvalue -> llvalue
1332 (** [set_initializer c gv] sets the initializer for the global variable
1333 [gv] to the constant [c].
1334 See the method [llvm::GlobalVariable::setInitializer]. *)
1335 val set_initializer : llvalue -> llvalue -> unit
1337 (** [remove_initializer gv] unsets the initializer for the global variable
1339 See the method [llvm::GlobalVariable::setInitializer]. *)
1340 val remove_initializer : llvalue -> unit
1342 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1343 thread-local and [false] otherwise.
1344 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1345 val is_thread_local : llvalue -> bool
1347 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1348 [c] is [true] and not otherwise.
1349 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1350 val set_thread_local : bool -> llvalue -> unit
1352 (** [is_thread_local gv] returns the thread local mode of the global
1354 See the method [llvm::GlobalVariable::getThreadLocalMode]. *)
1355 val thread_local_mode : llvalue -> ThreadLocalMode.t
1357 (** [set_thread_local c gv] sets the thread local mode of the global
1359 See the method [llvm::GlobalVariable::setThreadLocalMode]. *)
1360 val set_thread_local_mode : ThreadLocalMode.t -> llvalue -> unit
1362 (** [is_externally_initialized gv] returns [true] if the global
1363 variable [gv] is externally initialized and [false] otherwise.
1364 See the method [llvm::GlobalVariable::isExternallyInitialized]. *)
1365 val is_externally_initialized : llvalue -> bool
1367 (** [set_externally_initialized c gv] sets the global variable [gv] to be
1368 externally initialized if [c] is [true] and not otherwise.
1369 See the method [llvm::GlobalVariable::setExternallyInitialized]. *)
1370 val set_externally_initialized : bool -> llvalue -> unit
1373 (** {7 Operations on aliases} *)
1375 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1376 the aliasee [a] with the name [n].
1377 See the constructor for [llvm::GlobalAlias]. *)
1378 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1381 (** {7 Operations on functions} *)
1383 (** [declare_function name ty m] returns a new function of type [ty] and
1384 with name [name] in module [m]. If such a function already exists,
1385 it is returned. If the type of the existing function differs, then a bitcast
1386 to [ty] is returned. *)
1387 val declare_function : string -> lltype -> llmodule -> llvalue
1389 (** [define_function name ty m] creates a new function with name [name] and
1390 type [ty] in module [m]. If the named function already exists, it is
1391 renamed. An entry basic block is created in the function.
1392 See the constructor of [llvm::GlobalVariable]. *)
1393 val define_function : string -> lltype -> llmodule -> llvalue
1395 (** [lookup_function name m] returns [Some f] if a function with name
1396 [name] exists in module [m]. If no such function exists, returns [None].
1397 See the method [llvm::Module] constructor. *)
1398 val lookup_function : string -> llmodule -> llvalue option
1400 (** [delete_function f] destroys the function [f].
1401 See the method [llvm::Function::eraseFromParent]. *)
1402 val delete_function : llvalue -> unit
1404 (** [function_begin m] returns the first position in the function list of the
1405 module [m]. [function_begin] and [function_succ] can be used to iterate over
1406 the function list in order.
1407 See the method [llvm::Module::begin]. *)
1408 val function_begin : llmodule -> (llmodule, llvalue) llpos
1410 (** [function_succ gv] returns the function list position succeeding
1412 See the method [llvm::Module::iterator::operator++]. *)
1413 val function_succ : llvalue -> (llmodule, llvalue) llpos
1415 (** [iter_functions f m] applies function [f] to each of the functions of module
1416 [m] in order. Tail recursive. *)
1417 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1419 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1420 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1421 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1423 (** [function_end m] returns the last position in the function list of
1424 the module [m]. [function_end] and [function_pred] can be used to iterate
1425 over the function list in reverse.
1426 See the method [llvm::Module::end]. *)
1427 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1429 (** [function_pred gv] returns the function list position preceding [After gv].
1430 See the method [llvm::Module::iterator::operator--]. *)
1431 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1433 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1434 module [m] in reverse order. Tail recursive. *)
1435 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1437 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1438 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1439 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1441 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1442 See the method [llvm::Function::isIntrinsic]. *)
1443 val is_intrinsic : llvalue -> bool
1445 (** [function_call_conv f] returns the calling convention of the function [f].
1446 See the method [llvm::Function::getCallingConv]. *)
1447 val function_call_conv : llvalue -> int
1449 (** [set_function_call_conv cc f] sets the calling convention of the function
1450 [f] to the calling convention numbered [cc].
1451 See the method [llvm::Function::setCallingConv]. *)
1452 val set_function_call_conv : int -> llvalue -> unit
1454 (** [gc f] returns [Some name] if the function [f] has a garbage
1455 collection algorithm specified and [None] otherwise.
1456 See the method [llvm::Function::getGC]. *)
1457 val gc : llvalue -> string option
1459 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1460 [gc]. See the method [llvm::Function::setGC]. *)
1461 val set_gc : string option -> llvalue -> unit
1463 (** [add_function_attr f a] adds attribute [a] to the return type of function
1465 val add_function_attr : llvalue -> Attribute.t -> unit
1467 (** [add_target_dependent_function_attr f a] adds target-dependent attribute
1468 [a] to function [f]. *)
1469 val add_target_dependent_function_attr : llvalue -> string -> string -> unit
1471 (** [function_attr f] returns the function attribute for the function [f].
1472 See the method [llvm::Function::getAttributes] *)
1473 val function_attr : llvalue -> Attribute.t list
1475 (** [remove_function_attr f a] removes attribute [a] from the return type of
1477 val remove_function_attr : llvalue -> Attribute.t -> unit
1480 (** {7 Operations on params} *)
1482 (** [params f] returns the parameters of function [f].
1483 See the method [llvm::Function::getArgumentList]. *)
1484 val params : llvalue -> llvalue array
1486 (** [param f n] returns the [n]th parameter of function [f].
1487 See the method [llvm::Function::getArgumentList]. *)
1488 val param : llvalue -> int -> llvalue
1490 (** [param_attr p] returns the attributes of parameter [p].
1491 See the methods [llvm::Function::getAttributes] and
1492 [llvm::Attributes::getParamAttributes] *)
1493 val param_attr : llvalue -> Attribute.t list
1495 (** [param_parent p] returns the parent function that owns the parameter.
1496 See the method [llvm::Argument::getParent]. *)
1497 val param_parent : llvalue -> llvalue
1499 (** [param_begin f] returns the first position in the parameter list of the
1500 function [f]. [param_begin] and [param_succ] can be used to iterate over
1501 the parameter list in order.
1502 See the method [llvm::Function::arg_begin]. *)
1503 val param_begin : llvalue -> (llvalue, llvalue) llpos
1505 (** [param_succ bb] returns the parameter list position succeeding
1507 See the method [llvm::Function::arg_iterator::operator++]. *)
1508 val param_succ : llvalue -> (llvalue, llvalue) llpos
1510 (** [iter_params f fn] applies function [f] to each of the parameters
1511 of function [fn] in order. Tail recursive. *)
1512 val iter_params : (llvalue -> unit) -> llvalue -> unit
1514 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1515 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1516 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1518 (** [param_end f] returns the last position in the parameter list of
1519 the function [f]. [param_end] and [param_pred] can be used to iterate
1520 over the parameter list in reverse.
1521 See the method [llvm::Function::arg_end]. *)
1522 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1524 (** [param_pred gv] returns the function list position preceding [After gv].
1525 See the method [llvm::Function::arg_iterator::operator--]. *)
1526 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1528 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1529 of function [fn] in reverse order. Tail recursive. *)
1530 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1532 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1533 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1534 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1536 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1537 val add_param_attr : llvalue -> Attribute.t -> unit
1539 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1540 val remove_param_attr : llvalue -> Attribute.t -> unit
1542 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1543 val set_param_alignment : llvalue -> int -> unit
1546 (** {7 Operations on basic blocks} *)
1548 (** [basic_blocks fn] returns the basic blocks of the function [f].
1549 See the method [llvm::Function::getBasicBlockList]. *)
1550 val basic_blocks : llvalue -> llbasicblock array
1552 (** [entry_block fn] returns the entry basic block of the function [f].
1553 See the method [llvm::Function::getEntryBlock]. *)
1554 val entry_block : llvalue -> llbasicblock
1556 (** [delete_block bb] deletes the basic block [bb].
1557 See the method [llvm::BasicBlock::eraseFromParent]. *)
1558 val delete_block : llbasicblock -> unit
1560 (** [remove_block bb] removes the basic block [bb] from its parent function.
1561 See the method [llvm::BasicBlock::removeFromParent]. *)
1562 val remove_block : llbasicblock -> unit
1564 (** [move_block_before pos bb] moves the basic block [bb] before [pos].
1565 See the method [llvm::BasicBlock::moveBefore]. *)
1566 val move_block_before : llbasicblock -> llbasicblock -> unit
1568 (** [move_block_after pos bb] moves the basic block [bb] after [pos].
1569 See the method [llvm::BasicBlock::moveAfter]. *)
1570 val move_block_after : llbasicblock -> llbasicblock -> unit
1572 (** [append_block c name f] creates a new basic block named [name] at the end of
1573 function [f] in the context [c].
1574 See the constructor of [llvm::BasicBlock]. *)
1575 val append_block : llcontext -> string -> llvalue -> llbasicblock
1577 (** [insert_block c name bb] creates a new basic block named [name] before the
1578 basic block [bb] in the context [c].
1579 See the constructor of [llvm::BasicBlock]. *)
1580 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1582 (** [block_parent bb] returns the parent function that owns the basic block.
1583 See the method [llvm::BasicBlock::getParent]. *)
1584 val block_parent : llbasicblock -> llvalue
1586 (** [block_begin f] returns the first position in the basic block list of the
1587 function [f]. [block_begin] and [block_succ] can be used to iterate over
1588 the basic block list in order.
1589 See the method [llvm::Function::begin]. *)
1590 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1592 (** [block_succ bb] returns the basic block list position succeeding
1594 See the method [llvm::Function::iterator::operator++]. *)
1595 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1597 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1598 of function [fn] in order. Tail recursive. *)
1599 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1601 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1602 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1603 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1605 (** [block_end f] returns the last position in the basic block list of
1606 the function [f]. [block_end] and [block_pred] can be used to iterate
1607 over the basic block list in reverse.
1608 See the method [llvm::Function::end]. *)
1609 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1611 (** [block_pred bb] returns the basic block list position preceding [After bb].
1612 See the method [llvm::Function::iterator::operator--]. *)
1613 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1615 (** [block_terminator bb] returns the terminator of the basic block [bb]. *)
1616 val block_terminator : llbasicblock -> llvalue option
1618 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1619 of function [fn] in reverse order. Tail recursive. *)
1620 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1622 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1623 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1624 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1626 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1627 val value_of_block : llbasicblock -> llvalue
1629 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1631 Similar to [llvm::isa<BasicBlock>]. *)
1632 val value_is_block : llvalue -> bool
1634 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1635 val block_of_value : llvalue -> llbasicblock
1638 (** {7 Operations on instructions} *)
1640 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1641 See the method [llvm::Instruction::getParent]. *)
1642 val instr_parent : llvalue -> llbasicblock
1644 (** [delete_instruction i] deletes the instruction [i].
1645 * See the method [llvm::Instruction::eraseFromParent]. *)
1646 val delete_instruction : llvalue -> unit
1648 (** [instr_begin bb] returns the first position in the instruction list of the
1649 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1650 the instruction list in order.
1651 See the method [llvm::BasicBlock::begin]. *)
1652 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1654 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1655 See the method [llvm::BasicBlock::iterator::operator++]. *)
1656 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1658 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1659 block [bb] in order. Tail recursive. *)
1660 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1662 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1663 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1664 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1666 (** [instr_end bb] returns the last position in the instruction list of the
1667 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1668 the instruction list in reverse.
1669 See the method [llvm::BasicBlock::end]. *)
1670 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1672 (** [instr_pred i] returns the instruction list position preceding [After i].
1673 See the method [llvm::BasicBlock::iterator::operator--]. *)
1674 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1676 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1677 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1678 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1680 (** [inst_opcode i] returns the [Opcode.t] corresponding to instruction [i],
1681 or [Opcode.Invalid] if [i] is not an instruction. *)
1682 val instr_opcode : llvalue -> Opcode.t
1684 (** [icmp_predicate i] returns the [Icmp.t] corresponding to an [icmp]
1686 val icmp_predicate : llvalue -> Icmp.t option
1689 (** {7 Operations on call sites} *)
1691 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1692 instruction [ci], which may be one of the values from the module
1693 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1694 [llvm::InvokeInst::getCallingConv]. *)
1695 val instruction_call_conv: llvalue -> int
1697 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1698 or invoke instruction [ci] to the integer [cc], which can be one of the
1699 values from the module {!CallConv}.
1700 See the method [llvm::CallInst::setCallingConv]
1701 and [llvm::InvokeInst::setCallingConv]. *)
1702 val set_instruction_call_conv: int -> llvalue -> unit
1704 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1705 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1707 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1709 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1710 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1712 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1715 (** {7 Operations on call instructions (only)} *)
1717 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1718 eligible for tail call optimization, [false] otherwise.
1719 See the method [llvm::CallInst::isTailCall]. *)
1720 val is_tail_call : llvalue -> bool
1722 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1723 call optimization if [tc] is [true], clears otherwise.
1724 See the method [llvm::CallInst::setTailCall]. *)
1725 val set_tail_call : bool -> llvalue -> unit
1728 (** {7 Operations on load/store instructions (only)} *)
1730 (** [is_volatile i] is [true] if the load or store instruction [i] is marked
1732 See the methods [llvm::LoadInst::isVolatile] and
1733 [llvm::StoreInst::isVolatile]. *)
1734 val is_volatile : llvalue -> bool
1736 (** [set_volatile v i] marks the load or store instruction [i] as volatile
1737 if [v] is [true], unmarks otherwise.
1738 See the methods [llvm::LoadInst::setVolatile] and
1739 [llvm::StoreInst::setVolatile]. *)
1740 val set_volatile : bool -> llvalue -> unit
1743 (** {7 Operations on phi nodes} *)
1745 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1746 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1747 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1749 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1750 See the method [llvm::PHINode::getIncomingValue]. *)
1751 val incoming : llvalue -> (llvalue * llbasicblock) list
1755 (** {6 Instruction builders} *)
1757 (** [builder context] creates an instruction builder with no position in
1758 the context [context]. It is invalid to use this builder until its position
1759 is set with {!position_before} or {!position_at_end}. See the constructor
1760 for [llvm::LLVMBuilder]. *)
1761 val builder : llcontext -> llbuilder
1763 (** [builder_at ip] creates an instruction builder positioned at [ip].
1764 See the constructor for [llvm::LLVMBuilder]. *)
1765 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1767 (** [builder_before ins] creates an instruction builder positioned before the
1768 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1769 val builder_before : llcontext -> llvalue -> llbuilder
1771 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1772 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1773 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1775 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1777 See the constructor for [llvm::LLVMBuilder]. *)
1778 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1780 (** [position_before ins b] moves the instruction builder [b] to before the
1781 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1782 val position_before : llvalue -> llbuilder -> unit
1784 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1785 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1786 val position_at_end : llbasicblock -> llbuilder -> unit
1788 (** [insertion_block b] returns the basic block that the builder [b] is
1789 positioned to insert into. Raises [Not_Found] if the instruction builder is
1791 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1792 val insertion_block : llbuilder -> llbasicblock
1794 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1795 position specified by the instruction builder [b].
1796 See the method [llvm::LLVMBuilder::Insert]. *)
1797 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1802 (** [set_current_debug_location b md] sets the current debug location [md] in
1804 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1805 val set_current_debug_location : llbuilder -> llvalue -> unit
1807 (** [clear_current_debug_location b] clears the current debug location in the
1809 val clear_current_debug_location : llbuilder -> unit
1811 (** [current_debug_location b] returns the current debug location, or None
1812 if none is currently set.
1813 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1814 val current_debug_location : llbuilder -> llvalue option
1816 (** [set_inst_debug_location b i] sets the current debug location of the builder
1817 [b] to the instruction [i].
1818 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1819 val set_inst_debug_location : llbuilder -> llvalue -> unit
1822 (** {7 Terminators} *)
1824 (** [build_ret_void b] creates a
1826 instruction at the position specified by the instruction builder [b].
1827 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1828 val build_ret_void : llbuilder -> llvalue
1830 (** [build_ret v b] creates a
1832 instruction at the position specified by the instruction builder [b].
1833 See the method [llvm::LLVMBuilder::CreateRet]. *)
1834 val build_ret : llvalue -> llbuilder -> llvalue
1836 (** [build_aggregate_ret vs b] creates a
1837 [ret {...} { %v1, %v2, ... } ]
1838 instruction at the position specified by the instruction builder [b].
1839 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1840 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1842 (** [build_br bb b] creates a
1844 instruction at the position specified by the instruction builder [b].
1845 See the method [llvm::LLVMBuilder::CreateBr]. *)
1846 val build_br : llbasicblock -> llbuilder -> llvalue
1848 (** [build_cond_br cond tbb fbb b] creates a
1849 [br %cond, %tbb, %fbb]
1850 instruction at the position specified by the instruction builder [b].
1851 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1852 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1855 (** [build_switch case elsebb count b] creates an empty
1856 [switch %case, %elsebb]
1857 instruction at the position specified by the instruction builder [b] with
1858 space reserved for [count] cases.
1859 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1860 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1862 (** [build_malloc ty name b] creates an [malloc]
1863 instruction at the position specified by the instruction builder [b].
1864 See the method [llvm::CallInst::CreateMalloc]. *)
1865 val build_malloc : lltype -> string -> llbuilder -> llvalue
1867 (** [build_array_malloc ty val name b] creates an [array malloc]
1868 instruction at the position specified by the instruction builder [b].
1869 See the method [llvm::CallInst::CreateArrayMalloc]. *)
1870 val build_array_malloc : lltype -> llvalue -> string -> llbuilder -> llvalue
1872 (** [build_free p b] creates a [free]
1873 instruction at the position specified by the instruction builder [b].
1874 See the method [llvm::LLVMBuilder::CreateFree]. *)
1875 val build_free : llvalue -> llbuilder -> llvalue
1877 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1878 when its input matches the constant [onval].
1879 See the method [llvm::SwitchInst::addCase]. **)
1880 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1882 (** [switch_default_dest sw] returns the default destination of the [switch]
1884 See the method [llvm:;SwitchInst::getDefaultDest]. **)
1885 val switch_default_dest : llvalue -> llbasicblock
1887 (** [build_indirect_br addr count b] creates a
1889 instruction at the position specified by the instruction builder [b] with
1890 space reserved for [count] destinations.
1891 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1892 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1894 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1895 location for the indirectbr instruction [br].
1896 See the method [llvm::IndirectBrInst::addDestination]. **)
1897 val add_destination : llvalue -> llbasicblock -> unit
1899 (** [build_invoke fn args tobb unwindbb name b] creates an
1900 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1901 instruction at the position specified by the instruction builder [b].
1902 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1903 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1904 llbasicblock -> string -> llbuilder -> llvalue
1906 (** [build_landingpad ty persfn numclauses name b] creates an
1908 instruction at the position specified by the instruction builder [b].
1909 See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
1910 val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
1913 (** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
1914 See the method [llvm::LandingPadInst::setCleanup]. *)
1915 val set_cleanup : llvalue -> bool -> unit
1917 (** [add_clause lp clause] adds the clause to the [landingpad]instruction.
1918 See the method [llvm::LandingPadInst::addClause]. *)
1919 val add_clause : llvalue -> llvalue -> unit
1921 (** [build_resume exn b] builds a [resume exn] instruction
1922 at the position specified by the instruction builder [b].
1923 See the method [llvm::LLVMBuilder::CreateResume] *)
1924 val build_resume : llvalue -> llbuilder -> llvalue
1926 (** [build_unreachable b] creates an
1928 instruction at the position specified by the instruction builder [b].
1929 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1930 val build_unreachable : llbuilder -> llvalue
1933 (** {7 Arithmetic} *)
1935 (** [build_add x y name b] creates a
1936 [%name = add %x, %y]
1937 instruction at the position specified by the instruction builder [b].
1938 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1939 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1941 (** [build_nsw_add x y name b] creates a
1942 [%name = nsw add %x, %y]
1943 instruction at the position specified by the instruction builder [b].
1944 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1945 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1947 (** [build_nuw_add x y name b] creates a
1948 [%name = nuw add %x, %y]
1949 instruction at the position specified by the instruction builder [b].
1950 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1951 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1953 (** [build_fadd x y name b] creates a
1954 [%name = fadd %x, %y]
1955 instruction at the position specified by the instruction builder [b].
1956 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1957 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1959 (** [build_sub x y name b] creates a
1960 [%name = sub %x, %y]
1961 instruction at the position specified by the instruction builder [b].
1962 See the method [llvm::LLVMBuilder::CreateSub]. *)
1963 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1965 (** [build_nsw_sub x y name b] creates a
1966 [%name = nsw sub %x, %y]
1967 instruction at the position specified by the instruction builder [b].
1968 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1969 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1971 (** [build_nuw_sub x y name b] creates a
1972 [%name = nuw sub %x, %y]
1973 instruction at the position specified by the instruction builder [b].
1974 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1975 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1977 (** [build_fsub x y name b] creates a
1978 [%name = fsub %x, %y]
1979 instruction at the position specified by the instruction builder [b].
1980 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1981 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1983 (** [build_mul x y name b] creates a
1984 [%name = mul %x, %y]
1985 instruction at the position specified by the instruction builder [b].
1986 See the method [llvm::LLVMBuilder::CreateMul]. *)
1987 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1989 (** [build_nsw_mul x y name b] creates a
1990 [%name = nsw mul %x, %y]
1991 instruction at the position specified by the instruction builder [b].
1992 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1993 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1995 (** [build_nuw_mul x y name b] creates a
1996 [%name = nuw mul %x, %y]
1997 instruction at the position specified by the instruction builder [b].
1998 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1999 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
2001 (** [build_fmul x y name b] creates a
2002 [%name = fmul %x, %y]
2003 instruction at the position specified by the instruction builder [b].
2004 See the method [llvm::LLVMBuilder::CreateFMul]. *)
2005 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
2007 (** [build_udiv x y name b] creates a
2008 [%name = udiv %x, %y]
2009 instruction at the position specified by the instruction builder [b].
2010 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
2011 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2013 (** [build_sdiv x y name b] creates a
2014 [%name = sdiv %x, %y]
2015 instruction at the position specified by the instruction builder [b].
2016 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
2017 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2019 (** [build_exact_sdiv x y name b] creates a
2020 [%name = exact sdiv %x, %y]
2021 instruction at the position specified by the instruction builder [b].
2022 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
2023 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2025 (** [build_fdiv x y name b] creates a
2026 [%name = fdiv %x, %y]
2027 instruction at the position specified by the instruction builder [b].
2028 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
2029 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
2031 (** [build_urem x y name b] creates a
2032 [%name = urem %x, %y]
2033 instruction at the position specified by the instruction builder [b].
2034 See the method [llvm::LLVMBuilder::CreateURem]. *)
2035 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2037 (** [build_SRem x y name b] creates a
2038 [%name = srem %x, %y]
2039 instruction at the position specified by the instruction builder [b].
2040 See the method [llvm::LLVMBuilder::CreateSRem]. *)
2041 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2043 (** [build_frem x y name b] creates a
2044 [%name = frem %x, %y]
2045 instruction at the position specified by the instruction builder [b].
2046 See the method [llvm::LLVMBuilder::CreateFRem]. *)
2047 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
2049 (** [build_shl x y name b] creates a
2050 [%name = shl %x, %y]
2051 instruction at the position specified by the instruction builder [b].
2052 See the method [llvm::LLVMBuilder::CreateShl]. *)
2053 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
2055 (** [build_lshr x y name b] creates a
2056 [%name = lshr %x, %y]
2057 instruction at the position specified by the instruction builder [b].
2058 See the method [llvm::LLVMBuilder::CreateLShr]. *)
2059 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
2061 (** [build_ashr x y name b] creates a
2062 [%name = ashr %x, %y]
2063 instruction at the position specified by the instruction builder [b].
2064 See the method [llvm::LLVMBuilder::CreateAShr]. *)
2065 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
2067 (** [build_and x y name b] creates a
2068 [%name = and %x, %y]
2069 instruction at the position specified by the instruction builder [b].
2070 See the method [llvm::LLVMBuilder::CreateAnd]. *)
2071 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
2073 (** [build_or x y name b] creates a
2075 instruction at the position specified by the instruction builder [b].
2076 See the method [llvm::LLVMBuilder::CreateOr]. *)
2077 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
2079 (** [build_xor x y name b] creates a
2080 [%name = xor %x, %y]
2081 instruction at the position specified by the instruction builder [b].
2082 See the method [llvm::LLVMBuilder::CreateXor]. *)
2083 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
2085 (** [build_neg x name b] creates a
2087 instruction at the position specified by the instruction builder [b].
2088 [-0.0] is used for floating point types to compute the correct sign.
2089 See the method [llvm::LLVMBuilder::CreateNeg]. *)
2090 val build_neg : llvalue -> string -> llbuilder -> llvalue
2092 (** [build_nsw_neg x name b] creates a
2093 [%name = nsw sub 0, %x]
2094 instruction at the position specified by the instruction builder [b].
2095 [-0.0] is used for floating point types to compute the correct sign.
2096 See the method [llvm::LLVMBuilder::CreateNeg]. *)
2097 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
2099 (** [build_nuw_neg x name b] creates a
2100 [%name = nuw sub 0, %x]
2101 instruction at the position specified by the instruction builder [b].
2102 [-0.0] is used for floating point types to compute the correct sign.
2103 See the method [llvm::LLVMBuilder::CreateNeg]. *)
2104 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
2106 (** [build_fneg x name b] creates a
2107 [%name = fsub 0, %x]
2108 instruction at the position specified by the instruction builder [b].
2109 [-0.0] is used for floating point types to compute the correct sign.
2110 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
2111 val build_fneg : llvalue -> string -> llbuilder -> llvalue
2113 (** [build_xor x name b] creates a
2114 [%name = xor %x, -1]
2115 instruction at the position specified by the instruction builder [b].
2116 [-1] is the correct "all ones" value for the type of [x].
2117 See the method [llvm::LLVMBuilder::CreateXor]. *)
2118 val build_not : llvalue -> string -> llbuilder -> llvalue
2123 (** [build_alloca ty name b] creates a
2124 [%name = alloca %ty]
2125 instruction at the position specified by the instruction builder [b].
2126 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2127 val build_alloca : lltype -> string -> llbuilder -> llvalue
2129 (** [build_array_alloca ty n name b] creates a
2130 [%name = alloca %ty, %n]
2131 instruction at the position specified by the instruction builder [b].
2132 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2133 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
2136 (** [build_load v name b] creates a
2138 instruction at the position specified by the instruction builder [b].
2139 See the method [llvm::LLVMBuilder::CreateLoad]. *)
2140 val build_load : llvalue -> string -> llbuilder -> llvalue
2142 (** [build_store v p b] creates a
2144 instruction at the position specified by the instruction builder [b].
2145 See the method [llvm::LLVMBuilder::CreateStore]. *)
2146 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
2148 (** [build_atomicrmw op ptr val o st b] creates an [atomicrmw] instruction with
2149 operation [op] performed on pointer [ptr] and value [val] with ordering [o]
2150 and singlethread flag set to [st] at the position specified by
2151 the instruction builder [b].
2152 See the method [llvm::IRBuilder::CreateAtomicRMW]. *)
2153 val build_atomicrmw : AtomicRMWBinOp.t -> llvalue -> llvalue ->
2154 AtomicOrdering.t -> bool -> string -> llbuilder -> llvalue
2156 (** [build_gep p indices name b] creates a
2157 [%name = getelementptr %p, indices...]
2158 instruction at the position specified by the instruction builder [b].
2159 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
2160 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2162 (** [build_in_bounds_gep p indices name b] creates a
2163 [%name = gelementptr inbounds %p, indices...]
2164 instruction at the position specified by the instruction builder [b].
2165 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
2166 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
2169 (** [build_struct_gep p idx name b] creates a
2170 [%name = getelementptr %p, 0, idx]
2171 instruction at the position specified by the instruction builder [b].
2172 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
2173 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
2176 (** [build_global_string str name b] creates a series of instructions that adds
2177 a global string at the position specified by the instruction builder [b].
2178 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
2179 val build_global_string : string -> string -> llbuilder -> llvalue
2181 (** [build_global_stringptr str name b] creates a series of instructions that
2182 adds a global string pointer at the position specified by the instruction
2184 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
2185 val build_global_stringptr : string -> string -> llbuilder -> llvalue
2190 (** [build_trunc v ty name b] creates a
2191 [%name = trunc %p to %ty]
2192 instruction at the position specified by the instruction builder [b].
2193 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
2194 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2196 (** [build_zext v ty name b] creates a
2197 [%name = zext %p to %ty]
2198 instruction at the position specified by the instruction builder [b].
2199 See the method [llvm::LLVMBuilder::CreateZExt]. *)
2200 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
2202 (** [build_sext v ty name b] creates a
2203 [%name = sext %p to %ty]
2204 instruction at the position specified by the instruction builder [b].
2205 See the method [llvm::LLVMBuilder::CreateSExt]. *)
2206 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
2208 (** [build_fptoui v ty name b] creates a
2209 [%name = fptoui %p to %ty]
2210 instruction at the position specified by the instruction builder [b].
2211 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
2212 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
2214 (** [build_fptosi v ty name b] creates a
2215 [%name = fptosi %p to %ty]
2216 instruction at the position specified by the instruction builder [b].
2217 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
2218 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
2220 (** [build_uitofp v ty name b] creates a
2221 [%name = uitofp %p to %ty]
2222 instruction at the position specified by the instruction builder [b].
2223 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
2224 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2226 (** [build_sitofp v ty name b] creates a
2227 [%name = sitofp %p to %ty]
2228 instruction at the position specified by the instruction builder [b].
2229 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
2230 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2232 (** [build_fptrunc v ty name b] creates a
2233 [%name = fptrunc %p to %ty]
2234 instruction at the position specified by the instruction builder [b].
2235 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
2236 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2238 (** [build_fpext v ty name b] creates a
2239 [%name = fpext %p to %ty]
2240 instruction at the position specified by the instruction builder [b].
2241 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
2242 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
2244 (** [build_ptrtoint v ty name b] creates a
2245 [%name = prtotint %p to %ty]
2246 instruction at the position specified by the instruction builder [b].
2247 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2248 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2250 (** [build_inttoptr v ty name b] creates a
2251 [%name = inttoptr %p to %ty]
2252 instruction at the position specified by the instruction builder [b].
2253 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2254 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2256 (** [build_bitcast v ty name b] creates a
2257 [%name = bitcast %p to %ty]
2258 instruction at the position specified by the instruction builder [b].
2259 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2260 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2262 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2263 instruction at the position specified by the instruction builder [b].
2264 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2265 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2268 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2269 instruction at the position specified by the instruction builder [b].
2270 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2271 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2274 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2275 instruction at the position specified by the instruction builder [b].
2276 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2277 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2280 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2281 instruction at the position specified by the instruction builder [b].
2282 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2283 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2285 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2286 instruction at the position specified by the instruction builder [b].
2287 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2288 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2290 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2291 instruction at the position specified by the instruction builder [b].
2292 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2293 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2296 (** {7 Comparisons} *)
2298 (** [build_icmp pred x y name b] creates a
2299 [%name = icmp %pred %x, %y]
2300 instruction at the position specified by the instruction builder [b].
2301 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2302 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2303 llbuilder -> llvalue
2305 (** [build_fcmp pred x y name b] creates a
2306 [%name = fcmp %pred %x, %y]
2307 instruction at the position specified by the instruction builder [b].
2308 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2309 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2310 llbuilder -> llvalue
2313 (** {7 Miscellaneous instructions} *)
2315 (** [build_phi incoming name b] creates a
2316 [%name = phi %incoming]
2317 instruction at the position specified by the instruction builder [b].
2318 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2319 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2320 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2323 (** [build_call fn args name b] creates a
2324 [%name = call %fn(args...)]
2325 instruction at the position specified by the instruction builder [b].
2326 See the method [llvm::LLVMBuilder::CreateCall]. *)
2327 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2329 (** [build_select cond thenv elsev name b] creates a
2330 [%name = select %cond, %thenv, %elsev]
2331 instruction at the position specified by the instruction builder [b].
2332 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2333 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2336 (** [build_va_arg valist argty name b] creates a
2337 [%name = va_arg %valist, %argty]
2338 instruction at the position specified by the instruction builder [b].
2339 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2340 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2342 (** [build_extractelement vec i name b] creates a
2343 [%name = extractelement %vec, %i]
2344 instruction at the position specified by the instruction builder [b].
2345 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2346 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2349 (** [build_insertelement vec elt i name b] creates a
2350 [%name = insertelement %vec, %elt, %i]
2351 instruction at the position specified by the instruction builder [b].
2352 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2353 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2354 llbuilder -> llvalue
2356 (** [build_shufflevector veca vecb mask name b] creates a
2357 [%name = shufflevector %veca, %vecb, %mask]
2358 instruction at the position specified by the instruction builder [b].
2359 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2360 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2361 llbuilder -> llvalue
2363 (** [build_extractvalue agg idx name b] creates a
2364 [%name = extractvalue %agg, %idx]
2365 instruction at the position specified by the instruction builder [b].
2366 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2367 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2370 (** [build_insertvalue agg val idx name b] creates a
2371 [%name = insertvalue %agg, %val, %idx]
2372 instruction at the position specified by the instruction builder [b].
2373 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2374 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2377 (** [build_is_null val name b] creates a
2378 [%name = icmp eq %val, null]
2379 instruction at the position specified by the instruction builder [b].
2380 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2381 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2383 (** [build_is_not_null val name b] creates a
2384 [%name = icmp ne %val, null]
2385 instruction at the position specified by the instruction builder [b].
2386 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2387 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2389 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2390 the difference between two pointer values at the position specified by the
2391 instruction builder [b].
2392 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2393 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2396 (** {6 Memory buffers} *)
2398 module MemoryBuffer : sig
2399 (** [of_file p] is the memory buffer containing the contents of the file at
2400 path [p]. If the file could not be read, then [IoError msg] is
2402 val of_file : string -> llmemorybuffer
2404 (** [of_stdin ()] is the memory buffer containing the contents of standard input.
2405 If standard input is empty, then [IoError msg] is raised. *)
2406 val of_stdin : unit -> llmemorybuffer
2408 (** [of_string ~name s] is the memory buffer containing the contents of string [s].
2409 The name of memory buffer is set to [name] if it is provided. *)
2410 val of_string : ?name:string -> string -> llmemorybuffer
2412 (** [as_string mb] is the string containing the contents of memory buffer [mb]. *)
2413 val as_string : llmemorybuffer -> string
2415 (** Disposes of a memory buffer. *)
2416 val dispose : llmemorybuffer -> unit
2420 (** {6 Pass Managers} *)
2422 module PassManager : sig
2425 type any = [ `Module | `Function ]
2427 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2428 type of pipeline is suitable for link-time optimization and whole-module
2430 See the constructor of [llvm::PassManager]. *)
2431 val create : unit -> [ `Module ] t
2433 (** [PassManager.create_function m] constructs a new function-by-function
2434 pass pipeline over the module [m]. It does not take ownership of [m].
2435 This type of pipeline is suitable for code generation and JIT compilation
2437 See the constructor of [llvm::FunctionPassManager]. *)
2438 val create_function : llmodule -> [ `Function ] t
2440 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2441 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2442 any of the passes modified the module, [false] otherwise.
2443 See the [llvm::PassManager::run] method. *)
2444 val run_module : llmodule -> [ `Module ] t -> bool
2446 (** [initialize fpm] initializes all of the function passes scheduled in the
2447 function pass manager [fpm]. Returns [true] if any of the passes modified
2448 the module, [false] otherwise.
2449 See the [llvm::FunctionPassManager::doInitialization] method. *)
2450 val initialize : [ `Function ] t -> bool
2452 (** [run_function f fpm] executes all of the function passes scheduled in the
2453 function pass manager [fpm] over the function [f]. Returns [true] if any
2454 of the passes modified [f], [false] otherwise.
2455 See the [llvm::FunctionPassManager::run] method. *)
2456 val run_function : llvalue -> [ `Function ] t -> bool
2458 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2459 function pass manager [fpm]. Returns [true] if any of the passes
2460 modified the module, [false] otherwise.
2461 See the [llvm::FunctionPassManager::doFinalization] method. *)
2462 val finalize : [ `Function ] t -> bool
2464 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2466 See the destructor of [llvm::BasePassManager]. *)
2467 val dispose : [< any ] t -> unit