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 val icmp_predicate : llvalue -> Icmp.t option
1440 (** {7 Operations on call sites} *)
1442 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1443 instruction [ci], which may be one of the values from the module
1444 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1445 [llvm::InvokeInst::getCallingConv]. *)
1446 val instruction_call_conv: llvalue -> int
1449 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1450 or invoke instruction [ci] to the integer [cc], which can be one of the
1451 values from the module {!CallConv}.
1452 See the method [llvm::CallInst::setCallingConv]
1453 and [llvm::InvokeInst::setCallingConv]. *)
1454 val set_instruction_call_conv: int -> llvalue -> unit
1457 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1458 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1460 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1462 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1463 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1465 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1467 (** {Operations on call instructions (only)} *)
1469 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1470 eligible for tail call optimization, [false] otherwise.
1471 See the method [llvm::CallInst::isTailCall]. *)
1472 val is_tail_call : llvalue -> bool
1474 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1475 call optimization if [tc] is [true], clears otherwise.
1476 See the method [llvm::CallInst::setTailCall]. *)
1477 val set_tail_call : bool -> llvalue -> unit
1479 (** {7 Operations on phi nodes} *)
1481 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1482 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1483 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1486 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1487 See the method [llvm::PHINode::getIncomingValue]. *)
1488 val incoming : llvalue -> (llvalue * llbasicblock) list
1492 (** {6 Instruction builders} *)
1494 (** [builder context] creates an instruction builder with no position in
1495 the context [context]. It is invalid to use this builder until its position
1496 is set with {!position_before} or {!position_at_end}. See the constructor
1497 for [llvm::LLVMBuilder]. *)
1498 val builder : llcontext -> llbuilder
1500 (** [builder_at ip] creates an instruction builder positioned at [ip].
1501 See the constructor for [llvm::LLVMBuilder]. *)
1502 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1504 (** [builder_before ins] creates an instruction builder positioned before the
1505 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1506 val builder_before : llcontext -> llvalue -> llbuilder
1508 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1509 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1510 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1512 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1514 See the constructor for [llvm::LLVMBuilder]. *)
1515 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1518 (** [position_before ins b] moves the instruction builder [b] to before the
1519 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1520 val position_before : llvalue -> llbuilder -> unit
1522 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1523 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1524 val position_at_end : llbasicblock -> llbuilder -> unit
1526 (** [insertion_block b] returns the basic block that the builder [b] is
1527 positioned to insert into. Raises [Not_Found] if the instruction builder is
1529 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1530 val insertion_block : llbuilder -> llbasicblock
1532 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1533 position specified by the instruction builder [b].
1534 See the method [llvm::LLVMBuilder::Insert]. *)
1535 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1540 (** [set_current_debug_location b md] sets the current debug location [md] in
1542 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1543 val set_current_debug_location : llbuilder -> llvalue -> unit
1546 (** [clear_current_debug_location b] clears the current debug location in the
1548 val clear_current_debug_location : llbuilder -> unit
1551 (** [current_debug_location b] returns the current debug location, or None
1552 if none is currently set.
1553 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1554 val current_debug_location : llbuilder -> llvalue option
1557 (** [set_inst_debug_location b i] sets the current debug location of the builder
1558 [b] to the instruction [i].
1559 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1560 val set_inst_debug_location : llbuilder -> llvalue -> unit
1563 (** {7 Terminators} *)
1565 (** [build_ret_void b] creates a
1567 instruction at the position specified by the instruction builder [b].
1568 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1569 val build_ret_void : llbuilder -> llvalue
1571 (** [build_ret v b] creates a
1573 instruction at the position specified by the instruction builder [b].
1574 See the method [llvm::LLVMBuilder::CreateRet]. *)
1575 val build_ret : llvalue -> llbuilder -> llvalue
1577 (** [build_aggregate_ret vs b] creates a
1578 [ret {...} { %v1, %v2, ... } ]
1579 instruction at the position specified by the instruction builder [b].
1580 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1581 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1584 (** [build_br bb b] creates a
1586 instruction at the position specified by the instruction builder [b].
1587 See the method [llvm::LLVMBuilder::CreateBr]. *)
1588 val build_br : llbasicblock -> llbuilder -> llvalue
1590 (** [build_cond_br cond tbb fbb b] creates a
1591 [br %cond, %tbb, %fbb]
1592 instruction at the position specified by the instruction builder [b].
1593 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1594 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1597 (** [build_switch case elsebb count b] creates an empty
1598 [switch %case, %elsebb]
1599 instruction at the position specified by the instruction builder [b] with
1600 space reserved for [count] cases.
1601 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1602 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1605 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1606 when its input matches the constant [onval].
1607 See the method [llvm::SwitchInst::addCase]. **)
1608 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1611 (** [build_indirect_br addr count b] creates a
1613 instruction at the position specified by the instruction builder [b] with
1614 space reserved for [count] destinations.
1615 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1616 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1619 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1620 location for the indirectbr instruction [br].
1621 See the method [llvm::IndirectBrInst::addDestination]. **)
1622 val add_destination : llvalue -> llbasicblock -> unit
1625 (** [build_invoke fn args tobb unwindbb name b] creates an
1626 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1627 instruction at the position specified by the instruction builder [b].
1628 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1629 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1630 llbasicblock -> string -> llbuilder -> llvalue
1632 (** [build_landingpad ty persfn numclauses name b] creates an
1634 instruction at the position specified by the instruction builder [b].
1635 See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
1636 val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
1639 (** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
1640 See the method [llvm::LandingPadInst::setCleanup]. *)
1641 val set_cleanup : llvalue -> bool -> unit
1643 (** [build_unreachable b] creates an
1645 instruction at the position specified by the instruction builder [b].
1646 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1647 val build_unreachable : llbuilder -> llvalue
1650 (** {7 Arithmetic} *)
1652 (** [build_add x y name b] creates a
1653 [%name = add %x, %y]
1654 instruction at the position specified by the instruction builder [b].
1655 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1656 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1659 (** [build_nsw_add x y name b] creates a
1660 [%name = nsw add %x, %y]
1661 instruction at the position specified by the instruction builder [b].
1662 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1663 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1666 (** [build_nuw_add x y name b] creates a
1667 [%name = nuw add %x, %y]
1668 instruction at the position specified by the instruction builder [b].
1669 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1670 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1673 (** [build_fadd x y name b] creates a
1674 [%name = fadd %x, %y]
1675 instruction at the position specified by the instruction builder [b].
1676 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1677 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1680 (** [build_sub x y name b] creates a
1681 [%name = sub %x, %y]
1682 instruction at the position specified by the instruction builder [b].
1683 See the method [llvm::LLVMBuilder::CreateSub]. *)
1684 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1687 (** [build_nsw_sub x y name b] creates a
1688 [%name = nsw sub %x, %y]
1689 instruction at the position specified by the instruction builder [b].
1690 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1691 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1694 (** [build_nuw_sub x y name b] creates a
1695 [%name = nuw sub %x, %y]
1696 instruction at the position specified by the instruction builder [b].
1697 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1698 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1701 (** [build_fsub x y name b] creates a
1702 [%name = fsub %x, %y]
1703 instruction at the position specified by the instruction builder [b].
1704 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1705 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1708 (** [build_mul x y name b] creates a
1709 [%name = mul %x, %y]
1710 instruction at the position specified by the instruction builder [b].
1711 See the method [llvm::LLVMBuilder::CreateMul]. *)
1712 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1715 (** [build_nsw_mul x y name b] creates a
1716 [%name = nsw mul %x, %y]
1717 instruction at the position specified by the instruction builder [b].
1718 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1719 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1722 (** [build_nuw_mul x y name b] creates a
1723 [%name = nuw mul %x, %y]
1724 instruction at the position specified by the instruction builder [b].
1725 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1726 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1729 (** [build_fmul x y name b] creates a
1730 [%name = fmul %x, %y]
1731 instruction at the position specified by the instruction builder [b].
1732 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1733 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1736 (** [build_udiv x y name b] creates a
1737 [%name = udiv %x, %y]
1738 instruction at the position specified by the instruction builder [b].
1739 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1740 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1743 (** [build_sdiv x y name b] creates a
1744 [%name = sdiv %x, %y]
1745 instruction at the position specified by the instruction builder [b].
1746 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1747 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1750 (** [build_exact_sdiv x y name b] creates a
1751 [%name = exact sdiv %x, %y]
1752 instruction at the position specified by the instruction builder [b].
1753 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1754 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1757 (** [build_fdiv x y name b] creates a
1758 [%name = fdiv %x, %y]
1759 instruction at the position specified by the instruction builder [b].
1760 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1761 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1764 (** [build_urem x y name b] creates a
1765 [%name = urem %x, %y]
1766 instruction at the position specified by the instruction builder [b].
1767 See the method [llvm::LLVMBuilder::CreateURem]. *)
1768 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1771 (** [build_SRem x y name b] creates a
1772 [%name = srem %x, %y]
1773 instruction at the position specified by the instruction builder [b].
1774 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1775 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1778 (** [build_frem x y name b] creates a
1779 [%name = frem %x, %y]
1780 instruction at the position specified by the instruction builder [b].
1781 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1782 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1785 (** [build_shl x y name b] creates a
1786 [%name = shl %x, %y]
1787 instruction at the position specified by the instruction builder [b].
1788 See the method [llvm::LLVMBuilder::CreateShl]. *)
1789 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1792 (** [build_lshr x y name b] creates a
1793 [%name = lshr %x, %y]
1794 instruction at the position specified by the instruction builder [b].
1795 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1796 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1799 (** [build_ashr x y name b] creates a
1800 [%name = ashr %x, %y]
1801 instruction at the position specified by the instruction builder [b].
1802 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1803 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1806 (** [build_and x y name b] creates a
1807 [%name = and %x, %y]
1808 instruction at the position specified by the instruction builder [b].
1809 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1810 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1813 (** [build_or x y name b] creates a
1815 instruction at the position specified by the instruction builder [b].
1816 See the method [llvm::LLVMBuilder::CreateOr]. *)
1817 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1820 (** [build_xor x y name b] creates a
1821 [%name = xor %x, %y]
1822 instruction at the position specified by the instruction builder [b].
1823 See the method [llvm::LLVMBuilder::CreateXor]. *)
1824 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1827 (** [build_neg x name b] creates a
1829 instruction at the position specified by the instruction builder [b].
1830 [-0.0] is used for floating point types to compute the correct sign.
1831 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1832 val build_neg : llvalue -> string -> llbuilder -> llvalue
1835 (** [build_nsw_neg x name b] creates a
1836 [%name = nsw sub 0, %x]
1837 instruction at the position specified by the instruction builder [b].
1838 [-0.0] is used for floating point types to compute the correct sign.
1839 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1840 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1843 (** [build_nuw_neg x name b] creates a
1844 [%name = nuw sub 0, %x]
1845 instruction at the position specified by the instruction builder [b].
1846 [-0.0] is used for floating point types to compute the correct sign.
1847 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1848 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1851 (** [build_fneg x name b] creates a
1852 [%name = fsub 0, %x]
1853 instruction at the position specified by the instruction builder [b].
1854 [-0.0] is used for floating point types to compute the correct sign.
1855 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1856 val build_fneg : llvalue -> string -> llbuilder -> llvalue
1859 (** [build_xor x name b] creates a
1860 [%name = xor %x, -1]
1861 instruction at the position specified by the instruction builder [b].
1862 [-1] is the correct "all ones" value for the type of [x].
1863 See the method [llvm::LLVMBuilder::CreateXor]. *)
1864 val build_not : llvalue -> string -> llbuilder -> llvalue
1870 (** [build_alloca ty name b] creates a
1871 [%name = alloca %ty]
1872 instruction at the position specified by the instruction builder [b].
1873 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1874 val build_alloca : lltype -> string -> llbuilder -> llvalue
1877 (** [build_array_alloca ty n name b] creates a
1878 [%name = alloca %ty, %n]
1879 instruction at the position specified by the instruction builder [b].
1880 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1881 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1884 (** [build_load v name b] creates a
1886 instruction at the position specified by the instruction builder [b].
1887 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1888 val build_load : llvalue -> string -> llbuilder -> llvalue
1891 (** [build_store v p b] creates a
1893 instruction at the position specified by the instruction builder [b].
1894 See the method [llvm::LLVMBuilder::CreateStore]. *)
1895 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
1898 (** [build_gep p indices name b] creates a
1899 [%name = getelementptr %p, indices...]
1900 instruction at the position specified by the instruction builder [b].
1901 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1902 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1905 (** [build_in_bounds_gep p indices name b] creates a
1906 [%name = gelementptr inbounds %p, indices...]
1907 instruction at the position specified by the instruction builder [b].
1908 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1909 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1912 (** [build_struct_gep p idx name b] creates a
1913 [%name = getelementptr %p, 0, idx]
1914 instruction at the position specified by the instruction builder [b].
1915 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1916 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
1919 (** [build_global_string str name b] creates a series of instructions that adds
1920 a global string at the position specified by the instruction builder [b].
1921 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1922 val build_global_string : string -> string -> llbuilder -> llvalue
1925 (** [build_global_stringptr str name b] creates a series of instructions that
1926 adds a global string pointer at the position specified by the instruction
1928 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1929 val build_global_stringptr : string -> string -> llbuilder -> llvalue
1935 (** [build_trunc v ty name b] creates a
1936 [%name = trunc %p to %ty]
1937 instruction at the position specified by the instruction builder [b].
1938 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1939 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1942 (** [build_zext v ty name b] creates a
1943 [%name = zext %p to %ty]
1944 instruction at the position specified by the instruction builder [b].
1945 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1946 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1949 (** [build_sext v ty name b] creates a
1950 [%name = sext %p to %ty]
1951 instruction at the position specified by the instruction builder [b].
1952 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1953 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1956 (** [build_fptoui v ty name b] creates a
1957 [%name = fptoui %p to %ty]
1958 instruction at the position specified by the instruction builder [b].
1959 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1960 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1963 (** [build_fptosi v ty name b] creates a
1964 [%name = fptosi %p to %ty]
1965 instruction at the position specified by the instruction builder [b].
1966 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1967 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1970 (** [build_uitofp v ty name b] creates a
1971 [%name = uitofp %p to %ty]
1972 instruction at the position specified by the instruction builder [b].
1973 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1974 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1977 (** [build_sitofp v ty name b] creates a
1978 [%name = sitofp %p to %ty]
1979 instruction at the position specified by the instruction builder [b].
1980 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1981 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1984 (** [build_fptrunc v ty name b] creates a
1985 [%name = fptrunc %p to %ty]
1986 instruction at the position specified by the instruction builder [b].
1987 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1988 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1991 (** [build_fpext v ty name b] creates a
1992 [%name = fpext %p to %ty]
1993 instruction at the position specified by the instruction builder [b].
1994 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1995 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1998 (** [build_ptrtoint v ty name b] creates a
1999 [%name = prtotint %p to %ty]
2000 instruction at the position specified by the instruction builder [b].
2001 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2002 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2005 (** [build_inttoptr v ty name b] creates a
2006 [%name = inttoptr %p to %ty]
2007 instruction at the position specified by the instruction builder [b].
2008 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2009 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2012 (** [build_bitcast v ty name b] creates a
2013 [%name = bitcast %p to %ty]
2014 instruction at the position specified by the instruction builder [b].
2015 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2016 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2019 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2020 instruction at the position specified by the instruction builder [b].
2021 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2022 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2025 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2026 instruction at the position specified by the instruction builder [b].
2027 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2028 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2031 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2032 instruction at the position specified by the instruction builder [b].
2033 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2034 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2037 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2038 instruction at the position specified by the instruction builder [b].
2039 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2040 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2043 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2044 instruction at the position specified by the instruction builder [b].
2045 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2046 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2049 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2050 instruction at the position specified by the instruction builder [b].
2051 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2052 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2056 (** {7 Comparisons} *)
2058 (** [build_icmp pred x y name b] creates a
2059 [%name = icmp %pred %x, %y]
2060 instruction at the position specified by the instruction builder [b].
2061 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2062 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2063 llbuilder -> llvalue
2065 (** [build_fcmp pred x y name b] creates a
2066 [%name = fcmp %pred %x, %y]
2067 instruction at the position specified by the instruction builder [b].
2068 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2069 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2070 llbuilder -> llvalue
2073 (** {7 Miscellaneous instructions} *)
2075 (** [build_phi incoming name b] creates a
2076 [%name = phi %incoming]
2077 instruction at the position specified by the instruction builder [b].
2078 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2079 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2080 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2083 (** [build_call fn args name b] creates a
2084 [%name = call %fn(args...)]
2085 instruction at the position specified by the instruction builder [b].
2086 See the method [llvm::LLVMBuilder::CreateCall]. *)
2087 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2090 (** [build_select cond thenv elsev name b] creates a
2091 [%name = select %cond, %thenv, %elsev]
2092 instruction at the position specified by the instruction builder [b].
2093 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2094 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2097 (** [build_va_arg valist argty name b] creates a
2098 [%name = va_arg %valist, %argty]
2099 instruction at the position specified by the instruction builder [b].
2100 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2101 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2104 (** [build_extractelement vec i name b] creates a
2105 [%name = extractelement %vec, %i]
2106 instruction at the position specified by the instruction builder [b].
2107 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2108 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2111 (** [build_insertelement vec elt i name b] creates a
2112 [%name = insertelement %vec, %elt, %i]
2113 instruction at the position specified by the instruction builder [b].
2114 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2115 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2116 llbuilder -> llvalue
2118 (** [build_shufflevector veca vecb mask name b] creates a
2119 [%name = shufflevector %veca, %vecb, %mask]
2120 instruction at the position specified by the instruction builder [b].
2121 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2122 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2123 llbuilder -> llvalue
2125 (** [build_insertvalue agg idx name b] creates a
2126 [%name = extractvalue %agg, %idx]
2127 instruction at the position specified by the instruction builder [b].
2128 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2129 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2132 (** [build_insertvalue agg val idx name b] creates a
2133 [%name = insertvalue %agg, %val, %idx]
2134 instruction at the position specified by the instruction builder [b].
2135 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2136 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2139 (** [build_is_null val name b] creates a
2140 [%name = icmp eq %val, null]
2141 instruction at the position specified by the instruction builder [b].
2142 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2143 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2146 (** [build_is_not_null val name b] creates a
2147 [%name = icmp ne %val, null]
2148 instruction at the position specified by the instruction builder [b].
2149 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2150 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2153 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2154 the difference between two pointer values at the position specified by the
2155 instruction builder [b].
2156 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2157 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2161 (** {6 Memory buffers} *)
2163 module MemoryBuffer : sig
2164 (** [of_file p] is the memory buffer containing the contents of the file at
2165 path [p]. If the file could not be read, then [IoError msg] is
2167 val of_file : string -> llmemorybuffer
2169 (** [stdin ()] is the memory buffer containing the contents of standard input.
2170 If standard input is empty, then [IoError msg] is raised. *)
2171 val of_stdin : unit -> llmemorybuffer
2173 (** Disposes of a memory buffer. *)
2174 val dispose : llmemorybuffer -> unit
2178 (** {6 Pass Managers} *)
2180 module PassManager : sig
2183 type any = [ `Module | `Function ]
2185 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2186 type of pipeline is suitable for link-time optimization and whole-module
2188 See the constructor of [llvm::PassManager]. *)
2189 val create : unit -> [ `Module ] t
2191 (** [PassManager.create_function m] constructs a new function-by-function
2192 pass pipeline over the module [m]. It does not take ownership of [m].
2193 This type of pipeline is suitable for code generation and JIT compilation
2195 See the constructor of [llvm::FunctionPassManager]. *)
2196 val create_function : llmodule -> [ `Function ] t
2199 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2200 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2201 any of the passes modified the module, [false] otherwise.
2202 See the [llvm::PassManager::run] method. *)
2203 val run_module : llmodule -> [ `Module ] t -> bool
2206 (** [initialize fpm] initializes all of the function passes scheduled in the
2207 function pass manager [fpm]. Returns [true] if any of the passes modified
2208 the module, [false] otherwise.
2209 See the [llvm::FunctionPassManager::doInitialization] method. *)
2210 val initialize : [ `Function ] t -> bool
2212 (** [run_function f fpm] executes all of the function passes scheduled in the
2213 function pass manager [fpm] over the function [f]. Returns [true] if any
2214 of the passes modified [f], [false] otherwise.
2215 See the [llvm::FunctionPassManager::run] method. *)
2216 val run_function : llvalue -> [ `Function ] t -> bool
2219 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2220 function pass manager [fpm]. Returns [true] if any of the passes
2221 modified the module, [false] otherwise.
2222 See the [llvm::FunctionPassManager::doFinalization] method. *)
2223 val finalize : [ `Function ] t -> bool
2225 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2227 See the destructor of [llvm::BasePassManager]. *)
2228 val dispose : [< any ] t -> unit