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 (** [va_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
376 (** [struct_element_types sty] returns the constituent types of the struct type
377 [sty]. See the method [llvm::StructType::getElementType]. *)
378 val struct_element_types : lltype -> lltype array
381 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
382 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
383 val is_packed : lltype -> bool
386 (** {7 Operations on pointer, vector, and array types} *)
388 (** [array_type ty n] returns the array type containing [n] elements of type
389 [ty]. See the method [llvm::ArrayType::get]. *)
390 val array_type : lltype -> int -> lltype
392 (** [pointer_type ty] returns the pointer type referencing objects of type
393 [ty] in the default address space (0).
394 See the method [llvm::PointerType::getUnqual]. *)
395 val pointer_type : lltype -> lltype
397 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
398 of type [ty] in address space [as].
399 See the method [llvm::PointerType::get]. *)
400 val qualified_pointer_type : lltype -> int -> lltype
403 (** [vector_type ty n] returns the array type containing [n] elements of the
404 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
405 val vector_type : lltype -> int -> lltype
407 (** [element_type ty] returns the element type of the pointer, vector, or array
408 type [ty]. See the method [llvm::SequentialType::get]. *)
409 val element_type : lltype -> lltype
411 (** [element_type aty] returns the element count of the array type [aty].
412 See the method [llvm::ArrayType::getNumElements]. *)
413 val array_length : lltype -> int
415 (** [address_space pty] returns the address space qualifier of the pointer type
416 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
417 val address_space : lltype -> int
419 (** [element_type ty] returns the element count of the vector type [ty].
420 See the method [llvm::VectorType::getNumElements]. *)
421 val vector_size : lltype -> int
424 (** {7 Operations on other types} *)
426 (** [void_type c] creates a type of a function which does not return any
427 value in the context [c]. See [llvm::Type::VoidTy]. *)
428 val void_type : llcontext -> lltype
430 (** [label_type c] creates a type of a basic block in the context [c]. See
431 [llvm::Type::LabelTy]. *)
432 val label_type : llcontext -> lltype
436 (** [type_of v] returns the type of the value [v].
437 See the method [llvm::Value::getType]. *)
438 val type_of : llvalue -> lltype
440 (** [value_name v] returns the name of the value [v]. For global values, this is
441 the symbol name. For instructions and basic blocks, it is the SSA register
442 name. It is meaningless for constants.
443 See the method [llvm::Value::getName]. *)
444 val value_name : llvalue -> string
446 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
447 [llvm::Value::setName]. *)
448 val set_value_name : string -> llvalue -> unit
450 (** [dump_value v] prints the .ll representation of the value [v] to standard
451 error. See the method [llvm::Value::dump]. *)
452 val dump_value : llvalue -> unit
454 (** [replace_all_uses_with old new] replaces all uses of the value [old]
455 * with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
456 val replace_all_uses_with : llvalue -> llvalue -> unit
462 (** [use_begin v] returns the first position in the use list for the value [v].
463 [use_begin] and [use_succ] can e used to iterate over the use list in order.
464 See the method [llvm::Value::use_begin]. *)
465 val use_begin : llvalue -> lluse option
467 (** [use_succ u] returns the use list position succeeding [u].
468 See the method [llvm::use_value_iterator::operator++]. *)
469 val use_succ : lluse -> lluse option
471 (** [user u] returns the user of the use [u].
472 See the method [llvm::Use::getUser]. *)
473 val user : lluse -> llvalue
475 (** [used_value u] returns the usee of the use [u].
476 See the method [llvm::Use::getUsedValue]. *)
477 val used_value : lluse -> llvalue
479 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
480 in order. Tail recursive. *)
481 val iter_uses : (lluse -> unit) -> llvalue -> unit
483 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
484 [u1,...,uN] are the users of the value [v]. Tail recursive. *)
485 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
487 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
488 [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
489 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
494 (** [operand v i] returns the operand at index [i] for the value [v]. See the
495 method [llvm::User::getOperand]. *)
496 val operand : llvalue -> int -> llvalue
498 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
500 See the method [llvm::User::setOperand]. *)
501 val set_operand : llvalue -> int -> llvalue -> unit
503 (** [num_operands v] returns the number of operands for the value [v].
504 See the method [llvm::User::getNumOperands]. *)
505 val num_operands : llvalue -> int
507 (** {7 Operations on constants of (mostly) any type} *)
509 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
510 otherwise. Similar to [llvm::isa<Constant>]. *)
511 val is_constant : llvalue -> bool
513 (** [const_null ty] returns the constant null (zero) of the type [ty].
514 See the method [llvm::Constant::getNullValue]. *)
515 val const_null : lltype -> llvalue
517 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
518 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
519 val const_all_ones : (*int|vec*)lltype -> llvalue
521 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
522 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
523 val const_pointer_null : lltype -> llvalue
525 (** [undef ty] returns the undefined value of the type [ty].
526 See the method [llvm::UndefValue::get]. *)
527 val undef : lltype -> llvalue
529 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
530 See the method [llvm::Constant::isNullValue]. *)
531 val is_null : llvalue -> bool
533 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
534 otherwise. Similar to [llvm::isa<UndefValue>]. *)
535 val is_undef : llvalue -> bool
538 (** {7 Operations on instructions} *)
540 (** [has_metadata i] returns whether or not the instruction [i] has any
541 metadata attached to it. See the function
542 [llvm::Instruction::hasMetadata]. *)
543 val has_metadata : llvalue -> bool
545 (** [metadata i kind] optionally returns the metadata associated with the
546 kind [kind] in the instruction [i] See the function
547 [llvm::Instruction::getMetadata]. *)
548 val metadata : llvalue -> int -> llvalue option
550 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
551 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
552 val set_metadata : llvalue -> int -> llvalue -> unit
554 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
555 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
556 val clear_metadata : llvalue -> int -> unit
559 (** {7 Operations on metadata} *)
561 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
562 See the method [llvm::MDNode::get]. *)
563 val mdstring : llcontext -> string -> llvalue
565 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
567 See the method [llvm::MDNode::get]. *)
568 val mdnode : llcontext -> llvalue array -> llvalue
571 (** {7 Operations on scalar constants} *)
573 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
574 See the method [llvm::ConstantInt::get]. *)
575 val const_int : lltype -> int -> llvalue
577 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
578 [i]. See the method [llvm::ConstantInt::get]. *)
579 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
582 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
583 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
584 val const_int_of_string : lltype -> string -> int -> llvalue
587 (** [const_float ty n] returns the floating point constant of type [ty] and
588 value [n]. See the method [llvm::ConstantFP::get]. *)
589 val const_float : lltype -> float -> llvalue
591 (** [const_float_of_string ty s] returns the floating point constant of type
592 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
593 val const_float_of_string : lltype -> string -> llvalue
597 (** {7 Operations on composite constants} *)
599 (** [const_string c s] returns the constant [i8] array with the values of the
600 characters in the string [s] in the context [c]. The array is not
601 null-terminated (but see {!const_stringz}). This value can in turn be used
602 as the initializer for a global variable. See the method
603 [llvm::ConstantArray::get]. *)
604 val const_string : llcontext -> string -> llvalue
606 (** [const_stringz c s] returns the constant [i8] array with the values of the
607 characters in the string [s] and a null terminator in the context [c]. This
608 value can in turn be used as the initializer for a global variable.
609 See the method [llvm::ConstantArray::get]. *)
610 val const_stringz : llcontext -> string -> llvalue
612 (** [const_array ty elts] returns the constant array of type
613 [array_type ty (Array.length elts)] and containing the values [elts].
614 This value can in turn be used as the initializer for a global variable.
615 See the method [llvm::ConstantArray::get]. *)
616 val const_array : lltype -> llvalue array -> llvalue
618 (** [const_struct context elts] returns the structured constant of type
619 [struct_type (Array.map type_of elts)] and containing the values [elts]
620 in the context [context]. This value can in turn be used as the initializer
621 for a global variable. See the method [llvm::ConstantStruct::get]. *)
622 val const_struct : llcontext -> llvalue array -> llvalue
625 (** [const_packed_struct context elts] returns the structured constant of
626 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
627 values [elts] in the context [context]. This value can in turn be used as
628 the initializer for a global variable. See the method
629 [llvm::ConstantStruct::get]. *)
630 val const_packed_struct : llcontext -> llvalue array -> llvalue
633 (** [const_vector elts] returns the vector constant of type
634 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
635 values [elts]. See the method [llvm::ConstantVector::get]. *)
636 val const_vector : llvalue array -> llvalue
639 (** {7 Constant expressions} *)
641 (** [align_of ty] returns the alignof constant for the type [ty]. This is
642 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
643 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
644 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
645 val align_of : lltype -> llvalue
647 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
648 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
649 (const_int i32_type 1)) i64_type], but considerably more readable.
650 See the method [llvm::ConstantExpr::getSizeOf]. *)
651 val size_of : lltype -> llvalue
653 (** [const_neg c] returns the arithmetic negation of the constant [c].
654 See the method [llvm::ConstantExpr::getNeg]. *)
655 val const_neg : llvalue -> llvalue
657 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
658 no signed wrapping. The result is undefined if the negation overflows.
659 See the method [llvm::ConstantExpr::getNSWNeg]. *)
660 val const_nsw_neg : llvalue -> llvalue
662 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
663 no unsigned wrapping. The result is undefined if the negation overflows.
664 See the method [llvm::ConstantExpr::getNUWNeg]. *)
665 val const_nuw_neg : llvalue -> llvalue
667 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
668 See the method [llvm::ConstantExpr::getFNeg]. *)
669 val const_fneg : llvalue -> llvalue
671 (** [const_not c] returns the bitwise inverse of the constant [c].
672 See the method [llvm::ConstantExpr::getNot]. *)
673 val const_not : llvalue -> llvalue
675 (** [const_add c1 c2] returns the constant sum of two constants.
676 See the method [llvm::ConstantExpr::getAdd]. *)
677 val const_add : llvalue -> llvalue -> llvalue
679 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
680 signed wrapping. The result is undefined if the sum overflows.
681 See the method [llvm::ConstantExpr::getNSWAdd]. *)
682 val const_nsw_add : llvalue -> llvalue -> llvalue
684 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
685 unsigned wrapping. The result is undefined if the sum overflows.
686 See the method [llvm::ConstantExpr::getNSWAdd]. *)
687 val const_nuw_add : llvalue -> llvalue -> llvalue
689 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
690 See the method [llvm::ConstantExpr::getFAdd]. *)
691 val const_fadd : llvalue -> llvalue -> llvalue
693 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
694 constants. See the method [llvm::ConstantExpr::getSub]. *)
695 val const_sub : llvalue -> llvalue -> llvalue
697 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
698 no signed wrapping. The result is undefined if the sum overflows.
699 See the method [llvm::ConstantExpr::getNSWSub]. *)
700 val const_nsw_sub : llvalue -> llvalue -> llvalue
702 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
703 no unsigned wrapping. The result is undefined if the sum overflows.
704 See the method [llvm::ConstantExpr::getNSWSub]. *)
705 val const_nuw_sub : llvalue -> llvalue -> llvalue
707 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
708 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
709 val const_fsub : llvalue -> llvalue -> llvalue
711 (** [const_mul c1 c2] returns the constant product of two constants.
712 See the method [llvm::ConstantExpr::getMul]. *)
713 val const_mul : llvalue -> llvalue -> llvalue
715 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
716 no signed wrapping. The result is undefined if the sum overflows.
717 See the method [llvm::ConstantExpr::getNSWMul]. *)
718 val const_nsw_mul : llvalue -> llvalue -> llvalue
720 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
721 no unsigned wrapping. The result is undefined if the sum overflows.
722 See the method [llvm::ConstantExpr::getNSWMul]. *)
723 val const_nuw_mul : llvalue -> llvalue -> llvalue
725 (** [const_fmul c1 c2] returns the constant product of two constants floats.
726 See the method [llvm::ConstantExpr::getFMul]. *)
727 val const_fmul : llvalue -> llvalue -> llvalue
729 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
731 See the method [llvm::ConstantExpr::getUDiv]. *)
732 val const_udiv : llvalue -> llvalue -> llvalue
734 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
736 See the method [llvm::ConstantExpr::getSDiv]. *)
737 val const_sdiv : llvalue -> llvalue -> llvalue
739 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
740 signed integer constants. The result is undefined if the result is rounded
741 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
742 val const_exact_sdiv : llvalue -> llvalue -> llvalue
744 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
746 See the method [llvm::ConstantExpr::getFDiv]. *)
747 val const_fdiv : llvalue -> llvalue -> llvalue
749 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
750 unsigned integer constants.
751 See the method [llvm::ConstantExpr::getURem]. *)
752 val const_urem : llvalue -> llvalue -> llvalue
754 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
755 signed integer constants.
756 See the method [llvm::ConstantExpr::getSRem]. *)
757 val const_srem : llvalue -> llvalue -> llvalue
759 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
760 signed floating point constants.
761 See the method [llvm::ConstantExpr::getFRem]. *)
762 val const_frem : llvalue -> llvalue -> llvalue
764 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
766 See the method [llvm::ConstantExpr::getAnd]. *)
767 val const_and : llvalue -> llvalue -> llvalue
769 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
771 See the method [llvm::ConstantExpr::getOr]. *)
772 val const_or : llvalue -> llvalue -> llvalue
774 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
776 See the method [llvm::ConstantExpr::getXor]. *)
777 val const_xor : llvalue -> llvalue -> llvalue
779 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
780 constants, [c1 pred c2].
781 See the method [llvm::ConstantExpr::getICmp]. *)
782 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
785 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
786 point constants, [c1 pred c2].
787 See the method [llvm::ConstantExpr::getFCmp]. *)
788 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
791 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
792 constant integer [c2].
793 See the method [llvm::ConstantExpr::getShl]. *)
794 val const_shl : llvalue -> llvalue -> llvalue
796 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
797 constant integer [c2] with zero extension.
798 See the method [llvm::ConstantExpr::getLShr]. *)
799 val const_lshr : llvalue -> llvalue -> llvalue
801 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
802 constant integer [c2] with sign extension.
803 See the method [llvm::ConstantExpr::getAShr]. *)
804 val const_ashr : llvalue -> llvalue -> llvalue
806 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
807 constant integers indices from the array [indices].
808 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
809 val const_gep : llvalue -> llvalue array -> llvalue
811 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
812 with the constant integers indices from the array [indices].
813 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
814 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
817 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
818 to the smaller integer type [ty].
819 See the method [llvm::ConstantExpr::getTrunc]. *)
820 val const_trunc : llvalue -> lltype -> llvalue
822 (** [const_sext c ty] returns the constant sign extension of integer constant
823 [c] to the larger integer type [ty].
824 See the method [llvm::ConstantExpr::getSExt]. *)
825 val const_sext : llvalue -> lltype -> llvalue
827 (** [const_zext c ty] returns the constant zero extension of integer constant
828 [c] to the larger integer type [ty].
829 See the method [llvm::ConstantExpr::getZExt]. *)
830 val const_zext : llvalue -> lltype -> llvalue
832 (** [const_fptrunc c ty] returns the constant truncation of floating point
833 constant [c] to the smaller floating point type [ty].
834 See the method [llvm::ConstantExpr::getFPTrunc]. *)
835 val const_fptrunc : llvalue -> lltype -> llvalue
837 (** [const_fpext c ty] returns the constant extension of floating point constant
838 [c] to the larger floating point type [ty].
839 See the method [llvm::ConstantExpr::getFPExt]. *)
840 val const_fpext : llvalue -> lltype -> llvalue
842 (** [const_uitofp c ty] returns the constant floating point conversion of
843 unsigned integer constant [c] to the floating point type [ty].
844 See the method [llvm::ConstantExpr::getUIToFP]. *)
845 val const_uitofp : llvalue -> lltype -> llvalue
847 (** [const_sitofp c ty] returns the constant floating point conversion of
848 signed integer constant [c] to the floating point type [ty].
849 See the method [llvm::ConstantExpr::getSIToFP]. *)
850 val const_sitofp : llvalue -> lltype -> llvalue
852 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
853 floating point constant [c] to integer type [ty].
854 See the method [llvm::ConstantExpr::getFPToUI]. *)
855 val const_fptoui : llvalue -> lltype -> llvalue
857 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
858 floating point constant [c] to integer type [ty].
859 See the method [llvm::ConstantExpr::getFPToSI]. *)
860 val const_fptosi : llvalue -> lltype -> llvalue
862 (** [const_ptrtoint c ty] returns the constant integer conversion of
863 pointer constant [c] to integer type [ty].
864 See the method [llvm::ConstantExpr::getPtrToInt]. *)
865 val const_ptrtoint : llvalue -> lltype -> llvalue
867 (** [const_inttoptr c ty] returns the constant pointer conversion of
868 integer constant [c] to pointer type [ty].
869 See the method [llvm::ConstantExpr::getIntToPtr]. *)
870 val const_inttoptr : llvalue -> lltype -> llvalue
872 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
873 to type [ty] of equal size.
874 See the method [llvm::ConstantExpr::getBitCast]. *)
875 val const_bitcast : llvalue -> lltype -> llvalue
877 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
878 conversion of constant [c] to type [ty].
879 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
880 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
883 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
884 conversion of constant [c] to type [ty].
885 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
886 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
889 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
890 conversion of constant [c] to type [ty].
891 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
892 val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
895 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
896 cast conversion of constant [c] to type [ty] of equal size.
897 See the method [llvm::ConstantExpr::getPointerCast]. *)
898 val const_pointercast : llvalue -> lltype -> llvalue
901 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
902 -> integer casts of constant [c] to type [ty].
903 See the method [llvm::ConstantExpr::getIntCast]. *)
904 val const_intcast : llvalue -> lltype -> llvalue
907 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
908 fp casts of constant [c] to type [ty].
909 See the method [llvm::ConstantExpr::getFPCast]. *)
910 val const_fpcast : llvalue -> lltype -> llvalue
913 (** [const_select cond t f] returns the constant conditional which returns value
914 [t] if the boolean constant [cond] is true and the value [f] otherwise.
915 See the method [llvm::ConstantExpr::getSelect]. *)
916 val const_select : llvalue -> llvalue -> llvalue -> llvalue
919 (** [const_extractelement vec i] returns the constant [i]th element of
920 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
921 the size of the vector.
922 See the method [llvm::ConstantExpr::getExtractElement]. *)
923 val const_extractelement : llvalue -> llvalue -> llvalue
926 (** [const_insertelement vec v i] returns the constant vector with the same
927 elements as constant vector [v] but the [i]th element replaced by the
928 constant [v]. [v] must be a constant value with the type of the vector
929 elements. [i] must be a constant [i32] value unsigned less than the size
931 See the method [llvm::ConstantExpr::getInsertElement]. *)
932 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
935 (** [const_shufflevector a b mask] returns a constant [shufflevector].
936 See the LLVM Language Reference for details on the [shufflevector]
938 See the method [llvm::ConstantExpr::getShuffleVector]. *)
939 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
942 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
943 constant aggregate [agg]. Each [idxs] must be less than the size of the
944 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
945 val const_extractvalue : llvalue -> int array -> llvalue
948 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
949 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
950 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
951 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
954 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
955 See the method [llvm::InlineAsm::get]. *)
956 val const_inline_asm : lltype -> string -> string -> bool -> bool ->
960 (** [block_address f bb] returns the address of the basic block [bb] in the
961 function [f]. See the method [llvm::BasicBlock::get]. *)
962 val block_address : llvalue -> llbasicblock -> llvalue
965 (** {7 Operations on global variables, functions, and aliases (globals)} *)
967 (** [global_parent g] is the enclosing module of the global value [g].
968 See the method [llvm::GlobalValue::getParent]. *)
969 val global_parent : llvalue -> llmodule
971 (** [is_declaration g] returns [true] if the global value [g] is a declaration
972 only. Returns [false] otherwise.
973 See the method [llvm::GlobalValue::isDeclaration]. *)
974 val is_declaration : llvalue -> bool
976 (** [linkage g] returns the linkage of the global value [g].
977 See the method [llvm::GlobalValue::getLinkage]. *)
978 val linkage : llvalue -> Linkage.t
980 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
981 See the method [llvm::GlobalValue::setLinkage]. *)
982 val set_linkage : Linkage.t -> llvalue -> unit
984 (** [section g] returns the linker section of the global value [g].
985 See the method [llvm::GlobalValue::getSection]. *)
986 val section : llvalue -> string
988 (** [set_section s g] sets the linker section of the global value [g] to [s].
989 See the method [llvm::GlobalValue::setSection]. *)
990 val set_section : string -> llvalue -> unit
992 (** [visibility g] returns the linker visibility of the global value [g].
993 See the method [llvm::GlobalValue::getVisibility]. *)
994 val visibility : llvalue -> Visibility.t
996 (** [set_visibility v g] sets the linker visibility of the global value [g] to
997 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
998 val set_visibility : Visibility.t -> llvalue -> unit
1001 (** [alignment g] returns the required alignment of the global value [g].
1002 See the method [llvm::GlobalValue::getAlignment]. *)
1003 val alignment : llvalue -> int
1005 (** [set_alignment n g] sets the required alignment of the global value [g] to
1006 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1007 val set_alignment : int -> llvalue -> unit
1010 (** {7 Operations on global variables} *)
1012 (** [declare_global ty name m] returns a new global variable of type [ty] and
1013 with name [name] in module [m] in the default address space (0). If such a
1014 global variable already exists, it is returned. If the type of the existing
1015 global differs, then a bitcast to [ty] is returned. *)
1016 val declare_global : lltype -> string -> llmodule -> llvalue
1019 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1020 of type [ty] and with name [name] in module [m] in the address space
1021 [addrspace]. If such a global variable already exists, it is returned. If
1022 the type of the existing global differs, then a bitcast to [ty] is
1024 val declare_qualified_global : lltype -> string -> int -> llmodule ->
1028 (** [define_global name init m] returns a new global with name [name] and
1029 initializer [init] in module [m] in the default address space (0). If the
1030 named global already exists, it is renamed.
1031 See the constructor of [llvm::GlobalVariable]. *)
1032 val define_global : string -> llvalue -> llmodule -> llvalue
1035 (** [define_qualified_global name init addrspace m] returns a new global with
1036 name [name] and initializer [init] in module [m] in the address space
1037 [addrspace]. If the named global already exists, it is renamed.
1038 See the constructor of [llvm::GlobalVariable]. *)
1039 val define_qualified_global : string -> llvalue -> int -> llmodule ->
1043 (** [lookup_global name m] returns [Some g] if a global variable with name
1044 [name] exists in module [m]. If no such global exists, returns [None].
1045 See the [llvm::GlobalVariable] constructor. *)
1046 val lookup_global : string -> llmodule -> llvalue option
1049 (** [delete_global gv] destroys the global variable [gv].
1050 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1051 val delete_global : llvalue -> unit
1053 (** [global_begin m] returns the first position in the global variable list of
1054 the module [m]. [global_begin] and [global_succ] can be used to iterate
1055 over the global list in order.
1056 See the method [llvm::Module::global_begin]. *)
1057 val global_begin : llmodule -> (llmodule, llvalue) llpos
1060 (** [global_succ gv] returns the global variable list position succeeding
1062 See the method [llvm::Module::global_iterator::operator++]. *)
1063 val global_succ : llvalue -> (llmodule, llvalue) llpos
1066 (** [iter_globals f m] applies function [f] to each of the global variables of
1067 module [m] in order. Tail recursive. *)
1068 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1070 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1071 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1072 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1074 (** [global_end m] returns the last position in the global variable list of the
1075 module [m]. [global_end] and [global_pred] can be used to iterate over the
1076 global list in reverse.
1077 See the method [llvm::Module::global_end]. *)
1078 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1081 (** [global_pred gv] returns the global variable list position preceding
1083 See the method [llvm::Module::global_iterator::operator--]. *)
1084 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1087 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1088 of module [m] in reverse order. Tail recursive. *)
1089 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1091 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1092 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1093 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1095 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1096 constant. Returns [false] otherwise.
1097 See the method [llvm::GlobalVariable::isConstant]. *)
1098 val is_global_constant : llvalue -> bool
1100 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1101 [c] is [true] and not if [c] is [false].
1102 See the method [llvm::GlobalVariable::setConstant]. *)
1103 val set_global_constant : bool -> llvalue -> unit
1106 (** [global_initializer gv] returns the initializer for the global variable
1107 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1108 val global_initializer : llvalue -> llvalue
1110 (** [set_initializer c gv] sets the initializer for the global variable
1111 [gv] to the constant [c].
1112 See the method [llvm::GlobalVariable::setInitializer]. *)
1113 val set_initializer : llvalue -> llvalue -> unit
1115 (** [remove_initializer gv] unsets the initializer for the global variable
1117 See the method [llvm::GlobalVariable::setInitializer]. *)
1118 val remove_initializer : llvalue -> unit
1120 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1121 thread-local and [false] otherwise.
1122 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1123 val is_thread_local : llvalue -> bool
1125 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1126 [c] is [true] and not otherwise.
1127 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1128 val set_thread_local : bool -> llvalue -> unit
1131 (** {7 Operations on aliases} *)
1133 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1134 the aliasee [a] with the name [n].
1135 See the constructor for [llvm::GlobalAlias]. *)
1136 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1140 (** {7 Operations on functions} *)
1142 (** [declare_function name ty m] returns a new function of type [ty] and
1143 with name [name] in module [m]. If such a function already exists,
1144 it is returned. If the type of the existing function differs, then a bitcast
1145 to [ty] is returned. *)
1146 val declare_function : string -> lltype -> llmodule -> llvalue
1149 (** [define_function name ty m] creates a new function with name [name] and
1150 type [ty] in module [m]. If the named function already exists, it is
1151 renamed. An entry basic block is created in the function.
1152 See the constructor of [llvm::GlobalVariable]. *)
1153 val define_function : string -> lltype -> llmodule -> llvalue
1156 (** [lookup_function name m] returns [Some f] if a function with name
1157 [name] exists in module [m]. If no such function exists, returns [None].
1158 See the method [llvm::Module] constructor. *)
1159 val lookup_function : string -> llmodule -> llvalue option
1162 (** [delete_function f] destroys the function [f].
1163 See the method [llvm::Function::eraseFromParent]. *)
1164 val delete_function : llvalue -> unit
1166 (** [function_begin m] returns the first position in the function list of the
1167 module [m]. [function_begin] and [function_succ] can be used to iterate over
1168 the function list in order.
1169 See the method [llvm::Module::begin]. *)
1170 val function_begin : llmodule -> (llmodule, llvalue) llpos
1173 (** [function_succ gv] returns the function list position succeeding
1175 See the method [llvm::Module::iterator::operator++]. *)
1176 val function_succ : llvalue -> (llmodule, llvalue) llpos
1179 (** [iter_functions f m] applies function [f] to each of the functions of module
1180 [m] in order. Tail recursive. *)
1181 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1183 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1184 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1185 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1187 (** [function_end m] returns the last position in the function list of
1188 the module [m]. [function_end] and [function_pred] can be used to iterate
1189 over the function list in reverse.
1190 See the method [llvm::Module::end]. *)
1191 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1194 (** [function_pred gv] returns the function list position preceding [After gv].
1195 See the method [llvm::Module::iterator::operator--]. *)
1196 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1199 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1200 module [m] in reverse order. Tail recursive. *)
1201 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1203 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1204 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1205 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1207 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1208 See the method [llvm::Function::isIntrinsic]. *)
1209 val is_intrinsic : llvalue -> bool
1211 (** [function_call_conv f] returns the calling convention of the function [f].
1212 See the method [llvm::Function::getCallingConv]. *)
1213 val function_call_conv : llvalue -> int
1215 (** [set_function_call_conv cc f] sets the calling convention of the function
1216 [f] to the calling convention numbered [cc].
1217 See the method [llvm::Function::setCallingConv]. *)
1218 val set_function_call_conv : int -> llvalue -> unit
1221 (** [gc f] returns [Some name] if the function [f] has a garbage
1222 collection algorithm specified and [None] otherwise.
1223 See the method [llvm::Function::getGC]. *)
1224 val gc : llvalue -> string option
1226 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1227 [gc]. See the method [llvm::Function::setGC]. *)
1228 val set_gc : string option -> llvalue -> unit
1230 (** [add_function_attr f a] adds attribute [a] to the return type of function
1232 val add_function_attr : llvalue -> Attribute.t -> unit
1234 (** [remove_function_attr f a] removes attribute [a] from the return type of
1236 val remove_function_attr : llvalue -> Attribute.t -> unit
1238 (** {7 Operations on params} *)
1240 (** [params f] returns the parameters of function [f].
1241 See the method [llvm::Function::getArgumentList]. *)
1242 val params : llvalue -> llvalue array
1244 (** [param f n] returns the [n]th parameter of function [f].
1245 See the method [llvm::Function::getArgumentList]. *)
1246 val param : llvalue -> int -> llvalue
1248 (** [param_parent p] returns the parent function that owns the parameter.
1249 See the method [llvm::Argument::getParent]. *)
1250 val param_parent : llvalue -> llvalue
1252 (** [param_begin f] returns the first position in the parameter list of the
1253 function [f]. [param_begin] and [param_succ] can be used to iterate over
1254 the parameter list in order.
1255 See the method [llvm::Function::arg_begin]. *)
1256 val param_begin : llvalue -> (llvalue, llvalue) llpos
1258 (** [param_succ bb] returns the parameter list position succeeding
1260 See the method [llvm::Function::arg_iterator::operator++]. *)
1261 val param_succ : llvalue -> (llvalue, llvalue) llpos
1263 (** [iter_params f fn] applies function [f] to each of the parameters
1264 of function [fn] in order. Tail recursive. *)
1265 val iter_params : (llvalue -> unit) -> llvalue -> unit
1267 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1268 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1269 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1271 (** [param_end f] returns the last position in the parameter list of
1272 the function [f]. [param_end] and [param_pred] can be used to iterate
1273 over the parameter list in reverse.
1274 See the method [llvm::Function::arg_end]. *)
1275 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1277 (** [param_pred gv] returns the function list position preceding [After gv].
1278 See the method [llvm::Function::arg_iterator::operator--]. *)
1279 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1282 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1283 of function [fn] in reverse order. Tail recursive. *)
1284 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1286 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1287 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1288 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1290 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1291 val add_param_attr : llvalue -> Attribute.t -> unit
1293 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1294 val remove_param_attr : llvalue -> Attribute.t -> unit
1296 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1297 val set_param_alignment : llvalue -> int -> unit
1300 (** {7 Operations on basic blocks} *)
1302 (** [basic_blocks fn] returns the basic blocks of the function [f].
1303 See the method [llvm::Function::getBasicBlockList]. *)
1304 val basic_blocks : llvalue -> llbasicblock array
1306 (** [entry_block fn] returns the entry basic block of the function [f].
1307 See the method [llvm::Function::getEntryBlock]. *)
1308 val entry_block : llvalue -> llbasicblock
1310 (** [delete_block bb] deletes the basic block [bb].
1311 See the method [llvm::BasicBlock::eraseFromParent]. *)
1312 val delete_block : llbasicblock -> unit
1314 (** [append_block c name f] creates a new basic block named [name] at the end of
1315 function [f] in the context [c].
1316 See the constructor of [llvm::BasicBlock]. *)
1317 val append_block : llcontext -> string -> llvalue -> llbasicblock
1320 (** [insert_block c name bb] creates a new basic block named [name] before the
1321 basic block [bb] in the context [c].
1322 See the constructor of [llvm::BasicBlock]. *)
1323 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1326 (** [block_parent bb] returns the parent function that owns the basic block.
1327 See the method [llvm::BasicBlock::getParent]. *)
1328 val block_parent : llbasicblock -> llvalue
1330 (** [block_begin f] returns the first position in the basic block list of the
1331 function [f]. [block_begin] and [block_succ] can be used to iterate over
1332 the basic block list in order.
1333 See the method [llvm::Function::begin]. *)
1334 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1337 (** [block_succ bb] returns the basic block list position succeeding
1339 See the method [llvm::Function::iterator::operator++]. *)
1340 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1343 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1344 of function [fn] in order. Tail recursive. *)
1345 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1347 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1348 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1349 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1351 (** [block_end f] returns the last position in the basic block list of
1352 the function [f]. [block_end] and [block_pred] can be used to iterate
1353 over the basic block list in reverse.
1354 See the method [llvm::Function::end]. *)
1355 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1358 (** [block_pred gv] returns the function list position preceding [After gv].
1359 See the method [llvm::Function::iterator::operator--]. *)
1360 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1363 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1364 of function [fn] in reverse order. Tail recursive. *)
1365 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1367 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1368 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1369 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1371 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1372 val value_of_block : llbasicblock -> llvalue
1374 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1376 Similar to [llvm::isa<BasicBlock>]. *)
1377 val value_is_block : llvalue -> bool
1379 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1380 val block_of_value : llvalue -> llbasicblock
1383 (** {7 Operations on instructions} *)
1385 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1386 See the method [llvm::Instruction::getParent]. *)
1387 val instr_parent : llvalue -> llbasicblock
1389 (** [instr_begin bb] returns the first position in the instruction list of the
1390 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1391 the instruction list in order.
1392 See the method [llvm::BasicBlock::begin]. *)
1393 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1396 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1397 See the method [llvm::BasicBlock::iterator::operator++]. *)
1398 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1401 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1402 block [bb] in order. Tail recursive. *)
1403 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1405 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1406 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1407 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1409 (** [instr_end bb] returns the last position in the instruction list of the
1410 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1411 the instruction list in reverse.
1412 See the method [llvm::BasicBlock::end]. *)
1413 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1416 (** [instr_pred i] returns the instruction list position preceding [After i].
1417 See the method [llvm::BasicBlock::iterator::operator--]. *)
1418 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1421 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1422 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1423 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1426 (** {7 Operations on call sites} *)
1428 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1429 instruction [ci], which may be one of the values from the module
1430 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1431 [llvm::InvokeInst::getCallingConv]. *)
1432 val instruction_call_conv: llvalue -> int
1435 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1436 or invoke instruction [ci] to the integer [cc], which can be one of the
1437 values from the module {!CallConv}.
1438 See the method [llvm::CallInst::setCallingConv]
1439 and [llvm::InvokeInst::setCallingConv]. *)
1440 val set_instruction_call_conv: int -> llvalue -> unit
1443 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1444 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1446 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1448 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1449 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1451 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1453 (** {Operations on call instructions (only)} *)
1455 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1456 eligible for tail call optimization, [false] otherwise.
1457 See the method [llvm::CallInst::isTailCall]. *)
1458 val is_tail_call : llvalue -> bool
1460 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1461 call optimization if [tc] is [true], clears otherwise.
1462 See the method [llvm::CallInst::setTailCall]. *)
1463 val set_tail_call : bool -> llvalue -> unit
1465 (** {7 Operations on phi nodes} *)
1467 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1468 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1469 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1472 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1473 See the method [llvm::PHINode::getIncomingValue]. *)
1474 val incoming : llvalue -> (llvalue * llbasicblock) list
1478 (** {6 Instruction builders} *)
1480 (** [builder context] creates an instruction builder with no position in
1481 the context [context]. It is invalid to use this builder until its position
1482 is set with {!position_before} or {!position_at_end}. See the constructor
1483 for [llvm::LLVMBuilder]. *)
1484 val builder : llcontext -> llbuilder
1486 (** [builder_at ip] creates an instruction builder positioned at [ip].
1487 See the constructor for [llvm::LLVMBuilder]. *)
1488 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1490 (** [builder_before ins] creates an instruction builder positioned before the
1491 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1492 val builder_before : llcontext -> llvalue -> llbuilder
1494 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1495 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1496 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1498 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1500 See the constructor for [llvm::LLVMBuilder]. *)
1501 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1504 (** [position_before ins b] moves the instruction builder [b] to before the
1505 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1506 val position_before : llvalue -> llbuilder -> unit
1508 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1509 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1510 val position_at_end : llbasicblock -> llbuilder -> unit
1512 (** [insertion_block b] returns the basic block that the builder [b] is
1513 positioned to insert into. Raises [Not_Found] if the instruction builder is
1515 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1516 val insertion_block : llbuilder -> llbasicblock
1518 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1519 position specified by the instruction builder [b].
1520 See the method [llvm::LLVMBuilder::Insert]. *)
1521 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1526 (** [set_current_debug_location b md] sets the current debug location [md] in
1528 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1529 val set_current_debug_location : llbuilder -> llvalue -> unit
1532 (** [clear_current_debug_location b] clears the current debug location in the
1534 val clear_current_debug_location : llbuilder -> unit
1537 (** [current_debug_location b] returns the current debug location, or None
1538 if none is currently set.
1539 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1540 val current_debug_location : llbuilder -> llvalue option
1543 (** [set_inst_debug_location b i] sets the current debug location of the builder
1544 [b] to the instruction [i].
1545 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1546 val set_inst_debug_location : llbuilder -> llvalue -> unit
1549 (** {7 Terminators} *)
1551 (** [build_ret_void b] creates a
1553 instruction at the position specified by the instruction builder [b].
1554 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1555 val build_ret_void : llbuilder -> llvalue
1557 (** [build_ret v b] creates a
1559 instruction at the position specified by the instruction builder [b].
1560 See the method [llvm::LLVMBuilder::CreateRet]. *)
1561 val build_ret : llvalue -> llbuilder -> llvalue
1563 (** [build_aggregate_ret vs b] creates a
1564 [ret {...} { %v1, %v2, ... } ]
1565 instruction at the position specified by the instruction builder [b].
1566 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1567 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1570 (** [build_br bb b] creates a
1572 instruction at the position specified by the instruction builder [b].
1573 See the method [llvm::LLVMBuilder::CreateBr]. *)
1574 val build_br : llbasicblock -> llbuilder -> llvalue
1576 (** [build_cond_br cond tbb fbb b] creates a
1577 [br %cond, %tbb, %fbb]
1578 instruction at the position specified by the instruction builder [b].
1579 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1580 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1583 (** [build_switch case elsebb count b] creates an empty
1584 [switch %case, %elsebb]
1585 instruction at the position specified by the instruction builder [b] with
1586 space reserved for [count] cases.
1587 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1588 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1591 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1592 when its input matches the constant [onval].
1593 See the method [llvm::SwitchInst::addCase]. **)
1594 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1597 (** [build_indirect_br addr count b] creates a
1599 instruction at the position specified by the instruction builder [b] with
1600 space reserved for [count] destinations.
1601 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1602 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1605 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1606 location for the indirectbr instruction [br].
1607 See the method [llvm::IndirectBrInst::addDestination]. **)
1608 val add_destination : llvalue -> llbasicblock -> unit
1611 (** [build_invoke fn args tobb unwindbb name b] creates an
1612 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1613 instruction at the position specified by the instruction builder [b].
1614 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1615 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1616 llbasicblock -> string -> llbuilder -> llvalue
1619 (** [build_unreachable b] creates an
1621 instruction at the position specified by the instruction builder [b].
1622 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1623 val build_unreachable : llbuilder -> llvalue
1626 (** {7 Arithmetic} *)
1628 (** [build_add x y name b] creates a
1629 [%name = add %x, %y]
1630 instruction at the position specified by the instruction builder [b].
1631 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1632 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1635 (** [build_nsw_add x y name b] creates a
1636 [%name = nsw add %x, %y]
1637 instruction at the position specified by the instruction builder [b].
1638 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1639 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1642 (** [build_nuw_add x y name b] creates a
1643 [%name = nuw add %x, %y]
1644 instruction at the position specified by the instruction builder [b].
1645 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1646 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1649 (** [build_fadd x y name b] creates a
1650 [%name = fadd %x, %y]
1651 instruction at the position specified by the instruction builder [b].
1652 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1653 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1656 (** [build_sub x y name b] creates a
1657 [%name = sub %x, %y]
1658 instruction at the position specified by the instruction builder [b].
1659 See the method [llvm::LLVMBuilder::CreateSub]. *)
1660 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1663 (** [build_nsw_sub x y name b] creates a
1664 [%name = nsw sub %x, %y]
1665 instruction at the position specified by the instruction builder [b].
1666 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1667 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1670 (** [build_nuw_sub x y name b] creates a
1671 [%name = nuw sub %x, %y]
1672 instruction at the position specified by the instruction builder [b].
1673 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1674 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1677 (** [build_fsub x y name b] creates a
1678 [%name = fsub %x, %y]
1679 instruction at the position specified by the instruction builder [b].
1680 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1681 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1684 (** [build_mul x y name b] creates a
1685 [%name = mul %x, %y]
1686 instruction at the position specified by the instruction builder [b].
1687 See the method [llvm::LLVMBuilder::CreateMul]. *)
1688 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1691 (** [build_nsw_mul x y name b] creates a
1692 [%name = nsw mul %x, %y]
1693 instruction at the position specified by the instruction builder [b].
1694 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1695 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1698 (** [build_nuw_mul x y name b] creates a
1699 [%name = nuw mul %x, %y]
1700 instruction at the position specified by the instruction builder [b].
1701 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1702 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1705 (** [build_fmul x y name b] creates a
1706 [%name = fmul %x, %y]
1707 instruction at the position specified by the instruction builder [b].
1708 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1709 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1712 (** [build_udiv x y name b] creates a
1713 [%name = udiv %x, %y]
1714 instruction at the position specified by the instruction builder [b].
1715 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1716 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1719 (** [build_sdiv x y name b] creates a
1720 [%name = sdiv %x, %y]
1721 instruction at the position specified by the instruction builder [b].
1722 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1723 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1726 (** [build_exact_sdiv x y name b] creates a
1727 [%name = exact sdiv %x, %y]
1728 instruction at the position specified by the instruction builder [b].
1729 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1730 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1733 (** [build_fdiv x y name b] creates a
1734 [%name = fdiv %x, %y]
1735 instruction at the position specified by the instruction builder [b].
1736 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1737 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1740 (** [build_urem x y name b] creates a
1741 [%name = urem %x, %y]
1742 instruction at the position specified by the instruction builder [b].
1743 See the method [llvm::LLVMBuilder::CreateURem]. *)
1744 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1747 (** [build_SRem x y name b] creates a
1748 [%name = srem %x, %y]
1749 instruction at the position specified by the instruction builder [b].
1750 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1751 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1754 (** [build_frem x y name b] creates a
1755 [%name = frem %x, %y]
1756 instruction at the position specified by the instruction builder [b].
1757 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1758 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1761 (** [build_shl x y name b] creates a
1762 [%name = shl %x, %y]
1763 instruction at the position specified by the instruction builder [b].
1764 See the method [llvm::LLVMBuilder::CreateShl]. *)
1765 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1768 (** [build_lshr x y name b] creates a
1769 [%name = lshr %x, %y]
1770 instruction at the position specified by the instruction builder [b].
1771 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1772 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1775 (** [build_ashr x y name b] creates a
1776 [%name = ashr %x, %y]
1777 instruction at the position specified by the instruction builder [b].
1778 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1779 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1782 (** [build_and x y name b] creates a
1783 [%name = and %x, %y]
1784 instruction at the position specified by the instruction builder [b].
1785 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1786 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1789 (** [build_or x y name b] creates a
1791 instruction at the position specified by the instruction builder [b].
1792 See the method [llvm::LLVMBuilder::CreateOr]. *)
1793 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1796 (** [build_xor x y name b] creates a
1797 [%name = xor %x, %y]
1798 instruction at the position specified by the instruction builder [b].
1799 See the method [llvm::LLVMBuilder::CreateXor]. *)
1800 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1803 (** [build_neg x name b] creates a
1805 instruction at the position specified by the instruction builder [b].
1806 [-0.0] is used for floating point types to compute the correct sign.
1807 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1808 val build_neg : llvalue -> string -> llbuilder -> llvalue
1811 (** [build_nsw_neg x name b] creates a
1812 [%name = nsw sub 0, %x]
1813 instruction at the position specified by the instruction builder [b].
1814 [-0.0] is used for floating point types to compute the correct sign.
1815 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1816 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1819 (** [build_nuw_neg x name b] creates a
1820 [%name = nuw sub 0, %x]
1821 instruction at the position specified by the instruction builder [b].
1822 [-0.0] is used for floating point types to compute the correct sign.
1823 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1824 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1827 (** [build_fneg x name b] creates a
1828 [%name = fsub 0, %x]
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::CreateFNeg]. *)
1832 val build_fneg : llvalue -> string -> llbuilder -> llvalue
1835 (** [build_xor x name b] creates a
1836 [%name = xor %x, -1]
1837 instruction at the position specified by the instruction builder [b].
1838 [-1] is the correct "all ones" value for the type of [x].
1839 See the method [llvm::LLVMBuilder::CreateXor]. *)
1840 val build_not : llvalue -> string -> llbuilder -> llvalue
1846 (** [build_alloca ty name b] creates a
1847 [%name = alloca %ty]
1848 instruction at the position specified by the instruction builder [b].
1849 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1850 val build_alloca : lltype -> string -> llbuilder -> llvalue
1853 (** [build_array_alloca ty n name b] creates a
1854 [%name = alloca %ty, %n]
1855 instruction at the position specified by the instruction builder [b].
1856 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1857 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1860 (** [build_load v name b] creates a
1862 instruction at the position specified by the instruction builder [b].
1863 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1864 val build_load : llvalue -> string -> llbuilder -> llvalue
1867 (** [build_store v p b] creates a
1869 instruction at the position specified by the instruction builder [b].
1870 See the method [llvm::LLVMBuilder::CreateStore]. *)
1871 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
1874 (** [build_gep p indices name b] creates a
1875 [%name = getelementptr %p, indices...]
1876 instruction at the position specified by the instruction builder [b].
1877 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1878 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1881 (** [build_in_bounds_gep p indices name b] creates a
1882 [%name = gelementptr inbounds %p, indices...]
1883 instruction at the position specified by the instruction builder [b].
1884 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1885 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1888 (** [build_struct_gep p idx name b] creates a
1889 [%name = getelementptr %p, 0, idx]
1890 instruction at the position specified by the instruction builder [b].
1891 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1892 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
1895 (** [build_global_string str name b] creates a series of instructions that adds
1896 a global string at the position specified by the instruction builder [b].
1897 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1898 val build_global_string : string -> string -> llbuilder -> llvalue
1901 (** [build_global_stringptr str name b] creates a series of instructions that
1902 adds a global string pointer at the position specified by the instruction
1904 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1905 val build_global_stringptr : string -> string -> llbuilder -> llvalue
1911 (** [build_trunc v ty name b] creates a
1912 [%name = trunc %p to %ty]
1913 instruction at the position specified by the instruction builder [b].
1914 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1915 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1918 (** [build_zext v ty name b] creates a
1919 [%name = zext %p to %ty]
1920 instruction at the position specified by the instruction builder [b].
1921 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1922 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1925 (** [build_sext v ty name b] creates a
1926 [%name = sext %p to %ty]
1927 instruction at the position specified by the instruction builder [b].
1928 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1929 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1932 (** [build_fptoui v ty name b] creates a
1933 [%name = fptoui %p to %ty]
1934 instruction at the position specified by the instruction builder [b].
1935 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1936 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1939 (** [build_fptosi v ty name b] creates a
1940 [%name = fptosi %p to %ty]
1941 instruction at the position specified by the instruction builder [b].
1942 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1943 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1946 (** [build_uitofp v ty name b] creates a
1947 [%name = uitofp %p to %ty]
1948 instruction at the position specified by the instruction builder [b].
1949 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1950 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1953 (** [build_sitofp v ty name b] creates a
1954 [%name = sitofp %p to %ty]
1955 instruction at the position specified by the instruction builder [b].
1956 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1957 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1960 (** [build_fptrunc v ty name b] creates a
1961 [%name = fptrunc %p to %ty]
1962 instruction at the position specified by the instruction builder [b].
1963 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1964 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1967 (** [build_fpext v ty name b] creates a
1968 [%name = fpext %p to %ty]
1969 instruction at the position specified by the instruction builder [b].
1970 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1971 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1974 (** [build_ptrtoint v ty name b] creates a
1975 [%name = prtotint %p to %ty]
1976 instruction at the position specified by the instruction builder [b].
1977 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1978 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1981 (** [build_inttoptr v ty name b] creates a
1982 [%name = inttoptr %p to %ty]
1983 instruction at the position specified by the instruction builder [b].
1984 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1985 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1988 (** [build_bitcast v ty name b] creates a
1989 [%name = bitcast %p to %ty]
1990 instruction at the position specified by the instruction builder [b].
1991 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
1992 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1995 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
1996 instruction at the position specified by the instruction builder [b].
1997 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1998 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2001 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2002 instruction at the position specified by the instruction builder [b].
2003 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2004 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2007 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2008 instruction at the position specified by the instruction builder [b].
2009 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2010 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2013 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2014 instruction at the position specified by the instruction builder [b].
2015 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2016 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2019 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2020 instruction at the position specified by the instruction builder [b].
2021 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2022 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2025 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2026 instruction at the position specified by the instruction builder [b].
2027 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2028 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2032 (** {7 Comparisons} *)
2034 (** [build_icmp pred x y name b] creates a
2035 [%name = icmp %pred %x, %y]
2036 instruction at the position specified by the instruction builder [b].
2037 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2038 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2039 llbuilder -> llvalue
2041 (** [build_fcmp pred x y name b] creates a
2042 [%name = fcmp %pred %x, %y]
2043 instruction at the position specified by the instruction builder [b].
2044 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2045 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2046 llbuilder -> llvalue
2049 (** {7 Miscellaneous instructions} *)
2051 (** [build_phi incoming name b] creates a
2052 [%name = phi %incoming]
2053 instruction at the position specified by the instruction builder [b].
2054 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2055 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2056 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2059 (** [build_call fn args name b] creates a
2060 [%name = call %fn(args...)]
2061 instruction at the position specified by the instruction builder [b].
2062 See the method [llvm::LLVMBuilder::CreateCall]. *)
2063 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2066 (** [build_select cond thenv elsev name b] creates a
2067 [%name = select %cond, %thenv, %elsev]
2068 instruction at the position specified by the instruction builder [b].
2069 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2070 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2073 (** [build_va_arg valist argty name b] creates a
2074 [%name = va_arg %valist, %argty]
2075 instruction at the position specified by the instruction builder [b].
2076 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2077 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2080 (** [build_extractelement vec i name b] creates a
2081 [%name = extractelement %vec, %i]
2082 instruction at the position specified by the instruction builder [b].
2083 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2084 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2087 (** [build_insertelement vec elt i name b] creates a
2088 [%name = insertelement %vec, %elt, %i]
2089 instruction at the position specified by the instruction builder [b].
2090 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2091 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2092 llbuilder -> llvalue
2094 (** [build_shufflevector veca vecb mask name b] creates a
2095 [%name = shufflevector %veca, %vecb, %mask]
2096 instruction at the position specified by the instruction builder [b].
2097 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2098 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2099 llbuilder -> llvalue
2101 (** [build_insertvalue agg idx name b] creates a
2102 [%name = extractvalue %agg, %idx]
2103 instruction at the position specified by the instruction builder [b].
2104 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2105 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2108 (** [build_insertvalue agg val idx name b] creates a
2109 [%name = insertvalue %agg, %val, %idx]
2110 instruction at the position specified by the instruction builder [b].
2111 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2112 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2115 (** [build_is_null val name b] creates a
2116 [%name = icmp eq %val, null]
2117 instruction at the position specified by the instruction builder [b].
2118 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2119 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2122 (** [build_is_not_null val name b] creates a
2123 [%name = icmp ne %val, null]
2124 instruction at the position specified by the instruction builder [b].
2125 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2126 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2129 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2130 the difference between two pointer values at the position specified by the
2131 instruction builder [b].
2132 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2133 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2137 (** {6 Memory buffers} *)
2139 module MemoryBuffer : sig
2140 (** [of_file p] is the memory buffer containing the contents of the file at
2141 path [p]. If the file could not be read, then [IoError msg] is
2143 val of_file : string -> llmemorybuffer
2145 (** [stdin ()] is the memory buffer containing the contents of standard input.
2146 If standard input is empty, then [IoError msg] is raised. *)
2147 val of_stdin : unit -> llmemorybuffer
2149 (** Disposes of a memory buffer. *)
2150 val dispose : llmemorybuffer -> unit
2154 (** {6 Pass Managers} *)
2156 module PassManager : sig
2159 type any = [ `Module | `Function ]
2161 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2162 type of pipeline is suitable for link-time optimization and whole-module
2164 See the constructor of [llvm::PassManager]. *)
2165 val create : unit -> [ `Module ] t
2167 (** [PassManager.create_function m] constructs a new function-by-function
2168 pass pipeline over the module [m]. It does not take ownership of [m].
2169 This type of pipeline is suitable for code generation and JIT compilation
2171 See the constructor of [llvm::FunctionPassManager]. *)
2172 val create_function : llmodule -> [ `Function ] t
2175 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2176 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2177 any of the passes modified the module, [false] otherwise.
2178 See the [llvm::PassManager::run] method. *)
2179 val run_module : llmodule -> [ `Module ] t -> bool
2182 (** [initialize fpm] initializes all of the function passes scheduled in the
2183 function pass manager [fpm]. Returns [true] if any of the passes modified
2184 the module, [false] otherwise.
2185 See the [llvm::FunctionPassManager::doInitialization] method. *)
2186 val initialize : [ `Function ] t -> bool
2188 (** [run_function f fpm] executes all of the function passes scheduled in the
2189 function pass manager [fpm] over the function [f]. Returns [true] if any
2190 of the passes modified [f], [false] otherwise.
2191 See the [llvm::FunctionPassManager::run] method. *)
2192 val run_function : llvalue -> [ `Function ] t -> bool
2195 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2196 function pass manager [fpm]. Returns [true] if any of the passes
2197 modified the module, [false] otherwise.
2198 See the [llvm::FunctionPassManager::doFinalization] method. *)
2199 val finalize : [ `Function ] t -> bool
2201 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2203 See the destructor of [llvm::BasePassManager]. *)
2204 val dispose : [< any ] t -> unit