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
94 (** The linker visibility of a global value, accessed with {!visibility} and
95 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
96 module Visibility : sig
103 (** The following calling convention values may be accessed with
104 {!function_call_conv} and {!set_function_call_conv}. Calling
105 conventions are open-ended. *)
106 module CallConv : sig
107 val c : int (** [c] is the C calling convention. *)
108 val fast : int (** [fast] is the calling convention to allow LLVM
109 maximum optimization opportunities. Use only with
111 val cold : int (** [cold] is the calling convention for
113 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling
114 convention from C. *)
115 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
116 convention from C. *)
119 module Attribute : sig
134 (** The predicate for an integer comparison ([icmp]) instruction.
135 See the [llvm::ICmpInst::Predicate] enumeration. *)
150 (** The predicate for a floating-point comparison ([fcmp]) instruction.
151 See the [llvm::FCmpInst::Predicate] enumeration. *)
175 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
176 of [a]. [llpos] is used to specify positions in and for forward iteration
177 through the various value lists maintained by the LLVM IR. *)
178 type ('a, 'b) llpos =
182 (** [After b] and [At_start a] specify positions from the end of the ['b] list
183 of [a]. [llrev_pos] is used for reverse iteration through the various value
184 lists maintained by the LLVM IR. *)
185 type ('a, 'b) llrev_pos =
190 (** {6 Exceptions} *)
192 exception IoError of string
197 (** [create_context ()] creates a context for storing the "global" state in
198 LLVM. See the constructor [llvm::LLVMContext]. *)
199 external create_context : unit -> llcontext = "llvm_create_context"
201 (** [destroy_context ()] destroys a context. See the destructor
202 [llvm::LLVMContext::~LLVMContext]. *)
203 external dispose_context : unit -> llcontext = "llvm_dispose_context"
205 (** See the function [llvm::getGlobalContext]. *)
206 external global_context : unit -> llcontext = "llvm_global_context"
211 (** [create_module context id] creates a module with the supplied module ID in
212 the context [context]. Modules are not garbage collected; it is mandatory
213 to call {!dispose_module} to free memory. See the constructor
214 [llvm::Module::Module]. *)
215 external create_module : llcontext -> string -> llmodule = "llvm_create_module"
217 (** [dispose_module m] destroys a module [m] and all of the IR objects it
218 contained. All references to subordinate objects are invalidated;
219 referencing them will invoke undefined behavior. See the destructor
220 [llvm::Module::~Module]. *)
221 external dispose_module : llmodule -> unit = "llvm_dispose_module"
223 (** [target_triple m] is the target specifier for the module [m], something like
224 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
225 external target_triple: llmodule -> string
226 = "llvm_target_triple"
228 (** [target_triple triple m] changes the target specifier for the module [m] to
229 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
230 external set_target_triple: string -> llmodule -> unit
231 = "llvm_set_target_triple"
233 (** [data_layout m] is the data layout specifier for the module [m], something
234 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
235 method [llvm::Module::getDataLayout]. *)
236 external data_layout: llmodule -> string
239 (** [set_data_layout s m] changes the data layout specifier for the module [m]
240 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
241 external set_data_layout: string -> llmodule -> unit
242 = "llvm_set_data_layout"
244 (** [define_type_name name ty m] adds a named type to the module's symbol table.
245 Returns [true] if successful. If such a name already exists, then no entry
246 is added and [false] is returned. See the [llvm::Module::addTypeName]
248 external define_type_name : string -> lltype -> llmodule -> bool
249 = "llvm_add_type_name"
251 (** [delete_type_name name] removes a type name from the module's symbol
253 external delete_type_name : string -> llmodule -> unit
254 = "llvm_delete_type_name"
256 (** [dump_module m] prints the .ll representation of the module [m] to standard
257 error. See the method [llvm::Module::dump]. *)
258 external dump_module : llmodule -> unit = "llvm_dump_module"
263 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
264 See the method [llvm::Type::getTypeID]. *)
265 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
267 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
268 See the method [llvm::Type::getContext]. *)
269 external type_context : lltype -> llcontext = "llvm_type_context"
271 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
272 val string_of_lltype : lltype -> string
274 (** {7 Operations on integer types} *)
276 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
277 [llvm::Type::Int1Ty]. *)
278 external i1_type : llcontext -> lltype = "llvm_i1_type"
280 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
281 [llvm::Type::Int8Ty]. *)
282 external i8_type : llcontext -> lltype = "llvm_i8_type"
284 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
285 [llvm::Type::Int16Ty]. *)
286 external i16_type : llcontext -> lltype = "llvm_i16_type"
288 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
289 [llvm::Type::Int32Ty]. *)
290 external i32_type : llcontext -> lltype = "llvm_i32_type"
292 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
293 [llvm::Type::Int64Ty]. *)
294 external i64_type : llcontext -> lltype = "llvm_i64_type"
296 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
297 [c]. See the method [llvm::IntegerType::get]. *)
298 external integer_type : llcontext -> int -> lltype = "llvm_integer_type"
300 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
301 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
302 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
305 (** {7 Operations on real types} *)
307 (** [float_type c] returns the IEEE 32-bit floating point type in the context
308 [c]. See [llvm::Type::FloatTy]. *)
309 external float_type : llcontext -> lltype = "llvm_float_type"
311 (** [double_type c] returns the IEEE 64-bit floating point type in the context
312 [c]. See [llvm::Type::DoubleTy]. *)
313 external double_type : llcontext -> lltype = "llvm_double_type"
315 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
316 [c]. See [llvm::Type::X86_FP80Ty]. *)
317 external x86fp80_type : llcontext -> lltype = "llvm_x86fp80_type"
319 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
320 [c]. See [llvm::Type::FP128Ty]. *)
321 external fp128_type : llcontext -> lltype = "llvm_fp128_type"
323 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
324 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
325 external ppc_fp128_type : llcontext -> lltype = "llvm_ppc_fp128_type"
328 (** {7 Operations on function types} *)
330 (** [function_type ret_ty param_tys] returns the function type returning
331 [ret_ty] and taking [param_tys] as parameters.
332 See the method [llvm::FunctionType::get]. *)
333 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
335 (** [va_arg_function_type ret_ty param_tys] is just like
336 [function_type ret_ty param_tys] except that it returns the function type
337 which also takes a variable number of arguments.
338 See the method [llvm::FunctionType::get]. *)
339 external var_arg_function_type : lltype -> lltype array -> lltype
340 = "llvm_var_arg_function_type"
342 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
343 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
344 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
346 (** [return_type fty] gets the return type of the function type [fty].
347 See the method [llvm::FunctionType::getReturnType]. *)
348 external return_type : lltype -> lltype = "LLVMGetReturnType"
350 (** [param_types fty] gets the parameter types of the function type [fty].
351 See the method [llvm::FunctionType::getParamType]. *)
352 external param_types : lltype -> lltype array = "llvm_param_types"
355 (** {7 Operations on struct types} *)
357 (** [struct_type context tys] returns the structure type in the context
358 [context] containing in the types in the array [tys]. See the method
359 [llvm::StructType::get]. *)
360 external struct_type : llcontext -> lltype array -> lltype
363 (** [packed_struct_type context ys] returns the packed structure type in the
364 context [context] containing in the types in the array [tys]. See the method
365 [llvm::StructType::get]. *)
366 external packed_struct_type : llcontext -> lltype array -> lltype
367 = "llvm_packed_struct_type"
369 (** [element_types sty] returns the constituent types of the struct type [sty].
370 See the method [llvm::StructType::getElementType]. *)
371 external element_types : lltype -> lltype array = "llvm_element_types"
373 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
374 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
375 external is_packed : lltype -> bool = "llvm_is_packed"
378 (** {7 Operations on pointer, vector, and array types} *)
380 (** [array_type ty n] returns the array type containing [n] elements of type
381 [ty]. See the method [llvm::ArrayType::get]. *)
382 external array_type : lltype -> int -> lltype = "llvm_array_type"
384 (** [pointer_type ty] returns the pointer type referencing objects of type
385 [ty] in the default address space (0).
386 See the method [llvm::PointerType::getUnqual]. *)
387 external pointer_type : lltype -> lltype = "llvm_pointer_type"
389 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
390 of type [ty] in address space [as].
391 See the method [llvm::PointerType::get]. *)
392 external qualified_pointer_type : lltype -> int -> lltype
393 = "llvm_qualified_pointer_type"
395 (** [vector_type ty n] returns the array type containing [n] elements of the
396 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
397 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
399 (** [element_type ty] returns the element type of the pointer, vector, or array
400 type [ty]. See the method [llvm::SequentialType::get]. *)
401 external element_type : lltype -> lltype = "LLVMGetElementType"
403 (** [element_type aty] returns the element count of the array type [aty].
404 See the method [llvm::ArrayType::getNumElements]. *)
405 external array_length : lltype -> int = "llvm_array_length"
407 (** [address_space pty] returns the address space qualifier of the pointer type
408 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
409 external address_space : lltype -> int = "llvm_address_space"
411 (** [element_type ty] returns the element count of the vector type [ty].
412 See the method [llvm::VectorType::getNumElements]. *)
413 external vector_size : lltype -> int = "llvm_vector_size"
416 (** {7 Operations on other types} *)
418 (** [opaque_type c] creates a new opaque type distinct from any other in the
419 context [c]. Opaque types are useful for building recursive types in
420 combination with {!refine_type}. See [llvm::OpaqueType::get]. *)
421 external opaque_type : llcontext -> lltype = "llvm_opaque_type"
423 (** [void_type c] creates a type of a function which does not return any
424 value in the context [c]. See [llvm::Type::VoidTy]. *)
425 external void_type : llcontext -> lltype = "llvm_void_type"
427 (** [label_type c] creates a type of a basic block in the context [c]. See
428 [llvm::Type::LabelTy]. *)
429 external label_type : llcontext -> lltype = "llvm_label_type"
431 (** {7 Operations on type handles} *)
433 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
434 refined as a result of a call to {!refine_type}, the handle will be updated;
435 any bare [lltype] references will become invalid.
436 See the class [llvm::PATypeHolder]. *)
437 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
439 (** [type_of_handle tyh] resolves the type handle [tyh].
440 See the method [llvm::PATypeHolder::get()]. *)
441 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
443 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
444 concrete type [ty] in all users. Warning: This may invalidate {!lltype}
445 values! Use {!lltypehandle} to manipulate potentially abstract types. See
446 the method [llvm::Type::refineAbstractType]. *)
447 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
452 (** [type_of v] returns the type of the value [v].
453 See the method [llvm::Value::getType]. *)
454 external type_of : llvalue -> lltype = "llvm_type_of"
456 (** [value_name v] returns the name of the value [v]. For global values, this is
457 the symbol name. For instructions and basic blocks, it is the SSA register
458 name. It is meaningless for constants.
459 See the method [llvm::Value::getName]. *)
460 external value_name : llvalue -> string = "llvm_value_name"
462 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
463 [llvm::Value::setName]. *)
464 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
466 (** [dump_value v] prints the .ll representation of the value [v] to standard
467 error. See the method [llvm::Value::dump]. *)
468 external dump_value : llvalue -> unit = "llvm_dump_value"
471 (** {7 Operations on constants of (mostly) any type} *)
473 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
474 otherwise. Similar to [llvm::isa<Constant>]. *)
475 external is_constant : llvalue -> bool = "llvm_is_constant"
477 (** [const_null ty] returns the constant null (zero) of the type [ty].
478 See the method [llvm::Constant::getNullValue]. *)
479 external const_null : lltype -> llvalue = "LLVMConstNull"
481 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
482 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
483 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
485 (** [undef ty] returns the undefined value of the type [ty].
486 See the method [llvm::UndefValue::get]. *)
487 external undef : lltype -> llvalue = "LLVMGetUndef"
489 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
490 See the method [llvm::Constant::isNullValue]. *)
491 external is_null : llvalue -> bool = "llvm_is_null"
493 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
494 otherwise. Similar to [llvm::isa<UndefValue>]. *)
495 external is_undef : llvalue -> bool = "llvm_is_undef"
498 (** {7 Operations on scalar constants} *)
500 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
501 See the method [llvm::ConstantInt::get]. *)
502 external const_int : lltype -> int -> llvalue = "llvm_const_int"
504 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
505 [i]. See the method [llvm::ConstantInt::get]. *)
506 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
507 = "llvm_const_of_int64"
509 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
510 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
511 external const_int_of_string : lltype -> string -> int -> llvalue
512 = "llvm_const_int_of_string"
514 (** [const_float ty n] returns the floating point constant of type [ty] and
515 value [n]. See the method [llvm::ConstantFP::get]. *)
516 external const_float : lltype -> float -> llvalue = "llvm_const_float"
518 (** [const_float_of_string ty s] returns the floating point constant of type
519 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
520 external const_float_of_string : lltype -> string -> llvalue
521 = "llvm_const_float_of_string"
524 (** {7 Operations on composite constants} *)
526 (** [const_string c s] returns the constant [i8] array with the values of the
527 characters in the string [s] in the context [c]. The array is not
528 null-terminated (but see {!const_stringz}). This value can in turn be used
529 as the initializer for a global variable. See the method
530 [llvm::ConstantArray::get]. *)
531 external const_string : llcontext -> string -> llvalue = "llvm_const_string"
533 (** [const_stringz c s] returns the constant [i8] array with the values of the
534 characters in the string [s] and a null terminator in the context [c]. This
535 value can in turn be used as the initializer for a global variable.
536 See the method [llvm::ConstantArray::get]. *)
537 external const_stringz : llcontext -> string -> llvalue = "llvm_const_stringz"
539 (** [const_array ty elts] returns the constant array of type
540 [array_type ty (Array.length elts)] and containing the values [elts].
541 This value can in turn be used as the initializer for a global variable.
542 See the method [llvm::ConstantArray::get]. *)
543 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
545 (** [const_struct context elts] returns the structured constant of type
546 [struct_type (Array.map type_of elts)] and containing the values [elts]
547 in the context [context]. This value can in turn be used as the initializer
548 for a global variable. See the method [llvm::ConstantStruct::get]. *)
549 external const_struct : llcontext -> llvalue array -> llvalue
550 = "llvm_const_struct"
552 (** [const_packed_struct context elts] returns the structured constant of
553 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
554 values [elts] in the context [context]. This value can in turn be used as
555 the initializer for a global variable. See the method
556 [llvm::ConstantStruct::get]. *)
557 external const_packed_struct : llcontext -> llvalue array -> llvalue
558 = "llvm_const_packed_struct"
560 (** [const_vector elts] returns the vector constant of type
561 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
562 values [elts]. See the method [llvm::ConstantVector::get]. *)
563 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
566 (** {7 Constant expressions} *)
568 (** [align_of ty] returns the alignof constant for the type [ty]. This is
569 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
570 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
571 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
572 external align_of : lltype -> llvalue = "LLVMAlignOf"
574 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
575 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
576 (const_int i32_type 1)) i64_type], but considerably more readable.
577 See the method [llvm::ConstantExpr::getSizeOf]. *)
578 external size_of : lltype -> llvalue = "LLVMSizeOf"
580 (** [const_neg c] returns the arithmetic negation of the constant [c].
581 See the method [llvm::ConstantExpr::getNeg]. *)
582 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
584 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
585 See the method [llvm::ConstantExpr::getFNeg]. *)
586 external const_fneg : llvalue -> llvalue = "LLVMConstFNeg"
588 (** [const_not c] returns the bitwise inverse of the constant [c].
589 See the method [llvm::ConstantExpr::getNot]. *)
590 external const_not : llvalue -> llvalue = "LLVMConstNot"
592 (** [const_add c1 c2] returns the constant sum of two constants.
593 See the method [llvm::ConstantExpr::getAdd]. *)
594 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
596 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
597 signed wrapping. The result is undefined if the sum overflows.
598 See the method [llvm::ConstantExpr::getNSWAdd]. *)
599 external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd"
601 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
602 See the method [llvm::ConstantExpr::getFAdd]. *)
603 external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd"
605 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
606 constants. See the method [llvm::ConstantExpr::getSub]. *)
607 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
609 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
610 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
611 external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub"
613 (** [const_mul c1 c2] returns the constant product of two constants.
614 See the method [llvm::ConstantExpr::getMul]. *)
615 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
617 (** [const_fmul c1 c2] returns the constant product of two constants floats.
618 See the method [llvm::ConstantExpr::getFMul]. *)
619 external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul"
621 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
623 See the method [llvm::ConstantExpr::getUDiv]. *)
624 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
626 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
628 See the method [llvm::ConstantExpr::getSDiv]. *)
629 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
631 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
632 signed integer constants. The result is undefined if the result is rounded
633 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
634 external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv"
636 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
638 See the method [llvm::ConstantExpr::getFDiv]. *)
639 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
641 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
642 unsigned integer constants.
643 See the method [llvm::ConstantExpr::getURem]. *)
644 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
646 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
647 signed integer constants.
648 See the method [llvm::ConstantExpr::getSRem]. *)
649 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
651 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
652 signed floating point constants.
653 See the method [llvm::ConstantExpr::getFRem]. *)
654 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
656 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
658 See the method [llvm::ConstantExpr::getAnd]. *)
659 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
661 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
663 See the method [llvm::ConstantExpr::getOr]. *)
664 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
666 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
668 See the method [llvm::ConstantExpr::getXor]. *)
669 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
671 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
672 constants, [c1 pred c2].
673 See the method [llvm::ConstantExpr::getICmp]. *)
674 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
677 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
678 point constants, [c1 pred c2].
679 See the method [llvm::ConstantExpr::getFCmp]. *)
680 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
683 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
684 constant integer [c2].
685 See the method [llvm::ConstantExpr::getShl]. *)
686 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
688 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
689 constant integer [c2] with zero extension.
690 See the method [llvm::ConstantExpr::getLShr]. *)
691 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
693 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
694 constant integer [c2] with sign extension.
695 See the method [llvm::ConstantExpr::getAShr]. *)
696 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
698 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
699 constant integers indices from the array [indices].
700 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
701 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
703 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
704 with the constant integers indices from the array [indices].
705 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
706 external const_in_bounds_gep : llvalue -> llvalue array -> llvalue
707 = "llvm_const_in_bounds_gep"
709 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
710 to the smaller integer type [ty].
711 See the method [llvm::ConstantExpr::getTrunc]. *)
712 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
714 (** [const_sext c ty] returns the constant sign extension of integer constant
715 [c] to the larger integer type [ty].
716 See the method [llvm::ConstantExpr::getSExt]. *)
717 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
719 (** [const_zext c ty] returns the constant zero extension of integer constant
720 [c] to the larger integer type [ty].
721 See the method [llvm::ConstantExpr::getZExt]. *)
722 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
724 (** [const_fptrunc c ty] returns the constant truncation of floating point
725 constant [c] to the smaller floating point type [ty].
726 See the method [llvm::ConstantExpr::getFPTrunc]. *)
727 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
729 (** [const_fpext c ty] returns the constant extension of floating point constant
730 [c] to the larger floating point type [ty].
731 See the method [llvm::ConstantExpr::getFPExt]. *)
732 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
734 (** [const_uitofp c ty] returns the constant floating point conversion of
735 unsigned integer constant [c] to the floating point type [ty].
736 See the method [llvm::ConstantExpr::getUIToFP]. *)
737 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
739 (** [const_sitofp c ty] returns the constant floating point conversion of
740 signed integer constant [c] to the floating point type [ty].
741 See the method [llvm::ConstantExpr::getSIToFP]. *)
742 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
744 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
745 floating point constant [c] to integer type [ty].
746 See the method [llvm::ConstantExpr::getFPToUI]. *)
747 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
749 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
750 floating point constant [c] to integer type [ty].
751 See the method [llvm::ConstantExpr::getFPToSI]. *)
752 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
754 (** [const_ptrtoint c ty] returns the constant integer conversion of
755 pointer constant [c] to integer type [ty].
756 See the method [llvm::ConstantExpr::getPtrToInt]. *)
757 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
759 (** [const_inttoptr c ty] returns the constant pointer conversion of
760 integer constant [c] to pointer type [ty].
761 See the method [llvm::ConstantExpr::getIntToPtr]. *)
762 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
764 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
765 to type [ty] of equal size.
766 See the method [llvm::ConstantExpr::getBitCast]. *)
767 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
769 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
770 conversion of constant [c] to type [ty].
771 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
772 external const_zext_or_bitcast : llvalue -> lltype -> llvalue
773 = "LLVMConstZExtOrBitCast"
775 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
776 conversion of constant [c] to type [ty].
777 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
778 external const_sext_or_bitcast : llvalue -> lltype -> llvalue
779 = "LLVMConstSExtOrBitCast"
781 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
782 conversion of constant [c] to type [ty].
783 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
784 external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
785 = "LLVMConstTruncOrBitCast"
787 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
788 cast conversion of constant [c] to type [ty] of equal size.
789 See the method [llvm::ConstantExpr::getPointerCast]. *)
790 external const_pointercast : llvalue -> lltype -> llvalue
791 = "LLVMConstPointerCast"
793 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
794 -> integer casts of constant [c] to type [ty].
795 See the method [llvm::ConstantExpr::getIntCast]. *)
796 external const_intcast : llvalue -> lltype -> llvalue
799 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
800 fp casts of constant [c] to type [ty].
801 See the method [llvm::ConstantExpr::getFPCast]. *)
802 external const_fpcast : llvalue -> lltype -> llvalue
805 (** [const_select cond t f] returns the constant conditional which returns value
806 [t] if the boolean constant [cond] is true and the value [f] otherwise.
807 See the method [llvm::ConstantExpr::getSelect]. *)
808 external const_select : llvalue -> llvalue -> llvalue -> llvalue
811 (** [const_extractelement vec i] returns the constant [i]th element of
812 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
813 the size of the vector.
814 See the method [llvm::ConstantExpr::getExtractElement]. *)
815 external const_extractelement : llvalue -> llvalue -> llvalue
816 = "LLVMConstExtractElement"
818 (** [const_insertelement vec v i] returns the constant vector with the same
819 elements as constant vector [v] but the [i]th element replaced by the
820 constant [v]. [v] must be a constant value with the type of the vector
821 elements. [i] must be a constant [i32] value unsigned less than the size
823 See the method [llvm::ConstantExpr::getInsertElement]. *)
824 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
825 = "LLVMConstInsertElement"
827 (** [const_shufflevector a b mask] returns a constant [shufflevector].
828 See the LLVM Language Reference for details on the [sufflevector]
830 See the method [llvm::ConstantExpr::getShuffleVector]. *)
831 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
832 = "LLVMConstShuffleVector"
834 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
835 constant aggregate [agg]. Each [idxs] must be less than the size of the
836 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
837 external const_extractvalue : llvalue -> int array -> llvalue
838 = "llvm_const_extractvalue"
840 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
841 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
842 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
843 external const_insertvalue : llvalue -> llvalue -> int array -> llvalue
844 = "llvm_const_insertvalue"
847 (** {7 Operations on global variables, functions, and aliases (globals)} *)
849 (** [global_parent g] is the enclosing module of the global value [g].
850 See the method [llvm::GlobalValue::getParent]. *)
851 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
853 (** [is_declaration g] returns [true] if the global value [g] is a declaration
854 only. Returns [false] otherwise.
855 See the method [llvm::GlobalValue::isDeclaration]. *)
856 external is_declaration : llvalue -> bool = "llvm_is_declaration"
858 (** [linkage g] returns the linkage of the global value [g].
859 See the method [llvm::GlobalValue::getLinkage]. *)
860 external linkage : llvalue -> Linkage.t = "llvm_linkage"
862 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
863 See the method [llvm::GlobalValue::setLinkage]. *)
864 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
866 (** [section g] returns the linker section of the global value [g].
867 See the method [llvm::GlobalValue::getSection]. *)
868 external section : llvalue -> string = "llvm_section"
870 (** [set_section s g] sets the linker section of the global value [g] to [s].
871 See the method [llvm::GlobalValue::setSection]. *)
872 external set_section : string -> llvalue -> unit = "llvm_set_section"
874 (** [visibility g] returns the linker visibility of the global value [g].
875 See the method [llvm::GlobalValue::getVisibility]. *)
876 external visibility : llvalue -> Visibility.t = "llvm_visibility"
878 (** [set_visibility v g] sets the linker visibility of the global value [g] to
879 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
880 external set_visibility : Visibility.t -> llvalue -> unit
881 = "llvm_set_visibility"
883 (** [alignment g] returns the required alignment of the global value [g].
884 See the method [llvm::GlobalValue::getAlignment]. *)
885 external alignment : llvalue -> int = "llvm_alignment"
887 (** [set_alignment n g] sets the required alignment of the global value [g] to
888 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
889 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
892 (** {7 Operations on global variables} *)
894 (** [declare_global ty name m] returns a new global variable of type [ty] and
895 with name [name] in module [m]. If such a global variable already exists,
896 it is returned. If the type of the existing global differs, then a bitcast
897 to [ty] is returned. *)
898 external declare_global : lltype -> string -> llmodule -> llvalue
899 = "llvm_declare_global"
901 (** [define_global name init m] returns a new global with name [name] and
902 initializer [init] in module [m]. If the named global already exists, it is
904 See the constructor of [llvm::GlobalVariable]. *)
905 external define_global : string -> llvalue -> llmodule -> llvalue
906 = "llvm_define_global"
908 (** [lookup_global name m] returns [Some g] if a global variable with name
909 [name] exists in module [m]. If no such global exists, returns [None].
910 See the [llvm::GlobalVariable] constructor. *)
911 external lookup_global : string -> llmodule -> llvalue option
912 = "llvm_lookup_global"
914 (** [delete_global gv] destroys the global variable [gv].
915 See the method [llvm::GlobalVariable::eraseFromParent]. *)
916 external delete_global : llvalue -> unit = "llvm_delete_global"
918 (** [global_begin m] returns the first position in the global variable list of
919 the module [m]. [global_begin] and [global_succ] can be used to iterate
920 over the global list in order.
921 See the method [llvm::Module::global_begin]. *)
922 external global_begin : llmodule -> (llmodule, llvalue) llpos
923 = "llvm_global_begin"
925 (** [global_succ gv] returns the global variable list position succeeding
927 See the method [llvm::Module::global_iterator::operator++]. *)
928 external global_succ : llvalue -> (llmodule, llvalue) llpos
931 (** [iter_globals f m] applies function [f] to each of the global variables of
932 module [m] in order. Tail recursive. *)
933 val iter_globals : (llvalue -> unit) -> llmodule -> unit
935 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
936 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
937 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
939 (** [global_end m] returns the last position in the global variable list of the
940 module [m]. [global_end] and [global_pred] can be used to iterate over the
941 global list in reverse.
942 See the method [llvm::Module::global_end]. *)
943 external global_end : llmodule -> (llmodule, llvalue) llrev_pos
946 (** [global_pred gv] returns the global variable list position preceding
948 See the method [llvm::Module::global_iterator::operator--]. *)
949 external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
952 (** [rev_iter_globals f m] applies function [f] to each of the global variables
953 of module [m] in reverse order. Tail recursive. *)
954 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
956 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
957 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
958 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
960 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
961 constant. Returns [false] otherwise.
962 See the method [llvm::GlobalVariable::isConstant]. *)
963 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
965 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
966 [c] is [true] and not if [c] is [false].
967 See the method [llvm::GlobalVariable::setConstant]. *)
968 external set_global_constant : bool -> llvalue -> unit
969 = "llvm_set_global_constant"
971 (** [global_initializer gv] returns the initializer for the global variable
972 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
973 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
975 (** [set_initializer c gv] sets the initializer for the global variable
976 [gv] to the constant [c].
977 See the method [llvm::GlobalVariable::setInitializer]. *)
978 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
980 (** [remove_initializer gv] unsets the initializer for the global variable
982 See the method [llvm::GlobalVariable::setInitializer]. *)
983 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
985 (** [is_thread_local gv] returns [true] if the global variable [gv] is
986 thread-local and [false] otherwise.
987 See the method [llvm::GlobalVariable::isThreadLocal]. *)
988 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
990 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
991 [c] is [true] and not otherwise.
992 See the method [llvm::GlobalVariable::setThreadLocal]. *)
993 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
996 (** {7 Operations on functions} *)
998 (** [declare_function name ty m] returns a new function of type [ty] and
999 with name [name] in module [m]. If such a function already exists,
1000 it is returned. If the type of the existing function differs, then a bitcast
1001 to [ty] is returned. *)
1002 external declare_function : string -> lltype -> llmodule -> llvalue
1003 = "llvm_declare_function"
1005 (** [define_function name ty m] creates a new function with name [name] and
1006 type [ty] in module [m]. If the named function already exists, it is
1007 renamed. An entry basic block is created in the function.
1008 See the constructor of [llvm::GlobalVariable]. *)
1009 external define_function : string -> lltype -> llmodule -> llvalue
1010 = "llvm_define_function"
1012 (** [lookup_function name m] returns [Some f] if a function with name
1013 [name] exists in module [m]. If no such function exists, returns [None].
1014 See the method [llvm::Module] constructor. *)
1015 external lookup_function : string -> llmodule -> llvalue option
1016 = "llvm_lookup_function"
1018 (** [delete_function f] destroys the function [f].
1019 See the method [llvm::Function::eraseFromParent]. *)
1020 external delete_function : llvalue -> unit = "llvm_delete_function"
1022 (** [function_begin m] returns the first position in the function list of the
1023 module [m]. [function_begin] and [function_succ] can be used to iterate over
1024 the function list in order.
1025 See the method [llvm::Module::begin]. *)
1026 external function_begin : llmodule -> (llmodule, llvalue) llpos
1027 = "llvm_function_begin"
1029 (** [function_succ gv] returns the function list position succeeding
1031 See the method [llvm::Module::iterator::operator++]. *)
1032 external function_succ : llvalue -> (llmodule, llvalue) llpos
1033 = "llvm_function_succ"
1035 (** [iter_functions f m] applies function [f] to each of the functions of module
1036 [m] in order. Tail recursive. *)
1037 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1039 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1040 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1041 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1043 (** [function_end m] returns the last position in the function list of
1044 the module [m]. [function_end] and [function_pred] can be used to iterate
1045 over the function list in reverse.
1046 See the method [llvm::Module::end]. *)
1047 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
1048 = "llvm_function_end"
1050 (** [function_pred gv] returns the function list position preceding [After gv].
1051 See the method [llvm::Module::iterator::operator--]. *)
1052 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1053 = "llvm_function_pred"
1055 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1056 module [m] in reverse order. Tail recursive. *)
1057 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1059 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1060 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1061 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1063 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1064 See the method [llvm::Function::isIntrinsic]. *)
1065 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
1067 (** [function_call_conv f] returns the calling convention of the function [f].
1068 See the method [llvm::Function::getCallingConv]. *)
1069 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
1071 (** [set_function_call_conv cc f] sets the calling convention of the function
1072 [f] to the calling convention numbered [cc].
1073 See the method [llvm::Function::setCallingConv]. *)
1074 external set_function_call_conv : int -> llvalue -> unit
1075 = "llvm_set_function_call_conv"
1077 (** [gc f] returns [Some name] if the function [f] has a garbage
1078 collection algorithm specified and [None] otherwise.
1079 See the method [llvm::Function::getGC]. *)
1080 external gc : llvalue -> string option = "llvm_gc"
1082 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1083 [gc]. See the method [llvm::Function::setGC]. *)
1084 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
1086 (** [add_function_attr f a] adds attribute [a] to the return type of function
1088 external add_function_attr : llvalue -> Attribute.t -> unit
1089 = "llvm_add_function_attr"
1091 (** [remove_function_attr f a] removes attribute [a] from the return type of
1093 external remove_function_attr : llvalue -> Attribute.t -> unit
1094 = "llvm_remove_function_attr"
1096 (** {7 Operations on params} *)
1098 (** [params f] returns the parameters of function [f].
1099 See the method [llvm::Function::getArgumentList]. *)
1100 external params : llvalue -> llvalue array = "llvm_params"
1102 (** [param f n] returns the [n]th parameter of function [f].
1103 See the method [llvm::Function::getArgumentList]. *)
1104 external param : llvalue -> int -> llvalue = "llvm_param"
1106 (** [param_parent p] returns the parent function that owns the parameter.
1107 See the method [llvm::Argument::getParent]. *)
1108 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
1110 (** [param_begin f] returns the first position in the parameter list of the
1111 function [f]. [param_begin] and [param_succ] can be used to iterate over
1112 the parameter list in order.
1113 See the method [llvm::Function::arg_begin]. *)
1114 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
1116 (** [param_succ bb] returns the parameter list position succeeding
1118 See the method [llvm::Function::arg_iterator::operator++]. *)
1119 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
1121 (** [iter_params f fn] applies function [f] to each of the parameters
1122 of function [fn] in order. Tail recursive. *)
1123 val iter_params : (llvalue -> unit) -> llvalue -> unit
1125 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1126 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1127 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1129 (** [param_end f] returns the last position in the parameter list of
1130 the function [f]. [param_end] and [param_pred] can be used to iterate
1131 over the parameter list in reverse.
1132 See the method [llvm::Function::arg_end]. *)
1133 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
1135 (** [param_pred gv] returns the function list position preceding [After gv].
1136 See the method [llvm::Function::arg_iterator::operator--]. *)
1137 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1140 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1141 of function [fn] in reverse order. Tail recursive. *)
1142 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1144 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1145 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1146 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1148 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1149 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1151 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1152 external remove_param_attr : llvalue -> Attribute.t -> unit
1153 = "llvm_remove_param_attr"
1155 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1156 external set_param_alignment : llvalue -> int -> unit
1157 = "llvm_set_param_alignment"
1159 (** {7 Operations on basic blocks} *)
1161 (** [basic_blocks fn] returns the basic blocks of the function [f].
1162 See the method [llvm::Function::getBasicBlockList]. *)
1163 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
1165 (** [entry_block fn] returns the entry basic block of the function [f].
1166 See the method [llvm::Function::getEntryBlock]. *)
1167 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1169 (** [delete_block bb] deletes the basic block [bb].
1170 See the method [llvm::BasicBlock::eraseFromParent]. *)
1171 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1173 (** [append_block c name f] creates a new basic block named [name] at the end of
1174 function [f] in the context [c].
1175 See the constructor of [llvm::BasicBlock]. *)
1176 external append_block : llcontext -> string -> llvalue -> llbasicblock
1177 = "llvm_append_block"
1179 (** [insert_block c name bb] creates a new basic block named [name] before the
1180 basic block [bb] in the context [c].
1181 See the constructor of [llvm::BasicBlock]. *)
1182 external insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1183 = "llvm_insert_block"
1185 (** [block_parent bb] returns the parent function that owns the basic block.
1186 See the method [llvm::BasicBlock::getParent]. *)
1187 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1189 (** [block_begin f] returns the first position in the basic block list of the
1190 function [f]. [block_begin] and [block_succ] can be used to iterate over
1191 the basic block list in order.
1192 See the method [llvm::Function::begin]. *)
1193 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1194 = "llvm_block_begin"
1196 (** [block_succ bb] returns the basic block list position succeeding
1198 See the method [llvm::Function::iterator::operator++]. *)
1199 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1202 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1203 of function [fn] in order. Tail recursive. *)
1204 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1206 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1207 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1208 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1210 (** [block_end f] returns the last position in the basic block list of
1211 the function [f]. [block_end] and [block_pred] can be used to iterate
1212 over the basic block list in reverse.
1213 See the method [llvm::Function::end]. *)
1214 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1217 (** [block_pred gv] returns the function list position preceding [After gv].
1218 See the method [llvm::Function::iterator::operator--]. *)
1219 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1222 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1223 of function [fn] in reverse order. Tail recursive. *)
1224 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1226 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1227 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1228 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1230 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1231 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1233 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1235 Similar to [llvm::isa<BasicBlock>]. *)
1236 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1238 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1239 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1242 (** {7 Operations on instructions} *)
1244 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1245 See the method [llvm::Instruction::getParent]. *)
1246 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1248 (** [instr_begin bb] returns the first position in the instruction list of the
1249 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1250 the instruction list in order.
1251 See the method [llvm::BasicBlock::begin]. *)
1252 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1253 = "llvm_instr_begin"
1255 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1256 See the method [llvm::BasicBlock::iterator::operator++]. *)
1257 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1260 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1261 block [bb] in order. Tail recursive. *)
1262 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1264 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1265 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1266 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1268 (** [instr_end bb] returns the last position in the instruction list of the
1269 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1270 the instruction list in reverse.
1271 See the method [llvm::BasicBlock::end]. *)
1272 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1275 (** [instr_pred i] returns the instruction list position preceding [After i].
1276 See the method [llvm::BasicBlock::iterator::operator--]. *)
1277 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1280 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1281 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1282 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1285 (** {7 Operations on call sites} *)
1287 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1288 instruction [ci], which may be one of the values from the module
1289 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1290 [llvm::InvokeInst::getCallingConv]. *)
1291 external instruction_call_conv: llvalue -> int
1292 = "llvm_instruction_call_conv"
1294 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1295 or invoke instruction [ci] to the integer [cc], which can be one of the
1296 values from the module {!CallConv}.
1297 See the method [llvm::CallInst::setCallingConv]
1298 and [llvm::InvokeInst::setCallingConv]. *)
1299 external set_instruction_call_conv: int -> llvalue -> unit
1300 = "llvm_set_instruction_call_conv"
1302 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1303 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1305 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1306 = "llvm_add_instruction_param_attr"
1308 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1309 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1311 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1312 = "llvm_remove_instruction_param_attr"
1314 (** {Operations on call instructions (only)} *)
1316 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1317 eligible for tail call optimization, [false] otherwise.
1318 See the method [llvm::CallInst::isTailCall]. *)
1319 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
1321 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1322 call optimization if [tc] is [true], clears otherwise.
1323 See the method [llvm::CallInst::setTailCall]. *)
1324 external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call"
1326 (** {7 Operations on phi nodes} *)
1328 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1329 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1330 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1331 = "llvm_add_incoming"
1333 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1334 See the method [llvm::PHINode::getIncomingValue]. *)
1335 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1339 (** {6 Instruction builders} *)
1341 (** [builder context] creates an instruction builder with no position in
1342 the context [context]. It is invalid to use this builder until its position
1343 is set with {!position_before} or {!position_at_end}. See the constructor
1344 for [llvm::LLVMBuilder]. *)
1345 external builder : llcontext -> llbuilder = "llvm_builder"
1347 (** [builder_at ip] creates an instruction builder positioned at [ip].
1348 See the constructor for [llvm::LLVMBuilder]. *)
1349 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1351 (** [builder_before ins] creates an instruction builder positioned before the
1352 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1353 val builder_before : llcontext -> llvalue -> llbuilder
1355 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1356 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1357 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1359 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1361 See the constructor for [llvm::LLVMBuilder]. *)
1362 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1363 = "llvm_position_builder"
1365 (** [position_before ins b] moves the instruction builder [b] to before the
1366 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1367 val position_before : llvalue -> llbuilder -> unit
1369 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1370 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1371 val position_at_end : llbasicblock -> llbuilder -> unit
1373 (** [insertion_block b] returns the basic block that the builder [b] is
1374 positioned to insert into. Raises [Not_Found] if the instruction builder is
1376 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1377 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1379 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1380 position specified by the instruction builder [b].
1381 See the method [llvm::LLVMBuilder::Insert]. *)
1382 external insert_into_builder : llvalue -> string -> llbuilder -> unit
1383 = "llvm_insert_into_builder"
1386 (** {7 Terminators} *)
1388 (** [build_ret_void b] creates a
1390 instruction at the position specified by the instruction builder [b].
1391 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1392 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1394 (** [build_ret v b] creates a
1396 instruction at the position specified by the instruction builder [b].
1397 See the method [llvm::LLVMBuilder::CreateRet]. *)
1398 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1400 (** [build_aggregate_ret vs b] creates a
1401 [ret {...} { %v1, %v2, ... } ]
1402 instruction at the position specified by the instruction builder [b].
1403 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1404 external build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1405 = "llvm_build_aggregate_ret"
1407 (** [build_br bb b] creates a
1409 instruction at the position specified by the instruction builder [b].
1410 See the method [llvm::LLVMBuilder::CreateBr]. *)
1411 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1413 (** [build_cond_br cond tbb fbb b] creates a
1414 [b %cond, %tbb, %fbb]
1415 instruction at the position specified by the instruction builder [b].
1416 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1417 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1418 llvalue = "llvm_build_cond_br"
1420 (** [build_switch case elsebb count b] creates an empty
1421 [switch %case, %elsebb]
1422 instruction at the position specified by the instruction builder [b] with
1423 space reserved for [count] cases.
1424 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1425 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1426 = "llvm_build_switch"
1428 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1429 when its input matches the constant [onval].
1430 See the method [llvm::SwitchInst::addCase]. **)
1431 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1434 (** [build_invoke fn args tobb unwindbb name b] creates an
1435 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1436 instruction at the position specified by the instruction builder [b].
1437 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1438 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1439 llbasicblock -> string -> llbuilder -> llvalue
1440 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1442 (** [build_unwind b] creates an
1444 instruction at the position specified by the instruction builder [b].
1445 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1446 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1448 (** [build_unreachable b] creates an
1450 instruction at the position specified by the instruction builder [b].
1451 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1452 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1455 (** {7 Arithmetic} *)
1457 (** [build_add x y name b] creates a
1458 [%name = add %x, %y]
1459 instruction at the position specified by the instruction builder [b].
1460 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1461 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1464 (** [build_nswadd x y name b] creates a
1465 [%name = nsw add %x, %y]
1466 instruction at the position specified by the instruction builder [b].
1467 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1468 external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1469 = "llvm_build_nsw_add"
1471 (** [build_fadd x y name b] creates a
1472 [%name = fadd %x, %y]
1473 instruction at the position specified by the instruction builder [b].
1474 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1475 external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1478 (** [build_sub x y name b] creates a
1479 [%name = sub %x, %y]
1480 instruction at the position specified by the instruction builder [b].
1481 See the method [llvm::LLVMBuilder::CreateSub]. *)
1482 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1485 (** [build_fsub x y name b] creates a
1486 [%name = fsub %x, %y]
1487 instruction at the position specified by the instruction builder [b].
1488 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1489 external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1492 (** [build_mul x y name b] creates a
1493 [%name = mul %x, %y]
1494 instruction at the position specified by the instruction builder [b].
1495 See the method [llvm::LLVMBuilder::CreateMul]. *)
1496 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1499 (** [build_fmul x y name b] creates a
1500 [%name = fmul %x, %y]
1501 instruction at the position specified by the instruction builder [b].
1502 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1503 external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1506 (** [build_udiv x y name b] creates a
1507 [%name = udiv %x, %y]
1508 instruction at the position specified by the instruction builder [b].
1509 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1510 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1513 (** [build_sdiv x y name b] creates a
1514 [%name = sdiv %x, %y]
1515 instruction at the position specified by the instruction builder [b].
1516 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1517 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1520 (** [build_exact_sdiv x y name b] creates a
1521 [%name = exact sdiv %x, %y]
1522 instruction at the position specified by the instruction builder [b].
1523 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1524 external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1525 = "llvm_build_exact_sdiv"
1527 (** [build_fdiv x y name b] creates a
1528 [%name = fdiv %x, %y]
1529 instruction at the position specified by the instruction builder [b].
1530 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1531 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1534 (** [build_urem x y name b] creates a
1535 [%name = urem %x, %y]
1536 instruction at the position specified by the instruction builder [b].
1537 See the method [llvm::LLVMBuilder::CreateURem]. *)
1538 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1541 (** [build_SRem x y name b] creates a
1542 [%name = srem %x, %y]
1543 instruction at the position specified by the instruction builder [b].
1544 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1545 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1548 (** [build_frem x y name b] creates a
1549 [%name = frem %x, %y]
1550 instruction at the position specified by the instruction builder [b].
1551 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1552 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1555 (** [build_shl x y name b] creates a
1556 [%name = shl %x, %y]
1557 instruction at the position specified by the instruction builder [b].
1558 See the method [llvm::LLVMBuilder::CreateShl]. *)
1559 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1562 (** [build_lshr x y name b] creates a
1563 [%name = lshr %x, %y]
1564 instruction at the position specified by the instruction builder [b].
1565 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1566 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1569 (** [build_ashr x y name b] creates a
1570 [%name = ashr %x, %y]
1571 instruction at the position specified by the instruction builder [b].
1572 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1573 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1576 (** [build_and x y name b] creates a
1577 [%name = and %x, %y]
1578 instruction at the position specified by the instruction builder [b].
1579 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1580 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1583 (** [build_or x y name b] creates a
1585 instruction at the position specified by the instruction builder [b].
1586 See the method [llvm::LLVMBuilder::CreateOr]. *)
1587 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1590 (** [build_xor x y name b] creates a
1591 [%name = xor %x, %y]
1592 instruction at the position specified by the instruction builder [b].
1593 See the method [llvm::LLVMBuilder::CreateXor]. *)
1594 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1597 (** [build_neg x name b] creates a
1599 instruction at the position specified by the instruction builder [b].
1600 [-0.0] is used for floating point types to compute the correct sign.
1601 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1602 external build_neg : llvalue -> string -> llbuilder -> llvalue
1605 (** [build_xor x name b] creates a
1606 [%name = xor %x, -1]
1607 instruction at the position specified by the instruction builder [b].
1608 [-1] is the correct "all ones" value for the type of [x].
1609 See the method [llvm::LLVMBuilder::CreateXor]. *)
1610 external build_not : llvalue -> string -> llbuilder -> llvalue
1616 (** [build_malloc ty name b] creates a
1617 [%name = malloc %ty]
1618 instruction at the position specified by the instruction builder [b].
1619 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1620 external build_malloc : lltype -> string -> llbuilder -> llvalue
1621 = "llvm_build_malloc"
1623 (** [build_array_malloc ty n name b] creates a
1624 [%name = malloc %ty, %n]
1625 instruction at the position specified by the instruction builder [b].
1626 See the method [llvm::LLVMBuilder::CreateMalloc]. *)
1627 external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1628 llvalue = "llvm_build_array_malloc"
1630 (** [build_alloca ty name b] creates a
1631 [%name = alloca %ty]
1632 instruction at the position specified by the instruction builder [b].
1633 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1634 external build_alloca : lltype -> string -> llbuilder -> llvalue
1635 = "llvm_build_alloca"
1637 (** [build_array_alloca ty n name b] creates a
1638 [%name = alloca %ty, %n]
1639 instruction at the position specified by the instruction builder [b].
1640 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1641 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1642 llvalue = "llvm_build_array_alloca"
1644 (** [build_free v b] creates a
1646 instruction at the position specified by the instruction builder [b].
1647 See the method [llvm::LLVMBuilder::CreateFree]. *)
1648 external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1650 (** [build_load v name b] creates a
1652 instruction at the position specified by the instruction builder [b].
1653 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1654 external build_load : llvalue -> string -> llbuilder -> llvalue
1657 (** [build_store v p b] creates a
1659 instruction at the position specified by the instruction builder [b].
1660 See the method [llvm::LLVMBuilder::CreateStore]. *)
1661 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1662 = "llvm_build_store"
1664 (** [build_gep p indices name b] creates a
1665 [%name = getelementptr %p, indices...]
1666 instruction at the position specified by the instruction builder [b].
1667 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1668 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1671 (** [build_in_bounds_gep p indices name b] creates a
1672 [%name = gelementptr inbounds %p, indices...]
1673 instruction at the position specified by the instruction builder [b].
1674 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1675 external build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1676 llvalue = "llvm_build_in_bounds_gep"
1678 (** [build_struct_gep p idx name b] creates a
1679 [%name = getelementptr %p, 0, idx]
1680 instruction at the position specified by the instruction builder [b].
1681 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1682 external build_struct_gep : llvalue -> int -> string -> llbuilder ->
1683 llvalue = "llvm_build_struct_gep"
1685 (** [build_global_string str name b] creates a series of instructions that adds
1686 a global string at the position specified by the instruction builder [b].
1687 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1688 external build_global_string : string -> string -> llbuilder -> llvalue
1689 = "llvm_build_global_string"
1691 (** [build_global_stringptr str name b] creates a series of instructions that
1692 adds a global string pointer at the position specified by the instruction
1694 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1695 external build_global_stringptr : string -> string -> llbuilder -> llvalue
1696 = "llvm_build_global_stringptr"
1701 (** [build_trunc v ty name b] creates a
1702 [%name = trunc %p to %ty]
1703 instruction at the position specified by the instruction builder [b].
1704 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1705 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1706 = "llvm_build_trunc"
1708 (** [build_zext v ty name b] creates a
1709 [%name = zext %p to %ty]
1710 instruction at the position specified by the instruction builder [b].
1711 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1712 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1715 (** [build_sext v ty name b] creates a
1716 [%name = sext %p to %ty]
1717 instruction at the position specified by the instruction builder [b].
1718 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1719 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1722 (** [build_fptoui v ty name b] creates a
1723 [%name = fptoui %p to %ty]
1724 instruction at the position specified by the instruction builder [b].
1725 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1726 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1727 = "llvm_build_fptoui"
1729 (** [build_fptosi v ty name b] creates a
1730 [%name = fptosi %p to %ty]
1731 instruction at the position specified by the instruction builder [b].
1732 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1733 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1734 = "llvm_build_fptosi"
1736 (** [build_uitofp v ty name b] creates a
1737 [%name = uitofp %p to %ty]
1738 instruction at the position specified by the instruction builder [b].
1739 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1740 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1741 = "llvm_build_uitofp"
1743 (** [build_sitofp v ty name b] creates a
1744 [%name = sitofp %p to %ty]
1745 instruction at the position specified by the instruction builder [b].
1746 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1747 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1748 = "llvm_build_sitofp"
1750 (** [build_fptrunc v ty name b] creates a
1751 [%name = fptrunc %p to %ty]
1752 instruction at the position specified by the instruction builder [b].
1753 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1754 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1755 = "llvm_build_fptrunc"
1757 (** [build_fpext v ty name b] creates a
1758 [%name = fpext %p to %ty]
1759 instruction at the position specified by the instruction builder [b].
1760 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1761 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1762 = "llvm_build_fpext"
1764 (** [build_ptrtoint v ty name b] creates a
1765 [%name = prtotint %p to %ty]
1766 instruction at the position specified by the instruction builder [b].
1767 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1768 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1769 = "llvm_build_prttoint"
1771 (** [build_inttoptr v ty name b] creates a
1772 [%name = inttoptr %p to %ty]
1773 instruction at the position specified by the instruction builder [b].
1774 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1775 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1776 = "llvm_build_inttoptr"
1778 (** [build_bitcast v ty name b] creates a
1779 [%name = bitcast %p to %ty]
1780 instruction at the position specified by the instruction builder [b].
1781 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
1782 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1783 = "llvm_build_bitcast"
1785 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
1786 instruction at the position specified by the instruction builder [b].
1787 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1788 external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1789 llvalue = "llvm_build_zext_or_bitcast"
1791 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
1792 instruction at the position specified by the instruction builder [b].
1793 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
1794 external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1795 llvalue = "llvm_build_sext_or_bitcast"
1797 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
1798 instruction at the position specified by the instruction builder [b].
1799 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1800 external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1801 llvalue = "llvm_build_trunc_or_bitcast"
1803 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
1804 instruction at the position specified by the instruction builder [b].
1805 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
1806 external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
1807 = "llvm_build_pointercast"
1809 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
1810 instruction at the position specified by the instruction builder [b].
1811 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
1812 external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1813 = "llvm_build_intcast"
1815 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
1816 instruction at the position specified by the instruction builder [b].
1817 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
1818 external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1819 = "llvm_build_fpcast"
1822 (** {7 Comparisons} *)
1824 (** [build_icmp pred x y name b] creates a
1825 [%name = icmp %pred %x, %y]
1826 instruction at the position specified by the instruction builder [b].
1827 See the method [llvm::LLVMBuilder::CreateICmp]. *)
1828 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1829 llbuilder -> llvalue = "llvm_build_icmp"
1831 (** [build_fcmp pred x y name b] creates a
1832 [%name = fcmp %pred %x, %y]
1833 instruction at the position specified by the instruction builder [b].
1834 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1835 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1836 llbuilder -> llvalue = "llvm_build_fcmp"
1839 (** {7 Miscellaneous instructions} *)
1841 (** [build_phi incoming name b] creates a
1842 [%name = phi %incoming]
1843 instruction at the position specified by the instruction builder [b].
1844 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1845 See the method [llvm::LLVMBuilder::CreatePHI]. *)
1846 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1847 llvalue = "llvm_build_phi"
1849 (** [build_call fn args name b] creates a
1850 [%name = call %fn(args...)]
1851 instruction at the position specified by the instruction builder [b].
1852 See the method [llvm::LLVMBuilder::CreateCall]. *)
1853 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1856 (** [build_select cond thenv elsev name b] creates a
1857 [%name = select %cond, %thenv, %elsev]
1858 instruction at the position specified by the instruction builder [b].
1859 See the method [llvm::LLVMBuilder::CreateSelect]. *)
1860 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1861 llvalue = "llvm_build_select"
1863 (** [build_va_arg valist argty name b] creates a
1864 [%name = va_arg %valist, %argty]
1865 instruction at the position specified by the instruction builder [b].
1866 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1867 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1868 = "llvm_build_va_arg"
1870 (** [build_extractelement vec i name b] creates a
1871 [%name = extractelement %vec, %i]
1872 instruction at the position specified by the instruction builder [b].
1873 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1874 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1875 llvalue = "llvm_build_extractelement"
1877 (** [build_insertelement vec elt i name b] creates a
1878 [%name = insertelement %vec, %elt, %i]
1879 instruction at the position specified by the instruction builder [b].
1880 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1881 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1882 llbuilder -> llvalue = "llvm_build_insertelement"
1884 (** [build_shufflevector veca vecb mask name b] creates a
1885 [%name = shufflevector %veca, %vecb, %mask]
1886 instruction at the position specified by the instruction builder [b].
1887 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1888 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1889 llbuilder -> llvalue = "llvm_build_shufflevector"
1891 (** [build_insertvalue agg idx name b] creates a
1892 [%name = extractvalue %agg, %idx]
1893 instruction at the position specified by the instruction builder [b].
1894 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
1895 external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
1896 = "llvm_build_extractvalue"
1898 (** [build_insertvalue agg val idx name b] creates a
1899 [%name = insertvalue %agg, %val, %idx]
1900 instruction at the position specified by the instruction builder [b].
1901 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
1902 external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
1903 llvalue = "llvm_build_insertvalue"
1905 (** [build_is_null val name b] creates a
1906 [%name = icmp eq %val, null]
1907 instruction at the position specified by the instruction builder [b].
1908 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
1909 external build_is_null : llvalue -> string -> llbuilder -> llvalue
1910 = "llvm_build_is_null"
1912 (** [build_is_not_null val name b] creates a
1913 [%name = icmp ne %val, null]
1914 instruction at the position specified by the instruction builder [b].
1915 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
1916 external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
1917 = "llvm_build_is_not_null"
1919 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
1920 the difference between two pointer values at the position specified by the
1921 instruction builder [b].
1922 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
1923 external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
1924 = "llvm_build_ptrdiff"
1926 (** {6 Module providers} *)
1928 module ModuleProvider : sig
1929 (** [create_module_provider m] encapsulates [m] in a module provider and takes
1930 ownership of the module. See the constructor
1931 [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
1932 external create : llmodule -> llmoduleprovider
1933 = "LLVMCreateModuleProviderForExistingModule"
1935 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1936 the contained module. *)
1937 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1941 (** {6 Memory buffers} *)
1943 module MemoryBuffer : sig
1944 (** [of_file p] is the memory buffer containing the contents of the file at
1945 path [p]. If the file could not be read, then [IoError msg] is
1947 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1949 (** [stdin ()] is the memory buffer containing the contents of standard input.
1950 If standard input is empty, then [IoError msg] is raised. *)
1951 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1953 (** Disposes of a memory buffer. *)
1954 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
1958 (** {6 Pass Managers} *)
1960 module PassManager : sig
1963 type any = [ `Module | `Function ]
1965 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
1966 type of pipeline is suitable for link-time optimization and whole-module
1968 See the constructor of [llvm::PassManager]. *)
1969 external create : unit -> [ `Module ] t = "llvm_passmanager_create"
1971 (** [PassManager.create_function mp] constructs a new function-by-function
1972 pass pipeline over the module provider [mp]. It does not take ownership of
1973 [mp]. This type of pipeline is suitable for code generation and JIT
1975 See the constructor of [llvm::FunctionPassManager]. *)
1976 external create_function : llmoduleprovider -> [ `Function ] t
1977 = "LLVMCreateFunctionPassManager"
1979 (** [run_module m pm] initializes, executes on the module [m], and finalizes
1980 all of the passes scheduled in the pass manager [pm]. Returns [true] if
1981 any of the passes modified the module, [false] otherwise.
1982 See the [llvm::PassManager::run] method. *)
1983 external run_module : llmodule -> [ `Module ] t -> bool
1984 = "llvm_passmanager_run_module"
1986 (** [initialize fpm] initializes all of the function passes scheduled in the
1987 function pass manager [fpm]. Returns [true] if any of the passes modified
1988 the module, [false] otherwise.
1989 See the [llvm::FunctionPassManager::doInitialization] method. *)
1990 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
1992 (** [run_function f fpm] executes all of the function passes scheduled in the
1993 function pass manager [fpm] over the function [f]. Returns [true] if any
1994 of the passes modified [f], [false] otherwise.
1995 See the [llvm::FunctionPassManager::run] method. *)
1996 external run_function : llvalue -> [ `Function ] t -> bool
1997 = "llvm_passmanager_run_function"
1999 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2000 function pass manager [fpm]. Returns [true] if any of the passes
2001 modified the module, [false] otherwise.
2002 See the [llvm::FunctionPassManager::doFinalization] method. *)
2003 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
2005 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2006 the module provider.
2007 See the destructor of [llvm::BasePassManager]. *)
2008 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"