1 (*===-- llvm/llvm.mli - LLVM OCaml Interface ------------------------------===*
3 * The LLVM Compiler Infrastructure
5 * This file is distributed under the University of Illinois Open Source
6 * License. See LICENSE.TXT for details.
8 *===----------------------------------------------------------------------===*)
12 This interface provides an OCaml API for the LLVM intermediate
13 representation, the classes in the VMCore library. *)
16 (** {6 Abstract types}
18 These abstract types correlate directly to the LLVM VMCore classes. *)
20 (** The top-level container for all LLVM global data. See the
21 [llvm::LLVMContext] class. *)
24 (** The top-level container for all other LLVM Intermediate Representation (IR)
25 objects. See the [llvm::Module] class. *)
28 (** Each value in the LLVM IR has a type, an instance of [lltype]. See the
29 [llvm::Type] class. *)
32 (** Any value in the LLVM IR. Functions, instructions, global variables,
33 constants, and much more are all [llvalues]. See the [llvm::Value] class.
34 This type covers a wide range of subclasses. *)
37 (** Used to store users and usees of values. See the [llvm::Use] class. *)
40 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *)
43 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
47 (** Used to efficiently handle large buffers of read-only binary data.
48 See the [llvm::MemoryBuffer] class. *)
51 (** The kind of an [lltype], the result of [classify_type ty]. See the
52 [llvm::Type::TypeID] enumeration. *)
72 (** The linkage of a global value, accessed with {!linkage} and
73 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
77 | Available_externally
93 (** The linker visibility of a global value, accessed with {!visibility} and
94 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
95 module Visibility : sig
102 (** The following calling convention values may be accessed with
103 {!function_call_conv} and {!set_function_call_conv}. Calling
104 conventions are open-ended. *)
105 module CallConv : sig
106 val c : int (** [c] is the C calling convention. *)
107 val fast : int (** [fast] is the calling convention to allow LLVM
108 maximum optimization opportunities. Use only with
110 val cold : int (** [cold] is the calling convention for
112 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling
113 convention from C. *)
114 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
115 convention from C. *)
118 module Attribute : sig
142 | Stackalignment of int
148 (** The predicate for an integer comparison ([icmp]) instruction.
149 See the [llvm::ICmpInst::Predicate] enumeration. *)
164 (** The predicate for a floating-point comparison ([fcmp]) instruction.
165 See the [llvm::FCmpInst::Predicate] enumeration. *)
186 (** The opcodes for LLVM instructions and constant expressions. *)
189 | Invalid (* not an instruction *)
190 (* Terminator Instructions *)
198 (* Standard Binary Operators *)
211 (* Logical Operators *)
218 (* Memory Operators *)
236 (* Other Operators *)
258 (** The kind of an [llvalue], the result of [classify_value v].
259 See the various [LLVMIsA*] functions. *)
260 module ValueKind : sig
269 | ConstantAggregateZero
274 | ConstantPointerNull
281 | Instruction of Opcode.t
287 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
288 of [a]. [llpos] is used to specify positions in and for forward iteration
289 through the various value lists maintained by the LLVM IR. *)
290 type ('a, 'b) llpos =
294 (** [After b] and [At_start a] specify positions from the end of the ['b] list
295 of [a]. [llrev_pos] is used for reverse iteration through the various value
296 lists maintained by the LLVM IR. *)
297 type ('a, 'b) llrev_pos =
302 (** {6 Exceptions} *)
304 exception IoError of string
309 (** [create_context ()] creates a context for storing the "global" state in
310 LLVM. See the constructor [llvm::LLVMContext]. *)
311 val create_context : unit -> llcontext
313 (** [destroy_context ()] destroys a context. See the destructor
314 [llvm::LLVMContext::~LLVMContext]. *)
315 val dispose_context : llcontext -> unit
317 (** See the function [llvm::getGlobalContext]. *)
318 val global_context : unit -> llcontext
320 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
321 name [name] in the context [context]. See the function
322 [llvm::LLVMContext::getMDKindID]. *)
323 val mdkind_id : llcontext -> string -> int
328 (** [create_module context id] creates a module with the supplied module ID in
329 the context [context]. Modules are not garbage collected; it is mandatory
330 to call {!dispose_module} to free memory. See the constructor
331 [llvm::Module::Module]. *)
332 val create_module : llcontext -> string -> llmodule
334 (** [dispose_module m] destroys a module [m] and all of the IR objects it
335 contained. All references to subordinate objects are invalidated;
336 referencing them will invoke undefined behavior. See the destructor
337 [llvm::Module::~Module]. *)
338 val dispose_module : llmodule -> unit
340 (** [target_triple m] is the target specifier for the module [m], something like
341 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
342 val target_triple: llmodule -> string
344 (** [target_triple triple m] changes the target specifier for the module [m] to
345 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
346 val set_target_triple: string -> llmodule -> unit
348 (** [data_layout m] is the data layout specifier for the module [m], something
349 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
350 method [llvm::Module::getDataLayout]. *)
351 val data_layout: llmodule -> string
353 (** [set_data_layout s m] changes the data layout specifier for the module [m]
354 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
355 val set_data_layout: string -> llmodule -> unit
357 (** [dump_module m] prints the .ll representation of the module [m] to standard
358 error. See the method [llvm::Module::dump]. *)
359 val dump_module : llmodule -> unit
361 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
362 the method [llvm::Module::setModuleInlineAsm]. *)
363 val set_module_inline_asm : llmodule -> string -> unit
365 (** [module_context m] returns the context of the specified module.
366 See the method [llvm::Module::getContext] *)
367 val module_context : llmodule -> llcontext
372 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
373 See the method [llvm::Type::getTypeID]. *)
374 val classify_type : lltype -> TypeKind.t
376 (** [type_is_sized ty] returns whether the type has a size or not.
377 If it doesn't then it is not safe to call the [DataLayout::] methods on it.
379 val type_is_sized : lltype -> bool
381 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
382 See the method [llvm::Type::getContext]. *)
383 val type_context : lltype -> llcontext
385 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
386 val string_of_lltype : lltype -> string
389 (** {7 Operations on integer types} *)
391 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
392 [llvm::Type::Int1Ty]. *)
393 val i1_type : llcontext -> lltype
395 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
396 [llvm::Type::Int8Ty]. *)
397 val i8_type : llcontext -> lltype
399 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
400 [llvm::Type::Int16Ty]. *)
401 val i16_type : llcontext -> lltype
403 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
404 [llvm::Type::Int32Ty]. *)
405 val i32_type : llcontext -> lltype
407 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
408 [llvm::Type::Int64Ty]. *)
409 val i64_type : llcontext -> lltype
411 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
412 [c]. See the method [llvm::IntegerType::get]. *)
413 val integer_type : llcontext -> int -> lltype
415 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
416 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
417 val integer_bitwidth : lltype -> int
420 (** {7 Operations on real types} *)
422 (** [float_type c] returns the IEEE 32-bit floating point type in the context
423 [c]. See [llvm::Type::FloatTy]. *)
424 val float_type : llcontext -> lltype
426 (** [double_type c] returns the IEEE 64-bit floating point type in the context
427 [c]. See [llvm::Type::DoubleTy]. *)
428 val double_type : llcontext -> lltype
430 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
431 [c]. See [llvm::Type::X86_FP80Ty]. *)
432 val x86fp80_type : llcontext -> lltype
434 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
435 [c]. See [llvm::Type::FP128Ty]. *)
436 val fp128_type : llcontext -> lltype
438 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
439 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
440 val ppc_fp128_type : llcontext -> lltype
443 (** {7 Operations on function types} *)
445 (** [function_type ret_ty param_tys] returns the function type returning
446 [ret_ty] and taking [param_tys] as parameters.
447 See the method [llvm::FunctionType::get]. *)
448 val function_type : lltype -> lltype array -> lltype
450 (** [var_arg_function_type ret_ty param_tys] is just like
451 [function_type ret_ty param_tys] except that it returns the function type
452 which also takes a variable number of arguments.
453 See the method [llvm::FunctionType::get]. *)
454 val var_arg_function_type : lltype -> lltype array -> lltype
456 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
457 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
458 val is_var_arg : lltype -> bool
460 (** [return_type fty] gets the return type of the function type [fty].
461 See the method [llvm::FunctionType::getReturnType]. *)
462 val return_type : lltype -> lltype
464 (** [param_types fty] gets the parameter types of the function type [fty].
465 See the method [llvm::FunctionType::getParamType]. *)
466 val param_types : lltype -> lltype array
469 (** {7 Operations on struct types} *)
471 (** [struct_type context tys] returns the structure type in the context
472 [context] containing in the types in the array [tys]. See the method
473 [llvm::StructType::get]. *)
474 val struct_type : llcontext -> lltype array -> lltype
476 (** [packed_struct_type context ys] returns the packed structure type in the
477 context [context] containing in the types in the array [tys]. See the method
478 [llvm::StructType::get]. *)
479 val packed_struct_type : llcontext -> lltype array -> lltype
481 (** [struct_name ty] returns the name of the named structure type [ty],
482 or None if the structure type is not named *)
483 val struct_name : lltype -> string option
485 (** [named_struct_type context name] returns the named structure type [name]
486 in the context [context].
487 See the method [llvm::StructType::get]. *)
488 val named_struct_type : llcontext -> string -> lltype
490 (** [struct_set_body ty elts ispacked] sets the body of the named struct [ty]
491 to the [elts] elements.
492 See the moethd [llvm::StructType::setBody]. *)
493 val struct_set_body : lltype -> lltype array -> bool -> unit
495 (** [struct_element_types sty] returns the constituent types of the struct type
496 [sty]. See the method [llvm::StructType::getElementType]. *)
497 val struct_element_types : lltype -> lltype array
499 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
500 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
501 val is_packed : lltype -> bool
503 (** [is_opaque sty] returns [true] if the structure type [sty] is opaque.
504 [false] otherwise. See the method [llvm::StructType::isOpaque]. *)
505 val is_opaque : lltype -> bool
508 (** {7 Operations on pointer, vector, and array types} *)
510 (** [array_type ty n] returns the array type containing [n] elements of type
511 [ty]. See the method [llvm::ArrayType::get]. *)
512 val array_type : lltype -> int -> lltype
514 (** [pointer_type ty] returns the pointer type referencing objects of type
515 [ty] in the default address space (0).
516 See the method [llvm::PointerType::getUnqual]. *)
517 val pointer_type : lltype -> lltype
519 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
520 of type [ty] in address space [as].
521 See the method [llvm::PointerType::get]. *)
522 val qualified_pointer_type : lltype -> int -> lltype
524 (** [vector_type ty n] returns the array type containing [n] elements of the
525 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
526 val vector_type : lltype -> int -> lltype
528 (** [element_type ty] returns the element type of the pointer, vector, or array
529 type [ty]. See the method [llvm::SequentialType::get]. *)
530 val element_type : lltype -> lltype
532 (** [element_type aty] returns the element count of the array type [aty].
533 See the method [llvm::ArrayType::getNumElements]. *)
534 val array_length : lltype -> int
536 (** [address_space pty] returns the address space qualifier of the pointer type
537 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
538 val address_space : lltype -> int
540 (** [element_type ty] returns the element count of the vector type [ty].
541 See the method [llvm::VectorType::getNumElements]. *)
542 val vector_size : lltype -> int
545 (** {7 Operations on other types} *)
547 (** [void_type c] creates a type of a function which does not return any
548 value in the context [c]. See [llvm::Type::VoidTy]. *)
549 val void_type : llcontext -> lltype
551 (** [label_type c] creates a type of a basic block in the context [c]. See
552 [llvm::Type::LabelTy]. *)
553 val label_type : llcontext -> lltype
555 (** [type_by_name m name] returns the specified type from the current module
557 See the method [llvm::Module::getTypeByName] *)
558 val type_by_name : llmodule -> string -> lltype option
563 (** [type_of v] returns the type of the value [v].
564 See the method [llvm::Value::getType]. *)
565 val type_of : llvalue -> lltype
567 val classify_value : llvalue -> ValueKind.t
569 (** [value_name v] returns the name of the value [v]. For global values, this is
570 the symbol name. For instructions and basic blocks, it is the SSA register
571 name. It is meaningless for constants.
572 See the method [llvm::Value::getName]. *)
573 val value_name : llvalue -> string
575 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
576 [llvm::Value::setName]. *)
577 val set_value_name : string -> llvalue -> unit
579 (** [dump_value v] prints the .ll representation of the value [v] to standard
580 error. See the method [llvm::Value::dump]. *)
581 val dump_value : llvalue -> unit
583 (** [replace_all_uses_with old new] replaces all uses of the value [old]
584 with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
585 val replace_all_uses_with : llvalue -> llvalue -> unit
590 (** [use_begin v] returns the first position in the use list for the value [v].
591 [use_begin] and [use_succ] can e used to iterate over the use list in order.
592 See the method [llvm::Value::use_begin]. *)
593 val use_begin : llvalue -> lluse option
595 (** [use_succ u] returns the use list position succeeding [u].
596 See the method [llvm::use_value_iterator::operator++]. *)
597 val use_succ : lluse -> lluse option
599 (** [user u] returns the user of the use [u].
600 See the method [llvm::Use::getUser]. *)
601 val user : lluse -> llvalue
603 (** [used_value u] returns the usee of the use [u].
604 See the method [llvm::Use::getUsedValue]. *)
605 val used_value : lluse -> llvalue
607 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
608 in order. Tail recursive. *)
609 val iter_uses : (lluse -> unit) -> llvalue -> unit
611 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
612 [u1,...,uN] are the users of the value [v]. Tail recursive. *)
613 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
615 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
616 [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
617 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
622 (** [operand v i] returns the operand at index [i] for the value [v]. See the
623 method [llvm::User::getOperand]. *)
624 val operand : llvalue -> int -> llvalue
626 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
628 See the method [llvm::User::setOperand]. *)
629 val set_operand : llvalue -> int -> llvalue -> unit
631 (** [num_operands v] returns the number of operands for the value [v].
632 See the method [llvm::User::getNumOperands]. *)
633 val num_operands : llvalue -> int
636 (** {7 Operations on constants of (mostly) any type} *)
638 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
639 otherwise. Similar to [llvm::isa<Constant>]. *)
640 val is_constant : llvalue -> bool
642 (** [const_null ty] returns the constant null (zero) of the type [ty].
643 See the method [llvm::Constant::getNullValue]. *)
644 val const_null : lltype -> llvalue
646 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
647 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
648 val const_all_ones : (*int|vec*)lltype -> llvalue
650 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
651 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
652 val const_pointer_null : lltype -> llvalue
654 (** [undef ty] returns the undefined value of the type [ty].
655 See the method [llvm::UndefValue::get]. *)
656 val undef : lltype -> llvalue
658 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
659 See the method [llvm::Constant::isNullValue]. *)
660 val is_null : llvalue -> bool
662 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
663 otherwise. Similar to [llvm::isa<UndefValue>]. *)
664 val is_undef : llvalue -> bool
666 val constexpr_opcode : llvalue -> Opcode.t
669 (** {7 Operations on instructions} *)
671 (** [has_metadata i] returns whether or not the instruction [i] has any
672 metadata attached to it. See the function
673 [llvm::Instruction::hasMetadata]. *)
674 val has_metadata : llvalue -> bool
676 (** [metadata i kind] optionally returns the metadata associated with the
677 kind [kind] in the instruction [i] See the function
678 [llvm::Instruction::getMetadata]. *)
679 val metadata : llvalue -> int -> llvalue option
681 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
682 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
683 val set_metadata : llvalue -> int -> llvalue -> unit
685 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
686 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
687 val clear_metadata : llvalue -> int -> unit
690 (** {7 Operations on metadata} *)
692 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
693 See the method [llvm::MDNode::get]. *)
694 val mdstring : llcontext -> string -> llvalue
696 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
698 See the method [llvm::MDNode::get]. *)
699 val mdnode : llcontext -> llvalue array -> llvalue
701 (** [get_mdstring v] returns the MDString.
702 See the method [llvm::MDString::getString] *)
703 val get_mdstring : llvalue -> string option
705 (** [get_named_metadata m name] return all the MDNodes belonging to the named
707 See the method [llvm::NamedMDNode::getOperand]. *)
708 val get_named_metadata : llmodule -> string -> llvalue array
711 (** {7 Operations on scalar constants} *)
713 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
714 See the method [llvm::ConstantInt::get]. *)
715 val const_int : lltype -> int -> llvalue
717 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
718 [i]. See the method [llvm::ConstantInt::get]. *)
719 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
721 (** [int64_of_const c] returns the int64 value of the [c] constant integer.
722 None is returned if this is not an integer constant, or bitwidth exceeds 64.
723 See the method [llvm::ConstantInt::getSExtValue].*)
724 val int64_of_const : llvalue -> Int64.t option
726 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
727 value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
728 val const_int_of_string : lltype -> string -> int -> llvalue
730 (** [const_float ty n] returns the floating point constant of type [ty] and
731 value [n]. See the method [llvm::ConstantFP::get]. *)
732 val const_float : lltype -> float -> llvalue
734 (** [const_float_of_string ty s] returns the floating point constant of type
735 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
736 val const_float_of_string : lltype -> string -> llvalue
739 (** {7 Operations on composite constants} *)
741 (** [const_string c s] returns the constant [i8] array with the values of the
742 characters in the string [s] in the context [c]. The array is not
743 null-terminated (but see {!const_stringz}). This value can in turn be used
744 as the initializer for a global variable. See the method
745 [llvm::ConstantArray::get]. *)
746 val const_string : llcontext -> string -> llvalue
748 (** [const_stringz c s] returns the constant [i8] array with the values of the
749 characters in the string [s] and a null terminator in the context [c]. This
750 value can in turn be used as the initializer for a global variable.
751 See the method [llvm::ConstantArray::get]. *)
752 val const_stringz : llcontext -> string -> llvalue
754 (** [const_array ty elts] returns the constant array of type
755 [array_type ty (Array.length elts)] and containing the values [elts].
756 This value can in turn be used as the initializer for a global variable.
757 See the method [llvm::ConstantArray::get]. *)
758 val const_array : lltype -> llvalue array -> llvalue
760 (** [const_struct context elts] returns the structured constant of type
761 [struct_type (Array.map type_of elts)] and containing the values [elts]
762 in the context [context]. This value can in turn be used as the initializer
763 for a global variable. See the method [llvm::ConstantStruct::getAnon]. *)
764 val const_struct : llcontext -> llvalue array -> llvalue
766 (** [const_named_struct namedty elts] returns the structured constant of type
767 [namedty] (which must be a named structure type) and containing the values [elts].
768 This value can in turn be used as the initializer
769 for a global variable. See the method [llvm::ConstantStruct::get]. *)
770 val const_named_struct : lltype -> llvalue array -> llvalue
772 (** [const_packed_struct context elts] returns the structured constant of
773 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
774 values [elts] in the context [context]. This value can in turn be used as
775 the initializer for a global variable. See the method
776 [llvm::ConstantStruct::get]. *)
777 val const_packed_struct : llcontext -> llvalue array -> llvalue
779 (** [const_vector elts] returns the vector constant of type
780 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
781 values [elts]. See the method [llvm::ConstantVector::get]. *)
782 val const_vector : llvalue array -> llvalue
785 (** {7 Constant expressions} *)
787 (** [align_of ty] returns the alignof constant for the type [ty]. This is
788 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
789 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
790 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
791 val align_of : lltype -> llvalue
793 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
794 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
795 (const_int i32_type 1)) i64_type], but considerably more readable.
796 See the method [llvm::ConstantExpr::getSizeOf]. *)
797 val size_of : lltype -> llvalue
799 (** [const_neg c] returns the arithmetic negation of the constant [c].
800 See the method [llvm::ConstantExpr::getNeg]. *)
801 val const_neg : llvalue -> llvalue
803 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
804 no signed wrapping. The result is undefined if the negation overflows.
805 See the method [llvm::ConstantExpr::getNSWNeg]. *)
806 val const_nsw_neg : llvalue -> llvalue
808 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
809 no unsigned wrapping. The result is undefined if the negation overflows.
810 See the method [llvm::ConstantExpr::getNUWNeg]. *)
811 val const_nuw_neg : llvalue -> llvalue
813 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
814 See the method [llvm::ConstantExpr::getFNeg]. *)
815 val const_fneg : llvalue -> llvalue
817 (** [const_not c] returns the bitwise inverse of the constant [c].
818 See the method [llvm::ConstantExpr::getNot]. *)
819 val const_not : llvalue -> llvalue
821 (** [const_add c1 c2] returns the constant sum of two constants.
822 See the method [llvm::ConstantExpr::getAdd]. *)
823 val const_add : llvalue -> llvalue -> llvalue
825 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
826 signed wrapping. The result is undefined if the sum overflows.
827 See the method [llvm::ConstantExpr::getNSWAdd]. *)
828 val const_nsw_add : llvalue -> llvalue -> llvalue
830 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
831 unsigned wrapping. The result is undefined if the sum overflows.
832 See the method [llvm::ConstantExpr::getNSWAdd]. *)
833 val const_nuw_add : llvalue -> llvalue -> llvalue
835 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
836 See the method [llvm::ConstantExpr::getFAdd]. *)
837 val const_fadd : llvalue -> llvalue -> llvalue
839 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
840 constants. See the method [llvm::ConstantExpr::getSub]. *)
841 val const_sub : llvalue -> llvalue -> llvalue
843 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
844 no signed wrapping. The result is undefined if the sum overflows.
845 See the method [llvm::ConstantExpr::getNSWSub]. *)
846 val const_nsw_sub : llvalue -> llvalue -> llvalue
848 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
849 no unsigned wrapping. The result is undefined if the sum overflows.
850 See the method [llvm::ConstantExpr::getNSWSub]. *)
851 val const_nuw_sub : llvalue -> llvalue -> llvalue
853 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
854 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
855 val const_fsub : llvalue -> llvalue -> llvalue
857 (** [const_mul c1 c2] returns the constant product of two constants.
858 See the method [llvm::ConstantExpr::getMul]. *)
859 val const_mul : llvalue -> llvalue -> llvalue
861 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
862 no signed wrapping. The result is undefined if the sum overflows.
863 See the method [llvm::ConstantExpr::getNSWMul]. *)
864 val const_nsw_mul : llvalue -> llvalue -> llvalue
866 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
867 no unsigned wrapping. The result is undefined if the sum overflows.
868 See the method [llvm::ConstantExpr::getNSWMul]. *)
869 val const_nuw_mul : llvalue -> llvalue -> llvalue
871 (** [const_fmul c1 c2] returns the constant product of two constants floats.
872 See the method [llvm::ConstantExpr::getFMul]. *)
873 val const_fmul : llvalue -> llvalue -> llvalue
875 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
877 See the method [llvm::ConstantExpr::getUDiv]. *)
878 val const_udiv : llvalue -> llvalue -> llvalue
880 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
882 See the method [llvm::ConstantExpr::getSDiv]. *)
883 val const_sdiv : llvalue -> llvalue -> llvalue
885 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
886 signed integer constants. The result is undefined if the result is rounded
887 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
888 val const_exact_sdiv : llvalue -> llvalue -> llvalue
890 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
892 See the method [llvm::ConstantExpr::getFDiv]. *)
893 val const_fdiv : llvalue -> llvalue -> llvalue
895 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
896 unsigned integer constants.
897 See the method [llvm::ConstantExpr::getURem]. *)
898 val const_urem : llvalue -> llvalue -> llvalue
900 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
901 signed integer constants.
902 See the method [llvm::ConstantExpr::getSRem]. *)
903 val const_srem : llvalue -> llvalue -> llvalue
905 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
906 signed floating point constants.
907 See the method [llvm::ConstantExpr::getFRem]. *)
908 val const_frem : llvalue -> llvalue -> llvalue
910 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
912 See the method [llvm::ConstantExpr::getAnd]. *)
913 val const_and : llvalue -> llvalue -> llvalue
915 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
917 See the method [llvm::ConstantExpr::getOr]. *)
918 val const_or : llvalue -> llvalue -> llvalue
920 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
922 See the method [llvm::ConstantExpr::getXor]. *)
923 val const_xor : llvalue -> llvalue -> llvalue
925 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
926 constants, [c1 pred c2].
927 See the method [llvm::ConstantExpr::getICmp]. *)
928 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
930 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
931 point constants, [c1 pred c2].
932 See the method [llvm::ConstantExpr::getFCmp]. *)
933 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
935 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
936 constant integer [c2].
937 See the method [llvm::ConstantExpr::getShl]. *)
938 val const_shl : llvalue -> llvalue -> llvalue
940 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
941 constant integer [c2] with zero extension.
942 See the method [llvm::ConstantExpr::getLShr]. *)
943 val const_lshr : llvalue -> llvalue -> llvalue
945 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
946 constant integer [c2] with sign extension.
947 See the method [llvm::ConstantExpr::getAShr]. *)
948 val const_ashr : llvalue -> llvalue -> llvalue
950 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
951 constant integers indices from the array [indices].
952 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
953 val const_gep : llvalue -> llvalue array -> llvalue
955 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
956 with the constant integers indices from the array [indices].
957 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
958 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
960 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
961 to the smaller integer type [ty].
962 See the method [llvm::ConstantExpr::getTrunc]. *)
963 val const_trunc : llvalue -> lltype -> llvalue
965 (** [const_sext c ty] returns the constant sign extension of integer constant
966 [c] to the larger integer type [ty].
967 See the method [llvm::ConstantExpr::getSExt]. *)
968 val const_sext : llvalue -> lltype -> llvalue
970 (** [const_zext c ty] returns the constant zero extension of integer constant
971 [c] to the larger integer type [ty].
972 See the method [llvm::ConstantExpr::getZExt]. *)
973 val const_zext : llvalue -> lltype -> llvalue
975 (** [const_fptrunc c ty] returns the constant truncation of floating point
976 constant [c] to the smaller floating point type [ty].
977 See the method [llvm::ConstantExpr::getFPTrunc]. *)
978 val const_fptrunc : llvalue -> lltype -> llvalue
980 (** [const_fpext c ty] returns the constant extension of floating point constant
981 [c] to the larger floating point type [ty].
982 See the method [llvm::ConstantExpr::getFPExt]. *)
983 val const_fpext : llvalue -> lltype -> llvalue
985 (** [const_uitofp c ty] returns the constant floating point conversion of
986 unsigned integer constant [c] to the floating point type [ty].
987 See the method [llvm::ConstantExpr::getUIToFP]. *)
988 val const_uitofp : llvalue -> lltype -> llvalue
990 (** [const_sitofp c ty] returns the constant floating point conversion of
991 signed integer constant [c] to the floating point type [ty].
992 See the method [llvm::ConstantExpr::getSIToFP]. *)
993 val const_sitofp : llvalue -> lltype -> llvalue
995 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
996 floating point constant [c] to integer type [ty].
997 See the method [llvm::ConstantExpr::getFPToUI]. *)
998 val const_fptoui : llvalue -> lltype -> llvalue
1000 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
1001 floating point constant [c] to integer type [ty].
1002 See the method [llvm::ConstantExpr::getFPToSI]. *)
1003 val const_fptosi : llvalue -> lltype -> llvalue
1005 (** [const_ptrtoint c ty] returns the constant integer conversion of
1006 pointer constant [c] to integer type [ty].
1007 See the method [llvm::ConstantExpr::getPtrToInt]. *)
1008 val const_ptrtoint : llvalue -> lltype -> llvalue
1010 (** [const_inttoptr c ty] returns the constant pointer conversion of
1011 integer constant [c] to pointer type [ty].
1012 See the method [llvm::ConstantExpr::getIntToPtr]. *)
1013 val const_inttoptr : llvalue -> lltype -> llvalue
1015 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
1016 to type [ty] of equal size.
1017 See the method [llvm::ConstantExpr::getBitCast]. *)
1018 val const_bitcast : llvalue -> lltype -> llvalue
1020 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
1021 conversion of constant [c] to type [ty].
1022 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
1023 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
1025 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
1026 conversion of constant [c] to type [ty].
1027 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
1028 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
1030 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
1031 conversion of constant [c] to type [ty].
1032 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
1033 val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
1035 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
1036 cast conversion of constant [c] to type [ty] of equal size.
1037 See the method [llvm::ConstantExpr::getPointerCast]. *)
1038 val const_pointercast : llvalue -> lltype -> llvalue
1040 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
1041 -> integer casts of constant [c] to type [ty].
1042 See the method [llvm::ConstantExpr::getIntCast]. *)
1043 val const_intcast : llvalue -> lltype -> llvalue
1045 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
1046 fp casts of constant [c] to type [ty].
1047 See the method [llvm::ConstantExpr::getFPCast]. *)
1048 val const_fpcast : llvalue -> lltype -> llvalue
1050 (** [const_select cond t f] returns the constant conditional which returns value
1051 [t] if the boolean constant [cond] is true and the value [f] otherwise.
1052 See the method [llvm::ConstantExpr::getSelect]. *)
1053 val const_select : llvalue -> llvalue -> llvalue -> llvalue
1055 (** [const_extractelement vec i] returns the constant [i]th element of
1056 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
1057 the size of the vector.
1058 See the method [llvm::ConstantExpr::getExtractElement]. *)
1059 val const_extractelement : llvalue -> llvalue -> llvalue
1061 (** [const_insertelement vec v i] returns the constant vector with the same
1062 elements as constant vector [v] but the [i]th element replaced by the
1063 constant [v]. [v] must be a constant value with the type of the vector
1064 elements. [i] must be a constant [i32] value unsigned less than the size
1066 See the method [llvm::ConstantExpr::getInsertElement]. *)
1067 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
1069 (** [const_shufflevector a b mask] returns a constant [shufflevector].
1070 See the LLVM Language Reference for details on the [shufflevector]
1072 See the method [llvm::ConstantExpr::getShuffleVector]. *)
1073 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
1075 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
1076 constant aggregate [agg]. Each [idxs] must be less than the size of the
1077 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
1078 val const_extractvalue : llvalue -> int array -> llvalue
1080 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
1081 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
1082 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
1083 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
1085 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
1086 See the method [llvm::InlineAsm::get]. *)
1087 val const_inline_asm : lltype -> string -> string -> bool -> bool -> llvalue
1089 (** [block_address f bb] returns the address of the basic block [bb] in the
1090 function [f]. See the method [llvm::BasicBlock::get]. *)
1091 val block_address : llvalue -> llbasicblock -> llvalue
1094 (** {7 Operations on global variables, functions, and aliases (globals)} *)
1096 (** [global_parent g] is the enclosing module of the global value [g].
1097 See the method [llvm::GlobalValue::getParent]. *)
1098 val global_parent : llvalue -> llmodule
1100 (** [is_declaration g] returns [true] if the global value [g] is a declaration
1101 only. Returns [false] otherwise.
1102 See the method [llvm::GlobalValue::isDeclaration]. *)
1103 val is_declaration : llvalue -> bool
1105 (** [linkage g] returns the linkage of the global value [g].
1106 See the method [llvm::GlobalValue::getLinkage]. *)
1107 val linkage : llvalue -> Linkage.t
1109 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
1110 See the method [llvm::GlobalValue::setLinkage]. *)
1111 val set_linkage : Linkage.t -> llvalue -> unit
1113 (** [section g] returns the linker section of the global value [g].
1114 See the method [llvm::GlobalValue::getSection]. *)
1115 val section : llvalue -> string
1117 (** [set_section s g] sets the linker section of the global value [g] to [s].
1118 See the method [llvm::GlobalValue::setSection]. *)
1119 val set_section : string -> llvalue -> unit
1121 (** [visibility g] returns the linker visibility of the global value [g].
1122 See the method [llvm::GlobalValue::getVisibility]. *)
1123 val visibility : llvalue -> Visibility.t
1125 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1126 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1127 val set_visibility : Visibility.t -> llvalue -> unit
1129 (** [alignment g] returns the required alignment of the global value [g].
1130 See the method [llvm::GlobalValue::getAlignment]. *)
1131 val alignment : llvalue -> int
1133 (** [set_alignment n g] sets the required alignment of the global value [g] to
1134 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1135 val set_alignment : int -> llvalue -> unit
1138 (** {7 Operations on global variables} *)
1140 (** [declare_global ty name m] returns a new global variable of type [ty] and
1141 with name [name] in module [m] in the default address space (0). If such a
1142 global variable already exists, it is returned. If the type of the existing
1143 global differs, then a bitcast to [ty] is returned. *)
1144 val declare_global : lltype -> string -> llmodule -> llvalue
1146 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1147 of type [ty] and with name [name] in module [m] in the address space
1148 [addrspace]. If such a global variable already exists, it is returned. If
1149 the type of the existing global differs, then a bitcast to [ty] is
1151 val declare_qualified_global : lltype -> string -> int -> llmodule -> llvalue
1153 (** [define_global name init m] returns a new global with name [name] and
1154 initializer [init] in module [m] in the default address space (0). If the
1155 named global already exists, it is renamed.
1156 See the constructor of [llvm::GlobalVariable]. *)
1157 val define_global : string -> llvalue -> llmodule -> llvalue
1159 (** [define_qualified_global name init addrspace m] returns a new global with
1160 name [name] and initializer [init] in module [m] in the address space
1161 [addrspace]. If the named global already exists, it is renamed.
1162 See the constructor of [llvm::GlobalVariable]. *)
1163 val define_qualified_global : string -> llvalue -> int -> llmodule -> llvalue
1165 (** [lookup_global name m] returns [Some g] if a global variable with name
1166 [name] exists in module [m]. If no such global exists, returns [None].
1167 See the [llvm::GlobalVariable] constructor. *)
1168 val lookup_global : string -> llmodule -> llvalue option
1170 (** [delete_global gv] destroys the global variable [gv].
1171 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1172 val delete_global : llvalue -> unit
1174 (** [global_begin m] returns the first position in the global variable list of
1175 the module [m]. [global_begin] and [global_succ] can be used to iterate
1176 over the global list in order.
1177 See the method [llvm::Module::global_begin]. *)
1178 val global_begin : llmodule -> (llmodule, llvalue) llpos
1180 (** [global_succ gv] returns the global variable list position succeeding
1182 See the method [llvm::Module::global_iterator::operator++]. *)
1183 val global_succ : llvalue -> (llmodule, llvalue) llpos
1185 (** [iter_globals f m] applies function [f] to each of the global variables of
1186 module [m] in order. Tail recursive. *)
1187 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1189 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1190 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1191 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1193 (** [global_end m] returns the last position in the global variable list of the
1194 module [m]. [global_end] and [global_pred] can be used to iterate over the
1195 global list in reverse.
1196 See the method [llvm::Module::global_end]. *)
1197 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1199 (** [global_pred gv] returns the global variable list position preceding
1201 See the method [llvm::Module::global_iterator::operator--]. *)
1202 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1204 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1205 of module [m] in reverse order. Tail recursive. *)
1206 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1208 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1209 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1210 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1212 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1213 constant. Returns [false] otherwise.
1214 See the method [llvm::GlobalVariable::isConstant]. *)
1215 val is_global_constant : llvalue -> bool
1217 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1218 [c] is [true] and not if [c] is [false].
1219 See the method [llvm::GlobalVariable::setConstant]. *)
1220 val set_global_constant : bool -> llvalue -> unit
1222 (** [global_initializer gv] returns the initializer for the global variable
1223 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1224 val global_initializer : llvalue -> llvalue
1226 (** [set_initializer c gv] sets the initializer for the global variable
1227 [gv] to the constant [c].
1228 See the method [llvm::GlobalVariable::setInitializer]. *)
1229 val set_initializer : llvalue -> llvalue -> unit
1231 (** [remove_initializer gv] unsets the initializer for the global variable
1233 See the method [llvm::GlobalVariable::setInitializer]. *)
1234 val remove_initializer : llvalue -> unit
1236 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1237 thread-local and [false] otherwise.
1238 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1239 val is_thread_local : llvalue -> bool
1241 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1242 [c] is [true] and not otherwise.
1243 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1244 val set_thread_local : bool -> llvalue -> unit
1247 (** {7 Operations on aliases} *)
1249 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1250 the aliasee [a] with the name [n].
1251 See the constructor for [llvm::GlobalAlias]. *)
1252 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1255 (** {7 Operations on functions} *)
1257 (** [declare_function name ty m] returns a new function of type [ty] and
1258 with name [name] in module [m]. If such a function already exists,
1259 it is returned. If the type of the existing function differs, then a bitcast
1260 to [ty] is returned. *)
1261 val declare_function : string -> lltype -> llmodule -> llvalue
1263 (** [define_function name ty m] creates a new function with name [name] and
1264 type [ty] in module [m]. If the named function already exists, it is
1265 renamed. An entry basic block is created in the function.
1266 See the constructor of [llvm::GlobalVariable]. *)
1267 val define_function : string -> lltype -> llmodule -> llvalue
1269 (** [lookup_function name m] returns [Some f] if a function with name
1270 [name] exists in module [m]. If no such function exists, returns [None].
1271 See the method [llvm::Module] constructor. *)
1272 val lookup_function : string -> llmodule -> llvalue option
1274 (** [delete_function f] destroys the function [f].
1275 See the method [llvm::Function::eraseFromParent]. *)
1276 val delete_function : llvalue -> unit
1278 (** [function_begin m] returns the first position in the function list of the
1279 module [m]. [function_begin] and [function_succ] can be used to iterate over
1280 the function list in order.
1281 See the method [llvm::Module::begin]. *)
1282 val function_begin : llmodule -> (llmodule, llvalue) llpos
1284 (** [function_succ gv] returns the function list position succeeding
1286 See the method [llvm::Module::iterator::operator++]. *)
1287 val function_succ : llvalue -> (llmodule, llvalue) llpos
1289 (** [iter_functions f m] applies function [f] to each of the functions of module
1290 [m] in order. Tail recursive. *)
1291 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1293 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1294 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1295 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1297 (** [function_end m] returns the last position in the function list of
1298 the module [m]. [function_end] and [function_pred] can be used to iterate
1299 over the function list in reverse.
1300 See the method [llvm::Module::end]. *)
1301 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1303 (** [function_pred gv] returns the function list position preceding [After gv].
1304 See the method [llvm::Module::iterator::operator--]. *)
1305 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1307 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1308 module [m] in reverse order. Tail recursive. *)
1309 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1311 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1312 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1313 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1315 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1316 See the method [llvm::Function::isIntrinsic]. *)
1317 val is_intrinsic : llvalue -> bool
1319 (** [function_call_conv f] returns the calling convention of the function [f].
1320 See the method [llvm::Function::getCallingConv]. *)
1321 val function_call_conv : llvalue -> int
1323 (** [set_function_call_conv cc f] sets the calling convention of the function
1324 [f] to the calling convention numbered [cc].
1325 See the method [llvm::Function::setCallingConv]. *)
1326 val set_function_call_conv : int -> llvalue -> unit
1328 (** [gc f] returns [Some name] if the function [f] has a garbage
1329 collection algorithm specified and [None] otherwise.
1330 See the method [llvm::Function::getGC]. *)
1331 val gc : llvalue -> string option
1333 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1334 [gc]. See the method [llvm::Function::setGC]. *)
1335 val set_gc : string option -> llvalue -> unit
1337 (** [add_function_attr f a] adds attribute [a] to the return type of function
1339 val add_function_attr : llvalue -> Attribute.t -> unit
1341 (** [function_attr f] returns the function attribute for the function [f].
1342 See the method [llvm::Function::getAttributes] *)
1343 val function_attr : llvalue -> Attribute.t list
1345 (** [remove_function_attr f a] removes attribute [a] from the return type of
1347 val remove_function_attr : llvalue -> Attribute.t -> unit
1350 (** {7 Operations on params} *)
1352 (** [params f] returns the parameters of function [f].
1353 See the method [llvm::Function::getArgumentList]. *)
1354 val params : llvalue -> llvalue array
1356 (** [param f n] returns the [n]th parameter of function [f].
1357 See the method [llvm::Function::getArgumentList]. *)
1358 val param : llvalue -> int -> llvalue
1360 (** [param_attr p] returns the attributes of parameter [p].
1361 See the methods [llvm::Function::getAttributes] and
1362 [llvm::Attributes::getParamAttributes] *)
1363 val param_attr : llvalue -> Attribute.t list
1365 (** [param_parent p] returns the parent function that owns the parameter.
1366 See the method [llvm::Argument::getParent]. *)
1367 val param_parent : llvalue -> llvalue
1369 (** [param_begin f] returns the first position in the parameter list of the
1370 function [f]. [param_begin] and [param_succ] can be used to iterate over
1371 the parameter list in order.
1372 See the method [llvm::Function::arg_begin]. *)
1373 val param_begin : llvalue -> (llvalue, llvalue) llpos
1375 (** [param_succ bb] returns the parameter list position succeeding
1377 See the method [llvm::Function::arg_iterator::operator++]. *)
1378 val param_succ : llvalue -> (llvalue, llvalue) llpos
1380 (** [iter_params f fn] applies function [f] to each of the parameters
1381 of function [fn] in order. Tail recursive. *)
1382 val iter_params : (llvalue -> unit) -> llvalue -> unit
1384 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1385 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1386 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1388 (** [param_end f] returns the last position in the parameter list of
1389 the function [f]. [param_end] and [param_pred] can be used to iterate
1390 over the parameter list in reverse.
1391 See the method [llvm::Function::arg_end]. *)
1392 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1394 (** [param_pred gv] returns the function list position preceding [After gv].
1395 See the method [llvm::Function::arg_iterator::operator--]. *)
1396 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1398 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1399 of function [fn] in reverse order. Tail recursive. *)
1400 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1402 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1403 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1404 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1406 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1407 val add_param_attr : llvalue -> Attribute.t -> unit
1409 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1410 val remove_param_attr : llvalue -> Attribute.t -> unit
1412 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1413 val set_param_alignment : llvalue -> int -> unit
1416 (** {7 Operations on basic blocks} *)
1418 (** [basic_blocks fn] returns the basic blocks of the function [f].
1419 See the method [llvm::Function::getBasicBlockList]. *)
1420 val basic_blocks : llvalue -> llbasicblock array
1422 (** [entry_block fn] returns the entry basic block of the function [f].
1423 See the method [llvm::Function::getEntryBlock]. *)
1424 val entry_block : llvalue -> llbasicblock
1426 (** [delete_block bb] deletes the basic block [bb].
1427 See the method [llvm::BasicBlock::eraseFromParent]. *)
1428 val delete_block : llbasicblock -> unit
1430 (** [append_block c name f] creates a new basic block named [name] at the end of
1431 function [f] in the context [c].
1432 See the constructor of [llvm::BasicBlock]. *)
1433 val append_block : llcontext -> string -> llvalue -> llbasicblock
1435 (** [insert_block c name bb] creates a new basic block named [name] before the
1436 basic block [bb] in the context [c].
1437 See the constructor of [llvm::BasicBlock]. *)
1438 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1440 (** [block_parent bb] returns the parent function that owns the basic block.
1441 See the method [llvm::BasicBlock::getParent]. *)
1442 val block_parent : llbasicblock -> llvalue
1444 (** [block_begin f] returns the first position in the basic block list of the
1445 function [f]. [block_begin] and [block_succ] can be used to iterate over
1446 the basic block list in order.
1447 See the method [llvm::Function::begin]. *)
1448 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1450 (** [block_succ bb] returns the basic block list position succeeding
1452 See the method [llvm::Function::iterator::operator++]. *)
1453 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1455 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1456 of function [fn] in order. Tail recursive. *)
1457 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1459 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1460 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1461 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1463 (** [block_end f] returns the last position in the basic block list of
1464 the function [f]. [block_end] and [block_pred] can be used to iterate
1465 over the basic block list in reverse.
1466 See the method [llvm::Function::end]. *)
1467 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1469 (** [block_pred gv] returns the function list position preceding [After gv].
1470 See the method [llvm::Function::iterator::operator--]. *)
1471 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1473 val block_terminator : llbasicblock -> llvalue option
1475 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1476 of function [fn] in reverse order. Tail recursive. *)
1477 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1479 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1480 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1481 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1483 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1484 val value_of_block : llbasicblock -> llvalue
1486 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1488 Similar to [llvm::isa<BasicBlock>]. *)
1489 val value_is_block : llvalue -> bool
1491 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1492 val block_of_value : llvalue -> llbasicblock
1495 (** {7 Operations on instructions} *)
1497 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1498 See the method [llvm::Instruction::getParent]. *)
1499 val instr_parent : llvalue -> llbasicblock
1501 (** [instr_begin bb] returns the first position in the instruction list of the
1502 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1503 the instruction list in order.
1504 See the method [llvm::BasicBlock::begin]. *)
1505 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1507 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1508 See the method [llvm::BasicBlock::iterator::operator++]. *)
1509 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1511 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1512 block [bb] in order. Tail recursive. *)
1513 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1515 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1516 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1517 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1519 (** [instr_end bb] returns the last position in the instruction list of the
1520 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1521 the instruction list in reverse.
1522 See the method [llvm::BasicBlock::end]. *)
1523 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1525 (** [instr_pred i] returns the instruction list position preceding [After i].
1526 See the method [llvm::BasicBlock::iterator::operator--]. *)
1527 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1529 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1530 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1531 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1533 val instr_opcode : llvalue -> Opcode.t
1535 val icmp_predicate : llvalue -> Icmp.t option
1538 (** {7 Operations on call sites} *)
1540 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1541 instruction [ci], which may be one of the values from the module
1542 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1543 [llvm::InvokeInst::getCallingConv]. *)
1544 val instruction_call_conv: llvalue -> int
1546 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1547 or invoke instruction [ci] to the integer [cc], which can be one of the
1548 values from the module {!CallConv}.
1549 See the method [llvm::CallInst::setCallingConv]
1550 and [llvm::InvokeInst::setCallingConv]. *)
1551 val set_instruction_call_conv: int -> llvalue -> unit
1553 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1554 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1556 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1558 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1559 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1561 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1564 (** {Operations on call instructions (only)} *)
1566 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1567 eligible for tail call optimization, [false] otherwise.
1568 See the method [llvm::CallInst::isTailCall]. *)
1569 val is_tail_call : llvalue -> bool
1571 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1572 call optimization if [tc] is [true], clears otherwise.
1573 See the method [llvm::CallInst::setTailCall]. *)
1574 val set_tail_call : bool -> llvalue -> unit
1577 (** {7 Operations on phi nodes} *)
1579 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1580 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1581 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1583 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1584 See the method [llvm::PHINode::getIncomingValue]. *)
1585 val incoming : llvalue -> (llvalue * llbasicblock) list
1587 (** [delete_instruction i] deletes the instruction [i].
1588 * See the method [llvm::Instruction::eraseFromParent]. *)
1589 val delete_instruction : llvalue -> unit
1592 (** {6 Instruction builders} *)
1594 (** [builder context] creates an instruction builder with no position in
1595 the context [context]. It is invalid to use this builder until its position
1596 is set with {!position_before} or {!position_at_end}. See the constructor
1597 for [llvm::LLVMBuilder]. *)
1598 val builder : llcontext -> llbuilder
1600 (** [builder_at ip] creates an instruction builder positioned at [ip].
1601 See the constructor for [llvm::LLVMBuilder]. *)
1602 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1604 (** [builder_before ins] creates an instruction builder positioned before the
1605 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1606 val builder_before : llcontext -> llvalue -> llbuilder
1608 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1609 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1610 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1612 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1614 See the constructor for [llvm::LLVMBuilder]. *)
1615 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1617 (** [position_before ins b] moves the instruction builder [b] to before the
1618 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1619 val position_before : llvalue -> llbuilder -> unit
1621 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1622 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1623 val position_at_end : llbasicblock -> llbuilder -> unit
1625 (** [insertion_block b] returns the basic block that the builder [b] is
1626 positioned to insert into. Raises [Not_Found] if the instruction builder is
1628 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1629 val insertion_block : llbuilder -> llbasicblock
1631 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1632 position specified by the instruction builder [b].
1633 See the method [llvm::LLVMBuilder::Insert]. *)
1634 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1639 (** [set_current_debug_location b md] sets the current debug location [md] in
1641 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1642 val set_current_debug_location : llbuilder -> llvalue -> unit
1644 (** [clear_current_debug_location b] clears the current debug location in the
1646 val clear_current_debug_location : llbuilder -> unit
1648 (** [current_debug_location b] returns the current debug location, or None
1649 if none is currently set.
1650 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1651 val current_debug_location : llbuilder -> llvalue option
1653 (** [set_inst_debug_location b i] sets the current debug location of the builder
1654 [b] to the instruction [i].
1655 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1656 val set_inst_debug_location : llbuilder -> llvalue -> unit
1659 (** {7 Terminators} *)
1661 (** [build_ret_void b] creates a
1663 instruction at the position specified by the instruction builder [b].
1664 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1665 val build_ret_void : llbuilder -> llvalue
1667 (** [build_ret v b] creates a
1669 instruction at the position specified by the instruction builder [b].
1670 See the method [llvm::LLVMBuilder::CreateRet]. *)
1671 val build_ret : llvalue -> llbuilder -> llvalue
1673 (** [build_aggregate_ret vs b] creates a
1674 [ret {...} { %v1, %v2, ... } ]
1675 instruction at the position specified by the instruction builder [b].
1676 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1677 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1679 (** [build_br bb b] creates a
1681 instruction at the position specified by the instruction builder [b].
1682 See the method [llvm::LLVMBuilder::CreateBr]. *)
1683 val build_br : llbasicblock -> llbuilder -> llvalue
1685 (** [build_cond_br cond tbb fbb b] creates a
1686 [br %cond, %tbb, %fbb]
1687 instruction at the position specified by the instruction builder [b].
1688 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1689 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1692 (** [build_switch case elsebb count b] creates an empty
1693 [switch %case, %elsebb]
1694 instruction at the position specified by the instruction builder [b] with
1695 space reserved for [count] cases.
1696 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1697 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1699 (** [build_malloc ty name b] creates an [malloc]
1700 instruction at the position specified by the instruction builder [b].
1701 See the method [llvm::CallInst::CreateMalloc]. *)
1702 val build_malloc : lltype -> string -> llbuilder -> llvalue
1704 (** [build_array_malloc ty val name b] creates an [array malloc]
1705 instruction at the position specified by the instruction builder [b].
1706 See the method [llvm::CallInst::CreateArrayMalloc]. *)
1707 val build_array_malloc : lltype -> llvalue -> string -> llbuilder -> llvalue
1709 (** [build_free p b] creates a [free]
1710 instruction at the position specified by the instruction builder [b].
1711 See the method [llvm::LLVMBuilder::CreateFree]. *)
1712 val build_free : llvalue -> llbuilder -> llvalue
1714 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1715 when its input matches the constant [onval].
1716 See the method [llvm::SwitchInst::addCase]. **)
1717 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1719 (** [switch_default_dest sw] returns the default destination of the [switch]
1721 See the method [llvm:;SwitchInst::getDefaultDest]. **)
1722 val switch_default_dest : llvalue -> llbasicblock
1724 (** [build_indirect_br addr count b] creates a
1726 instruction at the position specified by the instruction builder [b] with
1727 space reserved for [count] destinations.
1728 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1729 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1731 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1732 location for the indirectbr instruction [br].
1733 See the method [llvm::IndirectBrInst::addDestination]. **)
1734 val add_destination : llvalue -> llbasicblock -> unit
1736 (** [build_invoke fn args tobb unwindbb name b] creates an
1737 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1738 instruction at the position specified by the instruction builder [b].
1739 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1740 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1741 llbasicblock -> string -> llbuilder -> llvalue
1743 (** [build_landingpad ty persfn numclauses name b] creates an
1745 instruction at the position specified by the instruction builder [b].
1746 See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
1747 val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
1750 (** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
1751 See the method [llvm::LandingPadInst::setCleanup]. *)
1752 val set_cleanup : llvalue -> bool -> unit
1754 (** [add_clause lp clause] adds the clause to the [landingpad]instruction.
1755 See the method [llvm::LandingPadInst::addClause]. *)
1756 val add_clause : llvalue -> llvalue -> unit
1758 (** [build_resume exn b] builds a [resume exn] instruction
1759 at the position specified by the instruction builder [b].
1760 See the method [llvm::LLVMBuilder::CreateResume] *)
1761 val build_resume : llvalue -> llbuilder -> llvalue
1763 (** [build_unreachable b] creates an
1765 instruction at the position specified by the instruction builder [b].
1766 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1767 val build_unreachable : llbuilder -> llvalue
1770 (** {7 Arithmetic} *)
1772 (** [build_add x y name b] creates a
1773 [%name = add %x, %y]
1774 instruction at the position specified by the instruction builder [b].
1775 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1776 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1778 (** [build_nsw_add x y name b] creates a
1779 [%name = nsw add %x, %y]
1780 instruction at the position specified by the instruction builder [b].
1781 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1782 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1784 (** [build_nuw_add x y name b] creates a
1785 [%name = nuw add %x, %y]
1786 instruction at the position specified by the instruction builder [b].
1787 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1788 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1790 (** [build_fadd x y name b] creates a
1791 [%name = fadd %x, %y]
1792 instruction at the position specified by the instruction builder [b].
1793 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1794 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1796 (** [build_sub x y name b] creates a
1797 [%name = sub %x, %y]
1798 instruction at the position specified by the instruction builder [b].
1799 See the method [llvm::LLVMBuilder::CreateSub]. *)
1800 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1802 (** [build_nsw_sub x y name b] creates a
1803 [%name = nsw sub %x, %y]
1804 instruction at the position specified by the instruction builder [b].
1805 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1806 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1808 (** [build_nuw_sub x y name b] creates a
1809 [%name = nuw sub %x, %y]
1810 instruction at the position specified by the instruction builder [b].
1811 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1812 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1814 (** [build_fsub x y name b] creates a
1815 [%name = fsub %x, %y]
1816 instruction at the position specified by the instruction builder [b].
1817 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1818 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1820 (** [build_mul x y name b] creates a
1821 [%name = mul %x, %y]
1822 instruction at the position specified by the instruction builder [b].
1823 See the method [llvm::LLVMBuilder::CreateMul]. *)
1824 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1826 (** [build_nsw_mul x y name b] creates a
1827 [%name = nsw mul %x, %y]
1828 instruction at the position specified by the instruction builder [b].
1829 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1830 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1832 (** [build_nuw_mul x y name b] creates a
1833 [%name = nuw mul %x, %y]
1834 instruction at the position specified by the instruction builder [b].
1835 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1836 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1838 (** [build_fmul x y name b] creates a
1839 [%name = fmul %x, %y]
1840 instruction at the position specified by the instruction builder [b].
1841 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1842 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1844 (** [build_udiv x y name b] creates a
1845 [%name = udiv %x, %y]
1846 instruction at the position specified by the instruction builder [b].
1847 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1848 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1850 (** [build_sdiv x y name b] creates a
1851 [%name = sdiv %x, %y]
1852 instruction at the position specified by the instruction builder [b].
1853 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1854 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1856 (** [build_exact_sdiv x y name b] creates a
1857 [%name = exact sdiv %x, %y]
1858 instruction at the position specified by the instruction builder [b].
1859 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1860 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1862 (** [build_fdiv x y name b] creates a
1863 [%name = fdiv %x, %y]
1864 instruction at the position specified by the instruction builder [b].
1865 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1866 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1868 (** [build_urem x y name b] creates a
1869 [%name = urem %x, %y]
1870 instruction at the position specified by the instruction builder [b].
1871 See the method [llvm::LLVMBuilder::CreateURem]. *)
1872 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1874 (** [build_SRem x y name b] creates a
1875 [%name = srem %x, %y]
1876 instruction at the position specified by the instruction builder [b].
1877 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1878 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1880 (** [build_frem x y name b] creates a
1881 [%name = frem %x, %y]
1882 instruction at the position specified by the instruction builder [b].
1883 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1884 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1886 (** [build_shl x y name b] creates a
1887 [%name = shl %x, %y]
1888 instruction at the position specified by the instruction builder [b].
1889 See the method [llvm::LLVMBuilder::CreateShl]. *)
1890 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1892 (** [build_lshr x y name b] creates a
1893 [%name = lshr %x, %y]
1894 instruction at the position specified by the instruction builder [b].
1895 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1896 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1898 (** [build_ashr x y name b] creates a
1899 [%name = ashr %x, %y]
1900 instruction at the position specified by the instruction builder [b].
1901 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1902 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1904 (** [build_and x y name b] creates a
1905 [%name = and %x, %y]
1906 instruction at the position specified by the instruction builder [b].
1907 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1908 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1910 (** [build_or x y name b] creates a
1912 instruction at the position specified by the instruction builder [b].
1913 See the method [llvm::LLVMBuilder::CreateOr]. *)
1914 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1916 (** [build_xor x y name b] creates a
1917 [%name = xor %x, %y]
1918 instruction at the position specified by the instruction builder [b].
1919 See the method [llvm::LLVMBuilder::CreateXor]. *)
1920 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1922 (** [build_neg x name b] creates a
1924 instruction at the position specified by the instruction builder [b].
1925 [-0.0] is used for floating point types to compute the correct sign.
1926 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1927 val build_neg : llvalue -> string -> llbuilder -> llvalue
1929 (** [build_nsw_neg x name b] creates a
1930 [%name = nsw sub 0, %x]
1931 instruction at the position specified by the instruction builder [b].
1932 [-0.0] is used for floating point types to compute the correct sign.
1933 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1934 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1936 (** [build_nuw_neg x name b] creates a
1937 [%name = nuw sub 0, %x]
1938 instruction at the position specified by the instruction builder [b].
1939 [-0.0] is used for floating point types to compute the correct sign.
1940 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1941 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1943 (** [build_fneg x name b] creates a
1944 [%name = fsub 0, %x]
1945 instruction at the position specified by the instruction builder [b].
1946 [-0.0] is used for floating point types to compute the correct sign.
1947 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1948 val build_fneg : llvalue -> string -> llbuilder -> llvalue
1950 (** [build_xor x name b] creates a
1951 [%name = xor %x, -1]
1952 instruction at the position specified by the instruction builder [b].
1953 [-1] is the correct "all ones" value for the type of [x].
1954 See the method [llvm::LLVMBuilder::CreateXor]. *)
1955 val build_not : llvalue -> string -> llbuilder -> llvalue
1960 (** [build_alloca ty name b] creates a
1961 [%name = alloca %ty]
1962 instruction at the position specified by the instruction builder [b].
1963 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1964 val build_alloca : lltype -> string -> llbuilder -> llvalue
1966 (** [build_array_alloca ty n name b] creates a
1967 [%name = alloca %ty, %n]
1968 instruction at the position specified by the instruction builder [b].
1969 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1970 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1973 (** [build_load v name b] creates a
1975 instruction at the position specified by the instruction builder [b].
1976 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1977 val build_load : llvalue -> string -> llbuilder -> llvalue
1979 (** [build_store v p b] creates a
1981 instruction at the position specified by the instruction builder [b].
1982 See the method [llvm::LLVMBuilder::CreateStore]. *)
1983 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
1985 (** [build_gep p indices name b] creates a
1986 [%name = getelementptr %p, indices...]
1987 instruction at the position specified by the instruction builder [b].
1988 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1989 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1991 (** [build_in_bounds_gep p indices name b] creates a
1992 [%name = gelementptr inbounds %p, indices...]
1993 instruction at the position specified by the instruction builder [b].
1994 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1995 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1998 (** [build_struct_gep p idx name b] creates a
1999 [%name = getelementptr %p, 0, idx]
2000 instruction at the position specified by the instruction builder [b].
2001 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
2002 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
2005 (** [build_global_string str name b] creates a series of instructions that adds
2006 a global string at the position specified by the instruction builder [b].
2007 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
2008 val build_global_string : string -> string -> llbuilder -> llvalue
2010 (** [build_global_stringptr str name b] creates a series of instructions that
2011 adds a global string pointer at the position specified by the instruction
2013 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
2014 val build_global_stringptr : string -> string -> llbuilder -> llvalue
2019 (** [build_trunc v ty name b] creates a
2020 [%name = trunc %p to %ty]
2021 instruction at the position specified by the instruction builder [b].
2022 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
2023 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2025 (** [build_zext v ty name b] creates a
2026 [%name = zext %p to %ty]
2027 instruction at the position specified by the instruction builder [b].
2028 See the method [llvm::LLVMBuilder::CreateZExt]. *)
2029 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
2031 (** [build_sext v ty name b] creates a
2032 [%name = sext %p to %ty]
2033 instruction at the position specified by the instruction builder [b].
2034 See the method [llvm::LLVMBuilder::CreateSExt]. *)
2035 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
2037 (** [build_fptoui v ty name b] creates a
2038 [%name = fptoui %p to %ty]
2039 instruction at the position specified by the instruction builder [b].
2040 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
2041 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
2043 (** [build_fptosi v ty name b] creates a
2044 [%name = fptosi %p to %ty]
2045 instruction at the position specified by the instruction builder [b].
2046 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
2047 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
2049 (** [build_uitofp v ty name b] creates a
2050 [%name = uitofp %p to %ty]
2051 instruction at the position specified by the instruction builder [b].
2052 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
2053 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2055 (** [build_sitofp v ty name b] creates a
2056 [%name = sitofp %p to %ty]
2057 instruction at the position specified by the instruction builder [b].
2058 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
2059 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2061 (** [build_fptrunc v ty name b] creates a
2062 [%name = fptrunc %p to %ty]
2063 instruction at the position specified by the instruction builder [b].
2064 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
2065 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2067 (** [build_fpext v ty name b] creates a
2068 [%name = fpext %p to %ty]
2069 instruction at the position specified by the instruction builder [b].
2070 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
2071 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
2073 (** [build_ptrtoint v ty name b] creates a
2074 [%name = prtotint %p to %ty]
2075 instruction at the position specified by the instruction builder [b].
2076 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2077 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2079 (** [build_inttoptr v ty name b] creates a
2080 [%name = inttoptr %p to %ty]
2081 instruction at the position specified by the instruction builder [b].
2082 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2083 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2085 (** [build_bitcast v ty name b] creates a
2086 [%name = bitcast %p to %ty]
2087 instruction at the position specified by the instruction builder [b].
2088 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2089 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2091 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2092 instruction at the position specified by the instruction builder [b].
2093 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2094 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2097 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2098 instruction at the position specified by the instruction builder [b].
2099 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2100 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2103 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2104 instruction at the position specified by the instruction builder [b].
2105 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2106 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2109 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2110 instruction at the position specified by the instruction builder [b].
2111 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2112 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2114 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2115 instruction at the position specified by the instruction builder [b].
2116 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2117 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2119 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2120 instruction at the position specified by the instruction builder [b].
2121 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2122 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2125 (** {7 Comparisons} *)
2127 (** [build_icmp pred x y name b] creates a
2128 [%name = icmp %pred %x, %y]
2129 instruction at the position specified by the instruction builder [b].
2130 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2131 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2132 llbuilder -> llvalue
2134 (** [build_fcmp pred x y name b] creates a
2135 [%name = fcmp %pred %x, %y]
2136 instruction at the position specified by the instruction builder [b].
2137 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2138 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2139 llbuilder -> llvalue
2142 (** {7 Miscellaneous instructions} *)
2144 (** [build_phi incoming name b] creates a
2145 [%name = phi %incoming]
2146 instruction at the position specified by the instruction builder [b].
2147 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2148 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2149 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2152 (** [build_call fn args name b] creates a
2153 [%name = call %fn(args...)]
2154 instruction at the position specified by the instruction builder [b].
2155 See the method [llvm::LLVMBuilder::CreateCall]. *)
2156 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2158 (** [build_select cond thenv elsev name b] creates a
2159 [%name = select %cond, %thenv, %elsev]
2160 instruction at the position specified by the instruction builder [b].
2161 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2162 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2165 (** [build_va_arg valist argty name b] creates a
2166 [%name = va_arg %valist, %argty]
2167 instruction at the position specified by the instruction builder [b].
2168 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2169 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2171 (** [build_extractelement vec i name b] creates a
2172 [%name = extractelement %vec, %i]
2173 instruction at the position specified by the instruction builder [b].
2174 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2175 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2178 (** [build_insertelement vec elt i name b] creates a
2179 [%name = insertelement %vec, %elt, %i]
2180 instruction at the position specified by the instruction builder [b].
2181 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2182 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2183 llbuilder -> llvalue
2185 (** [build_shufflevector veca vecb mask name b] creates a
2186 [%name = shufflevector %veca, %vecb, %mask]
2187 instruction at the position specified by the instruction builder [b].
2188 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2189 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2190 llbuilder -> llvalue
2192 (** [build_insertvalue agg idx name b] creates a
2193 [%name = extractvalue %agg, %idx]
2194 instruction at the position specified by the instruction builder [b].
2195 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2196 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2199 (** [build_insertvalue agg val idx name b] creates a
2200 [%name = insertvalue %agg, %val, %idx]
2201 instruction at the position specified by the instruction builder [b].
2202 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2203 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2206 (** [build_is_null val name b] creates a
2207 [%name = icmp eq %val, null]
2208 instruction at the position specified by the instruction builder [b].
2209 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2210 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2212 (** [build_is_not_null val name b] creates a
2213 [%name = icmp ne %val, null]
2214 instruction at the position specified by the instruction builder [b].
2215 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2216 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2218 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2219 the difference between two pointer values at the position specified by the
2220 instruction builder [b].
2221 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2222 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2225 (** {6 Memory buffers} *)
2227 module MemoryBuffer : sig
2228 (** [of_file p] is the memory buffer containing the contents of the file at
2229 path [p]. If the file could not be read, then [IoError msg] is
2231 val of_file : string -> llmemorybuffer
2233 (** [of_stdin ()] is the memory buffer containing the contents of standard input.
2234 If standard input is empty, then [IoError msg] is raised. *)
2235 val of_stdin : unit -> llmemorybuffer
2237 (** [of_string ~name s] is the memory buffer containing the contents of string [s].
2238 The name of memory buffer is set to [name] if it is provided. *)
2239 val of_string : ?name:string -> string -> llmemorybuffer
2241 (** [as_string mb] is the string containing the contents of memory buffer [mb]. *)
2242 val as_string : llmemorybuffer -> string
2244 (** Disposes of a memory buffer. *)
2245 val dispose : llmemorybuffer -> unit
2249 (** {6 Pass Managers} *)
2251 module PassManager : sig
2254 type any = [ `Module | `Function ]
2256 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2257 type of pipeline is suitable for link-time optimization and whole-module
2259 See the constructor of [llvm::PassManager]. *)
2260 val create : unit -> [ `Module ] t
2262 (** [PassManager.create_function m] constructs a new function-by-function
2263 pass pipeline over the module [m]. It does not take ownership of [m].
2264 This type of pipeline is suitable for code generation and JIT compilation
2266 See the constructor of [llvm::FunctionPassManager]. *)
2267 val create_function : llmodule -> [ `Function ] t
2269 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2270 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2271 any of the passes modified the module, [false] otherwise.
2272 See the [llvm::PassManager::run] method. *)
2273 val run_module : llmodule -> [ `Module ] t -> bool
2275 (** [initialize fpm] initializes all of the function passes scheduled in the
2276 function pass manager [fpm]. Returns [true] if any of the passes modified
2277 the module, [false] otherwise.
2278 See the [llvm::FunctionPassManager::doInitialization] method. *)
2279 val initialize : [ `Function ] t -> bool
2281 (** [run_function f fpm] executes all of the function passes scheduled in the
2282 function pass manager [fpm] over the function [f]. Returns [true] if any
2283 of the passes modified [f], [false] otherwise.
2284 See the [llvm::FunctionPassManager::run] method. *)
2285 val run_function : llvalue -> [ `Function ] t -> bool
2287 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2288 function pass manager [fpm]. Returns [true] if any of the passes
2289 modified the module, [false] otherwise.
2290 See the [llvm::FunctionPassManager::doFinalization] method. *)
2291 val finalize : [ `Function ] t -> bool
2293 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2295 See the destructor of [llvm::BasePassManager]. *)
2296 val dispose : [< any ] t -> unit