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 (** When building recursive types using {!refine_type}, [lltype] values may
33 become invalid; use [lltypehandle] to resolve this problem. See the
34 [llvm::AbstractTypeHolder] class. *)
37 (** Any value in the LLVM IR. Functions, instructions, global variables,
38 constants, and much more are all [llvalues]. See the [llvm::Value] class.
39 This type covers a wide range of subclasses. *)
42 (** Used to store users and usees of values. See the [llvm::Use] class. *)
45 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *)
48 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
52 (** Used to efficiently handle large buffers of read-only binary data.
53 See the [llvm::MemoryBuffer] class. *)
56 (** The kind of an [lltype], the result of [classify_type ty]. See the
57 [llvm::Type::TypeID] enumeration. *)
77 (** The linkage of a global value, accessed with {!linkage} and
78 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
82 | Available_externally
98 (** The linker visibility of a global value, accessed with {!visibility} and
99 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
100 module Visibility : sig
107 (** The following calling convention values may be accessed with
108 {!function_call_conv} and {!set_function_call_conv}. Calling
109 conventions are open-ended. *)
110 module CallConv : sig
111 val c : int (** [c] is the C calling convention. *)
112 val fast : int (** [fast] is the calling convention to allow LLVM
113 maximum optimization opportunities. Use only with
115 val cold : int (** [cold] is the calling convention for
117 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling
118 convention from C. *)
119 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
120 convention from C. *)
123 module Attribute : sig
147 | Stackalignment of int
150 (** The predicate for an integer comparison ([icmp]) instruction.
151 See the [llvm::ICmpInst::Predicate] enumeration. *)
166 (** The predicate for a floating-point comparison ([fcmp]) instruction.
167 See the [llvm::FCmpInst::Predicate] enumeration. *)
191 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
192 of [a]. [llpos] is used to specify positions in and for forward iteration
193 through the various value lists maintained by the LLVM IR. *)
194 type ('a, 'b) llpos =
198 (** [After b] and [At_start a] specify positions from the end of the ['b] list
199 of [a]. [llrev_pos] is used for reverse iteration through the various value
200 lists maintained by the LLVM IR. *)
201 type ('a, 'b) llrev_pos =
206 (** {6 Exceptions} *)
208 exception IoError of string
213 (** [create_context ()] creates a context for storing the "global" state in
214 LLVM. See the constructor [llvm::LLVMContext]. *)
215 val create_context : unit -> llcontext
217 (** [destroy_context ()] destroys a context. See the destructor
218 [llvm::LLVMContext::~LLVMContext]. *)
219 val dispose_context : llcontext -> unit
221 (** See the function [llvm::getGlobalContext]. *)
222 val global_context : unit -> llcontext
224 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
225 name [name] in the context [context]. See the function
226 [llvm::LLVMContext::getMDKindID]. *)
227 val mdkind_id : llcontext -> string -> int
232 (** [create_module context id] creates a module with the supplied module ID in
233 the context [context]. Modules are not garbage collected; it is mandatory
234 to call {!dispose_module} to free memory. See the constructor
235 [llvm::Module::Module]. *)
236 val create_module : llcontext -> string -> llmodule
238 (** [dispose_module m] destroys a module [m] and all of the IR objects it
239 contained. All references to subordinate objects are invalidated;
240 referencing them will invoke undefined behavior. See the destructor
241 [llvm::Module::~Module]. *)
242 val dispose_module : llmodule -> unit
244 (** [target_triple m] is the target specifier for the module [m], something like
245 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
246 val target_triple: llmodule -> string
249 (** [target_triple triple m] changes the target specifier for the module [m] to
250 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
251 val set_target_triple: string -> llmodule -> unit
254 (** [data_layout m] is the data layout specifier for the module [m], something
255 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
256 method [llvm::Module::getDataLayout]. *)
257 val data_layout: llmodule -> string
260 (** [set_data_layout s m] changes the data layout specifier for the module [m]
261 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
262 val set_data_layout: string -> llmodule -> unit
265 (** [define_type_name name ty m] adds a named type to the module's symbol table.
266 Returns [true] if successful. If such a name already exists, then no entry
267 is added and [false] is returned. See the [llvm::Module::addTypeName]
269 val define_type_name : string -> lltype -> llmodule -> bool
272 (** [delete_type_name name] removes a type name from the module's symbol
274 val delete_type_name : string -> llmodule -> unit
277 (** [type_by_name m n] returns the type in the module [m] named [n], or [None]
278 if it does not exist. See the method [llvm::Module::getTypeByName]. *)
279 val type_by_name : llmodule -> string -> lltype option
282 (** [dump_module m] prints the .ll representation of the module [m] to standard
283 error. See the method [llvm::Module::dump]. *)
284 val dump_module : llmodule -> unit
286 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
287 the method [llvm::Module::setModuleInlineAsm]. *)
288 val set_module_inline_asm : llmodule -> string -> unit
294 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
295 See the method [llvm::Type::getTypeID]. *)
296 val classify_type : lltype -> TypeKind.t
298 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
299 See the method [llvm::Type::getContext]. *)
300 val type_context : lltype -> llcontext
302 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
303 val string_of_lltype : lltype -> string
305 (** {7 Operations on integer types} *)
307 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
308 [llvm::Type::Int1Ty]. *)
309 val i1_type : llcontext -> lltype
311 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
312 [llvm::Type::Int8Ty]. *)
313 val i8_type : llcontext -> lltype
315 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
316 [llvm::Type::Int16Ty]. *)
317 val i16_type : llcontext -> lltype
319 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
320 [llvm::Type::Int32Ty]. *)
321 val i32_type : llcontext -> lltype
323 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
324 [llvm::Type::Int64Ty]. *)
325 val i64_type : llcontext -> lltype
327 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
328 [c]. See the method [llvm::IntegerType::get]. *)
329 val integer_type : llcontext -> int -> lltype
331 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
332 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
333 val integer_bitwidth : lltype -> int
336 (** {7 Operations on real types} *)
338 (** [float_type c] returns the IEEE 32-bit floating point type in the context
339 [c]. See [llvm::Type::FloatTy]. *)
340 val float_type : llcontext -> lltype
342 (** [double_type c] returns the IEEE 64-bit floating point type in the context
343 [c]. See [llvm::Type::DoubleTy]. *)
344 val double_type : llcontext -> lltype
346 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
347 [c]. See [llvm::Type::X86_FP80Ty]. *)
348 val x86fp80_type : llcontext -> lltype
350 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
351 [c]. See [llvm::Type::FP128Ty]. *)
352 val fp128_type : llcontext -> lltype
354 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
355 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
356 val ppc_fp128_type : llcontext -> lltype
359 (** {7 Operations on function types} *)
361 (** [function_type ret_ty param_tys] returns the function type returning
362 [ret_ty] and taking [param_tys] as parameters.
363 See the method [llvm::FunctionType::get]. *)
364 val function_type : lltype -> lltype array -> lltype
366 (** [va_arg_function_type ret_ty param_tys] is just like
367 [function_type ret_ty param_tys] except that it returns the function type
368 which also takes a variable number of arguments.
369 See the method [llvm::FunctionType::get]. *)
370 val var_arg_function_type : lltype -> lltype array -> lltype
373 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
374 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
375 val is_var_arg : lltype -> bool
377 (** [return_type fty] gets the return type of the function type [fty].
378 See the method [llvm::FunctionType::getReturnType]. *)
379 val return_type : lltype -> lltype
381 (** [param_types fty] gets the parameter types of the function type [fty].
382 See the method [llvm::FunctionType::getParamType]. *)
383 val param_types : lltype -> lltype array
386 (** {7 Operations on struct types} *)
388 (** [struct_type context tys] returns the structure type in the context
389 [context] containing in the types in the array [tys]. See the method
390 [llvm::StructType::get]. *)
391 val struct_type : llcontext -> lltype array -> lltype
394 (** [packed_struct_type context ys] returns the packed structure type in the
395 context [context] containing in the types in the array [tys]. See the method
396 [llvm::StructType::get]. *)
397 val packed_struct_type : llcontext -> lltype array -> lltype
400 (** [struct_element_types sty] returns the constituent types of the struct type
401 [sty]. See the method [llvm::StructType::getElementType]. *)
402 val struct_element_types : lltype -> lltype array
405 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
406 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
407 val is_packed : lltype -> bool
410 (** {7 Operations on pointer, vector, and array types} *)
412 (** [array_type ty n] returns the array type containing [n] elements of type
413 [ty]. See the method [llvm::ArrayType::get]. *)
414 val array_type : lltype -> int -> lltype
416 (** [pointer_type ty] returns the pointer type referencing objects of type
417 [ty] in the default address space (0).
418 See the method [llvm::PointerType::getUnqual]. *)
419 val pointer_type : lltype -> lltype
421 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
422 of type [ty] in address space [as].
423 See the method [llvm::PointerType::get]. *)
424 val qualified_pointer_type : lltype -> int -> lltype
427 (** [vector_type ty n] returns the array type containing [n] elements of the
428 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
429 val vector_type : lltype -> int -> lltype
431 (** [element_type ty] returns the element type of the pointer, vector, or array
432 type [ty]. See the method [llvm::SequentialType::get]. *)
433 val element_type : lltype -> lltype
435 (** [element_type aty] returns the element count of the array type [aty].
436 See the method [llvm::ArrayType::getNumElements]. *)
437 val array_length : lltype -> int
439 (** [address_space pty] returns the address space qualifier of the pointer type
440 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
441 val address_space : lltype -> int
443 (** [element_type ty] returns the element count of the vector type [ty].
444 See the method [llvm::VectorType::getNumElements]. *)
445 val vector_size : lltype -> int
448 (** {7 Operations on other types} *)
450 (** [opaque_type c] creates a new opaque type distinct from any other in the
451 context [c]. Opaque types are useful for building recursive types in
452 combination with {!refine_type}. See [llvm::OpaqueType::get]. *)
453 val opaque_type : llcontext -> lltype
455 (** [void_type c] creates a type of a function which does not return any
456 value in the context [c]. See [llvm::Type::VoidTy]. *)
457 val void_type : llcontext -> lltype
459 (** [label_type c] creates a type of a basic block in the context [c]. See
460 [llvm::Type::LabelTy]. *)
461 val label_type : llcontext -> lltype
463 (** {7 Operations on type handles} *)
465 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
466 refined as a result of a call to {!refine_type}, the handle will be updated;
467 any bare [lltype] references will become invalid.
468 See the class [llvm::PATypeHolder]. *)
469 val handle_to_type : lltype -> lltypehandle
471 (** [type_of_handle tyh] resolves the type handle [tyh].
472 See the method [llvm::PATypeHolder::get()]. *)
473 val type_of_handle : lltypehandle -> lltype
475 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
476 concrete type [ty] in all users. Warning: This may invalidate {!lltype}
477 values! Use {!lltypehandle} to manipulate potentially abstract types. See
478 the method [llvm::Type::refineAbstractType]. *)
479 val refine_type : lltype -> lltype -> unit
484 (** [type_of v] returns the type of the value [v].
485 See the method [llvm::Value::getType]. *)
486 val type_of : llvalue -> lltype
488 (** [value_name v] returns the name of the value [v]. For global values, this is
489 the symbol name. For instructions and basic blocks, it is the SSA register
490 name. It is meaningless for constants.
491 See the method [llvm::Value::getName]. *)
492 val value_name : llvalue -> string
494 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
495 [llvm::Value::setName]. *)
496 val set_value_name : string -> llvalue -> unit
498 (** [dump_value v] prints the .ll representation of the value [v] to standard
499 error. See the method [llvm::Value::dump]. *)
500 val dump_value : llvalue -> unit
502 (** [replace_all_uses_with old new] replaces all uses of the value [old]
503 * with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
504 val replace_all_uses_with : llvalue -> llvalue -> unit
510 (** [use_begin v] returns the first position in the use list for the value [v].
511 [use_begin] and [use_succ] can e used to iterate over the use list in order.
512 See the method [llvm::Value::use_begin]. *)
513 val use_begin : llvalue -> lluse option
515 (** [use_succ u] returns the use list position succeeding [u].
516 See the method [llvm::use_value_iterator::operator++]. *)
517 val use_succ : lluse -> lluse option
519 (** [user u] returns the user of the use [u].
520 See the method [llvm::Use::getUser]. *)
521 val user : lluse -> llvalue
523 (** [used_value u] returns the usee of the use [u].
524 See the method [llvm::Use::getUsedValue]. *)
525 val used_value : lluse -> llvalue
527 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
528 in order. Tail recursive. *)
529 val iter_uses : (lluse -> unit) -> llvalue -> unit
531 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
532 [u1,...,uN] are the users of the value [v]. Tail recursive. *)
533 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
535 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
536 [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
537 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
542 (** [operand v i] returns the operand at index [i] for the value [v]. See the
543 method [llvm::User::getOperand]. *)
544 val operand : llvalue -> int -> llvalue
546 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
548 See the method [llvm::User::setOperand]. *)
549 val set_operand : llvalue -> int -> llvalue -> unit
551 (** [num_operands v] returns the number of operands for the value [v].
552 See the method [llvm::User::getNumOperands]. *)
553 val num_operands : llvalue -> int
555 (** {7 Operations on constants of (mostly) any type} *)
557 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
558 otherwise. Similar to [llvm::isa<Constant>]. *)
559 val is_constant : llvalue -> bool
561 (** [const_null ty] returns the constant null (zero) of the type [ty].
562 See the method [llvm::Constant::getNullValue]. *)
563 val const_null : lltype -> llvalue
565 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
566 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
567 val const_all_ones : (*int|vec*)lltype -> llvalue
569 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
570 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
571 val const_pointer_null : lltype -> llvalue
573 (** [undef ty] returns the undefined value of the type [ty].
574 See the method [llvm::UndefValue::get]. *)
575 val undef : lltype -> llvalue
577 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
578 See the method [llvm::Constant::isNullValue]. *)
579 val is_null : llvalue -> bool
581 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
582 otherwise. Similar to [llvm::isa<UndefValue>]. *)
583 val is_undef : llvalue -> bool
586 (** {7 Operations on instructions} *)
588 (** [has_metadata i] returns whether or not the instruction [i] has any
589 metadata attached to it. See the function
590 [llvm::Instruction::hasMetadata]. *)
591 val has_metadata : llvalue -> bool
593 (** [metadata i kind] optionally returns the metadata associated with the
594 kind [kind] in the instruction [i] See the function
595 [llvm::Instruction::getMetadata]. *)
596 val metadata : llvalue -> int -> llvalue option
598 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
599 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
600 val set_metadata : llvalue -> int -> llvalue -> unit
602 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
603 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
604 val clear_metadata : llvalue -> int -> unit
607 (** {7 Operations on metadata} *)
609 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
610 See the method [llvm::MDNode::get]. *)
611 val mdstring : llcontext -> string -> llvalue
613 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
615 See the method [llvm::MDNode::get]. *)
616 val mdnode : llcontext -> llvalue array -> llvalue
619 (** {7 Operations on scalar constants} *)
621 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
622 See the method [llvm::ConstantInt::get]. *)
623 val const_int : lltype -> int -> llvalue
625 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
626 [i]. See the method [llvm::ConstantInt::get]. *)
627 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
630 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
631 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
632 val const_int_of_string : lltype -> string -> int -> llvalue
635 (** [const_float ty n] returns the floating point constant of type [ty] and
636 value [n]. See the method [llvm::ConstantFP::get]. *)
637 val const_float : lltype -> float -> llvalue
639 (** [const_float_of_string ty s] returns the floating point constant of type
640 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
641 val const_float_of_string : lltype -> string -> llvalue
645 (** {7 Operations on composite constants} *)
647 (** [const_string c s] returns the constant [i8] array with the values of the
648 characters in the string [s] in the context [c]. The array is not
649 null-terminated (but see {!const_stringz}). This value can in turn be used
650 as the initializer for a global variable. See the method
651 [llvm::ConstantArray::get]. *)
652 val const_string : llcontext -> string -> llvalue
654 (** [const_stringz c s] returns the constant [i8] array with the values of the
655 characters in the string [s] and a null terminator in the context [c]. This
656 value can in turn be used as the initializer for a global variable.
657 See the method [llvm::ConstantArray::get]. *)
658 val const_stringz : llcontext -> string -> llvalue
660 (** [const_array ty elts] returns the constant array of type
661 [array_type ty (Array.length elts)] and containing the values [elts].
662 This value can in turn be used as the initializer for a global variable.
663 See the method [llvm::ConstantArray::get]. *)
664 val const_array : lltype -> llvalue array -> llvalue
666 (** [const_struct context elts] returns the structured constant of type
667 [struct_type (Array.map type_of elts)] and containing the values [elts]
668 in the context [context]. This value can in turn be used as the initializer
669 for a global variable. See the method [llvm::ConstantStruct::get]. *)
670 val const_struct : llcontext -> llvalue array -> llvalue
673 (** [const_packed_struct context elts] returns the structured constant of
674 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
675 values [elts] in the context [context]. This value can in turn be used as
676 the initializer for a global variable. See the method
677 [llvm::ConstantStruct::get]. *)
678 val const_packed_struct : llcontext -> llvalue array -> llvalue
681 (** [const_vector elts] returns the vector constant of type
682 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
683 values [elts]. See the method [llvm::ConstantVector::get]. *)
684 val const_vector : llvalue array -> llvalue
687 (** {7 Constant expressions} *)
689 (** [align_of ty] returns the alignof constant for the type [ty]. This is
690 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
691 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
692 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
693 val align_of : lltype -> llvalue
695 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
696 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
697 (const_int i32_type 1)) i64_type], but considerably more readable.
698 See the method [llvm::ConstantExpr::getSizeOf]. *)
699 val size_of : lltype -> llvalue
701 (** [const_neg c] returns the arithmetic negation of the constant [c].
702 See the method [llvm::ConstantExpr::getNeg]. *)
703 val const_neg : llvalue -> llvalue
705 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
706 no signed wrapping. The result is undefined if the negation overflows.
707 See the method [llvm::ConstantExpr::getNSWNeg]. *)
708 val const_nsw_neg : llvalue -> llvalue
710 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
711 no unsigned wrapping. The result is undefined if the negation overflows.
712 See the method [llvm::ConstantExpr::getNUWNeg]. *)
713 val const_nuw_neg : llvalue -> llvalue
715 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
716 See the method [llvm::ConstantExpr::getFNeg]. *)
717 val const_fneg : llvalue -> llvalue
719 (** [const_not c] returns the bitwise inverse of the constant [c].
720 See the method [llvm::ConstantExpr::getNot]. *)
721 val const_not : llvalue -> llvalue
723 (** [const_add c1 c2] returns the constant sum of two constants.
724 See the method [llvm::ConstantExpr::getAdd]. *)
725 val const_add : llvalue -> llvalue -> llvalue
727 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
728 signed wrapping. The result is undefined if the sum overflows.
729 See the method [llvm::ConstantExpr::getNSWAdd]. *)
730 val const_nsw_add : llvalue -> llvalue -> llvalue
732 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
733 unsigned wrapping. The result is undefined if the sum overflows.
734 See the method [llvm::ConstantExpr::getNSWAdd]. *)
735 val const_nuw_add : llvalue -> llvalue -> llvalue
737 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
738 See the method [llvm::ConstantExpr::getFAdd]. *)
739 val const_fadd : llvalue -> llvalue -> llvalue
741 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
742 constants. See the method [llvm::ConstantExpr::getSub]. *)
743 val const_sub : llvalue -> llvalue -> llvalue
745 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
746 no signed wrapping. The result is undefined if the sum overflows.
747 See the method [llvm::ConstantExpr::getNSWSub]. *)
748 val const_nsw_sub : llvalue -> llvalue -> llvalue
750 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
751 no unsigned wrapping. The result is undefined if the sum overflows.
752 See the method [llvm::ConstantExpr::getNSWSub]. *)
753 val const_nuw_sub : llvalue -> llvalue -> llvalue
755 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
756 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
757 val const_fsub : llvalue -> llvalue -> llvalue
759 (** [const_mul c1 c2] returns the constant product of two constants.
760 See the method [llvm::ConstantExpr::getMul]. *)
761 val const_mul : llvalue -> llvalue -> llvalue
763 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
764 no signed wrapping. The result is undefined if the sum overflows.
765 See the method [llvm::ConstantExpr::getNSWMul]. *)
766 val const_nsw_mul : llvalue -> llvalue -> llvalue
768 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
769 no unsigned wrapping. The result is undefined if the sum overflows.
770 See the method [llvm::ConstantExpr::getNSWMul]. *)
771 val const_nuw_mul : llvalue -> llvalue -> llvalue
773 (** [const_fmul c1 c2] returns the constant product of two constants floats.
774 See the method [llvm::ConstantExpr::getFMul]. *)
775 val const_fmul : llvalue -> llvalue -> llvalue
777 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
779 See the method [llvm::ConstantExpr::getUDiv]. *)
780 val const_udiv : llvalue -> llvalue -> llvalue
782 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
784 See the method [llvm::ConstantExpr::getSDiv]. *)
785 val const_sdiv : llvalue -> llvalue -> llvalue
787 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
788 signed integer constants. The result is undefined if the result is rounded
789 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
790 val const_exact_sdiv : llvalue -> llvalue -> llvalue
792 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
794 See the method [llvm::ConstantExpr::getFDiv]. *)
795 val const_fdiv : llvalue -> llvalue -> llvalue
797 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
798 unsigned integer constants.
799 See the method [llvm::ConstantExpr::getURem]. *)
800 val const_urem : llvalue -> llvalue -> llvalue
802 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
803 signed integer constants.
804 See the method [llvm::ConstantExpr::getSRem]. *)
805 val const_srem : llvalue -> llvalue -> llvalue
807 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
808 signed floating point constants.
809 See the method [llvm::ConstantExpr::getFRem]. *)
810 val const_frem : llvalue -> llvalue -> llvalue
812 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
814 See the method [llvm::ConstantExpr::getAnd]. *)
815 val const_and : llvalue -> llvalue -> llvalue
817 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
819 See the method [llvm::ConstantExpr::getOr]. *)
820 val const_or : llvalue -> llvalue -> llvalue
822 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
824 See the method [llvm::ConstantExpr::getXor]. *)
825 val const_xor : llvalue -> llvalue -> llvalue
827 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
828 constants, [c1 pred c2].
829 See the method [llvm::ConstantExpr::getICmp]. *)
830 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
833 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
834 point constants, [c1 pred c2].
835 See the method [llvm::ConstantExpr::getFCmp]. *)
836 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
839 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
840 constant integer [c2].
841 See the method [llvm::ConstantExpr::getShl]. *)
842 val const_shl : llvalue -> llvalue -> llvalue
844 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
845 constant integer [c2] with zero extension.
846 See the method [llvm::ConstantExpr::getLShr]. *)
847 val const_lshr : llvalue -> llvalue -> llvalue
849 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
850 constant integer [c2] with sign extension.
851 See the method [llvm::ConstantExpr::getAShr]. *)
852 val const_ashr : llvalue -> llvalue -> llvalue
854 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
855 constant integers indices from the array [indices].
856 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
857 val const_gep : llvalue -> llvalue array -> llvalue
859 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
860 with the constant integers indices from the array [indices].
861 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
862 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
865 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
866 to the smaller integer type [ty].
867 See the method [llvm::ConstantExpr::getTrunc]. *)
868 val const_trunc : llvalue -> lltype -> llvalue
870 (** [const_sext c ty] returns the constant sign extension of integer constant
871 [c] to the larger integer type [ty].
872 See the method [llvm::ConstantExpr::getSExt]. *)
873 val const_sext : llvalue -> lltype -> llvalue
875 (** [const_zext c ty] returns the constant zero extension of integer constant
876 [c] to the larger integer type [ty].
877 See the method [llvm::ConstantExpr::getZExt]. *)
878 val const_zext : llvalue -> lltype -> llvalue
880 (** [const_fptrunc c ty] returns the constant truncation of floating point
881 constant [c] to the smaller floating point type [ty].
882 See the method [llvm::ConstantExpr::getFPTrunc]. *)
883 val const_fptrunc : llvalue -> lltype -> llvalue
885 (** [const_fpext c ty] returns the constant extension of floating point constant
886 [c] to the larger floating point type [ty].
887 See the method [llvm::ConstantExpr::getFPExt]. *)
888 val const_fpext : llvalue -> lltype -> llvalue
890 (** [const_uitofp c ty] returns the constant floating point conversion of
891 unsigned integer constant [c] to the floating point type [ty].
892 See the method [llvm::ConstantExpr::getUIToFP]. *)
893 val const_uitofp : llvalue -> lltype -> llvalue
895 (** [const_sitofp c ty] returns the constant floating point conversion of
896 signed integer constant [c] to the floating point type [ty].
897 See the method [llvm::ConstantExpr::getSIToFP]. *)
898 val const_sitofp : llvalue -> lltype -> llvalue
900 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
901 floating point constant [c] to integer type [ty].
902 See the method [llvm::ConstantExpr::getFPToUI]. *)
903 val const_fptoui : llvalue -> lltype -> llvalue
905 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
906 floating point constant [c] to integer type [ty].
907 See the method [llvm::ConstantExpr::getFPToSI]. *)
908 val const_fptosi : llvalue -> lltype -> llvalue
910 (** [const_ptrtoint c ty] returns the constant integer conversion of
911 pointer constant [c] to integer type [ty].
912 See the method [llvm::ConstantExpr::getPtrToInt]. *)
913 val const_ptrtoint : llvalue -> lltype -> llvalue
915 (** [const_inttoptr c ty] returns the constant pointer conversion of
916 integer constant [c] to pointer type [ty].
917 See the method [llvm::ConstantExpr::getIntToPtr]. *)
918 val const_inttoptr : llvalue -> lltype -> llvalue
920 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
921 to type [ty] of equal size.
922 See the method [llvm::ConstantExpr::getBitCast]. *)
923 val const_bitcast : llvalue -> lltype -> llvalue
925 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
926 conversion of constant [c] to type [ty].
927 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
928 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
931 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
932 conversion of constant [c] to type [ty].
933 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
934 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
937 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
938 conversion of constant [c] to type [ty].
939 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
940 val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
943 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
944 cast conversion of constant [c] to type [ty] of equal size.
945 See the method [llvm::ConstantExpr::getPointerCast]. *)
946 val const_pointercast : llvalue -> lltype -> llvalue
949 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
950 -> integer casts of constant [c] to type [ty].
951 See the method [llvm::ConstantExpr::getIntCast]. *)
952 val const_intcast : llvalue -> lltype -> llvalue
955 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
956 fp casts of constant [c] to type [ty].
957 See the method [llvm::ConstantExpr::getFPCast]. *)
958 val const_fpcast : llvalue -> lltype -> llvalue
961 (** [const_select cond t f] returns the constant conditional which returns value
962 [t] if the boolean constant [cond] is true and the value [f] otherwise.
963 See the method [llvm::ConstantExpr::getSelect]. *)
964 val const_select : llvalue -> llvalue -> llvalue -> llvalue
967 (** [const_extractelement vec i] returns the constant [i]th element of
968 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
969 the size of the vector.
970 See the method [llvm::ConstantExpr::getExtractElement]. *)
971 val const_extractelement : llvalue -> llvalue -> llvalue
974 (** [const_insertelement vec v i] returns the constant vector with the same
975 elements as constant vector [v] but the [i]th element replaced by the
976 constant [v]. [v] must be a constant value with the type of the vector
977 elements. [i] must be a constant [i32] value unsigned less than the size
979 See the method [llvm::ConstantExpr::getInsertElement]. *)
980 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
983 (** [const_shufflevector a b mask] returns a constant [shufflevector].
984 See the LLVM Language Reference for details on the [shufflevector]
986 See the method [llvm::ConstantExpr::getShuffleVector]. *)
987 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
990 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
991 constant aggregate [agg]. Each [idxs] must be less than the size of the
992 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
993 val const_extractvalue : llvalue -> int array -> llvalue
996 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
997 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
998 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
999 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
1002 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
1003 See the method [llvm::InlineAsm::get]. *)
1004 val const_inline_asm : lltype -> string -> string -> bool -> bool ->
1008 (** [block_address f bb] returns the address of the basic block [bb] in the
1009 function [f]. See the method [llvm::BasicBlock::get]. *)
1010 val block_address : llvalue -> llbasicblock -> llvalue
1013 (** {7 Operations on global variables, functions, and aliases (globals)} *)
1015 (** [global_parent g] is the enclosing module of the global value [g].
1016 See the method [llvm::GlobalValue::getParent]. *)
1017 val global_parent : llvalue -> llmodule
1019 (** [is_declaration g] returns [true] if the global value [g] is a declaration
1020 only. Returns [false] otherwise.
1021 See the method [llvm::GlobalValue::isDeclaration]. *)
1022 val is_declaration : llvalue -> bool
1024 (** [linkage g] returns the linkage of the global value [g].
1025 See the method [llvm::GlobalValue::getLinkage]. *)
1026 val linkage : llvalue -> Linkage.t
1028 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
1029 See the method [llvm::GlobalValue::setLinkage]. *)
1030 val set_linkage : Linkage.t -> llvalue -> unit
1032 (** [section g] returns the linker section of the global value [g].
1033 See the method [llvm::GlobalValue::getSection]. *)
1034 val section : llvalue -> string
1036 (** [set_section s g] sets the linker section of the global value [g] to [s].
1037 See the method [llvm::GlobalValue::setSection]. *)
1038 val set_section : string -> llvalue -> unit
1040 (** [visibility g] returns the linker visibility of the global value [g].
1041 See the method [llvm::GlobalValue::getVisibility]. *)
1042 val visibility : llvalue -> Visibility.t
1044 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1045 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1046 val set_visibility : Visibility.t -> llvalue -> unit
1049 (** [alignment g] returns the required alignment of the global value [g].
1050 See the method [llvm::GlobalValue::getAlignment]. *)
1051 val alignment : llvalue -> int
1053 (** [set_alignment n g] sets the required alignment of the global value [g] to
1054 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1055 val set_alignment : int -> llvalue -> unit
1058 (** {7 Operations on global variables} *)
1060 (** [declare_global ty name m] returns a new global variable of type [ty] and
1061 with name [name] in module [m] in the default address space (0). If such a
1062 global variable already exists, it is returned. If the type of the existing
1063 global differs, then a bitcast to [ty] is returned. *)
1064 val declare_global : lltype -> string -> llmodule -> llvalue
1067 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1068 of type [ty] and with name [name] in module [m] in the address space
1069 [addrspace]. If such a global variable already exists, it is returned. If
1070 the type of the existing global differs, then a bitcast to [ty] is
1072 val declare_qualified_global : lltype -> string -> int -> llmodule ->
1076 (** [define_global name init m] returns a new global with name [name] and
1077 initializer [init] in module [m] in the default address space (0). If the
1078 named global already exists, it is renamed.
1079 See the constructor of [llvm::GlobalVariable]. *)
1080 val define_global : string -> llvalue -> llmodule -> llvalue
1083 (** [define_qualified_global name init addrspace m] returns a new global with
1084 name [name] and initializer [init] in module [m] in the address space
1085 [addrspace]. If the named global already exists, it is renamed.
1086 See the constructor of [llvm::GlobalVariable]. *)
1087 val define_qualified_global : string -> llvalue -> int -> llmodule ->
1091 (** [lookup_global name m] returns [Some g] if a global variable with name
1092 [name] exists in module [m]. If no such global exists, returns [None].
1093 See the [llvm::GlobalVariable] constructor. *)
1094 val lookup_global : string -> llmodule -> llvalue option
1097 (** [delete_global gv] destroys the global variable [gv].
1098 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1099 val delete_global : llvalue -> unit
1101 (** [global_begin m] returns the first position in the global variable list of
1102 the module [m]. [global_begin] and [global_succ] can be used to iterate
1103 over the global list in order.
1104 See the method [llvm::Module::global_begin]. *)
1105 val global_begin : llmodule -> (llmodule, llvalue) llpos
1108 (** [global_succ gv] returns the global variable list position succeeding
1110 See the method [llvm::Module::global_iterator::operator++]. *)
1111 val global_succ : llvalue -> (llmodule, llvalue) llpos
1114 (** [iter_globals f m] applies function [f] to each of the global variables of
1115 module [m] in order. Tail recursive. *)
1116 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1118 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1119 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1120 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1122 (** [global_end m] returns the last position in the global variable list of the
1123 module [m]. [global_end] and [global_pred] can be used to iterate over the
1124 global list in reverse.
1125 See the method [llvm::Module::global_end]. *)
1126 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1129 (** [global_pred gv] returns the global variable list position preceding
1131 See the method [llvm::Module::global_iterator::operator--]. *)
1132 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1135 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1136 of module [m] in reverse order. Tail recursive. *)
1137 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1139 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1140 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1141 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1143 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1144 constant. Returns [false] otherwise.
1145 See the method [llvm::GlobalVariable::isConstant]. *)
1146 val is_global_constant : llvalue -> bool
1148 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1149 [c] is [true] and not if [c] is [false].
1150 See the method [llvm::GlobalVariable::setConstant]. *)
1151 val set_global_constant : bool -> llvalue -> unit
1154 (** [global_initializer gv] returns the initializer for the global variable
1155 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1156 val global_initializer : llvalue -> llvalue
1158 (** [set_initializer c gv] sets the initializer for the global variable
1159 [gv] to the constant [c].
1160 See the method [llvm::GlobalVariable::setInitializer]. *)
1161 val set_initializer : llvalue -> llvalue -> unit
1163 (** [remove_initializer gv] unsets the initializer for the global variable
1165 See the method [llvm::GlobalVariable::setInitializer]. *)
1166 val remove_initializer : llvalue -> unit
1168 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1169 thread-local and [false] otherwise.
1170 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1171 val is_thread_local : llvalue -> bool
1173 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1174 [c] is [true] and not otherwise.
1175 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1176 val set_thread_local : bool -> llvalue -> unit
1179 (** {7 Operations on aliases} *)
1181 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1182 the aliasee [a] with the name [n].
1183 See the constructor for [llvm::GlobalAlias]. *)
1184 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1188 (** {7 Operations on functions} *)
1190 (** [declare_function name ty m] returns a new function of type [ty] and
1191 with name [name] in module [m]. If such a function already exists,
1192 it is returned. If the type of the existing function differs, then a bitcast
1193 to [ty] is returned. *)
1194 val declare_function : string -> lltype -> llmodule -> llvalue
1197 (** [define_function name ty m] creates a new function with name [name] and
1198 type [ty] in module [m]. If the named function already exists, it is
1199 renamed. An entry basic block is created in the function.
1200 See the constructor of [llvm::GlobalVariable]. *)
1201 val define_function : string -> lltype -> llmodule -> llvalue
1204 (** [lookup_function name m] returns [Some f] if a function with name
1205 [name] exists in module [m]. If no such function exists, returns [None].
1206 See the method [llvm::Module] constructor. *)
1207 val lookup_function : string -> llmodule -> llvalue option
1210 (** [delete_function f] destroys the function [f].
1211 See the method [llvm::Function::eraseFromParent]. *)
1212 val delete_function : llvalue -> unit
1214 (** [function_begin m] returns the first position in the function list of the
1215 module [m]. [function_begin] and [function_succ] can be used to iterate over
1216 the function list in order.
1217 See the method [llvm::Module::begin]. *)
1218 val function_begin : llmodule -> (llmodule, llvalue) llpos
1221 (** [function_succ gv] returns the function list position succeeding
1223 See the method [llvm::Module::iterator::operator++]. *)
1224 val function_succ : llvalue -> (llmodule, llvalue) llpos
1227 (** [iter_functions f m] applies function [f] to each of the functions of module
1228 [m] in order. Tail recursive. *)
1229 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1231 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1232 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1233 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1235 (** [function_end m] returns the last position in the function list of
1236 the module [m]. [function_end] and [function_pred] can be used to iterate
1237 over the function list in reverse.
1238 See the method [llvm::Module::end]. *)
1239 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1242 (** [function_pred gv] returns the function list position preceding [After gv].
1243 See the method [llvm::Module::iterator::operator--]. *)
1244 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1247 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1248 module [m] in reverse order. Tail recursive. *)
1249 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1251 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1252 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1253 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1255 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1256 See the method [llvm::Function::isIntrinsic]. *)
1257 val is_intrinsic : llvalue -> bool
1259 (** [function_call_conv f] returns the calling convention of the function [f].
1260 See the method [llvm::Function::getCallingConv]. *)
1261 val function_call_conv : llvalue -> int
1263 (** [set_function_call_conv cc f] sets the calling convention of the function
1264 [f] to the calling convention numbered [cc].
1265 See the method [llvm::Function::setCallingConv]. *)
1266 val set_function_call_conv : int -> llvalue -> unit
1269 (** [gc f] returns [Some name] if the function [f] has a garbage
1270 collection algorithm specified and [None] otherwise.
1271 See the method [llvm::Function::getGC]. *)
1272 val gc : llvalue -> string option
1274 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1275 [gc]. See the method [llvm::Function::setGC]. *)
1276 val set_gc : string option -> llvalue -> unit
1278 (** [add_function_attr f a] adds attribute [a] to the return type of function
1280 val add_function_attr : llvalue -> Attribute.t -> unit
1282 (** [remove_function_attr f a] removes attribute [a] from the return type of
1284 val remove_function_attr : llvalue -> Attribute.t -> unit
1286 (** {7 Operations on params} *)
1288 (** [params f] returns the parameters of function [f].
1289 See the method [llvm::Function::getArgumentList]. *)
1290 val params : llvalue -> llvalue array
1292 (** [param f n] returns the [n]th parameter of function [f].
1293 See the method [llvm::Function::getArgumentList]. *)
1294 val param : llvalue -> int -> llvalue
1296 (** [param_parent p] returns the parent function that owns the parameter.
1297 See the method [llvm::Argument::getParent]. *)
1298 val param_parent : llvalue -> llvalue
1300 (** [param_begin f] returns the first position in the parameter list of the
1301 function [f]. [param_begin] and [param_succ] can be used to iterate over
1302 the parameter list in order.
1303 See the method [llvm::Function::arg_begin]. *)
1304 val param_begin : llvalue -> (llvalue, llvalue) llpos
1306 (** [param_succ bb] returns the parameter list position succeeding
1308 See the method [llvm::Function::arg_iterator::operator++]. *)
1309 val param_succ : llvalue -> (llvalue, llvalue) llpos
1311 (** [iter_params f fn] applies function [f] to each of the parameters
1312 of function [fn] in order. Tail recursive. *)
1313 val iter_params : (llvalue -> unit) -> llvalue -> unit
1315 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1316 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1317 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1319 (** [param_end f] returns the last position in the parameter list of
1320 the function [f]. [param_end] and [param_pred] can be used to iterate
1321 over the parameter list in reverse.
1322 See the method [llvm::Function::arg_end]. *)
1323 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1325 (** [param_pred gv] returns the function list position preceding [After gv].
1326 See the method [llvm::Function::arg_iterator::operator--]. *)
1327 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1330 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1331 of function [fn] in reverse order. Tail recursive. *)
1332 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1334 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1335 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1336 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1338 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1339 val add_param_attr : llvalue -> Attribute.t -> unit
1341 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1342 val remove_param_attr : llvalue -> Attribute.t -> unit
1344 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1345 val set_param_alignment : llvalue -> int -> unit
1348 (** {7 Operations on basic blocks} *)
1350 (** [basic_blocks fn] returns the basic blocks of the function [f].
1351 See the method [llvm::Function::getBasicBlockList]. *)
1352 val basic_blocks : llvalue -> llbasicblock array
1354 (** [entry_block fn] returns the entry basic block of the function [f].
1355 See the method [llvm::Function::getEntryBlock]. *)
1356 val entry_block : llvalue -> llbasicblock
1358 (** [delete_block bb] deletes the basic block [bb].
1359 See the method [llvm::BasicBlock::eraseFromParent]. *)
1360 val delete_block : llbasicblock -> unit
1362 (** [append_block c name f] creates a new basic block named [name] at the end of
1363 function [f] in the context [c].
1364 See the constructor of [llvm::BasicBlock]. *)
1365 val append_block : llcontext -> string -> llvalue -> llbasicblock
1368 (** [insert_block c name bb] creates a new basic block named [name] before the
1369 basic block [bb] in the context [c].
1370 See the constructor of [llvm::BasicBlock]. *)
1371 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1374 (** [block_parent bb] returns the parent function that owns the basic block.
1375 See the method [llvm::BasicBlock::getParent]. *)
1376 val block_parent : llbasicblock -> llvalue
1378 (** [block_begin f] returns the first position in the basic block list of the
1379 function [f]. [block_begin] and [block_succ] can be used to iterate over
1380 the basic block list in order.
1381 See the method [llvm::Function::begin]. *)
1382 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1385 (** [block_succ bb] returns the basic block list position succeeding
1387 See the method [llvm::Function::iterator::operator++]. *)
1388 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1391 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1392 of function [fn] in order. Tail recursive. *)
1393 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1395 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1396 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1397 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1399 (** [block_end f] returns the last position in the basic block list of
1400 the function [f]. [block_end] and [block_pred] can be used to iterate
1401 over the basic block list in reverse.
1402 See the method [llvm::Function::end]. *)
1403 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1406 (** [block_pred gv] returns the function list position preceding [After gv].
1407 See the method [llvm::Function::iterator::operator--]. *)
1408 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1411 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1412 of function [fn] in reverse order. Tail recursive. *)
1413 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1415 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1416 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1417 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1419 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1420 val value_of_block : llbasicblock -> llvalue
1422 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1424 Similar to [llvm::isa<BasicBlock>]. *)
1425 val value_is_block : llvalue -> bool
1427 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1428 val block_of_value : llvalue -> llbasicblock
1431 (** {7 Operations on instructions} *)
1433 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1434 See the method [llvm::Instruction::getParent]. *)
1435 val instr_parent : llvalue -> llbasicblock
1437 (** [instr_begin bb] returns the first position in the instruction list of the
1438 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1439 the instruction list in order.
1440 See the method [llvm::BasicBlock::begin]. *)
1441 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1444 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1445 See the method [llvm::BasicBlock::iterator::operator++]. *)
1446 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1449 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1450 block [bb] in order. Tail recursive. *)
1451 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1453 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1454 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1455 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1457 (** [instr_end bb] returns the last position in the instruction list of the
1458 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1459 the instruction list in reverse.
1460 See the method [llvm::BasicBlock::end]. *)
1461 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1464 (** [instr_pred i] returns the instruction list position preceding [After i].
1465 See the method [llvm::BasicBlock::iterator::operator--]. *)
1466 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1469 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1470 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1471 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1474 (** {7 Operations on call sites} *)
1476 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1477 instruction [ci], which may be one of the values from the module
1478 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1479 [llvm::InvokeInst::getCallingConv]. *)
1480 val instruction_call_conv: llvalue -> int
1483 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1484 or invoke instruction [ci] to the integer [cc], which can be one of the
1485 values from the module {!CallConv}.
1486 See the method [llvm::CallInst::setCallingConv]
1487 and [llvm::InvokeInst::setCallingConv]. *)
1488 val set_instruction_call_conv: int -> llvalue -> unit
1491 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1492 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1494 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1496 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1497 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1499 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1501 (** {Operations on call instructions (only)} *)
1503 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1504 eligible for tail call optimization, [false] otherwise.
1505 See the method [llvm::CallInst::isTailCall]. *)
1506 val is_tail_call : llvalue -> bool
1508 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1509 call optimization if [tc] is [true], clears otherwise.
1510 See the method [llvm::CallInst::setTailCall]. *)
1511 val set_tail_call : bool -> llvalue -> unit
1513 (** {7 Operations on phi nodes} *)
1515 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1516 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1517 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1520 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1521 See the method [llvm::PHINode::getIncomingValue]. *)
1522 val incoming : llvalue -> (llvalue * llbasicblock) list
1526 (** {6 Instruction builders} *)
1528 (** [builder context] creates an instruction builder with no position in
1529 the context [context]. It is invalid to use this builder until its position
1530 is set with {!position_before} or {!position_at_end}. See the constructor
1531 for [llvm::LLVMBuilder]. *)
1532 val builder : llcontext -> llbuilder
1534 (** [builder_at ip] creates an instruction builder positioned at [ip].
1535 See the constructor for [llvm::LLVMBuilder]. *)
1536 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1538 (** [builder_before ins] creates an instruction builder positioned before the
1539 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1540 val builder_before : llcontext -> llvalue -> llbuilder
1542 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1543 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1544 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1546 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1548 See the constructor for [llvm::LLVMBuilder]. *)
1549 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1552 (** [position_before ins b] moves the instruction builder [b] to before the
1553 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1554 val position_before : llvalue -> llbuilder -> unit
1556 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1557 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1558 val position_at_end : llbasicblock -> llbuilder -> unit
1560 (** [insertion_block b] returns the basic block that the builder [b] is
1561 positioned to insert into. Raises [Not_Found] if the instruction builder is
1563 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1564 val insertion_block : llbuilder -> llbasicblock
1566 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1567 position specified by the instruction builder [b].
1568 See the method [llvm::LLVMBuilder::Insert]. *)
1569 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1574 (** [set_current_debug_location b md] sets the current debug location [md] in
1576 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1577 val set_current_debug_location : llbuilder -> llvalue -> unit
1580 (** [clear_current_debug_location b] clears the current debug location in the
1582 val clear_current_debug_location : llbuilder -> unit
1585 (** [current_debug_location b] returns the current debug location, or None
1586 if none is currently set.
1587 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1588 val current_debug_location : llbuilder -> llvalue option
1591 (** [set_inst_debug_location b i] sets the current debug location of the builder
1592 [b] to the instruction [i].
1593 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1594 val set_inst_debug_location : llbuilder -> llvalue -> unit
1597 (** {7 Terminators} *)
1599 (** [build_ret_void b] creates a
1601 instruction at the position specified by the instruction builder [b].
1602 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1603 val build_ret_void : llbuilder -> llvalue
1605 (** [build_ret v b] creates a
1607 instruction at the position specified by the instruction builder [b].
1608 See the method [llvm::LLVMBuilder::CreateRet]. *)
1609 val build_ret : llvalue -> llbuilder -> llvalue
1611 (** [build_aggregate_ret vs b] creates a
1612 [ret {...} { %v1, %v2, ... } ]
1613 instruction at the position specified by the instruction builder [b].
1614 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1615 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1618 (** [build_br bb b] creates a
1620 instruction at the position specified by the instruction builder [b].
1621 See the method [llvm::LLVMBuilder::CreateBr]. *)
1622 val build_br : llbasicblock -> llbuilder -> llvalue
1624 (** [build_cond_br cond tbb fbb b] creates a
1625 [br %cond, %tbb, %fbb]
1626 instruction at the position specified by the instruction builder [b].
1627 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1628 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1631 (** [build_switch case elsebb count b] creates an empty
1632 [switch %case, %elsebb]
1633 instruction at the position specified by the instruction builder [b] with
1634 space reserved for [count] cases.
1635 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1636 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1639 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1640 when its input matches the constant [onval].
1641 See the method [llvm::SwitchInst::addCase]. **)
1642 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1645 (** [build_indirect_br addr count b] creates a
1647 instruction at the position specified by the instruction builder [b] with
1648 space reserved for [count] destinations.
1649 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1650 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1653 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1654 location for the indirectbr instruction [br].
1655 See the method [llvm::IndirectBrInst::addDestination]. **)
1656 val add_destination : llvalue -> llbasicblock -> unit
1659 (** [build_invoke fn args tobb unwindbb name b] creates an
1660 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1661 instruction at the position specified by the instruction builder [b].
1662 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1663 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1664 llbasicblock -> string -> llbuilder -> llvalue
1667 (** [build_unwind b] creates an
1669 instruction at the position specified by the instruction builder [b].
1670 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1671 val build_unwind : llbuilder -> llvalue
1673 (** [build_unreachable b] creates an
1675 instruction at the position specified by the instruction builder [b].
1676 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1677 val build_unreachable : llbuilder -> llvalue
1680 (** {7 Arithmetic} *)
1682 (** [build_add x y name b] creates a
1683 [%name = add %x, %y]
1684 instruction at the position specified by the instruction builder [b].
1685 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1686 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1689 (** [build_nsw_add x y name b] creates a
1690 [%name = nsw add %x, %y]
1691 instruction at the position specified by the instruction builder [b].
1692 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1693 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1696 (** [build_nuw_add x y name b] creates a
1697 [%name = nuw add %x, %y]
1698 instruction at the position specified by the instruction builder [b].
1699 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1700 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1703 (** [build_fadd x y name b] creates a
1704 [%name = fadd %x, %y]
1705 instruction at the position specified by the instruction builder [b].
1706 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1707 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1710 (** [build_sub x y name b] creates a
1711 [%name = sub %x, %y]
1712 instruction at the position specified by the instruction builder [b].
1713 See the method [llvm::LLVMBuilder::CreateSub]. *)
1714 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1717 (** [build_nsw_sub x y name b] creates a
1718 [%name = nsw sub %x, %y]
1719 instruction at the position specified by the instruction builder [b].
1720 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1721 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1724 (** [build_nuw_sub x y name b] creates a
1725 [%name = nuw sub %x, %y]
1726 instruction at the position specified by the instruction builder [b].
1727 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1728 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1731 (** [build_fsub x y name b] creates a
1732 [%name = fsub %x, %y]
1733 instruction at the position specified by the instruction builder [b].
1734 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1735 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1738 (** [build_mul x y name b] creates a
1739 [%name = mul %x, %y]
1740 instruction at the position specified by the instruction builder [b].
1741 See the method [llvm::LLVMBuilder::CreateMul]. *)
1742 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1745 (** [build_nsw_mul x y name b] creates a
1746 [%name = nsw mul %x, %y]
1747 instruction at the position specified by the instruction builder [b].
1748 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1749 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1752 (** [build_nuw_mul x y name b] creates a
1753 [%name = nuw mul %x, %y]
1754 instruction at the position specified by the instruction builder [b].
1755 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1756 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1759 (** [build_fmul x y name b] creates a
1760 [%name = fmul %x, %y]
1761 instruction at the position specified by the instruction builder [b].
1762 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1763 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1766 (** [build_udiv x y name b] creates a
1767 [%name = udiv %x, %y]
1768 instruction at the position specified by the instruction builder [b].
1769 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1770 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1773 (** [build_sdiv x y name b] creates a
1774 [%name = sdiv %x, %y]
1775 instruction at the position specified by the instruction builder [b].
1776 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1777 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1780 (** [build_exact_sdiv x y name b] creates a
1781 [%name = exact sdiv %x, %y]
1782 instruction at the position specified by the instruction builder [b].
1783 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1784 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1787 (** [build_fdiv x y name b] creates a
1788 [%name = fdiv %x, %y]
1789 instruction at the position specified by the instruction builder [b].
1790 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1791 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1794 (** [build_urem x y name b] creates a
1795 [%name = urem %x, %y]
1796 instruction at the position specified by the instruction builder [b].
1797 See the method [llvm::LLVMBuilder::CreateURem]. *)
1798 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1801 (** [build_SRem x y name b] creates a
1802 [%name = srem %x, %y]
1803 instruction at the position specified by the instruction builder [b].
1804 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1805 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1808 (** [build_frem x y name b] creates a
1809 [%name = frem %x, %y]
1810 instruction at the position specified by the instruction builder [b].
1811 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1812 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1815 (** [build_shl x y name b] creates a
1816 [%name = shl %x, %y]
1817 instruction at the position specified by the instruction builder [b].
1818 See the method [llvm::LLVMBuilder::CreateShl]. *)
1819 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1822 (** [build_lshr x y name b] creates a
1823 [%name = lshr %x, %y]
1824 instruction at the position specified by the instruction builder [b].
1825 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1826 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1829 (** [build_ashr x y name b] creates a
1830 [%name = ashr %x, %y]
1831 instruction at the position specified by the instruction builder [b].
1832 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1833 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1836 (** [build_and x y name b] creates a
1837 [%name = and %x, %y]
1838 instruction at the position specified by the instruction builder [b].
1839 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1840 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1843 (** [build_or x y name b] creates a
1845 instruction at the position specified by the instruction builder [b].
1846 See the method [llvm::LLVMBuilder::CreateOr]. *)
1847 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1850 (** [build_xor x y name b] creates a
1851 [%name = xor %x, %y]
1852 instruction at the position specified by the instruction builder [b].
1853 See the method [llvm::LLVMBuilder::CreateXor]. *)
1854 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1857 (** [build_neg x name b] creates a
1859 instruction at the position specified by the instruction builder [b].
1860 [-0.0] is used for floating point types to compute the correct sign.
1861 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1862 val build_neg : llvalue -> string -> llbuilder -> llvalue
1865 (** [build_nsw_neg x name b] creates a
1866 [%name = nsw sub 0, %x]
1867 instruction at the position specified by the instruction builder [b].
1868 [-0.0] is used for floating point types to compute the correct sign.
1869 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1870 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1873 (** [build_nuw_neg x name b] creates a
1874 [%name = nuw sub 0, %x]
1875 instruction at the position specified by the instruction builder [b].
1876 [-0.0] is used for floating point types to compute the correct sign.
1877 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1878 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1881 (** [build_fneg x name b] creates a
1882 [%name = fsub 0, %x]
1883 instruction at the position specified by the instruction builder [b].
1884 [-0.0] is used for floating point types to compute the correct sign.
1885 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1886 val build_fneg : llvalue -> string -> llbuilder -> llvalue
1889 (** [build_xor x name b] creates a
1890 [%name = xor %x, -1]
1891 instruction at the position specified by the instruction builder [b].
1892 [-1] is the correct "all ones" value for the type of [x].
1893 See the method [llvm::LLVMBuilder::CreateXor]. *)
1894 val build_not : llvalue -> string -> llbuilder -> llvalue
1900 (** [build_alloca ty name b] creates a
1901 [%name = alloca %ty]
1902 instruction at the position specified by the instruction builder [b].
1903 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1904 val build_alloca : lltype -> string -> llbuilder -> llvalue
1907 (** [build_array_alloca ty n name b] creates a
1908 [%name = alloca %ty, %n]
1909 instruction at the position specified by the instruction builder [b].
1910 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1911 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1914 (** [build_load v name b] creates a
1916 instruction at the position specified by the instruction builder [b].
1917 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1918 val build_load : llvalue -> string -> llbuilder -> llvalue
1921 (** [build_store v p b] creates a
1923 instruction at the position specified by the instruction builder [b].
1924 See the method [llvm::LLVMBuilder::CreateStore]. *)
1925 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
1928 (** [build_gep p indices name b] creates a
1929 [%name = getelementptr %p, indices...]
1930 instruction at the position specified by the instruction builder [b].
1931 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1932 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1935 (** [build_in_bounds_gep p indices name b] creates a
1936 [%name = gelementptr inbounds %p, indices...]
1937 instruction at the position specified by the instruction builder [b].
1938 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1939 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1942 (** [build_struct_gep p idx name b] creates a
1943 [%name = getelementptr %p, 0, idx]
1944 instruction at the position specified by the instruction builder [b].
1945 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1946 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
1949 (** [build_global_string str name b] creates a series of instructions that adds
1950 a global string at the position specified by the instruction builder [b].
1951 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1952 val build_global_string : string -> string -> llbuilder -> llvalue
1955 (** [build_global_stringptr str name b] creates a series of instructions that
1956 adds a global string pointer at the position specified by the instruction
1958 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1959 val build_global_stringptr : string -> string -> llbuilder -> llvalue
1965 (** [build_trunc v ty name b] creates a
1966 [%name = trunc %p to %ty]
1967 instruction at the position specified by the instruction builder [b].
1968 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1969 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1972 (** [build_zext v ty name b] creates a
1973 [%name = zext %p to %ty]
1974 instruction at the position specified by the instruction builder [b].
1975 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1976 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1979 (** [build_sext v ty name b] creates a
1980 [%name = sext %p to %ty]
1981 instruction at the position specified by the instruction builder [b].
1982 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1983 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1986 (** [build_fptoui v ty name b] creates a
1987 [%name = fptoui %p to %ty]
1988 instruction at the position specified by the instruction builder [b].
1989 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1990 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1993 (** [build_fptosi v ty name b] creates a
1994 [%name = fptosi %p to %ty]
1995 instruction at the position specified by the instruction builder [b].
1996 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1997 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
2000 (** [build_uitofp v ty name b] creates a
2001 [%name = uitofp %p to %ty]
2002 instruction at the position specified by the instruction builder [b].
2003 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
2004 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2007 (** [build_sitofp v ty name b] creates a
2008 [%name = sitofp %p to %ty]
2009 instruction at the position specified by the instruction builder [b].
2010 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
2011 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2014 (** [build_fptrunc v ty name b] creates a
2015 [%name = fptrunc %p to %ty]
2016 instruction at the position specified by the instruction builder [b].
2017 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
2018 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2021 (** [build_fpext v ty name b] creates a
2022 [%name = fpext %p to %ty]
2023 instruction at the position specified by the instruction builder [b].
2024 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
2025 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
2028 (** [build_ptrtoint v ty name b] creates a
2029 [%name = prtotint %p to %ty]
2030 instruction at the position specified by the instruction builder [b].
2031 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2032 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2035 (** [build_inttoptr v ty name b] creates a
2036 [%name = inttoptr %p to %ty]
2037 instruction at the position specified by the instruction builder [b].
2038 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2039 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2042 (** [build_bitcast v ty name b] creates a
2043 [%name = bitcast %p to %ty]
2044 instruction at the position specified by the instruction builder [b].
2045 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2046 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2049 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2050 instruction at the position specified by the instruction builder [b].
2051 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2052 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2055 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2056 instruction at the position specified by the instruction builder [b].
2057 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2058 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2061 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2062 instruction at the position specified by the instruction builder [b].
2063 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2064 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2067 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2068 instruction at the position specified by the instruction builder [b].
2069 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2070 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2073 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2074 instruction at the position specified by the instruction builder [b].
2075 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2076 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2079 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2080 instruction at the position specified by the instruction builder [b].
2081 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2082 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2086 (** {7 Comparisons} *)
2088 (** [build_icmp pred x y name b] creates a
2089 [%name = icmp %pred %x, %y]
2090 instruction at the position specified by the instruction builder [b].
2091 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2092 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2093 llbuilder -> llvalue
2095 (** [build_fcmp pred x y name b] creates a
2096 [%name = fcmp %pred %x, %y]
2097 instruction at the position specified by the instruction builder [b].
2098 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2099 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2100 llbuilder -> llvalue
2103 (** {7 Miscellaneous instructions} *)
2105 (** [build_phi incoming name b] creates a
2106 [%name = phi %incoming]
2107 instruction at the position specified by the instruction builder [b].
2108 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2109 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2110 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2113 (** [build_call fn args name b] creates a
2114 [%name = call %fn(args...)]
2115 instruction at the position specified by the instruction builder [b].
2116 See the method [llvm::LLVMBuilder::CreateCall]. *)
2117 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2120 (** [build_select cond thenv elsev name b] creates a
2121 [%name = select %cond, %thenv, %elsev]
2122 instruction at the position specified by the instruction builder [b].
2123 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2124 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2127 (** [build_va_arg valist argty name b] creates a
2128 [%name = va_arg %valist, %argty]
2129 instruction at the position specified by the instruction builder [b].
2130 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2131 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2134 (** [build_extractelement vec i name b] creates a
2135 [%name = extractelement %vec, %i]
2136 instruction at the position specified by the instruction builder [b].
2137 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2138 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2141 (** [build_insertelement vec elt i name b] creates a
2142 [%name = insertelement %vec, %elt, %i]
2143 instruction at the position specified by the instruction builder [b].
2144 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2145 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2146 llbuilder -> llvalue
2148 (** [build_shufflevector veca vecb mask name b] creates a
2149 [%name = shufflevector %veca, %vecb, %mask]
2150 instruction at the position specified by the instruction builder [b].
2151 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2152 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2153 llbuilder -> llvalue
2155 (** [build_insertvalue agg idx name b] creates a
2156 [%name = extractvalue %agg, %idx]
2157 instruction at the position specified by the instruction builder [b].
2158 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2159 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2162 (** [build_insertvalue agg val idx name b] creates a
2163 [%name = insertvalue %agg, %val, %idx]
2164 instruction at the position specified by the instruction builder [b].
2165 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2166 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2169 (** [build_is_null val name b] creates a
2170 [%name = icmp eq %val, null]
2171 instruction at the position specified by the instruction builder [b].
2172 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2173 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2176 (** [build_is_not_null val name b] creates a
2177 [%name = icmp ne %val, null]
2178 instruction at the position specified by the instruction builder [b].
2179 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2180 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2183 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2184 the difference between two pointer values at the position specified by the
2185 instruction builder [b].
2186 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2187 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2191 (** {6 Memory buffers} *)
2193 module MemoryBuffer : sig
2194 (** [of_file p] is the memory buffer containing the contents of the file at
2195 path [p]. If the file could not be read, then [IoError msg] is
2197 val of_file : string -> llmemorybuffer
2199 (** [stdin ()] is the memory buffer containing the contents of standard input.
2200 If standard input is empty, then [IoError msg] is raised. *)
2201 val of_stdin : unit -> llmemorybuffer
2203 (** Disposes of a memory buffer. *)
2204 val dispose : llmemorybuffer -> unit
2208 (** {6 Pass Managers} *)
2210 module PassManager : sig
2213 type any = [ `Module | `Function ]
2215 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2216 type of pipeline is suitable for link-time optimization and whole-module
2218 See the constructor of [llvm::PassManager]. *)
2219 val create : unit -> [ `Module ] t
2221 (** [PassManager.create_function m] constructs a new function-by-function
2222 pass pipeline over the module [m]. It does not take ownership of [m].
2223 This type of pipeline is suitable for code generation and JIT compilation
2225 See the constructor of [llvm::FunctionPassManager]. *)
2226 val create_function : llmodule -> [ `Function ] t
2229 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2230 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2231 any of the passes modified the module, [false] otherwise.
2232 See the [llvm::PassManager::run] method. *)
2233 val run_module : llmodule -> [ `Module ] t -> bool
2236 (** [initialize fpm] initializes all of the function passes scheduled in the
2237 function pass manager [fpm]. Returns [true] if any of the passes modified
2238 the module, [false] otherwise.
2239 See the [llvm::FunctionPassManager::doInitialization] method. *)
2240 val initialize : [ `Function ] t -> bool
2242 (** [run_function f fpm] executes all of the function passes scheduled in the
2243 function pass manager [fpm] over the function [f]. Returns [true] if any
2244 of the passes modified [f], [false] otherwise.
2245 See the [llvm::FunctionPassManager::run] method. *)
2246 val run_function : llvalue -> [ `Function ] t -> bool
2249 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2250 function pass manager [fpm]. Returns [true] if any of the passes
2251 modified the module, [false] otherwise.
2252 See the [llvm::FunctionPassManager::doFinalization] method. *)
2253 val finalize : [ `Function ] t -> bool
2255 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2257 See the destructor of [llvm::BasePassManager]. *)
2258 val dispose : [< any ] t -> unit