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. *)
71 (** The linkage of a global value, accessed with {!linkage} and
72 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
76 | Available_externally
92 (** The linker visibility of a global value, accessed with {!visibility} and
93 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
94 module Visibility : sig
101 (** The following calling convention values may be accessed with
102 {!function_call_conv} and {!set_function_call_conv}. Calling
103 conventions are open-ended. *)
104 module CallConv : sig
105 val c : int (** [c] is the C calling convention. *)
106 val fast : int (** [fast] is the calling convention to allow LLVM
107 maximum optimization opportunities. Use only with
109 val cold : int (** [cold] is the calling convention for
111 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling
112 convention from C. *)
113 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
114 convention from C. *)
117 module Attribute : sig
141 | Stackalignment of int
147 (** The predicate for an integer comparison ([icmp]) instruction.
148 See the [llvm::ICmpInst::Predicate] enumeration. *)
163 (** The predicate for a floating-point comparison ([fcmp]) instruction.
164 See the [llvm::FCmpInst::Predicate] enumeration. *)
185 (** The opcodes for LLVM instructions and constant expressions. *)
188 | Invalid (* not an instruction *)
189 (* Terminator Instructions *)
197 (* Standard Binary Operators *)
210 (* Logical Operators *)
217 (* Memory Operators *)
235 (* Other Operators *)
257 (** The kind of an [llvalue], the result of [classify_value v].
258 * See the various [LLVMIsA*] functions. *)
259 module ValueKind : sig
268 | ConstantAggregateZero
273 | ConstantPointerNull
280 | Instruction of Opcode.t
285 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
286 of [a]. [llpos] is used to specify positions in and for forward iteration
287 through the various value lists maintained by the LLVM IR. *)
288 type ('a, 'b) llpos =
292 (** [After b] and [At_start a] specify positions from the end of the ['b] list
293 of [a]. [llrev_pos] is used for reverse iteration through the various value
294 lists maintained by the LLVM IR. *)
295 type ('a, 'b) llrev_pos =
300 (** {6 Exceptions} *)
302 exception IoError of string
307 (** [create_context ()] creates a context for storing the "global" state in
308 LLVM. See the constructor [llvm::LLVMContext]. *)
309 val create_context : unit -> llcontext
311 (** [destroy_context ()] destroys a context. See the destructor
312 [llvm::LLVMContext::~LLVMContext]. *)
313 val dispose_context : llcontext -> unit
315 (** See the function [llvm::getGlobalContext]. *)
316 val global_context : unit -> llcontext
318 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
319 name [name] in the context [context]. See the function
320 [llvm::LLVMContext::getMDKindID]. *)
321 val mdkind_id : llcontext -> string -> int
326 (** [create_module context id] creates a module with the supplied module ID in
327 the context [context]. Modules are not garbage collected; it is mandatory
328 to call {!dispose_module} to free memory. See the constructor
329 [llvm::Module::Module]. *)
330 val create_module : llcontext -> string -> llmodule
332 (** [dispose_module m] destroys a module [m] and all of the IR objects it
333 contained. All references to subordinate objects are invalidated;
334 referencing them will invoke undefined behavior. See the destructor
335 [llvm::Module::~Module]. *)
336 val dispose_module : llmodule -> unit
338 (** [target_triple m] is the target specifier for the module [m], something like
339 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
340 val target_triple: llmodule -> string
343 (** [target_triple triple m] changes the target specifier for the module [m] to
344 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
345 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
354 (** [set_data_layout s m] changes the data layout specifier for the module [m]
355 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
356 val set_data_layout: string -> llmodule -> unit
358 (** [dump_module m] prints the .ll representation of the module [m] to standard
359 error. See the method [llvm::Module::dump]. *)
360 val dump_module : llmodule -> unit
362 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
363 the method [llvm::Module::setModuleInlineAsm]. *)
364 val set_module_inline_asm : llmodule -> string -> unit
370 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
371 See the method [llvm::Type::getTypeID]. *)
372 val classify_type : lltype -> TypeKind.t
374 (** [type_is_sized ty] returns whether the type has a size or not.
375 * If it doesn't then it is not safe to call the [TargetData::] methods on it.
377 val type_is_sized : lltype -> bool
379 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
380 See the method [llvm::Type::getContext]. *)
381 val type_context : lltype -> llcontext
383 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
384 val string_of_lltype : lltype -> string
386 (** {7 Operations on integer types} *)
388 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
389 [llvm::Type::Int1Ty]. *)
390 val i1_type : llcontext -> lltype
392 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
393 [llvm::Type::Int8Ty]. *)
394 val i8_type : llcontext -> lltype
396 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
397 [llvm::Type::Int16Ty]. *)
398 val i16_type : llcontext -> lltype
400 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
401 [llvm::Type::Int32Ty]. *)
402 val i32_type : llcontext -> lltype
404 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
405 [llvm::Type::Int64Ty]. *)
406 val i64_type : llcontext -> lltype
408 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
409 [c]. See the method [llvm::IntegerType::get]. *)
410 val integer_type : llcontext -> int -> lltype
412 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
413 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
414 val integer_bitwidth : lltype -> int
417 (** {7 Operations on real types} *)
419 (** [float_type c] returns the IEEE 32-bit floating point type in the context
420 [c]. See [llvm::Type::FloatTy]. *)
421 val float_type : llcontext -> lltype
423 (** [double_type c] returns the IEEE 64-bit floating point type in the context
424 [c]. See [llvm::Type::DoubleTy]. *)
425 val double_type : llcontext -> lltype
427 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
428 [c]. See [llvm::Type::X86_FP80Ty]. *)
429 val x86fp80_type : llcontext -> lltype
431 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
432 [c]. See [llvm::Type::FP128Ty]. *)
433 val fp128_type : llcontext -> lltype
435 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
436 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
437 val ppc_fp128_type : llcontext -> lltype
440 (** {7 Operations on function types} *)
442 (** [function_type ret_ty param_tys] returns the function type returning
443 [ret_ty] and taking [param_tys] as parameters.
444 See the method [llvm::FunctionType::get]. *)
445 val function_type : lltype -> lltype array -> lltype
447 (** [var_arg_function_type ret_ty param_tys] is just like
448 [function_type ret_ty param_tys] except that it returns the function type
449 which also takes a variable number of arguments.
450 See the method [llvm::FunctionType::get]. *)
451 val var_arg_function_type : lltype -> lltype array -> lltype
454 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
455 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
456 val is_var_arg : lltype -> bool
458 (** [return_type fty] gets the return type of the function type [fty].
459 See the method [llvm::FunctionType::getReturnType]. *)
460 val return_type : lltype -> lltype
462 (** [param_types fty] gets the parameter types of the function type [fty].
463 See the method [llvm::FunctionType::getParamType]. *)
464 val param_types : lltype -> lltype array
467 (** {7 Operations on struct types} *)
469 (** [struct_type context tys] returns the structure type in the context
470 [context] containing in the types in the array [tys]. See the method
471 [llvm::StructType::get]. *)
472 val struct_type : llcontext -> lltype array -> lltype
475 (** [packed_struct_type context ys] returns the packed structure type in the
476 context [context] containing in the types in the array [tys]. See the method
477 [llvm::StructType::get]. *)
478 val packed_struct_type : llcontext -> lltype array -> lltype
480 (** [struct_name ty] returns the name of the named structure type [ty],
481 * or None if the structure type is not named *)
482 val struct_name : lltype -> string option
484 (** [named_struct_type context name] returns the named structure type [name]
485 * in the context [context].
486 * See the method [llvm::StructType::get]. *)
487 val named_struct_type : llcontext -> string -> lltype
489 (** [struct_set_body ty elts ispacked] sets the body of the named struct [ty]
490 * to the [elts] elements.
491 * See the moethd [llvm::StructType::setBody]. *)
492 val struct_set_body : lltype -> lltype array -> bool -> unit
494 (** [struct_element_types sty] returns the constituent types of the struct type
495 [sty]. See the method [llvm::StructType::getElementType]. *)
496 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
507 (** {7 Operations on pointer, vector, and array types} *)
509 (** [array_type ty n] returns the array type containing [n] elements of type
510 [ty]. See the method [llvm::ArrayType::get]. *)
511 val array_type : lltype -> int -> lltype
513 (** [pointer_type ty] returns the pointer type referencing objects of type
514 [ty] in the default address space (0).
515 See the method [llvm::PointerType::getUnqual]. *)
516 val pointer_type : lltype -> lltype
518 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
519 of type [ty] in address space [as].
520 See the method [llvm::PointerType::get]. *)
521 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
557 (** [type_of v] returns the type of the value [v].
558 See the method [llvm::Value::getType]. *)
559 val type_of : llvalue -> lltype
561 val classify_value : llvalue -> ValueKind.t
563 (** [value_name v] returns the name of the value [v]. For global values, this is
564 the symbol name. For instructions and basic blocks, it is the SSA register
565 name. It is meaningless for constants.
566 See the method [llvm::Value::getName]. *)
567 val value_name : llvalue -> string
569 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
570 [llvm::Value::setName]. *)
571 val set_value_name : string -> llvalue -> unit
573 (** [dump_value v] prints the .ll representation of the value [v] to standard
574 error. See the method [llvm::Value::dump]. *)
575 val dump_value : llvalue -> unit
577 (** [replace_all_uses_with old new] replaces all uses of the value [old]
578 * with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
579 val replace_all_uses_with : llvalue -> llvalue -> unit
585 (** [use_begin v] returns the first position in the use list for the value [v].
586 [use_begin] and [use_succ] can e used to iterate over the use list in order.
587 See the method [llvm::Value::use_begin]. *)
588 val use_begin : llvalue -> lluse option
590 (** [use_succ u] returns the use list position succeeding [u].
591 See the method [llvm::use_value_iterator::operator++]. *)
592 val use_succ : lluse -> lluse option
594 (** [user u] returns the user of the use [u].
595 See the method [llvm::Use::getUser]. *)
596 val user : lluse -> llvalue
598 (** [used_value u] returns the usee of the use [u].
599 See the method [llvm::Use::getUsedValue]. *)
600 val used_value : lluse -> llvalue
602 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
603 in order. Tail recursive. *)
604 val iter_uses : (lluse -> unit) -> llvalue -> unit
606 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
607 [u1,...,uN] are the users of the value [v]. Tail recursive. *)
608 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
610 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
611 [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
612 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
617 (** [operand v i] returns the operand at index [i] for the value [v]. See the
618 method [llvm::User::getOperand]. *)
619 val operand : llvalue -> int -> llvalue
621 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
623 See the method [llvm::User::setOperand]. *)
624 val set_operand : llvalue -> int -> llvalue -> unit
626 (** [num_operands v] returns the number of operands for the value [v].
627 See the method [llvm::User::getNumOperands]. *)
628 val num_operands : llvalue -> int
630 (** {7 Operations on constants of (mostly) any type} *)
632 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
633 otherwise. Similar to [llvm::isa<Constant>]. *)
634 val is_constant : llvalue -> bool
636 (** [const_null ty] returns the constant null (zero) of the type [ty].
637 See the method [llvm::Constant::getNullValue]. *)
638 val const_null : lltype -> llvalue
640 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
641 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
642 val const_all_ones : (*int|vec*)lltype -> llvalue
644 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
645 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
646 val const_pointer_null : lltype -> llvalue
648 (** [undef ty] returns the undefined value of the type [ty].
649 See the method [llvm::UndefValue::get]. *)
650 val undef : lltype -> llvalue
652 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
653 See the method [llvm::Constant::isNullValue]. *)
654 val is_null : llvalue -> bool
656 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
657 otherwise. Similar to [llvm::isa<UndefValue>]. *)
658 val is_undef : llvalue -> bool
660 val constexpr_opcode : llvalue -> Opcode.t
661 (** {7 Operations on instructions} *)
663 (** [has_metadata i] returns whether or not the instruction [i] has any
664 metadata attached to it. See the function
665 [llvm::Instruction::hasMetadata]. *)
666 val has_metadata : llvalue -> bool
668 (** [metadata i kind] optionally returns the metadata associated with the
669 kind [kind] in the instruction [i] See the function
670 [llvm::Instruction::getMetadata]. *)
671 val metadata : llvalue -> int -> llvalue option
673 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
674 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
675 val set_metadata : llvalue -> int -> llvalue -> unit
677 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
678 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
679 val clear_metadata : llvalue -> int -> unit
682 (** {7 Operations on metadata} *)
684 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
685 See the method [llvm::MDNode::get]. *)
686 val mdstring : llcontext -> string -> llvalue
688 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
690 See the method [llvm::MDNode::get]. *)
691 val mdnode : llcontext -> llvalue array -> llvalue
693 (** [get_mdstring v] returns the MDString.
694 * See the method [llvm::MDString::getString] *)
695 val get_mdstring : llvalue -> string option
697 (** [get_named_metadata m name] return all the MDNodes belonging to the named
699 * See the method [llvm::NamedMDNode::getOperand]. *)
700 val get_named_metadata : llmodule -> string -> llvalue array
702 (** {7 Operations on scalar constants} *)
704 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
705 See the method [llvm::ConstantInt::get]. *)
706 val const_int : lltype -> int -> llvalue
708 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
709 [i]. See the method [llvm::ConstantInt::get]. *)
710 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
712 (** [int64_of_const c] returns the int64 value of the [c] constant integer.
713 * None is returned if this is not an integer constant, or bitwidth exceeds 64.
714 * See the method [llvm::ConstantInt::getSExtValue].*)
715 val int64_of_const : llvalue -> Int64.t option
717 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
718 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
719 val const_int_of_string : lltype -> string -> int -> llvalue
722 (** [const_float ty n] returns the floating point constant of type [ty] and
723 value [n]. See the method [llvm::ConstantFP::get]. *)
724 val const_float : lltype -> float -> llvalue
726 (** [const_float_of_string ty s] returns the floating point constant of type
727 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
728 val const_float_of_string : lltype -> string -> llvalue
732 (** {7 Operations on composite constants} *)
734 (** [const_string c s] returns the constant [i8] array with the values of the
735 characters in the string [s] in the context [c]. The array is not
736 null-terminated (but see {!const_stringz}). This value can in turn be used
737 as the initializer for a global variable. See the method
738 [llvm::ConstantArray::get]. *)
739 val const_string : llcontext -> string -> llvalue
741 (** [const_stringz c s] returns the constant [i8] array with the values of the
742 characters in the string [s] and a null terminator in the context [c]. This
743 value can in turn be used as the initializer for a global variable.
744 See the method [llvm::ConstantArray::get]. *)
745 val const_stringz : llcontext -> string -> llvalue
747 (** [const_array ty elts] returns the constant array of type
748 [array_type ty (Array.length elts)] and containing the values [elts].
749 This value can in turn be used as the initializer for a global variable.
750 See the method [llvm::ConstantArray::get]. *)
751 val const_array : lltype -> llvalue array -> llvalue
753 (** [const_struct context elts] returns the structured constant of type
754 [struct_type (Array.map type_of elts)] and containing the values [elts]
755 in the context [context]. This value can in turn be used as the initializer
756 for a global variable. See the method [llvm::ConstantStruct::getAnon]. *)
757 val const_struct : llcontext -> llvalue array -> llvalue
759 (** [const_named_struct namedty elts] returns the structured constant of type
760 [namedty] (which must be a named structure type) and containing the values [elts].
761 This value can in turn be used as the initializer
762 for a global variable. See the method [llvm::ConstantStruct::get]. *)
763 val const_named_struct : lltype -> llvalue array -> llvalue
765 (** [const_packed_struct context elts] returns the structured constant of
766 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
767 values [elts] in the context [context]. This value can in turn be used as
768 the initializer for a global variable. See the method
769 [llvm::ConstantStruct::get]. *)
770 val const_packed_struct : llcontext -> llvalue array -> llvalue
773 (** [const_vector elts] returns the vector constant of type
774 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
775 values [elts]. See the method [llvm::ConstantVector::get]. *)
776 val const_vector : llvalue array -> llvalue
779 (** {7 Constant expressions} *)
781 (** [align_of ty] returns the alignof constant for the type [ty]. This is
782 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
783 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
784 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
785 val align_of : lltype -> llvalue
787 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
788 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
789 (const_int i32_type 1)) i64_type], but considerably more readable.
790 See the method [llvm::ConstantExpr::getSizeOf]. *)
791 val size_of : lltype -> llvalue
793 (** [const_neg c] returns the arithmetic negation of the constant [c].
794 See the method [llvm::ConstantExpr::getNeg]. *)
795 val const_neg : llvalue -> llvalue
797 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
798 no signed wrapping. The result is undefined if the negation overflows.
799 See the method [llvm::ConstantExpr::getNSWNeg]. *)
800 val const_nsw_neg : llvalue -> llvalue
802 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
803 no unsigned wrapping. The result is undefined if the negation overflows.
804 See the method [llvm::ConstantExpr::getNUWNeg]. *)
805 val const_nuw_neg : llvalue -> llvalue
807 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
808 See the method [llvm::ConstantExpr::getFNeg]. *)
809 val const_fneg : llvalue -> llvalue
811 (** [const_not c] returns the bitwise inverse of the constant [c].
812 See the method [llvm::ConstantExpr::getNot]. *)
813 val const_not : llvalue -> llvalue
815 (** [const_add c1 c2] returns the constant sum of two constants.
816 See the method [llvm::ConstantExpr::getAdd]. *)
817 val const_add : llvalue -> llvalue -> llvalue
819 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
820 signed wrapping. The result is undefined if the sum overflows.
821 See the method [llvm::ConstantExpr::getNSWAdd]. *)
822 val const_nsw_add : llvalue -> llvalue -> llvalue
824 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
825 unsigned wrapping. The result is undefined if the sum overflows.
826 See the method [llvm::ConstantExpr::getNSWAdd]. *)
827 val const_nuw_add : llvalue -> llvalue -> llvalue
829 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
830 See the method [llvm::ConstantExpr::getFAdd]. *)
831 val const_fadd : llvalue -> llvalue -> llvalue
833 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
834 constants. See the method [llvm::ConstantExpr::getSub]. *)
835 val const_sub : llvalue -> llvalue -> llvalue
837 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
838 no signed wrapping. The result is undefined if the sum overflows.
839 See the method [llvm::ConstantExpr::getNSWSub]. *)
840 val const_nsw_sub : llvalue -> llvalue -> llvalue
842 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
843 no unsigned wrapping. The result is undefined if the sum overflows.
844 See the method [llvm::ConstantExpr::getNSWSub]. *)
845 val const_nuw_sub : llvalue -> llvalue -> llvalue
847 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
848 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
849 val const_fsub : llvalue -> llvalue -> llvalue
851 (** [const_mul c1 c2] returns the constant product of two constants.
852 See the method [llvm::ConstantExpr::getMul]. *)
853 val const_mul : llvalue -> llvalue -> llvalue
855 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
856 no signed wrapping. The result is undefined if the sum overflows.
857 See the method [llvm::ConstantExpr::getNSWMul]. *)
858 val const_nsw_mul : llvalue -> llvalue -> llvalue
860 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
861 no unsigned wrapping. The result is undefined if the sum overflows.
862 See the method [llvm::ConstantExpr::getNSWMul]. *)
863 val const_nuw_mul : llvalue -> llvalue -> llvalue
865 (** [const_fmul c1 c2] returns the constant product of two constants floats.
866 See the method [llvm::ConstantExpr::getFMul]. *)
867 val const_fmul : llvalue -> llvalue -> llvalue
869 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
871 See the method [llvm::ConstantExpr::getUDiv]. *)
872 val const_udiv : llvalue -> llvalue -> llvalue
874 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
876 See the method [llvm::ConstantExpr::getSDiv]. *)
877 val const_sdiv : llvalue -> llvalue -> llvalue
879 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
880 signed integer constants. The result is undefined if the result is rounded
881 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
882 val const_exact_sdiv : llvalue -> llvalue -> llvalue
884 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
886 See the method [llvm::ConstantExpr::getFDiv]. *)
887 val const_fdiv : llvalue -> llvalue -> llvalue
889 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
890 unsigned integer constants.
891 See the method [llvm::ConstantExpr::getURem]. *)
892 val const_urem : llvalue -> llvalue -> llvalue
894 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
895 signed integer constants.
896 See the method [llvm::ConstantExpr::getSRem]. *)
897 val const_srem : llvalue -> llvalue -> llvalue
899 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
900 signed floating point constants.
901 See the method [llvm::ConstantExpr::getFRem]. *)
902 val const_frem : llvalue -> llvalue -> llvalue
904 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
906 See the method [llvm::ConstantExpr::getAnd]. *)
907 val const_and : llvalue -> llvalue -> llvalue
909 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
911 See the method [llvm::ConstantExpr::getOr]. *)
912 val const_or : llvalue -> llvalue -> llvalue
914 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
916 See the method [llvm::ConstantExpr::getXor]. *)
917 val const_xor : llvalue -> llvalue -> llvalue
919 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
920 constants, [c1 pred c2].
921 See the method [llvm::ConstantExpr::getICmp]. *)
922 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
925 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
926 point constants, [c1 pred c2].
927 See the method [llvm::ConstantExpr::getFCmp]. *)
928 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
931 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
932 constant integer [c2].
933 See the method [llvm::ConstantExpr::getShl]. *)
934 val const_shl : llvalue -> llvalue -> llvalue
936 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
937 constant integer [c2] with zero extension.
938 See the method [llvm::ConstantExpr::getLShr]. *)
939 val const_lshr : llvalue -> llvalue -> llvalue
941 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
942 constant integer [c2] with sign extension.
943 See the method [llvm::ConstantExpr::getAShr]. *)
944 val const_ashr : llvalue -> llvalue -> llvalue
946 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
947 constant integers indices from the array [indices].
948 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
949 val const_gep : llvalue -> llvalue array -> llvalue
951 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
952 with the constant integers indices from the array [indices].
953 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
954 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
957 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
958 to the smaller integer type [ty].
959 See the method [llvm::ConstantExpr::getTrunc]. *)
960 val const_trunc : llvalue -> lltype -> llvalue
962 (** [const_sext c ty] returns the constant sign extension of integer constant
963 [c] to the larger integer type [ty].
964 See the method [llvm::ConstantExpr::getSExt]. *)
965 val const_sext : llvalue -> lltype -> llvalue
967 (** [const_zext c ty] returns the constant zero extension of integer constant
968 [c] to the larger integer type [ty].
969 See the method [llvm::ConstantExpr::getZExt]. *)
970 val const_zext : llvalue -> lltype -> llvalue
972 (** [const_fptrunc c ty] returns the constant truncation of floating point
973 constant [c] to the smaller floating point type [ty].
974 See the method [llvm::ConstantExpr::getFPTrunc]. *)
975 val const_fptrunc : llvalue -> lltype -> llvalue
977 (** [const_fpext c ty] returns the constant extension of floating point constant
978 [c] to the larger floating point type [ty].
979 See the method [llvm::ConstantExpr::getFPExt]. *)
980 val const_fpext : llvalue -> lltype -> llvalue
982 (** [const_uitofp c ty] returns the constant floating point conversion of
983 unsigned integer constant [c] to the floating point type [ty].
984 See the method [llvm::ConstantExpr::getUIToFP]. *)
985 val const_uitofp : llvalue -> lltype -> llvalue
987 (** [const_sitofp c ty] returns the constant floating point conversion of
988 signed integer constant [c] to the floating point type [ty].
989 See the method [llvm::ConstantExpr::getSIToFP]. *)
990 val const_sitofp : llvalue -> lltype -> llvalue
992 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
993 floating point constant [c] to integer type [ty].
994 See the method [llvm::ConstantExpr::getFPToUI]. *)
995 val const_fptoui : llvalue -> lltype -> llvalue
997 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
998 floating point constant [c] to integer type [ty].
999 See the method [llvm::ConstantExpr::getFPToSI]. *)
1000 val const_fptosi : llvalue -> lltype -> llvalue
1002 (** [const_ptrtoint c ty] returns the constant integer conversion of
1003 pointer constant [c] to integer type [ty].
1004 See the method [llvm::ConstantExpr::getPtrToInt]. *)
1005 val const_ptrtoint : llvalue -> lltype -> llvalue
1007 (** [const_inttoptr c ty] returns the constant pointer conversion of
1008 integer constant [c] to pointer type [ty].
1009 See the method [llvm::ConstantExpr::getIntToPtr]. *)
1010 val const_inttoptr : llvalue -> lltype -> llvalue
1012 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
1013 to type [ty] of equal size.
1014 See the method [llvm::ConstantExpr::getBitCast]. *)
1015 val const_bitcast : llvalue -> lltype -> llvalue
1017 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
1018 conversion of constant [c] to type [ty].
1019 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
1020 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
1023 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
1024 conversion of constant [c] to type [ty].
1025 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
1026 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
1029 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
1030 conversion of constant [c] to type [ty].
1031 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
1032 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
1041 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
1042 -> integer casts of constant [c] to type [ty].
1043 See the method [llvm::ConstantExpr::getIntCast]. *)
1044 val const_intcast : llvalue -> lltype -> llvalue
1047 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
1048 fp casts of constant [c] to type [ty].
1049 See the method [llvm::ConstantExpr::getFPCast]. *)
1050 val const_fpcast : llvalue -> lltype -> llvalue
1053 (** [const_select cond t f] returns the constant conditional which returns value
1054 [t] if the boolean constant [cond] is true and the value [f] otherwise.
1055 See the method [llvm::ConstantExpr::getSelect]. *)
1056 val const_select : llvalue -> llvalue -> llvalue -> llvalue
1059 (** [const_extractelement vec i] returns the constant [i]th element of
1060 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
1061 the size of the vector.
1062 See the method [llvm::ConstantExpr::getExtractElement]. *)
1063 val const_extractelement : llvalue -> llvalue -> llvalue
1066 (** [const_insertelement vec v i] returns the constant vector with the same
1067 elements as constant vector [v] but the [i]th element replaced by the
1068 constant [v]. [v] must be a constant value with the type of the vector
1069 elements. [i] must be a constant [i32] value unsigned less than the size
1071 See the method [llvm::ConstantExpr::getInsertElement]. *)
1072 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
1075 (** [const_shufflevector a b mask] returns a constant [shufflevector].
1076 See the LLVM Language Reference for details on the [shufflevector]
1078 See the method [llvm::ConstantExpr::getShuffleVector]. *)
1079 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
1082 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
1083 constant aggregate [agg]. Each [idxs] must be less than the size of the
1084 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
1085 val const_extractvalue : llvalue -> int array -> llvalue
1088 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
1089 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
1090 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
1091 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
1094 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
1095 See the method [llvm::InlineAsm::get]. *)
1096 val const_inline_asm : lltype -> string -> string -> bool -> bool ->
1100 (** [block_address f bb] returns the address of the basic block [bb] in the
1101 function [f]. See the method [llvm::BasicBlock::get]. *)
1102 val block_address : llvalue -> llbasicblock -> llvalue
1105 (** {7 Operations on global variables, functions, and aliases (globals)} *)
1107 (** [global_parent g] is the enclosing module of the global value [g].
1108 See the method [llvm::GlobalValue::getParent]. *)
1109 val global_parent : llvalue -> llmodule
1111 (** [is_declaration g] returns [true] if the global value [g] is a declaration
1112 only. Returns [false] otherwise.
1113 See the method [llvm::GlobalValue::isDeclaration]. *)
1114 val is_declaration : llvalue -> bool
1116 (** [linkage g] returns the linkage of the global value [g].
1117 See the method [llvm::GlobalValue::getLinkage]. *)
1118 val linkage : llvalue -> Linkage.t
1120 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
1121 See the method [llvm::GlobalValue::setLinkage]. *)
1122 val set_linkage : Linkage.t -> llvalue -> unit
1124 (** [section g] returns the linker section of the global value [g].
1125 See the method [llvm::GlobalValue::getSection]. *)
1126 val section : llvalue -> string
1128 (** [set_section s g] sets the linker section of the global value [g] to [s].
1129 See the method [llvm::GlobalValue::setSection]. *)
1130 val set_section : string -> llvalue -> unit
1132 (** [visibility g] returns the linker visibility of the global value [g].
1133 See the method [llvm::GlobalValue::getVisibility]. *)
1134 val visibility : llvalue -> Visibility.t
1136 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1137 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1138 val set_visibility : Visibility.t -> llvalue -> unit
1141 (** [alignment g] returns the required alignment of the global value [g].
1142 See the method [llvm::GlobalValue::getAlignment]. *)
1143 val alignment : llvalue -> int
1145 (** [set_alignment n g] sets the required alignment of the global value [g] to
1146 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1147 val set_alignment : int -> llvalue -> unit
1150 (** {7 Operations on global variables} *)
1152 (** [declare_global ty name m] returns a new global variable of type [ty] and
1153 with name [name] in module [m] in the default address space (0). If such a
1154 global variable already exists, it is returned. If the type of the existing
1155 global differs, then a bitcast to [ty] is returned. *)
1156 val declare_global : lltype -> string -> llmodule -> llvalue
1159 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1160 of type [ty] and with name [name] in module [m] in the address space
1161 [addrspace]. If such a global variable already exists, it is returned. If
1162 the type of the existing global differs, then a bitcast to [ty] is
1164 val declare_qualified_global : lltype -> string -> int -> llmodule ->
1168 (** [define_global name init m] returns a new global with name [name] and
1169 initializer [init] in module [m] in the default address space (0). If the
1170 named global already exists, it is renamed.
1171 See the constructor of [llvm::GlobalVariable]. *)
1172 val define_global : string -> llvalue -> llmodule -> llvalue
1175 (** [define_qualified_global name init addrspace m] returns a new global with
1176 name [name] and initializer [init] in module [m] in the address space
1177 [addrspace]. If the named global already exists, it is renamed.
1178 See the constructor of [llvm::GlobalVariable]. *)
1179 val define_qualified_global : string -> llvalue -> int -> llmodule ->
1183 (** [lookup_global name m] returns [Some g] if a global variable with name
1184 [name] exists in module [m]. If no such global exists, returns [None].
1185 See the [llvm::GlobalVariable] constructor. *)
1186 val lookup_global : string -> llmodule -> llvalue option
1189 (** [delete_global gv] destroys the global variable [gv].
1190 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1191 val delete_global : llvalue -> unit
1193 (** [global_begin m] returns the first position in the global variable list of
1194 the module [m]. [global_begin] and [global_succ] can be used to iterate
1195 over the global list in order.
1196 See the method [llvm::Module::global_begin]. *)
1197 val global_begin : llmodule -> (llmodule, llvalue) llpos
1200 (** [global_succ gv] returns the global variable list position succeeding
1202 See the method [llvm::Module::global_iterator::operator++]. *)
1203 val global_succ : llvalue -> (llmodule, llvalue) llpos
1206 (** [iter_globals f m] applies function [f] to each of the global variables of
1207 module [m] in order. Tail recursive. *)
1208 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1210 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1211 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1212 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1214 (** [global_end m] returns the last position in the global variable list of the
1215 module [m]. [global_end] and [global_pred] can be used to iterate over the
1216 global list in reverse.
1217 See the method [llvm::Module::global_end]. *)
1218 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1221 (** [global_pred gv] returns the global variable list position preceding
1223 See the method [llvm::Module::global_iterator::operator--]. *)
1224 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1227 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1228 of module [m] in reverse order. Tail recursive. *)
1229 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1231 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1232 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1233 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1235 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1236 constant. Returns [false] otherwise.
1237 See the method [llvm::GlobalVariable::isConstant]. *)
1238 val is_global_constant : llvalue -> bool
1240 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1241 [c] is [true] and not if [c] is [false].
1242 See the method [llvm::GlobalVariable::setConstant]. *)
1243 val set_global_constant : bool -> llvalue -> unit
1246 (** [global_initializer gv] returns the initializer for the global variable
1247 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1248 val global_initializer : llvalue -> llvalue
1250 (** [set_initializer c gv] sets the initializer for the global variable
1251 [gv] to the constant [c].
1252 See the method [llvm::GlobalVariable::setInitializer]. *)
1253 val set_initializer : llvalue -> llvalue -> unit
1255 (** [remove_initializer gv] unsets the initializer for the global variable
1257 See the method [llvm::GlobalVariable::setInitializer]. *)
1258 val remove_initializer : llvalue -> unit
1260 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1261 thread-local and [false] otherwise.
1262 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1263 val is_thread_local : llvalue -> bool
1265 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1266 [c] is [true] and not otherwise.
1267 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1268 val set_thread_local : bool -> llvalue -> unit
1271 (** {7 Operations on aliases} *)
1273 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1274 the aliasee [a] with the name [n].
1275 See the constructor for [llvm::GlobalAlias]. *)
1276 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1280 (** {7 Operations on functions} *)
1282 (** [declare_function name ty m] returns a new function of type [ty] and
1283 with name [name] in module [m]. If such a function already exists,
1284 it is returned. If the type of the existing function differs, then a bitcast
1285 to [ty] is returned. *)
1286 val declare_function : string -> lltype -> llmodule -> llvalue
1289 (** [define_function name ty m] creates a new function with name [name] and
1290 type [ty] in module [m]. If the named function already exists, it is
1291 renamed. An entry basic block is created in the function.
1292 See the constructor of [llvm::GlobalVariable]. *)
1293 val define_function : string -> lltype -> llmodule -> llvalue
1296 (** [lookup_function name m] returns [Some f] if a function with name
1297 [name] exists in module [m]. If no such function exists, returns [None].
1298 See the method [llvm::Module] constructor. *)
1299 val lookup_function : string -> llmodule -> llvalue option
1302 (** [delete_function f] destroys the function [f].
1303 See the method [llvm::Function::eraseFromParent]. *)
1304 val delete_function : llvalue -> unit
1306 (** [function_begin m] returns the first position in the function list of the
1307 module [m]. [function_begin] and [function_succ] can be used to iterate over
1308 the function list in order.
1309 See the method [llvm::Module::begin]. *)
1310 val function_begin : llmodule -> (llmodule, llvalue) llpos
1313 (** [function_succ gv] returns the function list position succeeding
1315 See the method [llvm::Module::iterator::operator++]. *)
1316 val function_succ : llvalue -> (llmodule, llvalue) llpos
1319 (** [iter_functions f m] applies function [f] to each of the functions of module
1320 [m] in order. Tail recursive. *)
1321 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1323 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1324 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1325 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1327 (** [function_end m] returns the last position in the function list of
1328 the module [m]. [function_end] and [function_pred] can be used to iterate
1329 over the function list in reverse.
1330 See the method [llvm::Module::end]. *)
1331 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1334 (** [function_pred gv] returns the function list position preceding [After gv].
1335 See the method [llvm::Module::iterator::operator--]. *)
1336 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1339 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1340 module [m] in reverse order. Tail recursive. *)
1341 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1343 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1344 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1345 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1347 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1348 See the method [llvm::Function::isIntrinsic]. *)
1349 val is_intrinsic : llvalue -> bool
1351 (** [function_call_conv f] returns the calling convention of the function [f].
1352 See the method [llvm::Function::getCallingConv]. *)
1353 val function_call_conv : llvalue -> int
1355 (** [set_function_call_conv cc f] sets the calling convention of the function
1356 [f] to the calling convention numbered [cc].
1357 See the method [llvm::Function::setCallingConv]. *)
1358 val set_function_call_conv : int -> llvalue -> unit
1361 (** [gc f] returns [Some name] if the function [f] has a garbage
1362 collection algorithm specified and [None] otherwise.
1363 See the method [llvm::Function::getGC]. *)
1364 val gc : llvalue -> string option
1366 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1367 [gc]. See the method [llvm::Function::setGC]. *)
1368 val set_gc : string option -> llvalue -> unit
1370 (** [add_function_attr f a] adds attribute [a] to the return type of function
1372 val add_function_attr : llvalue -> Attribute.t -> unit
1374 (** [function_attr f] returns the function attribute for the function [f].
1375 * See the method [llvm::Function::getAttributes] *)
1376 val function_attr : llvalue -> Attribute.t list
1378 (** [remove_function_attr f a] removes attribute [a] from the return type of
1380 val remove_function_attr : llvalue -> Attribute.t -> unit
1382 (** {7 Operations on params} *)
1384 (** [params f] returns the parameters of function [f].
1385 See the method [llvm::Function::getArgumentList]. *)
1386 val params : llvalue -> llvalue array
1388 (** [param f n] returns the [n]th parameter of function [f].
1389 See the method [llvm::Function::getArgumentList]. *)
1390 val param : llvalue -> int -> llvalue
1392 (** [param_attr p] returns the attributes of parameter [p].
1393 * See the methods [llvm::Function::getAttributes] and
1394 * [llvm::Attributes::getParamAttributes] *)
1395 val param_attr : llvalue -> Attribute.t list
1397 (** [param_parent p] returns the parent function that owns the parameter.
1398 See the method [llvm::Argument::getParent]. *)
1399 val param_parent : llvalue -> llvalue
1401 (** [param_begin f] returns the first position in the parameter list of the
1402 function [f]. [param_begin] and [param_succ] can be used to iterate over
1403 the parameter list in order.
1404 See the method [llvm::Function::arg_begin]. *)
1405 val param_begin : llvalue -> (llvalue, llvalue) llpos
1407 (** [param_succ bb] returns the parameter list position succeeding
1409 See the method [llvm::Function::arg_iterator::operator++]. *)
1410 val param_succ : llvalue -> (llvalue, llvalue) llpos
1412 (** [iter_params f fn] applies function [f] to each of the parameters
1413 of function [fn] in order. Tail recursive. *)
1414 val iter_params : (llvalue -> unit) -> llvalue -> unit
1416 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1417 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1418 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1420 (** [param_end f] returns the last position in the parameter list of
1421 the function [f]. [param_end] and [param_pred] can be used to iterate
1422 over the parameter list in reverse.
1423 See the method [llvm::Function::arg_end]. *)
1424 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1426 (** [param_pred gv] returns the function list position preceding [After gv].
1427 See the method [llvm::Function::arg_iterator::operator--]. *)
1428 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1431 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1432 of function [fn] in reverse order. Tail recursive. *)
1433 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1435 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1436 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1437 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1439 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1440 val add_param_attr : llvalue -> Attribute.t -> unit
1442 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1443 val remove_param_attr : llvalue -> Attribute.t -> unit
1445 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1446 val set_param_alignment : llvalue -> int -> unit
1449 (** {7 Operations on basic blocks} *)
1451 (** [basic_blocks fn] returns the basic blocks of the function [f].
1452 See the method [llvm::Function::getBasicBlockList]. *)
1453 val basic_blocks : llvalue -> llbasicblock array
1455 (** [entry_block fn] returns the entry basic block of the function [f].
1456 See the method [llvm::Function::getEntryBlock]. *)
1457 val entry_block : llvalue -> llbasicblock
1459 (** [delete_block bb] deletes the basic block [bb].
1460 See the method [llvm::BasicBlock::eraseFromParent]. *)
1461 val delete_block : llbasicblock -> unit
1463 (** [append_block c name f] creates a new basic block named [name] at the end of
1464 function [f] in the context [c].
1465 See the constructor of [llvm::BasicBlock]. *)
1466 val append_block : llcontext -> string -> llvalue -> llbasicblock
1469 (** [insert_block c name bb] creates a new basic block named [name] before the
1470 basic block [bb] in the context [c].
1471 See the constructor of [llvm::BasicBlock]. *)
1472 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1475 (** [block_parent bb] returns the parent function that owns the basic block.
1476 See the method [llvm::BasicBlock::getParent]. *)
1477 val block_parent : llbasicblock -> llvalue
1479 (** [block_begin f] returns the first position in the basic block list of the
1480 function [f]. [block_begin] and [block_succ] can be used to iterate over
1481 the basic block list in order.
1482 See the method [llvm::Function::begin]. *)
1483 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1486 (** [block_succ bb] returns the basic block list position succeeding
1488 See the method [llvm::Function::iterator::operator++]. *)
1489 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1492 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1493 of function [fn] in order. Tail recursive. *)
1494 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1496 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1497 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1498 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1500 (** [block_end f] returns the last position in the basic block list of
1501 the function [f]. [block_end] and [block_pred] can be used to iterate
1502 over the basic block list in reverse.
1503 See the method [llvm::Function::end]. *)
1504 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1507 (** [block_pred gv] returns the function list position preceding [After gv].
1508 See the method [llvm::Function::iterator::operator--]. *)
1509 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1512 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1513 of function [fn] in reverse order. Tail recursive. *)
1514 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1516 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1517 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1518 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1520 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1521 val value_of_block : llbasicblock -> llvalue
1523 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1525 Similar to [llvm::isa<BasicBlock>]. *)
1526 val value_is_block : llvalue -> bool
1528 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1529 val block_of_value : llvalue -> llbasicblock
1532 (** {7 Operations on instructions} *)
1534 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1535 See the method [llvm::Instruction::getParent]. *)
1536 val instr_parent : llvalue -> llbasicblock
1538 (** [instr_begin bb] returns the first position in the instruction list of the
1539 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1540 the instruction list in order.
1541 See the method [llvm::BasicBlock::begin]. *)
1542 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1545 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1546 See the method [llvm::BasicBlock::iterator::operator++]. *)
1547 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1550 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1551 block [bb] in order. Tail recursive. *)
1552 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1554 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1555 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1556 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1558 (** [instr_end bb] returns the last position in the instruction list of the
1559 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1560 the instruction list in reverse.
1561 See the method [llvm::BasicBlock::end]. *)
1562 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1565 (** [instr_pred i] returns the instruction list position preceding [After i].
1566 See the method [llvm::BasicBlock::iterator::operator--]. *)
1567 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1570 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1571 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1572 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1574 val instr_opcode : llvalue -> Opcode.t
1576 val icmp_predicate : llvalue -> Icmp.t option
1578 (** {7 Operations on call sites} *)
1580 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1581 instruction [ci], which may be one of the values from the module
1582 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1583 [llvm::InvokeInst::getCallingConv]. *)
1584 val instruction_call_conv: llvalue -> int
1587 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1588 or invoke instruction [ci] to the integer [cc], which can be one of the
1589 values from the module {!CallConv}.
1590 See the method [llvm::CallInst::setCallingConv]
1591 and [llvm::InvokeInst::setCallingConv]. *)
1592 val set_instruction_call_conv: int -> llvalue -> unit
1595 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1596 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1598 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1600 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1601 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1603 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1605 (** {Operations on call instructions (only)} *)
1607 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1608 eligible for tail call optimization, [false] otherwise.
1609 See the method [llvm::CallInst::isTailCall]. *)
1610 val is_tail_call : llvalue -> bool
1612 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1613 call optimization if [tc] is [true], clears otherwise.
1614 See the method [llvm::CallInst::setTailCall]. *)
1615 val set_tail_call : bool -> llvalue -> unit
1617 (** {7 Operations on phi nodes} *)
1619 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1620 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1621 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1624 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1625 See the method [llvm::PHINode::getIncomingValue]. *)
1626 val incoming : llvalue -> (llvalue * llbasicblock) list
1630 (** {6 Instruction builders} *)
1632 (** [builder context] creates an instruction builder with no position in
1633 the context [context]. It is invalid to use this builder until its position
1634 is set with {!position_before} or {!position_at_end}. See the constructor
1635 for [llvm::LLVMBuilder]. *)
1636 val builder : llcontext -> llbuilder
1638 (** [builder_at ip] creates an instruction builder positioned at [ip].
1639 See the constructor for [llvm::LLVMBuilder]. *)
1640 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1642 (** [builder_before ins] creates an instruction builder positioned before the
1643 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1644 val builder_before : llcontext -> llvalue -> llbuilder
1646 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1647 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1648 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1650 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1652 See the constructor for [llvm::LLVMBuilder]. *)
1653 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1656 (** [position_before ins b] moves the instruction builder [b] to before the
1657 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1658 val position_before : llvalue -> llbuilder -> unit
1660 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1661 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1662 val position_at_end : llbasicblock -> llbuilder -> unit
1664 (** [insertion_block b] returns the basic block that the builder [b] is
1665 positioned to insert into. Raises [Not_Found] if the instruction builder is
1667 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1668 val insertion_block : llbuilder -> llbasicblock
1670 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1671 position specified by the instruction builder [b].
1672 See the method [llvm::LLVMBuilder::Insert]. *)
1673 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1678 (** [set_current_debug_location b md] sets the current debug location [md] in
1680 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1681 val set_current_debug_location : llbuilder -> llvalue -> unit
1684 (** [clear_current_debug_location b] clears the current debug location in the
1686 val clear_current_debug_location : llbuilder -> unit
1689 (** [current_debug_location b] returns the current debug location, or None
1690 if none is currently set.
1691 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1692 val current_debug_location : llbuilder -> llvalue option
1695 (** [set_inst_debug_location b i] sets the current debug location of the builder
1696 [b] to the instruction [i].
1697 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1698 val set_inst_debug_location : llbuilder -> llvalue -> unit
1701 (** {7 Terminators} *)
1703 (** [build_ret_void b] creates a
1705 instruction at the position specified by the instruction builder [b].
1706 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1707 val build_ret_void : llbuilder -> llvalue
1709 (** [build_ret v b] creates a
1711 instruction at the position specified by the instruction builder [b].
1712 See the method [llvm::LLVMBuilder::CreateRet]. *)
1713 val build_ret : llvalue -> llbuilder -> llvalue
1715 (** [build_aggregate_ret vs b] creates a
1716 [ret {...} { %v1, %v2, ... } ]
1717 instruction at the position specified by the instruction builder [b].
1718 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1719 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1722 (** [build_br bb b] creates a
1724 instruction at the position specified by the instruction builder [b].
1725 See the method [llvm::LLVMBuilder::CreateBr]. *)
1726 val build_br : llbasicblock -> llbuilder -> llvalue
1728 (** [build_cond_br cond tbb fbb b] creates a
1729 [br %cond, %tbb, %fbb]
1730 instruction at the position specified by the instruction builder [b].
1731 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1732 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1735 (** [build_switch case elsebb count b] creates an empty
1736 [switch %case, %elsebb]
1737 instruction at the position specified by the instruction builder [b] with
1738 space reserved for [count] cases.
1739 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1740 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1743 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1744 when its input matches the constant [onval].
1745 See the method [llvm::SwitchInst::addCase]. **)
1746 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1749 (** [build_indirect_br addr count b] creates a
1751 instruction at the position specified by the instruction builder [b] with
1752 space reserved for [count] destinations.
1753 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1754 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1757 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1758 location for the indirectbr instruction [br].
1759 See the method [llvm::IndirectBrInst::addDestination]. **)
1760 val add_destination : llvalue -> llbasicblock -> unit
1763 (** [build_invoke fn args tobb unwindbb name b] creates an
1764 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1765 instruction at the position specified by the instruction builder [b].
1766 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1767 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1768 llbasicblock -> string -> llbuilder -> llvalue
1770 (** [build_landingpad ty persfn numclauses name b] creates an
1772 instruction at the position specified by the instruction builder [b].
1773 See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
1774 val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
1777 (** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
1778 See the method [llvm::LandingPadInst::setCleanup]. *)
1779 val set_cleanup : llvalue -> bool -> unit
1781 (** [build_unreachable b] creates an
1783 instruction at the position specified by the instruction builder [b].
1784 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1785 val build_unreachable : llbuilder -> llvalue
1788 (** {7 Arithmetic} *)
1790 (** [build_add x y name b] creates a
1791 [%name = add %x, %y]
1792 instruction at the position specified by the instruction builder [b].
1793 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1794 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1797 (** [build_nsw_add x y name b] creates a
1798 [%name = nsw add %x, %y]
1799 instruction at the position specified by the instruction builder [b].
1800 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1801 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1804 (** [build_nuw_add x y name b] creates a
1805 [%name = nuw add %x, %y]
1806 instruction at the position specified by the instruction builder [b].
1807 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1808 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1811 (** [build_fadd x y name b] creates a
1812 [%name = fadd %x, %y]
1813 instruction at the position specified by the instruction builder [b].
1814 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1815 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1818 (** [build_sub x y name b] creates a
1819 [%name = sub %x, %y]
1820 instruction at the position specified by the instruction builder [b].
1821 See the method [llvm::LLVMBuilder::CreateSub]. *)
1822 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1825 (** [build_nsw_sub x y name b] creates a
1826 [%name = nsw sub %x, %y]
1827 instruction at the position specified by the instruction builder [b].
1828 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1829 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1832 (** [build_nuw_sub x y name b] creates a
1833 [%name = nuw sub %x, %y]
1834 instruction at the position specified by the instruction builder [b].
1835 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1836 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1839 (** [build_fsub x y name b] creates a
1840 [%name = fsub %x, %y]
1841 instruction at the position specified by the instruction builder [b].
1842 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1843 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1846 (** [build_mul x y name b] creates a
1847 [%name = mul %x, %y]
1848 instruction at the position specified by the instruction builder [b].
1849 See the method [llvm::LLVMBuilder::CreateMul]. *)
1850 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1853 (** [build_nsw_mul x y name b] creates a
1854 [%name = nsw mul %x, %y]
1855 instruction at the position specified by the instruction builder [b].
1856 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1857 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1860 (** [build_nuw_mul x y name b] creates a
1861 [%name = nuw mul %x, %y]
1862 instruction at the position specified by the instruction builder [b].
1863 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1864 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1867 (** [build_fmul x y name b] creates a
1868 [%name = fmul %x, %y]
1869 instruction at the position specified by the instruction builder [b].
1870 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1871 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1874 (** [build_udiv x y name b] creates a
1875 [%name = udiv %x, %y]
1876 instruction at the position specified by the instruction builder [b].
1877 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1878 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1881 (** [build_sdiv x y name b] creates a
1882 [%name = sdiv %x, %y]
1883 instruction at the position specified by the instruction builder [b].
1884 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1885 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1888 (** [build_exact_sdiv x y name b] creates a
1889 [%name = exact sdiv %x, %y]
1890 instruction at the position specified by the instruction builder [b].
1891 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1892 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1895 (** [build_fdiv x y name b] creates a
1896 [%name = fdiv %x, %y]
1897 instruction at the position specified by the instruction builder [b].
1898 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1899 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1902 (** [build_urem x y name b] creates a
1903 [%name = urem %x, %y]
1904 instruction at the position specified by the instruction builder [b].
1905 See the method [llvm::LLVMBuilder::CreateURem]. *)
1906 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1909 (** [build_SRem x y name b] creates a
1910 [%name = srem %x, %y]
1911 instruction at the position specified by the instruction builder [b].
1912 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1913 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1916 (** [build_frem x y name b] creates a
1917 [%name = frem %x, %y]
1918 instruction at the position specified by the instruction builder [b].
1919 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1920 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1923 (** [build_shl x y name b] creates a
1924 [%name = shl %x, %y]
1925 instruction at the position specified by the instruction builder [b].
1926 See the method [llvm::LLVMBuilder::CreateShl]. *)
1927 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1930 (** [build_lshr x y name b] creates a
1931 [%name = lshr %x, %y]
1932 instruction at the position specified by the instruction builder [b].
1933 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1934 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1937 (** [build_ashr x y name b] creates a
1938 [%name = ashr %x, %y]
1939 instruction at the position specified by the instruction builder [b].
1940 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1941 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1944 (** [build_and x y name b] creates a
1945 [%name = and %x, %y]
1946 instruction at the position specified by the instruction builder [b].
1947 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1948 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1951 (** [build_or x y name b] creates a
1953 instruction at the position specified by the instruction builder [b].
1954 See the method [llvm::LLVMBuilder::CreateOr]. *)
1955 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1958 (** [build_xor x y name b] creates a
1959 [%name = xor %x, %y]
1960 instruction at the position specified by the instruction builder [b].
1961 See the method [llvm::LLVMBuilder::CreateXor]. *)
1962 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1965 (** [build_neg x name b] creates a
1967 instruction at the position specified by the instruction builder [b].
1968 [-0.0] is used for floating point types to compute the correct sign.
1969 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1970 val build_neg : llvalue -> string -> llbuilder -> llvalue
1973 (** [build_nsw_neg x name b] creates a
1974 [%name = nsw sub 0, %x]
1975 instruction at the position specified by the instruction builder [b].
1976 [-0.0] is used for floating point types to compute the correct sign.
1977 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1978 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1981 (** [build_nuw_neg x name b] creates a
1982 [%name = nuw sub 0, %x]
1983 instruction at the position specified by the instruction builder [b].
1984 [-0.0] is used for floating point types to compute the correct sign.
1985 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1986 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1989 (** [build_fneg x name b] creates a
1990 [%name = fsub 0, %x]
1991 instruction at the position specified by the instruction builder [b].
1992 [-0.0] is used for floating point types to compute the correct sign.
1993 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1994 val build_fneg : llvalue -> string -> llbuilder -> llvalue
1997 (** [build_xor x name b] creates a
1998 [%name = xor %x, -1]
1999 instruction at the position specified by the instruction builder [b].
2000 [-1] is the correct "all ones" value for the type of [x].
2001 See the method [llvm::LLVMBuilder::CreateXor]. *)
2002 val build_not : llvalue -> string -> llbuilder -> llvalue
2008 (** [build_alloca ty name b] creates a
2009 [%name = alloca %ty]
2010 instruction at the position specified by the instruction builder [b].
2011 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2012 val build_alloca : lltype -> string -> llbuilder -> llvalue
2015 (** [build_array_alloca ty n name b] creates a
2016 [%name = alloca %ty, %n]
2017 instruction at the position specified by the instruction builder [b].
2018 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
2019 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
2022 (** [build_load v name b] creates a
2024 instruction at the position specified by the instruction builder [b].
2025 See the method [llvm::LLVMBuilder::CreateLoad]. *)
2026 val build_load : llvalue -> string -> llbuilder -> llvalue
2029 (** [build_store v p b] creates a
2031 instruction at the position specified by the instruction builder [b].
2032 See the method [llvm::LLVMBuilder::CreateStore]. *)
2033 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
2036 (** [build_gep p indices name b] creates a
2037 [%name = getelementptr %p, indices...]
2038 instruction at the position specified by the instruction builder [b].
2039 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
2040 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2043 (** [build_in_bounds_gep p indices name b] creates a
2044 [%name = gelementptr inbounds %p, indices...]
2045 instruction at the position specified by the instruction builder [b].
2046 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
2047 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
2050 (** [build_struct_gep p idx name b] creates a
2051 [%name = getelementptr %p, 0, idx]
2052 instruction at the position specified by the instruction builder [b].
2053 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
2054 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
2057 (** [build_global_string str name b] creates a series of instructions that adds
2058 a global string at the position specified by the instruction builder [b].
2059 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
2060 val build_global_string : string -> string -> llbuilder -> llvalue
2063 (** [build_global_stringptr str name b] creates a series of instructions that
2064 adds a global string pointer at the position specified by the instruction
2066 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
2067 val build_global_stringptr : string -> string -> llbuilder -> llvalue
2073 (** [build_trunc v ty name b] creates a
2074 [%name = trunc %p to %ty]
2075 instruction at the position specified by the instruction builder [b].
2076 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
2077 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2080 (** [build_zext v ty name b] creates a
2081 [%name = zext %p to %ty]
2082 instruction at the position specified by the instruction builder [b].
2083 See the method [llvm::LLVMBuilder::CreateZExt]. *)
2084 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
2087 (** [build_sext v ty name b] creates a
2088 [%name = sext %p to %ty]
2089 instruction at the position specified by the instruction builder [b].
2090 See the method [llvm::LLVMBuilder::CreateSExt]. *)
2091 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
2094 (** [build_fptoui v ty name b] creates a
2095 [%name = fptoui %p to %ty]
2096 instruction at the position specified by the instruction builder [b].
2097 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
2098 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
2101 (** [build_fptosi v ty name b] creates a
2102 [%name = fptosi %p to %ty]
2103 instruction at the position specified by the instruction builder [b].
2104 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
2105 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
2108 (** [build_uitofp v ty name b] creates a
2109 [%name = uitofp %p to %ty]
2110 instruction at the position specified by the instruction builder [b].
2111 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
2112 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2115 (** [build_sitofp v ty name b] creates a
2116 [%name = sitofp %p to %ty]
2117 instruction at the position specified by the instruction builder [b].
2118 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
2119 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2122 (** [build_fptrunc v ty name b] creates a
2123 [%name = fptrunc %p to %ty]
2124 instruction at the position specified by the instruction builder [b].
2125 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
2126 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2129 (** [build_fpext v ty name b] creates a
2130 [%name = fpext %p to %ty]
2131 instruction at the position specified by the instruction builder [b].
2132 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
2133 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
2136 (** [build_ptrtoint v ty name b] creates a
2137 [%name = prtotint %p to %ty]
2138 instruction at the position specified by the instruction builder [b].
2139 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2140 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2143 (** [build_inttoptr v ty name b] creates a
2144 [%name = inttoptr %p to %ty]
2145 instruction at the position specified by the instruction builder [b].
2146 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2147 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2150 (** [build_bitcast v ty name b] creates a
2151 [%name = bitcast %p to %ty]
2152 instruction at the position specified by the instruction builder [b].
2153 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2154 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2157 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2158 instruction at the position specified by the instruction builder [b].
2159 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2160 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2163 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2164 instruction at the position specified by the instruction builder [b].
2165 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2166 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2169 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2170 instruction at the position specified by the instruction builder [b].
2171 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2172 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2175 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2176 instruction at the position specified by the instruction builder [b].
2177 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2178 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2181 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2182 instruction at the position specified by the instruction builder [b].
2183 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2184 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2187 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2188 instruction at the position specified by the instruction builder [b].
2189 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2190 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2194 (** {7 Comparisons} *)
2196 (** [build_icmp pred x y name b] creates a
2197 [%name = icmp %pred %x, %y]
2198 instruction at the position specified by the instruction builder [b].
2199 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2200 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2201 llbuilder -> llvalue
2203 (** [build_fcmp pred x y name b] creates a
2204 [%name = fcmp %pred %x, %y]
2205 instruction at the position specified by the instruction builder [b].
2206 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2207 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2208 llbuilder -> llvalue
2211 (** {7 Miscellaneous instructions} *)
2213 (** [build_phi incoming name b] creates a
2214 [%name = phi %incoming]
2215 instruction at the position specified by the instruction builder [b].
2216 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2217 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2218 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2221 (** [build_call fn args name b] creates a
2222 [%name = call %fn(args...)]
2223 instruction at the position specified by the instruction builder [b].
2224 See the method [llvm::LLVMBuilder::CreateCall]. *)
2225 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2228 (** [build_select cond thenv elsev name b] creates a
2229 [%name = select %cond, %thenv, %elsev]
2230 instruction at the position specified by the instruction builder [b].
2231 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2232 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2235 (** [build_va_arg valist argty name b] creates a
2236 [%name = va_arg %valist, %argty]
2237 instruction at the position specified by the instruction builder [b].
2238 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2239 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2242 (** [build_extractelement vec i name b] creates a
2243 [%name = extractelement %vec, %i]
2244 instruction at the position specified by the instruction builder [b].
2245 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2246 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2249 (** [build_insertelement vec elt i name b] creates a
2250 [%name = insertelement %vec, %elt, %i]
2251 instruction at the position specified by the instruction builder [b].
2252 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2253 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2254 llbuilder -> llvalue
2256 (** [build_shufflevector veca vecb mask name b] creates a
2257 [%name = shufflevector %veca, %vecb, %mask]
2258 instruction at the position specified by the instruction builder [b].
2259 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2260 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2261 llbuilder -> llvalue
2263 (** [build_insertvalue agg idx name b] creates a
2264 [%name = extractvalue %agg, %idx]
2265 instruction at the position specified by the instruction builder [b].
2266 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2267 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2270 (** [build_insertvalue agg val idx name b] creates a
2271 [%name = insertvalue %agg, %val, %idx]
2272 instruction at the position specified by the instruction builder [b].
2273 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2274 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2277 (** [build_is_null val name b] creates a
2278 [%name = icmp eq %val, null]
2279 instruction at the position specified by the instruction builder [b].
2280 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2281 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2284 (** [build_is_not_null val name b] creates a
2285 [%name = icmp ne %val, null]
2286 instruction at the position specified by the instruction builder [b].
2287 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2288 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2291 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2292 the difference between two pointer values at the position specified by the
2293 instruction builder [b].
2294 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2295 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2299 (** {6 Memory buffers} *)
2301 module MemoryBuffer : sig
2302 (** [of_file p] is the memory buffer containing the contents of the file at
2303 path [p]. If the file could not be read, then [IoError msg] is
2305 val of_file : string -> llmemorybuffer
2307 (** [stdin ()] is the memory buffer containing the contents of standard input.
2308 If standard input is empty, then [IoError msg] is raised. *)
2309 val of_stdin : unit -> llmemorybuffer
2311 (** Disposes of a memory buffer. *)
2312 val dispose : llmemorybuffer -> unit
2316 (** {6 Pass Managers} *)
2318 module PassManager : sig
2321 type any = [ `Module | `Function ]
2323 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2324 type of pipeline is suitable for link-time optimization and whole-module
2326 See the constructor of [llvm::PassManager]. *)
2327 val create : unit -> [ `Module ] t
2329 (** [PassManager.create_function m] constructs a new function-by-function
2330 pass pipeline over the module [m]. It does not take ownership of [m].
2331 This type of pipeline is suitable for code generation and JIT compilation
2333 See the constructor of [llvm::FunctionPassManager]. *)
2334 val create_function : llmodule -> [ `Function ] t
2337 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2338 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2339 any of the passes modified the module, [false] otherwise.
2340 See the [llvm::PassManager::run] method. *)
2341 val run_module : llmodule -> [ `Module ] t -> bool
2344 (** [initialize fpm] initializes all of the function passes scheduled in the
2345 function pass manager [fpm]. Returns [true] if any of the passes modified
2346 the module, [false] otherwise.
2347 See the [llvm::FunctionPassManager::doInitialization] method. *)
2348 val initialize : [ `Function ] t -> bool
2350 (** [run_function f fpm] executes all of the function passes scheduled in the
2351 function pass manager [fpm] over the function [f]. Returns [true] if any
2352 of the passes modified [f], [false] otherwise.
2353 See the [llvm::FunctionPassManager::run] method. *)
2354 val run_function : llvalue -> [ `Function ] t -> bool
2357 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2358 function pass manager [fpm]. Returns [true] if any of the passes
2359 modified the module, [false] otherwise.
2360 See the [llvm::FunctionPassManager::doFinalization] method. *)
2361 val finalize : [ `Function ] t -> bool
2363 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2365 See the destructor of [llvm::BasePassManager]. *)
2366 val dispose : [< any ] t -> unit