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. *)
185 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
186 of [a]. [llpos] is used to specify positions in and for forward iteration
187 through the various value lists maintained by the LLVM IR. *)
188 type ('a, 'b) llpos =
192 (** [After b] and [At_start a] specify positions from the end of the ['b] list
193 of [a]. [llrev_pos] is used for reverse iteration through the various value
194 lists maintained by the LLVM IR. *)
195 type ('a, 'b) llrev_pos =
200 (** {6 Exceptions} *)
202 exception IoError of string
207 (** [create_context ()] creates a context for storing the "global" state in
208 LLVM. See the constructor [llvm::LLVMContext]. *)
209 val create_context : unit -> llcontext
211 (** [destroy_context ()] destroys a context. See the destructor
212 [llvm::LLVMContext::~LLVMContext]. *)
213 val dispose_context : llcontext -> unit
215 (** See the function [llvm::getGlobalContext]. *)
216 val global_context : unit -> llcontext
218 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
219 name [name] in the context [context]. See the function
220 [llvm::LLVMContext::getMDKindID]. *)
221 val mdkind_id : llcontext -> string -> int
226 (** [create_module context id] creates a module with the supplied module ID in
227 the context [context]. Modules are not garbage collected; it is mandatory
228 to call {!dispose_module} to free memory. See the constructor
229 [llvm::Module::Module]. *)
230 val create_module : llcontext -> string -> llmodule
232 (** [dispose_module m] destroys a module [m] and all of the IR objects it
233 contained. All references to subordinate objects are invalidated;
234 referencing them will invoke undefined behavior. See the destructor
235 [llvm::Module::~Module]. *)
236 val dispose_module : llmodule -> unit
238 (** [target_triple m] is the target specifier for the module [m], something like
239 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
240 val target_triple: llmodule -> string
243 (** [target_triple triple m] changes the target specifier for the module [m] to
244 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
245 val set_target_triple: string -> llmodule -> unit
248 (** [data_layout m] is the data layout specifier for the module [m], something
249 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
250 method [llvm::Module::getDataLayout]. *)
251 val data_layout: llmodule -> string
254 (** [set_data_layout s m] changes the data layout specifier for the module [m]
255 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
256 val set_data_layout: string -> llmodule -> unit
258 (** [dump_module m] prints the .ll representation of the module [m] to standard
259 error. See the method [llvm::Module::dump]. *)
260 val dump_module : llmodule -> unit
262 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
263 the method [llvm::Module::setModuleInlineAsm]. *)
264 val set_module_inline_asm : llmodule -> string -> unit
270 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
271 See the method [llvm::Type::getTypeID]. *)
272 val classify_type : lltype -> TypeKind.t
274 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
275 See the method [llvm::Type::getContext]. *)
276 val type_context : lltype -> llcontext
278 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
279 val string_of_lltype : lltype -> string
281 (** {7 Operations on integer types} *)
283 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
284 [llvm::Type::Int1Ty]. *)
285 val i1_type : llcontext -> lltype
287 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
288 [llvm::Type::Int8Ty]. *)
289 val i8_type : llcontext -> lltype
291 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
292 [llvm::Type::Int16Ty]. *)
293 val i16_type : llcontext -> lltype
295 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
296 [llvm::Type::Int32Ty]. *)
297 val i32_type : llcontext -> lltype
299 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
300 [llvm::Type::Int64Ty]. *)
301 val i64_type : llcontext -> lltype
303 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
304 [c]. See the method [llvm::IntegerType::get]. *)
305 val integer_type : llcontext -> int -> lltype
307 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
308 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
309 val integer_bitwidth : lltype -> int
312 (** {7 Operations on real types} *)
314 (** [float_type c] returns the IEEE 32-bit floating point type in the context
315 [c]. See [llvm::Type::FloatTy]. *)
316 val float_type : llcontext -> lltype
318 (** [double_type c] returns the IEEE 64-bit floating point type in the context
319 [c]. See [llvm::Type::DoubleTy]. *)
320 val double_type : llcontext -> lltype
322 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
323 [c]. See [llvm::Type::X86_FP80Ty]. *)
324 val x86fp80_type : llcontext -> lltype
326 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
327 [c]. See [llvm::Type::FP128Ty]. *)
328 val fp128_type : llcontext -> lltype
330 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
331 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
332 val ppc_fp128_type : llcontext -> lltype
335 (** {7 Operations on function types} *)
337 (** [function_type ret_ty param_tys] returns the function type returning
338 [ret_ty] and taking [param_tys] as parameters.
339 See the method [llvm::FunctionType::get]. *)
340 val function_type : lltype -> lltype array -> lltype
342 (** [var_arg_function_type ret_ty param_tys] is just like
343 [function_type ret_ty param_tys] except that it returns the function type
344 which also takes a variable number of arguments.
345 See the method [llvm::FunctionType::get]. *)
346 val var_arg_function_type : lltype -> lltype array -> lltype
349 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
350 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
351 val is_var_arg : lltype -> bool
353 (** [return_type fty] gets the return type of the function type [fty].
354 See the method [llvm::FunctionType::getReturnType]. *)
355 val return_type : lltype -> lltype
357 (** [param_types fty] gets the parameter types of the function type [fty].
358 See the method [llvm::FunctionType::getParamType]. *)
359 val param_types : lltype -> lltype array
362 (** {7 Operations on struct types} *)
364 (** [struct_type context tys] returns the structure type in the context
365 [context] containing in the types in the array [tys]. See the method
366 [llvm::StructType::get]. *)
367 val struct_type : llcontext -> lltype array -> lltype
370 (** [packed_struct_type context ys] returns the packed structure type in the
371 context [context] containing in the types in the array [tys]. See the method
372 [llvm::StructType::get]. *)
373 val packed_struct_type : llcontext -> lltype array -> lltype
375 (** [struct_name ty] returns the name of the named structure type [ty],
376 * or None if the structure type is not named *)
377 val struct_name : lltype -> string option
380 (** [struct_element_types sty] returns the constituent types of the struct type
381 [sty]. See the method [llvm::StructType::getElementType]. *)
382 val struct_element_types : lltype -> lltype array
385 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
386 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
387 val is_packed : lltype -> bool
390 (** {7 Operations on pointer, vector, and array types} *)
392 (** [array_type ty n] returns the array type containing [n] elements of type
393 [ty]. See the method [llvm::ArrayType::get]. *)
394 val array_type : lltype -> int -> lltype
396 (** [pointer_type ty] returns the pointer type referencing objects of type
397 [ty] in the default address space (0).
398 See the method [llvm::PointerType::getUnqual]. *)
399 val pointer_type : lltype -> lltype
401 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
402 of type [ty] in address space [as].
403 See the method [llvm::PointerType::get]. *)
404 val qualified_pointer_type : lltype -> int -> lltype
407 (** [vector_type ty n] returns the array type containing [n] elements of the
408 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
409 val vector_type : lltype -> int -> lltype
411 (** [element_type ty] returns the element type of the pointer, vector, or array
412 type [ty]. See the method [llvm::SequentialType::get]. *)
413 val element_type : lltype -> lltype
415 (** [element_type aty] returns the element count of the array type [aty].
416 See the method [llvm::ArrayType::getNumElements]. *)
417 val array_length : lltype -> int
419 (** [address_space pty] returns the address space qualifier of the pointer type
420 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
421 val address_space : lltype -> int
423 (** [element_type ty] returns the element count of the vector type [ty].
424 See the method [llvm::VectorType::getNumElements]. *)
425 val vector_size : lltype -> int
428 (** {7 Operations on other types} *)
430 (** [void_type c] creates a type of a function which does not return any
431 value in the context [c]. See [llvm::Type::VoidTy]. *)
432 val void_type : llcontext -> lltype
434 (** [label_type c] creates a type of a basic block in the context [c]. See
435 [llvm::Type::LabelTy]. *)
436 val label_type : llcontext -> lltype
440 (** [type_of v] returns the type of the value [v].
441 See the method [llvm::Value::getType]. *)
442 val type_of : llvalue -> lltype
444 (** [value_name v] returns the name of the value [v]. For global values, this is
445 the symbol name. For instructions and basic blocks, it is the SSA register
446 name. It is meaningless for constants.
447 See the method [llvm::Value::getName]. *)
448 val value_name : llvalue -> string
450 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
451 [llvm::Value::setName]. *)
452 val set_value_name : string -> llvalue -> unit
454 (** [dump_value v] prints the .ll representation of the value [v] to standard
455 error. See the method [llvm::Value::dump]. *)
456 val dump_value : llvalue -> unit
458 (** [replace_all_uses_with old new] replaces all uses of the value [old]
459 * with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
460 val replace_all_uses_with : llvalue -> llvalue -> unit
466 (** [use_begin v] returns the first position in the use list for the value [v].
467 [use_begin] and [use_succ] can e used to iterate over the use list in order.
468 See the method [llvm::Value::use_begin]. *)
469 val use_begin : llvalue -> lluse option
471 (** [use_succ u] returns the use list position succeeding [u].
472 See the method [llvm::use_value_iterator::operator++]. *)
473 val use_succ : lluse -> lluse option
475 (** [user u] returns the user of the use [u].
476 See the method [llvm::Use::getUser]. *)
477 val user : lluse -> llvalue
479 (** [used_value u] returns the usee of the use [u].
480 See the method [llvm::Use::getUsedValue]. *)
481 val used_value : lluse -> llvalue
483 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
484 in order. Tail recursive. *)
485 val iter_uses : (lluse -> unit) -> llvalue -> unit
487 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
488 [u1,...,uN] are the users of the value [v]. Tail recursive. *)
489 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
491 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
492 [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
493 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
498 (** [operand v i] returns the operand at index [i] for the value [v]. See the
499 method [llvm::User::getOperand]. *)
500 val operand : llvalue -> int -> llvalue
502 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
504 See the method [llvm::User::setOperand]. *)
505 val set_operand : llvalue -> int -> llvalue -> unit
507 (** [num_operands v] returns the number of operands for the value [v].
508 See the method [llvm::User::getNumOperands]. *)
509 val num_operands : llvalue -> int
511 (** {7 Operations on constants of (mostly) any type} *)
513 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
514 otherwise. Similar to [llvm::isa<Constant>]. *)
515 val is_constant : llvalue -> bool
517 (** [const_null ty] returns the constant null (zero) of the type [ty].
518 See the method [llvm::Constant::getNullValue]. *)
519 val const_null : lltype -> llvalue
521 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
522 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
523 val const_all_ones : (*int|vec*)lltype -> llvalue
525 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
526 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
527 val const_pointer_null : lltype -> llvalue
529 (** [undef ty] returns the undefined value of the type [ty].
530 See the method [llvm::UndefValue::get]. *)
531 val undef : lltype -> llvalue
533 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
534 See the method [llvm::Constant::isNullValue]. *)
535 val is_null : llvalue -> bool
537 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
538 otherwise. Similar to [llvm::isa<UndefValue>]. *)
539 val is_undef : llvalue -> bool
542 (** {7 Operations on instructions} *)
544 (** [has_metadata i] returns whether or not the instruction [i] has any
545 metadata attached to it. See the function
546 [llvm::Instruction::hasMetadata]. *)
547 val has_metadata : llvalue -> bool
549 (** [metadata i kind] optionally returns the metadata associated with the
550 kind [kind] in the instruction [i] See the function
551 [llvm::Instruction::getMetadata]. *)
552 val metadata : llvalue -> int -> llvalue option
554 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
555 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
556 val set_metadata : llvalue -> int -> llvalue -> unit
558 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
559 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
560 val clear_metadata : llvalue -> int -> unit
563 (** {7 Operations on metadata} *)
565 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
566 See the method [llvm::MDNode::get]. *)
567 val mdstring : llcontext -> string -> llvalue
569 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
571 See the method [llvm::MDNode::get]. *)
572 val mdnode : llcontext -> llvalue array -> llvalue
574 (** [get_mdstring v] returns the MDString.
575 * See the method [llvm::MDString::getString] *)
576 val get_mdstring : llvalue -> string option
578 (** [get_named_metadata m name] return all the MDNodes belonging to the named
580 * See the method [llvm::NamedMDNode::getOperand]. *)
581 val get_named_metadata : llmodule -> string -> llvalue array
583 (** {7 Operations on scalar constants} *)
585 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
586 See the method [llvm::ConstantInt::get]. *)
587 val const_int : lltype -> int -> llvalue
589 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
590 [i]. See the method [llvm::ConstantInt::get]. *)
591 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
594 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
595 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
596 val const_int_of_string : lltype -> string -> int -> llvalue
599 (** [const_float ty n] returns the floating point constant of type [ty] and
600 value [n]. See the method [llvm::ConstantFP::get]. *)
601 val const_float : lltype -> float -> llvalue
603 (** [const_float_of_string ty s] returns the floating point constant of type
604 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
605 val const_float_of_string : lltype -> string -> llvalue
609 (** {7 Operations on composite constants} *)
611 (** [const_string c s] returns the constant [i8] array with the values of the
612 characters in the string [s] in the context [c]. The array is not
613 null-terminated (but see {!const_stringz}). This value can in turn be used
614 as the initializer for a global variable. See the method
615 [llvm::ConstantArray::get]. *)
616 val const_string : llcontext -> string -> llvalue
618 (** [const_stringz c s] returns the constant [i8] array with the values of the
619 characters in the string [s] and a null terminator in the context [c]. This
620 value can in turn be used as the initializer for a global variable.
621 See the method [llvm::ConstantArray::get]. *)
622 val const_stringz : llcontext -> string -> llvalue
624 (** [const_array ty elts] returns the constant array of type
625 [array_type ty (Array.length elts)] and containing the values [elts].
626 This value can in turn be used as the initializer for a global variable.
627 See the method [llvm::ConstantArray::get]. *)
628 val const_array : lltype -> llvalue array -> llvalue
630 (** [const_struct context elts] returns the structured constant of type
631 [struct_type (Array.map type_of elts)] and containing the values [elts]
632 in the context [context]. This value can in turn be used as the initializer
633 for a global variable. See the method [llvm::ConstantStruct::get]. *)
634 val const_struct : llcontext -> llvalue array -> llvalue
637 (** [const_packed_struct context elts] returns the structured constant of
638 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
639 values [elts] in the context [context]. This value can in turn be used as
640 the initializer for a global variable. See the method
641 [llvm::ConstantStruct::get]. *)
642 val const_packed_struct : llcontext -> llvalue array -> llvalue
645 (** [const_vector elts] returns the vector constant of type
646 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
647 values [elts]. See the method [llvm::ConstantVector::get]. *)
648 val const_vector : llvalue array -> llvalue
651 (** {7 Constant expressions} *)
653 (** [align_of ty] returns the alignof constant for the type [ty]. This is
654 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
655 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
656 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
657 val align_of : lltype -> llvalue
659 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
660 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
661 (const_int i32_type 1)) i64_type], but considerably more readable.
662 See the method [llvm::ConstantExpr::getSizeOf]. *)
663 val size_of : lltype -> llvalue
665 (** [const_neg c] returns the arithmetic negation of the constant [c].
666 See the method [llvm::ConstantExpr::getNeg]. *)
667 val const_neg : llvalue -> llvalue
669 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
670 no signed wrapping. The result is undefined if the negation overflows.
671 See the method [llvm::ConstantExpr::getNSWNeg]. *)
672 val const_nsw_neg : llvalue -> llvalue
674 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
675 no unsigned wrapping. The result is undefined if the negation overflows.
676 See the method [llvm::ConstantExpr::getNUWNeg]. *)
677 val const_nuw_neg : llvalue -> llvalue
679 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
680 See the method [llvm::ConstantExpr::getFNeg]. *)
681 val const_fneg : llvalue -> llvalue
683 (** [const_not c] returns the bitwise inverse of the constant [c].
684 See the method [llvm::ConstantExpr::getNot]. *)
685 val const_not : llvalue -> llvalue
687 (** [const_add c1 c2] returns the constant sum of two constants.
688 See the method [llvm::ConstantExpr::getAdd]. *)
689 val const_add : llvalue -> llvalue -> llvalue
691 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
692 signed wrapping. The result is undefined if the sum overflows.
693 See the method [llvm::ConstantExpr::getNSWAdd]. *)
694 val const_nsw_add : llvalue -> llvalue -> llvalue
696 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
697 unsigned wrapping. The result is undefined if the sum overflows.
698 See the method [llvm::ConstantExpr::getNSWAdd]. *)
699 val const_nuw_add : llvalue -> llvalue -> llvalue
701 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
702 See the method [llvm::ConstantExpr::getFAdd]. *)
703 val const_fadd : llvalue -> llvalue -> llvalue
705 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
706 constants. See the method [llvm::ConstantExpr::getSub]. *)
707 val const_sub : llvalue -> llvalue -> llvalue
709 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
710 no signed wrapping. The result is undefined if the sum overflows.
711 See the method [llvm::ConstantExpr::getNSWSub]. *)
712 val const_nsw_sub : llvalue -> llvalue -> llvalue
714 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
715 no unsigned wrapping. The result is undefined if the sum overflows.
716 See the method [llvm::ConstantExpr::getNSWSub]. *)
717 val const_nuw_sub : llvalue -> llvalue -> llvalue
719 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
720 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
721 val const_fsub : llvalue -> llvalue -> llvalue
723 (** [const_mul c1 c2] returns the constant product of two constants.
724 See the method [llvm::ConstantExpr::getMul]. *)
725 val const_mul : llvalue -> llvalue -> llvalue
727 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
728 no signed wrapping. The result is undefined if the sum overflows.
729 See the method [llvm::ConstantExpr::getNSWMul]. *)
730 val const_nsw_mul : llvalue -> llvalue -> llvalue
732 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
733 no unsigned wrapping. The result is undefined if the sum overflows.
734 See the method [llvm::ConstantExpr::getNSWMul]. *)
735 val const_nuw_mul : llvalue -> llvalue -> llvalue
737 (** [const_fmul c1 c2] returns the constant product of two constants floats.
738 See the method [llvm::ConstantExpr::getFMul]. *)
739 val const_fmul : llvalue -> llvalue -> llvalue
741 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
743 See the method [llvm::ConstantExpr::getUDiv]. *)
744 val const_udiv : llvalue -> llvalue -> llvalue
746 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
748 See the method [llvm::ConstantExpr::getSDiv]. *)
749 val const_sdiv : llvalue -> llvalue -> llvalue
751 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
752 signed integer constants. The result is undefined if the result is rounded
753 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
754 val const_exact_sdiv : llvalue -> llvalue -> llvalue
756 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
758 See the method [llvm::ConstantExpr::getFDiv]. *)
759 val const_fdiv : llvalue -> llvalue -> llvalue
761 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
762 unsigned integer constants.
763 See the method [llvm::ConstantExpr::getURem]. *)
764 val const_urem : llvalue -> llvalue -> llvalue
766 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
767 signed integer constants.
768 See the method [llvm::ConstantExpr::getSRem]. *)
769 val const_srem : llvalue -> llvalue -> llvalue
771 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
772 signed floating point constants.
773 See the method [llvm::ConstantExpr::getFRem]. *)
774 val const_frem : llvalue -> llvalue -> llvalue
776 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
778 See the method [llvm::ConstantExpr::getAnd]. *)
779 val const_and : llvalue -> llvalue -> llvalue
781 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
783 See the method [llvm::ConstantExpr::getOr]. *)
784 val const_or : llvalue -> llvalue -> llvalue
786 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
788 See the method [llvm::ConstantExpr::getXor]. *)
789 val const_xor : llvalue -> llvalue -> llvalue
791 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
792 constants, [c1 pred c2].
793 See the method [llvm::ConstantExpr::getICmp]. *)
794 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
797 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
798 point constants, [c1 pred c2].
799 See the method [llvm::ConstantExpr::getFCmp]. *)
800 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
803 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
804 constant integer [c2].
805 See the method [llvm::ConstantExpr::getShl]. *)
806 val const_shl : llvalue -> llvalue -> llvalue
808 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
809 constant integer [c2] with zero extension.
810 See the method [llvm::ConstantExpr::getLShr]. *)
811 val const_lshr : llvalue -> llvalue -> llvalue
813 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
814 constant integer [c2] with sign extension.
815 See the method [llvm::ConstantExpr::getAShr]. *)
816 val const_ashr : llvalue -> llvalue -> llvalue
818 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
819 constant integers indices from the array [indices].
820 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
821 val const_gep : llvalue -> llvalue array -> llvalue
823 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
824 with the constant integers indices from the array [indices].
825 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
826 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
829 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
830 to the smaller integer type [ty].
831 See the method [llvm::ConstantExpr::getTrunc]. *)
832 val const_trunc : llvalue -> lltype -> llvalue
834 (** [const_sext c ty] returns the constant sign extension of integer constant
835 [c] to the larger integer type [ty].
836 See the method [llvm::ConstantExpr::getSExt]. *)
837 val const_sext : llvalue -> lltype -> llvalue
839 (** [const_zext c ty] returns the constant zero extension of integer constant
840 [c] to the larger integer type [ty].
841 See the method [llvm::ConstantExpr::getZExt]. *)
842 val const_zext : llvalue -> lltype -> llvalue
844 (** [const_fptrunc c ty] returns the constant truncation of floating point
845 constant [c] to the smaller floating point type [ty].
846 See the method [llvm::ConstantExpr::getFPTrunc]. *)
847 val const_fptrunc : llvalue -> lltype -> llvalue
849 (** [const_fpext c ty] returns the constant extension of floating point constant
850 [c] to the larger floating point type [ty].
851 See the method [llvm::ConstantExpr::getFPExt]. *)
852 val const_fpext : llvalue -> lltype -> llvalue
854 (** [const_uitofp c ty] returns the constant floating point conversion of
855 unsigned integer constant [c] to the floating point type [ty].
856 See the method [llvm::ConstantExpr::getUIToFP]. *)
857 val const_uitofp : llvalue -> lltype -> llvalue
859 (** [const_sitofp c ty] returns the constant floating point conversion of
860 signed integer constant [c] to the floating point type [ty].
861 See the method [llvm::ConstantExpr::getSIToFP]. *)
862 val const_sitofp : llvalue -> lltype -> llvalue
864 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
865 floating point constant [c] to integer type [ty].
866 See the method [llvm::ConstantExpr::getFPToUI]. *)
867 val const_fptoui : llvalue -> lltype -> llvalue
869 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
870 floating point constant [c] to integer type [ty].
871 See the method [llvm::ConstantExpr::getFPToSI]. *)
872 val const_fptosi : llvalue -> lltype -> llvalue
874 (** [const_ptrtoint c ty] returns the constant integer conversion of
875 pointer constant [c] to integer type [ty].
876 See the method [llvm::ConstantExpr::getPtrToInt]. *)
877 val const_ptrtoint : llvalue -> lltype -> llvalue
879 (** [const_inttoptr c ty] returns the constant pointer conversion of
880 integer constant [c] to pointer type [ty].
881 See the method [llvm::ConstantExpr::getIntToPtr]. *)
882 val const_inttoptr : llvalue -> lltype -> llvalue
884 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
885 to type [ty] of equal size.
886 See the method [llvm::ConstantExpr::getBitCast]. *)
887 val const_bitcast : llvalue -> lltype -> llvalue
889 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
890 conversion of constant [c] to type [ty].
891 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
892 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
895 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
896 conversion of constant [c] to type [ty].
897 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
898 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
901 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
902 conversion of constant [c] to type [ty].
903 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
904 val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
907 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
908 cast conversion of constant [c] to type [ty] of equal size.
909 See the method [llvm::ConstantExpr::getPointerCast]. *)
910 val const_pointercast : llvalue -> lltype -> llvalue
913 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
914 -> integer casts of constant [c] to type [ty].
915 See the method [llvm::ConstantExpr::getIntCast]. *)
916 val const_intcast : llvalue -> lltype -> llvalue
919 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
920 fp casts of constant [c] to type [ty].
921 See the method [llvm::ConstantExpr::getFPCast]. *)
922 val const_fpcast : llvalue -> lltype -> llvalue
925 (** [const_select cond t f] returns the constant conditional which returns value
926 [t] if the boolean constant [cond] is true and the value [f] otherwise.
927 See the method [llvm::ConstantExpr::getSelect]. *)
928 val const_select : llvalue -> llvalue -> llvalue -> llvalue
931 (** [const_extractelement vec i] returns the constant [i]th element of
932 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
933 the size of the vector.
934 See the method [llvm::ConstantExpr::getExtractElement]. *)
935 val const_extractelement : llvalue -> llvalue -> llvalue
938 (** [const_insertelement vec v i] returns the constant vector with the same
939 elements as constant vector [v] but the [i]th element replaced by the
940 constant [v]. [v] must be a constant value with the type of the vector
941 elements. [i] must be a constant [i32] value unsigned less than the size
943 See the method [llvm::ConstantExpr::getInsertElement]. *)
944 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
947 (** [const_shufflevector a b mask] returns a constant [shufflevector].
948 See the LLVM Language Reference for details on the [shufflevector]
950 See the method [llvm::ConstantExpr::getShuffleVector]. *)
951 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
954 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
955 constant aggregate [agg]. Each [idxs] must be less than the size of the
956 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
957 val const_extractvalue : llvalue -> int array -> llvalue
960 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
961 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
962 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
963 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
966 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
967 See the method [llvm::InlineAsm::get]. *)
968 val const_inline_asm : lltype -> string -> string -> bool -> bool ->
972 (** [block_address f bb] returns the address of the basic block [bb] in the
973 function [f]. See the method [llvm::BasicBlock::get]. *)
974 val block_address : llvalue -> llbasicblock -> llvalue
977 (** {7 Operations on global variables, functions, and aliases (globals)} *)
979 (** [global_parent g] is the enclosing module of the global value [g].
980 See the method [llvm::GlobalValue::getParent]. *)
981 val global_parent : llvalue -> llmodule
983 (** [is_declaration g] returns [true] if the global value [g] is a declaration
984 only. Returns [false] otherwise.
985 See the method [llvm::GlobalValue::isDeclaration]. *)
986 val is_declaration : llvalue -> bool
988 (** [linkage g] returns the linkage of the global value [g].
989 See the method [llvm::GlobalValue::getLinkage]. *)
990 val linkage : llvalue -> Linkage.t
992 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
993 See the method [llvm::GlobalValue::setLinkage]. *)
994 val set_linkage : Linkage.t -> llvalue -> unit
996 (** [section g] returns the linker section of the global value [g].
997 See the method [llvm::GlobalValue::getSection]. *)
998 val section : llvalue -> string
1000 (** [set_section s g] sets the linker section of the global value [g] to [s].
1001 See the method [llvm::GlobalValue::setSection]. *)
1002 val set_section : string -> llvalue -> unit
1004 (** [visibility g] returns the linker visibility of the global value [g].
1005 See the method [llvm::GlobalValue::getVisibility]. *)
1006 val visibility : llvalue -> Visibility.t
1008 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1009 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1010 val set_visibility : Visibility.t -> llvalue -> unit
1013 (** [alignment g] returns the required alignment of the global value [g].
1014 See the method [llvm::GlobalValue::getAlignment]. *)
1015 val alignment : llvalue -> int
1017 (** [set_alignment n g] sets the required alignment of the global value [g] to
1018 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1019 val set_alignment : int -> llvalue -> unit
1022 (** {7 Operations on global variables} *)
1024 (** [declare_global ty name m] returns a new global variable of type [ty] and
1025 with name [name] in module [m] in the default address space (0). If such a
1026 global variable already exists, it is returned. If the type of the existing
1027 global differs, then a bitcast to [ty] is returned. *)
1028 val declare_global : lltype -> string -> llmodule -> llvalue
1031 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1032 of type [ty] and with name [name] in module [m] in the address space
1033 [addrspace]. If such a global variable already exists, it is returned. If
1034 the type of the existing global differs, then a bitcast to [ty] is
1036 val declare_qualified_global : lltype -> string -> int -> llmodule ->
1040 (** [define_global name init m] returns a new global with name [name] and
1041 initializer [init] in module [m] in the default address space (0). If the
1042 named global already exists, it is renamed.
1043 See the constructor of [llvm::GlobalVariable]. *)
1044 val define_global : string -> llvalue -> llmodule -> llvalue
1047 (** [define_qualified_global name init addrspace m] returns a new global with
1048 name [name] and initializer [init] in module [m] in the address space
1049 [addrspace]. If the named global already exists, it is renamed.
1050 See the constructor of [llvm::GlobalVariable]. *)
1051 val define_qualified_global : string -> llvalue -> int -> llmodule ->
1055 (** [lookup_global name m] returns [Some g] if a global variable with name
1056 [name] exists in module [m]. If no such global exists, returns [None].
1057 See the [llvm::GlobalVariable] constructor. *)
1058 val lookup_global : string -> llmodule -> llvalue option
1061 (** [delete_global gv] destroys the global variable [gv].
1062 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1063 val delete_global : llvalue -> unit
1065 (** [global_begin m] returns the first position in the global variable list of
1066 the module [m]. [global_begin] and [global_succ] can be used to iterate
1067 over the global list in order.
1068 See the method [llvm::Module::global_begin]. *)
1069 val global_begin : llmodule -> (llmodule, llvalue) llpos
1072 (** [global_succ gv] returns the global variable list position succeeding
1074 See the method [llvm::Module::global_iterator::operator++]. *)
1075 val global_succ : llvalue -> (llmodule, llvalue) llpos
1078 (** [iter_globals f m] applies function [f] to each of the global variables of
1079 module [m] in order. Tail recursive. *)
1080 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1082 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1083 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1084 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1086 (** [global_end m] returns the last position in the global variable list of the
1087 module [m]. [global_end] and [global_pred] can be used to iterate over the
1088 global list in reverse.
1089 See the method [llvm::Module::global_end]. *)
1090 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1093 (** [global_pred gv] returns the global variable list position preceding
1095 See the method [llvm::Module::global_iterator::operator--]. *)
1096 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1099 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1100 of module [m] in reverse order. Tail recursive. *)
1101 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1103 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1104 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1105 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1107 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1108 constant. Returns [false] otherwise.
1109 See the method [llvm::GlobalVariable::isConstant]. *)
1110 val is_global_constant : llvalue -> bool
1112 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1113 [c] is [true] and not if [c] is [false].
1114 See the method [llvm::GlobalVariable::setConstant]. *)
1115 val set_global_constant : bool -> llvalue -> unit
1118 (** [global_initializer gv] returns the initializer for the global variable
1119 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1120 val global_initializer : llvalue -> llvalue
1122 (** [set_initializer c gv] sets the initializer for the global variable
1123 [gv] to the constant [c].
1124 See the method [llvm::GlobalVariable::setInitializer]. *)
1125 val set_initializer : llvalue -> llvalue -> unit
1127 (** [remove_initializer gv] unsets the initializer for the global variable
1129 See the method [llvm::GlobalVariable::setInitializer]. *)
1130 val remove_initializer : llvalue -> unit
1132 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1133 thread-local and [false] otherwise.
1134 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1135 val is_thread_local : llvalue -> bool
1137 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1138 [c] is [true] and not otherwise.
1139 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1140 val set_thread_local : bool -> llvalue -> unit
1143 (** {7 Operations on aliases} *)
1145 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1146 the aliasee [a] with the name [n].
1147 See the constructor for [llvm::GlobalAlias]. *)
1148 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1152 (** {7 Operations on functions} *)
1154 (** [declare_function name ty m] returns a new function of type [ty] and
1155 with name [name] in module [m]. If such a function already exists,
1156 it is returned. If the type of the existing function differs, then a bitcast
1157 to [ty] is returned. *)
1158 val declare_function : string -> lltype -> llmodule -> llvalue
1161 (** [define_function name ty m] creates a new function with name [name] and
1162 type [ty] in module [m]. If the named function already exists, it is
1163 renamed. An entry basic block is created in the function.
1164 See the constructor of [llvm::GlobalVariable]. *)
1165 val define_function : string -> lltype -> llmodule -> llvalue
1168 (** [lookup_function name m] returns [Some f] if a function with name
1169 [name] exists in module [m]. If no such function exists, returns [None].
1170 See the method [llvm::Module] constructor. *)
1171 val lookup_function : string -> llmodule -> llvalue option
1174 (** [delete_function f] destroys the function [f].
1175 See the method [llvm::Function::eraseFromParent]. *)
1176 val delete_function : llvalue -> unit
1178 (** [function_begin m] returns the first position in the function list of the
1179 module [m]. [function_begin] and [function_succ] can be used to iterate over
1180 the function list in order.
1181 See the method [llvm::Module::begin]. *)
1182 val function_begin : llmodule -> (llmodule, llvalue) llpos
1185 (** [function_succ gv] returns the function list position succeeding
1187 See the method [llvm::Module::iterator::operator++]. *)
1188 val function_succ : llvalue -> (llmodule, llvalue) llpos
1191 (** [iter_functions f m] applies function [f] to each of the functions of module
1192 [m] in order. Tail recursive. *)
1193 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1195 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1196 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1197 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1199 (** [function_end m] returns the last position in the function list of
1200 the module [m]. [function_end] and [function_pred] can be used to iterate
1201 over the function list in reverse.
1202 See the method [llvm::Module::end]. *)
1203 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1206 (** [function_pred gv] returns the function list position preceding [After gv].
1207 See the method [llvm::Module::iterator::operator--]. *)
1208 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1211 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1212 module [m] in reverse order. Tail recursive. *)
1213 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1215 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1216 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1217 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1219 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1220 See the method [llvm::Function::isIntrinsic]. *)
1221 val is_intrinsic : llvalue -> bool
1223 (** [function_call_conv f] returns the calling convention of the function [f].
1224 See the method [llvm::Function::getCallingConv]. *)
1225 val function_call_conv : llvalue -> int
1227 (** [set_function_call_conv cc f] sets the calling convention of the function
1228 [f] to the calling convention numbered [cc].
1229 See the method [llvm::Function::setCallingConv]. *)
1230 val set_function_call_conv : int -> llvalue -> unit
1233 (** [gc f] returns [Some name] if the function [f] has a garbage
1234 collection algorithm specified and [None] otherwise.
1235 See the method [llvm::Function::getGC]. *)
1236 val gc : llvalue -> string option
1238 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1239 [gc]. See the method [llvm::Function::setGC]. *)
1240 val set_gc : string option -> llvalue -> unit
1242 (** [add_function_attr f a] adds attribute [a] to the return type of function
1244 val add_function_attr : llvalue -> Attribute.t -> unit
1246 (** [remove_function_attr f a] removes attribute [a] from the return type of
1248 val remove_function_attr : llvalue -> Attribute.t -> unit
1250 (** {7 Operations on params} *)
1252 (** [params f] returns the parameters of function [f].
1253 See the method [llvm::Function::getArgumentList]. *)
1254 val params : llvalue -> llvalue array
1256 (** [param f n] returns the [n]th parameter of function [f].
1257 See the method [llvm::Function::getArgumentList]. *)
1258 val param : llvalue -> int -> llvalue
1260 (** [param_parent p] returns the parent function that owns the parameter.
1261 See the method [llvm::Argument::getParent]. *)
1262 val param_parent : llvalue -> llvalue
1264 (** [param_begin f] returns the first position in the parameter list of the
1265 function [f]. [param_begin] and [param_succ] can be used to iterate over
1266 the parameter list in order.
1267 See the method [llvm::Function::arg_begin]. *)
1268 val param_begin : llvalue -> (llvalue, llvalue) llpos
1270 (** [param_succ bb] returns the parameter list position succeeding
1272 See the method [llvm::Function::arg_iterator::operator++]. *)
1273 val param_succ : llvalue -> (llvalue, llvalue) llpos
1275 (** [iter_params f fn] applies function [f] to each of the parameters
1276 of function [fn] in order. Tail recursive. *)
1277 val iter_params : (llvalue -> unit) -> llvalue -> unit
1279 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1280 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1281 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1283 (** [param_end f] returns the last position in the parameter list of
1284 the function [f]. [param_end] and [param_pred] can be used to iterate
1285 over the parameter list in reverse.
1286 See the method [llvm::Function::arg_end]. *)
1287 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1289 (** [param_pred gv] returns the function list position preceding [After gv].
1290 See the method [llvm::Function::arg_iterator::operator--]. *)
1291 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1294 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1295 of function [fn] in reverse order. Tail recursive. *)
1296 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1298 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1299 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1300 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1302 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1303 val add_param_attr : llvalue -> Attribute.t -> unit
1305 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1306 val remove_param_attr : llvalue -> Attribute.t -> unit
1308 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1309 val set_param_alignment : llvalue -> int -> unit
1312 (** {7 Operations on basic blocks} *)
1314 (** [basic_blocks fn] returns the basic blocks of the function [f].
1315 See the method [llvm::Function::getBasicBlockList]. *)
1316 val basic_blocks : llvalue -> llbasicblock array
1318 (** [entry_block fn] returns the entry basic block of the function [f].
1319 See the method [llvm::Function::getEntryBlock]. *)
1320 val entry_block : llvalue -> llbasicblock
1322 (** [delete_block bb] deletes the basic block [bb].
1323 See the method [llvm::BasicBlock::eraseFromParent]. *)
1324 val delete_block : llbasicblock -> unit
1326 (** [append_block c name f] creates a new basic block named [name] at the end of
1327 function [f] in the context [c].
1328 See the constructor of [llvm::BasicBlock]. *)
1329 val append_block : llcontext -> string -> llvalue -> llbasicblock
1332 (** [insert_block c name bb] creates a new basic block named [name] before the
1333 basic block [bb] in the context [c].
1334 See the constructor of [llvm::BasicBlock]. *)
1335 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1338 (** [block_parent bb] returns the parent function that owns the basic block.
1339 See the method [llvm::BasicBlock::getParent]. *)
1340 val block_parent : llbasicblock -> llvalue
1342 (** [block_begin f] returns the first position in the basic block list of the
1343 function [f]. [block_begin] and [block_succ] can be used to iterate over
1344 the basic block list in order.
1345 See the method [llvm::Function::begin]. *)
1346 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1349 (** [block_succ bb] returns the basic block list position succeeding
1351 See the method [llvm::Function::iterator::operator++]. *)
1352 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1355 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1356 of function [fn] in order. Tail recursive. *)
1357 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1359 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1360 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1361 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1363 (** [block_end f] returns the last position in the basic block list of
1364 the function [f]. [block_end] and [block_pred] can be used to iterate
1365 over the basic block list in reverse.
1366 See the method [llvm::Function::end]. *)
1367 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1370 (** [block_pred gv] returns the function list position preceding [After gv].
1371 See the method [llvm::Function::iterator::operator--]. *)
1372 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1375 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1376 of function [fn] in reverse order. Tail recursive. *)
1377 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1379 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1380 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1381 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1383 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1384 val value_of_block : llbasicblock -> llvalue
1386 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1388 Similar to [llvm::isa<BasicBlock>]. *)
1389 val value_is_block : llvalue -> bool
1391 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1392 val block_of_value : llvalue -> llbasicblock
1395 (** {7 Operations on instructions} *)
1397 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1398 See the method [llvm::Instruction::getParent]. *)
1399 val instr_parent : llvalue -> llbasicblock
1401 (** [instr_begin bb] returns the first position in the instruction list of the
1402 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1403 the instruction list in order.
1404 See the method [llvm::BasicBlock::begin]. *)
1405 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1408 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1409 See the method [llvm::BasicBlock::iterator::operator++]. *)
1410 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1413 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1414 block [bb] in order. Tail recursive. *)
1415 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1417 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1418 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1419 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1421 (** [instr_end bb] returns the last position in the instruction list of the
1422 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1423 the instruction list in reverse.
1424 See the method [llvm::BasicBlock::end]. *)
1425 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1428 (** [instr_pred i] returns the instruction list position preceding [After i].
1429 See the method [llvm::BasicBlock::iterator::operator--]. *)
1430 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1433 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1434 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1435 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1438 (** {7 Operations on call sites} *)
1440 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1441 instruction [ci], which may be one of the values from the module
1442 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1443 [llvm::InvokeInst::getCallingConv]. *)
1444 val instruction_call_conv: llvalue -> int
1447 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1448 or invoke instruction [ci] to the integer [cc], which can be one of the
1449 values from the module {!CallConv}.
1450 See the method [llvm::CallInst::setCallingConv]
1451 and [llvm::InvokeInst::setCallingConv]. *)
1452 val set_instruction_call_conv: int -> llvalue -> unit
1455 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1456 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1458 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1460 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1461 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1463 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1465 (** {Operations on call instructions (only)} *)
1467 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1468 eligible for tail call optimization, [false] otherwise.
1469 See the method [llvm::CallInst::isTailCall]. *)
1470 val is_tail_call : llvalue -> bool
1472 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1473 call optimization if [tc] is [true], clears otherwise.
1474 See the method [llvm::CallInst::setTailCall]. *)
1475 val set_tail_call : bool -> llvalue -> unit
1477 (** {7 Operations on phi nodes} *)
1479 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1480 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1481 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1484 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1485 See the method [llvm::PHINode::getIncomingValue]. *)
1486 val incoming : llvalue -> (llvalue * llbasicblock) list
1490 (** {6 Instruction builders} *)
1492 (** [builder context] creates an instruction builder with no position in
1493 the context [context]. It is invalid to use this builder until its position
1494 is set with {!position_before} or {!position_at_end}. See the constructor
1495 for [llvm::LLVMBuilder]. *)
1496 val builder : llcontext -> llbuilder
1498 (** [builder_at ip] creates an instruction builder positioned at [ip].
1499 See the constructor for [llvm::LLVMBuilder]. *)
1500 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1502 (** [builder_before ins] creates an instruction builder positioned before the
1503 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1504 val builder_before : llcontext -> llvalue -> llbuilder
1506 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1507 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1508 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1510 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1512 See the constructor for [llvm::LLVMBuilder]. *)
1513 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1516 (** [position_before ins b] moves the instruction builder [b] to before the
1517 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1518 val position_before : llvalue -> llbuilder -> unit
1520 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1521 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1522 val position_at_end : llbasicblock -> llbuilder -> unit
1524 (** [insertion_block b] returns the basic block that the builder [b] is
1525 positioned to insert into. Raises [Not_Found] if the instruction builder is
1527 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1528 val insertion_block : llbuilder -> llbasicblock
1530 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1531 position specified by the instruction builder [b].
1532 See the method [llvm::LLVMBuilder::Insert]. *)
1533 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1538 (** [set_current_debug_location b md] sets the current debug location [md] in
1540 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1541 val set_current_debug_location : llbuilder -> llvalue -> unit
1544 (** [clear_current_debug_location b] clears the current debug location in the
1546 val clear_current_debug_location : llbuilder -> unit
1549 (** [current_debug_location b] returns the current debug location, or None
1550 if none is currently set.
1551 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1552 val current_debug_location : llbuilder -> llvalue option
1555 (** [set_inst_debug_location b i] sets the current debug location of the builder
1556 [b] to the instruction [i].
1557 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1558 val set_inst_debug_location : llbuilder -> llvalue -> unit
1561 (** {7 Terminators} *)
1563 (** [build_ret_void b] creates a
1565 instruction at the position specified by the instruction builder [b].
1566 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1567 val build_ret_void : llbuilder -> llvalue
1569 (** [build_ret v b] creates a
1571 instruction at the position specified by the instruction builder [b].
1572 See the method [llvm::LLVMBuilder::CreateRet]. *)
1573 val build_ret : llvalue -> llbuilder -> llvalue
1575 (** [build_aggregate_ret vs b] creates a
1576 [ret {...} { %v1, %v2, ... } ]
1577 instruction at the position specified by the instruction builder [b].
1578 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1579 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1582 (** [build_br bb b] creates a
1584 instruction at the position specified by the instruction builder [b].
1585 See the method [llvm::LLVMBuilder::CreateBr]. *)
1586 val build_br : llbasicblock -> llbuilder -> llvalue
1588 (** [build_cond_br cond tbb fbb b] creates a
1589 [br %cond, %tbb, %fbb]
1590 instruction at the position specified by the instruction builder [b].
1591 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1592 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1595 (** [build_switch case elsebb count b] creates an empty
1596 [switch %case, %elsebb]
1597 instruction at the position specified by the instruction builder [b] with
1598 space reserved for [count] cases.
1599 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1600 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1603 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1604 when its input matches the constant [onval].
1605 See the method [llvm::SwitchInst::addCase]. **)
1606 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1609 (** [build_indirect_br addr count b] creates a
1611 instruction at the position specified by the instruction builder [b] with
1612 space reserved for [count] destinations.
1613 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1614 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1617 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1618 location for the indirectbr instruction [br].
1619 See the method [llvm::IndirectBrInst::addDestination]. **)
1620 val add_destination : llvalue -> llbasicblock -> unit
1623 (** [build_invoke fn args tobb unwindbb name b] creates an
1624 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1625 instruction at the position specified by the instruction builder [b].
1626 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1627 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1628 llbasicblock -> string -> llbuilder -> llvalue
1630 (** [build_landingpad ty persfn numclauses name b] creates an
1632 instruction at the position specified by the instruction builder [b].
1633 See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
1634 val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
1637 (** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
1638 See the method [llvm::LandingPadInst::setCleanup]. *)
1639 val set_cleanup : llvalue -> bool -> unit
1641 (** [build_unreachable b] creates an
1643 instruction at the position specified by the instruction builder [b].
1644 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1645 val build_unreachable : llbuilder -> llvalue
1648 (** {7 Arithmetic} *)
1650 (** [build_add x y name b] creates a
1651 [%name = add %x, %y]
1652 instruction at the position specified by the instruction builder [b].
1653 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1654 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1657 (** [build_nsw_add x y name b] creates a
1658 [%name = nsw add %x, %y]
1659 instruction at the position specified by the instruction builder [b].
1660 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1661 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1664 (** [build_nuw_add x y name b] creates a
1665 [%name = nuw add %x, %y]
1666 instruction at the position specified by the instruction builder [b].
1667 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1668 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1671 (** [build_fadd x y name b] creates a
1672 [%name = fadd %x, %y]
1673 instruction at the position specified by the instruction builder [b].
1674 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1675 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1678 (** [build_sub x y name b] creates a
1679 [%name = sub %x, %y]
1680 instruction at the position specified by the instruction builder [b].
1681 See the method [llvm::LLVMBuilder::CreateSub]. *)
1682 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1685 (** [build_nsw_sub x y name b] creates a
1686 [%name = nsw sub %x, %y]
1687 instruction at the position specified by the instruction builder [b].
1688 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1689 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1692 (** [build_nuw_sub x y name b] creates a
1693 [%name = nuw sub %x, %y]
1694 instruction at the position specified by the instruction builder [b].
1695 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1696 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1699 (** [build_fsub x y name b] creates a
1700 [%name = fsub %x, %y]
1701 instruction at the position specified by the instruction builder [b].
1702 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1703 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1706 (** [build_mul x y name b] creates a
1707 [%name = mul %x, %y]
1708 instruction at the position specified by the instruction builder [b].
1709 See the method [llvm::LLVMBuilder::CreateMul]. *)
1710 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1713 (** [build_nsw_mul x y name b] creates a
1714 [%name = nsw mul %x, %y]
1715 instruction at the position specified by the instruction builder [b].
1716 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1717 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1720 (** [build_nuw_mul x y name b] creates a
1721 [%name = nuw mul %x, %y]
1722 instruction at the position specified by the instruction builder [b].
1723 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1724 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1727 (** [build_fmul x y name b] creates a
1728 [%name = fmul %x, %y]
1729 instruction at the position specified by the instruction builder [b].
1730 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1731 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1734 (** [build_udiv x y name b] creates a
1735 [%name = udiv %x, %y]
1736 instruction at the position specified by the instruction builder [b].
1737 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1738 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1741 (** [build_sdiv x y name b] creates a
1742 [%name = sdiv %x, %y]
1743 instruction at the position specified by the instruction builder [b].
1744 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1745 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1748 (** [build_exact_sdiv x y name b] creates a
1749 [%name = exact sdiv %x, %y]
1750 instruction at the position specified by the instruction builder [b].
1751 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1752 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1755 (** [build_fdiv x y name b] creates a
1756 [%name = fdiv %x, %y]
1757 instruction at the position specified by the instruction builder [b].
1758 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1759 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1762 (** [build_urem x y name b] creates a
1763 [%name = urem %x, %y]
1764 instruction at the position specified by the instruction builder [b].
1765 See the method [llvm::LLVMBuilder::CreateURem]. *)
1766 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1769 (** [build_SRem x y name b] creates a
1770 [%name = srem %x, %y]
1771 instruction at the position specified by the instruction builder [b].
1772 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1773 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1776 (** [build_frem x y name b] creates a
1777 [%name = frem %x, %y]
1778 instruction at the position specified by the instruction builder [b].
1779 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1780 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1783 (** [build_shl x y name b] creates a
1784 [%name = shl %x, %y]
1785 instruction at the position specified by the instruction builder [b].
1786 See the method [llvm::LLVMBuilder::CreateShl]. *)
1787 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1790 (** [build_lshr x y name b] creates a
1791 [%name = lshr %x, %y]
1792 instruction at the position specified by the instruction builder [b].
1793 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1794 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1797 (** [build_ashr x y name b] creates a
1798 [%name = ashr %x, %y]
1799 instruction at the position specified by the instruction builder [b].
1800 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1801 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1804 (** [build_and x y name b] creates a
1805 [%name = and %x, %y]
1806 instruction at the position specified by the instruction builder [b].
1807 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1808 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1811 (** [build_or x y name b] creates a
1813 instruction at the position specified by the instruction builder [b].
1814 See the method [llvm::LLVMBuilder::CreateOr]. *)
1815 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1818 (** [build_xor x y name b] creates a
1819 [%name = xor %x, %y]
1820 instruction at the position specified by the instruction builder [b].
1821 See the method [llvm::LLVMBuilder::CreateXor]. *)
1822 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1825 (** [build_neg x name b] creates a
1827 instruction at the position specified by the instruction builder [b].
1828 [-0.0] is used for floating point types to compute the correct sign.
1829 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1830 val build_neg : llvalue -> string -> llbuilder -> llvalue
1833 (** [build_nsw_neg x name b] creates a
1834 [%name = nsw sub 0, %x]
1835 instruction at the position specified by the instruction builder [b].
1836 [-0.0] is used for floating point types to compute the correct sign.
1837 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1838 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1841 (** [build_nuw_neg x name b] creates a
1842 [%name = nuw sub 0, %x]
1843 instruction at the position specified by the instruction builder [b].
1844 [-0.0] is used for floating point types to compute the correct sign.
1845 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1846 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1849 (** [build_fneg x name b] creates a
1850 [%name = fsub 0, %x]
1851 instruction at the position specified by the instruction builder [b].
1852 [-0.0] is used for floating point types to compute the correct sign.
1853 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1854 val build_fneg : llvalue -> string -> llbuilder -> llvalue
1857 (** [build_xor x name b] creates a
1858 [%name = xor %x, -1]
1859 instruction at the position specified by the instruction builder [b].
1860 [-1] is the correct "all ones" value for the type of [x].
1861 See the method [llvm::LLVMBuilder::CreateXor]. *)
1862 val build_not : llvalue -> string -> llbuilder -> llvalue
1868 (** [build_alloca ty name b] creates a
1869 [%name = alloca %ty]
1870 instruction at the position specified by the instruction builder [b].
1871 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1872 val build_alloca : lltype -> string -> llbuilder -> llvalue
1875 (** [build_array_alloca ty n name b] creates a
1876 [%name = alloca %ty, %n]
1877 instruction at the position specified by the instruction builder [b].
1878 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1879 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1882 (** [build_load v name b] creates a
1884 instruction at the position specified by the instruction builder [b].
1885 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1886 val build_load : llvalue -> string -> llbuilder -> llvalue
1889 (** [build_store v p b] creates a
1891 instruction at the position specified by the instruction builder [b].
1892 See the method [llvm::LLVMBuilder::CreateStore]. *)
1893 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
1896 (** [build_gep p indices name b] creates a
1897 [%name = getelementptr %p, indices...]
1898 instruction at the position specified by the instruction builder [b].
1899 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1900 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1903 (** [build_in_bounds_gep p indices name b] creates a
1904 [%name = gelementptr inbounds %p, indices...]
1905 instruction at the position specified by the instruction builder [b].
1906 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1907 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1910 (** [build_struct_gep p idx name b] creates a
1911 [%name = getelementptr %p, 0, idx]
1912 instruction at the position specified by the instruction builder [b].
1913 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1914 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
1917 (** [build_global_string str name b] creates a series of instructions that adds
1918 a global string at the position specified by the instruction builder [b].
1919 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1920 val build_global_string : string -> string -> llbuilder -> llvalue
1923 (** [build_global_stringptr str name b] creates a series of instructions that
1924 adds a global string pointer at the position specified by the instruction
1926 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1927 val build_global_stringptr : string -> string -> llbuilder -> llvalue
1933 (** [build_trunc v ty name b] creates a
1934 [%name = trunc %p to %ty]
1935 instruction at the position specified by the instruction builder [b].
1936 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1937 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1940 (** [build_zext v ty name b] creates a
1941 [%name = zext %p to %ty]
1942 instruction at the position specified by the instruction builder [b].
1943 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1944 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1947 (** [build_sext v ty name b] creates a
1948 [%name = sext %p to %ty]
1949 instruction at the position specified by the instruction builder [b].
1950 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1951 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1954 (** [build_fptoui v ty name b] creates a
1955 [%name = fptoui %p to %ty]
1956 instruction at the position specified by the instruction builder [b].
1957 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1958 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1961 (** [build_fptosi v ty name b] creates a
1962 [%name = fptosi %p to %ty]
1963 instruction at the position specified by the instruction builder [b].
1964 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1965 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1968 (** [build_uitofp v ty name b] creates a
1969 [%name = uitofp %p to %ty]
1970 instruction at the position specified by the instruction builder [b].
1971 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1972 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1975 (** [build_sitofp v ty name b] creates a
1976 [%name = sitofp %p to %ty]
1977 instruction at the position specified by the instruction builder [b].
1978 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1979 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1982 (** [build_fptrunc v ty name b] creates a
1983 [%name = fptrunc %p to %ty]
1984 instruction at the position specified by the instruction builder [b].
1985 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1986 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1989 (** [build_fpext v ty name b] creates a
1990 [%name = fpext %p to %ty]
1991 instruction at the position specified by the instruction builder [b].
1992 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1993 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1996 (** [build_ptrtoint v ty name b] creates a
1997 [%name = prtotint %p to %ty]
1998 instruction at the position specified by the instruction builder [b].
1999 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2000 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2003 (** [build_inttoptr v ty name b] creates a
2004 [%name = inttoptr %p to %ty]
2005 instruction at the position specified by the instruction builder [b].
2006 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2007 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2010 (** [build_bitcast v ty name b] creates a
2011 [%name = bitcast %p to %ty]
2012 instruction at the position specified by the instruction builder [b].
2013 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2014 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2017 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2018 instruction at the position specified by the instruction builder [b].
2019 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2020 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2023 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2024 instruction at the position specified by the instruction builder [b].
2025 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2026 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2029 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2030 instruction at the position specified by the instruction builder [b].
2031 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2032 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2035 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2036 instruction at the position specified by the instruction builder [b].
2037 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2038 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2041 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2042 instruction at the position specified by the instruction builder [b].
2043 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2044 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2047 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2048 instruction at the position specified by the instruction builder [b].
2049 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2050 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2054 (** {7 Comparisons} *)
2056 (** [build_icmp pred x y name b] creates a
2057 [%name = icmp %pred %x, %y]
2058 instruction at the position specified by the instruction builder [b].
2059 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2060 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2061 llbuilder -> llvalue
2063 (** [build_fcmp pred x y name b] creates a
2064 [%name = fcmp %pred %x, %y]
2065 instruction at the position specified by the instruction builder [b].
2066 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2067 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2068 llbuilder -> llvalue
2071 (** {7 Miscellaneous instructions} *)
2073 (** [build_phi incoming name b] creates a
2074 [%name = phi %incoming]
2075 instruction at the position specified by the instruction builder [b].
2076 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2077 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2078 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2081 (** [build_call fn args name b] creates a
2082 [%name = call %fn(args...)]
2083 instruction at the position specified by the instruction builder [b].
2084 See the method [llvm::LLVMBuilder::CreateCall]. *)
2085 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2088 (** [build_select cond thenv elsev name b] creates a
2089 [%name = select %cond, %thenv, %elsev]
2090 instruction at the position specified by the instruction builder [b].
2091 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2092 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2095 (** [build_va_arg valist argty name b] creates a
2096 [%name = va_arg %valist, %argty]
2097 instruction at the position specified by the instruction builder [b].
2098 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2099 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2102 (** [build_extractelement vec i name b] creates a
2103 [%name = extractelement %vec, %i]
2104 instruction at the position specified by the instruction builder [b].
2105 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2106 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2109 (** [build_insertelement vec elt i name b] creates a
2110 [%name = insertelement %vec, %elt, %i]
2111 instruction at the position specified by the instruction builder [b].
2112 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2113 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2114 llbuilder -> llvalue
2116 (** [build_shufflevector veca vecb mask name b] creates a
2117 [%name = shufflevector %veca, %vecb, %mask]
2118 instruction at the position specified by the instruction builder [b].
2119 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2120 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2121 llbuilder -> llvalue
2123 (** [build_insertvalue agg idx name b] creates a
2124 [%name = extractvalue %agg, %idx]
2125 instruction at the position specified by the instruction builder [b].
2126 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2127 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2130 (** [build_insertvalue agg val idx name b] creates a
2131 [%name = insertvalue %agg, %val, %idx]
2132 instruction at the position specified by the instruction builder [b].
2133 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2134 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2137 (** [build_is_null val name b] creates a
2138 [%name = icmp eq %val, null]
2139 instruction at the position specified by the instruction builder [b].
2140 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2141 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2144 (** [build_is_not_null val name b] creates a
2145 [%name = icmp ne %val, null]
2146 instruction at the position specified by the instruction builder [b].
2147 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2148 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2151 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2152 the difference between two pointer values at the position specified by the
2153 instruction builder [b].
2154 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2155 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2159 (** {6 Memory buffers} *)
2161 module MemoryBuffer : sig
2162 (** [of_file p] is the memory buffer containing the contents of the file at
2163 path [p]. If the file could not be read, then [IoError msg] is
2165 val of_file : string -> llmemorybuffer
2167 (** [stdin ()] is the memory buffer containing the contents of standard input.
2168 If standard input is empty, then [IoError msg] is raised. *)
2169 val of_stdin : unit -> llmemorybuffer
2171 (** Disposes of a memory buffer. *)
2172 val dispose : llmemorybuffer -> unit
2176 (** {6 Pass Managers} *)
2178 module PassManager : sig
2181 type any = [ `Module | `Function ]
2183 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2184 type of pipeline is suitable for link-time optimization and whole-module
2186 See the constructor of [llvm::PassManager]. *)
2187 val create : unit -> [ `Module ] t
2189 (** [PassManager.create_function m] constructs a new function-by-function
2190 pass pipeline over the module [m]. It does not take ownership of [m].
2191 This type of pipeline is suitable for code generation and JIT compilation
2193 See the constructor of [llvm::FunctionPassManager]. *)
2194 val create_function : llmodule -> [ `Function ] t
2197 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2198 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2199 any of the passes modified the module, [false] otherwise.
2200 See the [llvm::PassManager::run] method. *)
2201 val run_module : llmodule -> [ `Module ] t -> bool
2204 (** [initialize fpm] initializes all of the function passes scheduled in the
2205 function pass manager [fpm]. Returns [true] if any of the passes modified
2206 the module, [false] otherwise.
2207 See the [llvm::FunctionPassManager::doInitialization] method. *)
2208 val initialize : [ `Function ] t -> bool
2210 (** [run_function f fpm] executes all of the function passes scheduled in the
2211 function pass manager [fpm] over the function [f]. Returns [true] if any
2212 of the passes modified [f], [false] otherwise.
2213 See the [llvm::FunctionPassManager::run] method. *)
2214 val run_function : llvalue -> [ `Function ] t -> bool
2217 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2218 function pass manager [fpm]. Returns [true] if any of the passes
2219 modified the module, [false] otherwise.
2220 See the [llvm::FunctionPassManager::doFinalization] method. *)
2221 val finalize : [ `Function ] t -> bool
2223 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2225 See the destructor of [llvm::BasePassManager]. *)
2226 val dispose : [< any ] t -> unit