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
575 (** {7 Operations on scalar constants} *)
577 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
578 See the method [llvm::ConstantInt::get]. *)
579 val const_int : lltype -> int -> llvalue
581 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
582 [i]. See the method [llvm::ConstantInt::get]. *)
583 val const_of_int64 : lltype -> Int64.t -> bool -> llvalue
586 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
587 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
588 val const_int_of_string : lltype -> string -> int -> llvalue
591 (** [const_float ty n] returns the floating point constant of type [ty] and
592 value [n]. See the method [llvm::ConstantFP::get]. *)
593 val const_float : lltype -> float -> llvalue
595 (** [const_float_of_string ty s] returns the floating point constant of type
596 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
597 val const_float_of_string : lltype -> string -> llvalue
601 (** {7 Operations on composite constants} *)
603 (** [const_string c s] returns the constant [i8] array with the values of the
604 characters in the string [s] in the context [c]. The array is not
605 null-terminated (but see {!const_stringz}). This value can in turn be used
606 as the initializer for a global variable. See the method
607 [llvm::ConstantArray::get]. *)
608 val const_string : llcontext -> string -> llvalue
610 (** [const_stringz c s] returns the constant [i8] array with the values of the
611 characters in the string [s] and a null terminator in the context [c]. This
612 value can in turn be used as the initializer for a global variable.
613 See the method [llvm::ConstantArray::get]. *)
614 val const_stringz : llcontext -> string -> llvalue
616 (** [const_array ty elts] returns the constant array of type
617 [array_type ty (Array.length elts)] and containing the values [elts].
618 This value can in turn be used as the initializer for a global variable.
619 See the method [llvm::ConstantArray::get]. *)
620 val const_array : lltype -> llvalue array -> llvalue
622 (** [const_struct context elts] returns the structured constant of type
623 [struct_type (Array.map type_of elts)] and containing the values [elts]
624 in the context [context]. This value can in turn be used as the initializer
625 for a global variable. See the method [llvm::ConstantStruct::get]. *)
626 val const_struct : llcontext -> llvalue array -> llvalue
629 (** [const_packed_struct context elts] returns the structured constant of
630 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
631 values [elts] in the context [context]. This value can in turn be used as
632 the initializer for a global variable. See the method
633 [llvm::ConstantStruct::get]. *)
634 val const_packed_struct : llcontext -> llvalue array -> llvalue
637 (** [const_vector elts] returns the vector constant of type
638 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
639 values [elts]. See the method [llvm::ConstantVector::get]. *)
640 val const_vector : llvalue array -> llvalue
643 (** {7 Constant expressions} *)
645 (** [align_of ty] returns the alignof constant for the type [ty]. This is
646 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
647 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
648 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
649 val align_of : lltype -> llvalue
651 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
652 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
653 (const_int i32_type 1)) i64_type], but considerably more readable.
654 See the method [llvm::ConstantExpr::getSizeOf]. *)
655 val size_of : lltype -> llvalue
657 (** [const_neg c] returns the arithmetic negation of the constant [c].
658 See the method [llvm::ConstantExpr::getNeg]. *)
659 val const_neg : llvalue -> llvalue
661 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
662 no signed wrapping. The result is undefined if the negation overflows.
663 See the method [llvm::ConstantExpr::getNSWNeg]. *)
664 val const_nsw_neg : llvalue -> llvalue
666 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
667 no unsigned wrapping. The result is undefined if the negation overflows.
668 See the method [llvm::ConstantExpr::getNUWNeg]. *)
669 val const_nuw_neg : llvalue -> llvalue
671 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
672 See the method [llvm::ConstantExpr::getFNeg]. *)
673 val const_fneg : llvalue -> llvalue
675 (** [const_not c] returns the bitwise inverse of the constant [c].
676 See the method [llvm::ConstantExpr::getNot]. *)
677 val const_not : llvalue -> llvalue
679 (** [const_add c1 c2] returns the constant sum of two constants.
680 See the method [llvm::ConstantExpr::getAdd]. *)
681 val const_add : llvalue -> llvalue -> llvalue
683 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
684 signed wrapping. The result is undefined if the sum overflows.
685 See the method [llvm::ConstantExpr::getNSWAdd]. *)
686 val const_nsw_add : llvalue -> llvalue -> llvalue
688 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
689 unsigned wrapping. The result is undefined if the sum overflows.
690 See the method [llvm::ConstantExpr::getNSWAdd]. *)
691 val const_nuw_add : llvalue -> llvalue -> llvalue
693 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
694 See the method [llvm::ConstantExpr::getFAdd]. *)
695 val const_fadd : llvalue -> llvalue -> llvalue
697 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
698 constants. See the method [llvm::ConstantExpr::getSub]. *)
699 val const_sub : llvalue -> llvalue -> llvalue
701 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
702 no signed wrapping. The result is undefined if the sum overflows.
703 See the method [llvm::ConstantExpr::getNSWSub]. *)
704 val const_nsw_sub : llvalue -> llvalue -> llvalue
706 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
707 no unsigned wrapping. The result is undefined if the sum overflows.
708 See the method [llvm::ConstantExpr::getNSWSub]. *)
709 val const_nuw_sub : llvalue -> llvalue -> llvalue
711 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
712 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
713 val const_fsub : llvalue -> llvalue -> llvalue
715 (** [const_mul c1 c2] returns the constant product of two constants.
716 See the method [llvm::ConstantExpr::getMul]. *)
717 val const_mul : llvalue -> llvalue -> llvalue
719 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
720 no signed wrapping. The result is undefined if the sum overflows.
721 See the method [llvm::ConstantExpr::getNSWMul]. *)
722 val const_nsw_mul : llvalue -> llvalue -> llvalue
724 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
725 no unsigned wrapping. The result is undefined if the sum overflows.
726 See the method [llvm::ConstantExpr::getNSWMul]. *)
727 val const_nuw_mul : llvalue -> llvalue -> llvalue
729 (** [const_fmul c1 c2] returns the constant product of two constants floats.
730 See the method [llvm::ConstantExpr::getFMul]. *)
731 val const_fmul : llvalue -> llvalue -> llvalue
733 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
735 See the method [llvm::ConstantExpr::getUDiv]. *)
736 val const_udiv : llvalue -> llvalue -> llvalue
738 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
740 See the method [llvm::ConstantExpr::getSDiv]. *)
741 val const_sdiv : llvalue -> llvalue -> llvalue
743 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
744 signed integer constants. The result is undefined if the result is rounded
745 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
746 val const_exact_sdiv : llvalue -> llvalue -> llvalue
748 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
750 See the method [llvm::ConstantExpr::getFDiv]. *)
751 val const_fdiv : llvalue -> llvalue -> llvalue
753 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
754 unsigned integer constants.
755 See the method [llvm::ConstantExpr::getURem]. *)
756 val const_urem : llvalue -> llvalue -> llvalue
758 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
759 signed integer constants.
760 See the method [llvm::ConstantExpr::getSRem]. *)
761 val const_srem : llvalue -> llvalue -> llvalue
763 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
764 signed floating point constants.
765 See the method [llvm::ConstantExpr::getFRem]. *)
766 val const_frem : llvalue -> llvalue -> llvalue
768 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
770 See the method [llvm::ConstantExpr::getAnd]. *)
771 val const_and : llvalue -> llvalue -> llvalue
773 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
775 See the method [llvm::ConstantExpr::getOr]. *)
776 val const_or : llvalue -> llvalue -> llvalue
778 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
780 See the method [llvm::ConstantExpr::getXor]. *)
781 val const_xor : llvalue -> llvalue -> llvalue
783 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
784 constants, [c1 pred c2].
785 See the method [llvm::ConstantExpr::getICmp]. *)
786 val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
789 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
790 point constants, [c1 pred c2].
791 See the method [llvm::ConstantExpr::getFCmp]. *)
792 val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
795 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
796 constant integer [c2].
797 See the method [llvm::ConstantExpr::getShl]. *)
798 val const_shl : llvalue -> llvalue -> llvalue
800 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
801 constant integer [c2] with zero extension.
802 See the method [llvm::ConstantExpr::getLShr]. *)
803 val const_lshr : llvalue -> llvalue -> llvalue
805 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
806 constant integer [c2] with sign extension.
807 See the method [llvm::ConstantExpr::getAShr]. *)
808 val const_ashr : llvalue -> llvalue -> llvalue
810 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
811 constant integers indices from the array [indices].
812 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
813 val const_gep : llvalue -> llvalue array -> llvalue
815 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
816 with the constant integers indices from the array [indices].
817 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
818 val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
821 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
822 to the smaller integer type [ty].
823 See the method [llvm::ConstantExpr::getTrunc]. *)
824 val const_trunc : llvalue -> lltype -> llvalue
826 (** [const_sext c ty] returns the constant sign extension of integer constant
827 [c] to the larger integer type [ty].
828 See the method [llvm::ConstantExpr::getSExt]. *)
829 val const_sext : llvalue -> lltype -> llvalue
831 (** [const_zext c ty] returns the constant zero extension of integer constant
832 [c] to the larger integer type [ty].
833 See the method [llvm::ConstantExpr::getZExt]. *)
834 val const_zext : llvalue -> lltype -> llvalue
836 (** [const_fptrunc c ty] returns the constant truncation of floating point
837 constant [c] to the smaller floating point type [ty].
838 See the method [llvm::ConstantExpr::getFPTrunc]. *)
839 val const_fptrunc : llvalue -> lltype -> llvalue
841 (** [const_fpext c ty] returns the constant extension of floating point constant
842 [c] to the larger floating point type [ty].
843 See the method [llvm::ConstantExpr::getFPExt]. *)
844 val const_fpext : llvalue -> lltype -> llvalue
846 (** [const_uitofp c ty] returns the constant floating point conversion of
847 unsigned integer constant [c] to the floating point type [ty].
848 See the method [llvm::ConstantExpr::getUIToFP]. *)
849 val const_uitofp : llvalue -> lltype -> llvalue
851 (** [const_sitofp c ty] returns the constant floating point conversion of
852 signed integer constant [c] to the floating point type [ty].
853 See the method [llvm::ConstantExpr::getSIToFP]. *)
854 val const_sitofp : llvalue -> lltype -> llvalue
856 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
857 floating point constant [c] to integer type [ty].
858 See the method [llvm::ConstantExpr::getFPToUI]. *)
859 val const_fptoui : llvalue -> lltype -> llvalue
861 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
862 floating point constant [c] to integer type [ty].
863 See the method [llvm::ConstantExpr::getFPToSI]. *)
864 val const_fptosi : llvalue -> lltype -> llvalue
866 (** [const_ptrtoint c ty] returns the constant integer conversion of
867 pointer constant [c] to integer type [ty].
868 See the method [llvm::ConstantExpr::getPtrToInt]. *)
869 val const_ptrtoint : llvalue -> lltype -> llvalue
871 (** [const_inttoptr c ty] returns the constant pointer conversion of
872 integer constant [c] to pointer type [ty].
873 See the method [llvm::ConstantExpr::getIntToPtr]. *)
874 val const_inttoptr : llvalue -> lltype -> llvalue
876 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
877 to type [ty] of equal size.
878 See the method [llvm::ConstantExpr::getBitCast]. *)
879 val const_bitcast : llvalue -> lltype -> llvalue
881 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
882 conversion of constant [c] to type [ty].
883 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
884 val const_zext_or_bitcast : llvalue -> lltype -> llvalue
887 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
888 conversion of constant [c] to type [ty].
889 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
890 val const_sext_or_bitcast : llvalue -> lltype -> llvalue
893 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
894 conversion of constant [c] to type [ty].
895 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
896 val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
899 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
900 cast conversion of constant [c] to type [ty] of equal size.
901 See the method [llvm::ConstantExpr::getPointerCast]. *)
902 val const_pointercast : llvalue -> lltype -> llvalue
905 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
906 -> integer casts of constant [c] to type [ty].
907 See the method [llvm::ConstantExpr::getIntCast]. *)
908 val const_intcast : llvalue -> lltype -> llvalue
911 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
912 fp casts of constant [c] to type [ty].
913 See the method [llvm::ConstantExpr::getFPCast]. *)
914 val const_fpcast : llvalue -> lltype -> llvalue
917 (** [const_select cond t f] returns the constant conditional which returns value
918 [t] if the boolean constant [cond] is true and the value [f] otherwise.
919 See the method [llvm::ConstantExpr::getSelect]. *)
920 val const_select : llvalue -> llvalue -> llvalue -> llvalue
923 (** [const_extractelement vec i] returns the constant [i]th element of
924 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
925 the size of the vector.
926 See the method [llvm::ConstantExpr::getExtractElement]. *)
927 val const_extractelement : llvalue -> llvalue -> llvalue
930 (** [const_insertelement vec v i] returns the constant vector with the same
931 elements as constant vector [v] but the [i]th element replaced by the
932 constant [v]. [v] must be a constant value with the type of the vector
933 elements. [i] must be a constant [i32] value unsigned less than the size
935 See the method [llvm::ConstantExpr::getInsertElement]. *)
936 val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
939 (** [const_shufflevector a b mask] returns a constant [shufflevector].
940 See the LLVM Language Reference for details on the [shufflevector]
942 See the method [llvm::ConstantExpr::getShuffleVector]. *)
943 val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
946 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
947 constant aggregate [agg]. Each [idxs] must be less than the size of the
948 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
949 val const_extractvalue : llvalue -> int array -> llvalue
952 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
953 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
954 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
955 val const_insertvalue : llvalue -> llvalue -> int array -> llvalue
958 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
959 See the method [llvm::InlineAsm::get]. *)
960 val const_inline_asm : lltype -> string -> string -> bool -> bool ->
964 (** [block_address f bb] returns the address of the basic block [bb] in the
965 function [f]. See the method [llvm::BasicBlock::get]. *)
966 val block_address : llvalue -> llbasicblock -> llvalue
969 (** {7 Operations on global variables, functions, and aliases (globals)} *)
971 (** [global_parent g] is the enclosing module of the global value [g].
972 See the method [llvm::GlobalValue::getParent]. *)
973 val global_parent : llvalue -> llmodule
975 (** [is_declaration g] returns [true] if the global value [g] is a declaration
976 only. Returns [false] otherwise.
977 See the method [llvm::GlobalValue::isDeclaration]. *)
978 val is_declaration : llvalue -> bool
980 (** [linkage g] returns the linkage of the global value [g].
981 See the method [llvm::GlobalValue::getLinkage]. *)
982 val linkage : llvalue -> Linkage.t
984 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
985 See the method [llvm::GlobalValue::setLinkage]. *)
986 val set_linkage : Linkage.t -> llvalue -> unit
988 (** [section g] returns the linker section of the global value [g].
989 See the method [llvm::GlobalValue::getSection]. *)
990 val section : llvalue -> string
992 (** [set_section s g] sets the linker section of the global value [g] to [s].
993 See the method [llvm::GlobalValue::setSection]. *)
994 val set_section : string -> llvalue -> unit
996 (** [visibility g] returns the linker visibility of the global value [g].
997 See the method [llvm::GlobalValue::getVisibility]. *)
998 val visibility : llvalue -> Visibility.t
1000 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1001 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1002 val set_visibility : Visibility.t -> llvalue -> unit
1005 (** [alignment g] returns the required alignment of the global value [g].
1006 See the method [llvm::GlobalValue::getAlignment]. *)
1007 val alignment : llvalue -> int
1009 (** [set_alignment n g] sets the required alignment of the global value [g] to
1010 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1011 val set_alignment : int -> llvalue -> unit
1014 (** {7 Operations on global variables} *)
1016 (** [declare_global ty name m] returns a new global variable of type [ty] and
1017 with name [name] in module [m] in the default address space (0). If such a
1018 global variable already exists, it is returned. If the type of the existing
1019 global differs, then a bitcast to [ty] is returned. *)
1020 val declare_global : lltype -> string -> llmodule -> llvalue
1023 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1024 of type [ty] and with name [name] in module [m] in the address space
1025 [addrspace]. If such a global variable already exists, it is returned. If
1026 the type of the existing global differs, then a bitcast to [ty] is
1028 val declare_qualified_global : lltype -> string -> int -> llmodule ->
1032 (** [define_global name init m] returns a new global with name [name] and
1033 initializer [init] in module [m] in the default address space (0). If the
1034 named global already exists, it is renamed.
1035 See the constructor of [llvm::GlobalVariable]. *)
1036 val define_global : string -> llvalue -> llmodule -> llvalue
1039 (** [define_qualified_global name init addrspace m] returns a new global with
1040 name [name] and initializer [init] in module [m] in the address space
1041 [addrspace]. If the named global already exists, it is renamed.
1042 See the constructor of [llvm::GlobalVariable]. *)
1043 val define_qualified_global : string -> llvalue -> int -> llmodule ->
1047 (** [lookup_global name m] returns [Some g] if a global variable with name
1048 [name] exists in module [m]. If no such global exists, returns [None].
1049 See the [llvm::GlobalVariable] constructor. *)
1050 val lookup_global : string -> llmodule -> llvalue option
1053 (** [delete_global gv] destroys the global variable [gv].
1054 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1055 val delete_global : llvalue -> unit
1057 (** [global_begin m] returns the first position in the global variable list of
1058 the module [m]. [global_begin] and [global_succ] can be used to iterate
1059 over the global list in order.
1060 See the method [llvm::Module::global_begin]. *)
1061 val global_begin : llmodule -> (llmodule, llvalue) llpos
1064 (** [global_succ gv] returns the global variable list position succeeding
1066 See the method [llvm::Module::global_iterator::operator++]. *)
1067 val global_succ : llvalue -> (llmodule, llvalue) llpos
1070 (** [iter_globals f m] applies function [f] to each of the global variables of
1071 module [m] in order. Tail recursive. *)
1072 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1074 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1075 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1076 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1078 (** [global_end m] returns the last position in the global variable list of the
1079 module [m]. [global_end] and [global_pred] can be used to iterate over the
1080 global list in reverse.
1081 See the method [llvm::Module::global_end]. *)
1082 val global_end : llmodule -> (llmodule, llvalue) llrev_pos
1085 (** [global_pred gv] returns the global variable list position preceding
1087 See the method [llvm::Module::global_iterator::operator--]. *)
1088 val global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1091 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1092 of module [m] in reverse order. Tail recursive. *)
1093 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1095 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1096 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1097 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1099 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1100 constant. Returns [false] otherwise.
1101 See the method [llvm::GlobalVariable::isConstant]. *)
1102 val is_global_constant : llvalue -> bool
1104 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1105 [c] is [true] and not if [c] is [false].
1106 See the method [llvm::GlobalVariable::setConstant]. *)
1107 val set_global_constant : bool -> llvalue -> unit
1110 (** [global_initializer gv] returns the initializer for the global variable
1111 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1112 val global_initializer : llvalue -> llvalue
1114 (** [set_initializer c gv] sets the initializer for the global variable
1115 [gv] to the constant [c].
1116 See the method [llvm::GlobalVariable::setInitializer]. *)
1117 val set_initializer : llvalue -> llvalue -> unit
1119 (** [remove_initializer gv] unsets the initializer for the global variable
1121 See the method [llvm::GlobalVariable::setInitializer]. *)
1122 val remove_initializer : llvalue -> unit
1124 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1125 thread-local and [false] otherwise.
1126 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1127 val is_thread_local : llvalue -> bool
1129 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1130 [c] is [true] and not otherwise.
1131 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1132 val set_thread_local : bool -> llvalue -> unit
1135 (** {7 Operations on aliases} *)
1137 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1138 the aliasee [a] with the name [n].
1139 See the constructor for [llvm::GlobalAlias]. *)
1140 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1144 (** {7 Operations on functions} *)
1146 (** [declare_function name ty m] returns a new function of type [ty] and
1147 with name [name] in module [m]. If such a function already exists,
1148 it is returned. If the type of the existing function differs, then a bitcast
1149 to [ty] is returned. *)
1150 val declare_function : string -> lltype -> llmodule -> llvalue
1153 (** [define_function name ty m] creates a new function with name [name] and
1154 type [ty] in module [m]. If the named function already exists, it is
1155 renamed. An entry basic block is created in the function.
1156 See the constructor of [llvm::GlobalVariable]. *)
1157 val define_function : string -> lltype -> llmodule -> llvalue
1160 (** [lookup_function name m] returns [Some f] if a function with name
1161 [name] exists in module [m]. If no such function exists, returns [None].
1162 See the method [llvm::Module] constructor. *)
1163 val lookup_function : string -> llmodule -> llvalue option
1166 (** [delete_function f] destroys the function [f].
1167 See the method [llvm::Function::eraseFromParent]. *)
1168 val delete_function : llvalue -> unit
1170 (** [function_begin m] returns the first position in the function list of the
1171 module [m]. [function_begin] and [function_succ] can be used to iterate over
1172 the function list in order.
1173 See the method [llvm::Module::begin]. *)
1174 val function_begin : llmodule -> (llmodule, llvalue) llpos
1177 (** [function_succ gv] returns the function list position succeeding
1179 See the method [llvm::Module::iterator::operator++]. *)
1180 val function_succ : llvalue -> (llmodule, llvalue) llpos
1183 (** [iter_functions f m] applies function [f] to each of the functions of module
1184 [m] in order. Tail recursive. *)
1185 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1187 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1188 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1189 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1191 (** [function_end m] returns the last position in the function list of
1192 the module [m]. [function_end] and [function_pred] can be used to iterate
1193 over the function list in reverse.
1194 See the method [llvm::Module::end]. *)
1195 val function_end : llmodule -> (llmodule, llvalue) llrev_pos
1198 (** [function_pred gv] returns the function list position preceding [After gv].
1199 See the method [llvm::Module::iterator::operator--]. *)
1200 val function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1203 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1204 module [m] in reverse order. Tail recursive. *)
1205 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1207 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1208 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1209 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1211 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1212 See the method [llvm::Function::isIntrinsic]. *)
1213 val is_intrinsic : llvalue -> bool
1215 (** [function_call_conv f] returns the calling convention of the function [f].
1216 See the method [llvm::Function::getCallingConv]. *)
1217 val function_call_conv : llvalue -> int
1219 (** [set_function_call_conv cc f] sets the calling convention of the function
1220 [f] to the calling convention numbered [cc].
1221 See the method [llvm::Function::setCallingConv]. *)
1222 val set_function_call_conv : int -> llvalue -> unit
1225 (** [gc f] returns [Some name] if the function [f] has a garbage
1226 collection algorithm specified and [None] otherwise.
1227 See the method [llvm::Function::getGC]. *)
1228 val gc : llvalue -> string option
1230 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1231 [gc]. See the method [llvm::Function::setGC]. *)
1232 val set_gc : string option -> llvalue -> unit
1234 (** [add_function_attr f a] adds attribute [a] to the return type of function
1236 val add_function_attr : llvalue -> Attribute.t -> unit
1238 (** [remove_function_attr f a] removes attribute [a] from the return type of
1240 val remove_function_attr : llvalue -> Attribute.t -> unit
1242 (** {7 Operations on params} *)
1244 (** [params f] returns the parameters of function [f].
1245 See the method [llvm::Function::getArgumentList]. *)
1246 val params : llvalue -> llvalue array
1248 (** [param f n] returns the [n]th parameter of function [f].
1249 See the method [llvm::Function::getArgumentList]. *)
1250 val param : llvalue -> int -> llvalue
1252 (** [param_parent p] returns the parent function that owns the parameter.
1253 See the method [llvm::Argument::getParent]. *)
1254 val param_parent : llvalue -> llvalue
1256 (** [param_begin f] returns the first position in the parameter list of the
1257 function [f]. [param_begin] and [param_succ] can be used to iterate over
1258 the parameter list in order.
1259 See the method [llvm::Function::arg_begin]. *)
1260 val param_begin : llvalue -> (llvalue, llvalue) llpos
1262 (** [param_succ bb] returns the parameter list position succeeding
1264 See the method [llvm::Function::arg_iterator::operator++]. *)
1265 val param_succ : llvalue -> (llvalue, llvalue) llpos
1267 (** [iter_params f fn] applies function [f] to each of the parameters
1268 of function [fn] in order. Tail recursive. *)
1269 val iter_params : (llvalue -> unit) -> llvalue -> unit
1271 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1272 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1273 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1275 (** [param_end f] returns the last position in the parameter list of
1276 the function [f]. [param_end] and [param_pred] can be used to iterate
1277 over the parameter list in reverse.
1278 See the method [llvm::Function::arg_end]. *)
1279 val param_end : llvalue -> (llvalue, llvalue) llrev_pos
1281 (** [param_pred gv] returns the function list position preceding [After gv].
1282 See the method [llvm::Function::arg_iterator::operator--]. *)
1283 val param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1286 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1287 of function [fn] in reverse order. Tail recursive. *)
1288 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1290 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1291 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1292 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1294 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1295 val add_param_attr : llvalue -> Attribute.t -> unit
1297 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1298 val remove_param_attr : llvalue -> Attribute.t -> unit
1300 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1301 val set_param_alignment : llvalue -> int -> unit
1304 (** {7 Operations on basic blocks} *)
1306 (** [basic_blocks fn] returns the basic blocks of the function [f].
1307 See the method [llvm::Function::getBasicBlockList]. *)
1308 val basic_blocks : llvalue -> llbasicblock array
1310 (** [entry_block fn] returns the entry basic block of the function [f].
1311 See the method [llvm::Function::getEntryBlock]. *)
1312 val entry_block : llvalue -> llbasicblock
1314 (** [delete_block bb] deletes the basic block [bb].
1315 See the method [llvm::BasicBlock::eraseFromParent]. *)
1316 val delete_block : llbasicblock -> unit
1318 (** [append_block c name f] creates a new basic block named [name] at the end of
1319 function [f] in the context [c].
1320 See the constructor of [llvm::BasicBlock]. *)
1321 val append_block : llcontext -> string -> llvalue -> llbasicblock
1324 (** [insert_block c name bb] creates a new basic block named [name] before the
1325 basic block [bb] in the context [c].
1326 See the constructor of [llvm::BasicBlock]. *)
1327 val insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1330 (** [block_parent bb] returns the parent function that owns the basic block.
1331 See the method [llvm::BasicBlock::getParent]. *)
1332 val block_parent : llbasicblock -> llvalue
1334 (** [block_begin f] returns the first position in the basic block list of the
1335 function [f]. [block_begin] and [block_succ] can be used to iterate over
1336 the basic block list in order.
1337 See the method [llvm::Function::begin]. *)
1338 val block_begin : llvalue -> (llvalue, llbasicblock) llpos
1341 (** [block_succ bb] returns the basic block list position succeeding
1343 See the method [llvm::Function::iterator::operator++]. *)
1344 val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1347 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1348 of function [fn] in order. Tail recursive. *)
1349 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1351 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1352 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1353 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1355 (** [block_end f] returns the last position in the basic block list of
1356 the function [f]. [block_end] and [block_pred] can be used to iterate
1357 over the basic block list in reverse.
1358 See the method [llvm::Function::end]. *)
1359 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1362 (** [block_pred gv] returns the function list position preceding [After gv].
1363 See the method [llvm::Function::iterator::operator--]. *)
1364 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1367 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1368 of function [fn] in reverse order. Tail recursive. *)
1369 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1371 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1372 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1373 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1375 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1376 val value_of_block : llbasicblock -> llvalue
1378 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1380 Similar to [llvm::isa<BasicBlock>]. *)
1381 val value_is_block : llvalue -> bool
1383 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1384 val block_of_value : llvalue -> llbasicblock
1387 (** {7 Operations on instructions} *)
1389 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1390 See the method [llvm::Instruction::getParent]. *)
1391 val instr_parent : llvalue -> llbasicblock
1393 (** [instr_begin bb] returns the first position in the instruction list of the
1394 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1395 the instruction list in order.
1396 See the method [llvm::BasicBlock::begin]. *)
1397 val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1400 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1401 See the method [llvm::BasicBlock::iterator::operator++]. *)
1402 val instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1405 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1406 block [bb] in order. Tail recursive. *)
1407 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1409 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1410 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1411 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1413 (** [instr_end bb] returns the last position in the instruction list of the
1414 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1415 the instruction list in reverse.
1416 See the method [llvm::BasicBlock::end]. *)
1417 val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1420 (** [instr_pred i] returns the instruction list position preceding [After i].
1421 See the method [llvm::BasicBlock::iterator::operator--]. *)
1422 val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1425 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1426 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1427 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1430 (** {7 Operations on call sites} *)
1432 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1433 instruction [ci], which may be one of the values from the module
1434 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1435 [llvm::InvokeInst::getCallingConv]. *)
1436 val instruction_call_conv: llvalue -> int
1439 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1440 or invoke instruction [ci] to the integer [cc], which can be one of the
1441 values from the module {!CallConv}.
1442 See the method [llvm::CallInst::setCallingConv]
1443 and [llvm::InvokeInst::setCallingConv]. *)
1444 val set_instruction_call_conv: int -> llvalue -> unit
1447 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1448 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1450 val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1452 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1453 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1455 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1457 (** {Operations on call instructions (only)} *)
1459 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1460 eligible for tail call optimization, [false] otherwise.
1461 See the method [llvm::CallInst::isTailCall]. *)
1462 val is_tail_call : llvalue -> bool
1464 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1465 call optimization if [tc] is [true], clears otherwise.
1466 See the method [llvm::CallInst::setTailCall]. *)
1467 val set_tail_call : bool -> llvalue -> unit
1469 (** {7 Operations on phi nodes} *)
1471 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1472 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1473 val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1476 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1477 See the method [llvm::PHINode::getIncomingValue]. *)
1478 val incoming : llvalue -> (llvalue * llbasicblock) list
1482 (** {6 Instruction builders} *)
1484 (** [builder context] creates an instruction builder with no position in
1485 the context [context]. It is invalid to use this builder until its position
1486 is set with {!position_before} or {!position_at_end}. See the constructor
1487 for [llvm::LLVMBuilder]. *)
1488 val builder : llcontext -> llbuilder
1490 (** [builder_at ip] creates an instruction builder positioned at [ip].
1491 See the constructor for [llvm::LLVMBuilder]. *)
1492 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1494 (** [builder_before ins] creates an instruction builder positioned before the
1495 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1496 val builder_before : llcontext -> llvalue -> llbuilder
1498 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1499 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1500 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1502 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1504 See the constructor for [llvm::LLVMBuilder]. *)
1505 val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1508 (** [position_before ins b] moves the instruction builder [b] to before the
1509 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1510 val position_before : llvalue -> llbuilder -> unit
1512 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1513 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1514 val position_at_end : llbasicblock -> llbuilder -> unit
1516 (** [insertion_block b] returns the basic block that the builder [b] is
1517 positioned to insert into. Raises [Not_Found] if the instruction builder is
1519 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1520 val insertion_block : llbuilder -> llbasicblock
1522 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1523 position specified by the instruction builder [b].
1524 See the method [llvm::LLVMBuilder::Insert]. *)
1525 val insert_into_builder : llvalue -> string -> llbuilder -> unit
1530 (** [set_current_debug_location b md] sets the current debug location [md] in
1532 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1533 val set_current_debug_location : llbuilder -> llvalue -> unit
1536 (** [clear_current_debug_location b] clears the current debug location in the
1538 val clear_current_debug_location : llbuilder -> unit
1541 (** [current_debug_location b] returns the current debug location, or None
1542 if none is currently set.
1543 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1544 val current_debug_location : llbuilder -> llvalue option
1547 (** [set_inst_debug_location b i] sets the current debug location of the builder
1548 [b] to the instruction [i].
1549 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1550 val set_inst_debug_location : llbuilder -> llvalue -> unit
1553 (** {7 Terminators} *)
1555 (** [build_ret_void b] creates a
1557 instruction at the position specified by the instruction builder [b].
1558 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1559 val build_ret_void : llbuilder -> llvalue
1561 (** [build_ret v b] creates a
1563 instruction at the position specified by the instruction builder [b].
1564 See the method [llvm::LLVMBuilder::CreateRet]. *)
1565 val build_ret : llvalue -> llbuilder -> llvalue
1567 (** [build_aggregate_ret vs b] creates a
1568 [ret {...} { %v1, %v2, ... } ]
1569 instruction at the position specified by the instruction builder [b].
1570 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1571 val build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1574 (** [build_br bb b] creates a
1576 instruction at the position specified by the instruction builder [b].
1577 See the method [llvm::LLVMBuilder::CreateBr]. *)
1578 val build_br : llbasicblock -> llbuilder -> llvalue
1580 (** [build_cond_br cond tbb fbb b] creates a
1581 [br %cond, %tbb, %fbb]
1582 instruction at the position specified by the instruction builder [b].
1583 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1584 val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1587 (** [build_switch case elsebb count b] creates an empty
1588 [switch %case, %elsebb]
1589 instruction at the position specified by the instruction builder [b] with
1590 space reserved for [count] cases.
1591 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1592 val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1595 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1596 when its input matches the constant [onval].
1597 See the method [llvm::SwitchInst::addCase]. **)
1598 val add_case : llvalue -> llvalue -> llbasicblock -> unit
1601 (** [build_indirect_br addr count b] creates a
1603 instruction at the position specified by the instruction builder [b] with
1604 space reserved for [count] destinations.
1605 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1606 val build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1609 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1610 location for the indirectbr instruction [br].
1611 See the method [llvm::IndirectBrInst::addDestination]. **)
1612 val add_destination : llvalue -> llbasicblock -> unit
1615 (** [build_invoke fn args tobb unwindbb name b] creates an
1616 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1617 instruction at the position specified by the instruction builder [b].
1618 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1619 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
1620 llbasicblock -> string -> llbuilder -> llvalue
1622 (** [build_landingpad ty persfn numclauses name b] creates an
1624 instruction at the position specified by the instruction builder [b].
1625 See the method [llvm::LLVMBuilder::CreateLandingPad]. *)
1626 val build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
1629 (** [set_cleanup lp] sets the cleanup flag in the [landingpad]instruction.
1630 See the method [llvm::LandingPadInst::setCleanup]. *)
1631 val set_cleanup : llvalue -> bool -> unit
1633 (** [build_unreachable b] creates an
1635 instruction at the position specified by the instruction builder [b].
1636 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1637 val build_unreachable : llbuilder -> llvalue
1640 (** {7 Arithmetic} *)
1642 (** [build_add x y name b] creates a
1643 [%name = add %x, %y]
1644 instruction at the position specified by the instruction builder [b].
1645 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1646 val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1649 (** [build_nsw_add x y name b] creates a
1650 [%name = nsw add %x, %y]
1651 instruction at the position specified by the instruction builder [b].
1652 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1653 val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1656 (** [build_nuw_add x y name b] creates a
1657 [%name = nuw add %x, %y]
1658 instruction at the position specified by the instruction builder [b].
1659 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1660 val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1663 (** [build_fadd x y name b] creates a
1664 [%name = fadd %x, %y]
1665 instruction at the position specified by the instruction builder [b].
1666 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1667 val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1670 (** [build_sub x y name b] creates a
1671 [%name = sub %x, %y]
1672 instruction at the position specified by the instruction builder [b].
1673 See the method [llvm::LLVMBuilder::CreateSub]. *)
1674 val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1677 (** [build_nsw_sub x y name b] creates a
1678 [%name = nsw sub %x, %y]
1679 instruction at the position specified by the instruction builder [b].
1680 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1681 val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1684 (** [build_nuw_sub x y name b] creates a
1685 [%name = nuw sub %x, %y]
1686 instruction at the position specified by the instruction builder [b].
1687 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1688 val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1691 (** [build_fsub x y name b] creates a
1692 [%name = fsub %x, %y]
1693 instruction at the position specified by the instruction builder [b].
1694 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1695 val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1698 (** [build_mul x y name b] creates a
1699 [%name = mul %x, %y]
1700 instruction at the position specified by the instruction builder [b].
1701 See the method [llvm::LLVMBuilder::CreateMul]. *)
1702 val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1705 (** [build_nsw_mul x y name b] creates a
1706 [%name = nsw mul %x, %y]
1707 instruction at the position specified by the instruction builder [b].
1708 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1709 val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1712 (** [build_nuw_mul x y name b] creates a
1713 [%name = nuw mul %x, %y]
1714 instruction at the position specified by the instruction builder [b].
1715 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1716 val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1719 (** [build_fmul x y name b] creates a
1720 [%name = fmul %x, %y]
1721 instruction at the position specified by the instruction builder [b].
1722 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1723 val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1726 (** [build_udiv x y name b] creates a
1727 [%name = udiv %x, %y]
1728 instruction at the position specified by the instruction builder [b].
1729 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1730 val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1733 (** [build_sdiv x y name b] creates a
1734 [%name = sdiv %x, %y]
1735 instruction at the position specified by the instruction builder [b].
1736 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1737 val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1740 (** [build_exact_sdiv x y name b] creates a
1741 [%name = exact sdiv %x, %y]
1742 instruction at the position specified by the instruction builder [b].
1743 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1744 val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1747 (** [build_fdiv x y name b] creates a
1748 [%name = fdiv %x, %y]
1749 instruction at the position specified by the instruction builder [b].
1750 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1751 val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1754 (** [build_urem x y name b] creates a
1755 [%name = urem %x, %y]
1756 instruction at the position specified by the instruction builder [b].
1757 See the method [llvm::LLVMBuilder::CreateURem]. *)
1758 val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1761 (** [build_SRem x y name b] creates a
1762 [%name = srem %x, %y]
1763 instruction at the position specified by the instruction builder [b].
1764 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1765 val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1768 (** [build_frem x y name b] creates a
1769 [%name = frem %x, %y]
1770 instruction at the position specified by the instruction builder [b].
1771 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1772 val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1775 (** [build_shl x y name b] creates a
1776 [%name = shl %x, %y]
1777 instruction at the position specified by the instruction builder [b].
1778 See the method [llvm::LLVMBuilder::CreateShl]. *)
1779 val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1782 (** [build_lshr x y name b] creates a
1783 [%name = lshr %x, %y]
1784 instruction at the position specified by the instruction builder [b].
1785 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1786 val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1789 (** [build_ashr x y name b] creates a
1790 [%name = ashr %x, %y]
1791 instruction at the position specified by the instruction builder [b].
1792 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1793 val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1796 (** [build_and x y name b] creates a
1797 [%name = and %x, %y]
1798 instruction at the position specified by the instruction builder [b].
1799 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1800 val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1803 (** [build_or x y name b] creates a
1805 instruction at the position specified by the instruction builder [b].
1806 See the method [llvm::LLVMBuilder::CreateOr]. *)
1807 val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1810 (** [build_xor x y name b] creates a
1811 [%name = xor %x, %y]
1812 instruction at the position specified by the instruction builder [b].
1813 See the method [llvm::LLVMBuilder::CreateXor]. *)
1814 val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1817 (** [build_neg x name b] creates a
1819 instruction at the position specified by the instruction builder [b].
1820 [-0.0] is used for floating point types to compute the correct sign.
1821 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1822 val build_neg : llvalue -> string -> llbuilder -> llvalue
1825 (** [build_nsw_neg x name b] creates a
1826 [%name = nsw sub 0, %x]
1827 instruction at the position specified by the instruction builder [b].
1828 [-0.0] is used for floating point types to compute the correct sign.
1829 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1830 val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1833 (** [build_nuw_neg x name b] creates a
1834 [%name = nuw sub 0, %x]
1835 instruction at the position specified by the instruction builder [b].
1836 [-0.0] is used for floating point types to compute the correct sign.
1837 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1838 val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1841 (** [build_fneg x name b] creates a
1842 [%name = fsub 0, %x]
1843 instruction at the position specified by the instruction builder [b].
1844 [-0.0] is used for floating point types to compute the correct sign.
1845 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1846 val build_fneg : llvalue -> string -> llbuilder -> llvalue
1849 (** [build_xor x name b] creates a
1850 [%name = xor %x, -1]
1851 instruction at the position specified by the instruction builder [b].
1852 [-1] is the correct "all ones" value for the type of [x].
1853 See the method [llvm::LLVMBuilder::CreateXor]. *)
1854 val build_not : llvalue -> string -> llbuilder -> llvalue
1860 (** [build_alloca ty name b] creates a
1861 [%name = alloca %ty]
1862 instruction at the position specified by the instruction builder [b].
1863 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1864 val build_alloca : lltype -> string -> llbuilder -> llvalue
1867 (** [build_array_alloca ty n name b] creates a
1868 [%name = alloca %ty, %n]
1869 instruction at the position specified by the instruction builder [b].
1870 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1871 val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1874 (** [build_load v name b] creates a
1876 instruction at the position specified by the instruction builder [b].
1877 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1878 val build_load : llvalue -> string -> llbuilder -> llvalue
1881 (** [build_store v p b] creates a
1883 instruction at the position specified by the instruction builder [b].
1884 See the method [llvm::LLVMBuilder::CreateStore]. *)
1885 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
1888 (** [build_gep p indices name b] creates a
1889 [%name = getelementptr %p, indices...]
1890 instruction at the position specified by the instruction builder [b].
1891 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1892 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1895 (** [build_in_bounds_gep p indices name b] creates a
1896 [%name = gelementptr inbounds %p, indices...]
1897 instruction at the position specified by the instruction builder [b].
1898 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1899 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1902 (** [build_struct_gep p idx name b] creates a
1903 [%name = getelementptr %p, 0, idx]
1904 instruction at the position specified by the instruction builder [b].
1905 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1906 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
1909 (** [build_global_string str name b] creates a series of instructions that adds
1910 a global string at the position specified by the instruction builder [b].
1911 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1912 val build_global_string : string -> string -> llbuilder -> llvalue
1915 (** [build_global_stringptr str name b] creates a series of instructions that
1916 adds a global string pointer at the position specified by the instruction
1918 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1919 val build_global_stringptr : string -> string -> llbuilder -> llvalue
1925 (** [build_trunc v ty name b] creates a
1926 [%name = trunc %p to %ty]
1927 instruction at the position specified by the instruction builder [b].
1928 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1929 val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1932 (** [build_zext v ty name b] creates a
1933 [%name = zext %p to %ty]
1934 instruction at the position specified by the instruction builder [b].
1935 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1936 val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1939 (** [build_sext v ty name b] creates a
1940 [%name = sext %p to %ty]
1941 instruction at the position specified by the instruction builder [b].
1942 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1943 val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1946 (** [build_fptoui v ty name b] creates a
1947 [%name = fptoui %p to %ty]
1948 instruction at the position specified by the instruction builder [b].
1949 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1950 val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1953 (** [build_fptosi v ty name b] creates a
1954 [%name = fptosi %p to %ty]
1955 instruction at the position specified by the instruction builder [b].
1956 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1957 val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1960 (** [build_uitofp v ty name b] creates a
1961 [%name = uitofp %p to %ty]
1962 instruction at the position specified by the instruction builder [b].
1963 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1964 val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1967 (** [build_sitofp v ty name b] creates a
1968 [%name = sitofp %p to %ty]
1969 instruction at the position specified by the instruction builder [b].
1970 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1971 val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1974 (** [build_fptrunc v ty name b] creates a
1975 [%name = fptrunc %p to %ty]
1976 instruction at the position specified by the instruction builder [b].
1977 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1978 val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1981 (** [build_fpext v ty name b] creates a
1982 [%name = fpext %p to %ty]
1983 instruction at the position specified by the instruction builder [b].
1984 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1985 val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1988 (** [build_ptrtoint v ty name b] creates a
1989 [%name = prtotint %p to %ty]
1990 instruction at the position specified by the instruction builder [b].
1991 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1992 val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1995 (** [build_inttoptr v ty name b] creates a
1996 [%name = inttoptr %p to %ty]
1997 instruction at the position specified by the instruction builder [b].
1998 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1999 val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2002 (** [build_bitcast v ty name b] creates a
2003 [%name = bitcast %p to %ty]
2004 instruction at the position specified by the instruction builder [b].
2005 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2006 val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2009 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2010 instruction at the position specified by the instruction builder [b].
2011 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2012 val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2015 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2016 instruction at the position specified by the instruction builder [b].
2017 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2018 val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2021 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2022 instruction at the position specified by the instruction builder [b].
2023 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2024 val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2027 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2028 instruction at the position specified by the instruction builder [b].
2029 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2030 val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2033 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2034 instruction at the position specified by the instruction builder [b].
2035 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2036 val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2039 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2040 instruction at the position specified by the instruction builder [b].
2041 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2042 val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2046 (** {7 Comparisons} *)
2048 (** [build_icmp pred x y name b] creates a
2049 [%name = icmp %pred %x, %y]
2050 instruction at the position specified by the instruction builder [b].
2051 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2052 val build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2053 llbuilder -> llvalue
2055 (** [build_fcmp pred x y name b] creates a
2056 [%name = fcmp %pred %x, %y]
2057 instruction at the position specified by the instruction builder [b].
2058 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2059 val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2060 llbuilder -> llvalue
2063 (** {7 Miscellaneous instructions} *)
2065 (** [build_phi incoming name b] creates a
2066 [%name = phi %incoming]
2067 instruction at the position specified by the instruction builder [b].
2068 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2069 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2070 val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2073 (** [build_call fn args name b] creates a
2074 [%name = call %fn(args...)]
2075 instruction at the position specified by the instruction builder [b].
2076 See the method [llvm::LLVMBuilder::CreateCall]. *)
2077 val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2080 (** [build_select cond thenv elsev name b] creates a
2081 [%name = select %cond, %thenv, %elsev]
2082 instruction at the position specified by the instruction builder [b].
2083 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2084 val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2087 (** [build_va_arg valist argty name b] creates a
2088 [%name = va_arg %valist, %argty]
2089 instruction at the position specified by the instruction builder [b].
2090 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2091 val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2094 (** [build_extractelement vec i name b] creates a
2095 [%name = extractelement %vec, %i]
2096 instruction at the position specified by the instruction builder [b].
2097 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2098 val build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2101 (** [build_insertelement vec elt i name b] creates a
2102 [%name = insertelement %vec, %elt, %i]
2103 instruction at the position specified by the instruction builder [b].
2104 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2105 val build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2106 llbuilder -> llvalue
2108 (** [build_shufflevector veca vecb mask name b] creates a
2109 [%name = shufflevector %veca, %vecb, %mask]
2110 instruction at the position specified by the instruction builder [b].
2111 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2112 val build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2113 llbuilder -> llvalue
2115 (** [build_insertvalue agg idx name b] creates a
2116 [%name = extractvalue %agg, %idx]
2117 instruction at the position specified by the instruction builder [b].
2118 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2119 val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2122 (** [build_insertvalue agg val idx name b] creates a
2123 [%name = insertvalue %agg, %val, %idx]
2124 instruction at the position specified by the instruction builder [b].
2125 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2126 val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2129 (** [build_is_null val name b] creates a
2130 [%name = icmp eq %val, null]
2131 instruction at the position specified by the instruction builder [b].
2132 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2133 val build_is_null : llvalue -> string -> llbuilder -> llvalue
2136 (** [build_is_not_null val name b] creates a
2137 [%name = icmp ne %val, null]
2138 instruction at the position specified by the instruction builder [b].
2139 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2140 val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2143 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2144 the difference between two pointer values at the position specified by the
2145 instruction builder [b].
2146 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2147 val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2151 (** {6 Memory buffers} *)
2153 module MemoryBuffer : sig
2154 (** [of_file p] is the memory buffer containing the contents of the file at
2155 path [p]. If the file could not be read, then [IoError msg] is
2157 val of_file : string -> llmemorybuffer
2159 (** [stdin ()] is the memory buffer containing the contents of standard input.
2160 If standard input is empty, then [IoError msg] is raised. *)
2161 val of_stdin : unit -> llmemorybuffer
2163 (** Disposes of a memory buffer. *)
2164 val dispose : llmemorybuffer -> unit
2168 (** {6 Pass Managers} *)
2170 module PassManager : sig
2173 type any = [ `Module | `Function ]
2175 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2176 type of pipeline is suitable for link-time optimization and whole-module
2178 See the constructor of [llvm::PassManager]. *)
2179 val create : unit -> [ `Module ] t
2181 (** [PassManager.create_function m] constructs a new function-by-function
2182 pass pipeline over the module [m]. It does not take ownership of [m].
2183 This type of pipeline is suitable for code generation and JIT compilation
2185 See the constructor of [llvm::FunctionPassManager]. *)
2186 val create_function : llmodule -> [ `Function ] t
2189 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2190 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2191 any of the passes modified the module, [false] otherwise.
2192 See the [llvm::PassManager::run] method. *)
2193 val run_module : llmodule -> [ `Module ] t -> bool
2196 (** [initialize fpm] initializes all of the function passes scheduled in the
2197 function pass manager [fpm]. Returns [true] if any of the passes modified
2198 the module, [false] otherwise.
2199 See the [llvm::FunctionPassManager::doInitialization] method. *)
2200 val initialize : [ `Function ] t -> bool
2202 (** [run_function f fpm] executes all of the function passes scheduled in the
2203 function pass manager [fpm] over the function [f]. Returns [true] if any
2204 of the passes modified [f], [false] otherwise.
2205 See the [llvm::FunctionPassManager::run] method. *)
2206 val run_function : llvalue -> [ `Function ] t -> bool
2209 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2210 function pass manager [fpm]. Returns [true] if any of the passes
2211 modified the module, [false] otherwise.
2212 See the [llvm::FunctionPassManager::doFinalization] method. *)
2213 val finalize : [ `Function ] t -> bool
2215 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2217 See the destructor of [llvm::BasePassManager]. *)
2218 val dispose : [< any ] t -> unit