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. *)
79 (** The linkage of a global value, accessed with {!linkage} and
80 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
84 | Available_externally
100 (** The linker visibility of a global value, accessed with {!visibility} and
101 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
102 module Visibility : sig
109 (** The following calling convention values may be accessed with
110 {!function_call_conv} and {!set_function_call_conv}. Calling
111 conventions are open-ended. *)
112 module CallConv : sig
113 val c : int (** [c] is the C calling convention. *)
114 val fast : int (** [fast] is the calling convention to allow LLVM
115 maximum optimization opportunities. Use only with
117 val cold : int (** [cold] is the calling convention for
119 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling
120 convention from C. *)
121 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
122 convention from C. *)
125 module Attribute : sig
150 (** The predicate for an integer comparison ([icmp]) instruction.
151 See the [llvm::ICmpInst::Predicate] enumeration. *)
166 (** The predicate for a floating-point comparison ([fcmp]) instruction.
167 See the [llvm::FCmpInst::Predicate] enumeration. *)
191 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
192 of [a]. [llpos] is used to specify positions in and for forward iteration
193 through the various value lists maintained by the LLVM IR. *)
194 type ('a, 'b) llpos =
198 (** [After b] and [At_start a] specify positions from the end of the ['b] list
199 of [a]. [llrev_pos] is used for reverse iteration through the various value
200 lists maintained by the LLVM IR. *)
201 type ('a, 'b) llrev_pos =
206 (** {6 Exceptions} *)
208 exception IoError of string
213 (** [create_context ()] creates a context for storing the "global" state in
214 LLVM. See the constructor [llvm::LLVMContext]. *)
215 external create_context : unit -> llcontext = "llvm_create_context"
217 (** [destroy_context ()] destroys a context. See the destructor
218 [llvm::LLVMContext::~LLVMContext]. *)
219 external dispose_context : llcontext -> unit = "llvm_dispose_context"
221 (** See the function [llvm::getGlobalContext]. *)
222 external global_context : unit -> llcontext = "llvm_global_context"
227 (** [create_module context id] creates a module with the supplied module ID in
228 the context [context]. Modules are not garbage collected; it is mandatory
229 to call {!dispose_module} to free memory. See the constructor
230 [llvm::Module::Module]. *)
231 external create_module : llcontext -> string -> llmodule = "llvm_create_module"
233 (** [dispose_module m] destroys a module [m] and all of the IR objects it
234 contained. All references to subordinate objects are invalidated;
235 referencing them will invoke undefined behavior. See the destructor
236 [llvm::Module::~Module]. *)
237 external dispose_module : llmodule -> unit = "llvm_dispose_module"
239 (** [target_triple m] is the target specifier for the module [m], something like
240 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
241 external target_triple: llmodule -> string
242 = "llvm_target_triple"
244 (** [target_triple triple m] changes the target specifier for the module [m] to
245 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
246 external set_target_triple: string -> llmodule -> unit
247 = "llvm_set_target_triple"
249 (** [data_layout m] is the data layout specifier for the module [m], something
250 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
251 method [llvm::Module::getDataLayout]. *)
252 external data_layout: llmodule -> string
255 (** [set_data_layout s m] changes the data layout specifier for the module [m]
256 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
257 external set_data_layout: string -> llmodule -> unit
258 = "llvm_set_data_layout"
260 (** [define_type_name name ty m] adds a named type to the module's symbol table.
261 Returns [true] if successful. If such a name already exists, then no entry
262 is added and [false] is returned. See the [llvm::Module::addTypeName]
264 external define_type_name : string -> lltype -> llmodule -> bool
265 = "llvm_add_type_name"
267 (** [delete_type_name name] removes a type name from the module's symbol
269 external delete_type_name : string -> llmodule -> unit
270 = "llvm_delete_type_name"
272 (** [dump_module m] prints the .ll representation of the module [m] to standard
273 error. See the method [llvm::Module::dump]. *)
274 external dump_module : llmodule -> unit = "llvm_dump_module"
279 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
280 See the method [llvm::Type::getTypeID]. *)
281 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
283 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
284 See the method [llvm::Type::getContext]. *)
285 external type_context : lltype -> llcontext = "llvm_type_context"
287 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
288 val string_of_lltype : lltype -> string
290 (** {7 Operations on integer types} *)
292 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
293 [llvm::Type::Int1Ty]. *)
294 external i1_type : llcontext -> lltype = "llvm_i1_type"
296 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
297 [llvm::Type::Int8Ty]. *)
298 external i8_type : llcontext -> lltype = "llvm_i8_type"
300 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
301 [llvm::Type::Int16Ty]. *)
302 external i16_type : llcontext -> lltype = "llvm_i16_type"
304 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
305 [llvm::Type::Int32Ty]. *)
306 external i32_type : llcontext -> lltype = "llvm_i32_type"
308 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
309 [llvm::Type::Int64Ty]. *)
310 external i64_type : llcontext -> lltype = "llvm_i64_type"
312 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
313 [c]. See the method [llvm::IntegerType::get]. *)
314 external integer_type : llcontext -> int -> lltype = "llvm_integer_type"
316 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
317 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
318 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
321 (** {7 Operations on real types} *)
323 (** [float_type c] returns the IEEE 32-bit floating point type in the context
324 [c]. See [llvm::Type::FloatTy]. *)
325 external float_type : llcontext -> lltype = "llvm_float_type"
327 (** [double_type c] returns the IEEE 64-bit floating point type in the context
328 [c]. See [llvm::Type::DoubleTy]. *)
329 external double_type : llcontext -> lltype = "llvm_double_type"
331 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
332 [c]. See [llvm::Type::X86_FP80Ty]. *)
333 external x86fp80_type : llcontext -> lltype = "llvm_x86fp80_type"
335 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
336 [c]. See [llvm::Type::FP128Ty]. *)
337 external fp128_type : llcontext -> lltype = "llvm_fp128_type"
339 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
340 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
341 external ppc_fp128_type : llcontext -> lltype = "llvm_ppc_fp128_type"
344 (** {7 Operations on function types} *)
346 (** [function_type ret_ty param_tys] returns the function type returning
347 [ret_ty] and taking [param_tys] as parameters.
348 See the method [llvm::FunctionType::get]. *)
349 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
351 (** [va_arg_function_type ret_ty param_tys] is just like
352 [function_type ret_ty param_tys] except that it returns the function type
353 which also takes a variable number of arguments.
354 See the method [llvm::FunctionType::get]. *)
355 external var_arg_function_type : lltype -> lltype array -> lltype
356 = "llvm_var_arg_function_type"
358 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
359 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
360 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
362 (** [return_type fty] gets the return type of the function type [fty].
363 See the method [llvm::FunctionType::getReturnType]. *)
364 external return_type : lltype -> lltype = "LLVMGetReturnType"
366 (** [param_types fty] gets the parameter types of the function type [fty].
367 See the method [llvm::FunctionType::getParamType]. *)
368 external param_types : lltype -> lltype array = "llvm_param_types"
371 (** {7 Operations on struct types} *)
373 (** [struct_type context tys] returns the structure type in the context
374 [context] containing in the types in the array [tys]. See the method
375 [llvm::StructType::get]. *)
376 external struct_type : llcontext -> lltype array -> lltype
379 (** [packed_struct_type context ys] returns the packed structure type in the
380 context [context] containing in the types in the array [tys]. See the method
381 [llvm::StructType::get]. *)
382 external packed_struct_type : llcontext -> lltype array -> lltype
383 = "llvm_packed_struct_type"
385 (** [struct_element_types sty] returns the constituent types of the struct type
386 [sty]. See the method [llvm::StructType::getElementType]. *)
387 external struct_element_types : lltype -> lltype array
388 = "llvm_struct_element_types"
390 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
391 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
392 external is_packed : lltype -> bool = "llvm_is_packed"
395 (** {7 Operations on union types} *)
397 (** [union_type context tys] returns the union type in the context [context]
398 containing the types in the array [tys]. See the method
399 [llvm::UnionType::get] *)
400 external union_type : llcontext -> lltype array -> lltype = "llvm_union_type"
402 (** [union_element_types uty] returns the constituent types of the union type
403 [uty]. See the method [llvm::UnionType::getElementType]. *)
404 external union_element_types : lltype -> lltype array
405 = "llvm_union_element_types"
408 (** {7 Operations on pointer, vector, and array types} *)
410 (** [array_type ty n] returns the array type containing [n] elements of type
411 [ty]. See the method [llvm::ArrayType::get]. *)
412 external array_type : lltype -> int -> lltype = "llvm_array_type"
414 (** [pointer_type ty] returns the pointer type referencing objects of type
415 [ty] in the default address space (0).
416 See the method [llvm::PointerType::getUnqual]. *)
417 external pointer_type : lltype -> lltype = "llvm_pointer_type"
419 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
420 of type [ty] in address space [as].
421 See the method [llvm::PointerType::get]. *)
422 external qualified_pointer_type : lltype -> int -> lltype
423 = "llvm_qualified_pointer_type"
425 (** [vector_type ty n] returns the array type containing [n] elements of the
426 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
427 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
429 (** [element_type ty] returns the element type of the pointer, vector, or array
430 type [ty]. See the method [llvm::SequentialType::get]. *)
431 external element_type : lltype -> lltype = "LLVMGetElementType"
433 (** [element_type aty] returns the element count of the array type [aty].
434 See the method [llvm::ArrayType::getNumElements]. *)
435 external array_length : lltype -> int = "llvm_array_length"
437 (** [address_space pty] returns the address space qualifier of the pointer type
438 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
439 external address_space : lltype -> int = "llvm_address_space"
441 (** [element_type ty] returns the element count of the vector type [ty].
442 See the method [llvm::VectorType::getNumElements]. *)
443 external vector_size : lltype -> int = "llvm_vector_size"
446 (** {7 Operations on other types} *)
448 (** [opaque_type c] creates a new opaque type distinct from any other in the
449 context [c]. Opaque types are useful for building recursive types in
450 combination with {!refine_type}. See [llvm::OpaqueType::get]. *)
451 external opaque_type : llcontext -> lltype = "llvm_opaque_type"
453 (** [void_type c] creates a type of a function which does not return any
454 value in the context [c]. See [llvm::Type::VoidTy]. *)
455 external void_type : llcontext -> lltype = "llvm_void_type"
457 (** [label_type c] creates a type of a basic block in the context [c]. See
458 [llvm::Type::LabelTy]. *)
459 external label_type : llcontext -> lltype = "llvm_label_type"
461 (** {7 Operations on type handles} *)
463 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
464 refined as a result of a call to {!refine_type}, the handle will be updated;
465 any bare [lltype] references will become invalid.
466 See the class [llvm::PATypeHolder]. *)
467 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
469 (** [type_of_handle tyh] resolves the type handle [tyh].
470 See the method [llvm::PATypeHolder::get()]. *)
471 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
473 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
474 concrete type [ty] in all users. Warning: This may invalidate {!lltype}
475 values! Use {!lltypehandle} to manipulate potentially abstract types. See
476 the method [llvm::Type::refineAbstractType]. *)
477 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
482 (** [type_of v] returns the type of the value [v].
483 See the method [llvm::Value::getType]. *)
484 external type_of : llvalue -> lltype = "llvm_type_of"
486 (** [value_name v] returns the name of the value [v]. For global values, this is
487 the symbol name. For instructions and basic blocks, it is the SSA register
488 name. It is meaningless for constants.
489 See the method [llvm::Value::getName]. *)
490 external value_name : llvalue -> string = "llvm_value_name"
492 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
493 [llvm::Value::setName]. *)
494 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
496 (** [dump_value v] prints the .ll representation of the value [v] to standard
497 error. See the method [llvm::Value::dump]. *)
498 external dump_value : llvalue -> unit = "llvm_dump_value"
501 (** {7 Operations on constants of (mostly) any type} *)
503 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
504 otherwise. Similar to [llvm::isa<Constant>]. *)
505 external is_constant : llvalue -> bool = "llvm_is_constant"
507 (** [const_null ty] returns the constant null (zero) of the type [ty].
508 See the method [llvm::Constant::getNullValue]. *)
509 external const_null : lltype -> llvalue = "LLVMConstNull"
511 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
512 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
513 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
515 (** [undef ty] returns the undefined value of the type [ty].
516 See the method [llvm::UndefValue::get]. *)
517 external undef : lltype -> llvalue = "LLVMGetUndef"
519 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
520 See the method [llvm::Constant::isNullValue]. *)
521 external is_null : llvalue -> bool = "llvm_is_null"
523 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
524 otherwise. Similar to [llvm::isa<UndefValue>]. *)
525 external is_undef : llvalue -> bool = "llvm_is_undef"
528 (** {7 Operations on scalar constants} *)
530 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
531 See the method [llvm::ConstantInt::get]. *)
532 external const_int : lltype -> int -> llvalue = "llvm_const_int"
534 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
535 [i]. See the method [llvm::ConstantInt::get]. *)
536 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
537 = "llvm_const_of_int64"
539 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
540 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
541 external const_int_of_string : lltype -> string -> int -> llvalue
542 = "llvm_const_int_of_string"
544 (** [const_float ty n] returns the floating point constant of type [ty] and
545 value [n]. See the method [llvm::ConstantFP::get]. *)
546 external const_float : lltype -> float -> llvalue = "llvm_const_float"
548 (** [const_float_of_string ty s] returns the floating point constant of type
549 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
550 external const_float_of_string : lltype -> string -> llvalue
551 = "llvm_const_float_of_string"
554 (** {7 Operations on composite constants} *)
556 (** [const_string c s] returns the constant [i8] array with the values of the
557 characters in the string [s] in the context [c]. The array is not
558 null-terminated (but see {!const_stringz}). This value can in turn be used
559 as the initializer for a global variable. See the method
560 [llvm::ConstantArray::get]. *)
561 external const_string : llcontext -> string -> llvalue = "llvm_const_string"
563 (** [const_stringz c s] returns the constant [i8] array with the values of the
564 characters in the string [s] and a null terminator in the context [c]. This
565 value can in turn be used as the initializer for a global variable.
566 See the method [llvm::ConstantArray::get]. *)
567 external const_stringz : llcontext -> string -> llvalue = "llvm_const_stringz"
569 (** [const_array ty elts] returns the constant array of type
570 [array_type ty (Array.length elts)] and containing the values [elts].
571 This value can in turn be used as the initializer for a global variable.
572 See the method [llvm::ConstantArray::get]. *)
573 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
575 (** [const_struct context elts] returns the structured constant of type
576 [struct_type (Array.map type_of elts)] and containing the values [elts]
577 in the context [context]. This value can in turn be used as the initializer
578 for a global variable. See the method [llvm::ConstantStruct::get]. *)
579 external const_struct : llcontext -> llvalue array -> llvalue
580 = "llvm_const_struct"
582 (** [const_packed_struct context elts] returns the structured constant of
583 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
584 values [elts] in the context [context]. This value can in turn be used as
585 the initializer for a global variable. See the method
586 [llvm::ConstantStruct::get]. *)
587 external const_packed_struct : llcontext -> llvalue array -> llvalue
588 = "llvm_const_packed_struct"
590 (** [const_vector elts] returns the vector constant of type
591 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
592 values [elts]. See the method [llvm::ConstantVector::get]. *)
593 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
595 (** [const_union ty v] returns the union constant of type [union_type tys] and
596 containing the value [v]. See the method [llvm::ConstantUnion::get]. *)
597 external const_union : lltype -> llvalue -> llvalue = "LLVMConstUnion"
600 (** {7 Constant expressions} *)
602 (** [align_of ty] returns the alignof constant for the type [ty]. This is
603 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
604 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
605 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
606 external align_of : lltype -> llvalue = "LLVMAlignOf"
608 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
609 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
610 (const_int i32_type 1)) i64_type], but considerably more readable.
611 See the method [llvm::ConstantExpr::getSizeOf]. *)
612 external size_of : lltype -> llvalue = "LLVMSizeOf"
614 (** [const_neg c] returns the arithmetic negation of the constant [c].
615 See the method [llvm::ConstantExpr::getNeg]. *)
616 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
618 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
619 See the method [llvm::ConstantExpr::getFNeg]. *)
620 external const_fneg : llvalue -> llvalue = "LLVMConstFNeg"
622 (** [const_not c] returns the bitwise inverse of the constant [c].
623 See the method [llvm::ConstantExpr::getNot]. *)
624 external const_not : llvalue -> llvalue = "LLVMConstNot"
626 (** [const_add c1 c2] returns the constant sum of two constants.
627 See the method [llvm::ConstantExpr::getAdd]. *)
628 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
630 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
631 signed wrapping. The result is undefined if the sum overflows.
632 See the method [llvm::ConstantExpr::getNSWAdd]. *)
633 external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd"
635 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
636 See the method [llvm::ConstantExpr::getFAdd]. *)
637 external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd"
639 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
640 constants. See the method [llvm::ConstantExpr::getSub]. *)
641 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
643 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
644 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
645 external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub"
647 (** [const_mul c1 c2] returns the constant product of two constants.
648 See the method [llvm::ConstantExpr::getMul]. *)
649 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
651 (** [const_fmul c1 c2] returns the constant product of two constants floats.
652 See the method [llvm::ConstantExpr::getFMul]. *)
653 external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul"
655 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
657 See the method [llvm::ConstantExpr::getUDiv]. *)
658 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
660 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
662 See the method [llvm::ConstantExpr::getSDiv]. *)
663 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
665 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
666 signed integer constants. The result is undefined if the result is rounded
667 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
668 external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv"
670 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
672 See the method [llvm::ConstantExpr::getFDiv]. *)
673 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
675 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
676 unsigned integer constants.
677 See the method [llvm::ConstantExpr::getURem]. *)
678 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
680 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
681 signed integer constants.
682 See the method [llvm::ConstantExpr::getSRem]. *)
683 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
685 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
686 signed floating point constants.
687 See the method [llvm::ConstantExpr::getFRem]. *)
688 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
690 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
692 See the method [llvm::ConstantExpr::getAnd]. *)
693 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
695 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
697 See the method [llvm::ConstantExpr::getOr]. *)
698 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
700 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
702 See the method [llvm::ConstantExpr::getXor]. *)
703 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
705 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
706 constants, [c1 pred c2].
707 See the method [llvm::ConstantExpr::getICmp]. *)
708 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
711 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
712 point constants, [c1 pred c2].
713 See the method [llvm::ConstantExpr::getFCmp]. *)
714 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
717 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
718 constant integer [c2].
719 See the method [llvm::ConstantExpr::getShl]. *)
720 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
722 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
723 constant integer [c2] with zero extension.
724 See the method [llvm::ConstantExpr::getLShr]. *)
725 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
727 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
728 constant integer [c2] with sign extension.
729 See the method [llvm::ConstantExpr::getAShr]. *)
730 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
732 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
733 constant integers indices from the array [indices].
734 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
735 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
737 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
738 with the constant integers indices from the array [indices].
739 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
740 external const_in_bounds_gep : llvalue -> llvalue array -> llvalue
741 = "llvm_const_in_bounds_gep"
743 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
744 to the smaller integer type [ty].
745 See the method [llvm::ConstantExpr::getTrunc]. *)
746 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
748 (** [const_sext c ty] returns the constant sign extension of integer constant
749 [c] to the larger integer type [ty].
750 See the method [llvm::ConstantExpr::getSExt]. *)
751 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
753 (** [const_zext c ty] returns the constant zero extension of integer constant
754 [c] to the larger integer type [ty].
755 See the method [llvm::ConstantExpr::getZExt]. *)
756 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
758 (** [const_fptrunc c ty] returns the constant truncation of floating point
759 constant [c] to the smaller floating point type [ty].
760 See the method [llvm::ConstantExpr::getFPTrunc]. *)
761 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
763 (** [const_fpext c ty] returns the constant extension of floating point constant
764 [c] to the larger floating point type [ty].
765 See the method [llvm::ConstantExpr::getFPExt]. *)
766 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
768 (** [const_uitofp c ty] returns the constant floating point conversion of
769 unsigned integer constant [c] to the floating point type [ty].
770 See the method [llvm::ConstantExpr::getUIToFP]. *)
771 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
773 (** [const_sitofp c ty] returns the constant floating point conversion of
774 signed integer constant [c] to the floating point type [ty].
775 See the method [llvm::ConstantExpr::getSIToFP]. *)
776 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
778 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
779 floating point constant [c] to integer type [ty].
780 See the method [llvm::ConstantExpr::getFPToUI]. *)
781 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
783 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
784 floating point constant [c] to integer type [ty].
785 See the method [llvm::ConstantExpr::getFPToSI]. *)
786 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
788 (** [const_ptrtoint c ty] returns the constant integer conversion of
789 pointer constant [c] to integer type [ty].
790 See the method [llvm::ConstantExpr::getPtrToInt]. *)
791 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
793 (** [const_inttoptr c ty] returns the constant pointer conversion of
794 integer constant [c] to pointer type [ty].
795 See the method [llvm::ConstantExpr::getIntToPtr]. *)
796 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
798 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
799 to type [ty] of equal size.
800 See the method [llvm::ConstantExpr::getBitCast]. *)
801 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
803 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
804 conversion of constant [c] to type [ty].
805 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
806 external const_zext_or_bitcast : llvalue -> lltype -> llvalue
807 = "LLVMConstZExtOrBitCast"
809 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
810 conversion of constant [c] to type [ty].
811 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
812 external const_sext_or_bitcast : llvalue -> lltype -> llvalue
813 = "LLVMConstSExtOrBitCast"
815 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
816 conversion of constant [c] to type [ty].
817 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
818 external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
819 = "LLVMConstTruncOrBitCast"
821 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
822 cast conversion of constant [c] to type [ty] of equal size.
823 See the method [llvm::ConstantExpr::getPointerCast]. *)
824 external const_pointercast : llvalue -> lltype -> llvalue
825 = "LLVMConstPointerCast"
827 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
828 -> integer casts of constant [c] to type [ty].
829 See the method [llvm::ConstantExpr::getIntCast]. *)
830 external const_intcast : llvalue -> lltype -> llvalue
833 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
834 fp casts of constant [c] to type [ty].
835 See the method [llvm::ConstantExpr::getFPCast]. *)
836 external const_fpcast : llvalue -> lltype -> llvalue
839 (** [const_select cond t f] returns the constant conditional which returns value
840 [t] if the boolean constant [cond] is true and the value [f] otherwise.
841 See the method [llvm::ConstantExpr::getSelect]. *)
842 external const_select : llvalue -> llvalue -> llvalue -> llvalue
845 (** [const_extractelement vec i] returns the constant [i]th element of
846 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
847 the size of the vector.
848 See the method [llvm::ConstantExpr::getExtractElement]. *)
849 external const_extractelement : llvalue -> llvalue -> llvalue
850 = "LLVMConstExtractElement"
852 (** [const_insertelement vec v i] returns the constant vector with the same
853 elements as constant vector [v] but the [i]th element replaced by the
854 constant [v]. [v] must be a constant value with the type of the vector
855 elements. [i] must be a constant [i32] value unsigned less than the size
857 See the method [llvm::ConstantExpr::getInsertElement]. *)
858 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
859 = "LLVMConstInsertElement"
861 (** [const_shufflevector a b mask] returns a constant [shufflevector].
862 See the LLVM Language Reference for details on the [sufflevector]
864 See the method [llvm::ConstantExpr::getShuffleVector]. *)
865 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
866 = "LLVMConstShuffleVector"
868 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
869 constant aggregate [agg]. Each [idxs] must be less than the size of the
870 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
871 external const_extractvalue : llvalue -> int array -> llvalue
872 = "llvm_const_extractvalue"
874 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
875 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
876 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
877 external const_insertvalue : llvalue -> llvalue -> int array -> llvalue
878 = "llvm_const_insertvalue"
881 (** {7 Operations on global variables, functions, and aliases (globals)} *)
883 (** [global_parent g] is the enclosing module of the global value [g].
884 See the method [llvm::GlobalValue::getParent]. *)
885 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
887 (** [is_declaration g] returns [true] if the global value [g] is a declaration
888 only. Returns [false] otherwise.
889 See the method [llvm::GlobalValue::isDeclaration]. *)
890 external is_declaration : llvalue -> bool = "llvm_is_declaration"
892 (** [linkage g] returns the linkage of the global value [g].
893 See the method [llvm::GlobalValue::getLinkage]. *)
894 external linkage : llvalue -> Linkage.t = "llvm_linkage"
896 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
897 See the method [llvm::GlobalValue::setLinkage]. *)
898 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
900 (** [section g] returns the linker section of the global value [g].
901 See the method [llvm::GlobalValue::getSection]. *)
902 external section : llvalue -> string = "llvm_section"
904 (** [set_section s g] sets the linker section of the global value [g] to [s].
905 See the method [llvm::GlobalValue::setSection]. *)
906 external set_section : string -> llvalue -> unit = "llvm_set_section"
908 (** [visibility g] returns the linker visibility of the global value [g].
909 See the method [llvm::GlobalValue::getVisibility]. *)
910 external visibility : llvalue -> Visibility.t = "llvm_visibility"
912 (** [set_visibility v g] sets the linker visibility of the global value [g] to
913 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
914 external set_visibility : Visibility.t -> llvalue -> unit
915 = "llvm_set_visibility"
917 (** [alignment g] returns the required alignment of the global value [g].
918 See the method [llvm::GlobalValue::getAlignment]. *)
919 external alignment : llvalue -> int = "llvm_alignment"
921 (** [set_alignment n g] sets the required alignment of the global value [g] to
922 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
923 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
926 (** {7 Operations on global variables} *)
928 (** [declare_global ty name m] returns a new global variable of type [ty] and
929 with name [name] in module [m]. If such a global variable already exists,
930 it is returned. If the type of the existing global differs, then a bitcast
931 to [ty] is returned. *)
932 external declare_global : lltype -> string -> llmodule -> llvalue
933 = "llvm_declare_global"
935 (** [define_global name init m] returns a new global with name [name] and
936 initializer [init] in module [m]. If the named global already exists, it is
938 See the constructor of [llvm::GlobalVariable]. *)
939 external define_global : string -> llvalue -> llmodule -> llvalue
940 = "llvm_define_global"
942 (** [lookup_global name m] returns [Some g] if a global variable with name
943 [name] exists in module [m]. If no such global exists, returns [None].
944 See the [llvm::GlobalVariable] constructor. *)
945 external lookup_global : string -> llmodule -> llvalue option
946 = "llvm_lookup_global"
948 (** [delete_global gv] destroys the global variable [gv].
949 See the method [llvm::GlobalVariable::eraseFromParent]. *)
950 external delete_global : llvalue -> unit = "llvm_delete_global"
952 (** [global_begin m] returns the first position in the global variable list of
953 the module [m]. [global_begin] and [global_succ] can be used to iterate
954 over the global list in order.
955 See the method [llvm::Module::global_begin]. *)
956 external global_begin : llmodule -> (llmodule, llvalue) llpos
957 = "llvm_global_begin"
959 (** [global_succ gv] returns the global variable list position succeeding
961 See the method [llvm::Module::global_iterator::operator++]. *)
962 external global_succ : llvalue -> (llmodule, llvalue) llpos
965 (** [iter_globals f m] applies function [f] to each of the global variables of
966 module [m] in order. Tail recursive. *)
967 val iter_globals : (llvalue -> unit) -> llmodule -> unit
969 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
970 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
971 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
973 (** [global_end m] returns the last position in the global variable list of the
974 module [m]. [global_end] and [global_pred] can be used to iterate over the
975 global list in reverse.
976 See the method [llvm::Module::global_end]. *)
977 external global_end : llmodule -> (llmodule, llvalue) llrev_pos
980 (** [global_pred gv] returns the global variable list position preceding
982 See the method [llvm::Module::global_iterator::operator--]. *)
983 external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
986 (** [rev_iter_globals f m] applies function [f] to each of the global variables
987 of module [m] in reverse order. Tail recursive. *)
988 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
990 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
991 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
992 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
994 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
995 constant. Returns [false] otherwise.
996 See the method [llvm::GlobalVariable::isConstant]. *)
997 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
999 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1000 [c] is [true] and not if [c] is [false].
1001 See the method [llvm::GlobalVariable::setConstant]. *)
1002 external set_global_constant : bool -> llvalue -> unit
1003 = "llvm_set_global_constant"
1005 (** [global_initializer gv] returns the initializer for the global variable
1006 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1007 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
1009 (** [set_initializer c gv] sets the initializer for the global variable
1010 [gv] to the constant [c].
1011 See the method [llvm::GlobalVariable::setInitializer]. *)
1012 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
1014 (** [remove_initializer gv] unsets the initializer for the global variable
1016 See the method [llvm::GlobalVariable::setInitializer]. *)
1017 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
1019 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1020 thread-local and [false] otherwise.
1021 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1022 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
1024 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1025 [c] is [true] and not otherwise.
1026 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1027 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
1030 (** {7 Operations on functions} *)
1032 (** [declare_function name ty m] returns a new function of type [ty] and
1033 with name [name] in module [m]. If such a function already exists,
1034 it is returned. If the type of the existing function differs, then a bitcast
1035 to [ty] is returned. *)
1036 external declare_function : string -> lltype -> llmodule -> llvalue
1037 = "llvm_declare_function"
1039 (** [define_function name ty m] creates a new function with name [name] and
1040 type [ty] in module [m]. If the named function already exists, it is
1041 renamed. An entry basic block is created in the function.
1042 See the constructor of [llvm::GlobalVariable]. *)
1043 external define_function : string -> lltype -> llmodule -> llvalue
1044 = "llvm_define_function"
1046 (** [lookup_function name m] returns [Some f] if a function with name
1047 [name] exists in module [m]. If no such function exists, returns [None].
1048 See the method [llvm::Module] constructor. *)
1049 external lookup_function : string -> llmodule -> llvalue option
1050 = "llvm_lookup_function"
1052 (** [delete_function f] destroys the function [f].
1053 See the method [llvm::Function::eraseFromParent]. *)
1054 external delete_function : llvalue -> unit = "llvm_delete_function"
1056 (** [function_begin m] returns the first position in the function list of the
1057 module [m]. [function_begin] and [function_succ] can be used to iterate over
1058 the function list in order.
1059 See the method [llvm::Module::begin]. *)
1060 external function_begin : llmodule -> (llmodule, llvalue) llpos
1061 = "llvm_function_begin"
1063 (** [function_succ gv] returns the function list position succeeding
1065 See the method [llvm::Module::iterator::operator++]. *)
1066 external function_succ : llvalue -> (llmodule, llvalue) llpos
1067 = "llvm_function_succ"
1069 (** [iter_functions f m] applies function [f] to each of the functions of module
1070 [m] in order. Tail recursive. *)
1071 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1073 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1074 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1075 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1077 (** [function_end m] returns the last position in the function list of
1078 the module [m]. [function_end] and [function_pred] can be used to iterate
1079 over the function list in reverse.
1080 See the method [llvm::Module::end]. *)
1081 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
1082 = "llvm_function_end"
1084 (** [function_pred gv] returns the function list position preceding [After gv].
1085 See the method [llvm::Module::iterator::operator--]. *)
1086 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1087 = "llvm_function_pred"
1089 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1090 module [m] in reverse order. Tail recursive. *)
1091 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1093 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1094 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1095 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1097 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1098 See the method [llvm::Function::isIntrinsic]. *)
1099 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
1101 (** [function_call_conv f] returns the calling convention of the function [f].
1102 See the method [llvm::Function::getCallingConv]. *)
1103 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
1105 (** [set_function_call_conv cc f] sets the calling convention of the function
1106 [f] to the calling convention numbered [cc].
1107 See the method [llvm::Function::setCallingConv]. *)
1108 external set_function_call_conv : int -> llvalue -> unit
1109 = "llvm_set_function_call_conv"
1111 (** [gc f] returns [Some name] if the function [f] has a garbage
1112 collection algorithm specified and [None] otherwise.
1113 See the method [llvm::Function::getGC]. *)
1114 external gc : llvalue -> string option = "llvm_gc"
1116 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1117 [gc]. See the method [llvm::Function::setGC]. *)
1118 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
1120 (** [add_function_attr f a] adds attribute [a] to the return type of function
1122 external add_function_attr : llvalue -> Attribute.t -> unit
1123 = "llvm_add_function_attr"
1125 (** [remove_function_attr f a] removes attribute [a] from the return type of
1127 external remove_function_attr : llvalue -> Attribute.t -> unit
1128 = "llvm_remove_function_attr"
1130 (** {7 Operations on params} *)
1132 (** [params f] returns the parameters of function [f].
1133 See the method [llvm::Function::getArgumentList]. *)
1134 external params : llvalue -> llvalue array = "llvm_params"
1136 (** [param f n] returns the [n]th parameter of function [f].
1137 See the method [llvm::Function::getArgumentList]. *)
1138 external param : llvalue -> int -> llvalue = "llvm_param"
1140 (** [param_parent p] returns the parent function that owns the parameter.
1141 See the method [llvm::Argument::getParent]. *)
1142 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
1144 (** [param_begin f] returns the first position in the parameter list of the
1145 function [f]. [param_begin] and [param_succ] can be used to iterate over
1146 the parameter list in order.
1147 See the method [llvm::Function::arg_begin]. *)
1148 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
1150 (** [param_succ bb] returns the parameter list position succeeding
1152 See the method [llvm::Function::arg_iterator::operator++]. *)
1153 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
1155 (** [iter_params f fn] applies function [f] to each of the parameters
1156 of function [fn] in order. Tail recursive. *)
1157 val iter_params : (llvalue -> unit) -> llvalue -> unit
1159 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1160 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1161 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1163 (** [param_end f] returns the last position in the parameter list of
1164 the function [f]. [param_end] and [param_pred] can be used to iterate
1165 over the parameter list in reverse.
1166 See the method [llvm::Function::arg_end]. *)
1167 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
1169 (** [param_pred gv] returns the function list position preceding [After gv].
1170 See the method [llvm::Function::arg_iterator::operator--]. *)
1171 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1174 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1175 of function [fn] in reverse order. Tail recursive. *)
1176 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1178 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1179 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1180 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1182 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1183 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1185 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1186 external remove_param_attr : llvalue -> Attribute.t -> unit
1187 = "llvm_remove_param_attr"
1189 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1190 external set_param_alignment : llvalue -> int -> unit
1191 = "llvm_set_param_alignment"
1193 (** {7 Operations on basic blocks} *)
1195 (** [basic_blocks fn] returns the basic blocks of the function [f].
1196 See the method [llvm::Function::getBasicBlockList]. *)
1197 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
1199 (** [entry_block fn] returns the entry basic block of the function [f].
1200 See the method [llvm::Function::getEntryBlock]. *)
1201 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1203 (** [delete_block bb] deletes the basic block [bb].
1204 See the method [llvm::BasicBlock::eraseFromParent]. *)
1205 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1207 (** [append_block c name f] creates a new basic block named [name] at the end of
1208 function [f] in the context [c].
1209 See the constructor of [llvm::BasicBlock]. *)
1210 external append_block : llcontext -> string -> llvalue -> llbasicblock
1211 = "llvm_append_block"
1213 (** [insert_block c name bb] creates a new basic block named [name] before the
1214 basic block [bb] in the context [c].
1215 See the constructor of [llvm::BasicBlock]. *)
1216 external insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1217 = "llvm_insert_block"
1219 (** [block_parent bb] returns the parent function that owns the basic block.
1220 See the method [llvm::BasicBlock::getParent]. *)
1221 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1223 (** [block_begin f] returns the first position in the basic block list of the
1224 function [f]. [block_begin] and [block_succ] can be used to iterate over
1225 the basic block list in order.
1226 See the method [llvm::Function::begin]. *)
1227 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1228 = "llvm_block_begin"
1230 (** [block_succ bb] returns the basic block list position succeeding
1232 See the method [llvm::Function::iterator::operator++]. *)
1233 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1236 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1237 of function [fn] in order. Tail recursive. *)
1238 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1240 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1241 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1242 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1244 (** [block_end f] returns the last position in the basic block list of
1245 the function [f]. [block_end] and [block_pred] can be used to iterate
1246 over the basic block list in reverse.
1247 See the method [llvm::Function::end]. *)
1248 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1251 (** [block_pred gv] returns the function list position preceding [After gv].
1252 See the method [llvm::Function::iterator::operator--]. *)
1253 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1256 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1257 of function [fn] in reverse order. Tail recursive. *)
1258 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1260 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1261 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1262 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1264 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1265 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1267 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1269 Similar to [llvm::isa<BasicBlock>]. *)
1270 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1272 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1273 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1276 (** {7 Operations on instructions} *)
1278 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1279 See the method [llvm::Instruction::getParent]. *)
1280 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1282 (** [instr_begin bb] returns the first position in the instruction list of the
1283 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1284 the instruction list in order.
1285 See the method [llvm::BasicBlock::begin]. *)
1286 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1287 = "llvm_instr_begin"
1289 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1290 See the method [llvm::BasicBlock::iterator::operator++]. *)
1291 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1294 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1295 block [bb] in order. Tail recursive. *)
1296 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1298 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1299 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1300 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1302 (** [instr_end bb] returns the last position in the instruction list of the
1303 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1304 the instruction list in reverse.
1305 See the method [llvm::BasicBlock::end]. *)
1306 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1309 (** [instr_pred i] returns the instruction list position preceding [After i].
1310 See the method [llvm::BasicBlock::iterator::operator--]. *)
1311 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1314 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1315 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1316 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1319 (** {7 Operations on call sites} *)
1321 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1322 instruction [ci], which may be one of the values from the module
1323 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1324 [llvm::InvokeInst::getCallingConv]. *)
1325 external instruction_call_conv: llvalue -> int
1326 = "llvm_instruction_call_conv"
1328 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1329 or invoke instruction [ci] to the integer [cc], which can be one of the
1330 values from the module {!CallConv}.
1331 See the method [llvm::CallInst::setCallingConv]
1332 and [llvm::InvokeInst::setCallingConv]. *)
1333 external set_instruction_call_conv: int -> llvalue -> unit
1334 = "llvm_set_instruction_call_conv"
1336 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1337 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1339 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1340 = "llvm_add_instruction_param_attr"
1342 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1343 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1345 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1346 = "llvm_remove_instruction_param_attr"
1348 (** {Operations on call instructions (only)} *)
1350 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1351 eligible for tail call optimization, [false] otherwise.
1352 See the method [llvm::CallInst::isTailCall]. *)
1353 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
1355 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1356 call optimization if [tc] is [true], clears otherwise.
1357 See the method [llvm::CallInst::setTailCall]. *)
1358 external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call"
1360 (** {7 Operations on phi nodes} *)
1362 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1363 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1364 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1365 = "llvm_add_incoming"
1367 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1368 See the method [llvm::PHINode::getIncomingValue]. *)
1369 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1373 (** {6 Instruction builders} *)
1375 (** [builder context] creates an instruction builder with no position in
1376 the context [context]. It is invalid to use this builder until its position
1377 is set with {!position_before} or {!position_at_end}. See the constructor
1378 for [llvm::LLVMBuilder]. *)
1379 external builder : llcontext -> llbuilder = "llvm_builder"
1381 (** [builder_at ip] creates an instruction builder positioned at [ip].
1382 See the constructor for [llvm::LLVMBuilder]. *)
1383 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1385 (** [builder_before ins] creates an instruction builder positioned before the
1386 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1387 val builder_before : llcontext -> llvalue -> llbuilder
1389 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1390 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1391 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1393 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1395 See the constructor for [llvm::LLVMBuilder]. *)
1396 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1397 = "llvm_position_builder"
1399 (** [position_before ins b] moves the instruction builder [b] to before the
1400 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1401 val position_before : llvalue -> llbuilder -> unit
1403 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1404 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1405 val position_at_end : llbasicblock -> llbuilder -> unit
1407 (** [insertion_block b] returns the basic block that the builder [b] is
1408 positioned to insert into. Raises [Not_Found] if the instruction builder is
1410 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1411 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1413 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1414 position specified by the instruction builder [b].
1415 See the method [llvm::LLVMBuilder::Insert]. *)
1416 external insert_into_builder : llvalue -> string -> llbuilder -> unit
1417 = "llvm_insert_into_builder"
1420 (** {7 Terminators} *)
1422 (** [build_ret_void b] creates a
1424 instruction at the position specified by the instruction builder [b].
1425 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1426 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1428 (** [build_ret v b] creates a
1430 instruction at the position specified by the instruction builder [b].
1431 See the method [llvm::LLVMBuilder::CreateRet]. *)
1432 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1434 (** [build_aggregate_ret vs b] creates a
1435 [ret {...} { %v1, %v2, ... } ]
1436 instruction at the position specified by the instruction builder [b].
1437 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1438 external build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1439 = "llvm_build_aggregate_ret"
1441 (** [build_br bb b] creates a
1443 instruction at the position specified by the instruction builder [b].
1444 See the method [llvm::LLVMBuilder::CreateBr]. *)
1445 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1447 (** [build_cond_br cond tbb fbb b] creates a
1448 [br %cond, %tbb, %fbb]
1449 instruction at the position specified by the instruction builder [b].
1450 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1451 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1452 llvalue = "llvm_build_cond_br"
1454 (** [build_switch case elsebb count b] creates an empty
1455 [switch %case, %elsebb]
1456 instruction at the position specified by the instruction builder [b] with
1457 space reserved for [count] cases.
1458 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1459 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1460 = "llvm_build_switch"
1462 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1463 when its input matches the constant [onval].
1464 See the method [llvm::SwitchInst::addCase]. **)
1465 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1468 (** [build_invoke fn args tobb unwindbb name b] creates an
1469 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1470 instruction at the position specified by the instruction builder [b].
1471 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1472 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1473 llbasicblock -> string -> llbuilder -> llvalue
1474 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1476 (** [build_unwind b] creates an
1478 instruction at the position specified by the instruction builder [b].
1479 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1480 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1482 (** [build_unreachable b] creates an
1484 instruction at the position specified by the instruction builder [b].
1485 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1486 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1489 (** {7 Arithmetic} *)
1491 (** [build_add x y name b] creates a
1492 [%name = add %x, %y]
1493 instruction at the position specified by the instruction builder [b].
1494 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1495 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1498 (** [build_nsw_add x y name b] creates a
1499 [%name = nsw add %x, %y]
1500 instruction at the position specified by the instruction builder [b].
1501 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1502 external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1503 = "llvm_build_nsw_add"
1505 (** [build_fadd x y name b] creates a
1506 [%name = fadd %x, %y]
1507 instruction at the position specified by the instruction builder [b].
1508 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1509 external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1512 (** [build_sub x y name b] creates a
1513 [%name = sub %x, %y]
1514 instruction at the position specified by the instruction builder [b].
1515 See the method [llvm::LLVMBuilder::CreateSub]. *)
1516 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1519 (** [build_fsub x y name b] creates a
1520 [%name = fsub %x, %y]
1521 instruction at the position specified by the instruction builder [b].
1522 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1523 external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1526 (** [build_mul x y name b] creates a
1527 [%name = mul %x, %y]
1528 instruction at the position specified by the instruction builder [b].
1529 See the method [llvm::LLVMBuilder::CreateMul]. *)
1530 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1533 (** [build_fmul x y name b] creates a
1534 [%name = fmul %x, %y]
1535 instruction at the position specified by the instruction builder [b].
1536 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1537 external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1540 (** [build_udiv x y name b] creates a
1541 [%name = udiv %x, %y]
1542 instruction at the position specified by the instruction builder [b].
1543 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1544 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1547 (** [build_sdiv x y name b] creates a
1548 [%name = sdiv %x, %y]
1549 instruction at the position specified by the instruction builder [b].
1550 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1551 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1554 (** [build_exact_sdiv x y name b] creates a
1555 [%name = exact sdiv %x, %y]
1556 instruction at the position specified by the instruction builder [b].
1557 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1558 external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1559 = "llvm_build_exact_sdiv"
1561 (** [build_fdiv x y name b] creates a
1562 [%name = fdiv %x, %y]
1563 instruction at the position specified by the instruction builder [b].
1564 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1565 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1568 (** [build_urem x y name b] creates a
1569 [%name = urem %x, %y]
1570 instruction at the position specified by the instruction builder [b].
1571 See the method [llvm::LLVMBuilder::CreateURem]. *)
1572 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1575 (** [build_SRem x y name b] creates a
1576 [%name = srem %x, %y]
1577 instruction at the position specified by the instruction builder [b].
1578 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1579 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1582 (** [build_frem x y name b] creates a
1583 [%name = frem %x, %y]
1584 instruction at the position specified by the instruction builder [b].
1585 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1586 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1589 (** [build_shl x y name b] creates a
1590 [%name = shl %x, %y]
1591 instruction at the position specified by the instruction builder [b].
1592 See the method [llvm::LLVMBuilder::CreateShl]. *)
1593 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1596 (** [build_lshr x y name b] creates a
1597 [%name = lshr %x, %y]
1598 instruction at the position specified by the instruction builder [b].
1599 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1600 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1603 (** [build_ashr x y name b] creates a
1604 [%name = ashr %x, %y]
1605 instruction at the position specified by the instruction builder [b].
1606 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1607 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1610 (** [build_and x y name b] creates a
1611 [%name = and %x, %y]
1612 instruction at the position specified by the instruction builder [b].
1613 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1614 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1617 (** [build_or x y name b] creates a
1619 instruction at the position specified by the instruction builder [b].
1620 See the method [llvm::LLVMBuilder::CreateOr]. *)
1621 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1624 (** [build_xor x y name b] creates a
1625 [%name = xor %x, %y]
1626 instruction at the position specified by the instruction builder [b].
1627 See the method [llvm::LLVMBuilder::CreateXor]. *)
1628 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1631 (** [build_neg x name b] creates a
1633 instruction at the position specified by the instruction builder [b].
1634 [-0.0] is used for floating point types to compute the correct sign.
1635 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1636 external build_neg : llvalue -> string -> llbuilder -> llvalue
1639 (** [build_xor x name b] creates a
1640 [%name = xor %x, -1]
1641 instruction at the position specified by the instruction builder [b].
1642 [-1] is the correct "all ones" value for the type of [x].
1643 See the method [llvm::LLVMBuilder::CreateXor]. *)
1644 external build_not : llvalue -> string -> llbuilder -> llvalue
1650 (** [build_alloca ty name b] creates a
1651 [%name = alloca %ty]
1652 instruction at the position specified by the instruction builder [b].
1653 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1654 external build_alloca : lltype -> string -> llbuilder -> llvalue
1655 = "llvm_build_alloca"
1657 (** [build_array_alloca ty n name b] creates a
1658 [%name = alloca %ty, %n]
1659 instruction at the position specified by the instruction builder [b].
1660 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1661 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1662 llvalue = "llvm_build_array_alloca"
1664 (** [build_load v name b] creates a
1666 instruction at the position specified by the instruction builder [b].
1667 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1668 external build_load : llvalue -> string -> llbuilder -> llvalue
1671 (** [build_store v p b] creates a
1673 instruction at the position specified by the instruction builder [b].
1674 See the method [llvm::LLVMBuilder::CreateStore]. *)
1675 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1676 = "llvm_build_store"
1678 (** [build_gep p indices name b] creates a
1679 [%name = getelementptr %p, indices...]
1680 instruction at the position specified by the instruction builder [b].
1681 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1682 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1685 (** [build_in_bounds_gep p indices name b] creates a
1686 [%name = gelementptr inbounds %p, indices...]
1687 instruction at the position specified by the instruction builder [b].
1688 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1689 external build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1690 llvalue = "llvm_build_in_bounds_gep"
1692 (** [build_struct_gep p idx name b] creates a
1693 [%name = getelementptr %p, 0, idx]
1694 instruction at the position specified by the instruction builder [b].
1695 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1696 external build_struct_gep : llvalue -> int -> string -> llbuilder ->
1697 llvalue = "llvm_build_struct_gep"
1699 (** [build_global_string str name b] creates a series of instructions that adds
1700 a global string at the position specified by the instruction builder [b].
1701 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1702 external build_global_string : string -> string -> llbuilder -> llvalue
1703 = "llvm_build_global_string"
1705 (** [build_global_stringptr str name b] creates a series of instructions that
1706 adds a global string pointer at the position specified by the instruction
1708 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1709 external build_global_stringptr : string -> string -> llbuilder -> llvalue
1710 = "llvm_build_global_stringptr"
1715 (** [build_trunc v ty name b] creates a
1716 [%name = trunc %p to %ty]
1717 instruction at the position specified by the instruction builder [b].
1718 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1719 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1720 = "llvm_build_trunc"
1722 (** [build_zext v ty name b] creates a
1723 [%name = zext %p to %ty]
1724 instruction at the position specified by the instruction builder [b].
1725 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1726 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1729 (** [build_sext v ty name b] creates a
1730 [%name = sext %p to %ty]
1731 instruction at the position specified by the instruction builder [b].
1732 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1733 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1736 (** [build_fptoui v ty name b] creates a
1737 [%name = fptoui %p to %ty]
1738 instruction at the position specified by the instruction builder [b].
1739 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1740 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1741 = "llvm_build_fptoui"
1743 (** [build_fptosi v ty name b] creates a
1744 [%name = fptosi %p to %ty]
1745 instruction at the position specified by the instruction builder [b].
1746 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1747 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1748 = "llvm_build_fptosi"
1750 (** [build_uitofp v ty name b] creates a
1751 [%name = uitofp %p to %ty]
1752 instruction at the position specified by the instruction builder [b].
1753 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1754 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1755 = "llvm_build_uitofp"
1757 (** [build_sitofp v ty name b] creates a
1758 [%name = sitofp %p to %ty]
1759 instruction at the position specified by the instruction builder [b].
1760 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1761 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1762 = "llvm_build_sitofp"
1764 (** [build_fptrunc v ty name b] creates a
1765 [%name = fptrunc %p to %ty]
1766 instruction at the position specified by the instruction builder [b].
1767 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1768 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1769 = "llvm_build_fptrunc"
1771 (** [build_fpext v ty name b] creates a
1772 [%name = fpext %p to %ty]
1773 instruction at the position specified by the instruction builder [b].
1774 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1775 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1776 = "llvm_build_fpext"
1778 (** [build_ptrtoint v ty name b] creates a
1779 [%name = prtotint %p to %ty]
1780 instruction at the position specified by the instruction builder [b].
1781 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1782 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1783 = "llvm_build_prttoint"
1785 (** [build_inttoptr v ty name b] creates a
1786 [%name = inttoptr %p to %ty]
1787 instruction at the position specified by the instruction builder [b].
1788 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1789 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1790 = "llvm_build_inttoptr"
1792 (** [build_bitcast v ty name b] creates a
1793 [%name = bitcast %p to %ty]
1794 instruction at the position specified by the instruction builder [b].
1795 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
1796 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1797 = "llvm_build_bitcast"
1799 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
1800 instruction at the position specified by the instruction builder [b].
1801 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1802 external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1803 llvalue = "llvm_build_zext_or_bitcast"
1805 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
1806 instruction at the position specified by the instruction builder [b].
1807 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
1808 external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1809 llvalue = "llvm_build_sext_or_bitcast"
1811 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
1812 instruction at the position specified by the instruction builder [b].
1813 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1814 external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1815 llvalue = "llvm_build_trunc_or_bitcast"
1817 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
1818 instruction at the position specified by the instruction builder [b].
1819 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
1820 external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
1821 = "llvm_build_pointercast"
1823 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
1824 instruction at the position specified by the instruction builder [b].
1825 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
1826 external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1827 = "llvm_build_intcast"
1829 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
1830 instruction at the position specified by the instruction builder [b].
1831 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
1832 external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1833 = "llvm_build_fpcast"
1836 (** {7 Comparisons} *)
1838 (** [build_icmp pred x y name b] creates a
1839 [%name = icmp %pred %x, %y]
1840 instruction at the position specified by the instruction builder [b].
1841 See the method [llvm::LLVMBuilder::CreateICmp]. *)
1842 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1843 llbuilder -> llvalue = "llvm_build_icmp"
1845 (** [build_fcmp pred x y name b] creates a
1846 [%name = fcmp %pred %x, %y]
1847 instruction at the position specified by the instruction builder [b].
1848 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1849 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1850 llbuilder -> llvalue = "llvm_build_fcmp"
1853 (** {7 Miscellaneous instructions} *)
1855 (** [build_phi incoming name b] creates a
1856 [%name = phi %incoming]
1857 instruction at the position specified by the instruction builder [b].
1858 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1859 See the method [llvm::LLVMBuilder::CreatePHI]. *)
1860 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1861 llvalue = "llvm_build_phi"
1863 (** [build_call fn args name b] creates a
1864 [%name = call %fn(args...)]
1865 instruction at the position specified by the instruction builder [b].
1866 See the method [llvm::LLVMBuilder::CreateCall]. *)
1867 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1870 (** [build_select cond thenv elsev name b] creates a
1871 [%name = select %cond, %thenv, %elsev]
1872 instruction at the position specified by the instruction builder [b].
1873 See the method [llvm::LLVMBuilder::CreateSelect]. *)
1874 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1875 llvalue = "llvm_build_select"
1877 (** [build_va_arg valist argty name b] creates a
1878 [%name = va_arg %valist, %argty]
1879 instruction at the position specified by the instruction builder [b].
1880 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1881 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1882 = "llvm_build_va_arg"
1884 (** [build_extractelement vec i name b] creates a
1885 [%name = extractelement %vec, %i]
1886 instruction at the position specified by the instruction builder [b].
1887 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1888 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1889 llvalue = "llvm_build_extractelement"
1891 (** [build_insertelement vec elt i name b] creates a
1892 [%name = insertelement %vec, %elt, %i]
1893 instruction at the position specified by the instruction builder [b].
1894 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1895 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1896 llbuilder -> llvalue = "llvm_build_insertelement"
1898 (** [build_shufflevector veca vecb mask name b] creates a
1899 [%name = shufflevector %veca, %vecb, %mask]
1900 instruction at the position specified by the instruction builder [b].
1901 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1902 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1903 llbuilder -> llvalue = "llvm_build_shufflevector"
1905 (** [build_insertvalue agg idx name b] creates a
1906 [%name = extractvalue %agg, %idx]
1907 instruction at the position specified by the instruction builder [b].
1908 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
1909 external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
1910 = "llvm_build_extractvalue"
1912 (** [build_insertvalue agg val idx name b] creates a
1913 [%name = insertvalue %agg, %val, %idx]
1914 instruction at the position specified by the instruction builder [b].
1915 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
1916 external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
1917 llvalue = "llvm_build_insertvalue"
1919 (** [build_is_null val name b] creates a
1920 [%name = icmp eq %val, null]
1921 instruction at the position specified by the instruction builder [b].
1922 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
1923 external build_is_null : llvalue -> string -> llbuilder -> llvalue
1924 = "llvm_build_is_null"
1926 (** [build_is_not_null val name b] creates a
1927 [%name = icmp ne %val, null]
1928 instruction at the position specified by the instruction builder [b].
1929 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
1930 external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
1931 = "llvm_build_is_not_null"
1933 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
1934 the difference between two pointer values at the position specified by the
1935 instruction builder [b].
1936 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
1937 external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
1938 = "llvm_build_ptrdiff"
1940 (** {6 Module providers} *)
1942 module ModuleProvider : sig
1943 (** [create_module_provider m] encapsulates [m] in a module provider and takes
1944 ownership of the module. See the constructor
1945 [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
1946 external create : llmodule -> llmoduleprovider
1947 = "LLVMCreateModuleProviderForExistingModule"
1949 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1950 the contained module. *)
1951 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1955 (** {6 Memory buffers} *)
1957 module MemoryBuffer : sig
1958 (** [of_file p] is the memory buffer containing the contents of the file at
1959 path [p]. If the file could not be read, then [IoError msg] is
1961 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1963 (** [stdin ()] is the memory buffer containing the contents of standard input.
1964 If standard input is empty, then [IoError msg] is raised. *)
1965 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1967 (** Disposes of a memory buffer. *)
1968 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
1972 (** {6 Pass Managers} *)
1974 module PassManager : sig
1977 type any = [ `Module | `Function ]
1979 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
1980 type of pipeline is suitable for link-time optimization and whole-module
1982 See the constructor of [llvm::PassManager]. *)
1983 external create : unit -> [ `Module ] t = "llvm_passmanager_create"
1985 (** [PassManager.create_function mp] constructs a new function-by-function
1986 pass pipeline over the module provider [mp]. It does not take ownership of
1987 [mp]. This type of pipeline is suitable for code generation and JIT
1989 See the constructor of [llvm::FunctionPassManager]. *)
1990 external create_function : llmoduleprovider -> [ `Function ] t
1991 = "LLVMCreateFunctionPassManager"
1993 (** [run_module m pm] initializes, executes on the module [m], and finalizes
1994 all of the passes scheduled in the pass manager [pm]. Returns [true] if
1995 any of the passes modified the module, [false] otherwise.
1996 See the [llvm::PassManager::run] method. *)
1997 external run_module : llmodule -> [ `Module ] t -> bool
1998 = "llvm_passmanager_run_module"
2000 (** [initialize fpm] initializes all of the function passes scheduled in the
2001 function pass manager [fpm]. Returns [true] if any of the passes modified
2002 the module, [false] otherwise.
2003 See the [llvm::FunctionPassManager::doInitialization] method. *)
2004 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
2006 (** [run_function f fpm] executes all of the function passes scheduled in the
2007 function pass manager [fpm] over the function [f]. Returns [true] if any
2008 of the passes modified [f], [false] otherwise.
2009 See the [llvm::FunctionPassManager::run] method. *)
2010 external run_function : llvalue -> [ `Function ] t -> bool
2011 = "llvm_passmanager_run_function"
2013 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2014 function pass manager [fpm]. Returns [true] if any of the passes
2015 modified the module, [false] otherwise.
2016 See the [llvm::FunctionPassManager::doFinalization] method. *)
2017 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
2019 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2020 the module provider.
2021 See the destructor of [llvm::BasePassManager]. *)
2022 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"