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 (** The 1-bit integer type. See [llvm::Type::Int1Ty]. *)
279 (** The 8-bit integer type. See [llvm::Type::Int8Ty]. *)
282 (** The 16-bit integer type. See [llvm::Type::Int16Ty]. *)
283 val i16_type : lltype
285 (** The 32-bit integer type. See [llvm::Type::Int32Ty]. *)
286 val i32_type : lltype
288 (** The 64-bit integer type. See [llvm::Type::Int64Ty]. *)
289 val i64_type : lltype
291 (** [integer_type n] returns an integer type of bitwidth [n].
292 See the method [llvm::IntegerType::get]. *)
293 external integer_type : int -> lltype = "llvm_integer_type"
295 (** [integer_bitwidth ty] returns the number of bits in the integer type [ty].
296 See the method [llvm::IntegerType::getBitWidth]. *)
297 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
300 (** {7 Operations on real types} *)
302 (** The IEEE 32-bit floating point type. See [llvm::Type::FloatTy]. *)
303 val float_type : lltype
305 (** The IEEE 64-bit floating point type. See [llvm::Type::DoubleTy]. *)
306 val double_type : lltype
308 (** The x87 80-bit floating point type. See [llvm::Type::X86_FP80Ty]. *)
309 val x86fp80_type : lltype
311 (** The IEEE 128-bit floating point type. See [llvm::Type::FP128Ty]. *)
312 val fp128_type : lltype
314 (** The PowerPC 128-bit floating point type. See [llvm::Type::PPC_FP128Ty]. *)
315 val ppc_fp128_type : lltype
318 (** {7 Operations on function types} *)
320 (** [function_type ret_ty param_tys] returns the function type returning
321 [ret_ty] and taking [param_tys] as parameters.
322 See the method [llvm::FunctionType::get]. *)
323 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
325 (** [va_arg_function_type ret_ty param_tys] is just like
326 [function_type ret_ty param_tys] except that it returns the function type
327 which also takes a variable number of arguments.
328 See the method [llvm::FunctionType::get]. *)
329 external var_arg_function_type : lltype -> lltype array -> lltype
330 = "llvm_var_arg_function_type"
332 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
333 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
334 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
336 (** [return_type fty] gets the return type of the function type [fty].
337 See the method [llvm::FunctionType::getReturnType]. *)
338 external return_type : lltype -> lltype = "LLVMGetReturnType"
340 (** [param_types fty] gets the parameter types of the function type [fty].
341 See the method [llvm::FunctionType::getParamType]. *)
342 external param_types : lltype -> lltype array = "llvm_param_types"
345 (** {7 Operations on struct types} *)
347 (** [struct_type context tys] returns the structure type in the context
348 [context] containing in the types in the array [tys]. See the method
349 [llvm::StructType::get]. *)
350 external struct_type : llcontext -> lltype array -> lltype
353 (** [packed_struct_type context ys] returns the packed structure type in the
354 context [context] containing in the types in the array [tys]. See the method
355 [llvm::StructType::get]. *)
356 external packed_struct_type : llcontext -> lltype array -> lltype
357 = "llvm_packed_struct_type"
359 (** [element_types sty] returns the constituent types of the struct type [sty].
360 See the method [llvm::StructType::getElementType]. *)
361 external element_types : lltype -> lltype array = "llvm_element_types"
363 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
364 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
365 external is_packed : lltype -> bool = "llvm_is_packed"
368 (** {7 Operations on pointer, vector, and array types} *)
370 (** [array_type ty n] returns the array type containing [n] elements of type
371 [ty]. See the method [llvm::ArrayType::get]. *)
372 external array_type : lltype -> int -> lltype = "llvm_array_type"
374 (** [pointer_type ty] returns the pointer type referencing objects of type
375 [ty] in the default address space (0).
376 See the method [llvm::PointerType::getUnqual]. *)
377 external pointer_type : lltype -> lltype = "llvm_pointer_type"
379 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
380 of type [ty] in address space [as].
381 See the method [llvm::PointerType::get]. *)
382 external qualified_pointer_type : lltype -> int -> lltype
383 = "llvm_qualified_pointer_type"
385 (** [vector_type ty n] returns the array type containing [n] elements of the
386 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
387 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
389 (** [element_type ty] returns the element type of the pointer, vector, or array
390 type [ty]. See the method [llvm::SequentialType::get]. *)
391 external element_type : lltype -> lltype = "LLVMGetElementType"
393 (** [element_type aty] returns the element count of the array type [aty].
394 See the method [llvm::ArrayType::getNumElements]. *)
395 external array_length : lltype -> int = "llvm_array_length"
397 (** [address_space pty] returns the address space qualifier of the pointer type
398 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
399 external address_space : lltype -> int = "llvm_address_space"
401 (** [element_type ty] returns the element count of the vector type [ty].
402 See the method [llvm::VectorType::getNumElements]. *)
403 external vector_size : lltype -> int = "llvm_vector_size"
406 (** {7 Operations on other types} *)
408 (** [opaque_type ()] creates a new opaque type distinct from any other.
409 Opaque types are useful for building recursive types in combination with
411 See [llvm::OpaqueType::get]. *)
412 external opaque_type : unit -> lltype = "llvm_opaque_type"
414 (** [void_type] is the type of a function which does not return any value.
415 See [llvm::Type::VoidTy]. *)
416 val void_type : lltype
418 (** [label_type] is the type of a basic block. See [llvm::Type::LabelTy]. *)
419 val label_type : lltype
421 (** {7 Operations on type handles} *)
423 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
424 refined as a result of a call to {!refine_type}, the handle will be updated;
425 any bare [lltype] references will become invalid.
426 See the class [llvm::PATypeHolder]. *)
427 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
429 (** [type_of_handle tyh] resolves the type handle [tyh].
430 See the method [llvm::PATypeHolder::get()]. *)
431 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
433 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
434 concrete type [ty] in all users. Warning: This may invalidate {!lltype}
435 values! Use {!lltypehandle} to manipulate potentially abstract types. See
436 the method [llvm::Type::refineAbstractType]. *)
437 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
442 (** [type_of v] returns the type of the value [v].
443 See the method [llvm::Value::getType]. *)
444 external type_of : llvalue -> lltype = "llvm_type_of"
446 (** [value_name v] returns the name of the value [v]. For global values, this is
447 the symbol name. For instructions and basic blocks, it is the SSA register
448 name. It is meaningless for constants.
449 See the method [llvm::Value::getName]. *)
450 external value_name : llvalue -> string = "llvm_value_name"
452 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
453 [llvm::Value::setName]. *)
454 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
456 (** [dump_value v] prints the .ll representation of the value [v] to standard
457 error. See the method [llvm::Value::dump]. *)
458 external dump_value : llvalue -> unit = "llvm_dump_value"
461 (** {7 Operations on constants of (mostly) any type} *)
463 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
464 otherwise. Similar to [llvm::isa<Constant>]. *)
465 external is_constant : llvalue -> bool = "llvm_is_constant"
467 (** [const_null ty] returns the constant null (zero) of the type [ty].
468 See the method [llvm::Constant::getNullValue]. *)
469 external const_null : lltype -> llvalue = "LLVMConstNull"
471 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
472 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
473 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
475 (** [undef ty] returns the undefined value of the type [ty].
476 See the method [llvm::UndefValue::get]. *)
477 external undef : lltype -> llvalue = "LLVMGetUndef"
479 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
480 See the method [llvm::Constant::isNullValue]. *)
481 external is_null : llvalue -> bool = "llvm_is_null"
483 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
484 otherwise. Similar to [llvm::isa<UndefValue>]. *)
485 external is_undef : llvalue -> bool = "llvm_is_undef"
488 (** {7 Operations on scalar constants} *)
490 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
491 See the method [llvm::ConstantInt::get]. *)
492 external const_int : lltype -> int -> llvalue = "llvm_const_int"
494 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
495 [i]. See the method [llvm::ConstantInt::get]. *)
496 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
497 = "llvm_const_of_int64"
499 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
500 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
501 external const_int_of_string : lltype -> string -> int -> llvalue
502 = "llvm_const_int_of_string"
504 (** [const_float ty n] returns the floating point constant of type [ty] and
505 value [n]. See the method [llvm::ConstantFP::get]. *)
506 external const_float : lltype -> float -> llvalue = "llvm_const_float"
508 (** [const_float_of_string ty s] returns the floating point constant of type
509 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
510 external const_float_of_string : lltype -> string -> llvalue
511 = "llvm_const_float_of_string"
514 (** {7 Operations on composite constants} *)
516 (** [const_string s] returns the constant [i8] array with the values of the
517 characters in the string [s]. The array is not null-terminated (but see
518 {!const_stringz}). This value can in turn be used as the initializer for a
519 global variable. See the method [llvm::ConstantArray::get]. *)
520 external const_string : string -> llvalue = "llvm_const_string"
522 (** [const_stringz s] returns the constant [i8] array with the values of the
523 characters in the string [s] and a null terminator. This value can in turn
524 be used as the initializer for a global variable.
525 See the method [llvm::ConstantArray::get]. *)
526 external const_stringz : string -> llvalue = "llvm_const_stringz"
528 (** [const_array ty elts] returns the constant array of type
529 [array_type ty (Array.length elts)] and containing the values [elts].
530 This value can in turn be used as the initializer for a global variable.
531 See the method [llvm::ConstantArray::get]. *)
532 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
534 (** [const_struct context elts] returns the structured constant of type
535 [struct_type (Array.map type_of elts)] and containing the values [elts]
536 in the context [context]. This value can in turn be used as the initializer
537 for a global variable. See the method [llvm::ConstantStruct::get]. *)
538 external const_struct : llcontext -> llvalue array -> llvalue
539 = "llvm_const_struct"
541 (** [const_packed_struct context elts] returns the structured constant of
542 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
543 values [elts] in the context [context]. This value can in turn be used as
544 the initializer for a global variable. See the method
545 [llvm::ConstantStruct::get]. *)
546 external const_packed_struct : llcontext -> llvalue array -> llvalue
547 = "llvm_const_packed_struct"
549 (** [const_vector elts] returns the vector constant of type
550 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
551 values [elts]. See the method [llvm::ConstantVector::get]. *)
552 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
555 (** {7 Constant expressions} *)
557 (** [align_of ty] returns the alignof constant for the type [ty]. This is
558 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
559 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
560 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
561 external align_of : lltype -> llvalue = "LLVMAlignOf"
563 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
564 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
565 (const_int i32_type 1)) i64_type], but considerably more readable.
566 See the method [llvm::ConstantExpr::getSizeOf]. *)
567 external size_of : lltype -> llvalue = "LLVMSizeOf"
569 (** [const_neg c] returns the arithmetic negation of the constant [c].
570 See the method [llvm::ConstantExpr::getNeg]. *)
571 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
573 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
574 See the method [llvm::ConstantExpr::getFNeg]. *)
575 external const_fneg : llvalue -> llvalue = "LLVMConstFNeg"
577 (** [const_not c] returns the bitwise inverse of the constant [c].
578 See the method [llvm::ConstantExpr::getNot]. *)
579 external const_not : llvalue -> llvalue = "LLVMConstNot"
581 (** [const_add c1 c2] returns the constant sum of two constants.
582 See the method [llvm::ConstantExpr::getAdd]. *)
583 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
585 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
586 signed wrapping. The result is undefined if the sum overflows.
587 See the method [llvm::ConstantExpr::getNSWAdd]. *)
588 external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd"
590 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
591 See the method [llvm::ConstantExpr::getFAdd]. *)
592 external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd"
594 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
595 constants. See the method [llvm::ConstantExpr::getSub]. *)
596 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
598 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
599 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
600 external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub"
602 (** [const_mul c1 c2] returns the constant product of two constants.
603 See the method [llvm::ConstantExpr::getMul]. *)
604 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
606 (** [const_fmul c1 c2] returns the constant product of two constants floats.
607 See the method [llvm::ConstantExpr::getFMul]. *)
608 external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul"
610 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
612 See the method [llvm::ConstantExpr::getUDiv]. *)
613 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
615 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
617 See the method [llvm::ConstantExpr::getSDiv]. *)
618 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
620 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
621 signed integer constants. The result is undefined if the result is rounded
622 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
623 external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv"
625 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
627 See the method [llvm::ConstantExpr::getFDiv]. *)
628 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
630 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
631 unsigned integer constants.
632 See the method [llvm::ConstantExpr::getURem]. *)
633 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
635 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
636 signed integer constants.
637 See the method [llvm::ConstantExpr::getSRem]. *)
638 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
640 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
641 signed floating point constants.
642 See the method [llvm::ConstantExpr::getFRem]. *)
643 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
645 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
647 See the method [llvm::ConstantExpr::getAnd]. *)
648 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
650 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
652 See the method [llvm::ConstantExpr::getOr]. *)
653 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
655 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
657 See the method [llvm::ConstantExpr::getXor]. *)
658 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
660 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
661 constants, [c1 pred c2].
662 See the method [llvm::ConstantExpr::getICmp]. *)
663 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
666 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
667 point constants, [c1 pred c2].
668 See the method [llvm::ConstantExpr::getFCmp]. *)
669 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
672 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
673 constant integer [c2].
674 See the method [llvm::ConstantExpr::getShl]. *)
675 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
677 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
678 constant integer [c2] with zero extension.
679 See the method [llvm::ConstantExpr::getLShr]. *)
680 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
682 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
683 constant integer [c2] with sign extension.
684 See the method [llvm::ConstantExpr::getAShr]. *)
685 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
687 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
688 constant integers indices from the array [indices].
689 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
690 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
692 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
693 with the constant integers indices from the array [indices].
694 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
695 external const_in_bounds_gep : llvalue -> llvalue array -> llvalue
696 = "llvm_const_in_bounds_gep"
698 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
699 to the smaller integer type [ty].
700 See the method [llvm::ConstantExpr::getTrunc]. *)
701 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
703 (** [const_sext c ty] returns the constant sign extension of integer constant
704 [c] to the larger integer type [ty].
705 See the method [llvm::ConstantExpr::getSExt]. *)
706 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
708 (** [const_zext c ty] returns the constant zero extension of integer constant
709 [c] to the larger integer type [ty].
710 See the method [llvm::ConstantExpr::getZExt]. *)
711 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
713 (** [const_fptrunc c ty] returns the constant truncation of floating point
714 constant [c] to the smaller floating point type [ty].
715 See the method [llvm::ConstantExpr::getFPTrunc]. *)
716 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
718 (** [const_fpext c ty] returns the constant extension of floating point constant
719 [c] to the larger floating point type [ty].
720 See the method [llvm::ConstantExpr::getFPExt]. *)
721 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
723 (** [const_uitofp c ty] returns the constant floating point conversion of
724 unsigned integer constant [c] to the floating point type [ty].
725 See the method [llvm::ConstantExpr::getUIToFP]. *)
726 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
728 (** [const_sitofp c ty] returns the constant floating point conversion of
729 signed integer constant [c] to the floating point type [ty].
730 See the method [llvm::ConstantExpr::getSIToFP]. *)
731 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
733 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
734 floating point constant [c] to integer type [ty].
735 See the method [llvm::ConstantExpr::getFPToUI]. *)
736 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
738 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
739 floating point constant [c] to integer type [ty].
740 See the method [llvm::ConstantExpr::getFPToSI]. *)
741 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
743 (** [const_ptrtoint c ty] returns the constant integer conversion of
744 pointer constant [c] to integer type [ty].
745 See the method [llvm::ConstantExpr::getPtrToInt]. *)
746 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
748 (** [const_inttoptr c ty] returns the constant pointer conversion of
749 integer constant [c] to pointer type [ty].
750 See the method [llvm::ConstantExpr::getIntToPtr]. *)
751 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
753 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
754 to type [ty] of equal size.
755 See the method [llvm::ConstantExpr::getBitCast]. *)
756 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
758 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
759 conversion of constant [c] to type [ty].
760 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
761 external const_zext_or_bitcast : llvalue -> lltype -> llvalue
762 = "LLVMConstZExtOrBitCast"
764 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
765 conversion of constant [c] to type [ty].
766 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
767 external const_sext_or_bitcast : llvalue -> lltype -> llvalue
768 = "LLVMConstSExtOrBitCast"
770 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
771 conversion of constant [c] to type [ty].
772 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
773 external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
774 = "LLVMConstTruncOrBitCast"
776 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
777 cast conversion of constant [c] to type [ty] of equal size.
778 See the method [llvm::ConstantExpr::getPointerCast]. *)
779 external const_pointercast : llvalue -> lltype -> llvalue
780 = "LLVMConstPointerCast"
782 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
783 -> integer casts of constant [c] to type [ty].
784 See the method [llvm::ConstantExpr::getIntCast]. *)
785 external const_intcast : llvalue -> lltype -> llvalue
788 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
789 fp casts of constant [c] to type [ty].
790 See the method [llvm::ConstantExpr::getFPCast]. *)
791 external const_fpcast : llvalue -> lltype -> llvalue
794 (** [const_select cond t f] returns the constant conditional which returns value
795 [t] if the boolean constant [cond] is true and the value [f] otherwise.
796 See the method [llvm::ConstantExpr::getSelect]. *)
797 external const_select : llvalue -> llvalue -> llvalue -> llvalue
800 (** [const_extractelement vec i] returns the constant [i]th element of
801 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
802 the size of the vector.
803 See the method [llvm::ConstantExpr::getExtractElement]. *)
804 external const_extractelement : llvalue -> llvalue -> llvalue
805 = "LLVMConstExtractElement"
807 (** [const_insertelement vec v i] returns the constant vector with the same
808 elements as constant vector [v] but the [i]th element replaced by the
809 constant [v]. [v] must be a constant value with the type of the vector
810 elements. [i] must be a constant [i32] value unsigned less than the size
812 See the method [llvm::ConstantExpr::getInsertElement]. *)
813 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
814 = "LLVMConstInsertElement"
816 (** [const_shufflevector a b mask] returns a constant [shufflevector].
817 See the LLVM Language Reference for details on the [sufflevector]
819 See the method [llvm::ConstantExpr::getShuffleVector]. *)
820 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
821 = "LLVMConstShuffleVector"
823 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
824 constant aggregate [agg]. Each [idxs] must be less than the size of the
825 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
826 external const_extractvalue : llvalue -> int array -> llvalue
827 = "llvm_const_extractvalue"
829 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
830 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
831 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
832 external const_insertvalue : llvalue -> llvalue -> int array -> llvalue
833 = "llvm_const_insertvalue"
836 (** {7 Operations on global variables, functions, and aliases (globals)} *)
838 (** [global_parent g] is the enclosing module of the global value [g].
839 See the method [llvm::GlobalValue::getParent]. *)
840 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
842 (** [is_declaration g] returns [true] if the global value [g] is a declaration
843 only. Returns [false] otherwise.
844 See the method [llvm::GlobalValue::isDeclaration]. *)
845 external is_declaration : llvalue -> bool = "llvm_is_declaration"
847 (** [linkage g] returns the linkage of the global value [g].
848 See the method [llvm::GlobalValue::getLinkage]. *)
849 external linkage : llvalue -> Linkage.t = "llvm_linkage"
851 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
852 See the method [llvm::GlobalValue::setLinkage]. *)
853 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
855 (** [section g] returns the linker section of the global value [g].
856 See the method [llvm::GlobalValue::getSection]. *)
857 external section : llvalue -> string = "llvm_section"
859 (** [set_section s g] sets the linker section of the global value [g] to [s].
860 See the method [llvm::GlobalValue::setSection]. *)
861 external set_section : string -> llvalue -> unit = "llvm_set_section"
863 (** [visibility g] returns the linker visibility of the global value [g].
864 See the method [llvm::GlobalValue::getVisibility]. *)
865 external visibility : llvalue -> Visibility.t = "llvm_visibility"
867 (** [set_visibility v g] sets the linker visibility of the global value [g] to
868 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
869 external set_visibility : Visibility.t -> llvalue -> unit
870 = "llvm_set_visibility"
872 (** [alignment g] returns the required alignment of the global value [g].
873 See the method [llvm::GlobalValue::getAlignment]. *)
874 external alignment : llvalue -> int = "llvm_alignment"
876 (** [set_alignment n g] sets the required alignment of the global value [g] to
877 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
878 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
881 (** {7 Operations on global variables} *)
883 (** [declare_global ty name m] returns a new global variable of type [ty] and
884 with name [name] in module [m]. If such a global variable already exists,
885 it is returned. If the type of the existing global differs, then a bitcast
886 to [ty] is returned. *)
887 external declare_global : lltype -> string -> llmodule -> llvalue
888 = "llvm_declare_global"
890 (** [define_global name init m] returns a new global with name [name] and
891 initializer [init] in module [m]. If the named global already exists, it is
893 See the constructor of [llvm::GlobalVariable]. *)
894 external define_global : string -> llvalue -> llmodule -> llvalue
895 = "llvm_define_global"
897 (** [lookup_global name m] returns [Some g] if a global variable with name
898 [name] exists in module [m]. If no such global exists, returns [None].
899 See the [llvm::GlobalVariable] constructor. *)
900 external lookup_global : string -> llmodule -> llvalue option
901 = "llvm_lookup_global"
903 (** [delete_global gv] destroys the global variable [gv].
904 See the method [llvm::GlobalVariable::eraseFromParent]. *)
905 external delete_global : llvalue -> unit = "llvm_delete_global"
907 (** [global_begin m] returns the first position in the global variable list of
908 the module [m]. [global_begin] and [global_succ] can be used to iterate
909 over the global list in order.
910 See the method [llvm::Module::global_begin]. *)
911 external global_begin : llmodule -> (llmodule, llvalue) llpos
912 = "llvm_global_begin"
914 (** [global_succ gv] returns the global variable list position succeeding
916 See the method [llvm::Module::global_iterator::operator++]. *)
917 external global_succ : llvalue -> (llmodule, llvalue) llpos
920 (** [iter_globals f m] applies function [f] to each of the global variables of
921 module [m] in order. Tail recursive. *)
922 val iter_globals : (llvalue -> unit) -> llmodule -> unit
924 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
925 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
926 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
928 (** [global_end m] returns the last position in the global variable list of the
929 module [m]. [global_end] and [global_pred] can be used to iterate over the
930 global list in reverse.
931 See the method [llvm::Module::global_end]. *)
932 external global_end : llmodule -> (llmodule, llvalue) llrev_pos
935 (** [global_pred gv] returns the global variable list position preceding
937 See the method [llvm::Module::global_iterator::operator--]. *)
938 external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
941 (** [rev_iter_globals f m] applies function [f] to each of the global variables
942 of module [m] in reverse order. Tail recursive. *)
943 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
945 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
946 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
947 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
949 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
950 constant. Returns [false] otherwise.
951 See the method [llvm::GlobalVariable::isConstant]. *)
952 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
954 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
955 [c] is [true] and not if [c] is [false].
956 See the method [llvm::GlobalVariable::setConstant]. *)
957 external set_global_constant : bool -> llvalue -> unit
958 = "llvm_set_global_constant"
960 (** [global_initializer gv] returns the initializer for the global variable
961 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
962 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
964 (** [set_initializer c gv] sets the initializer for the global variable
965 [gv] to the constant [c].
966 See the method [llvm::GlobalVariable::setInitializer]. *)
967 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
969 (** [remove_initializer gv] unsets the initializer for the global variable
971 See the method [llvm::GlobalVariable::setInitializer]. *)
972 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
974 (** [is_thread_local gv] returns [true] if the global variable [gv] is
975 thread-local and [false] otherwise.
976 See the method [llvm::GlobalVariable::isThreadLocal]. *)
977 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
979 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
980 [c] is [true] and not otherwise.
981 See the method [llvm::GlobalVariable::setThreadLocal]. *)
982 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
985 (** {7 Operations on functions} *)
987 (** [declare_function name ty m] returns a new function of type [ty] and
988 with name [name] in module [m]. If such a function already exists,
989 it is returned. If the type of the existing function differs, then a bitcast
990 to [ty] is returned. *)
991 external declare_function : string -> lltype -> llmodule -> llvalue
992 = "llvm_declare_function"
994 (** [define_function name ty m] creates a new function with name [name] and
995 type [ty] in module [m]. If the named function already exists, it is
996 renamed. An entry basic block is created in the function.
997 See the constructor of [llvm::GlobalVariable]. *)
998 external define_function : string -> lltype -> llmodule -> llvalue
999 = "llvm_define_function"
1001 (** [lookup_function name m] returns [Some f] if a function with name
1002 [name] exists in module [m]. If no such function exists, returns [None].
1003 See the method [llvm::Module] constructor. *)
1004 external lookup_function : string -> llmodule -> llvalue option
1005 = "llvm_lookup_function"
1007 (** [delete_function f] destroys the function [f].
1008 See the method [llvm::Function::eraseFromParent]. *)
1009 external delete_function : llvalue -> unit = "llvm_delete_function"
1011 (** [function_begin m] returns the first position in the function list of the
1012 module [m]. [function_begin] and [function_succ] can be used to iterate over
1013 the function list in order.
1014 See the method [llvm::Module::begin]. *)
1015 external function_begin : llmodule -> (llmodule, llvalue) llpos
1016 = "llvm_function_begin"
1018 (** [function_succ gv] returns the function list position succeeding
1020 See the method [llvm::Module::iterator::operator++]. *)
1021 external function_succ : llvalue -> (llmodule, llvalue) llpos
1022 = "llvm_function_succ"
1024 (** [iter_functions f m] applies function [f] to each of the functions of module
1025 [m] in order. Tail recursive. *)
1026 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1028 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1029 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1030 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1032 (** [function_end m] returns the last position in the function list of
1033 the module [m]. [function_end] and [function_pred] can be used to iterate
1034 over the function list in reverse.
1035 See the method [llvm::Module::end]. *)
1036 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
1037 = "llvm_function_end"
1039 (** [function_pred gv] returns the function list position preceding [After gv].
1040 See the method [llvm::Module::iterator::operator--]. *)
1041 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1042 = "llvm_function_pred"
1044 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1045 module [m] in reverse order. Tail recursive. *)
1046 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1048 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1049 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1050 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1052 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1053 See the method [llvm::Function::isIntrinsic]. *)
1054 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
1056 (** [function_call_conv f] returns the calling convention of the function [f].
1057 See the method [llvm::Function::getCallingConv]. *)
1058 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
1060 (** [set_function_call_conv cc f] sets the calling convention of the function
1061 [f] to the calling convention numbered [cc].
1062 See the method [llvm::Function::setCallingConv]. *)
1063 external set_function_call_conv : int -> llvalue -> unit
1064 = "llvm_set_function_call_conv"
1066 (** [gc f] returns [Some name] if the function [f] has a garbage
1067 collection algorithm specified and [None] otherwise.
1068 See the method [llvm::Function::getGC]. *)
1069 external gc : llvalue -> string option = "llvm_gc"
1071 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1072 [gc]. See the method [llvm::Function::setGC]. *)
1073 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
1075 (** [add_function_attr f a] adds attribute [a] to the return type of function
1077 external add_function_attr : llvalue -> Attribute.t -> unit
1078 = "llvm_add_function_attr"
1080 (** [remove_function_attr f a] removes attribute [a] from the return type of
1082 external remove_function_attr : llvalue -> Attribute.t -> unit
1083 = "llvm_remove_function_attr"
1085 (** {7 Operations on params} *)
1087 (** [params f] returns the parameters of function [f].
1088 See the method [llvm::Function::getArgumentList]. *)
1089 external params : llvalue -> llvalue array = "llvm_params"
1091 (** [param f n] returns the [n]th parameter of function [f].
1092 See the method [llvm::Function::getArgumentList]. *)
1093 external param : llvalue -> int -> llvalue = "llvm_param"
1095 (** [param_parent p] returns the parent function that owns the parameter.
1096 See the method [llvm::Argument::getParent]. *)
1097 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
1099 (** [param_begin f] returns the first position in the parameter list of the
1100 function [f]. [param_begin] and [param_succ] can be used to iterate over
1101 the parameter list in order.
1102 See the method [llvm::Function::arg_begin]. *)
1103 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
1105 (** [param_succ bb] returns the parameter list position succeeding
1107 See the method [llvm::Function::arg_iterator::operator++]. *)
1108 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
1110 (** [iter_params f fn] applies function [f] to each of the parameters
1111 of function [fn] in order. Tail recursive. *)
1112 val iter_params : (llvalue -> unit) -> llvalue -> unit
1114 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1115 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1116 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1118 (** [param_end f] returns the last position in the parameter list of
1119 the function [f]. [param_end] and [param_pred] can be used to iterate
1120 over the parameter list in reverse.
1121 See the method [llvm::Function::arg_end]. *)
1122 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
1124 (** [param_pred gv] returns the function list position preceding [After gv].
1125 See the method [llvm::Function::arg_iterator::operator--]. *)
1126 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1129 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1130 of function [fn] in reverse order. Tail recursive. *)
1131 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1133 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1134 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1135 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1137 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1138 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1140 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1141 external remove_param_attr : llvalue -> Attribute.t -> unit
1142 = "llvm_remove_param_attr"
1144 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1145 external set_param_alignment : llvalue -> int -> unit
1146 = "llvm_set_param_alignment"
1148 (** {7 Operations on basic blocks} *)
1150 (** [basic_blocks fn] returns the basic blocks of the function [f].
1151 See the method [llvm::Function::getBasicBlockList]. *)
1152 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
1154 (** [entry_block fn] returns the entry basic block of the function [f].
1155 See the method [llvm::Function::getEntryBlock]. *)
1156 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1158 (** [delete_block bb] deletes the basic block [bb].
1159 See the method [llvm::BasicBlock::eraseFromParent]. *)
1160 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1162 (** [append_block name f] creates a new basic block named [name] at the end of
1164 See the constructor of [llvm::BasicBlock]. *)
1165 external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
1167 (** [insert_block name bb] creates a new basic block named [name] before the
1169 See the constructor of [llvm::BasicBlock]. *)
1170 external insert_block : string -> llbasicblock -> llbasicblock
1171 = "llvm_insert_block"
1173 (** [block_parent bb] returns the parent function that owns the basic block.
1174 See the method [llvm::BasicBlock::getParent]. *)
1175 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1177 (** [block_begin f] returns the first position in the basic block list of the
1178 function [f]. [block_begin] and [block_succ] can be used to iterate over
1179 the basic block list in order.
1180 See the method [llvm::Function::begin]. *)
1181 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1182 = "llvm_block_begin"
1184 (** [block_succ bb] returns the basic block list position succeeding
1186 See the method [llvm::Function::iterator::operator++]. *)
1187 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1190 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1191 of function [fn] in order. Tail recursive. *)
1192 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1194 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1195 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1196 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1198 (** [block_end f] returns the last position in the basic block list of
1199 the function [f]. [block_end] and [block_pred] can be used to iterate
1200 over the basic block list in reverse.
1201 See the method [llvm::Function::end]. *)
1202 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1205 (** [block_pred gv] returns the function list position preceding [After gv].
1206 See the method [llvm::Function::iterator::operator--]. *)
1207 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1210 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1211 of function [fn] in reverse order. Tail recursive. *)
1212 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1214 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1215 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1216 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1218 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1219 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1221 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1223 Similar to [llvm::isa<BasicBlock>]. *)
1224 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1226 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1227 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1230 (** {7 Operations on instructions} *)
1232 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1233 See the method [llvm::Instruction::getParent]. *)
1234 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1236 (** [instr_begin bb] returns the first position in the instruction list of the
1237 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1238 the instruction list in order.
1239 See the method [llvm::BasicBlock::begin]. *)
1240 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1241 = "llvm_instr_begin"
1243 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1244 See the method [llvm::BasicBlock::iterator::operator++]. *)
1245 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1248 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1249 block [bb] in order. Tail recursive. *)
1250 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1252 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1253 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1254 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1256 (** [instr_end bb] returns the last position in the instruction list of the
1257 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1258 the instruction list in reverse.
1259 See the method [llvm::BasicBlock::end]. *)
1260 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1263 (** [instr_pred i] returns the instruction list position preceding [After i].
1264 See the method [llvm::BasicBlock::iterator::operator--]. *)
1265 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1268 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1269 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1270 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1273 (** {7 Operations on call sites} *)
1275 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1276 instruction [ci], which may be one of the values from the module
1277 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1278 [llvm::InvokeInst::getCallingConv]. *)
1279 external instruction_call_conv: llvalue -> int
1280 = "llvm_instruction_call_conv"
1282 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1283 or invoke instruction [ci] to the integer [cc], which can be one of the
1284 values from the module {!CallConv}.
1285 See the method [llvm::CallInst::setCallingConv]
1286 and [llvm::InvokeInst::setCallingConv]. *)
1287 external set_instruction_call_conv: int -> llvalue -> unit
1288 = "llvm_set_instruction_call_conv"
1290 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1291 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1293 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1294 = "llvm_add_instruction_param_attr"
1296 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1297 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1299 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1300 = "llvm_remove_instruction_param_attr"
1302 (** {Operations on call instructions (only)} *)
1304 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1305 eligible for tail call optimization, [false] otherwise.
1306 See the method [llvm::CallInst::isTailCall]. *)
1307 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
1309 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1310 call optimization if [tc] is [true], clears otherwise.
1311 See the method [llvm::CallInst::setTailCall]. *)
1312 external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call"
1314 (** {7 Operations on phi nodes} *)
1316 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1317 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1318 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1319 = "llvm_add_incoming"
1321 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1322 See the method [llvm::PHINode::getIncomingValue]. *)
1323 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1327 (** {6 Instruction builders} *)
1329 (** [builder context] creates an instruction builder with no position in
1330 the context [context]. It is invalid to use this builder until its position
1331 is set with {!position_before} or {!position_at_end}. See the constructor
1332 for [llvm::LLVMBuilder]. *)
1333 external builder : llcontext -> llbuilder = "llvm_builder"
1335 (** [builder_at ip] creates an instruction builder positioned at [ip].
1336 See the constructor for [llvm::LLVMBuilder]. *)
1337 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1339 (** [builder_before ins] creates an instruction builder positioned before the
1340 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1341 val builder_before : llcontext -> llvalue -> llbuilder
1343 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1344 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1345 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1347 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1349 See the constructor for [llvm::LLVMBuilder]. *)
1350 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1351 = "llvm_position_builder"
1353 (** [position_before ins b] moves the instruction builder [b] to before the
1354 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1355 val position_before : llvalue -> llbuilder -> unit
1357 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1358 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1359 val position_at_end : llbasicblock -> llbuilder -> unit
1361 (** [insertion_block b] returns the basic block that the builder [b] is
1362 positioned to insert into. Raises [Not_Found] if the instruction builder is
1364 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1365 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1367 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1368 position specified by the instruction builder [b].
1369 See the method [llvm::LLVMBuilder::Insert]. *)
1370 external insert_into_builder : llvalue -> string -> llbuilder -> unit
1371 = "llvm_insert_into_builder"
1374 (** {7 Terminators} *)
1376 (** [build_ret_void b] creates a
1378 instruction at the position specified by the instruction builder [b].
1379 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1380 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1382 (** [build_ret v b] creates a
1384 instruction at the position specified by the instruction builder [b].
1385 See the method [llvm::LLVMBuilder::CreateRet]. *)
1386 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1388 (** [build_aggregate_ret vs b] creates a
1389 [ret {...} { %v1, %v2, ... } ]
1390 instruction at the position specified by the instruction builder [b].
1391 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1392 external build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1393 = "llvm_build_aggregate_ret"
1395 (** [build_br bb b] creates a
1397 instruction at the position specified by the instruction builder [b].
1398 See the method [llvm::LLVMBuilder::CreateBr]. *)
1399 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1401 (** [build_cond_br cond tbb fbb b] creates a
1402 [b %cond, %tbb, %fbb]
1403 instruction at the position specified by the instruction builder [b].
1404 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1405 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1406 llvalue = "llvm_build_cond_br"
1408 (** [build_switch case elsebb count b] creates an empty
1409 [switch %case, %elsebb]
1410 instruction at the position specified by the instruction builder [b] with
1411 space reserved for [count] cases.
1412 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1413 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1414 = "llvm_build_switch"
1416 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1417 when its input matches the constant [onval].
1418 See the method [llvm::SwitchInst::addCase]. **)
1419 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1422 (** [build_invoke fn args tobb unwindbb name b] creates an
1423 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1424 instruction at the position specified by the instruction builder [b].
1425 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1426 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1427 llbasicblock -> string -> llbuilder -> llvalue
1428 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1430 (** [build_unwind b] creates an
1432 instruction at the position specified by the instruction builder [b].
1433 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1434 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1436 (** [build_unreachable b] creates an
1438 instruction at the position specified by the instruction builder [b].
1439 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1440 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1443 (** {7 Arithmetic} *)
1445 (** [build_add x y name b] creates a
1446 [%name = add %x, %y]
1447 instruction at the position specified by the instruction builder [b].
1448 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1449 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1452 (** [build_nswadd x y name b] creates a
1453 [%name = nsw add %x, %y]
1454 instruction at the position specified by the instruction builder [b].
1455 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1456 external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1457 = "llvm_build_nsw_add"
1459 (** [build_fadd x y name b] creates a
1460 [%name = fadd %x, %y]
1461 instruction at the position specified by the instruction builder [b].
1462 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1463 external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1466 (** [build_sub x y name b] creates a
1467 [%name = sub %x, %y]
1468 instruction at the position specified by the instruction builder [b].
1469 See the method [llvm::LLVMBuilder::CreateSub]. *)
1470 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1473 (** [build_fsub x y name b] creates a
1474 [%name = fsub %x, %y]
1475 instruction at the position specified by the instruction builder [b].
1476 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1477 external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1480 (** [build_mul x y name b] creates a
1481 [%name = mul %x, %y]
1482 instruction at the position specified by the instruction builder [b].
1483 See the method [llvm::LLVMBuilder::CreateMul]. *)
1484 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1487 (** [build_fmul x y name b] creates a
1488 [%name = fmul %x, %y]
1489 instruction at the position specified by the instruction builder [b].
1490 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1491 external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1494 (** [build_udiv x y name b] creates a
1495 [%name = udiv %x, %y]
1496 instruction at the position specified by the instruction builder [b].
1497 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1498 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1501 (** [build_sdiv x y name b] creates a
1502 [%name = sdiv %x, %y]
1503 instruction at the position specified by the instruction builder [b].
1504 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1505 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1508 (** [build_exact_sdiv x y name b] creates a
1509 [%name = exact sdiv %x, %y]
1510 instruction at the position specified by the instruction builder [b].
1511 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1512 external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1513 = "llvm_build_exact_sdiv"
1515 (** [build_fdiv x y name b] creates a
1516 [%name = fdiv %x, %y]
1517 instruction at the position specified by the instruction builder [b].
1518 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1519 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1522 (** [build_urem x y name b] creates a
1523 [%name = urem %x, %y]
1524 instruction at the position specified by the instruction builder [b].
1525 See the method [llvm::LLVMBuilder::CreateURem]. *)
1526 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1529 (** [build_SRem x y name b] creates a
1530 [%name = srem %x, %y]
1531 instruction at the position specified by the instruction builder [b].
1532 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1533 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1536 (** [build_frem x y name b] creates a
1537 [%name = frem %x, %y]
1538 instruction at the position specified by the instruction builder [b].
1539 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1540 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1543 (** [build_shl x y name b] creates a
1544 [%name = shl %x, %y]
1545 instruction at the position specified by the instruction builder [b].
1546 See the method [llvm::LLVMBuilder::CreateShl]. *)
1547 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1550 (** [build_lshr x y name b] creates a
1551 [%name = lshr %x, %y]
1552 instruction at the position specified by the instruction builder [b].
1553 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1554 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1557 (** [build_ashr x y name b] creates a
1558 [%name = ashr %x, %y]
1559 instruction at the position specified by the instruction builder [b].
1560 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1561 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1564 (** [build_and x y name b] creates a
1565 [%name = and %x, %y]
1566 instruction at the position specified by the instruction builder [b].
1567 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1568 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1571 (** [build_or x y name b] creates a
1573 instruction at the position specified by the instruction builder [b].
1574 See the method [llvm::LLVMBuilder::CreateOr]. *)
1575 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1578 (** [build_xor x y name b] creates a
1579 [%name = xor %x, %y]
1580 instruction at the position specified by the instruction builder [b].
1581 See the method [llvm::LLVMBuilder::CreateXor]. *)
1582 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1585 (** [build_neg x name b] creates a
1587 instruction at the position specified by the instruction builder [b].
1588 [-0.0] is used for floating point types to compute the correct sign.
1589 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1590 external build_neg : llvalue -> string -> llbuilder -> llvalue
1593 (** [build_xor x name b] creates a
1594 [%name = xor %x, -1]
1595 instruction at the position specified by the instruction builder [b].
1596 [-1] is the correct "all ones" value for the type of [x].
1597 See the method [llvm::LLVMBuilder::CreateXor]. *)
1598 external build_not : llvalue -> string -> llbuilder -> llvalue
1604 (** [build_malloc ty name b] creates a
1605 [%name = malloc %ty]
1606 instruction at the position specified by the instruction builder [b].
1607 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1608 external build_malloc : lltype -> string -> llbuilder -> llvalue
1609 = "llvm_build_malloc"
1611 (** [build_array_malloc ty n name b] creates a
1612 [%name = malloc %ty, %n]
1613 instruction at the position specified by the instruction builder [b].
1614 See the method [llvm::LLVMBuilder::CreateMalloc]. *)
1615 external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1616 llvalue = "llvm_build_array_malloc"
1618 (** [build_alloca ty name b] creates a
1619 [%name = alloca %ty]
1620 instruction at the position specified by the instruction builder [b].
1621 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1622 external build_alloca : lltype -> string -> llbuilder -> llvalue
1623 = "llvm_build_alloca"
1625 (** [build_array_alloca ty n name b] creates a
1626 [%name = alloca %ty, %n]
1627 instruction at the position specified by the instruction builder [b].
1628 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1629 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1630 llvalue = "llvm_build_array_alloca"
1632 (** [build_free v b] creates a
1634 instruction at the position specified by the instruction builder [b].
1635 See the method [llvm::LLVMBuilder::CreateFree]. *)
1636 external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1638 (** [build_load v name b] creates a
1640 instruction at the position specified by the instruction builder [b].
1641 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1642 external build_load : llvalue -> string -> llbuilder -> llvalue
1645 (** [build_store v p b] creates a
1647 instruction at the position specified by the instruction builder [b].
1648 See the method [llvm::LLVMBuilder::CreateStore]. *)
1649 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1650 = "llvm_build_store"
1652 (** [build_gep p indices name b] creates a
1653 [%name = getelementptr %p, indices...]
1654 instruction at the position specified by the instruction builder [b].
1655 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1656 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1659 (** [build_in_bounds_gep p indices name b] creates a
1660 [%name = gelementptr inbounds %p, indices...]
1661 instruction at the position specified by the instruction builder [b].
1662 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1663 external build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1664 llvalue = "llvm_build_in_bounds_gep"
1666 (** [build_struct_gep p idx name b] creates a
1667 [%name = getelementptr %p, 0, idx]
1668 instruction at the position specified by the instruction builder [b].
1669 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1670 external build_struct_gep : llvalue -> int -> string -> llbuilder ->
1671 llvalue = "llvm_build_struct_gep"
1673 (** [build_global_string str name b] creates a series of instructions that adds
1674 a global string at the position specified by the instruction builder [b].
1675 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1676 external build_global_string : string -> string -> llbuilder -> llvalue
1677 = "llvm_build_global_string"
1679 (** [build_global_stringptr str name b] creates a series of instructions that
1680 adds a global string pointer at the position specified by the instruction
1682 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1683 external build_global_stringptr : string -> string -> llbuilder -> llvalue
1684 = "llvm_build_global_stringptr"
1689 (** [build_trunc v ty name b] creates a
1690 [%name = trunc %p to %ty]
1691 instruction at the position specified by the instruction builder [b].
1692 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1693 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1694 = "llvm_build_trunc"
1696 (** [build_zext v ty name b] creates a
1697 [%name = zext %p to %ty]
1698 instruction at the position specified by the instruction builder [b].
1699 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1700 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1703 (** [build_sext v ty name b] creates a
1704 [%name = sext %p to %ty]
1705 instruction at the position specified by the instruction builder [b].
1706 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1707 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1710 (** [build_fptoui v ty name b] creates a
1711 [%name = fptoui %p to %ty]
1712 instruction at the position specified by the instruction builder [b].
1713 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1714 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1715 = "llvm_build_fptoui"
1717 (** [build_fptosi v ty name b] creates a
1718 [%name = fptosi %p to %ty]
1719 instruction at the position specified by the instruction builder [b].
1720 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1721 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1722 = "llvm_build_fptosi"
1724 (** [build_uitofp v ty name b] creates a
1725 [%name = uitofp %p to %ty]
1726 instruction at the position specified by the instruction builder [b].
1727 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1728 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1729 = "llvm_build_uitofp"
1731 (** [build_sitofp v ty name b] creates a
1732 [%name = sitofp %p to %ty]
1733 instruction at the position specified by the instruction builder [b].
1734 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1735 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1736 = "llvm_build_sitofp"
1738 (** [build_fptrunc v ty name b] creates a
1739 [%name = fptrunc %p to %ty]
1740 instruction at the position specified by the instruction builder [b].
1741 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1742 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1743 = "llvm_build_fptrunc"
1745 (** [build_fpext v ty name b] creates a
1746 [%name = fpext %p to %ty]
1747 instruction at the position specified by the instruction builder [b].
1748 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1749 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1750 = "llvm_build_fpext"
1752 (** [build_ptrtoint v ty name b] creates a
1753 [%name = prtotint %p to %ty]
1754 instruction at the position specified by the instruction builder [b].
1755 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1756 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1757 = "llvm_build_prttoint"
1759 (** [build_inttoptr v ty name b] creates a
1760 [%name = inttoptr %p to %ty]
1761 instruction at the position specified by the instruction builder [b].
1762 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1763 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1764 = "llvm_build_inttoptr"
1766 (** [build_bitcast v ty name b] creates a
1767 [%name = bitcast %p to %ty]
1768 instruction at the position specified by the instruction builder [b].
1769 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
1770 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1771 = "llvm_build_bitcast"
1773 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
1774 instruction at the position specified by the instruction builder [b].
1775 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1776 external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1777 llvalue = "llvm_build_zext_or_bitcast"
1779 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
1780 instruction at the position specified by the instruction builder [b].
1781 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
1782 external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1783 llvalue = "llvm_build_sext_or_bitcast"
1785 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
1786 instruction at the position specified by the instruction builder [b].
1787 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1788 external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1789 llvalue = "llvm_build_trunc_or_bitcast"
1791 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
1792 instruction at the position specified by the instruction builder [b].
1793 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
1794 external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
1795 = "llvm_build_pointercast"
1797 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
1798 instruction at the position specified by the instruction builder [b].
1799 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
1800 external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1801 = "llvm_build_intcast"
1803 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
1804 instruction at the position specified by the instruction builder [b].
1805 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
1806 external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1807 = "llvm_build_fpcast"
1810 (** {7 Comparisons} *)
1812 (** [build_icmp pred x y name b] creates a
1813 [%name = icmp %pred %x, %y]
1814 instruction at the position specified by the instruction builder [b].
1815 See the method [llvm::LLVMBuilder::CreateICmp]. *)
1816 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1817 llbuilder -> llvalue = "llvm_build_icmp"
1819 (** [build_fcmp pred x y name b] creates a
1820 [%name = fcmp %pred %x, %y]
1821 instruction at the position specified by the instruction builder [b].
1822 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1823 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1824 llbuilder -> llvalue = "llvm_build_fcmp"
1827 (** {7 Miscellaneous instructions} *)
1829 (** [build_phi incoming name b] creates a
1830 [%name = phi %incoming]
1831 instruction at the position specified by the instruction builder [b].
1832 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1833 See the method [llvm::LLVMBuilder::CreatePHI]. *)
1834 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1835 llvalue = "llvm_build_phi"
1837 (** [build_call fn args name b] creates a
1838 [%name = call %fn(args...)]
1839 instruction at the position specified by the instruction builder [b].
1840 See the method [llvm::LLVMBuilder::CreateCall]. *)
1841 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1844 (** [build_select cond thenv elsev name b] creates a
1845 [%name = select %cond, %thenv, %elsev]
1846 instruction at the position specified by the instruction builder [b].
1847 See the method [llvm::LLVMBuilder::CreateSelect]. *)
1848 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1849 llvalue = "llvm_build_select"
1851 (** [build_va_arg valist argty name b] creates a
1852 [%name = va_arg %valist, %argty]
1853 instruction at the position specified by the instruction builder [b].
1854 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1855 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1856 = "llvm_build_va_arg"
1858 (** [build_extractelement vec i name b] creates a
1859 [%name = extractelement %vec, %i]
1860 instruction at the position specified by the instruction builder [b].
1861 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1862 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1863 llvalue = "llvm_build_extractelement"
1865 (** [build_insertelement vec elt i name b] creates a
1866 [%name = insertelement %vec, %elt, %i]
1867 instruction at the position specified by the instruction builder [b].
1868 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1869 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1870 llbuilder -> llvalue = "llvm_build_insertelement"
1872 (** [build_shufflevector veca vecb mask name b] creates a
1873 [%name = shufflevector %veca, %vecb, %mask]
1874 instruction at the position specified by the instruction builder [b].
1875 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1876 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1877 llbuilder -> llvalue = "llvm_build_shufflevector"
1879 (** [build_insertvalue agg idx name b] creates a
1880 [%name = extractvalue %agg, %idx]
1881 instruction at the position specified by the instruction builder [b].
1882 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
1883 external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
1884 = "llvm_build_extractvalue"
1886 (** [build_insertvalue agg val idx name b] creates a
1887 [%name = insertvalue %agg, %val, %idx]
1888 instruction at the position specified by the instruction builder [b].
1889 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
1890 external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
1891 llvalue = "llvm_build_insertvalue"
1893 (** [build_is_null val name b] creates a
1894 [%name = icmp eq %val, null]
1895 instruction at the position specified by the instruction builder [b].
1896 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
1897 external build_is_null : llvalue -> string -> llbuilder -> llvalue
1898 = "llvm_build_is_null"
1900 (** [build_is_not_null val name b] creates a
1901 [%name = icmp ne %val, null]
1902 instruction at the position specified by the instruction builder [b].
1903 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
1904 external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
1905 = "llvm_build_is_not_null"
1907 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
1908 the difference between two pointer values at the position specified by the
1909 instruction builder [b].
1910 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
1911 external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
1912 = "llvm_build_ptrdiff"
1914 (** {6 Module providers} *)
1916 module ModuleProvider : sig
1917 (** [create_module_provider m] encapsulates [m] in a module provider and takes
1918 ownership of the module. See the constructor
1919 [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
1920 external create : llmodule -> llmoduleprovider
1921 = "LLVMCreateModuleProviderForExistingModule"
1923 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1924 the contained module. *)
1925 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1929 (** {6 Memory buffers} *)
1931 module MemoryBuffer : sig
1932 (** [of_file p] is the memory buffer containing the contents of the file at
1933 path [p]. If the file could not be read, then [IoError msg] is
1935 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1937 (** [stdin ()] is the memory buffer containing the contents of standard input.
1938 If standard input is empty, then [IoError msg] is raised. *)
1939 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1941 (** Disposes of a memory buffer. *)
1942 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
1946 (** {6 Pass Managers} *)
1948 module PassManager : sig
1951 type any = [ `Module | `Function ]
1953 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
1954 type of pipeline is suitable for link-time optimization and whole-module
1956 See the constructor of [llvm::PassManager]. *)
1957 external create : unit -> [ `Module ] t = "llvm_passmanager_create"
1959 (** [PassManager.create_function mp] constructs a new function-by-function
1960 pass pipeline over the module provider [mp]. It does not take ownership of
1961 [mp]. This type of pipeline is suitable for code generation and JIT
1963 See the constructor of [llvm::FunctionPassManager]. *)
1964 external create_function : llmoduleprovider -> [ `Function ] t
1965 = "LLVMCreateFunctionPassManager"
1967 (** [run_module m pm] initializes, executes on the module [m], and finalizes
1968 all of the passes scheduled in the pass manager [pm]. Returns [true] if
1969 any of the passes modified the module, [false] otherwise.
1970 See the [llvm::PassManager::run] method. *)
1971 external run_module : llmodule -> [ `Module ] t -> bool
1972 = "llvm_passmanager_run_module"
1974 (** [initialize fpm] initializes all of the function passes scheduled in the
1975 function pass manager [fpm]. Returns [true] if any of the passes modified
1976 the module, [false] otherwise.
1977 See the [llvm::FunctionPassManager::doInitialization] method. *)
1978 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
1980 (** [run_function f fpm] executes all of the function passes scheduled in the
1981 function pass manager [fpm] over the function [f]. Returns [true] if any
1982 of the passes modified [f], [false] otherwise.
1983 See the [llvm::FunctionPassManager::run] method. *)
1984 external run_function : llvalue -> [ `Function ] t -> bool
1985 = "llvm_passmanager_run_function"
1987 (** [finalize fpm] finalizes all of the function passes scheduled in in the
1988 function pass manager [fpm]. Returns [true] if any of the passes
1989 modified the module, [false] otherwise.
1990 See the [llvm::FunctionPassManager::doFinalization] method. *)
1991 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
1993 (** Frees the memory of a pass pipeline. For function pipelines, does not free
1994 the module provider.
1995 See the destructor of [llvm::BasePassManager]. *)
1996 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"