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