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_nsw_neg c] returns the arithmetic negation of the constant [c] with
619 no signed wrapping. The result is undefined if the negation overflows.
620 See the method [llvm::ConstantExpr::getNSWNeg]. *)
621 external const_nsw_neg : llvalue -> llvalue = "LLVMConstNSWNeg"
623 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
624 no unsigned wrapping. The result is undefined if the negation overflows.
625 See the method [llvm::ConstantExpr::getNUWNeg]. *)
626 external const_nuw_neg : llvalue -> llvalue = "LLVMConstNUWNeg"
628 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
629 See the method [llvm::ConstantExpr::getFNeg]. *)
630 external const_fneg : llvalue -> llvalue = "LLVMConstFNeg"
632 (** [const_not c] returns the bitwise inverse of the constant [c].
633 See the method [llvm::ConstantExpr::getNot]. *)
634 external const_not : llvalue -> llvalue = "LLVMConstNot"
636 (** [const_add c1 c2] returns the constant sum of two constants.
637 See the method [llvm::ConstantExpr::getAdd]. *)
638 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
640 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
641 signed wrapping. The result is undefined if the sum overflows.
642 See the method [llvm::ConstantExpr::getNSWAdd]. *)
643 external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd"
645 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
646 unsigned wrapping. The result is undefined if the sum overflows.
647 See the method [llvm::ConstantExpr::getNSWAdd]. *)
648 external const_nuw_add : llvalue -> llvalue -> llvalue = "LLVMConstNUWAdd"
650 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
651 See the method [llvm::ConstantExpr::getFAdd]. *)
652 external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd"
654 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
655 constants. See the method [llvm::ConstantExpr::getSub]. *)
656 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
658 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
659 no signed wrapping. The result is undefined if the sum overflows.
660 See the method [llvm::ConstantExpr::getNSWSub]. *)
661 external const_nsw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNSWSub"
663 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
664 no unsigned wrapping. The result is undefined if the sum overflows.
665 See the method [llvm::ConstantExpr::getNSWSub]. *)
666 external const_nuw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNUWSub"
668 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
669 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
670 external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub"
672 (** [const_mul c1 c2] returns the constant product of two constants.
673 See the method [llvm::ConstantExpr::getMul]. *)
674 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
676 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
677 no signed wrapping. The result is undefined if the sum overflows.
678 See the method [llvm::ConstantExpr::getNSWMul]. *)
679 external const_nsw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNSWMul"
681 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
682 no unsigned wrapping. The result is undefined if the sum overflows.
683 See the method [llvm::ConstantExpr::getNSWMul]. *)
684 external const_nuw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNUWMul"
686 (** [const_fmul c1 c2] returns the constant product of two constants floats.
687 See the method [llvm::ConstantExpr::getFMul]. *)
688 external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul"
690 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
692 See the method [llvm::ConstantExpr::getUDiv]. *)
693 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
695 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
697 See the method [llvm::ConstantExpr::getSDiv]. *)
698 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
700 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
701 signed integer constants. The result is undefined if the result is rounded
702 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
703 external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv"
705 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
707 See the method [llvm::ConstantExpr::getFDiv]. *)
708 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
710 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
711 unsigned integer constants.
712 See the method [llvm::ConstantExpr::getURem]. *)
713 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
715 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
716 signed integer constants.
717 See the method [llvm::ConstantExpr::getSRem]. *)
718 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
720 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
721 signed floating point constants.
722 See the method [llvm::ConstantExpr::getFRem]. *)
723 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
725 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
727 See the method [llvm::ConstantExpr::getAnd]. *)
728 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
730 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
732 See the method [llvm::ConstantExpr::getOr]. *)
733 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
735 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
737 See the method [llvm::ConstantExpr::getXor]. *)
738 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
740 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
741 constants, [c1 pred c2].
742 See the method [llvm::ConstantExpr::getICmp]. *)
743 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
746 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
747 point constants, [c1 pred c2].
748 See the method [llvm::ConstantExpr::getFCmp]. *)
749 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
752 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
753 constant integer [c2].
754 See the method [llvm::ConstantExpr::getShl]. *)
755 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
757 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
758 constant integer [c2] with zero extension.
759 See the method [llvm::ConstantExpr::getLShr]. *)
760 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
762 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
763 constant integer [c2] with sign extension.
764 See the method [llvm::ConstantExpr::getAShr]. *)
765 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
767 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
768 constant integers indices from the array [indices].
769 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
770 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
772 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
773 with the constant integers indices from the array [indices].
774 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
775 external const_in_bounds_gep : llvalue -> llvalue array -> llvalue
776 = "llvm_const_in_bounds_gep"
778 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
779 to the smaller integer type [ty].
780 See the method [llvm::ConstantExpr::getTrunc]. *)
781 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
783 (** [const_sext c ty] returns the constant sign extension of integer constant
784 [c] to the larger integer type [ty].
785 See the method [llvm::ConstantExpr::getSExt]. *)
786 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
788 (** [const_zext c ty] returns the constant zero extension of integer constant
789 [c] to the larger integer type [ty].
790 See the method [llvm::ConstantExpr::getZExt]. *)
791 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
793 (** [const_fptrunc c ty] returns the constant truncation of floating point
794 constant [c] to the smaller floating point type [ty].
795 See the method [llvm::ConstantExpr::getFPTrunc]. *)
796 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
798 (** [const_fpext c ty] returns the constant extension of floating point constant
799 [c] to the larger floating point type [ty].
800 See the method [llvm::ConstantExpr::getFPExt]. *)
801 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
803 (** [const_uitofp c ty] returns the constant floating point conversion of
804 unsigned integer constant [c] to the floating point type [ty].
805 See the method [llvm::ConstantExpr::getUIToFP]. *)
806 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
808 (** [const_sitofp c ty] returns the constant floating point conversion of
809 signed integer constant [c] to the floating point type [ty].
810 See the method [llvm::ConstantExpr::getSIToFP]. *)
811 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
813 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
814 floating point constant [c] to integer type [ty].
815 See the method [llvm::ConstantExpr::getFPToUI]. *)
816 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
818 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
819 floating point constant [c] to integer type [ty].
820 See the method [llvm::ConstantExpr::getFPToSI]. *)
821 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
823 (** [const_ptrtoint c ty] returns the constant integer conversion of
824 pointer constant [c] to integer type [ty].
825 See the method [llvm::ConstantExpr::getPtrToInt]. *)
826 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
828 (** [const_inttoptr c ty] returns the constant pointer conversion of
829 integer constant [c] to pointer type [ty].
830 See the method [llvm::ConstantExpr::getIntToPtr]. *)
831 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
833 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
834 to type [ty] of equal size.
835 See the method [llvm::ConstantExpr::getBitCast]. *)
836 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
838 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
839 conversion of constant [c] to type [ty].
840 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
841 external const_zext_or_bitcast : llvalue -> lltype -> llvalue
842 = "LLVMConstZExtOrBitCast"
844 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
845 conversion of constant [c] to type [ty].
846 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
847 external const_sext_or_bitcast : llvalue -> lltype -> llvalue
848 = "LLVMConstSExtOrBitCast"
850 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
851 conversion of constant [c] to type [ty].
852 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
853 external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
854 = "LLVMConstTruncOrBitCast"
856 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
857 cast conversion of constant [c] to type [ty] of equal size.
858 See the method [llvm::ConstantExpr::getPointerCast]. *)
859 external const_pointercast : llvalue -> lltype -> llvalue
860 = "LLVMConstPointerCast"
862 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
863 -> integer casts of constant [c] to type [ty].
864 See the method [llvm::ConstantExpr::getIntCast]. *)
865 external const_intcast : llvalue -> lltype -> llvalue
868 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
869 fp casts of constant [c] to type [ty].
870 See the method [llvm::ConstantExpr::getFPCast]. *)
871 external const_fpcast : llvalue -> lltype -> llvalue
874 (** [const_select cond t f] returns the constant conditional which returns value
875 [t] if the boolean constant [cond] is true and the value [f] otherwise.
876 See the method [llvm::ConstantExpr::getSelect]. *)
877 external const_select : llvalue -> llvalue -> llvalue -> llvalue
880 (** [const_extractelement vec i] returns the constant [i]th element of
881 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
882 the size of the vector.
883 See the method [llvm::ConstantExpr::getExtractElement]. *)
884 external const_extractelement : llvalue -> llvalue -> llvalue
885 = "LLVMConstExtractElement"
887 (** [const_insertelement vec v i] returns the constant vector with the same
888 elements as constant vector [v] but the [i]th element replaced by the
889 constant [v]. [v] must be a constant value with the type of the vector
890 elements. [i] must be a constant [i32] value unsigned less than the size
892 See the method [llvm::ConstantExpr::getInsertElement]. *)
893 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
894 = "LLVMConstInsertElement"
896 (** [const_shufflevector a b mask] returns a constant [shufflevector].
897 See the LLVM Language Reference for details on the [sufflevector]
899 See the method [llvm::ConstantExpr::getShuffleVector]. *)
900 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
901 = "LLVMConstShuffleVector"
903 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
904 constant aggregate [agg]. Each [idxs] must be less than the size of the
905 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
906 external const_extractvalue : llvalue -> int array -> llvalue
907 = "llvm_const_extractvalue"
909 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
910 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
911 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
912 external const_insertvalue : llvalue -> llvalue -> int array -> llvalue
913 = "llvm_const_insertvalue"
916 (** {7 Operations on global variables, functions, and aliases (globals)} *)
918 (** [global_parent g] is the enclosing module of the global value [g].
919 See the method [llvm::GlobalValue::getParent]. *)
920 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
922 (** [is_declaration g] returns [true] if the global value [g] is a declaration
923 only. Returns [false] otherwise.
924 See the method [llvm::GlobalValue::isDeclaration]. *)
925 external is_declaration : llvalue -> bool = "llvm_is_declaration"
927 (** [linkage g] returns the linkage of the global value [g].
928 See the method [llvm::GlobalValue::getLinkage]. *)
929 external linkage : llvalue -> Linkage.t = "llvm_linkage"
931 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
932 See the method [llvm::GlobalValue::setLinkage]. *)
933 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
935 (** [section g] returns the linker section of the global value [g].
936 See the method [llvm::GlobalValue::getSection]. *)
937 external section : llvalue -> string = "llvm_section"
939 (** [set_section s g] sets the linker section of the global value [g] to [s].
940 See the method [llvm::GlobalValue::setSection]. *)
941 external set_section : string -> llvalue -> unit = "llvm_set_section"
943 (** [visibility g] returns the linker visibility of the global value [g].
944 See the method [llvm::GlobalValue::getVisibility]. *)
945 external visibility : llvalue -> Visibility.t = "llvm_visibility"
947 (** [set_visibility v g] sets the linker visibility of the global value [g] to
948 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
949 external set_visibility : Visibility.t -> llvalue -> unit
950 = "llvm_set_visibility"
952 (** [alignment g] returns the required alignment of the global value [g].
953 See the method [llvm::GlobalValue::getAlignment]. *)
954 external alignment : llvalue -> int = "llvm_alignment"
956 (** [set_alignment n g] sets the required alignment of the global value [g] to
957 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
958 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
961 (** {7 Operations on global variables} *)
963 (** [declare_global ty name m] returns a new global variable of type [ty] and
964 with name [name] in module [m]. If such a global variable already exists,
965 it is returned. If the type of the existing global differs, then a bitcast
966 to [ty] is returned. *)
967 external declare_global : lltype -> string -> llmodule -> llvalue
968 = "llvm_declare_global"
970 (** [define_global name init m] returns a new global with name [name] and
971 initializer [init] in module [m]. If the named global already exists, it is
973 See the constructor of [llvm::GlobalVariable]. *)
974 external define_global : string -> llvalue -> llmodule -> llvalue
975 = "llvm_define_global"
977 (** [lookup_global name m] returns [Some g] if a global variable with name
978 [name] exists in module [m]. If no such global exists, returns [None].
979 See the [llvm::GlobalVariable] constructor. *)
980 external lookup_global : string -> llmodule -> llvalue option
981 = "llvm_lookup_global"
983 (** [delete_global gv] destroys the global variable [gv].
984 See the method [llvm::GlobalVariable::eraseFromParent]. *)
985 external delete_global : llvalue -> unit = "llvm_delete_global"
987 (** [global_begin m] returns the first position in the global variable list of
988 the module [m]. [global_begin] and [global_succ] can be used to iterate
989 over the global list in order.
990 See the method [llvm::Module::global_begin]. *)
991 external global_begin : llmodule -> (llmodule, llvalue) llpos
992 = "llvm_global_begin"
994 (** [global_succ gv] returns the global variable list position succeeding
996 See the method [llvm::Module::global_iterator::operator++]. *)
997 external global_succ : llvalue -> (llmodule, llvalue) llpos
1000 (** [iter_globals f m] applies function [f] to each of the global variables of
1001 module [m] in order. Tail recursive. *)
1002 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1004 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1005 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1006 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1008 (** [global_end m] returns the last position in the global variable list of the
1009 module [m]. [global_end] and [global_pred] can be used to iterate over the
1010 global list in reverse.
1011 See the method [llvm::Module::global_end]. *)
1012 external global_end : llmodule -> (llmodule, llvalue) llrev_pos
1015 (** [global_pred gv] returns the global variable list position preceding
1017 See the method [llvm::Module::global_iterator::operator--]. *)
1018 external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1019 = "llvm_global_pred"
1021 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1022 of module [m] in reverse order. Tail recursive. *)
1023 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1025 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1026 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1027 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1029 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1030 constant. Returns [false] otherwise.
1031 See the method [llvm::GlobalVariable::isConstant]. *)
1032 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
1034 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1035 [c] is [true] and not if [c] is [false].
1036 See the method [llvm::GlobalVariable::setConstant]. *)
1037 external set_global_constant : bool -> llvalue -> unit
1038 = "llvm_set_global_constant"
1040 (** [global_initializer gv] returns the initializer for the global variable
1041 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1042 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
1044 (** [set_initializer c gv] sets the initializer for the global variable
1045 [gv] to the constant [c].
1046 See the method [llvm::GlobalVariable::setInitializer]. *)
1047 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
1049 (** [remove_initializer gv] unsets the initializer for the global variable
1051 See the method [llvm::GlobalVariable::setInitializer]. *)
1052 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
1054 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1055 thread-local and [false] otherwise.
1056 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1057 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
1059 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1060 [c] is [true] and not otherwise.
1061 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1062 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
1065 (** {7 Operations on functions} *)
1067 (** [declare_function name ty m] returns a new function of type [ty] and
1068 with name [name] in module [m]. If such a function already exists,
1069 it is returned. If the type of the existing function differs, then a bitcast
1070 to [ty] is returned. *)
1071 external declare_function : string -> lltype -> llmodule -> llvalue
1072 = "llvm_declare_function"
1074 (** [define_function name ty m] creates a new function with name [name] and
1075 type [ty] in module [m]. If the named function already exists, it is
1076 renamed. An entry basic block is created in the function.
1077 See the constructor of [llvm::GlobalVariable]. *)
1078 external define_function : string -> lltype -> llmodule -> llvalue
1079 = "llvm_define_function"
1081 (** [lookup_function name m] returns [Some f] if a function with name
1082 [name] exists in module [m]. If no such function exists, returns [None].
1083 See the method [llvm::Module] constructor. *)
1084 external lookup_function : string -> llmodule -> llvalue option
1085 = "llvm_lookup_function"
1087 (** [delete_function f] destroys the function [f].
1088 See the method [llvm::Function::eraseFromParent]. *)
1089 external delete_function : llvalue -> unit = "llvm_delete_function"
1091 (** [function_begin m] returns the first position in the function list of the
1092 module [m]. [function_begin] and [function_succ] can be used to iterate over
1093 the function list in order.
1094 See the method [llvm::Module::begin]. *)
1095 external function_begin : llmodule -> (llmodule, llvalue) llpos
1096 = "llvm_function_begin"
1098 (** [function_succ gv] returns the function list position succeeding
1100 See the method [llvm::Module::iterator::operator++]. *)
1101 external function_succ : llvalue -> (llmodule, llvalue) llpos
1102 = "llvm_function_succ"
1104 (** [iter_functions f m] applies function [f] to each of the functions of module
1105 [m] in order. Tail recursive. *)
1106 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1108 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1109 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1110 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1112 (** [function_end m] returns the last position in the function list of
1113 the module [m]. [function_end] and [function_pred] can be used to iterate
1114 over the function list in reverse.
1115 See the method [llvm::Module::end]. *)
1116 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
1117 = "llvm_function_end"
1119 (** [function_pred gv] returns the function list position preceding [After gv].
1120 See the method [llvm::Module::iterator::operator--]. *)
1121 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1122 = "llvm_function_pred"
1124 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1125 module [m] in reverse order. Tail recursive. *)
1126 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1128 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1129 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1130 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1132 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1133 See the method [llvm::Function::isIntrinsic]. *)
1134 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
1136 (** [function_call_conv f] returns the calling convention of the function [f].
1137 See the method [llvm::Function::getCallingConv]. *)
1138 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
1140 (** [set_function_call_conv cc f] sets the calling convention of the function
1141 [f] to the calling convention numbered [cc].
1142 See the method [llvm::Function::setCallingConv]. *)
1143 external set_function_call_conv : int -> llvalue -> unit
1144 = "llvm_set_function_call_conv"
1146 (** [gc f] returns [Some name] if the function [f] has a garbage
1147 collection algorithm specified and [None] otherwise.
1148 See the method [llvm::Function::getGC]. *)
1149 external gc : llvalue -> string option = "llvm_gc"
1151 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1152 [gc]. See the method [llvm::Function::setGC]. *)
1153 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
1155 (** [add_function_attr f a] adds attribute [a] to the return type of function
1157 external add_function_attr : llvalue -> Attribute.t -> unit
1158 = "llvm_add_function_attr"
1160 (** [remove_function_attr f a] removes attribute [a] from the return type of
1162 external remove_function_attr : llvalue -> Attribute.t -> unit
1163 = "llvm_remove_function_attr"
1165 (** {7 Operations on params} *)
1167 (** [params f] returns the parameters of function [f].
1168 See the method [llvm::Function::getArgumentList]. *)
1169 external params : llvalue -> llvalue array = "llvm_params"
1171 (** [param f n] returns the [n]th parameter of function [f].
1172 See the method [llvm::Function::getArgumentList]. *)
1173 external param : llvalue -> int -> llvalue = "llvm_param"
1175 (** [param_parent p] returns the parent function that owns the parameter.
1176 See the method [llvm::Argument::getParent]. *)
1177 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
1179 (** [param_begin f] returns the first position in the parameter list of the
1180 function [f]. [param_begin] and [param_succ] can be used to iterate over
1181 the parameter list in order.
1182 See the method [llvm::Function::arg_begin]. *)
1183 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
1185 (** [param_succ bb] returns the parameter list position succeeding
1187 See the method [llvm::Function::arg_iterator::operator++]. *)
1188 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
1190 (** [iter_params f fn] applies function [f] to each of the parameters
1191 of function [fn] in order. Tail recursive. *)
1192 val iter_params : (llvalue -> unit) -> llvalue -> unit
1194 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1195 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1196 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1198 (** [param_end f] returns the last position in the parameter list of
1199 the function [f]. [param_end] and [param_pred] can be used to iterate
1200 over the parameter list in reverse.
1201 See the method [llvm::Function::arg_end]. *)
1202 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
1204 (** [param_pred gv] returns the function list position preceding [After gv].
1205 See the method [llvm::Function::arg_iterator::operator--]. *)
1206 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1209 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1210 of function [fn] in reverse order. Tail recursive. *)
1211 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1213 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1214 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1215 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1217 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1218 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1220 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1221 external remove_param_attr : llvalue -> Attribute.t -> unit
1222 = "llvm_remove_param_attr"
1224 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1225 external set_param_alignment : llvalue -> int -> unit
1226 = "llvm_set_param_alignment"
1228 (** {7 Operations on basic blocks} *)
1230 (** [basic_blocks fn] returns the basic blocks of the function [f].
1231 See the method [llvm::Function::getBasicBlockList]. *)
1232 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
1234 (** [entry_block fn] returns the entry basic block of the function [f].
1235 See the method [llvm::Function::getEntryBlock]. *)
1236 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1238 (** [delete_block bb] deletes the basic block [bb].
1239 See the method [llvm::BasicBlock::eraseFromParent]. *)
1240 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1242 (** [append_block c name f] creates a new basic block named [name] at the end of
1243 function [f] in the context [c].
1244 See the constructor of [llvm::BasicBlock]. *)
1245 external append_block : llcontext -> string -> llvalue -> llbasicblock
1246 = "llvm_append_block"
1248 (** [insert_block c name bb] creates a new basic block named [name] before the
1249 basic block [bb] in the context [c].
1250 See the constructor of [llvm::BasicBlock]. *)
1251 external insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1252 = "llvm_insert_block"
1254 (** [block_parent bb] returns the parent function that owns the basic block.
1255 See the method [llvm::BasicBlock::getParent]. *)
1256 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1258 (** [block_begin f] returns the first position in the basic block list of the
1259 function [f]. [block_begin] and [block_succ] can be used to iterate over
1260 the basic block list in order.
1261 See the method [llvm::Function::begin]. *)
1262 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1263 = "llvm_block_begin"
1265 (** [block_succ bb] returns the basic block list position succeeding
1267 See the method [llvm::Function::iterator::operator++]. *)
1268 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1271 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1272 of function [fn] in order. Tail recursive. *)
1273 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1275 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1276 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1277 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1279 (** [block_end f] returns the last position in the basic block list of
1280 the function [f]. [block_end] and [block_pred] can be used to iterate
1281 over the basic block list in reverse.
1282 See the method [llvm::Function::end]. *)
1283 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1286 (** [block_pred gv] returns the function list position preceding [After gv].
1287 See the method [llvm::Function::iterator::operator--]. *)
1288 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1291 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1292 of function [fn] in reverse order. Tail recursive. *)
1293 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1295 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1296 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1297 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1299 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1300 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1302 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1304 Similar to [llvm::isa<BasicBlock>]. *)
1305 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1307 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1308 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1311 (** {7 Operations on instructions} *)
1313 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1314 See the method [llvm::Instruction::getParent]. *)
1315 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1317 (** [instr_begin bb] returns the first position in the instruction list of the
1318 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1319 the instruction list in order.
1320 See the method [llvm::BasicBlock::begin]. *)
1321 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1322 = "llvm_instr_begin"
1324 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1325 See the method [llvm::BasicBlock::iterator::operator++]. *)
1326 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1329 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1330 block [bb] in order. Tail recursive. *)
1331 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1333 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1334 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1335 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1337 (** [instr_end bb] returns the last position in the instruction list of the
1338 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1339 the instruction list in reverse.
1340 See the method [llvm::BasicBlock::end]. *)
1341 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1344 (** [instr_pred i] returns the instruction list position preceding [After i].
1345 See the method [llvm::BasicBlock::iterator::operator--]. *)
1346 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1349 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1350 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1351 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1354 (** {7 Operations on call sites} *)
1356 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1357 instruction [ci], which may be one of the values from the module
1358 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1359 [llvm::InvokeInst::getCallingConv]. *)
1360 external instruction_call_conv: llvalue -> int
1361 = "llvm_instruction_call_conv"
1363 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1364 or invoke instruction [ci] to the integer [cc], which can be one of the
1365 values from the module {!CallConv}.
1366 See the method [llvm::CallInst::setCallingConv]
1367 and [llvm::InvokeInst::setCallingConv]. *)
1368 external set_instruction_call_conv: int -> llvalue -> unit
1369 = "llvm_set_instruction_call_conv"
1371 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1372 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1374 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1375 = "llvm_add_instruction_param_attr"
1377 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1378 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1380 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1381 = "llvm_remove_instruction_param_attr"
1383 (** {Operations on call instructions (only)} *)
1385 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1386 eligible for tail call optimization, [false] otherwise.
1387 See the method [llvm::CallInst::isTailCall]. *)
1388 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
1390 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1391 call optimization if [tc] is [true], clears otherwise.
1392 See the method [llvm::CallInst::setTailCall]. *)
1393 external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call"
1395 (** {7 Operations on phi nodes} *)
1397 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1398 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1399 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1400 = "llvm_add_incoming"
1402 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1403 See the method [llvm::PHINode::getIncomingValue]. *)
1404 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1408 (** {6 Instruction builders} *)
1410 (** [builder context] creates an instruction builder with no position in
1411 the context [context]. It is invalid to use this builder until its position
1412 is set with {!position_before} or {!position_at_end}. See the constructor
1413 for [llvm::LLVMBuilder]. *)
1414 external builder : llcontext -> llbuilder = "llvm_builder"
1416 (** [builder_at ip] creates an instruction builder positioned at [ip].
1417 See the constructor for [llvm::LLVMBuilder]. *)
1418 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1420 (** [builder_before ins] creates an instruction builder positioned before the
1421 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1422 val builder_before : llcontext -> llvalue -> llbuilder
1424 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1425 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1426 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1428 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1430 See the constructor for [llvm::LLVMBuilder]. *)
1431 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1432 = "llvm_position_builder"
1434 (** [position_before ins b] moves the instruction builder [b] to before the
1435 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1436 val position_before : llvalue -> llbuilder -> unit
1438 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1439 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1440 val position_at_end : llbasicblock -> llbuilder -> unit
1442 (** [insertion_block b] returns the basic block that the builder [b] is
1443 positioned to insert into. Raises [Not_Found] if the instruction builder is
1445 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1446 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1448 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1449 position specified by the instruction builder [b].
1450 See the method [llvm::LLVMBuilder::Insert]. *)
1451 external insert_into_builder : llvalue -> string -> llbuilder -> unit
1452 = "llvm_insert_into_builder"
1455 (** {7 Terminators} *)
1457 (** [build_ret_void b] creates a
1459 instruction at the position specified by the instruction builder [b].
1460 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1461 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1463 (** [build_ret v b] creates a
1465 instruction at the position specified by the instruction builder [b].
1466 See the method [llvm::LLVMBuilder::CreateRet]. *)
1467 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1469 (** [build_aggregate_ret vs b] creates a
1470 [ret {...} { %v1, %v2, ... } ]
1471 instruction at the position specified by the instruction builder [b].
1472 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1473 external build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1474 = "llvm_build_aggregate_ret"
1476 (** [build_br bb b] creates a
1478 instruction at the position specified by the instruction builder [b].
1479 See the method [llvm::LLVMBuilder::CreateBr]. *)
1480 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1482 (** [build_cond_br cond tbb fbb b] creates a
1483 [br %cond, %tbb, %fbb]
1484 instruction at the position specified by the instruction builder [b].
1485 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1486 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1487 llvalue = "llvm_build_cond_br"
1489 (** [build_switch case elsebb count b] creates an empty
1490 [switch %case, %elsebb]
1491 instruction at the position specified by the instruction builder [b] with
1492 space reserved for [count] cases.
1493 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1494 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1495 = "llvm_build_switch"
1497 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1498 when its input matches the constant [onval].
1499 See the method [llvm::SwitchInst::addCase]. **)
1500 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1503 (** [build_invoke fn args tobb unwindbb name b] creates an
1504 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1505 instruction at the position specified by the instruction builder [b].
1506 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1507 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1508 llbasicblock -> string -> llbuilder -> llvalue
1509 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1511 (** [build_unwind b] creates an
1513 instruction at the position specified by the instruction builder [b].
1514 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1515 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1517 (** [build_unreachable b] creates an
1519 instruction at the position specified by the instruction builder [b].
1520 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1521 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1524 (** {7 Arithmetic} *)
1526 (** [build_add x y name b] creates a
1527 [%name = add %x, %y]
1528 instruction at the position specified by the instruction builder [b].
1529 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1530 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1533 (** [build_nsw_add x y name b] creates a
1534 [%name = nsw add %x, %y]
1535 instruction at the position specified by the instruction builder [b].
1536 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1537 external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1538 = "llvm_build_nsw_add"
1540 (** [build_nuw_add x y name b] creates a
1541 [%name = nuw add %x, %y]
1542 instruction at the position specified by the instruction builder [b].
1543 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1544 external build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1545 = "llvm_build_nuw_add"
1547 (** [build_fadd x y name b] creates a
1548 [%name = fadd %x, %y]
1549 instruction at the position specified by the instruction builder [b].
1550 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1551 external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1554 (** [build_sub x y name b] creates a
1555 [%name = sub %x, %y]
1556 instruction at the position specified by the instruction builder [b].
1557 See the method [llvm::LLVMBuilder::CreateSub]. *)
1558 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1561 (** [build_nsw_sub x y name b] creates a
1562 [%name = nsw sub %x, %y]
1563 instruction at the position specified by the instruction builder [b].
1564 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1565 external build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1566 = "llvm_build_nsw_sub"
1568 (** [build_nuw_sub x y name b] creates a
1569 [%name = nuw sub %x, %y]
1570 instruction at the position specified by the instruction builder [b].
1571 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1572 external build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1573 = "llvm_build_nuw_sub"
1575 (** [build_fsub x y name b] creates a
1576 [%name = fsub %x, %y]
1577 instruction at the position specified by the instruction builder [b].
1578 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1579 external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1582 (** [build_mul x y name b] creates a
1583 [%name = mul %x, %y]
1584 instruction at the position specified by the instruction builder [b].
1585 See the method [llvm::LLVMBuilder::CreateMul]. *)
1586 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1589 (** [build_nsw_mul x y name b] creates a
1590 [%name = nsw mul %x, %y]
1591 instruction at the position specified by the instruction builder [b].
1592 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1593 external build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1594 = "llvm_build_nsw_mul"
1596 (** [build_nuw_mul x y name b] creates a
1597 [%name = nuw mul %x, %y]
1598 instruction at the position specified by the instruction builder [b].
1599 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1600 external build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1601 = "llvm_build_nuw_mul"
1603 (** [build_fmul x y name b] creates a
1604 [%name = fmul %x, %y]
1605 instruction at the position specified by the instruction builder [b].
1606 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1607 external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1610 (** [build_udiv x y name b] creates a
1611 [%name = udiv %x, %y]
1612 instruction at the position specified by the instruction builder [b].
1613 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1614 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1617 (** [build_sdiv x y name b] creates a
1618 [%name = sdiv %x, %y]
1619 instruction at the position specified by the instruction builder [b].
1620 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1621 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1624 (** [build_exact_sdiv x y name b] creates a
1625 [%name = exact sdiv %x, %y]
1626 instruction at the position specified by the instruction builder [b].
1627 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1628 external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1629 = "llvm_build_exact_sdiv"
1631 (** [build_fdiv x y name b] creates a
1632 [%name = fdiv %x, %y]
1633 instruction at the position specified by the instruction builder [b].
1634 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1635 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1638 (** [build_urem x y name b] creates a
1639 [%name = urem %x, %y]
1640 instruction at the position specified by the instruction builder [b].
1641 See the method [llvm::LLVMBuilder::CreateURem]. *)
1642 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1645 (** [build_SRem x y name b] creates a
1646 [%name = srem %x, %y]
1647 instruction at the position specified by the instruction builder [b].
1648 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1649 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1652 (** [build_frem x y name b] creates a
1653 [%name = frem %x, %y]
1654 instruction at the position specified by the instruction builder [b].
1655 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1656 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1659 (** [build_shl x y name b] creates a
1660 [%name = shl %x, %y]
1661 instruction at the position specified by the instruction builder [b].
1662 See the method [llvm::LLVMBuilder::CreateShl]. *)
1663 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1666 (** [build_lshr x y name b] creates a
1667 [%name = lshr %x, %y]
1668 instruction at the position specified by the instruction builder [b].
1669 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1670 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1673 (** [build_ashr x y name b] creates a
1674 [%name = ashr %x, %y]
1675 instruction at the position specified by the instruction builder [b].
1676 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1677 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1680 (** [build_and x y name b] creates a
1681 [%name = and %x, %y]
1682 instruction at the position specified by the instruction builder [b].
1683 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1684 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1687 (** [build_or x y name b] creates a
1689 instruction at the position specified by the instruction builder [b].
1690 See the method [llvm::LLVMBuilder::CreateOr]. *)
1691 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1694 (** [build_xor x y name b] creates a
1695 [%name = xor %x, %y]
1696 instruction at the position specified by the instruction builder [b].
1697 See the method [llvm::LLVMBuilder::CreateXor]. *)
1698 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1701 (** [build_neg x name b] creates a
1703 instruction at the position specified by the instruction builder [b].
1704 [-0.0] is used for floating point types to compute the correct sign.
1705 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1706 external build_neg : llvalue -> string -> llbuilder -> llvalue
1709 (** [build_nsw_neg x name b] creates a
1710 [%name = nsw sub 0, %x]
1711 instruction at the position specified by the instruction builder [b].
1712 [-0.0] is used for floating point types to compute the correct sign.
1713 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1714 external build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1715 = "llvm_build_nsw_neg"
1717 (** [build_nuw_neg x name b] creates a
1718 [%name = nuw sub 0, %x]
1719 instruction at the position specified by the instruction builder [b].
1720 [-0.0] is used for floating point types to compute the correct sign.
1721 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1722 external build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1723 = "llvm_build_nuw_neg"
1725 (** [build_fneg x name b] creates a
1726 [%name = fsub 0, %x]
1727 instruction at the position specified by the instruction builder [b].
1728 [-0.0] is used for floating point types to compute the correct sign.
1729 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1730 external build_fneg : llvalue -> string -> llbuilder -> llvalue
1733 (** [build_xor x name b] creates a
1734 [%name = xor %x, -1]
1735 instruction at the position specified by the instruction builder [b].
1736 [-1] is the correct "all ones" value for the type of [x].
1737 See the method [llvm::LLVMBuilder::CreateXor]. *)
1738 external build_not : llvalue -> string -> llbuilder -> llvalue
1744 (** [build_alloca ty name b] creates a
1745 [%name = alloca %ty]
1746 instruction at the position specified by the instruction builder [b].
1747 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1748 external build_alloca : lltype -> string -> llbuilder -> llvalue
1749 = "llvm_build_alloca"
1751 (** [build_array_alloca ty n name b] creates a
1752 [%name = alloca %ty, %n]
1753 instruction at the position specified by the instruction builder [b].
1754 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1755 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1756 llvalue = "llvm_build_array_alloca"
1758 (** [build_load v name b] creates a
1760 instruction at the position specified by the instruction builder [b].
1761 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1762 external build_load : llvalue -> string -> llbuilder -> llvalue
1765 (** [build_store v p b] creates a
1767 instruction at the position specified by the instruction builder [b].
1768 See the method [llvm::LLVMBuilder::CreateStore]. *)
1769 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1770 = "llvm_build_store"
1772 (** [build_gep p indices name b] creates a
1773 [%name = getelementptr %p, indices...]
1774 instruction at the position specified by the instruction builder [b].
1775 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1776 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1779 (** [build_in_bounds_gep p indices name b] creates a
1780 [%name = gelementptr inbounds %p, indices...]
1781 instruction at the position specified by the instruction builder [b].
1782 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1783 external build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1784 llvalue = "llvm_build_in_bounds_gep"
1786 (** [build_struct_gep p idx name b] creates a
1787 [%name = getelementptr %p, 0, idx]
1788 instruction at the position specified by the instruction builder [b].
1789 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1790 external build_struct_gep : llvalue -> int -> string -> llbuilder ->
1791 llvalue = "llvm_build_struct_gep"
1793 (** [build_global_string str name b] creates a series of instructions that adds
1794 a global string at the position specified by the instruction builder [b].
1795 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1796 external build_global_string : string -> string -> llbuilder -> llvalue
1797 = "llvm_build_global_string"
1799 (** [build_global_stringptr str name b] creates a series of instructions that
1800 adds a global string pointer at the position specified by the instruction
1802 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1803 external build_global_stringptr : string -> string -> llbuilder -> llvalue
1804 = "llvm_build_global_stringptr"
1809 (** [build_trunc v ty name b] creates a
1810 [%name = trunc %p to %ty]
1811 instruction at the position specified by the instruction builder [b].
1812 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1813 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1814 = "llvm_build_trunc"
1816 (** [build_zext v ty name b] creates a
1817 [%name = zext %p to %ty]
1818 instruction at the position specified by the instruction builder [b].
1819 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1820 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1823 (** [build_sext v ty name b] creates a
1824 [%name = sext %p to %ty]
1825 instruction at the position specified by the instruction builder [b].
1826 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1827 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1830 (** [build_fptoui v ty name b] creates a
1831 [%name = fptoui %p to %ty]
1832 instruction at the position specified by the instruction builder [b].
1833 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1834 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1835 = "llvm_build_fptoui"
1837 (** [build_fptosi v ty name b] creates a
1838 [%name = fptosi %p to %ty]
1839 instruction at the position specified by the instruction builder [b].
1840 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1841 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1842 = "llvm_build_fptosi"
1844 (** [build_uitofp v ty name b] creates a
1845 [%name = uitofp %p to %ty]
1846 instruction at the position specified by the instruction builder [b].
1847 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1848 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1849 = "llvm_build_uitofp"
1851 (** [build_sitofp v ty name b] creates a
1852 [%name = sitofp %p to %ty]
1853 instruction at the position specified by the instruction builder [b].
1854 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1855 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1856 = "llvm_build_sitofp"
1858 (** [build_fptrunc v ty name b] creates a
1859 [%name = fptrunc %p to %ty]
1860 instruction at the position specified by the instruction builder [b].
1861 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1862 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1863 = "llvm_build_fptrunc"
1865 (** [build_fpext v ty name b] creates a
1866 [%name = fpext %p to %ty]
1867 instruction at the position specified by the instruction builder [b].
1868 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1869 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1870 = "llvm_build_fpext"
1872 (** [build_ptrtoint v ty name b] creates a
1873 [%name = prtotint %p to %ty]
1874 instruction at the position specified by the instruction builder [b].
1875 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1876 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1877 = "llvm_build_prttoint"
1879 (** [build_inttoptr v ty name b] creates a
1880 [%name = inttoptr %p to %ty]
1881 instruction at the position specified by the instruction builder [b].
1882 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1883 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1884 = "llvm_build_inttoptr"
1886 (** [build_bitcast v ty name b] creates a
1887 [%name = bitcast %p to %ty]
1888 instruction at the position specified by the instruction builder [b].
1889 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
1890 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1891 = "llvm_build_bitcast"
1893 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
1894 instruction at the position specified by the instruction builder [b].
1895 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1896 external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1897 llvalue = "llvm_build_zext_or_bitcast"
1899 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
1900 instruction at the position specified by the instruction builder [b].
1901 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
1902 external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1903 llvalue = "llvm_build_sext_or_bitcast"
1905 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
1906 instruction at the position specified by the instruction builder [b].
1907 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1908 external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1909 llvalue = "llvm_build_trunc_or_bitcast"
1911 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
1912 instruction at the position specified by the instruction builder [b].
1913 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
1914 external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
1915 = "llvm_build_pointercast"
1917 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
1918 instruction at the position specified by the instruction builder [b].
1919 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
1920 external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1921 = "llvm_build_intcast"
1923 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
1924 instruction at the position specified by the instruction builder [b].
1925 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
1926 external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1927 = "llvm_build_fpcast"
1930 (** {7 Comparisons} *)
1932 (** [build_icmp pred x y name b] creates a
1933 [%name = icmp %pred %x, %y]
1934 instruction at the position specified by the instruction builder [b].
1935 See the method [llvm::LLVMBuilder::CreateICmp]. *)
1936 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1937 llbuilder -> llvalue = "llvm_build_icmp"
1939 (** [build_fcmp pred x y name b] creates a
1940 [%name = fcmp %pred %x, %y]
1941 instruction at the position specified by the instruction builder [b].
1942 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1943 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1944 llbuilder -> llvalue = "llvm_build_fcmp"
1947 (** {7 Miscellaneous instructions} *)
1949 (** [build_phi incoming name b] creates a
1950 [%name = phi %incoming]
1951 instruction at the position specified by the instruction builder [b].
1952 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1953 See the method [llvm::LLVMBuilder::CreatePHI]. *)
1954 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1955 llvalue = "llvm_build_phi"
1957 (** [build_call fn args name b] creates a
1958 [%name = call %fn(args...)]
1959 instruction at the position specified by the instruction builder [b].
1960 See the method [llvm::LLVMBuilder::CreateCall]. *)
1961 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1964 (** [build_select cond thenv elsev name b] creates a
1965 [%name = select %cond, %thenv, %elsev]
1966 instruction at the position specified by the instruction builder [b].
1967 See the method [llvm::LLVMBuilder::CreateSelect]. *)
1968 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1969 llvalue = "llvm_build_select"
1971 (** [build_va_arg valist argty name b] creates a
1972 [%name = va_arg %valist, %argty]
1973 instruction at the position specified by the instruction builder [b].
1974 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1975 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1976 = "llvm_build_va_arg"
1978 (** [build_extractelement vec i name b] creates a
1979 [%name = extractelement %vec, %i]
1980 instruction at the position specified by the instruction builder [b].
1981 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1982 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1983 llvalue = "llvm_build_extractelement"
1985 (** [build_insertelement vec elt i name b] creates a
1986 [%name = insertelement %vec, %elt, %i]
1987 instruction at the position specified by the instruction builder [b].
1988 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1989 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1990 llbuilder -> llvalue = "llvm_build_insertelement"
1992 (** [build_shufflevector veca vecb mask name b] creates a
1993 [%name = shufflevector %veca, %vecb, %mask]
1994 instruction at the position specified by the instruction builder [b].
1995 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1996 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1997 llbuilder -> llvalue = "llvm_build_shufflevector"
1999 (** [build_insertvalue agg idx name b] creates a
2000 [%name = extractvalue %agg, %idx]
2001 instruction at the position specified by the instruction builder [b].
2002 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2003 external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2004 = "llvm_build_extractvalue"
2006 (** [build_insertvalue agg val idx name b] creates a
2007 [%name = insertvalue %agg, %val, %idx]
2008 instruction at the position specified by the instruction builder [b].
2009 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2010 external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2011 llvalue = "llvm_build_insertvalue"
2013 (** [build_is_null val name b] creates a
2014 [%name = icmp eq %val, null]
2015 instruction at the position specified by the instruction builder [b].
2016 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2017 external build_is_null : llvalue -> string -> llbuilder -> llvalue
2018 = "llvm_build_is_null"
2020 (** [build_is_not_null val name b] creates a
2021 [%name = icmp ne %val, null]
2022 instruction at the position specified by the instruction builder [b].
2023 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2024 external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2025 = "llvm_build_is_not_null"
2027 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2028 the difference between two pointer values at the position specified by the
2029 instruction builder [b].
2030 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2031 external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2032 = "llvm_build_ptrdiff"
2034 (** {6 Module providers} *)
2036 module ModuleProvider : sig
2037 (** [create_module_provider m] encapsulates [m] in a module provider and takes
2038 ownership of the module. See the constructor
2039 [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
2040 external create : llmodule -> llmoduleprovider
2041 = "LLVMCreateModuleProviderForExistingModule"
2043 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
2044 the contained module. *)
2045 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
2049 (** {6 Memory buffers} *)
2051 module MemoryBuffer : sig
2052 (** [of_file p] is the memory buffer containing the contents of the file at
2053 path [p]. If the file could not be read, then [IoError msg] is
2055 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
2057 (** [stdin ()] is the memory buffer containing the contents of standard input.
2058 If standard input is empty, then [IoError msg] is raised. *)
2059 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
2061 (** Disposes of a memory buffer. *)
2062 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
2066 (** {6 Pass Managers} *)
2068 module PassManager : sig
2071 type any = [ `Module | `Function ]
2073 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2074 type of pipeline is suitable for link-time optimization and whole-module
2076 See the constructor of [llvm::PassManager]. *)
2077 external create : unit -> [ `Module ] t = "llvm_passmanager_create"
2079 (** [PassManager.create_function mp] constructs a new function-by-function
2080 pass pipeline over the module provider [mp]. It does not take ownership of
2081 [mp]. This type of pipeline is suitable for code generation and JIT
2083 See the constructor of [llvm::FunctionPassManager]. *)
2084 external create_function : llmoduleprovider -> [ `Function ] t
2085 = "LLVMCreateFunctionPassManager"
2087 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2088 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2089 any of the passes modified the module, [false] otherwise.
2090 See the [llvm::PassManager::run] method. *)
2091 external run_module : llmodule -> [ `Module ] t -> bool
2092 = "llvm_passmanager_run_module"
2094 (** [initialize fpm] initializes all of the function passes scheduled in the
2095 function pass manager [fpm]. Returns [true] if any of the passes modified
2096 the module, [false] otherwise.
2097 See the [llvm::FunctionPassManager::doInitialization] method. *)
2098 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
2100 (** [run_function f fpm] executes all of the function passes scheduled in the
2101 function pass manager [fpm] over the function [f]. Returns [true] if any
2102 of the passes modified [f], [false] otherwise.
2103 See the [llvm::FunctionPassManager::run] method. *)
2104 external run_function : llvalue -> [ `Function ] t -> bool
2105 = "llvm_passmanager_run_function"
2107 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2108 function pass manager [fpm]. Returns [true] if any of the passes
2109 modified the module, [false] otherwise.
2110 See the [llvm::FunctionPassManager::doFinalization] method. *)
2111 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
2113 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2114 the module provider.
2115 See the destructor of [llvm::BasePassManager]. *)
2116 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"