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
144 (** The predicate for an integer comparison ([icmp]) instruction.
145 See the [llvm::ICmpInst::Predicate] enumeration. *)
160 (** The predicate for a floating-point comparison ([fcmp]) instruction.
161 See the [llvm::FCmpInst::Predicate] enumeration. *)
182 (** The opcodes for LLVM instructions and constant expressions. *)
185 | Invalid (* not an instruction *)
186 (* Terminator Instructions *)
194 (* Standard Binary Operators *)
207 (* Logical Operators *)
214 (* Memory Operators *)
232 (* Other Operators *)
257 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
258 of [a]. [llpos] is used to specify positions in and for forward iteration
259 through the various value lists maintained by the LLVM IR. *)
260 type ('a, 'b) llpos =
264 (** [After b] and [At_start a] specify positions from the end of the ['b] list
265 of [a]. [llrev_pos] is used for reverse iteration through the various value
266 lists maintained by the LLVM IR. *)
267 type ('a, 'b) llrev_pos =
272 (** {6 Exceptions} *)
274 exception IoError of string
279 (** [create_context ()] creates a context for storing the "global" state in
280 LLVM. See the constructor [llvm::LLVMContext]. *)
281 val create_context : unit -> llcontext
283 (** [destroy_context ()] destroys a context. See the destructor
284 [llvm::LLVMContext::~LLVMContext]. *)
285 val dispose_context : llcontext -> unit
287 (** See the function [llvm::getGlobalContext]. *)
288 val global_context : unit -> llcontext
290 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
291 name [name] in the context [context]. See the function
292 [llvm::LLVMContext::getMDKindID]. *)
293 val mdkind_id : llcontext -> string -> int
298 (** [create_module context id] creates a module with the supplied module ID in
299 the context [context]. Modules are not garbage collected; it is mandatory
300 to call {!dispose_module} to free memory. See the constructor
301 [llvm::Module::Module]. *)
302 val create_module : llcontext -> string -> llmodule
304 (** [dispose_module m] destroys a module [m] and all of the IR objects it
305 contained. All references to subordinate objects are invalidated;
306 referencing them will invoke undefined behavior. See the destructor
307 [llvm::Module::~Module]. *)
308 val dispose_module : llmodule -> unit
310 (** [target_triple m] is the target specifier for the module [m], something like
311 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
312 val target_triple: llmodule -> string
315 (** [target_triple triple m] changes the target specifier for the module [m] to
316 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
317 val set_target_triple: string -> llmodule -> unit
320 (** [data_layout m] is the data layout specifier for the module [m], something
321 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
322 method [llvm::Module::getDataLayout]. *)
323 val data_layout: llmodule -> string
326 (** [set_data_layout s m] changes the data layout specifier for the module [m]
327 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
328 val set_data_layout: string -> llmodule -> unit
330 (** [dump_module m] prints the .ll representation of the module [m] to standard
331 error. See the method [llvm::Module::dump]. *)
332 val dump_module : llmodule -> unit
334 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
335 the method [llvm::Module::setModuleInlineAsm]. *)
336 val set_module_inline_asm : llmodule -> string -> unit
342 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
343 See the method [llvm::Type::getTypeID]. *)
344 val classify_type : lltype -> TypeKind.t
346 (** [type_is_sized ty] returns whether the type has a size or not.
347 * If it doesn't then it is not safe to call the [TargetData::] methods on it.
349 val type_is_sized : lltype -> bool
351 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
352 See the method [llvm::Type::getContext]. *)
353 val type_context : lltype -> llcontext
355 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
356 val string_of_lltype : lltype -> string
358 (** {7 Operations on integer types} *)
360 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
361 [llvm::Type::Int1Ty]. *)
362 val i1_type : llcontext -> lltype
364 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
365 [llvm::Type::Int8Ty]. *)
366 val i8_type : llcontext -> lltype
368 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
369 [llvm::Type::Int16Ty]. *)
370 val i16_type : llcontext -> lltype
372 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
373 [llvm::Type::Int32Ty]. *)
374 val i32_type : llcontext -> lltype
376 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
377 [llvm::Type::Int64Ty]. *)
378 val i64_type : llcontext -> lltype
380 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
381 [c]. See the method [llvm::IntegerType::get]. *)
382 val integer_type : llcontext -> int -> lltype
384 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
385 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
386 val integer_bitwidth : lltype -> int
389 (** {7 Operations on real types} *)
391 (** [float_type c] returns the IEEE 32-bit floating point type in the context
392 [c]. See [llvm::Type::FloatTy]. *)
393 val float_type : llcontext -> lltype
395 (** [double_type c] returns the IEEE 64-bit floating point type in the context
396 [c]. See [llvm::Type::DoubleTy]. *)
397 val double_type : llcontext -> lltype
399 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
400 [c]. See [llvm::Type::X86_FP80Ty]. *)
401 val x86fp80_type : llcontext -> lltype
403 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
404 [c]. See [llvm::Type::FP128Ty]. *)
405 val fp128_type : llcontext -> lltype
407 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
408 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
409 val ppc_fp128_type : llcontext -> lltype
412 (** {7 Operations on function types} *)
414 (** [function_type ret_ty param_tys] returns the function type returning
415 [ret_ty] and taking [param_tys] as parameters.
416 See the method [llvm::FunctionType::get]. *)
417 val function_type : lltype -> lltype array -> lltype
419 (** [var_arg_function_type ret_ty param_tys] is just like
420 [function_type ret_ty param_tys] except that it returns the function type
421 which also takes a variable number of arguments.
422 See the method [llvm::FunctionType::get]. *)
423 val var_arg_function_type : lltype -> lltype array -> lltype
426 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
427 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
428 val is_var_arg : lltype -> bool
430 (** [return_type fty] gets the return type of the function type [fty].
431 See the method [llvm::FunctionType::getReturnType]. *)
432 val return_type : lltype -> lltype
434 (** [param_types fty] gets the parameter types of the function type [fty].
435 See the method [llvm::FunctionType::getParamType]. *)
436 val param_types : lltype -> lltype array
439 (** {7 Operations on struct types} *)
441 (** [struct_type context tys] returns the structure type in the context
442 [context] containing in the types in the array [tys]. See the method
443 [llvm::StructType::get]. *)
444 val struct_type : llcontext -> lltype array -> lltype
447 (** [packed_struct_type context ys] returns the packed structure type in the
448 context [context] containing in the types in the array [tys]. See the method
449 [llvm::StructType::get]. *)
450 val packed_struct_type : llcontext -> lltype array -> lltype
452 (** [struct_name ty] returns the name of the named structure type [ty],
453 * or None if the structure type is not named *)
454 val struct_name : lltype -> string option
457 (** [struct_element_types sty] returns the constituent types of the struct type
458 [sty]. See the method [llvm::StructType::getElementType]. *)
459 val struct_element_types : lltype -> lltype array
462 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
463 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
464 val is_packed : lltype -> bool
467 (** {7 Operations on pointer, vector, and array types} *)
469 (** [array_type ty n] returns the array type containing [n] elements of type
470 [ty]. See the method [llvm::ArrayType::get]. *)
471 val array_type : lltype -> int -> lltype
473 (** [pointer_type ty] returns the pointer type referencing objects of type
474 [ty] in the default address space (0).
475 See the method [llvm::PointerType::getUnqual]. *)
476 val pointer_type : lltype -> lltype
478 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
479 of type [ty] in address space [as].
480 See the method [llvm::PointerType::get]. *)
481 val qualified_pointer_type : lltype -> int -> lltype
484 (** [vector_type ty n] returns the array type containing [n] elements of the
485 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
486 val vector_type : lltype -> int -> lltype
488 (** [element_type ty] returns the element type of the pointer, vector, or array
489 type [ty]. See the method [llvm::SequentialType::get]. *)
490 val element_type : lltype -> lltype
492 (** [element_type aty] returns the element count of the array type [aty].
493 See the method [llvm::ArrayType::getNumElements]. *)
494 val array_length : lltype -> int
496 (** [address_space pty] returns the address space qualifier of the pointer type
497 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
498 val address_space : lltype -> int
500 (** [element_type ty] returns the element count of the vector type [ty].
501 See the method [llvm::VectorType::getNumElements]. *)
502 val vector_size : lltype -> int
505 (** {7 Operations on other types} *)
507 (** [void_type c] creates a type of a function which does not return any
508 value in the context [c]. See [llvm::Type::VoidTy]. *)
509 val void_type : llcontext -> lltype
511 (** [label_type c] creates a type of a basic block in the context [c]. See
512 [llvm::Type::LabelTy]. *)
513 val label_type : llcontext -> lltype
517 (** [type_of v] returns the type of the value [v].
518 See the method [llvm::Value::getType]. *)
519 val type_of : llvalue -> lltype
521 (** [value_name v] returns the name of the value [v]. For global values, this is
522 the symbol name. For instructions and basic blocks, it is the SSA register
523 name. It is meaningless for constants.
524 See the method [llvm::Value::getName]. *)
525 val value_name : llvalue -> string
527 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
528 [llvm::Value::setName]. *)
529 val set_value_name : string -> llvalue -> unit
531 (** [dump_value v] prints the .ll representation of the value [v] to standard
532 error. See the method [llvm::Value::dump]. *)
533 val dump_value : llvalue -> unit
535 (** [replace_all_uses_with old new] replaces all uses of the value [old]
536 * with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
537 val replace_all_uses_with : llvalue -> llvalue -> unit
543 (** [use_begin v] returns the first position in the use list for the value [v].
544 [use_begin] and [use_succ] can e used to iterate over the use list in order.
545 See the method [llvm::Value::use_begin]. *)
546 val use_begin : llvalue -> lluse option
548 (** [use_succ u] returns the use list position succeeding [u].
549 See the method [llvm::use_value_iterator::operator++]. *)
550 val use_succ : lluse -> lluse option
552 (** [user u] returns the user of the use [u].
553 See the method [llvm::Use::getUser]. *)
554 val user : lluse -> llvalue
556 (** [used_value u] returns the usee of the use [u].
557 See the method [llvm::Use::getUsedValue]. *)
558 val used_value : lluse -> llvalue
560 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
561 in order. Tail recursive. *)
562 val iter_uses : (lluse -> unit) -> llvalue -> unit
564 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
565 [u1,...,uN] are the users of the value [v]. Tail recursive. *)
566 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
568 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
569 [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
570 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
575 (** [operand v i] returns the operand at index [i] for the value [v]. See the
576 method [llvm::User::getOperand]. *)
577 val operand : llvalue -> int -> llvalue
579 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
581 See the method [llvm::User::setOperand]. *)
582 val set_operand : llvalue -> int -> llvalue -> unit
584 (** [num_operands v] returns the number of operands for the value [v].
585 See the method [llvm::User::getNumOperands]. *)
586 val num_operands : llvalue -> int
588 (** {7 Operations on constants of (mostly) any type} *)
590 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
591 otherwise. Similar to [llvm::isa<Constant>]. *)
592 val is_constant : llvalue -> bool
594 (** [const_null ty] returns the constant null (zero) of the type [ty].
595 See the method [llvm::Constant::getNullValue]. *)
596 val const_null : lltype -> llvalue
598 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
599 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
600 val const_all_ones : (*int|vec*)lltype -> llvalue
602 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
603 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
604 val const_pointer_null : lltype -> llvalue
606 (** [undef ty] returns the undefined value of the type [ty].
607 See the method [llvm::UndefValue::get]. *)
608 val undef : lltype -> llvalue
610 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
611 See the method [llvm::Constant::isNullValue]. *)
612 val is_null : llvalue -> bool
614 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
615 otherwise. Similar to [llvm::isa<UndefValue>]. *)
616 val is_undef : llvalue -> bool
618 val constexpr_opcode : llvalue -> Opcode.t
619 (** {7 Operations on instructions} *)
621 (** [has_metadata i] returns whether or not the instruction [i] has any
622 metadata attached to it. See the function
623 [llvm::Instruction::hasMetadata]. *)
624 val has_metadata : llvalue -> bool
626 (** [metadata i kind] optionally returns the metadata associated with the
627 kind [kind] in the instruction [i] See the function
628 [llvm::Instruction::getMetadata]. *)
629 val metadata : llvalue -> int -> llvalue option
631 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
632 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
633 val set_metadata : llvalue -> int -> llvalue -> unit
635 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
636 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
637 val clear_metadata : llvalue -> int -> unit
640 (** {7 Operations on metadata} *)
642 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
643 See the method [llvm::MDNode::get]. *)
644 val mdstring : llcontext -> string -> llvalue
646 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
648 See the method [llvm::MDNode::get]. *)
649 val mdnode : llcontext -> llvalue array -> llvalue
651 (** [get_mdstring v] returns the MDString.
652 * See the method [llvm::MDString::getString] *)
653 val get_mdstring : llvalue -> string option
655 (** [get_named_metadata m name] return all the MDNodes belonging to the named
657 * See the method [llvm::NamedMDNode::getOperand]. *)
658 val get_named_metadata : llmodule -> string -> llvalue array
660 (** {7 Operations on scalar constants} *)
662 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
663 See the method [llvm::ConstantInt::get]. *)
664 val const_int : lltype -> int -> llvalue
666 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
667 [i]. See the method [llvm::ConstantInt::get]. *)
668 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
670 (** [int64_of_const c] returns the int64 value of the [c] constant integer.
671 * None is returned if this is not an integer constant, or bitwidth exceeds 64.
672 * See the method [llvm::ConstantInt::getSExtValue].*)
673 val int64_of_const : llvalue -> Int64.t option
675 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
676 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
677 val const_int_of_string : lltype -> string -> int -> llvalue
680 (** [const_float ty n] returns the floating point constant of type [ty] and
681 value [n]. See the method [llvm::ConstantFP::get]. *)
682 val const_float : lltype -> float -> llvalue
684 (** [const_float_of_string ty s] returns the floating point constant of type
685 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
686 val const_float_of_string : lltype -> string -> llvalue
690 (** {7 Operations on composite constants} *)
692 (** [const_string c s] returns the constant [i8] array with the values of the
693 characters in the string [s] in the context [c]. The array is not
694 null-terminated (but see {!const_stringz}). This value can in turn be used
695 as the initializer for a global variable. See the method
696 [llvm::ConstantArray::get]. *)
697 val const_string : llcontext -> string -> llvalue
699 (** [const_stringz c s] returns the constant [i8] array with the values of the
700 characters in the string [s] and a null terminator in the context [c]. This
701 value can in turn be used as the initializer for a global variable.
702 See the method [llvm::ConstantArray::get]. *)
703 val const_stringz : llcontext -> string -> llvalue
705 (** [const_array ty elts] returns the constant array of type
706 [array_type ty (Array.length elts)] and containing the values [elts].
707 This value can in turn be used as the initializer for a global variable.
708 See the method [llvm::ConstantArray::get]. *)
709 val const_array : lltype -> llvalue array -> llvalue
711 (** [const_struct context elts] returns the structured constant of type
712 [struct_type (Array.map type_of elts)] and containing the values [elts]
713 in the context [context]. This value can in turn be used as the initializer
714 for a global variable. See the method [llvm::ConstantStruct::get]. *)
715 val const_struct : llcontext -> llvalue array -> llvalue
718 (** [const_packed_struct context elts] returns the structured constant of
719 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
720 values [elts] in the context [context]. This value can in turn be used as
721 the initializer for a global variable. See the method
722 [llvm::ConstantStruct::get]. *)
723 val const_packed_struct : llcontext -> llvalue array -> llvalue
726 (** [const_vector elts] returns the vector constant of type
727 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
728 values [elts]. See the method [llvm::ConstantVector::get]. *)
729 val const_vector : llvalue array -> llvalue
732 (** {7 Constant expressions} *)
734 (** [align_of ty] returns the alignof constant for the type [ty]. This is
735 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
736 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
737 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
738 val align_of : lltype -> llvalue
740 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
741 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
742 (const_int i32_type 1)) i64_type], but considerably more readable.
743 See the method [llvm::ConstantExpr::getSizeOf]. *)
744 val size_of : lltype -> llvalue
746 (** [const_neg c] returns the arithmetic negation of the constant [c].
747 See the method [llvm::ConstantExpr::getNeg]. *)
748 val const_neg : llvalue -> llvalue
750 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
751 no signed wrapping. The result is undefined if the negation overflows.
752 See the method [llvm::ConstantExpr::getNSWNeg]. *)
753 val const_nsw_neg : llvalue -> llvalue
755 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
756 no unsigned wrapping. The result is undefined if the negation overflows.
757 See the method [llvm::ConstantExpr::getNUWNeg]. *)
758 val const_nuw_neg : llvalue -> llvalue
760 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
761 See the method [llvm::ConstantExpr::getFNeg]. *)
762 val const_fneg : llvalue -> llvalue
764 (** [const_not c] returns the bitwise inverse of the constant [c].
765 See the method [llvm::ConstantExpr::getNot]. *)
766 val const_not : llvalue -> llvalue
768 (** [const_add c1 c2] returns the constant sum of two constants.
769 See the method [llvm::ConstantExpr::getAdd]. *)
770 val const_add : llvalue -> llvalue -> llvalue
772 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
773 signed wrapping. The result is undefined if the sum overflows.
774 See the method [llvm::ConstantExpr::getNSWAdd]. *)
775 val const_nsw_add : llvalue -> llvalue -> llvalue
777 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
778 unsigned wrapping. The result is undefined if the sum overflows.
779 See the method [llvm::ConstantExpr::getNSWAdd]. *)
780 val const_nuw_add : llvalue -> llvalue -> llvalue
782 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
783 See the method [llvm::ConstantExpr::getFAdd]. *)
784 val const_fadd : llvalue -> llvalue -> llvalue
786 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
787 constants. See the method [llvm::ConstantExpr::getSub]. *)
788 val const_sub : llvalue -> llvalue -> llvalue
790 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
791 no signed wrapping. The result is undefined if the sum overflows.
792 See the method [llvm::ConstantExpr::getNSWSub]. *)
793 val const_nsw_sub : llvalue -> llvalue -> llvalue
795 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
796 no unsigned wrapping. The result is undefined if the sum overflows.
797 See the method [llvm::ConstantExpr::getNSWSub]. *)
798 val const_nuw_sub : llvalue -> llvalue -> llvalue
800 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
801 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
802 val const_fsub : llvalue -> llvalue -> llvalue
804 (** [const_mul c1 c2] returns the constant product of two constants.
805 See the method [llvm::ConstantExpr::getMul]. *)
806 val const_mul : llvalue -> llvalue -> llvalue
808 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
809 no signed wrapping. The result is undefined if the sum overflows.
810 See the method [llvm::ConstantExpr::getNSWMul]. *)
811 val const_nsw_mul : llvalue -> llvalue -> llvalue
813 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
814 no unsigned wrapping. The result is undefined if the sum overflows.
815 See the method [llvm::ConstantExpr::getNSWMul]. *)
816 val const_nuw_mul : llvalue -> llvalue -> llvalue
818 (** [const_fmul c1 c2] returns the constant product of two constants floats.
819 See the method [llvm::ConstantExpr::getFMul]. *)
820 val const_fmul : llvalue -> llvalue -> llvalue
822 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
824 See the method [llvm::ConstantExpr::getUDiv]. *)
825 val const_udiv : llvalue -> llvalue -> llvalue
827 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
829 See the method [llvm::ConstantExpr::getSDiv]. *)
830 val const_sdiv : llvalue -> llvalue -> llvalue
832 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
833 signed integer constants. The result is undefined if the result is rounded
834 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
835 val const_exact_sdiv : llvalue -> llvalue -> llvalue
837 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
839 See the method [llvm::ConstantExpr::getFDiv]. *)
840 val const_fdiv : llvalue -> llvalue -> llvalue
842 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
843 unsigned integer constants.
844 See the method [llvm::ConstantExpr::getURem]. *)
845 val const_urem : llvalue -> llvalue -> llvalue
847 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
848 signed integer constants.
849 See the method [llvm::ConstantExpr::getSRem]. *)
850 val const_srem : llvalue -> llvalue -> llvalue
852 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
853 signed floating point constants.
854 See the method [llvm::ConstantExpr::getFRem]. *)
855 val const_frem : llvalue -> llvalue -> llvalue
857 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
859 See the method [llvm::ConstantExpr::getAnd]. *)
860 val const_and : llvalue -> llvalue -> llvalue
862 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
864 See the method [llvm::ConstantExpr::getOr]. *)
865 val const_or : llvalue -> llvalue -> llvalue
867 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
869 See the method [llvm::ConstantExpr::getXor]. *)
870 val const_xor : llvalue -> llvalue -> llvalue
872 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
873 constants, [c1 pred c2].
874 See the method [llvm::ConstantExpr::getICmp]. *)
875 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
878 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
879 point constants, [c1 pred c2].
880 See the method [llvm::ConstantExpr::getFCmp]. *)
881 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
884 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
885 constant integer [c2].
886 See the method [llvm::ConstantExpr::getShl]. *)
887 val const_shl : llvalue -> llvalue -> llvalue
889 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
890 constant integer [c2] with zero extension.
891 See the method [llvm::ConstantExpr::getLShr]. *)
892 val const_lshr : llvalue -> llvalue -> llvalue
894 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
895 constant integer [c2] with sign extension.
896 See the method [llvm::ConstantExpr::getAShr]. *)
897 val const_ashr : llvalue -> llvalue -> llvalue
899 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
900 constant integers indices from the array [indices].
901 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
902 val const_gep : llvalue -> llvalue array -> llvalue
904 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
905 with the constant integers indices from the array [indices].
906 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
907 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
910 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
911 to the smaller integer type [ty].
912 See the method [llvm::ConstantExpr::getTrunc]. *)
913 val const_trunc : llvalue -> lltype -> llvalue
915 (** [const_sext c ty] returns the constant sign extension of integer constant
916 [c] to the larger integer type [ty].
917 See the method [llvm::ConstantExpr::getSExt]. *)
918 val const_sext : llvalue -> lltype -> llvalue
920 (** [const_zext c ty] returns the constant zero extension of integer constant
921 [c] to the larger integer type [ty].
922 See the method [llvm::ConstantExpr::getZExt]. *)
923 val const_zext : llvalue -> lltype -> llvalue
925 (** [const_fptrunc c ty] returns the constant truncation of floating point
926 constant [c] to the smaller floating point type [ty].
927 See the method [llvm::ConstantExpr::getFPTrunc]. *)
928 val const_fptrunc : llvalue -> lltype -> llvalue
930 (** [const_fpext c ty] returns the constant extension of floating point constant
931 [c] to the larger floating point type [ty].
932 See the method [llvm::ConstantExpr::getFPExt]. *)
933 val const_fpext : llvalue -> lltype -> llvalue
935 (** [const_uitofp c ty] returns the constant floating point conversion of
936 unsigned integer constant [c] to the floating point type [ty].
937 See the method [llvm::ConstantExpr::getUIToFP]. *)
938 val const_uitofp : llvalue -> lltype -> llvalue
940 (** [const_sitofp c ty] returns the constant floating point conversion of
941 signed integer constant [c] to the floating point type [ty].
942 See the method [llvm::ConstantExpr::getSIToFP]. *)
943 val const_sitofp : llvalue -> lltype -> llvalue
945 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
946 floating point constant [c] to integer type [ty].
947 See the method [llvm::ConstantExpr::getFPToUI]. *)
948 val const_fptoui : llvalue -> lltype -> llvalue
950 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
951 floating point constant [c] to integer type [ty].
952 See the method [llvm::ConstantExpr::getFPToSI]. *)
953 val const_fptosi : llvalue -> lltype -> llvalue
955 (** [const_ptrtoint c ty] returns the constant integer conversion of
956 pointer constant [c] to integer type [ty].
957 See the method [llvm::ConstantExpr::getPtrToInt]. *)
958 val const_ptrtoint : llvalue -> lltype -> llvalue
960 (** [const_inttoptr c ty] returns the constant pointer conversion of
961 integer constant [c] to pointer type [ty].
962 See the method [llvm::ConstantExpr::getIntToPtr]. *)
963 val const_inttoptr : llvalue -> lltype -> llvalue
965 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
966 to type [ty] of equal size.
967 See the method [llvm::ConstantExpr::getBitCast]. *)
968 val const_bitcast : llvalue -> lltype -> llvalue
970 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
971 conversion of constant [c] to type [ty].
972 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
973 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
976 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
977 conversion of constant [c] to type [ty].
978 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
979 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
982 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
983 conversion of constant [c] to type [ty].
984 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
985 val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
988 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
989 cast conversion of constant [c] to type [ty] of equal size.
990 See the method [llvm::ConstantExpr::getPointerCast]. *)
991 val const_pointercast : llvalue -> lltype -> llvalue
994 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
995 -> integer casts of constant [c] to type [ty].
996 See the method [llvm::ConstantExpr::getIntCast]. *)
997 val const_intcast : llvalue -> lltype -> llvalue
1000 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
1001 fp casts of constant [c] to type [ty].
1002 See the method [llvm::ConstantExpr::getFPCast]. *)
1003 val const_fpcast : llvalue -> lltype -> llvalue
1006 (** [const_select cond t f] returns the constant conditional which returns value
1007 [t] if the boolean constant [cond] is true and the value [f] otherwise.
1008 See the method [llvm::ConstantExpr::getSelect]. *)
1009 val const_select : llvalue -> llvalue -> llvalue -> llvalue
1012 (** [const_extractelement vec i] returns the constant [i]th element of
1013 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
1014 the size of the vector.
1015 See the method [llvm::ConstantExpr::getExtractElement]. *)
1016 val const_extractelement : llvalue -> llvalue -> llvalue
1019 (** [const_insertelement vec v i] returns the constant vector with the same
1020 elements as constant vector [v] but the [i]th element replaced by the
1021 constant [v]. [v] must be a constant value with the type of the vector
1022 elements. [i] must be a constant [i32] value unsigned less than the size
1024 See the method [llvm::ConstantExpr::getInsertElement]. *)
1025 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
1028 (** [const_shufflevector a b mask] returns a constant [shufflevector].
1029 See the LLVM Language Reference for details on the [shufflevector]
1031 See the method [llvm::ConstantExpr::getShuffleVector]. *)
1032 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
1035 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
1036 constant aggregate [agg]. Each [idxs] must be less than the size of the
1037 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
1038 val const_extractvalue : llvalue -> int array -> llvalue
1041 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
1042 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
1043 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
1044 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
1047 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
1048 See the method [llvm::InlineAsm::get]. *)
1049 val const_inline_asm : lltype -> string -> string -> bool -> bool ->
1053 (** [block_address f bb] returns the address of the basic block [bb] in the
1054 function [f]. See the method [llvm::BasicBlock::get]. *)
1055 val block_address : llvalue -> llbasicblock -> llvalue
1058 (** {7 Operations on global variables, functions, and aliases (globals)} *)
1060 (** [global_parent g] is the enclosing module of the global value [g].
1061 See the method [llvm::GlobalValue::getParent]. *)
1062 val global_parent : llvalue -> llmodule
1064 (** [is_declaration g] returns [true] if the global value [g] is a declaration
1065 only. Returns [false] otherwise.
1066 See the method [llvm::GlobalValue::isDeclaration]. *)
1067 val is_declaration : llvalue -> bool
1069 (** [linkage g] returns the linkage of the global value [g].
1070 See the method [llvm::GlobalValue::getLinkage]. *)
1071 val linkage : llvalue -> Linkage.t
1073 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
1074 See the method [llvm::GlobalValue::setLinkage]. *)
1075 val set_linkage : Linkage.t -> llvalue -> unit
1077 (** [section g] returns the linker section of the global value [g].
1078 See the method [llvm::GlobalValue::getSection]. *)
1079 val section : llvalue -> string
1081 (** [set_section s g] sets the linker section of the global value [g] to [s].
1082 See the method [llvm::GlobalValue::setSection]. *)
1083 val set_section : string -> llvalue -> unit
1085 (** [visibility g] returns the linker visibility of the global value [g].
1086 See the method [llvm::GlobalValue::getVisibility]. *)
1087 val visibility : llvalue -> Visibility.t
1089 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1090 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1091 val set_visibility : Visibility.t -> llvalue -> unit
1094 (** [alignment g] returns the required alignment of the global value [g].
1095 See the method [llvm::GlobalValue::getAlignment]. *)
1096 val alignment : llvalue -> int
1098 (** [set_alignment n g] sets the required alignment of the global value [g] to
1099 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1100 val set_alignment : int -> llvalue -> unit
1103 (** {7 Operations on global variables} *)
1105 (** [declare_global ty name m] returns a new global variable of type [ty] and
1106 with name [name] in module [m] in the default address space (0). If such a
1107 global variable already exists, it is returned. If the type of the existing
1108 global differs, then a bitcast to [ty] is returned. *)
1109 val declare_global : lltype -> string -> llmodule -> llvalue
1112 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1113 of type [ty] and with name [name] in module [m] in the address space
1114 [addrspace]. If such a global variable already exists, it is returned. If
1115 the type of the existing global differs, then a bitcast to [ty] is
1117 val declare_qualified_global : lltype -> string -> int -> llmodule ->
1121 (** [define_global name init m] returns a new global with name [name] and
1122 initializer [init] in module [m] in the default address space (0). If the
1123 named global already exists, it is renamed.
1124 See the constructor of [llvm::GlobalVariable]. *)
1125 val define_global : string -> llvalue -> llmodule -> llvalue
1128 (** [define_qualified_global name init addrspace m] returns a new global with
1129 name [name] and initializer [init] in module [m] in the address space
1130 [addrspace]. If the named global already exists, it is renamed.
1131 See the constructor of [llvm::GlobalVariable]. *)
1132 val define_qualified_global : string -> llvalue -> int -> llmodule ->
1136 (** [lookup_global name m] returns [Some g] if a global variable with name
1137 [name] exists in module [m]. If no such global exists, returns [None].
1138 See the [llvm::GlobalVariable] constructor. *)
1139 val lookup_global : string -> llmodule -> llvalue option
1142 (** [delete_global gv] destroys the global variable [gv].
1143 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1144 val delete_global : llvalue -> unit
1146 (** [global_begin m] returns the first position in the global variable list of
1147 the module [m]. [global_begin] and [global_succ] can be used to iterate
1148 over the global list in order.
1149 See the method [llvm::Module::global_begin]. *)
1150 val global_begin : llmodule -> (llmodule, llvalue) llpos
1153 (** [global_succ gv] returns the global variable list position succeeding
1155 See the method [llvm::Module::global_iterator::operator++]. *)
1156 val global_succ : llvalue -> (llmodule, llvalue) llpos
1159 (** [iter_globals f m] applies function [f] to each of the global variables of
1160 module [m] in order. Tail recursive. *)
1161 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1163 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1164 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1165 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1167 (** [global_end m] returns the last position in the global variable list of the
1168 module [m]. [global_end] and [global_pred] can be used to iterate over the
1169 global list in reverse.
1170 See the method [llvm::Module::global_end]. *)
1171 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1174 (** [global_pred gv] returns the global variable list position preceding
1176 See the method [llvm::Module::global_iterator::operator--]. *)
1177 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1180 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1181 of module [m] in reverse order. Tail recursive. *)
1182 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1184 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1185 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1186 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1188 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1189 constant. Returns [false] otherwise.
1190 See the method [llvm::GlobalVariable::isConstant]. *)
1191 val is_global_constant : llvalue -> bool
1193 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1194 [c] is [true] and not if [c] is [false].
1195 See the method [llvm::GlobalVariable::setConstant]. *)
1196 val set_global_constant : bool -> llvalue -> unit
1199 (** [global_initializer gv] returns the initializer for the global variable
1200 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1201 val global_initializer : llvalue -> llvalue
1203 (** [set_initializer c gv] sets the initializer for the global variable
1204 [gv] to the constant [c].
1205 See the method [llvm::GlobalVariable::setInitializer]. *)
1206 val set_initializer : llvalue -> llvalue -> unit
1208 (** [remove_initializer gv] unsets the initializer for the global variable
1210 See the method [llvm::GlobalVariable::setInitializer]. *)
1211 val remove_initializer : llvalue -> unit
1213 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1214 thread-local and [false] otherwise.
1215 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1216 val is_thread_local : llvalue -> bool
1218 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1219 [c] is [true] and not otherwise.
1220 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1221 val set_thread_local : bool -> llvalue -> unit
1224 (** {7 Operations on aliases} *)
1226 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1227 the aliasee [a] with the name [n].
1228 See the constructor for [llvm::GlobalAlias]. *)
1229 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1233 (** {7 Operations on functions} *)
1235 (** [declare_function name ty m] returns a new function of type [ty] and
1236 with name [name] in module [m]. If such a function already exists,
1237 it is returned. If the type of the existing function differs, then a bitcast
1238 to [ty] is returned. *)
1239 val declare_function : string -> lltype -> llmodule -> llvalue
1242 (** [define_function name ty m] creates a new function with name [name] and
1243 type [ty] in module [m]. If the named function already exists, it is
1244 renamed. An entry basic block is created in the function.
1245 See the constructor of [llvm::GlobalVariable]. *)
1246 val define_function : string -> lltype -> llmodule -> llvalue
1249 (** [lookup_function name m] returns [Some f] if a function with name
1250 [name] exists in module [m]. If no such function exists, returns [None].
1251 See the method [llvm::Module] constructor. *)
1252 val lookup_function : string -> llmodule -> llvalue option
1255 (** [delete_function f] destroys the function [f].
1256 See the method [llvm::Function::eraseFromParent]. *)
1257 val delete_function : llvalue -> unit
1259 (** [function_begin m] returns the first position in the function list of the
1260 module [m]. [function_begin] and [function_succ] can be used to iterate over
1261 the function list in order.
1262 See the method [llvm::Module::begin]. *)
1263 val function_begin : llmodule -> (llmodule, llvalue) llpos
1266 (** [function_succ gv] returns the function list position succeeding
1268 See the method [llvm::Module::iterator::operator++]. *)
1269 val function_succ : llvalue -> (llmodule, llvalue) llpos
1272 (** [iter_functions f m] applies function [f] to each of the functions of module
1273 [m] in order. Tail recursive. *)
1274 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1276 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1277 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1278 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1280 (** [function_end m] returns the last position in the function list of
1281 the module [m]. [function_end] and [function_pred] can be used to iterate
1282 over the function list in reverse.
1283 See the method [llvm::Module::end]. *)
1284 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1287 (** [function_pred gv] returns the function list position preceding [After gv].
1288 See the method [llvm::Module::iterator::operator--]. *)
1289 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1292 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1293 module [m] in reverse order. Tail recursive. *)
1294 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1296 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1297 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1298 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1300 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1301 See the method [llvm::Function::isIntrinsic]. *)
1302 val is_intrinsic : llvalue -> bool
1304 (** [function_call_conv f] returns the calling convention of the function [f].
1305 See the method [llvm::Function::getCallingConv]. *)
1306 val function_call_conv : llvalue -> int
1308 (** [set_function_call_conv cc f] sets the calling convention of the function
1309 [f] to the calling convention numbered [cc].
1310 See the method [llvm::Function::setCallingConv]. *)
1311 val set_function_call_conv : int -> llvalue -> unit
1314 (** [gc f] returns [Some name] if the function [f] has a garbage
1315 collection algorithm specified and [None] otherwise.
1316 See the method [llvm::Function::getGC]. *)
1317 val gc : llvalue -> string option
1319 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1320 [gc]. See the method [llvm::Function::setGC]. *)
1321 val set_gc : string option -> llvalue -> unit
1323 (** [add_function_attr f a] adds attribute [a] to the return type of function
1325 val add_function_attr : llvalue -> Attribute.t -> unit
1327 (** [remove_function_attr f a] removes attribute [a] from the return type of
1329 val remove_function_attr : llvalue -> Attribute.t -> unit
1331 (** {7 Operations on params} *)
1333 (** [params f] returns the parameters of function [f].
1334 See the method [llvm::Function::getArgumentList]. *)
1335 val params : llvalue -> llvalue array
1337 (** [param f n] returns the [n]th parameter of function [f].
1338 See the method [llvm::Function::getArgumentList]. *)
1339 val param : llvalue -> int -> llvalue
1341 (** [param_parent p] returns the parent function that owns the parameter.
1342 See the method [llvm::Argument::getParent]. *)
1343 val param_parent : llvalue -> llvalue
1345 (** [param_begin f] returns the first position in the parameter list of the
1346 function [f]. [param_begin] and [param_succ] can be used to iterate over
1347 the parameter list in order.
1348 See the method [llvm::Function::arg_begin]. *)
1349 val param_begin : llvalue -> (llvalue, llvalue) llpos
1351 (** [param_succ bb] returns the parameter list position succeeding
1353 See the method [llvm::Function::arg_iterator::operator++]. *)
1354 val param_succ : llvalue -> (llvalue, llvalue) llpos
1356 (** [iter_params f fn] applies function [f] to each of the parameters
1357 of function [fn] in order. Tail recursive. *)
1358 val iter_params : (llvalue -> unit) -> llvalue -> unit
1360 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1361 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1362 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1364 (** [param_end f] returns the last position in the parameter list of
1365 the function [f]. [param_end] and [param_pred] can be used to iterate
1366 over the parameter list in reverse.
1367 See the method [llvm::Function::arg_end]. *)
1368 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1370 (** [param_pred gv] returns the function list position preceding [After gv].
1371 See the method [llvm::Function::arg_iterator::operator--]. *)
1372 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1375 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1376 of function [fn] in reverse order. Tail recursive. *)
1377 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1379 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1380 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1381 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1383 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1384 val add_param_attr : llvalue -> Attribute.t -> unit
1386 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1387 val remove_param_attr : llvalue -> Attribute.t -> unit
1389 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1390 val set_param_alignment : llvalue -> int -> unit
1393 (** {7 Operations on basic blocks} *)
1395 (** [basic_blocks fn] returns the basic blocks of the function [f].
1396 See the method [llvm::Function::getBasicBlockList]. *)
1397 val basic_blocks : llvalue -> llbasicblock array
1399 (** [entry_block fn] returns the entry basic block of the function [f].
1400 See the method [llvm::Function::getEntryBlock]. *)
1401 val entry_block : llvalue -> llbasicblock
1403 (** [delete_block bb] deletes the basic block [bb].
1404 See the method [llvm::BasicBlock::eraseFromParent]. *)
1405 val delete_block : llbasicblock -> unit
1407 (** [append_block c name f] creates a new basic block named [name] at the end of
1408 function [f] in the context [c].
1409 See the constructor of [llvm::BasicBlock]. *)
1410 val append_block : llcontext -> string -> llvalue -> llbasicblock
1413 (** [insert_block c name bb] creates a new basic block named [name] before the
1414 basic block [bb] in the context [c].
1415 See the constructor of [llvm::BasicBlock]. *)
1416 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1419 (** [block_parent bb] returns the parent function that owns the basic block.
1420 See the method [llvm::BasicBlock::getParent]. *)
1421 val block_parent : llbasicblock -> llvalue
1423 (** [block_begin f] returns the first position in the basic block list of the
1424 function [f]. [block_begin] and [block_succ] can be used to iterate over
1425 the basic block list in order.
1426 See the method [llvm::Function::begin]. *)
1427 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1430 (** [block_succ bb] returns the basic block list position succeeding
1432 See the method [llvm::Function::iterator::operator++]. *)
1433 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1436 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1437 of function [fn] in order. Tail recursive. *)
1438 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1440 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1441 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1442 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1444 (** [block_end f] returns the last position in the basic block list of
1445 the function [f]. [block_end] and [block_pred] can be used to iterate
1446 over the basic block list in reverse.
1447 See the method [llvm::Function::end]. *)
1448 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1451 (** [block_pred gv] returns the function list position preceding [After gv].
1452 See the method [llvm::Function::iterator::operator--]. *)
1453 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1456 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1457 of function [fn] in reverse order. Tail recursive. *)
1458 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1460 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1461 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1462 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1464 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1465 val value_of_block : llbasicblock -> llvalue
1467 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1469 Similar to [llvm::isa<BasicBlock>]. *)
1470 val value_is_block : llvalue -> bool
1472 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1473 val block_of_value : llvalue -> llbasicblock
1476 (** {7 Operations on instructions} *)
1478 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1479 See the method [llvm::Instruction::getParent]. *)
1480 val instr_parent : llvalue -> llbasicblock
1482 (** [instr_begin bb] returns the first position in the instruction list of the
1483 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1484 the instruction list in order.
1485 See the method [llvm::BasicBlock::begin]. *)
1486 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1489 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1490 See the method [llvm::BasicBlock::iterator::operator++]. *)
1491 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1494 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1495 block [bb] in order. Tail recursive. *)
1496 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1498 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1499 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1500 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1502 (** [instr_end bb] returns the last position in the instruction list of the
1503 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1504 the instruction list in reverse.
1505 See the method [llvm::BasicBlock::end]. *)
1506 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1509 (** [instr_pred i] returns the instruction list position preceding [After i].
1510 See the method [llvm::BasicBlock::iterator::operator--]. *)
1511 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1514 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1515 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1516 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1518 val instr_opcode : llvalue -> Opcode.t
1520 val icmp_predicate : llvalue -> Icmp.t option
1522 (** {7 Operations on call sites} *)
1524 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1525 instruction [ci], which may be one of the values from the module
1526 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1527 [llvm::InvokeInst::getCallingConv]. *)
1528 val instruction_call_conv: llvalue -> int
1531 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1532 or invoke instruction [ci] to the integer [cc], which can be one of the
1533 values from the module {!CallConv}.
1534 See the method [llvm::CallInst::setCallingConv]
1535 and [llvm::InvokeInst::setCallingConv]. *)
1536 val set_instruction_call_conv: int -> llvalue -> unit
1539 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1540 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1542 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1544 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1545 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1547 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1549 (** {Operations on call instructions (only)} *)
1551 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1552 eligible for tail call optimization, [false] otherwise.
1553 See the method [llvm::CallInst::isTailCall]. *)
1554 val is_tail_call : llvalue -> bool
1556 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1557 call optimization if [tc] is [true], clears otherwise.
1558 See the method [llvm::CallInst::setTailCall]. *)
1559 val set_tail_call : bool -> llvalue -> unit
1561 (** {7 Operations on phi nodes} *)
1563 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1564 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1565 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1568 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1569 See the method [llvm::PHINode::getIncomingValue]. *)
1570 val incoming : llvalue -> (llvalue * llbasicblock) list
1574 (** {6 Instruction builders} *)
1576 (** [builder context] creates an instruction builder with no position in
1577 the context [context]. It is invalid to use this builder until its position
1578 is set with {!position_before} or {!position_at_end}. See the constructor
1579 for [llvm::LLVMBuilder]. *)
1580 val builder : llcontext -> llbuilder
1582 (** [builder_at ip] creates an instruction builder positioned at [ip].
1583 See the constructor for [llvm::LLVMBuilder]. *)
1584 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1586 (** [builder_before ins] creates an instruction builder positioned before the
1587 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1588 val builder_before : llcontext -> llvalue -> llbuilder
1590 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1591 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1592 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1594 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1596 See the constructor for [llvm::LLVMBuilder]. *)
1597 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1600 (** [position_before ins b] moves the instruction builder [b] to before the
1601 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1602 val position_before : llvalue -> llbuilder -> unit
1604 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1605 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1606 val position_at_end : llbasicblock -> llbuilder -> unit
1608 (** [insertion_block b] returns the basic block that the builder [b] is
1609 positioned to insert into. Raises [Not_Found] if the instruction builder is
1611 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1612 val insertion_block : llbuilder -> llbasicblock
1614 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1615 position specified by the instruction builder [b].
1616 See the method [llvm::LLVMBuilder::Insert]. *)
1617 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1622 (** [set_current_debug_location b md] sets the current debug location [md] in
1624 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1625 val set_current_debug_location : llbuilder -> llvalue -> unit
1628 (** [clear_current_debug_location b] clears the current debug location in the
1630 val clear_current_debug_location : llbuilder -> unit
1633 (** [current_debug_location b] returns the current debug location, or None
1634 if none is currently set.
1635 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1636 val current_debug_location : llbuilder -> llvalue option
1639 (** [set_inst_debug_location b i] sets the current debug location of the builder
1640 [b] to the instruction [i].
1641 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1642 val set_inst_debug_location : llbuilder -> llvalue -> unit
1645 (** {7 Terminators} *)
1647 (** [build_ret_void b] creates a
1649 instruction at the position specified by the instruction builder [b].
1650 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1651 val build_ret_void : llbuilder -> llvalue
1653 (** [build_ret v b] creates a
1655 instruction at the position specified by the instruction builder [b].
1656 See the method [llvm::LLVMBuilder::CreateRet]. *)
1657 val build_ret : llvalue -> llbuilder -> llvalue
1659 (** [build_aggregate_ret vs b] creates a
1660 [ret {...} { %v1, %v2, ... } ]
1661 instruction at the position specified by the instruction builder [b].
1662 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1663 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1666 (** [build_br bb b] creates a
1668 instruction at the position specified by the instruction builder [b].
1669 See the method [llvm::LLVMBuilder::CreateBr]. *)
1670 val build_br : llbasicblock -> llbuilder -> llvalue
1672 (** [build_cond_br cond tbb fbb b] creates a
1673 [br %cond, %tbb, %fbb]
1674 instruction at the position specified by the instruction builder [b].
1675 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1676 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1679 (** [build_switch case elsebb count b] creates an empty
1680 [switch %case, %elsebb]
1681 instruction at the position specified by the instruction builder [b] with
1682 space reserved for [count] cases.
1683 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1684 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1687 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1688 when its input matches the constant [onval].
1689 See the method [llvm::SwitchInst::addCase]. **)
1690 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1693 (** [build_indirect_br addr count b] creates a
1695 instruction at the position specified by the instruction builder [b] with
1696 space reserved for [count] destinations.
1697 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1698 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1701 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1702 location for the indirectbr instruction [br].
1703 See the method [llvm::IndirectBrInst::addDestination]. **)
1704 val add_destination : llvalue -> llbasicblock -> unit
1707 (** [build_invoke fn args tobb unwindbb name b] creates an
1708 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1709 instruction at the position specified by the instruction builder [b].
1710 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1711 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1712 llbasicblock -> string -> llbuilder -> llvalue
1714 (** [build_landingpad ty persfn numclauses name b] creates an
1716 instruction at the position specified by the instruction builder [b].
1717 See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
1718 val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
1721 (** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
1722 See the method [llvm::LandingPadInst::setCleanup]. *)
1723 val set_cleanup : llvalue -> bool -> unit
1725 (** [build_unreachable b] creates an
1727 instruction at the position specified by the instruction builder [b].
1728 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1729 val build_unreachable : llbuilder -> llvalue
1732 (** {7 Arithmetic} *)
1734 (** [build_add x y name b] creates a
1735 [%name = add %x, %y]
1736 instruction at the position specified by the instruction builder [b].
1737 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1738 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1741 (** [build_nsw_add x y name b] creates a
1742 [%name = nsw add %x, %y]
1743 instruction at the position specified by the instruction builder [b].
1744 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1745 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1748 (** [build_nuw_add x y name b] creates a
1749 [%name = nuw add %x, %y]
1750 instruction at the position specified by the instruction builder [b].
1751 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1752 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1755 (** [build_fadd x y name b] creates a
1756 [%name = fadd %x, %y]
1757 instruction at the position specified by the instruction builder [b].
1758 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1759 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1762 (** [build_sub x y name b] creates a
1763 [%name = sub %x, %y]
1764 instruction at the position specified by the instruction builder [b].
1765 See the method [llvm::LLVMBuilder::CreateSub]. *)
1766 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1769 (** [build_nsw_sub x y name b] creates a
1770 [%name = nsw sub %x, %y]
1771 instruction at the position specified by the instruction builder [b].
1772 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1773 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1776 (** [build_nuw_sub x y name b] creates a
1777 [%name = nuw sub %x, %y]
1778 instruction at the position specified by the instruction builder [b].
1779 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1780 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1783 (** [build_fsub x y name b] creates a
1784 [%name = fsub %x, %y]
1785 instruction at the position specified by the instruction builder [b].
1786 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1787 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1790 (** [build_mul x y name b] creates a
1791 [%name = mul %x, %y]
1792 instruction at the position specified by the instruction builder [b].
1793 See the method [llvm::LLVMBuilder::CreateMul]. *)
1794 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1797 (** [build_nsw_mul x y name b] creates a
1798 [%name = nsw mul %x, %y]
1799 instruction at the position specified by the instruction builder [b].
1800 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1801 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1804 (** [build_nuw_mul x y name b] creates a
1805 [%name = nuw mul %x, %y]
1806 instruction at the position specified by the instruction builder [b].
1807 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1808 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1811 (** [build_fmul x y name b] creates a
1812 [%name = fmul %x, %y]
1813 instruction at the position specified by the instruction builder [b].
1814 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1815 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1818 (** [build_udiv x y name b] creates a
1819 [%name = udiv %x, %y]
1820 instruction at the position specified by the instruction builder [b].
1821 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1822 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1825 (** [build_sdiv x y name b] creates a
1826 [%name = sdiv %x, %y]
1827 instruction at the position specified by the instruction builder [b].
1828 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1829 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1832 (** [build_exact_sdiv x y name b] creates a
1833 [%name = exact sdiv %x, %y]
1834 instruction at the position specified by the instruction builder [b].
1835 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1836 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1839 (** [build_fdiv x y name b] creates a
1840 [%name = fdiv %x, %y]
1841 instruction at the position specified by the instruction builder [b].
1842 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1843 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1846 (** [build_urem x y name b] creates a
1847 [%name = urem %x, %y]
1848 instruction at the position specified by the instruction builder [b].
1849 See the method [llvm::LLVMBuilder::CreateURem]. *)
1850 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1853 (** [build_SRem x y name b] creates a
1854 [%name = srem %x, %y]
1855 instruction at the position specified by the instruction builder [b].
1856 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1857 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1860 (** [build_frem x y name b] creates a
1861 [%name = frem %x, %y]
1862 instruction at the position specified by the instruction builder [b].
1863 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1864 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1867 (** [build_shl x y name b] creates a
1868 [%name = shl %x, %y]
1869 instruction at the position specified by the instruction builder [b].
1870 See the method [llvm::LLVMBuilder::CreateShl]. *)
1871 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1874 (** [build_lshr x y name b] creates a
1875 [%name = lshr %x, %y]
1876 instruction at the position specified by the instruction builder [b].
1877 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1878 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1881 (** [build_ashr x y name b] creates a
1882 [%name = ashr %x, %y]
1883 instruction at the position specified by the instruction builder [b].
1884 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1885 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1888 (** [build_and x y name b] creates a
1889 [%name = and %x, %y]
1890 instruction at the position specified by the instruction builder [b].
1891 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1892 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1895 (** [build_or x y name b] creates a
1897 instruction at the position specified by the instruction builder [b].
1898 See the method [llvm::LLVMBuilder::CreateOr]. *)
1899 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1902 (** [build_xor x y name b] creates a
1903 [%name = xor %x, %y]
1904 instruction at the position specified by the instruction builder [b].
1905 See the method [llvm::LLVMBuilder::CreateXor]. *)
1906 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1909 (** [build_neg x name b] creates a
1911 instruction at the position specified by the instruction builder [b].
1912 [-0.0] is used for floating point types to compute the correct sign.
1913 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1914 val build_neg : llvalue -> string -> llbuilder -> llvalue
1917 (** [build_nsw_neg x name b] creates a
1918 [%name = nsw sub 0, %x]
1919 instruction at the position specified by the instruction builder [b].
1920 [-0.0] is used for floating point types to compute the correct sign.
1921 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1922 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1925 (** [build_nuw_neg x name b] creates a
1926 [%name = nuw sub 0, %x]
1927 instruction at the position specified by the instruction builder [b].
1928 [-0.0] is used for floating point types to compute the correct sign.
1929 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1930 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1933 (** [build_fneg x name b] creates a
1934 [%name = fsub 0, %x]
1935 instruction at the position specified by the instruction builder [b].
1936 [-0.0] is used for floating point types to compute the correct sign.
1937 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1938 val build_fneg : llvalue -> string -> llbuilder -> llvalue
1941 (** [build_xor x name b] creates a
1942 [%name = xor %x, -1]
1943 instruction at the position specified by the instruction builder [b].
1944 [-1] is the correct "all ones" value for the type of [x].
1945 See the method [llvm::LLVMBuilder::CreateXor]. *)
1946 val build_not : llvalue -> string -> llbuilder -> llvalue
1952 (** [build_alloca ty name b] creates a
1953 [%name = alloca %ty]
1954 instruction at the position specified by the instruction builder [b].
1955 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1956 val build_alloca : lltype -> string -> llbuilder -> llvalue
1959 (** [build_array_alloca ty n name b] creates a
1960 [%name = alloca %ty, %n]
1961 instruction at the position specified by the instruction builder [b].
1962 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1963 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1966 (** [build_load v name b] creates a
1968 instruction at the position specified by the instruction builder [b].
1969 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1970 val build_load : llvalue -> string -> llbuilder -> llvalue
1973 (** [build_store v p b] creates a
1975 instruction at the position specified by the instruction builder [b].
1976 See the method [llvm::LLVMBuilder::CreateStore]. *)
1977 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
1980 (** [build_gep p indices name b] creates a
1981 [%name = getelementptr %p, indices...]
1982 instruction at the position specified by the instruction builder [b].
1983 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1984 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1987 (** [build_in_bounds_gep p indices name b] creates a
1988 [%name = gelementptr inbounds %p, indices...]
1989 instruction at the position specified by the instruction builder [b].
1990 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1991 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1994 (** [build_struct_gep p idx name b] creates a
1995 [%name = getelementptr %p, 0, idx]
1996 instruction at the position specified by the instruction builder [b].
1997 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1998 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
2001 (** [build_global_string str name b] creates a series of instructions that adds
2002 a global string at the position specified by the instruction builder [b].
2003 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
2004 val build_global_string : string -> string -> llbuilder -> llvalue
2007 (** [build_global_stringptr str name b] creates a series of instructions that
2008 adds a global string pointer at the position specified by the instruction
2010 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
2011 val build_global_stringptr : string -> string -> llbuilder -> llvalue
2017 (** [build_trunc v ty name b] creates a
2018 [%name = trunc %p to %ty]
2019 instruction at the position specified by the instruction builder [b].
2020 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
2021 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2024 (** [build_zext v ty name b] creates a
2025 [%name = zext %p to %ty]
2026 instruction at the position specified by the instruction builder [b].
2027 See the method [llvm::LLVMBuilder::CreateZExt]. *)
2028 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
2038 (** [build_fptoui v ty name b] creates a
2039 [%name = fptoui %p to %ty]
2040 instruction at the position specified by the instruction builder [b].
2041 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
2042 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
2045 (** [build_fptosi v ty name b] creates a
2046 [%name = fptosi %p to %ty]
2047 instruction at the position specified by the instruction builder [b].
2048 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
2049 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
2052 (** [build_uitofp v ty name b] creates a
2053 [%name = uitofp %p to %ty]
2054 instruction at the position specified by the instruction builder [b].
2055 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
2056 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2059 (** [build_sitofp v ty name b] creates a
2060 [%name = sitofp %p to %ty]
2061 instruction at the position specified by the instruction builder [b].
2062 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
2063 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2066 (** [build_fptrunc v ty name b] creates a
2067 [%name = fptrunc %p to %ty]
2068 instruction at the position specified by the instruction builder [b].
2069 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
2070 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2073 (** [build_fpext v ty name b] creates a
2074 [%name = fpext %p to %ty]
2075 instruction at the position specified by the instruction builder [b].
2076 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
2077 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
2080 (** [build_ptrtoint v ty name b] creates a
2081 [%name = prtotint %p to %ty]
2082 instruction at the position specified by the instruction builder [b].
2083 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2084 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2087 (** [build_inttoptr v ty name b] creates a
2088 [%name = inttoptr %p to %ty]
2089 instruction at the position specified by the instruction builder [b].
2090 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2091 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2094 (** [build_bitcast v ty name b] creates a
2095 [%name = bitcast %p to %ty]
2096 instruction at the position specified by the instruction builder [b].
2097 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2098 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2101 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2102 instruction at the position specified by the instruction builder [b].
2103 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2104 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2107 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2108 instruction at the position specified by the instruction builder [b].
2109 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2110 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2113 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2114 instruction at the position specified by the instruction builder [b].
2115 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2116 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2119 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2120 instruction at the position specified by the instruction builder [b].
2121 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2122 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2125 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2126 instruction at the position specified by the instruction builder [b].
2127 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2128 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2131 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2132 instruction at the position specified by the instruction builder [b].
2133 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2134 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2138 (** {7 Comparisons} *)
2140 (** [build_icmp pred x y name b] creates a
2141 [%name = icmp %pred %x, %y]
2142 instruction at the position specified by the instruction builder [b].
2143 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2144 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2145 llbuilder -> llvalue
2147 (** [build_fcmp pred x y name b] creates a
2148 [%name = fcmp %pred %x, %y]
2149 instruction at the position specified by the instruction builder [b].
2150 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2151 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2152 llbuilder -> llvalue
2155 (** {7 Miscellaneous instructions} *)
2157 (** [build_phi incoming name b] creates a
2158 [%name = phi %incoming]
2159 instruction at the position specified by the instruction builder [b].
2160 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2161 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2162 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2165 (** [build_call fn args name b] creates a
2166 [%name = call %fn(args...)]
2167 instruction at the position specified by the instruction builder [b].
2168 See the method [llvm::LLVMBuilder::CreateCall]. *)
2169 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2172 (** [build_select cond thenv elsev name b] creates a
2173 [%name = select %cond, %thenv, %elsev]
2174 instruction at the position specified by the instruction builder [b].
2175 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2176 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2179 (** [build_va_arg valist argty name b] creates a
2180 [%name = va_arg %valist, %argty]
2181 instruction at the position specified by the instruction builder [b].
2182 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2183 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2186 (** [build_extractelement vec i name b] creates a
2187 [%name = extractelement %vec, %i]
2188 instruction at the position specified by the instruction builder [b].
2189 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2190 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2193 (** [build_insertelement vec elt i name b] creates a
2194 [%name = insertelement %vec, %elt, %i]
2195 instruction at the position specified by the instruction builder [b].
2196 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2197 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2198 llbuilder -> llvalue
2200 (** [build_shufflevector veca vecb mask name b] creates a
2201 [%name = shufflevector %veca, %vecb, %mask]
2202 instruction at the position specified by the instruction builder [b].
2203 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2204 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2205 llbuilder -> llvalue
2207 (** [build_insertvalue agg idx name b] creates a
2208 [%name = extractvalue %agg, %idx]
2209 instruction at the position specified by the instruction builder [b].
2210 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2211 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2214 (** [build_insertvalue agg val idx name b] creates a
2215 [%name = insertvalue %agg, %val, %idx]
2216 instruction at the position specified by the instruction builder [b].
2217 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2218 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2221 (** [build_is_null val name b] creates a
2222 [%name = icmp eq %val, null]
2223 instruction at the position specified by the instruction builder [b].
2224 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2225 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2228 (** [build_is_not_null val name b] creates a
2229 [%name = icmp ne %val, null]
2230 instruction at the position specified by the instruction builder [b].
2231 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2232 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2235 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2236 the difference between two pointer values at the position specified by the
2237 instruction builder [b].
2238 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2239 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2243 (** {6 Memory buffers} *)
2245 module MemoryBuffer : sig
2246 (** [of_file p] is the memory buffer containing the contents of the file at
2247 path [p]. If the file could not be read, then [IoError msg] is
2249 val of_file : string -> llmemorybuffer
2251 (** [stdin ()] is the memory buffer containing the contents of standard input.
2252 If standard input is empty, then [IoError msg] is raised. *)
2253 val of_stdin : unit -> llmemorybuffer
2255 (** Disposes of a memory buffer. *)
2256 val dispose : llmemorybuffer -> unit
2260 (** {6 Pass Managers} *)
2262 module PassManager : sig
2265 type any = [ `Module | `Function ]
2267 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2268 type of pipeline is suitable for link-time optimization and whole-module
2270 See the constructor of [llvm::PassManager]. *)
2271 val create : unit -> [ `Module ] t
2273 (** [PassManager.create_function m] constructs a new function-by-function
2274 pass pipeline over the module [m]. It does not take ownership of [m].
2275 This type of pipeline is suitable for code generation and JIT compilation
2277 See the constructor of [llvm::FunctionPassManager]. *)
2278 val create_function : llmodule -> [ `Function ] t
2281 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2282 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2283 any of the passes modified the module, [false] otherwise.
2284 See the [llvm::PassManager::run] method. *)
2285 val run_module : llmodule -> [ `Module ] t -> bool
2288 (** [initialize fpm] initializes all of the function passes scheduled in the
2289 function pass manager [fpm]. Returns [true] if any of the passes modified
2290 the module, [false] otherwise.
2291 See the [llvm::FunctionPassManager::doInitialization] method. *)
2292 val initialize : [ `Function ] t -> bool
2294 (** [run_function f fpm] executes all of the function passes scheduled in the
2295 function pass manager [fpm] over the function [f]. Returns [true] if any
2296 of the passes modified [f], [false] otherwise.
2297 See the [llvm::FunctionPassManager::run] method. *)
2298 val run_function : llvalue -> [ `Function ] t -> bool
2301 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2302 function pass manager [fpm]. Returns [true] if any of the passes
2303 modified the module, [false] otherwise.
2304 See the [llvm::FunctionPassManager::doFinalization] method. *)
2305 val finalize : [ `Function ] t -> bool
2307 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2309 See the destructor of [llvm::BasePassManager]. *)
2310 val dispose : [< any ] t -> unit