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 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *)
45 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
49 (** Used to provide a module to JIT or interpreter.
50 See the [llvm::ModuleProvider] class. *)
53 (** Used to efficiently handle large buffers of read-only binary data.
54 See the [llvm::MemoryBuffer] class. *)
57 (** The kind of an [lltype], the result of [classify_type ty]. See the
58 [llvm::Type::TypeID] enumeration. *)
78 (** The linkage of a global value, accessed with {!linkage} and
79 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
83 | Available_externally
99 (** The linker visibility of a global value, accessed with {!visibility} and
100 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
101 module Visibility : sig
108 (** The following calling convention values may be accessed with
109 {!function_call_conv} and {!set_function_call_conv}. Calling
110 conventions are open-ended. *)
111 module CallConv : sig
112 val c : int (** [c] is the C calling convention. *)
113 val fast : int (** [fast] is the calling convention to allow LLVM
114 maximum optimization opportunities. Use only with
116 val cold : int (** [cold] is the calling convention for
118 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling
119 convention from C. *)
120 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
121 convention from C. *)
124 module Attribute : sig
149 (** The predicate for an integer comparison ([icmp]) instruction.
150 See the [llvm::ICmpInst::Predicate] enumeration. *)
165 (** The predicate for a floating-point comparison ([fcmp]) instruction.
166 See the [llvm::FCmpInst::Predicate] enumeration. *)
190 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
191 of [a]. [llpos] is used to specify positions in and for forward iteration
192 through the various value lists maintained by the LLVM IR. *)
193 type ('a, 'b) llpos =
197 (** [After b] and [At_start a] specify positions from the end of the ['b] list
198 of [a]. [llrev_pos] is used for reverse iteration through the various value
199 lists maintained by the LLVM IR. *)
200 type ('a, 'b) llrev_pos =
205 (** {6 Exceptions} *)
207 exception IoError of string
212 (** [create_context ()] creates a context for storing the "global" state in
213 LLVM. See the constructor [llvm::LLVMContext]. *)
214 external create_context : unit -> llcontext = "llvm_create_context"
216 (** [destroy_context ()] destroys a context. See the destructor
217 [llvm::LLVMContext::~LLVMContext]. *)
218 external dispose_context : llcontext -> unit = "llvm_dispose_context"
220 (** See the function [llvm::getGlobalContext]. *)
221 external global_context : unit -> llcontext = "llvm_global_context"
226 (** [create_module context id] creates a module with the supplied module ID in
227 the context [context]. Modules are not garbage collected; it is mandatory
228 to call {!dispose_module} to free memory. See the constructor
229 [llvm::Module::Module]. *)
230 external create_module : llcontext -> string -> llmodule = "llvm_create_module"
232 (** [dispose_module m] destroys a module [m] and all of the IR objects it
233 contained. All references to subordinate objects are invalidated;
234 referencing them will invoke undefined behavior. See the destructor
235 [llvm::Module::~Module]. *)
236 external dispose_module : llmodule -> unit = "llvm_dispose_module"
238 (** [target_triple m] is the target specifier for the module [m], something like
239 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
240 external target_triple: llmodule -> string
241 = "llvm_target_triple"
243 (** [target_triple triple m] changes the target specifier for the module [m] to
244 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
245 external set_target_triple: string -> llmodule -> unit
246 = "llvm_set_target_triple"
248 (** [data_layout m] is the data layout specifier for the module [m], something
249 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
250 method [llvm::Module::getDataLayout]. *)
251 external data_layout: llmodule -> string
254 (** [set_data_layout s m] changes the data layout specifier for the module [m]
255 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
256 external set_data_layout: string -> llmodule -> unit
257 = "llvm_set_data_layout"
259 (** [define_type_name name ty m] adds a named type to the module's symbol table.
260 Returns [true] if successful. If such a name already exists, then no entry
261 is added and [false] is returned. See the [llvm::Module::addTypeName]
263 external define_type_name : string -> lltype -> llmodule -> bool
264 = "llvm_add_type_name"
266 (** [delete_type_name name] removes a type name from the module's symbol
268 external delete_type_name : string -> llmodule -> unit
269 = "llvm_delete_type_name"
271 (** [dump_module m] prints the .ll representation of the module [m] to standard
272 error. See the method [llvm::Module::dump]. *)
273 external dump_module : llmodule -> unit = "llvm_dump_module"
278 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
279 See the method [llvm::Type::getTypeID]. *)
280 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
282 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
283 See the method [llvm::Type::getContext]. *)
284 external type_context : lltype -> llcontext = "llvm_type_context"
286 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
287 val string_of_lltype : lltype -> string
289 (** {7 Operations on integer types} *)
291 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
292 [llvm::Type::Int1Ty]. *)
293 external i1_type : llcontext -> lltype = "llvm_i1_type"
295 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
296 [llvm::Type::Int8Ty]. *)
297 external i8_type : llcontext -> lltype = "llvm_i8_type"
299 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
300 [llvm::Type::Int16Ty]. *)
301 external i16_type : llcontext -> lltype = "llvm_i16_type"
303 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
304 [llvm::Type::Int32Ty]. *)
305 external i32_type : llcontext -> lltype = "llvm_i32_type"
307 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
308 [llvm::Type::Int64Ty]. *)
309 external i64_type : llcontext -> lltype = "llvm_i64_type"
311 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
312 [c]. See the method [llvm::IntegerType::get]. *)
313 external integer_type : llcontext -> int -> lltype = "llvm_integer_type"
315 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
316 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
317 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
320 (** {7 Operations on real types} *)
322 (** [float_type c] returns the IEEE 32-bit floating point type in the context
323 [c]. See [llvm::Type::FloatTy]. *)
324 external float_type : llcontext -> lltype = "llvm_float_type"
326 (** [double_type c] returns the IEEE 64-bit floating point type in the context
327 [c]. See [llvm::Type::DoubleTy]. *)
328 external double_type : llcontext -> lltype = "llvm_double_type"
330 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
331 [c]. See [llvm::Type::X86_FP80Ty]. *)
332 external x86fp80_type : llcontext -> lltype = "llvm_x86fp80_type"
334 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
335 [c]. See [llvm::Type::FP128Ty]. *)
336 external fp128_type : llcontext -> lltype = "llvm_fp128_type"
338 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
339 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
340 external ppc_fp128_type : llcontext -> lltype = "llvm_ppc_fp128_type"
343 (** {7 Operations on function types} *)
345 (** [function_type ret_ty param_tys] returns the function type returning
346 [ret_ty] and taking [param_tys] as parameters.
347 See the method [llvm::FunctionType::get]. *)
348 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
350 (** [va_arg_function_type ret_ty param_tys] is just like
351 [function_type ret_ty param_tys] except that it returns the function type
352 which also takes a variable number of arguments.
353 See the method [llvm::FunctionType::get]. *)
354 external var_arg_function_type : lltype -> lltype array -> lltype
355 = "llvm_var_arg_function_type"
357 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
358 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
359 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
361 (** [return_type fty] gets the return type of the function type [fty].
362 See the method [llvm::FunctionType::getReturnType]. *)
363 external return_type : lltype -> lltype = "LLVMGetReturnType"
365 (** [param_types fty] gets the parameter types of the function type [fty].
366 See the method [llvm::FunctionType::getParamType]. *)
367 external param_types : lltype -> lltype array = "llvm_param_types"
370 (** {7 Operations on struct types} *)
372 (** [struct_type context tys] returns the structure type in the context
373 [context] containing in the types in the array [tys]. See the method
374 [llvm::StructType::get]. *)
375 external struct_type : llcontext -> lltype array -> lltype
378 (** [packed_struct_type context ys] returns the packed structure type in the
379 context [context] containing in the types in the array [tys]. See the method
380 [llvm::StructType::get]. *)
381 external packed_struct_type : llcontext -> lltype array -> lltype
382 = "llvm_packed_struct_type"
384 (** [element_types sty] returns the constituent types of the struct type [sty].
385 See the method [llvm::StructType::getElementType]. *)
386 external element_types : lltype -> lltype array = "llvm_element_types"
388 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
389 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
390 external is_packed : lltype -> bool = "llvm_is_packed"
393 (** {7 Operations on pointer, vector, and array types} *)
395 (** [array_type ty n] returns the array type containing [n] elements of type
396 [ty]. See the method [llvm::ArrayType::get]. *)
397 external array_type : lltype -> int -> lltype = "llvm_array_type"
399 (** [pointer_type ty] returns the pointer type referencing objects of type
400 [ty] in the default address space (0).
401 See the method [llvm::PointerType::getUnqual]. *)
402 external pointer_type : lltype -> lltype = "llvm_pointer_type"
404 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
405 of type [ty] in address space [as].
406 See the method [llvm::PointerType::get]. *)
407 external qualified_pointer_type : lltype -> int -> lltype
408 = "llvm_qualified_pointer_type"
410 (** [vector_type ty n] returns the array type containing [n] elements of the
411 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
412 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
414 (** [element_type ty] returns the element type of the pointer, vector, or array
415 type [ty]. See the method [llvm::SequentialType::get]. *)
416 external element_type : lltype -> lltype = "LLVMGetElementType"
418 (** [element_type aty] returns the element count of the array type [aty].
419 See the method [llvm::ArrayType::getNumElements]. *)
420 external array_length : lltype -> int = "llvm_array_length"
422 (** [address_space pty] returns the address space qualifier of the pointer type
423 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
424 external address_space : lltype -> int = "llvm_address_space"
426 (** [element_type ty] returns the element count of the vector type [ty].
427 See the method [llvm::VectorType::getNumElements]. *)
428 external vector_size : lltype -> int = "llvm_vector_size"
431 (** {7 Operations on other types} *)
433 (** [opaque_type c] creates a new opaque type distinct from any other in the
434 context [c]. Opaque types are useful for building recursive types in
435 combination with {!refine_type}. See [llvm::OpaqueType::get]. *)
436 external opaque_type : llcontext -> lltype = "llvm_opaque_type"
438 (** [void_type c] creates a type of a function which does not return any
439 value in the context [c]. See [llvm::Type::VoidTy]. *)
440 external void_type : llcontext -> lltype = "llvm_void_type"
442 (** [label_type c] creates a type of a basic block in the context [c]. See
443 [llvm::Type::LabelTy]. *)
444 external label_type : llcontext -> lltype = "llvm_label_type"
446 (** {7 Operations on type handles} *)
448 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
449 refined as a result of a call to {!refine_type}, the handle will be updated;
450 any bare [lltype] references will become invalid.
451 See the class [llvm::PATypeHolder]. *)
452 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
454 (** [type_of_handle tyh] resolves the type handle [tyh].
455 See the method [llvm::PATypeHolder::get()]. *)
456 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
458 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
459 concrete type [ty] in all users. Warning: This may invalidate {!lltype}
460 values! Use {!lltypehandle} to manipulate potentially abstract types. See
461 the method [llvm::Type::refineAbstractType]. *)
462 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
467 (** [type_of v] returns the type of the value [v].
468 See the method [llvm::Value::getType]. *)
469 external type_of : llvalue -> lltype = "llvm_type_of"
471 (** [value_name v] returns the name of the value [v]. For global values, this is
472 the symbol name. For instructions and basic blocks, it is the SSA register
473 name. It is meaningless for constants.
474 See the method [llvm::Value::getName]. *)
475 external value_name : llvalue -> string = "llvm_value_name"
477 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
478 [llvm::Value::setName]. *)
479 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
481 (** [dump_value v] prints the .ll representation of the value [v] to standard
482 error. See the method [llvm::Value::dump]. *)
483 external dump_value : llvalue -> unit = "llvm_dump_value"
486 (** {7 Operations on constants of (mostly) any type} *)
488 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
489 otherwise. Similar to [llvm::isa<Constant>]. *)
490 external is_constant : llvalue -> bool = "llvm_is_constant"
492 (** [const_null ty] returns the constant null (zero) of the type [ty].
493 See the method [llvm::Constant::getNullValue]. *)
494 external const_null : lltype -> llvalue = "LLVMConstNull"
496 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
497 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
498 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
500 (** [undef ty] returns the undefined value of the type [ty].
501 See the method [llvm::UndefValue::get]. *)
502 external undef : lltype -> llvalue = "LLVMGetUndef"
504 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
505 See the method [llvm::Constant::isNullValue]. *)
506 external is_null : llvalue -> bool = "llvm_is_null"
508 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
509 otherwise. Similar to [llvm::isa<UndefValue>]. *)
510 external is_undef : llvalue -> bool = "llvm_is_undef"
513 (** {7 Operations on scalar constants} *)
515 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
516 See the method [llvm::ConstantInt::get]. *)
517 external const_int : lltype -> int -> llvalue = "llvm_const_int"
519 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
520 [i]. See the method [llvm::ConstantInt::get]. *)
521 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
522 = "llvm_const_of_int64"
524 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
525 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
526 external const_int_of_string : lltype -> string -> int -> llvalue
527 = "llvm_const_int_of_string"
529 (** [const_float ty n] returns the floating point constant of type [ty] and
530 value [n]. See the method [llvm::ConstantFP::get]. *)
531 external const_float : lltype -> float -> llvalue = "llvm_const_float"
533 (** [const_float_of_string ty s] returns the floating point constant of type
534 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
535 external const_float_of_string : lltype -> string -> llvalue
536 = "llvm_const_float_of_string"
539 (** {7 Operations on composite constants} *)
541 (** [const_string c s] returns the constant [i8] array with the values of the
542 characters in the string [s] in the context [c]. The array is not
543 null-terminated (but see {!const_stringz}). This value can in turn be used
544 as the initializer for a global variable. See the method
545 [llvm::ConstantArray::get]. *)
546 external const_string : llcontext -> string -> llvalue = "llvm_const_string"
548 (** [const_stringz c s] returns the constant [i8] array with the values of the
549 characters in the string [s] and a null terminator in the context [c]. This
550 value can in turn be used as the initializer for a global variable.
551 See the method [llvm::ConstantArray::get]. *)
552 external const_stringz : llcontext -> string -> llvalue = "llvm_const_stringz"
554 (** [const_array ty elts] returns the constant array of type
555 [array_type ty (Array.length elts)] and containing the values [elts].
556 This value can in turn be used as the initializer for a global variable.
557 See the method [llvm::ConstantArray::get]. *)
558 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
560 (** [const_struct context elts] returns the structured constant of type
561 [struct_type (Array.map type_of elts)] and containing the values [elts]
562 in the context [context]. This value can in turn be used as the initializer
563 for a global variable. See the method [llvm::ConstantStruct::get]. *)
564 external const_struct : llcontext -> llvalue array -> llvalue
565 = "llvm_const_struct"
567 (** [const_packed_struct context elts] returns the structured constant of
568 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
569 values [elts] in the context [context]. This value can in turn be used as
570 the initializer for a global variable. See the method
571 [llvm::ConstantStruct::get]. *)
572 external const_packed_struct : llcontext -> llvalue array -> llvalue
573 = "llvm_const_packed_struct"
575 (** [const_vector elts] returns the vector constant of type
576 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
577 values [elts]. See the method [llvm::ConstantVector::get]. *)
578 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
581 (** {7 Constant expressions} *)
583 (** [align_of ty] returns the alignof constant for the type [ty]. This is
584 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
585 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
586 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
587 external align_of : lltype -> llvalue = "LLVMAlignOf"
589 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
590 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
591 (const_int i32_type 1)) i64_type], but considerably more readable.
592 See the method [llvm::ConstantExpr::getSizeOf]. *)
593 external size_of : lltype -> llvalue = "LLVMSizeOf"
595 (** [const_neg c] returns the arithmetic negation of the constant [c].
596 See the method [llvm::ConstantExpr::getNeg]. *)
597 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
599 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
600 See the method [llvm::ConstantExpr::getFNeg]. *)
601 external const_fneg : llvalue -> llvalue = "LLVMConstFNeg"
603 (** [const_not c] returns the bitwise inverse of the constant [c].
604 See the method [llvm::ConstantExpr::getNot]. *)
605 external const_not : llvalue -> llvalue = "LLVMConstNot"
607 (** [const_add c1 c2] returns the constant sum of two constants.
608 See the method [llvm::ConstantExpr::getAdd]. *)
609 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
611 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
612 signed wrapping. The result is undefined if the sum overflows.
613 See the method [llvm::ConstantExpr::getNSWAdd]. *)
614 external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd"
616 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
617 See the method [llvm::ConstantExpr::getFAdd]. *)
618 external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd"
620 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
621 constants. See the method [llvm::ConstantExpr::getSub]. *)
622 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
624 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
625 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
626 external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub"
628 (** [const_mul c1 c2] returns the constant product of two constants.
629 See the method [llvm::ConstantExpr::getMul]. *)
630 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
632 (** [const_fmul c1 c2] returns the constant product of two constants floats.
633 See the method [llvm::ConstantExpr::getFMul]. *)
634 external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul"
636 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
638 See the method [llvm::ConstantExpr::getUDiv]. *)
639 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
641 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
643 See the method [llvm::ConstantExpr::getSDiv]. *)
644 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
646 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
647 signed integer constants. The result is undefined if the result is rounded
648 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
649 external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv"
651 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
653 See the method [llvm::ConstantExpr::getFDiv]. *)
654 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
656 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
657 unsigned integer constants.
658 See the method [llvm::ConstantExpr::getURem]. *)
659 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
661 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
662 signed integer constants.
663 See the method [llvm::ConstantExpr::getSRem]. *)
664 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
666 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
667 signed floating point constants.
668 See the method [llvm::ConstantExpr::getFRem]. *)
669 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
671 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
673 See the method [llvm::ConstantExpr::getAnd]. *)
674 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
676 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
678 See the method [llvm::ConstantExpr::getOr]. *)
679 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
681 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
683 See the method [llvm::ConstantExpr::getXor]. *)
684 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
686 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
687 constants, [c1 pred c2].
688 See the method [llvm::ConstantExpr::getICmp]. *)
689 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
692 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
693 point constants, [c1 pred c2].
694 See the method [llvm::ConstantExpr::getFCmp]. *)
695 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
698 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
699 constant integer [c2].
700 See the method [llvm::ConstantExpr::getShl]. *)
701 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
703 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
704 constant integer [c2] with zero extension.
705 See the method [llvm::ConstantExpr::getLShr]. *)
706 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
708 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
709 constant integer [c2] with sign extension.
710 See the method [llvm::ConstantExpr::getAShr]. *)
711 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
713 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
714 constant integers indices from the array [indices].
715 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
716 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
718 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
719 with the constant integers indices from the array [indices].
720 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
721 external const_in_bounds_gep : llvalue -> llvalue array -> llvalue
722 = "llvm_const_in_bounds_gep"
724 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
725 to the smaller integer type [ty].
726 See the method [llvm::ConstantExpr::getTrunc]. *)
727 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
729 (** [const_sext c ty] returns the constant sign extension of integer constant
730 [c] to the larger integer type [ty].
731 See the method [llvm::ConstantExpr::getSExt]. *)
732 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
734 (** [const_zext c ty] returns the constant zero extension of integer constant
735 [c] to the larger integer type [ty].
736 See the method [llvm::ConstantExpr::getZExt]. *)
737 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
739 (** [const_fptrunc c ty] returns the constant truncation of floating point
740 constant [c] to the smaller floating point type [ty].
741 See the method [llvm::ConstantExpr::getFPTrunc]. *)
742 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
744 (** [const_fpext c ty] returns the constant extension of floating point constant
745 [c] to the larger floating point type [ty].
746 See the method [llvm::ConstantExpr::getFPExt]. *)
747 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
749 (** [const_uitofp c ty] returns the constant floating point conversion of
750 unsigned integer constant [c] to the floating point type [ty].
751 See the method [llvm::ConstantExpr::getUIToFP]. *)
752 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
754 (** [const_sitofp c ty] returns the constant floating point conversion of
755 signed integer constant [c] to the floating point type [ty].
756 See the method [llvm::ConstantExpr::getSIToFP]. *)
757 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
759 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
760 floating point constant [c] to integer type [ty].
761 See the method [llvm::ConstantExpr::getFPToUI]. *)
762 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
764 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
765 floating point constant [c] to integer type [ty].
766 See the method [llvm::ConstantExpr::getFPToSI]. *)
767 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
769 (** [const_ptrtoint c ty] returns the constant integer conversion of
770 pointer constant [c] to integer type [ty].
771 See the method [llvm::ConstantExpr::getPtrToInt]. *)
772 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
774 (** [const_inttoptr c ty] returns the constant pointer conversion of
775 integer constant [c] to pointer type [ty].
776 See the method [llvm::ConstantExpr::getIntToPtr]. *)
777 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
779 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
780 to type [ty] of equal size.
781 See the method [llvm::ConstantExpr::getBitCast]. *)
782 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
784 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
785 conversion of constant [c] to type [ty].
786 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
787 external const_zext_or_bitcast : llvalue -> lltype -> llvalue
788 = "LLVMConstZExtOrBitCast"
790 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
791 conversion of constant [c] to type [ty].
792 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
793 external const_sext_or_bitcast : llvalue -> lltype -> llvalue
794 = "LLVMConstSExtOrBitCast"
796 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
797 conversion of constant [c] to type [ty].
798 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
799 external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
800 = "LLVMConstTruncOrBitCast"
802 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
803 cast conversion of constant [c] to type [ty] of equal size.
804 See the method [llvm::ConstantExpr::getPointerCast]. *)
805 external const_pointercast : llvalue -> lltype -> llvalue
806 = "LLVMConstPointerCast"
808 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
809 -> integer casts of constant [c] to type [ty].
810 See the method [llvm::ConstantExpr::getIntCast]. *)
811 external const_intcast : llvalue -> lltype -> llvalue
814 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
815 fp casts of constant [c] to type [ty].
816 See the method [llvm::ConstantExpr::getFPCast]. *)
817 external const_fpcast : llvalue -> lltype -> llvalue
820 (** [const_select cond t f] returns the constant conditional which returns value
821 [t] if the boolean constant [cond] is true and the value [f] otherwise.
822 See the method [llvm::ConstantExpr::getSelect]. *)
823 external const_select : llvalue -> llvalue -> llvalue -> llvalue
826 (** [const_extractelement vec i] returns the constant [i]th element of
827 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
828 the size of the vector.
829 See the method [llvm::ConstantExpr::getExtractElement]. *)
830 external const_extractelement : llvalue -> llvalue -> llvalue
831 = "LLVMConstExtractElement"
833 (** [const_insertelement vec v i] returns the constant vector with the same
834 elements as constant vector [v] but the [i]th element replaced by the
835 constant [v]. [v] must be a constant value with the type of the vector
836 elements. [i] must be a constant [i32] value unsigned less than the size
838 See the method [llvm::ConstantExpr::getInsertElement]. *)
839 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
840 = "LLVMConstInsertElement"
842 (** [const_shufflevector a b mask] returns a constant [shufflevector].
843 See the LLVM Language Reference for details on the [sufflevector]
845 See the method [llvm::ConstantExpr::getShuffleVector]. *)
846 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
847 = "LLVMConstShuffleVector"
849 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
850 constant aggregate [agg]. Each [idxs] must be less than the size of the
851 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
852 external const_extractvalue : llvalue -> int array -> llvalue
853 = "llvm_const_extractvalue"
855 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
856 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
857 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
858 external const_insertvalue : llvalue -> llvalue -> int array -> llvalue
859 = "llvm_const_insertvalue"
862 (** {7 Operations on global variables, functions, and aliases (globals)} *)
864 (** [global_parent g] is the enclosing module of the global value [g].
865 See the method [llvm::GlobalValue::getParent]. *)
866 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
868 (** [is_declaration g] returns [true] if the global value [g] is a declaration
869 only. Returns [false] otherwise.
870 See the method [llvm::GlobalValue::isDeclaration]. *)
871 external is_declaration : llvalue -> bool = "llvm_is_declaration"
873 (** [linkage g] returns the linkage of the global value [g].
874 See the method [llvm::GlobalValue::getLinkage]. *)
875 external linkage : llvalue -> Linkage.t = "llvm_linkage"
877 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
878 See the method [llvm::GlobalValue::setLinkage]. *)
879 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
881 (** [section g] returns the linker section of the global value [g].
882 See the method [llvm::GlobalValue::getSection]. *)
883 external section : llvalue -> string = "llvm_section"
885 (** [set_section s g] sets the linker section of the global value [g] to [s].
886 See the method [llvm::GlobalValue::setSection]. *)
887 external set_section : string -> llvalue -> unit = "llvm_set_section"
889 (** [visibility g] returns the linker visibility of the global value [g].
890 See the method [llvm::GlobalValue::getVisibility]. *)
891 external visibility : llvalue -> Visibility.t = "llvm_visibility"
893 (** [set_visibility v g] sets the linker visibility of the global value [g] to
894 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
895 external set_visibility : Visibility.t -> llvalue -> unit
896 = "llvm_set_visibility"
898 (** [alignment g] returns the required alignment of the global value [g].
899 See the method [llvm::GlobalValue::getAlignment]. *)
900 external alignment : llvalue -> int = "llvm_alignment"
902 (** [set_alignment n g] sets the required alignment of the global value [g] to
903 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
904 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
907 (** {7 Operations on global variables} *)
909 (** [declare_global ty name m] returns a new global variable of type [ty] and
910 with name [name] in module [m]. If such a global variable already exists,
911 it is returned. If the type of the existing global differs, then a bitcast
912 to [ty] is returned. *)
913 external declare_global : lltype -> string -> llmodule -> llvalue
914 = "llvm_declare_global"
916 (** [define_global name init m] returns a new global with name [name] and
917 initializer [init] in module [m]. If the named global already exists, it is
919 See the constructor of [llvm::GlobalVariable]. *)
920 external define_global : string -> llvalue -> llmodule -> llvalue
921 = "llvm_define_global"
923 (** [lookup_global name m] returns [Some g] if a global variable with name
924 [name] exists in module [m]. If no such global exists, returns [None].
925 See the [llvm::GlobalVariable] constructor. *)
926 external lookup_global : string -> llmodule -> llvalue option
927 = "llvm_lookup_global"
929 (** [delete_global gv] destroys the global variable [gv].
930 See the method [llvm::GlobalVariable::eraseFromParent]. *)
931 external delete_global : llvalue -> unit = "llvm_delete_global"
933 (** [global_begin m] returns the first position in the global variable list of
934 the module [m]. [global_begin] and [global_succ] can be used to iterate
935 over the global list in order.
936 See the method [llvm::Module::global_begin]. *)
937 external global_begin : llmodule -> (llmodule, llvalue) llpos
938 = "llvm_global_begin"
940 (** [global_succ gv] returns the global variable list position succeeding
942 See the method [llvm::Module::global_iterator::operator++]. *)
943 external global_succ : llvalue -> (llmodule, llvalue) llpos
946 (** [iter_globals f m] applies function [f] to each of the global variables of
947 module [m] in order. Tail recursive. *)
948 val iter_globals : (llvalue -> unit) -> llmodule -> unit
950 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
951 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
952 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
954 (** [global_end m] returns the last position in the global variable list of the
955 module [m]. [global_end] and [global_pred] can be used to iterate over the
956 global list in reverse.
957 See the method [llvm::Module::global_end]. *)
958 external global_end : llmodule -> (llmodule, llvalue) llrev_pos
961 (** [global_pred gv] returns the global variable list position preceding
963 See the method [llvm::Module::global_iterator::operator--]. *)
964 external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
967 (** [rev_iter_globals f m] applies function [f] to each of the global variables
968 of module [m] in reverse order. Tail recursive. *)
969 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
971 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
972 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
973 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
975 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
976 constant. Returns [false] otherwise.
977 See the method [llvm::GlobalVariable::isConstant]. *)
978 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
980 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
981 [c] is [true] and not if [c] is [false].
982 See the method [llvm::GlobalVariable::setConstant]. *)
983 external set_global_constant : bool -> llvalue -> unit
984 = "llvm_set_global_constant"
986 (** [global_initializer gv] returns the initializer for the global variable
987 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
988 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
990 (** [set_initializer c gv] sets the initializer for the global variable
991 [gv] to the constant [c].
992 See the method [llvm::GlobalVariable::setInitializer]. *)
993 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
995 (** [remove_initializer gv] unsets the initializer for the global variable
997 See the method [llvm::GlobalVariable::setInitializer]. *)
998 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
1000 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1001 thread-local and [false] otherwise.
1002 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1003 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
1005 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1006 [c] is [true] and not otherwise.
1007 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1008 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
1011 (** {7 Operations on functions} *)
1013 (** [declare_function name ty m] returns a new function of type [ty] and
1014 with name [name] in module [m]. If such a function already exists,
1015 it is returned. If the type of the existing function differs, then a bitcast
1016 to [ty] is returned. *)
1017 external declare_function : string -> lltype -> llmodule -> llvalue
1018 = "llvm_declare_function"
1020 (** [define_function name ty m] creates a new function with name [name] and
1021 type [ty] in module [m]. If the named function already exists, it is
1022 renamed. An entry basic block is created in the function.
1023 See the constructor of [llvm::GlobalVariable]. *)
1024 external define_function : string -> lltype -> llmodule -> llvalue
1025 = "llvm_define_function"
1027 (** [lookup_function name m] returns [Some f] if a function with name
1028 [name] exists in module [m]. If no such function exists, returns [None].
1029 See the method [llvm::Module] constructor. *)
1030 external lookup_function : string -> llmodule -> llvalue option
1031 = "llvm_lookup_function"
1033 (** [delete_function f] destroys the function [f].
1034 See the method [llvm::Function::eraseFromParent]. *)
1035 external delete_function : llvalue -> unit = "llvm_delete_function"
1037 (** [function_begin m] returns the first position in the function list of the
1038 module [m]. [function_begin] and [function_succ] can be used to iterate over
1039 the function list in order.
1040 See the method [llvm::Module::begin]. *)
1041 external function_begin : llmodule -> (llmodule, llvalue) llpos
1042 = "llvm_function_begin"
1044 (** [function_succ gv] returns the function list position succeeding
1046 See the method [llvm::Module::iterator::operator++]. *)
1047 external function_succ : llvalue -> (llmodule, llvalue) llpos
1048 = "llvm_function_succ"
1050 (** [iter_functions f m] applies function [f] to each of the functions of module
1051 [m] in order. Tail recursive. *)
1052 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1054 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1055 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1056 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1058 (** [function_end m] returns the last position in the function list of
1059 the module [m]. [function_end] and [function_pred] can be used to iterate
1060 over the function list in reverse.
1061 See the method [llvm::Module::end]. *)
1062 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
1063 = "llvm_function_end"
1065 (** [function_pred gv] returns the function list position preceding [After gv].
1066 See the method [llvm::Module::iterator::operator--]. *)
1067 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1068 = "llvm_function_pred"
1070 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1071 module [m] in reverse order. Tail recursive. *)
1072 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1074 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1075 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1076 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1078 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1079 See the method [llvm::Function::isIntrinsic]. *)
1080 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
1082 (** [function_call_conv f] returns the calling convention of the function [f].
1083 See the method [llvm::Function::getCallingConv]. *)
1084 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
1086 (** [set_function_call_conv cc f] sets the calling convention of the function
1087 [f] to the calling convention numbered [cc].
1088 See the method [llvm::Function::setCallingConv]. *)
1089 external set_function_call_conv : int -> llvalue -> unit
1090 = "llvm_set_function_call_conv"
1092 (** [gc f] returns [Some name] if the function [f] has a garbage
1093 collection algorithm specified and [None] otherwise.
1094 See the method [llvm::Function::getGC]. *)
1095 external gc : llvalue -> string option = "llvm_gc"
1097 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1098 [gc]. See the method [llvm::Function::setGC]. *)
1099 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
1101 (** [add_function_attr f a] adds attribute [a] to the return type of function
1103 external add_function_attr : llvalue -> Attribute.t -> unit
1104 = "llvm_add_function_attr"
1106 (** [remove_function_attr f a] removes attribute [a] from the return type of
1108 external remove_function_attr : llvalue -> Attribute.t -> unit
1109 = "llvm_remove_function_attr"
1111 (** {7 Operations on params} *)
1113 (** [params f] returns the parameters of function [f].
1114 See the method [llvm::Function::getArgumentList]. *)
1115 external params : llvalue -> llvalue array = "llvm_params"
1117 (** [param f n] returns the [n]th parameter of function [f].
1118 See the method [llvm::Function::getArgumentList]. *)
1119 external param : llvalue -> int -> llvalue = "llvm_param"
1121 (** [param_parent p] returns the parent function that owns the parameter.
1122 See the method [llvm::Argument::getParent]. *)
1123 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
1125 (** [param_begin f] returns the first position in the parameter list of the
1126 function [f]. [param_begin] and [param_succ] can be used to iterate over
1127 the parameter list in order.
1128 See the method [llvm::Function::arg_begin]. *)
1129 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
1131 (** [param_succ bb] returns the parameter list position succeeding
1133 See the method [llvm::Function::arg_iterator::operator++]. *)
1134 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
1136 (** [iter_params f fn] applies function [f] to each of the parameters
1137 of function [fn] in order. Tail recursive. *)
1138 val iter_params : (llvalue -> unit) -> llvalue -> unit
1140 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1141 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1142 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1144 (** [param_end f] returns the last position in the parameter list of
1145 the function [f]. [param_end] and [param_pred] can be used to iterate
1146 over the parameter list in reverse.
1147 See the method [llvm::Function::arg_end]. *)
1148 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
1150 (** [param_pred gv] returns the function list position preceding [After gv].
1151 See the method [llvm::Function::arg_iterator::operator--]. *)
1152 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1155 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1156 of function [fn] in reverse order. Tail recursive. *)
1157 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1159 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1160 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1161 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1163 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1164 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1166 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1167 external remove_param_attr : llvalue -> Attribute.t -> unit
1168 = "llvm_remove_param_attr"
1170 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1171 external set_param_alignment : llvalue -> int -> unit
1172 = "llvm_set_param_alignment"
1174 (** {7 Operations on basic blocks} *)
1176 (** [basic_blocks fn] returns the basic blocks of the function [f].
1177 See the method [llvm::Function::getBasicBlockList]. *)
1178 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
1180 (** [entry_block fn] returns the entry basic block of the function [f].
1181 See the method [llvm::Function::getEntryBlock]. *)
1182 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1184 (** [delete_block bb] deletes the basic block [bb].
1185 See the method [llvm::BasicBlock::eraseFromParent]. *)
1186 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1188 (** [append_block c name f] creates a new basic block named [name] at the end of
1189 function [f] in the context [c].
1190 See the constructor of [llvm::BasicBlock]. *)
1191 external append_block : llcontext -> string -> llvalue -> llbasicblock
1192 = "llvm_append_block"
1194 (** [insert_block c name bb] creates a new basic block named [name] before the
1195 basic block [bb] in the context [c].
1196 See the constructor of [llvm::BasicBlock]. *)
1197 external insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1198 = "llvm_insert_block"
1200 (** [block_parent bb] returns the parent function that owns the basic block.
1201 See the method [llvm::BasicBlock::getParent]. *)
1202 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1204 (** [block_begin f] returns the first position in the basic block list of the
1205 function [f]. [block_begin] and [block_succ] can be used to iterate over
1206 the basic block list in order.
1207 See the method [llvm::Function::begin]. *)
1208 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1209 = "llvm_block_begin"
1211 (** [block_succ bb] returns the basic block list position succeeding
1213 See the method [llvm::Function::iterator::operator++]. *)
1214 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1217 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1218 of function [fn] in order. Tail recursive. *)
1219 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1221 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1222 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1223 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1225 (** [block_end f] returns the last position in the basic block list of
1226 the function [f]. [block_end] and [block_pred] can be used to iterate
1227 over the basic block list in reverse.
1228 See the method [llvm::Function::end]. *)
1229 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1232 (** [block_pred gv] returns the function list position preceding [After gv].
1233 See the method [llvm::Function::iterator::operator--]. *)
1234 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1237 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1238 of function [fn] in reverse order. Tail recursive. *)
1239 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1241 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1242 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1243 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1245 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1246 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1248 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1250 Similar to [llvm::isa<BasicBlock>]. *)
1251 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1253 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1254 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1257 (** {7 Operations on instructions} *)
1259 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1260 See the method [llvm::Instruction::getParent]. *)
1261 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1263 (** [instr_begin bb] returns the first position in the instruction list of the
1264 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1265 the instruction list in order.
1266 See the method [llvm::BasicBlock::begin]. *)
1267 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1268 = "llvm_instr_begin"
1270 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1271 See the method [llvm::BasicBlock::iterator::operator++]. *)
1272 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1275 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1276 block [bb] in order. Tail recursive. *)
1277 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1279 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1280 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1281 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1283 (** [instr_end bb] returns the last position in the instruction list of the
1284 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1285 the instruction list in reverse.
1286 See the method [llvm::BasicBlock::end]. *)
1287 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1290 (** [instr_pred i] returns the instruction list position preceding [After i].
1291 See the method [llvm::BasicBlock::iterator::operator--]. *)
1292 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1295 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1296 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1297 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1300 (** {7 Operations on call sites} *)
1302 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1303 instruction [ci], which may be one of the values from the module
1304 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1305 [llvm::InvokeInst::getCallingConv]. *)
1306 external instruction_call_conv: llvalue -> int
1307 = "llvm_instruction_call_conv"
1309 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1310 or invoke instruction [ci] to the integer [cc], which can be one of the
1311 values from the module {!CallConv}.
1312 See the method [llvm::CallInst::setCallingConv]
1313 and [llvm::InvokeInst::setCallingConv]. *)
1314 external set_instruction_call_conv: int -> llvalue -> unit
1315 = "llvm_set_instruction_call_conv"
1317 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1318 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1320 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1321 = "llvm_add_instruction_param_attr"
1323 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1324 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1326 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1327 = "llvm_remove_instruction_param_attr"
1329 (** {Operations on call instructions (only)} *)
1331 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1332 eligible for tail call optimization, [false] otherwise.
1333 See the method [llvm::CallInst::isTailCall]. *)
1334 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
1336 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1337 call optimization if [tc] is [true], clears otherwise.
1338 See the method [llvm::CallInst::setTailCall]. *)
1339 external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call"
1341 (** {7 Operations on phi nodes} *)
1343 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1344 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1345 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1346 = "llvm_add_incoming"
1348 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1349 See the method [llvm::PHINode::getIncomingValue]. *)
1350 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1354 (** {6 Instruction builders} *)
1356 (** [builder context] creates an instruction builder with no position in
1357 the context [context]. It is invalid to use this builder until its position
1358 is set with {!position_before} or {!position_at_end}. See the constructor
1359 for [llvm::LLVMBuilder]. *)
1360 external builder : llcontext -> llbuilder = "llvm_builder"
1362 (** [builder_at ip] creates an instruction builder positioned at [ip].
1363 See the constructor for [llvm::LLVMBuilder]. *)
1364 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1366 (** [builder_before ins] creates an instruction builder positioned before the
1367 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1368 val builder_before : llcontext -> llvalue -> llbuilder
1370 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1371 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1372 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1374 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1376 See the constructor for [llvm::LLVMBuilder]. *)
1377 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1378 = "llvm_position_builder"
1380 (** [position_before ins b] moves the instruction builder [b] to before the
1381 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1382 val position_before : llvalue -> llbuilder -> unit
1384 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1385 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1386 val position_at_end : llbasicblock -> llbuilder -> unit
1388 (** [insertion_block b] returns the basic block that the builder [b] is
1389 positioned to insert into. Raises [Not_Found] if the instruction builder is
1391 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1392 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1394 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1395 position specified by the instruction builder [b].
1396 See the method [llvm::LLVMBuilder::Insert]. *)
1397 external insert_into_builder : llvalue -> string -> llbuilder -> unit
1398 = "llvm_insert_into_builder"
1401 (** {7 Terminators} *)
1403 (** [build_ret_void b] creates a
1405 instruction at the position specified by the instruction builder [b].
1406 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1407 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1409 (** [build_ret v b] creates a
1411 instruction at the position specified by the instruction builder [b].
1412 See the method [llvm::LLVMBuilder::CreateRet]. *)
1413 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1415 (** [build_aggregate_ret vs b] creates a
1416 [ret {...} { %v1, %v2, ... } ]
1417 instruction at the position specified by the instruction builder [b].
1418 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1419 external build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1420 = "llvm_build_aggregate_ret"
1422 (** [build_br bb b] creates a
1424 instruction at the position specified by the instruction builder [b].
1425 See the method [llvm::LLVMBuilder::CreateBr]. *)
1426 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1428 (** [build_cond_br cond tbb fbb b] creates a
1429 [br %cond, %tbb, %fbb]
1430 instruction at the position specified by the instruction builder [b].
1431 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1432 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1433 llvalue = "llvm_build_cond_br"
1435 (** [build_switch case elsebb count b] creates an empty
1436 [switch %case, %elsebb]
1437 instruction at the position specified by the instruction builder [b] with
1438 space reserved for [count] cases.
1439 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1440 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1441 = "llvm_build_switch"
1443 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1444 when its input matches the constant [onval].
1445 See the method [llvm::SwitchInst::addCase]. **)
1446 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1449 (** [build_invoke fn args tobb unwindbb name b] creates an
1450 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1451 instruction at the position specified by the instruction builder [b].
1452 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1453 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1454 llbasicblock -> string -> llbuilder -> llvalue
1455 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1457 (** [build_unwind b] creates an
1459 instruction at the position specified by the instruction builder [b].
1460 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1461 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1463 (** [build_unreachable b] creates an
1465 instruction at the position specified by the instruction builder [b].
1466 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1467 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1470 (** {7 Arithmetic} *)
1472 (** [build_add x y name b] creates a
1473 [%name = add %x, %y]
1474 instruction at the position specified by the instruction builder [b].
1475 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1476 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1479 (** [build_nsw_add x y name b] creates a
1480 [%name = nsw add %x, %y]
1481 instruction at the position specified by the instruction builder [b].
1482 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1483 external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1484 = "llvm_build_nsw_add"
1486 (** [build_fadd x y name b] creates a
1487 [%name = fadd %x, %y]
1488 instruction at the position specified by the instruction builder [b].
1489 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1490 external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1493 (** [build_sub x y name b] creates a
1494 [%name = sub %x, %y]
1495 instruction at the position specified by the instruction builder [b].
1496 See the method [llvm::LLVMBuilder::CreateSub]. *)
1497 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1500 (** [build_fsub x y name b] creates a
1501 [%name = fsub %x, %y]
1502 instruction at the position specified by the instruction builder [b].
1503 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1504 external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1507 (** [build_mul x y name b] creates a
1508 [%name = mul %x, %y]
1509 instruction at the position specified by the instruction builder [b].
1510 See the method [llvm::LLVMBuilder::CreateMul]. *)
1511 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1514 (** [build_fmul x y name b] creates a
1515 [%name = fmul %x, %y]
1516 instruction at the position specified by the instruction builder [b].
1517 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1518 external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1521 (** [build_udiv x y name b] creates a
1522 [%name = udiv %x, %y]
1523 instruction at the position specified by the instruction builder [b].
1524 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1525 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1528 (** [build_sdiv x y name b] creates a
1529 [%name = sdiv %x, %y]
1530 instruction at the position specified by the instruction builder [b].
1531 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1532 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1535 (** [build_exact_sdiv x y name b] creates a
1536 [%name = exact sdiv %x, %y]
1537 instruction at the position specified by the instruction builder [b].
1538 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1539 external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1540 = "llvm_build_exact_sdiv"
1542 (** [build_fdiv x y name b] creates a
1543 [%name = fdiv %x, %y]
1544 instruction at the position specified by the instruction builder [b].
1545 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1546 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1549 (** [build_urem x y name b] creates a
1550 [%name = urem %x, %y]
1551 instruction at the position specified by the instruction builder [b].
1552 See the method [llvm::LLVMBuilder::CreateURem]. *)
1553 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1556 (** [build_SRem x y name b] creates a
1557 [%name = srem %x, %y]
1558 instruction at the position specified by the instruction builder [b].
1559 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1560 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1563 (** [build_frem x y name b] creates a
1564 [%name = frem %x, %y]
1565 instruction at the position specified by the instruction builder [b].
1566 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1567 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1570 (** [build_shl x y name b] creates a
1571 [%name = shl %x, %y]
1572 instruction at the position specified by the instruction builder [b].
1573 See the method [llvm::LLVMBuilder::CreateShl]. *)
1574 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1577 (** [build_lshr x y name b] creates a
1578 [%name = lshr %x, %y]
1579 instruction at the position specified by the instruction builder [b].
1580 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1581 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1584 (** [build_ashr x y name b] creates a
1585 [%name = ashr %x, %y]
1586 instruction at the position specified by the instruction builder [b].
1587 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1588 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1591 (** [build_and x y name b] creates a
1592 [%name = and %x, %y]
1593 instruction at the position specified by the instruction builder [b].
1594 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1595 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1598 (** [build_or x y name b] creates a
1600 instruction at the position specified by the instruction builder [b].
1601 See the method [llvm::LLVMBuilder::CreateOr]. *)
1602 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1605 (** [build_xor x y name b] creates a
1606 [%name = xor %x, %y]
1607 instruction at the position specified by the instruction builder [b].
1608 See the method [llvm::LLVMBuilder::CreateXor]. *)
1609 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1612 (** [build_neg x name b] creates a
1614 instruction at the position specified by the instruction builder [b].
1615 [-0.0] is used for floating point types to compute the correct sign.
1616 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1617 external build_neg : llvalue -> string -> llbuilder -> llvalue
1620 (** [build_xor x name b] creates a
1621 [%name = xor %x, -1]
1622 instruction at the position specified by the instruction builder [b].
1623 [-1] is the correct "all ones" value for the type of [x].
1624 See the method [llvm::LLVMBuilder::CreateXor]. *)
1625 external build_not : llvalue -> string -> llbuilder -> llvalue
1631 (** [build_alloca ty name b] creates a
1632 [%name = alloca %ty]
1633 instruction at the position specified by the instruction builder [b].
1634 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1635 external build_alloca : lltype -> string -> llbuilder -> llvalue
1636 = "llvm_build_alloca"
1638 (** [build_array_alloca ty n name b] creates a
1639 [%name = alloca %ty, %n]
1640 instruction at the position specified by the instruction builder [b].
1641 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1642 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1643 llvalue = "llvm_build_array_alloca"
1645 (** [build_load v name b] creates a
1647 instruction at the position specified by the instruction builder [b].
1648 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1649 external build_load : llvalue -> string -> llbuilder -> llvalue
1652 (** [build_store v p b] creates a
1654 instruction at the position specified by the instruction builder [b].
1655 See the method [llvm::LLVMBuilder::CreateStore]. *)
1656 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1657 = "llvm_build_store"
1659 (** [build_gep p indices name b] creates a
1660 [%name = getelementptr %p, indices...]
1661 instruction at the position specified by the instruction builder [b].
1662 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1663 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1666 (** [build_in_bounds_gep p indices name b] creates a
1667 [%name = gelementptr inbounds %p, indices...]
1668 instruction at the position specified by the instruction builder [b].
1669 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1670 external build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1671 llvalue = "llvm_build_in_bounds_gep"
1673 (** [build_struct_gep p idx name b] creates a
1674 [%name = getelementptr %p, 0, idx]
1675 instruction at the position specified by the instruction builder [b].
1676 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1677 external build_struct_gep : llvalue -> int -> string -> llbuilder ->
1678 llvalue = "llvm_build_struct_gep"
1680 (** [build_global_string str name b] creates a series of instructions that adds
1681 a global string at the position specified by the instruction builder [b].
1682 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1683 external build_global_string : string -> string -> llbuilder -> llvalue
1684 = "llvm_build_global_string"
1686 (** [build_global_stringptr str name b] creates a series of instructions that
1687 adds a global string pointer at the position specified by the instruction
1689 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1690 external build_global_stringptr : string -> string -> llbuilder -> llvalue
1691 = "llvm_build_global_stringptr"
1696 (** [build_trunc v ty name b] creates a
1697 [%name = trunc %p to %ty]
1698 instruction at the position specified by the instruction builder [b].
1699 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1700 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1701 = "llvm_build_trunc"
1703 (** [build_zext v ty name b] creates a
1704 [%name = zext %p to %ty]
1705 instruction at the position specified by the instruction builder [b].
1706 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1707 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1710 (** [build_sext v ty name b] creates a
1711 [%name = sext %p to %ty]
1712 instruction at the position specified by the instruction builder [b].
1713 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1714 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1717 (** [build_fptoui v ty name b] creates a
1718 [%name = fptoui %p to %ty]
1719 instruction at the position specified by the instruction builder [b].
1720 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1721 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1722 = "llvm_build_fptoui"
1724 (** [build_fptosi v ty name b] creates a
1725 [%name = fptosi %p to %ty]
1726 instruction at the position specified by the instruction builder [b].
1727 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1728 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1729 = "llvm_build_fptosi"
1731 (** [build_uitofp v ty name b] creates a
1732 [%name = uitofp %p to %ty]
1733 instruction at the position specified by the instruction builder [b].
1734 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1735 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1736 = "llvm_build_uitofp"
1738 (** [build_sitofp v ty name b] creates a
1739 [%name = sitofp %p to %ty]
1740 instruction at the position specified by the instruction builder [b].
1741 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1742 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1743 = "llvm_build_sitofp"
1745 (** [build_fptrunc v ty name b] creates a
1746 [%name = fptrunc %p to %ty]
1747 instruction at the position specified by the instruction builder [b].
1748 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1749 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1750 = "llvm_build_fptrunc"
1752 (** [build_fpext v ty name b] creates a
1753 [%name = fpext %p to %ty]
1754 instruction at the position specified by the instruction builder [b].
1755 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1756 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1757 = "llvm_build_fpext"
1759 (** [build_ptrtoint v ty name b] creates a
1760 [%name = prtotint %p to %ty]
1761 instruction at the position specified by the instruction builder [b].
1762 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1763 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1764 = "llvm_build_prttoint"
1766 (** [build_inttoptr v ty name b] creates a
1767 [%name = inttoptr %p to %ty]
1768 instruction at the position specified by the instruction builder [b].
1769 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1770 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1771 = "llvm_build_inttoptr"
1773 (** [build_bitcast v ty name b] creates a
1774 [%name = bitcast %p to %ty]
1775 instruction at the position specified by the instruction builder [b].
1776 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
1777 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1778 = "llvm_build_bitcast"
1780 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
1781 instruction at the position specified by the instruction builder [b].
1782 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1783 external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1784 llvalue = "llvm_build_zext_or_bitcast"
1786 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
1787 instruction at the position specified by the instruction builder [b].
1788 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
1789 external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1790 llvalue = "llvm_build_sext_or_bitcast"
1792 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
1793 instruction at the position specified by the instruction builder [b].
1794 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1795 external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1796 llvalue = "llvm_build_trunc_or_bitcast"
1798 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
1799 instruction at the position specified by the instruction builder [b].
1800 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
1801 external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
1802 = "llvm_build_pointercast"
1804 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
1805 instruction at the position specified by the instruction builder [b].
1806 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
1807 external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1808 = "llvm_build_intcast"
1810 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
1811 instruction at the position specified by the instruction builder [b].
1812 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
1813 external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1814 = "llvm_build_fpcast"
1817 (** {7 Comparisons} *)
1819 (** [build_icmp pred x y name b] creates a
1820 [%name = icmp %pred %x, %y]
1821 instruction at the position specified by the instruction builder [b].
1822 See the method [llvm::LLVMBuilder::CreateICmp]. *)
1823 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1824 llbuilder -> llvalue = "llvm_build_icmp"
1826 (** [build_fcmp pred x y name b] creates a
1827 [%name = fcmp %pred %x, %y]
1828 instruction at the position specified by the instruction builder [b].
1829 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1830 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1831 llbuilder -> llvalue = "llvm_build_fcmp"
1834 (** {7 Miscellaneous instructions} *)
1836 (** [build_phi incoming name b] creates a
1837 [%name = phi %incoming]
1838 instruction at the position specified by the instruction builder [b].
1839 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1840 See the method [llvm::LLVMBuilder::CreatePHI]. *)
1841 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1842 llvalue = "llvm_build_phi"
1844 (** [build_call fn args name b] creates a
1845 [%name = call %fn(args...)]
1846 instruction at the position specified by the instruction builder [b].
1847 See the method [llvm::LLVMBuilder::CreateCall]. *)
1848 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1851 (** [build_select cond thenv elsev name b] creates a
1852 [%name = select %cond, %thenv, %elsev]
1853 instruction at the position specified by the instruction builder [b].
1854 See the method [llvm::LLVMBuilder::CreateSelect]. *)
1855 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1856 llvalue = "llvm_build_select"
1858 (** [build_va_arg valist argty name b] creates a
1859 [%name = va_arg %valist, %argty]
1860 instruction at the position specified by the instruction builder [b].
1861 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1862 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1863 = "llvm_build_va_arg"
1865 (** [build_extractelement vec i name b] creates a
1866 [%name = extractelement %vec, %i]
1867 instruction at the position specified by the instruction builder [b].
1868 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1869 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1870 llvalue = "llvm_build_extractelement"
1872 (** [build_insertelement vec elt i name b] creates a
1873 [%name = insertelement %vec, %elt, %i]
1874 instruction at the position specified by the instruction builder [b].
1875 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1876 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1877 llbuilder -> llvalue = "llvm_build_insertelement"
1879 (** [build_shufflevector veca vecb mask name b] creates a
1880 [%name = shufflevector %veca, %vecb, %mask]
1881 instruction at the position specified by the instruction builder [b].
1882 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1883 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1884 llbuilder -> llvalue = "llvm_build_shufflevector"
1886 (** [build_insertvalue agg idx name b] creates a
1887 [%name = extractvalue %agg, %idx]
1888 instruction at the position specified by the instruction builder [b].
1889 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
1890 external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
1891 = "llvm_build_extractvalue"
1893 (** [build_insertvalue agg val idx name b] creates a
1894 [%name = insertvalue %agg, %val, %idx]
1895 instruction at the position specified by the instruction builder [b].
1896 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
1897 external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
1898 llvalue = "llvm_build_insertvalue"
1900 (** [build_is_null val name b] creates a
1901 [%name = icmp eq %val, null]
1902 instruction at the position specified by the instruction builder [b].
1903 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
1904 external build_is_null : llvalue -> string -> llbuilder -> llvalue
1905 = "llvm_build_is_null"
1907 (** [build_is_not_null val name b] creates a
1908 [%name = icmp ne %val, null]
1909 instruction at the position specified by the instruction builder [b].
1910 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
1911 external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
1912 = "llvm_build_is_not_null"
1914 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
1915 the difference between two pointer values at the position specified by the
1916 instruction builder [b].
1917 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
1918 external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
1919 = "llvm_build_ptrdiff"
1921 (** {6 Module providers} *)
1923 module ModuleProvider : sig
1924 (** [create_module_provider m] encapsulates [m] in a module provider and takes
1925 ownership of the module. See the constructor
1926 [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
1927 external create : llmodule -> llmoduleprovider
1928 = "LLVMCreateModuleProviderForExistingModule"
1930 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1931 the contained module. *)
1932 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1936 (** {6 Memory buffers} *)
1938 module MemoryBuffer : sig
1939 (** [of_file p] is the memory buffer containing the contents of the file at
1940 path [p]. If the file could not be read, then [IoError msg] is
1942 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1944 (** [stdin ()] is the memory buffer containing the contents of standard input.
1945 If standard input is empty, then [IoError msg] is raised. *)
1946 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1948 (** Disposes of a memory buffer. *)
1949 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
1953 (** {6 Pass Managers} *)
1955 module PassManager : sig
1958 type any = [ `Module | `Function ]
1960 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
1961 type of pipeline is suitable for link-time optimization and whole-module
1963 See the constructor of [llvm::PassManager]. *)
1964 external create : unit -> [ `Module ] t = "llvm_passmanager_create"
1966 (** [PassManager.create_function mp] constructs a new function-by-function
1967 pass pipeline over the module provider [mp]. It does not take ownership of
1968 [mp]. This type of pipeline is suitable for code generation and JIT
1970 See the constructor of [llvm::FunctionPassManager]. *)
1971 external create_function : llmoduleprovider -> [ `Function ] t
1972 = "LLVMCreateFunctionPassManager"
1974 (** [run_module m pm] initializes, executes on the module [m], and finalizes
1975 all of the passes scheduled in the pass manager [pm]. Returns [true] if
1976 any of the passes modified the module, [false] otherwise.
1977 See the [llvm::PassManager::run] method. *)
1978 external run_module : llmodule -> [ `Module ] t -> bool
1979 = "llvm_passmanager_run_module"
1981 (** [initialize fpm] initializes all of the function passes scheduled in the
1982 function pass manager [fpm]. Returns [true] if any of the passes modified
1983 the module, [false] otherwise.
1984 See the [llvm::FunctionPassManager::doInitialization] method. *)
1985 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
1987 (** [run_function f fpm] executes all of the function passes scheduled in the
1988 function pass manager [fpm] over the function [f]. Returns [true] if any
1989 of the passes modified [f], [false] otherwise.
1990 See the [llvm::FunctionPassManager::run] method. *)
1991 external run_function : llvalue -> [ `Function ] t -> bool
1992 = "llvm_passmanager_run_function"
1994 (** [finalize fpm] finalizes all of the function passes scheduled in in the
1995 function pass manager [fpm]. Returns [true] if any of the passes
1996 modified the module, [false] otherwise.
1997 See the [llvm::FunctionPassManager::doFinalization] method. *)
1998 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
2000 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2001 the module provider.
2002 See the destructor of [llvm::BasePassManager]. *)
2003 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"