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"
224 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
225 name [name] in the context [context]. See the function
226 [llvm::LLVMContext::getMDKindID]. *)
227 external mdkind_id : llcontext -> string -> int = "llvm_mdkind_id"
232 (** [create_module context id] creates a module with the supplied module ID in
233 the context [context]. Modules are not garbage collected; it is mandatory
234 to call {!dispose_module} to free memory. See the constructor
235 [llvm::Module::Module]. *)
236 external create_module : llcontext -> string -> llmodule = "llvm_create_module"
238 (** [dispose_module m] destroys a module [m] and all of the IR objects it
239 contained. All references to subordinate objects are invalidated;
240 referencing them will invoke undefined behavior. See the destructor
241 [llvm::Module::~Module]. *)
242 external dispose_module : llmodule -> unit = "llvm_dispose_module"
244 (** [target_triple m] is the target specifier for the module [m], something like
245 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
246 external target_triple: llmodule -> string
247 = "llvm_target_triple"
249 (** [target_triple triple m] changes the target specifier for the module [m] to
250 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
251 external set_target_triple: string -> llmodule -> unit
252 = "llvm_set_target_triple"
254 (** [data_layout m] is the data layout specifier for the module [m], something
255 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
256 method [llvm::Module::getDataLayout]. *)
257 external data_layout: llmodule -> string
260 (** [set_data_layout s m] changes the data layout specifier for the module [m]
261 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
262 external set_data_layout: string -> llmodule -> unit
263 = "llvm_set_data_layout"
265 (** [define_type_name name ty m] adds a named type to the module's symbol table.
266 Returns [true] if successful. If such a name already exists, then no entry
267 is added and [false] is returned. See the [llvm::Module::addTypeName]
269 external define_type_name : string -> lltype -> llmodule -> bool
270 = "llvm_add_type_name"
272 (** [delete_type_name name] removes a type name from the module's symbol
274 external delete_type_name : string -> llmodule -> unit
275 = "llvm_delete_type_name"
277 (** [type_by_name m n] returns the type in the module [m] named [n], or [None]
278 if it does not exist. See the method [llvm::Module::getTypeByName]. *)
279 external type_by_name : llmodule -> string -> lltype option
280 = "llvm_type_by_name"
282 (** [dump_module m] prints the .ll representation of the module [m] to standard
283 error. See the method [llvm::Module::dump]. *)
284 external dump_module : llmodule -> unit = "llvm_dump_module"
289 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
290 See the method [llvm::Type::getTypeID]. *)
291 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
293 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
294 See the method [llvm::Type::getContext]. *)
295 external type_context : lltype -> llcontext = "llvm_type_context"
297 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
298 val string_of_lltype : lltype -> string
300 (** {7 Operations on integer types} *)
302 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
303 [llvm::Type::Int1Ty]. *)
304 external i1_type : llcontext -> lltype = "llvm_i1_type"
306 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
307 [llvm::Type::Int8Ty]. *)
308 external i8_type : llcontext -> lltype = "llvm_i8_type"
310 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
311 [llvm::Type::Int16Ty]. *)
312 external i16_type : llcontext -> lltype = "llvm_i16_type"
314 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
315 [llvm::Type::Int32Ty]. *)
316 external i32_type : llcontext -> lltype = "llvm_i32_type"
318 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
319 [llvm::Type::Int64Ty]. *)
320 external i64_type : llcontext -> lltype = "llvm_i64_type"
322 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
323 [c]. See the method [llvm::IntegerType::get]. *)
324 external integer_type : llcontext -> int -> lltype = "llvm_integer_type"
326 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
327 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
328 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
331 (** {7 Operations on real types} *)
333 (** [float_type c] returns the IEEE 32-bit floating point type in the context
334 [c]. See [llvm::Type::FloatTy]. *)
335 external float_type : llcontext -> lltype = "llvm_float_type"
337 (** [double_type c] returns the IEEE 64-bit floating point type in the context
338 [c]. See [llvm::Type::DoubleTy]. *)
339 external double_type : llcontext -> lltype = "llvm_double_type"
341 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
342 [c]. See [llvm::Type::X86_FP80Ty]. *)
343 external x86fp80_type : llcontext -> lltype = "llvm_x86fp80_type"
345 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
346 [c]. See [llvm::Type::FP128Ty]. *)
347 external fp128_type : llcontext -> lltype = "llvm_fp128_type"
349 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
350 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
351 external ppc_fp128_type : llcontext -> lltype = "llvm_ppc_fp128_type"
354 (** {7 Operations on function types} *)
356 (** [function_type ret_ty param_tys] returns the function type returning
357 [ret_ty] and taking [param_tys] as parameters.
358 See the method [llvm::FunctionType::get]. *)
359 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
361 (** [va_arg_function_type ret_ty param_tys] is just like
362 [function_type ret_ty param_tys] except that it returns the function type
363 which also takes a variable number of arguments.
364 See the method [llvm::FunctionType::get]. *)
365 external var_arg_function_type : lltype -> lltype array -> lltype
366 = "llvm_var_arg_function_type"
368 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
369 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
370 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
372 (** [return_type fty] gets the return type of the function type [fty].
373 See the method [llvm::FunctionType::getReturnType]. *)
374 external return_type : lltype -> lltype = "LLVMGetReturnType"
376 (** [param_types fty] gets the parameter types of the function type [fty].
377 See the method [llvm::FunctionType::getParamType]. *)
378 external param_types : lltype -> lltype array = "llvm_param_types"
381 (** {7 Operations on struct types} *)
383 (** [struct_type context tys] returns the structure type in the context
384 [context] containing in the types in the array [tys]. See the method
385 [llvm::StructType::get]. *)
386 external struct_type : llcontext -> lltype array -> lltype
389 (** [packed_struct_type context ys] returns the packed structure type in the
390 context [context] containing in the types in the array [tys]. See the method
391 [llvm::StructType::get]. *)
392 external packed_struct_type : llcontext -> lltype array -> lltype
393 = "llvm_packed_struct_type"
395 (** [struct_element_types sty] returns the constituent types of the struct type
396 [sty]. See the method [llvm::StructType::getElementType]. *)
397 external struct_element_types : lltype -> lltype array
398 = "llvm_struct_element_types"
400 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
401 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
402 external is_packed : lltype -> bool = "llvm_is_packed"
405 (** {7 Operations on union types} *)
407 (** [union_type context tys] returns the union type in the context [context]
408 containing the types in the array [tys]. See the method
409 [llvm::UnionType::get] *)
410 external union_type : llcontext -> lltype array -> lltype = "llvm_union_type"
412 (** [union_element_types uty] returns the constituent types of the union type
413 [uty]. See the method [llvm::UnionType::getElementType]. *)
414 external union_element_types : lltype -> lltype array
415 = "llvm_union_element_types"
418 (** {7 Operations on pointer, vector, and array types} *)
420 (** [array_type ty n] returns the array type containing [n] elements of type
421 [ty]. See the method [llvm::ArrayType::get]. *)
422 external array_type : lltype -> int -> lltype = "llvm_array_type"
424 (** [pointer_type ty] returns the pointer type referencing objects of type
425 [ty] in the default address space (0).
426 See the method [llvm::PointerType::getUnqual]. *)
427 external pointer_type : lltype -> lltype = "llvm_pointer_type"
429 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
430 of type [ty] in address space [as].
431 See the method [llvm::PointerType::get]. *)
432 external qualified_pointer_type : lltype -> int -> lltype
433 = "llvm_qualified_pointer_type"
435 (** [vector_type ty n] returns the array type containing [n] elements of the
436 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
437 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
439 (** [element_type ty] returns the element type of the pointer, vector, or array
440 type [ty]. See the method [llvm::SequentialType::get]. *)
441 external element_type : lltype -> lltype = "LLVMGetElementType"
443 (** [element_type aty] returns the element count of the array type [aty].
444 See the method [llvm::ArrayType::getNumElements]. *)
445 external array_length : lltype -> int = "llvm_array_length"
447 (** [address_space pty] returns the address space qualifier of the pointer type
448 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
449 external address_space : lltype -> int = "llvm_address_space"
451 (** [element_type ty] returns the element count of the vector type [ty].
452 See the method [llvm::VectorType::getNumElements]. *)
453 external vector_size : lltype -> int = "llvm_vector_size"
456 (** {7 Operations on other types} *)
458 (** [opaque_type c] creates a new opaque type distinct from any other in the
459 context [c]. Opaque types are useful for building recursive types in
460 combination with {!refine_type}. See [llvm::OpaqueType::get]. *)
461 external opaque_type : llcontext -> lltype = "llvm_opaque_type"
463 (** [void_type c] creates a type of a function which does not return any
464 value in the context [c]. See [llvm::Type::VoidTy]. *)
465 external void_type : llcontext -> lltype = "llvm_void_type"
467 (** [label_type c] creates a type of a basic block in the context [c]. See
468 [llvm::Type::LabelTy]. *)
469 external label_type : llcontext -> lltype = "llvm_label_type"
471 (** {7 Operations on type handles} *)
473 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
474 refined as a result of a call to {!refine_type}, the handle will be updated;
475 any bare [lltype] references will become invalid.
476 See the class [llvm::PATypeHolder]. *)
477 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
479 (** [type_of_handle tyh] resolves the type handle [tyh].
480 See the method [llvm::PATypeHolder::get()]. *)
481 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
483 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
484 concrete type [ty] in all users. Warning: This may invalidate {!lltype}
485 values! Use {!lltypehandle} to manipulate potentially abstract types. See
486 the method [llvm::Type::refineAbstractType]. *)
487 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
492 (** [type_of v] returns the type of the value [v].
493 See the method [llvm::Value::getType]. *)
494 external type_of : llvalue -> lltype = "llvm_type_of"
496 (** [value_name v] returns the name of the value [v]. For global values, this is
497 the symbol name. For instructions and basic blocks, it is the SSA register
498 name. It is meaningless for constants.
499 See the method [llvm::Value::getName]. *)
500 external value_name : llvalue -> string = "llvm_value_name"
502 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
503 [llvm::Value::setName]. *)
504 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
506 (** [dump_value v] prints the .ll representation of the value [v] to standard
507 error. See the method [llvm::Value::dump]. *)
508 external dump_value : llvalue -> unit = "llvm_dump_value"
510 (** [replace_all_uses_with old new] replaces all uses of the value [old]
511 * with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
512 external replace_all_uses_with : llvalue -> llvalue -> unit
513 = "LLVMReplaceAllUsesWith"
518 (** [operand v i] returns the operand at index [i] for the value [v]. See the
519 method [llvm::User::getOperand]. *)
520 external operand : llvalue -> int -> llvalue = "llvm_operand"
523 (** {7 Operations on constants of (mostly) any type} *)
525 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
526 otherwise. Similar to [llvm::isa<Constant>]. *)
527 external is_constant : llvalue -> bool = "llvm_is_constant"
529 (** [const_null ty] returns the constant null (zero) of the type [ty].
530 See the method [llvm::Constant::getNullValue]. *)
531 external const_null : lltype -> llvalue = "LLVMConstNull"
533 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
534 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
535 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
537 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
538 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
539 external const_pointer_null : lltype -> llvalue = "LLVMConstPointerNull"
541 (** [undef ty] returns the undefined value of the type [ty].
542 See the method [llvm::UndefValue::get]. *)
543 external undef : lltype -> llvalue = "LLVMGetUndef"
545 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
546 See the method [llvm::Constant::isNullValue]. *)
547 external is_null : llvalue -> bool = "llvm_is_null"
549 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
550 otherwise. Similar to [llvm::isa<UndefValue>]. *)
551 external is_undef : llvalue -> bool = "llvm_is_undef"
554 (** {7 Operations on instructions} *)
556 (** [has_metadata i] returns whether or not the instruction [i] has any
557 metadata attached to it. See the function
558 [llvm::Instruction::hasMetadata]. *)
559 external has_metadata : llvalue -> bool = "llvm_has_metadata"
561 (** [metadata i kind] optionally returns the metadata associated with the
562 kind [kind] in the instruction [i] See the function
563 [llvm::Instruction::getMetadata]. *)
564 external metadata : llvalue -> int -> llvalue option = "llvm_metadata"
566 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
567 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
568 external set_metadata : llvalue -> int -> llvalue -> unit = "llvm_set_metadata"
570 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
571 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
572 external clear_metadata : llvalue -> int -> unit = "llvm_clear_metadata"
575 (** {7 Operations on metadata} *)
577 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
578 See the method [llvm::MDNode::get]. *)
579 external mdstring : llcontext -> string -> llvalue = "llvm_mdstring"
581 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
583 See the method [llvm::MDNode::get]. *)
584 external mdnode : llcontext -> llvalue array -> llvalue = "llvm_mdnode"
587 (** {7 Operations on scalar constants} *)
589 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
590 See the method [llvm::ConstantInt::get]. *)
591 external const_int : lltype -> int -> llvalue = "llvm_const_int"
593 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
594 [i]. See the method [llvm::ConstantInt::get]. *)
595 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
596 = "llvm_const_of_int64"
598 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
599 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
600 external const_int_of_string : lltype -> string -> int -> llvalue
601 = "llvm_const_int_of_string"
603 (** [const_float ty n] returns the floating point constant of type [ty] and
604 value [n]. See the method [llvm::ConstantFP::get]. *)
605 external const_float : lltype -> float -> llvalue = "llvm_const_float"
607 (** [const_float_of_string ty s] returns the floating point constant of type
608 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
609 external const_float_of_string : lltype -> string -> llvalue
610 = "llvm_const_float_of_string"
613 (** {7 Operations on composite constants} *)
615 (** [const_string c s] returns the constant [i8] array with the values of the
616 characters in the string [s] in the context [c]. The array is not
617 null-terminated (but see {!const_stringz}). This value can in turn be used
618 as the initializer for a global variable. See the method
619 [llvm::ConstantArray::get]. *)
620 external const_string : llcontext -> string -> llvalue = "llvm_const_string"
622 (** [const_stringz c s] returns the constant [i8] array with the values of the
623 characters in the string [s] and a null terminator in the context [c]. This
624 value can in turn be used as the initializer for a global variable.
625 See the method [llvm::ConstantArray::get]. *)
626 external const_stringz : llcontext -> string -> llvalue = "llvm_const_stringz"
628 (** [const_array ty elts] returns the constant array of type
629 [array_type ty (Array.length elts)] and containing the values [elts].
630 This value can in turn be used as the initializer for a global variable.
631 See the method [llvm::ConstantArray::get]. *)
632 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
634 (** [const_struct context elts] returns the structured constant of type
635 [struct_type (Array.map type_of elts)] and containing the values [elts]
636 in the context [context]. This value can in turn be used as the initializer
637 for a global variable. See the method [llvm::ConstantStruct::get]. *)
638 external const_struct : llcontext -> llvalue array -> llvalue
639 = "llvm_const_struct"
641 (** [const_packed_struct context elts] returns the structured constant of
642 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
643 values [elts] in the context [context]. This value can in turn be used as
644 the initializer for a global variable. See the method
645 [llvm::ConstantStruct::get]. *)
646 external const_packed_struct : llcontext -> llvalue array -> llvalue
647 = "llvm_const_packed_struct"
649 (** [const_vector elts] returns the vector constant of type
650 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
651 values [elts]. See the method [llvm::ConstantVector::get]. *)
652 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
654 (** [const_union ty v] returns the union constant of type [union_type tys] and
655 containing the value [v]. See the method [llvm::ConstantUnion::get]. *)
656 external const_union : lltype -> llvalue -> llvalue = "LLVMConstUnion"
659 (** {7 Constant expressions} *)
661 (** [align_of ty] returns the alignof constant for the type [ty]. This is
662 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
663 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
664 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
665 external align_of : lltype -> llvalue = "LLVMAlignOf"
667 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
668 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
669 (const_int i32_type 1)) i64_type], but considerably more readable.
670 See the method [llvm::ConstantExpr::getSizeOf]. *)
671 external size_of : lltype -> llvalue = "LLVMSizeOf"
673 (** [const_neg c] returns the arithmetic negation of the constant [c].
674 See the method [llvm::ConstantExpr::getNeg]. *)
675 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
677 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
678 no signed wrapping. The result is undefined if the negation overflows.
679 See the method [llvm::ConstantExpr::getNSWNeg]. *)
680 external const_nsw_neg : llvalue -> llvalue = "LLVMConstNSWNeg"
682 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
683 no unsigned wrapping. The result is undefined if the negation overflows.
684 See the method [llvm::ConstantExpr::getNUWNeg]. *)
685 external const_nuw_neg : llvalue -> llvalue = "LLVMConstNUWNeg"
687 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
688 See the method [llvm::ConstantExpr::getFNeg]. *)
689 external const_fneg : llvalue -> llvalue = "LLVMConstFNeg"
691 (** [const_not c] returns the bitwise inverse of the constant [c].
692 See the method [llvm::ConstantExpr::getNot]. *)
693 external const_not : llvalue -> llvalue = "LLVMConstNot"
695 (** [const_add c1 c2] returns the constant sum of two constants.
696 See the method [llvm::ConstantExpr::getAdd]. *)
697 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
699 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
700 signed wrapping. The result is undefined if the sum overflows.
701 See the method [llvm::ConstantExpr::getNSWAdd]. *)
702 external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd"
704 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
705 unsigned wrapping. The result is undefined if the sum overflows.
706 See the method [llvm::ConstantExpr::getNSWAdd]. *)
707 external const_nuw_add : llvalue -> llvalue -> llvalue = "LLVMConstNUWAdd"
709 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
710 See the method [llvm::ConstantExpr::getFAdd]. *)
711 external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd"
713 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
714 constants. See the method [llvm::ConstantExpr::getSub]. *)
715 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
717 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
718 no signed wrapping. The result is undefined if the sum overflows.
719 See the method [llvm::ConstantExpr::getNSWSub]. *)
720 external const_nsw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNSWSub"
722 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
723 no unsigned wrapping. The result is undefined if the sum overflows.
724 See the method [llvm::ConstantExpr::getNSWSub]. *)
725 external const_nuw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNUWSub"
727 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
728 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
729 external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub"
731 (** [const_mul c1 c2] returns the constant product of two constants.
732 See the method [llvm::ConstantExpr::getMul]. *)
733 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
735 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
736 no signed wrapping. The result is undefined if the sum overflows.
737 See the method [llvm::ConstantExpr::getNSWMul]. *)
738 external const_nsw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNSWMul"
740 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
741 no unsigned wrapping. The result is undefined if the sum overflows.
742 See the method [llvm::ConstantExpr::getNSWMul]. *)
743 external const_nuw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNUWMul"
745 (** [const_fmul c1 c2] returns the constant product of two constants floats.
746 See the method [llvm::ConstantExpr::getFMul]. *)
747 external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul"
749 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
751 See the method [llvm::ConstantExpr::getUDiv]. *)
752 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
754 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
756 See the method [llvm::ConstantExpr::getSDiv]. *)
757 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
759 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
760 signed integer constants. The result is undefined if the result is rounded
761 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
762 external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv"
764 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
766 See the method [llvm::ConstantExpr::getFDiv]. *)
767 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
769 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
770 unsigned integer constants.
771 See the method [llvm::ConstantExpr::getURem]. *)
772 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
774 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
775 signed integer constants.
776 See the method [llvm::ConstantExpr::getSRem]. *)
777 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
779 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
780 signed floating point constants.
781 See the method [llvm::ConstantExpr::getFRem]. *)
782 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
784 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
786 See the method [llvm::ConstantExpr::getAnd]. *)
787 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
789 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
791 See the method [llvm::ConstantExpr::getOr]. *)
792 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
794 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
796 See the method [llvm::ConstantExpr::getXor]. *)
797 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
799 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
800 constants, [c1 pred c2].
801 See the method [llvm::ConstantExpr::getICmp]. *)
802 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
805 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
806 point constants, [c1 pred c2].
807 See the method [llvm::ConstantExpr::getFCmp]. *)
808 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
811 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
812 constant integer [c2].
813 See the method [llvm::ConstantExpr::getShl]. *)
814 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
816 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
817 constant integer [c2] with zero extension.
818 See the method [llvm::ConstantExpr::getLShr]. *)
819 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
821 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
822 constant integer [c2] with sign extension.
823 See the method [llvm::ConstantExpr::getAShr]. *)
824 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
826 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
827 constant integers indices from the array [indices].
828 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
829 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
831 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
832 with the constant integers indices from the array [indices].
833 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
834 external const_in_bounds_gep : llvalue -> llvalue array -> llvalue
835 = "llvm_const_in_bounds_gep"
837 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
838 to the smaller integer type [ty].
839 See the method [llvm::ConstantExpr::getTrunc]. *)
840 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
842 (** [const_sext c ty] returns the constant sign extension of integer constant
843 [c] to the larger integer type [ty].
844 See the method [llvm::ConstantExpr::getSExt]. *)
845 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
847 (** [const_zext c ty] returns the constant zero extension of integer constant
848 [c] to the larger integer type [ty].
849 See the method [llvm::ConstantExpr::getZExt]. *)
850 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
852 (** [const_fptrunc c ty] returns the constant truncation of floating point
853 constant [c] to the smaller floating point type [ty].
854 See the method [llvm::ConstantExpr::getFPTrunc]. *)
855 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
857 (** [const_fpext c ty] returns the constant extension of floating point constant
858 [c] to the larger floating point type [ty].
859 See the method [llvm::ConstantExpr::getFPExt]. *)
860 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
862 (** [const_uitofp c ty] returns the constant floating point conversion of
863 unsigned integer constant [c] to the floating point type [ty].
864 See the method [llvm::ConstantExpr::getUIToFP]. *)
865 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
867 (** [const_sitofp c ty] returns the constant floating point conversion of
868 signed integer constant [c] to the floating point type [ty].
869 See the method [llvm::ConstantExpr::getSIToFP]. *)
870 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
872 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
873 floating point constant [c] to integer type [ty].
874 See the method [llvm::ConstantExpr::getFPToUI]. *)
875 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
877 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
878 floating point constant [c] to integer type [ty].
879 See the method [llvm::ConstantExpr::getFPToSI]. *)
880 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
882 (** [const_ptrtoint c ty] returns the constant integer conversion of
883 pointer constant [c] to integer type [ty].
884 See the method [llvm::ConstantExpr::getPtrToInt]. *)
885 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
887 (** [const_inttoptr c ty] returns the constant pointer conversion of
888 integer constant [c] to pointer type [ty].
889 See the method [llvm::ConstantExpr::getIntToPtr]. *)
890 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
892 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
893 to type [ty] of equal size.
894 See the method [llvm::ConstantExpr::getBitCast]. *)
895 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
897 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
898 conversion of constant [c] to type [ty].
899 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
900 external const_zext_or_bitcast : llvalue -> lltype -> llvalue
901 = "LLVMConstZExtOrBitCast"
903 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
904 conversion of constant [c] to type [ty].
905 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
906 external const_sext_or_bitcast : llvalue -> lltype -> llvalue
907 = "LLVMConstSExtOrBitCast"
909 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
910 conversion of constant [c] to type [ty].
911 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
912 external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
913 = "LLVMConstTruncOrBitCast"
915 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
916 cast conversion of constant [c] to type [ty] of equal size.
917 See the method [llvm::ConstantExpr::getPointerCast]. *)
918 external const_pointercast : llvalue -> lltype -> llvalue
919 = "LLVMConstPointerCast"
921 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
922 -> integer casts of constant [c] to type [ty].
923 See the method [llvm::ConstantExpr::getIntCast]. *)
924 external const_intcast : llvalue -> lltype -> llvalue
927 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
928 fp casts of constant [c] to type [ty].
929 See the method [llvm::ConstantExpr::getFPCast]. *)
930 external const_fpcast : llvalue -> lltype -> llvalue
933 (** [const_select cond t f] returns the constant conditional which returns value
934 [t] if the boolean constant [cond] is true and the value [f] otherwise.
935 See the method [llvm::ConstantExpr::getSelect]. *)
936 external const_select : llvalue -> llvalue -> llvalue -> llvalue
939 (** [const_extractelement vec i] returns the constant [i]th element of
940 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
941 the size of the vector.
942 See the method [llvm::ConstantExpr::getExtractElement]. *)
943 external const_extractelement : llvalue -> llvalue -> llvalue
944 = "LLVMConstExtractElement"
946 (** [const_insertelement vec v i] returns the constant vector with the same
947 elements as constant vector [v] but the [i]th element replaced by the
948 constant [v]. [v] must be a constant value with the type of the vector
949 elements. [i] must be a constant [i32] value unsigned less than the size
951 See the method [llvm::ConstantExpr::getInsertElement]. *)
952 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
953 = "LLVMConstInsertElement"
955 (** [const_shufflevector a b mask] returns a constant [shufflevector].
956 See the LLVM Language Reference for details on the [sufflevector]
958 See the method [llvm::ConstantExpr::getShuffleVector]. *)
959 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
960 = "LLVMConstShuffleVector"
962 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
963 constant aggregate [agg]. Each [idxs] must be less than the size of the
964 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
965 external const_extractvalue : llvalue -> int array -> llvalue
966 = "llvm_const_extractvalue"
968 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
969 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
970 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
971 external const_insertvalue : llvalue -> llvalue -> int array -> llvalue
972 = "llvm_const_insertvalue"
974 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
975 See the method [llvm::InlineAsm::get]. *)
976 external const_inline_asm : lltype -> string -> string -> bool -> bool ->
978 = "llvm_const_inline_asm"
980 (** [block_address f bb] returns the address of the basic block [bb] in the
981 function [f]. See the method [llvm::BasicBlock::get]. *)
982 external block_address : llvalue -> llbasicblock -> llvalue = "LLVMBlockAddress"
985 (** {7 Operations on global variables, functions, and aliases (globals)} *)
987 (** [global_parent g] is the enclosing module of the global value [g].
988 See the method [llvm::GlobalValue::getParent]. *)
989 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
991 (** [is_declaration g] returns [true] if the global value [g] is a declaration
992 only. Returns [false] otherwise.
993 See the method [llvm::GlobalValue::isDeclaration]. *)
994 external is_declaration : llvalue -> bool = "llvm_is_declaration"
996 (** [linkage g] returns the linkage of the global value [g].
997 See the method [llvm::GlobalValue::getLinkage]. *)
998 external linkage : llvalue -> Linkage.t = "llvm_linkage"
1000 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
1001 See the method [llvm::GlobalValue::setLinkage]. *)
1002 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
1004 (** [section g] returns the linker section of the global value [g].
1005 See the method [llvm::GlobalValue::getSection]. *)
1006 external section : llvalue -> string = "llvm_section"
1008 (** [set_section s g] sets the linker section of the global value [g] to [s].
1009 See the method [llvm::GlobalValue::setSection]. *)
1010 external set_section : string -> llvalue -> unit = "llvm_set_section"
1012 (** [visibility g] returns the linker visibility of the global value [g].
1013 See the method [llvm::GlobalValue::getVisibility]. *)
1014 external visibility : llvalue -> Visibility.t = "llvm_visibility"
1016 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1017 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1018 external set_visibility : Visibility.t -> llvalue -> unit
1019 = "llvm_set_visibility"
1021 (** [alignment g] returns the required alignment of the global value [g].
1022 See the method [llvm::GlobalValue::getAlignment]. *)
1023 external alignment : llvalue -> int = "llvm_alignment"
1025 (** [set_alignment n g] sets the required alignment of the global value [g] to
1026 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1027 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
1030 (** {7 Operations on global variables} *)
1032 (** [declare_global ty name m] returns a new global variable of type [ty] and
1033 with name [name] in module [m] in the default address space (0). If such a
1034 global variable already exists, it is returned. If the type of the existing
1035 global differs, then a bitcast to [ty] is returned. *)
1036 external declare_global : lltype -> string -> llmodule -> llvalue
1037 = "llvm_declare_global"
1039 (** [declare_qualified_global ty name as m] returns a new global variable of
1040 type [ty] and with name [name] in module [m] in the address space [as]. If
1041 such a global variable already exists, it is returned. If the type of the
1042 existing global differs, then a bitcast to [ty] is returned. *)
1043 external declare_qualified_global : lltype -> string -> int -> llmodule ->
1045 = "llvm_declare_qualified_global"
1047 (** [define_global name init m] returns a new global with name [name] and
1048 initializer [init] in module [m] in the default address space (0). If the
1049 named global already exists, it is renamed.
1050 See the constructor of [llvm::GlobalVariable]. *)
1051 external define_global : string -> llvalue -> llmodule -> llvalue
1052 = "llvm_define_global"
1054 (** [define_qualified_global name init as m] returns a new global with name
1055 [name] and initializer [init] in module [m] in the address space [as]. If
1056 the named global already exists, it is renamed.
1057 See the constructor of [llvm::GlobalVariable]. *)
1058 external define_qualified_global : string -> llvalue -> int -> llmodule ->
1060 = "llvm_define_qualified_global"
1062 (** [lookup_global name m] returns [Some g] if a global variable with name
1063 [name] exists in module [m]. If no such global exists, returns [None].
1064 See the [llvm::GlobalVariable] constructor. *)
1065 external lookup_global : string -> llmodule -> llvalue option
1066 = "llvm_lookup_global"
1068 (** [delete_global gv] destroys the global variable [gv].
1069 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1070 external delete_global : llvalue -> unit = "llvm_delete_global"
1072 (** [global_begin m] returns the first position in the global variable list of
1073 the module [m]. [global_begin] and [global_succ] can be used to iterate
1074 over the global list in order.
1075 See the method [llvm::Module::global_begin]. *)
1076 external global_begin : llmodule -> (llmodule, llvalue) llpos
1077 = "llvm_global_begin"
1079 (** [global_succ gv] returns the global variable list position succeeding
1081 See the method [llvm::Module::global_iterator::operator++]. *)
1082 external global_succ : llvalue -> (llmodule, llvalue) llpos
1083 = "llvm_global_succ"
1085 (** [iter_globals f m] applies function [f] to each of the global variables of
1086 module [m] in order. Tail recursive. *)
1087 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1089 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1090 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1091 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1093 (** [global_end m] returns the last position in the global variable list of the
1094 module [m]. [global_end] and [global_pred] can be used to iterate over the
1095 global list in reverse.
1096 See the method [llvm::Module::global_end]. *)
1097 external global_end : llmodule -> (llmodule, llvalue) llrev_pos
1100 (** [global_pred gv] returns the global variable list position preceding
1102 See the method [llvm::Module::global_iterator::operator--]. *)
1103 external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1104 = "llvm_global_pred"
1106 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1107 of module [m] in reverse order. Tail recursive. *)
1108 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1110 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1111 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1112 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1114 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1115 constant. Returns [false] otherwise.
1116 See the method [llvm::GlobalVariable::isConstant]. *)
1117 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
1119 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1120 [c] is [true] and not if [c] is [false].
1121 See the method [llvm::GlobalVariable::setConstant]. *)
1122 external set_global_constant : bool -> llvalue -> unit
1123 = "llvm_set_global_constant"
1125 (** [global_initializer gv] returns the initializer for the global variable
1126 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1127 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
1129 (** [set_initializer c gv] sets the initializer for the global variable
1130 [gv] to the constant [c].
1131 See the method [llvm::GlobalVariable::setInitializer]. *)
1132 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
1134 (** [remove_initializer gv] unsets the initializer for the global variable
1136 See the method [llvm::GlobalVariable::setInitializer]. *)
1137 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
1139 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1140 thread-local and [false] otherwise.
1141 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1142 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
1144 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1145 [c] is [true] and not otherwise.
1146 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1147 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
1150 (** {7 Operations on aliases} *)
1152 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1153 the aliasee [a] with the name [n].
1154 See the constructor for [llvm::GlobalAlias]. *)
1155 external add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1159 (** {7 Operations on functions} *)
1161 (** [declare_function name ty m] returns a new function of type [ty] and
1162 with name [name] in module [m]. If such a function already exists,
1163 it is returned. If the type of the existing function differs, then a bitcast
1164 to [ty] is returned. *)
1165 external declare_function : string -> lltype -> llmodule -> llvalue
1166 = "llvm_declare_function"
1168 (** [define_function name ty m] creates a new function with name [name] and
1169 type [ty] in module [m]. If the named function already exists, it is
1170 renamed. An entry basic block is created in the function.
1171 See the constructor of [llvm::GlobalVariable]. *)
1172 external define_function : string -> lltype -> llmodule -> llvalue
1173 = "llvm_define_function"
1175 (** [lookup_function name m] returns [Some f] if a function with name
1176 [name] exists in module [m]. If no such function exists, returns [None].
1177 See the method [llvm::Module] constructor. *)
1178 external lookup_function : string -> llmodule -> llvalue option
1179 = "llvm_lookup_function"
1181 (** [delete_function f] destroys the function [f].
1182 See the method [llvm::Function::eraseFromParent]. *)
1183 external delete_function : llvalue -> unit = "llvm_delete_function"
1185 (** [function_begin m] returns the first position in the function list of the
1186 module [m]. [function_begin] and [function_succ] can be used to iterate over
1187 the function list in order.
1188 See the method [llvm::Module::begin]. *)
1189 external function_begin : llmodule -> (llmodule, llvalue) llpos
1190 = "llvm_function_begin"
1192 (** [function_succ gv] returns the function list position succeeding
1194 See the method [llvm::Module::iterator::operator++]. *)
1195 external function_succ : llvalue -> (llmodule, llvalue) llpos
1196 = "llvm_function_succ"
1198 (** [iter_functions f m] applies function [f] to each of the functions of module
1199 [m] in order. Tail recursive. *)
1200 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1202 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1203 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1204 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1206 (** [function_end m] returns the last position in the function list of
1207 the module [m]. [function_end] and [function_pred] can be used to iterate
1208 over the function list in reverse.
1209 See the method [llvm::Module::end]. *)
1210 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
1211 = "llvm_function_end"
1213 (** [function_pred gv] returns the function list position preceding [After gv].
1214 See the method [llvm::Module::iterator::operator--]. *)
1215 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1216 = "llvm_function_pred"
1218 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1219 module [m] in reverse order. Tail recursive. *)
1220 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1222 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1223 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1224 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1226 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1227 See the method [llvm::Function::isIntrinsic]. *)
1228 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
1230 (** [function_call_conv f] returns the calling convention of the function [f].
1231 See the method [llvm::Function::getCallingConv]. *)
1232 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
1234 (** [set_function_call_conv cc f] sets the calling convention of the function
1235 [f] to the calling convention numbered [cc].
1236 See the method [llvm::Function::setCallingConv]. *)
1237 external set_function_call_conv : int -> llvalue -> unit
1238 = "llvm_set_function_call_conv"
1240 (** [gc f] returns [Some name] if the function [f] has a garbage
1241 collection algorithm specified and [None] otherwise.
1242 See the method [llvm::Function::getGC]. *)
1243 external gc : llvalue -> string option = "llvm_gc"
1245 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1246 [gc]. See the method [llvm::Function::setGC]. *)
1247 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
1249 (** [add_function_attr f a] adds attribute [a] to the return type of function
1251 external add_function_attr : llvalue -> Attribute.t -> unit
1252 = "llvm_add_function_attr"
1254 (** [remove_function_attr f a] removes attribute [a] from the return type of
1256 external remove_function_attr : llvalue -> Attribute.t -> unit
1257 = "llvm_remove_function_attr"
1259 (** {7 Operations on params} *)
1261 (** [params f] returns the parameters of function [f].
1262 See the method [llvm::Function::getArgumentList]. *)
1263 external params : llvalue -> llvalue array = "llvm_params"
1265 (** [param f n] returns the [n]th parameter of function [f].
1266 See the method [llvm::Function::getArgumentList]. *)
1267 external param : llvalue -> int -> llvalue = "llvm_param"
1269 (** [param_parent p] returns the parent function that owns the parameter.
1270 See the method [llvm::Argument::getParent]. *)
1271 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
1273 (** [param_begin f] returns the first position in the parameter list of the
1274 function [f]. [param_begin] and [param_succ] can be used to iterate over
1275 the parameter list in order.
1276 See the method [llvm::Function::arg_begin]. *)
1277 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
1279 (** [param_succ bb] returns the parameter list position succeeding
1281 See the method [llvm::Function::arg_iterator::operator++]. *)
1282 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
1284 (** [iter_params f fn] applies function [f] to each of the parameters
1285 of function [fn] in order. Tail recursive. *)
1286 val iter_params : (llvalue -> unit) -> llvalue -> unit
1288 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1289 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1290 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1292 (** [param_end f] returns the last position in the parameter list of
1293 the function [f]. [param_end] and [param_pred] can be used to iterate
1294 over the parameter list in reverse.
1295 See the method [llvm::Function::arg_end]. *)
1296 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
1298 (** [param_pred gv] returns the function list position preceding [After gv].
1299 See the method [llvm::Function::arg_iterator::operator--]. *)
1300 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1303 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1304 of function [fn] in reverse order. Tail recursive. *)
1305 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1307 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1308 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1309 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1311 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1312 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1314 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1315 external remove_param_attr : llvalue -> Attribute.t -> unit
1316 = "llvm_remove_param_attr"
1318 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1319 external set_param_alignment : llvalue -> int -> unit
1320 = "llvm_set_param_alignment"
1322 (** {7 Operations on basic blocks} *)
1324 (** [basic_blocks fn] returns the basic blocks of the function [f].
1325 See the method [llvm::Function::getBasicBlockList]. *)
1326 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
1328 (** [entry_block fn] returns the entry basic block of the function [f].
1329 See the method [llvm::Function::getEntryBlock]. *)
1330 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1332 (** [delete_block bb] deletes the basic block [bb].
1333 See the method [llvm::BasicBlock::eraseFromParent]. *)
1334 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1336 (** [append_block c name f] creates a new basic block named [name] at the end of
1337 function [f] in the context [c].
1338 See the constructor of [llvm::BasicBlock]. *)
1339 external append_block : llcontext -> string -> llvalue -> llbasicblock
1340 = "llvm_append_block"
1342 (** [insert_block c name bb] creates a new basic block named [name] before the
1343 basic block [bb] in the context [c].
1344 See the constructor of [llvm::BasicBlock]. *)
1345 external insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1346 = "llvm_insert_block"
1348 (** [block_parent bb] returns the parent function that owns the basic block.
1349 See the method [llvm::BasicBlock::getParent]. *)
1350 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1352 (** [block_begin f] returns the first position in the basic block list of the
1353 function [f]. [block_begin] and [block_succ] can be used to iterate over
1354 the basic block list in order.
1355 See the method [llvm::Function::begin]. *)
1356 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1357 = "llvm_block_begin"
1359 (** [block_succ bb] returns the basic block list position succeeding
1361 See the method [llvm::Function::iterator::operator++]. *)
1362 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1365 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1366 of function [fn] in order. Tail recursive. *)
1367 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1369 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1370 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1371 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1373 (** [block_end f] returns the last position in the basic block list of
1374 the function [f]. [block_end] and [block_pred] can be used to iterate
1375 over the basic block list in reverse.
1376 See the method [llvm::Function::end]. *)
1377 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1380 (** [block_pred gv] returns the function list position preceding [After gv].
1381 See the method [llvm::Function::iterator::operator--]. *)
1382 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1385 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1386 of function [fn] in reverse order. Tail recursive. *)
1387 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1389 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1390 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1391 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1393 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1394 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1396 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1398 Similar to [llvm::isa<BasicBlock>]. *)
1399 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1401 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1402 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1405 (** {7 Operations on instructions} *)
1407 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1408 See the method [llvm::Instruction::getParent]. *)
1409 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1411 (** [instr_begin bb] returns the first position in the instruction list of the
1412 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1413 the instruction list in order.
1414 See the method [llvm::BasicBlock::begin]. *)
1415 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1416 = "llvm_instr_begin"
1418 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1419 See the method [llvm::BasicBlock::iterator::operator++]. *)
1420 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1423 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1424 block [bb] in order. Tail recursive. *)
1425 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1427 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1428 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1429 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1431 (** [instr_end bb] returns the last position in the instruction list of the
1432 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1433 the instruction list in reverse.
1434 See the method [llvm::BasicBlock::end]. *)
1435 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1438 (** [instr_pred i] returns the instruction list position preceding [After i].
1439 See the method [llvm::BasicBlock::iterator::operator--]. *)
1440 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1443 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1444 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1445 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1448 (** {7 Operations on call sites} *)
1450 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1451 instruction [ci], which may be one of the values from the module
1452 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1453 [llvm::InvokeInst::getCallingConv]. *)
1454 external instruction_call_conv: llvalue -> int
1455 = "llvm_instruction_call_conv"
1457 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1458 or invoke instruction [ci] to the integer [cc], which can be one of the
1459 values from the module {!CallConv}.
1460 See the method [llvm::CallInst::setCallingConv]
1461 and [llvm::InvokeInst::setCallingConv]. *)
1462 external set_instruction_call_conv: int -> llvalue -> unit
1463 = "llvm_set_instruction_call_conv"
1465 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1466 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1468 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1469 = "llvm_add_instruction_param_attr"
1471 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1472 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1474 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1475 = "llvm_remove_instruction_param_attr"
1477 (** {Operations on call instructions (only)} *)
1479 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1480 eligible for tail call optimization, [false] otherwise.
1481 See the method [llvm::CallInst::isTailCall]. *)
1482 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
1484 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1485 call optimization if [tc] is [true], clears otherwise.
1486 See the method [llvm::CallInst::setTailCall]. *)
1487 external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call"
1489 (** {7 Operations on phi nodes} *)
1491 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1492 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1493 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1494 = "llvm_add_incoming"
1496 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1497 See the method [llvm::PHINode::getIncomingValue]. *)
1498 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1502 (** {6 Instruction builders} *)
1504 (** [builder context] creates an instruction builder with no position in
1505 the context [context]. It is invalid to use this builder until its position
1506 is set with {!position_before} or {!position_at_end}. See the constructor
1507 for [llvm::LLVMBuilder]. *)
1508 external builder : llcontext -> llbuilder = "llvm_builder"
1510 (** [builder_at ip] creates an instruction builder positioned at [ip].
1511 See the constructor for [llvm::LLVMBuilder]. *)
1512 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1514 (** [builder_before ins] creates an instruction builder positioned before the
1515 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1516 val builder_before : llcontext -> llvalue -> llbuilder
1518 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1519 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1520 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1522 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1524 See the constructor for [llvm::LLVMBuilder]. *)
1525 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1526 = "llvm_position_builder"
1528 (** [position_before ins b] moves the instruction builder [b] to before the
1529 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1530 val position_before : llvalue -> llbuilder -> unit
1532 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1533 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1534 val position_at_end : llbasicblock -> llbuilder -> unit
1536 (** [insertion_block b] returns the basic block that the builder [b] is
1537 positioned to insert into. Raises [Not_Found] if the instruction builder is
1539 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1540 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1542 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1543 position specified by the instruction builder [b].
1544 See the method [llvm::LLVMBuilder::Insert]. *)
1545 external insert_into_builder : llvalue -> string -> llbuilder -> unit
1546 = "llvm_insert_into_builder"
1550 (** [set_current_debug_location b md] sets the current debug location [md] in
1552 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1553 external set_current_debug_location : llbuilder -> llvalue -> unit
1554 = "llvm_set_current_debug_location"
1556 (** [clear_current_debug_location b] clears the current debug location in the
1558 external clear_current_debug_location : llbuilder -> unit
1559 = "llvm_clear_current_debug_location"
1561 (** [current_debug_location b] returns the current debug location, or None
1562 if none is currently set.
1563 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1564 external current_debug_location : llbuilder -> llvalue option
1565 = "llvm_current_debug_location"
1567 (** [set_inst_debug_location b i] sets the current debug location of the builder
1568 [b] to the instruction [i].
1569 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1570 external set_inst_debug_location : llbuilder -> llvalue -> unit
1571 = "llvm_set_inst_debug_location"
1573 (** {7 Terminators} *)
1575 (** [build_ret_void b] creates a
1577 instruction at the position specified by the instruction builder [b].
1578 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1579 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1581 (** [build_ret v b] creates a
1583 instruction at the position specified by the instruction builder [b].
1584 See the method [llvm::LLVMBuilder::CreateRet]. *)
1585 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1587 (** [build_aggregate_ret vs b] creates a
1588 [ret {...} { %v1, %v2, ... } ]
1589 instruction at the position specified by the instruction builder [b].
1590 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1591 external build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1592 = "llvm_build_aggregate_ret"
1594 (** [build_br bb b] creates a
1596 instruction at the position specified by the instruction builder [b].
1597 See the method [llvm::LLVMBuilder::CreateBr]. *)
1598 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1600 (** [build_cond_br cond tbb fbb b] creates a
1601 [br %cond, %tbb, %fbb]
1602 instruction at the position specified by the instruction builder [b].
1603 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1604 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1605 llvalue = "llvm_build_cond_br"
1607 (** [build_switch case elsebb count b] creates an empty
1608 [switch %case, %elsebb]
1609 instruction at the position specified by the instruction builder [b] with
1610 space reserved for [count] cases.
1611 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1612 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1613 = "llvm_build_switch"
1615 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1616 when its input matches the constant [onval].
1617 See the method [llvm::SwitchInst::addCase]. **)
1618 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1621 (** [build_indirect_br addr count b] creates a
1623 instruction at the position specified by the instruction builder [b] with
1624 space reserved for [count] destinations.
1625 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1626 external build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1627 = "llvm_build_indirect_br"
1629 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1630 location for the indirectbr instruction [br].
1631 See the method [llvm::IndirectBrInst::addDestination]. **)
1632 external add_destination : llvalue -> llbasicblock -> unit
1633 = "llvm_add_destination"
1635 (** [build_invoke fn args tobb unwindbb name b] creates an
1636 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1637 instruction at the position specified by the instruction builder [b].
1638 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1639 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1640 llbasicblock -> string -> llbuilder -> llvalue
1641 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1643 (** [build_unwind b] creates an
1645 instruction at the position specified by the instruction builder [b].
1646 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1647 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1649 (** [build_unreachable b] creates an
1651 instruction at the position specified by the instruction builder [b].
1652 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1653 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1656 (** {7 Arithmetic} *)
1658 (** [build_add x y name b] creates a
1659 [%name = add %x, %y]
1660 instruction at the position specified by the instruction builder [b].
1661 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1662 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1665 (** [build_nsw_add x y name b] creates a
1666 [%name = nsw add %x, %y]
1667 instruction at the position specified by the instruction builder [b].
1668 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1669 external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1670 = "llvm_build_nsw_add"
1672 (** [build_nuw_add x y name b] creates a
1673 [%name = nuw add %x, %y]
1674 instruction at the position specified by the instruction builder [b].
1675 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1676 external build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1677 = "llvm_build_nuw_add"
1679 (** [build_fadd x y name b] creates a
1680 [%name = fadd %x, %y]
1681 instruction at the position specified by the instruction builder [b].
1682 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1683 external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1686 (** [build_sub x y name b] creates a
1687 [%name = sub %x, %y]
1688 instruction at the position specified by the instruction builder [b].
1689 See the method [llvm::LLVMBuilder::CreateSub]. *)
1690 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1693 (** [build_nsw_sub x y name b] creates a
1694 [%name = nsw sub %x, %y]
1695 instruction at the position specified by the instruction builder [b].
1696 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1697 external build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1698 = "llvm_build_nsw_sub"
1700 (** [build_nuw_sub x y name b] creates a
1701 [%name = nuw sub %x, %y]
1702 instruction at the position specified by the instruction builder [b].
1703 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1704 external build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1705 = "llvm_build_nuw_sub"
1707 (** [build_fsub x y name b] creates a
1708 [%name = fsub %x, %y]
1709 instruction at the position specified by the instruction builder [b].
1710 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1711 external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1714 (** [build_mul x y name b] creates a
1715 [%name = mul %x, %y]
1716 instruction at the position specified by the instruction builder [b].
1717 See the method [llvm::LLVMBuilder::CreateMul]. *)
1718 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1721 (** [build_nsw_mul x y name b] creates a
1722 [%name = nsw mul %x, %y]
1723 instruction at the position specified by the instruction builder [b].
1724 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1725 external build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1726 = "llvm_build_nsw_mul"
1728 (** [build_nuw_mul x y name b] creates a
1729 [%name = nuw mul %x, %y]
1730 instruction at the position specified by the instruction builder [b].
1731 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1732 external build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1733 = "llvm_build_nuw_mul"
1735 (** [build_fmul x y name b] creates a
1736 [%name = fmul %x, %y]
1737 instruction at the position specified by the instruction builder [b].
1738 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1739 external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1742 (** [build_udiv x y name b] creates a
1743 [%name = udiv %x, %y]
1744 instruction at the position specified by the instruction builder [b].
1745 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1746 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1749 (** [build_sdiv x y name b] creates a
1750 [%name = sdiv %x, %y]
1751 instruction at the position specified by the instruction builder [b].
1752 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1753 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1756 (** [build_exact_sdiv x y name b] creates a
1757 [%name = exact sdiv %x, %y]
1758 instruction at the position specified by the instruction builder [b].
1759 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1760 external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1761 = "llvm_build_exact_sdiv"
1763 (** [build_fdiv x y name b] creates a
1764 [%name = fdiv %x, %y]
1765 instruction at the position specified by the instruction builder [b].
1766 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1767 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1770 (** [build_urem x y name b] creates a
1771 [%name = urem %x, %y]
1772 instruction at the position specified by the instruction builder [b].
1773 See the method [llvm::LLVMBuilder::CreateURem]. *)
1774 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1777 (** [build_SRem x y name b] creates a
1778 [%name = srem %x, %y]
1779 instruction at the position specified by the instruction builder [b].
1780 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1781 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1784 (** [build_frem x y name b] creates a
1785 [%name = frem %x, %y]
1786 instruction at the position specified by the instruction builder [b].
1787 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1788 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1791 (** [build_shl x y name b] creates a
1792 [%name = shl %x, %y]
1793 instruction at the position specified by the instruction builder [b].
1794 See the method [llvm::LLVMBuilder::CreateShl]. *)
1795 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1798 (** [build_lshr x y name b] creates a
1799 [%name = lshr %x, %y]
1800 instruction at the position specified by the instruction builder [b].
1801 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1802 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1805 (** [build_ashr x y name b] creates a
1806 [%name = ashr %x, %y]
1807 instruction at the position specified by the instruction builder [b].
1808 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1809 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1812 (** [build_and x y name b] creates a
1813 [%name = and %x, %y]
1814 instruction at the position specified by the instruction builder [b].
1815 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1816 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1819 (** [build_or x y name b] creates a
1821 instruction at the position specified by the instruction builder [b].
1822 See the method [llvm::LLVMBuilder::CreateOr]. *)
1823 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1826 (** [build_xor x y name b] creates a
1827 [%name = xor %x, %y]
1828 instruction at the position specified by the instruction builder [b].
1829 See the method [llvm::LLVMBuilder::CreateXor]. *)
1830 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1833 (** [build_neg x name b] creates a
1835 instruction at the position specified by the instruction builder [b].
1836 [-0.0] is used for floating point types to compute the correct sign.
1837 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1838 external build_neg : llvalue -> string -> llbuilder -> llvalue
1841 (** [build_nsw_neg x name b] creates a
1842 [%name = nsw sub 0, %x]
1843 instruction at the position specified by the instruction builder [b].
1844 [-0.0] is used for floating point types to compute the correct sign.
1845 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1846 external build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1847 = "llvm_build_nsw_neg"
1849 (** [build_nuw_neg x name b] creates a
1850 [%name = nuw sub 0, %x]
1851 instruction at the position specified by the instruction builder [b].
1852 [-0.0] is used for floating point types to compute the correct sign.
1853 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1854 external build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1855 = "llvm_build_nuw_neg"
1857 (** [build_fneg x name b] creates a
1858 [%name = fsub 0, %x]
1859 instruction at the position specified by the instruction builder [b].
1860 [-0.0] is used for floating point types to compute the correct sign.
1861 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1862 external build_fneg : llvalue -> string -> llbuilder -> llvalue
1865 (** [build_xor x name b] creates a
1866 [%name = xor %x, -1]
1867 instruction at the position specified by the instruction builder [b].
1868 [-1] is the correct "all ones" value for the type of [x].
1869 See the method [llvm::LLVMBuilder::CreateXor]. *)
1870 external build_not : llvalue -> string -> llbuilder -> llvalue
1876 (** [build_alloca ty name b] creates a
1877 [%name = alloca %ty]
1878 instruction at the position specified by the instruction builder [b].
1879 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1880 external build_alloca : lltype -> string -> llbuilder -> llvalue
1881 = "llvm_build_alloca"
1883 (** [build_array_alloca ty n name b] creates a
1884 [%name = alloca %ty, %n]
1885 instruction at the position specified by the instruction builder [b].
1886 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1887 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1888 llvalue = "llvm_build_array_alloca"
1890 (** [build_load v name b] creates a
1892 instruction at the position specified by the instruction builder [b].
1893 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1894 external build_load : llvalue -> string -> llbuilder -> llvalue
1897 (** [build_store v p b] creates a
1899 instruction at the position specified by the instruction builder [b].
1900 See the method [llvm::LLVMBuilder::CreateStore]. *)
1901 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1902 = "llvm_build_store"
1904 (** [build_gep p indices name b] creates a
1905 [%name = getelementptr %p, indices...]
1906 instruction at the position specified by the instruction builder [b].
1907 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1908 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1911 (** [build_in_bounds_gep p indices name b] creates a
1912 [%name = gelementptr inbounds %p, indices...]
1913 instruction at the position specified by the instruction builder [b].
1914 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1915 external build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1916 llvalue = "llvm_build_in_bounds_gep"
1918 (** [build_struct_gep p idx name b] creates a
1919 [%name = getelementptr %p, 0, idx]
1920 instruction at the position specified by the instruction builder [b].
1921 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1922 external build_struct_gep : llvalue -> int -> string -> llbuilder ->
1923 llvalue = "llvm_build_struct_gep"
1925 (** [build_global_string str name b] creates a series of instructions that adds
1926 a global string at the position specified by the instruction builder [b].
1927 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1928 external build_global_string : string -> string -> llbuilder -> llvalue
1929 = "llvm_build_global_string"
1931 (** [build_global_stringptr str name b] creates a series of instructions that
1932 adds a global string pointer at the position specified by the instruction
1934 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1935 external build_global_stringptr : string -> string -> llbuilder -> llvalue
1936 = "llvm_build_global_stringptr"
1941 (** [build_trunc v ty name b] creates a
1942 [%name = trunc %p to %ty]
1943 instruction at the position specified by the instruction builder [b].
1944 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1945 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1946 = "llvm_build_trunc"
1948 (** [build_zext v ty name b] creates a
1949 [%name = zext %p to %ty]
1950 instruction at the position specified by the instruction builder [b].
1951 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1952 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1955 (** [build_sext v ty name b] creates a
1956 [%name = sext %p to %ty]
1957 instruction at the position specified by the instruction builder [b].
1958 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1959 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1962 (** [build_fptoui v ty name b] creates a
1963 [%name = fptoui %p to %ty]
1964 instruction at the position specified by the instruction builder [b].
1965 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1966 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1967 = "llvm_build_fptoui"
1969 (** [build_fptosi v ty name b] creates a
1970 [%name = fptosi %p to %ty]
1971 instruction at the position specified by the instruction builder [b].
1972 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1973 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1974 = "llvm_build_fptosi"
1976 (** [build_uitofp v ty name b] creates a
1977 [%name = uitofp %p to %ty]
1978 instruction at the position specified by the instruction builder [b].
1979 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1980 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1981 = "llvm_build_uitofp"
1983 (** [build_sitofp v ty name b] creates a
1984 [%name = sitofp %p to %ty]
1985 instruction at the position specified by the instruction builder [b].
1986 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1987 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1988 = "llvm_build_sitofp"
1990 (** [build_fptrunc v ty name b] creates a
1991 [%name = fptrunc %p to %ty]
1992 instruction at the position specified by the instruction builder [b].
1993 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1994 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1995 = "llvm_build_fptrunc"
1997 (** [build_fpext v ty name b] creates a
1998 [%name = fpext %p to %ty]
1999 instruction at the position specified by the instruction builder [b].
2000 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
2001 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
2002 = "llvm_build_fpext"
2004 (** [build_ptrtoint v ty name b] creates a
2005 [%name = prtotint %p to %ty]
2006 instruction at the position specified by the instruction builder [b].
2007 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2008 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2009 = "llvm_build_prttoint"
2011 (** [build_inttoptr v ty name b] creates a
2012 [%name = inttoptr %p to %ty]
2013 instruction at the position specified by the instruction builder [b].
2014 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2015 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2016 = "llvm_build_inttoptr"
2018 (** [build_bitcast v ty name b] creates a
2019 [%name = bitcast %p to %ty]
2020 instruction at the position specified by the instruction builder [b].
2021 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2022 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2023 = "llvm_build_bitcast"
2025 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2026 instruction at the position specified by the instruction builder [b].
2027 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2028 external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2029 llvalue = "llvm_build_zext_or_bitcast"
2031 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2032 instruction at the position specified by the instruction builder [b].
2033 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2034 external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2035 llvalue = "llvm_build_sext_or_bitcast"
2037 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2038 instruction at the position specified by the instruction builder [b].
2039 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2040 external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2041 llvalue = "llvm_build_trunc_or_bitcast"
2043 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2044 instruction at the position specified by the instruction builder [b].
2045 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2046 external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2047 = "llvm_build_pointercast"
2049 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2050 instruction at the position specified by the instruction builder [b].
2051 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2052 external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2053 = "llvm_build_intcast"
2055 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2056 instruction at the position specified by the instruction builder [b].
2057 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2058 external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2059 = "llvm_build_fpcast"
2062 (** {7 Comparisons} *)
2064 (** [build_icmp pred x y name b] creates a
2065 [%name = icmp %pred %x, %y]
2066 instruction at the position specified by the instruction builder [b].
2067 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2068 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2069 llbuilder -> llvalue = "llvm_build_icmp"
2071 (** [build_fcmp pred x y name b] creates a
2072 [%name = fcmp %pred %x, %y]
2073 instruction at the position specified by the instruction builder [b].
2074 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2075 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2076 llbuilder -> llvalue = "llvm_build_fcmp"
2079 (** {7 Miscellaneous instructions} *)
2081 (** [build_phi incoming name b] creates a
2082 [%name = phi %incoming]
2083 instruction at the position specified by the instruction builder [b].
2084 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2085 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2086 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2087 llvalue = "llvm_build_phi"
2089 (** [build_call fn args name b] creates a
2090 [%name = call %fn(args...)]
2091 instruction at the position specified by the instruction builder [b].
2092 See the method [llvm::LLVMBuilder::CreateCall]. *)
2093 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2096 (** [build_select cond thenv elsev name b] creates a
2097 [%name = select %cond, %thenv, %elsev]
2098 instruction at the position specified by the instruction builder [b].
2099 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2100 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2101 llvalue = "llvm_build_select"
2103 (** [build_va_arg valist argty name b] creates a
2104 [%name = va_arg %valist, %argty]
2105 instruction at the position specified by the instruction builder [b].
2106 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2107 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2108 = "llvm_build_va_arg"
2110 (** [build_extractelement vec i name b] creates a
2111 [%name = extractelement %vec, %i]
2112 instruction at the position specified by the instruction builder [b].
2113 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2114 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2115 llvalue = "llvm_build_extractelement"
2117 (** [build_insertelement vec elt i name b] creates a
2118 [%name = insertelement %vec, %elt, %i]
2119 instruction at the position specified by the instruction builder [b].
2120 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2121 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2122 llbuilder -> llvalue = "llvm_build_insertelement"
2124 (** [build_shufflevector veca vecb mask name b] creates a
2125 [%name = shufflevector %veca, %vecb, %mask]
2126 instruction at the position specified by the instruction builder [b].
2127 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2128 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2129 llbuilder -> llvalue = "llvm_build_shufflevector"
2131 (** [build_insertvalue agg idx name b] creates a
2132 [%name = extractvalue %agg, %idx]
2133 instruction at the position specified by the instruction builder [b].
2134 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2135 external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2136 = "llvm_build_extractvalue"
2138 (** [build_insertvalue agg val idx name b] creates a
2139 [%name = insertvalue %agg, %val, %idx]
2140 instruction at the position specified by the instruction builder [b].
2141 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2142 external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2143 llvalue = "llvm_build_insertvalue"
2145 (** [build_is_null val name b] creates a
2146 [%name = icmp eq %val, null]
2147 instruction at the position specified by the instruction builder [b].
2148 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2149 external build_is_null : llvalue -> string -> llbuilder -> llvalue
2150 = "llvm_build_is_null"
2152 (** [build_is_not_null val name b] creates a
2153 [%name = icmp ne %val, null]
2154 instruction at the position specified by the instruction builder [b].
2155 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2156 external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2157 = "llvm_build_is_not_null"
2159 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2160 the difference between two pointer values at the position specified by the
2161 instruction builder [b].
2162 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2163 external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2164 = "llvm_build_ptrdiff"
2166 (** {6 Module providers} *)
2168 module ModuleProvider : sig
2169 (** [create_module_provider m] encapsulates [m] in a module provider and takes
2170 ownership of the module. See the constructor
2171 [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
2172 external create : llmodule -> llmoduleprovider
2173 = "LLVMCreateModuleProviderForExistingModule"
2175 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
2176 the contained module. *)
2177 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
2181 (** {6 Memory buffers} *)
2183 module MemoryBuffer : sig
2184 (** [of_file p] is the memory buffer containing the contents of the file at
2185 path [p]. If the file could not be read, then [IoError msg] is
2187 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
2189 (** [stdin ()] is the memory buffer containing the contents of standard input.
2190 If standard input is empty, then [IoError msg] is raised. *)
2191 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
2193 (** Disposes of a memory buffer. *)
2194 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
2198 (** {6 Pass Managers} *)
2200 module PassManager : sig
2203 type any = [ `Module | `Function ]
2205 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2206 type of pipeline is suitable for link-time optimization and whole-module
2208 See the constructor of [llvm::PassManager]. *)
2209 external create : unit -> [ `Module ] t = "llvm_passmanager_create"
2211 (** [PassManager.create_function mp] constructs a new function-by-function
2212 pass pipeline over the module provider [mp]. It does not take ownership of
2213 [mp]. This type of pipeline is suitable for code generation and JIT
2215 See the constructor of [llvm::FunctionPassManager]. *)
2216 external create_function : llmoduleprovider -> [ `Function ] t
2217 = "LLVMCreateFunctionPassManager"
2219 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2220 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2221 any of the passes modified the module, [false] otherwise.
2222 See the [llvm::PassManager::run] method. *)
2223 external run_module : llmodule -> [ `Module ] t -> bool
2224 = "llvm_passmanager_run_module"
2226 (** [initialize fpm] initializes all of the function passes scheduled in the
2227 function pass manager [fpm]. Returns [true] if any of the passes modified
2228 the module, [false] otherwise.
2229 See the [llvm::FunctionPassManager::doInitialization] method. *)
2230 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
2232 (** [run_function f fpm] executes all of the function passes scheduled in the
2233 function pass manager [fpm] over the function [f]. Returns [true] if any
2234 of the passes modified [f], [false] otherwise.
2235 See the [llvm::FunctionPassManager::run] method. *)
2236 external run_function : llvalue -> [ `Function ] t -> bool
2237 = "llvm_passmanager_run_function"
2239 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2240 function pass manager [fpm]. Returns [true] if any of the passes
2241 modified the module, [false] otherwise.
2242 See the [llvm::FunctionPassManager::doFinalization] method. *)
2243 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
2245 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2246 the module provider.
2247 See the destructor of [llvm::BasePassManager]. *)
2248 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"