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 (** [dump_module m] prints the .ll representation of the module [m] to standard
278 error. See the method [llvm::Module::dump]. *)
279 external dump_module : llmodule -> unit = "llvm_dump_module"
284 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
285 See the method [llvm::Type::getTypeID]. *)
286 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
288 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
289 See the method [llvm::Type::getContext]. *)
290 external type_context : lltype -> llcontext = "llvm_type_context"
292 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
293 val string_of_lltype : lltype -> string
295 (** {7 Operations on integer types} *)
297 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
298 [llvm::Type::Int1Ty]. *)
299 external i1_type : llcontext -> lltype = "llvm_i1_type"
301 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
302 [llvm::Type::Int8Ty]. *)
303 external i8_type : llcontext -> lltype = "llvm_i8_type"
305 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
306 [llvm::Type::Int16Ty]. *)
307 external i16_type : llcontext -> lltype = "llvm_i16_type"
309 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
310 [llvm::Type::Int32Ty]. *)
311 external i32_type : llcontext -> lltype = "llvm_i32_type"
313 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
314 [llvm::Type::Int64Ty]. *)
315 external i64_type : llcontext -> lltype = "llvm_i64_type"
317 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
318 [c]. See the method [llvm::IntegerType::get]. *)
319 external integer_type : llcontext -> int -> lltype = "llvm_integer_type"
321 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
322 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
323 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
326 (** {7 Operations on real types} *)
328 (** [float_type c] returns the IEEE 32-bit floating point type in the context
329 [c]. See [llvm::Type::FloatTy]. *)
330 external float_type : llcontext -> lltype = "llvm_float_type"
332 (** [double_type c] returns the IEEE 64-bit floating point type in the context
333 [c]. See [llvm::Type::DoubleTy]. *)
334 external double_type : llcontext -> lltype = "llvm_double_type"
336 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
337 [c]. See [llvm::Type::X86_FP80Ty]. *)
338 external x86fp80_type : llcontext -> lltype = "llvm_x86fp80_type"
340 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
341 [c]. See [llvm::Type::FP128Ty]. *)
342 external fp128_type : llcontext -> lltype = "llvm_fp128_type"
344 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
345 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
346 external ppc_fp128_type : llcontext -> lltype = "llvm_ppc_fp128_type"
349 (** {7 Operations on function types} *)
351 (** [function_type ret_ty param_tys] returns the function type returning
352 [ret_ty] and taking [param_tys] as parameters.
353 See the method [llvm::FunctionType::get]. *)
354 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
356 (** [va_arg_function_type ret_ty param_tys] is just like
357 [function_type ret_ty param_tys] except that it returns the function type
358 which also takes a variable number of arguments.
359 See the method [llvm::FunctionType::get]. *)
360 external var_arg_function_type : lltype -> lltype array -> lltype
361 = "llvm_var_arg_function_type"
363 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
364 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
365 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
367 (** [return_type fty] gets the return type of the function type [fty].
368 See the method [llvm::FunctionType::getReturnType]. *)
369 external return_type : lltype -> lltype = "LLVMGetReturnType"
371 (** [param_types fty] gets the parameter types of the function type [fty].
372 See the method [llvm::FunctionType::getParamType]. *)
373 external param_types : lltype -> lltype array = "llvm_param_types"
376 (** {7 Operations on struct types} *)
378 (** [struct_type context tys] returns the structure type in the context
379 [context] containing in the types in the array [tys]. See the method
380 [llvm::StructType::get]. *)
381 external struct_type : llcontext -> lltype array -> lltype
384 (** [packed_struct_type context ys] returns the packed structure type in the
385 context [context] containing in the types in the array [tys]. See the method
386 [llvm::StructType::get]. *)
387 external packed_struct_type : llcontext -> lltype array -> lltype
388 = "llvm_packed_struct_type"
390 (** [struct_element_types sty] returns the constituent types of the struct type
391 [sty]. See the method [llvm::StructType::getElementType]. *)
392 external struct_element_types : lltype -> lltype array
393 = "llvm_struct_element_types"
395 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
396 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
397 external is_packed : lltype -> bool = "llvm_is_packed"
400 (** {7 Operations on union types} *)
402 (** [union_type context tys] returns the union type in the context [context]
403 containing the types in the array [tys]. See the method
404 [llvm::UnionType::get] *)
405 external union_type : llcontext -> lltype array -> lltype = "llvm_union_type"
407 (** [union_element_types uty] returns the constituent types of the union type
408 [uty]. See the method [llvm::UnionType::getElementType]. *)
409 external union_element_types : lltype -> lltype array
410 = "llvm_union_element_types"
413 (** {7 Operations on pointer, vector, and array types} *)
415 (** [array_type ty n] returns the array type containing [n] elements of type
416 [ty]. See the method [llvm::ArrayType::get]. *)
417 external array_type : lltype -> int -> lltype = "llvm_array_type"
419 (** [pointer_type ty] returns the pointer type referencing objects of type
420 [ty] in the default address space (0).
421 See the method [llvm::PointerType::getUnqual]. *)
422 external pointer_type : lltype -> lltype = "llvm_pointer_type"
424 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
425 of type [ty] in address space [as].
426 See the method [llvm::PointerType::get]. *)
427 external qualified_pointer_type : lltype -> int -> lltype
428 = "llvm_qualified_pointer_type"
430 (** [vector_type ty n] returns the array type containing [n] elements of the
431 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
432 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
434 (** [element_type ty] returns the element type of the pointer, vector, or array
435 type [ty]. See the method [llvm::SequentialType::get]. *)
436 external element_type : lltype -> lltype = "LLVMGetElementType"
438 (** [element_type aty] returns the element count of the array type [aty].
439 See the method [llvm::ArrayType::getNumElements]. *)
440 external array_length : lltype -> int = "llvm_array_length"
442 (** [address_space pty] returns the address space qualifier of the pointer type
443 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
444 external address_space : lltype -> int = "llvm_address_space"
446 (** [element_type ty] returns the element count of the vector type [ty].
447 See the method [llvm::VectorType::getNumElements]. *)
448 external vector_size : lltype -> int = "llvm_vector_size"
451 (** {7 Operations on other types} *)
453 (** [opaque_type c] creates a new opaque type distinct from any other in the
454 context [c]. Opaque types are useful for building recursive types in
455 combination with {!refine_type}. See [llvm::OpaqueType::get]. *)
456 external opaque_type : llcontext -> lltype = "llvm_opaque_type"
458 (** [void_type c] creates a type of a function which does not return any
459 value in the context [c]. See [llvm::Type::VoidTy]. *)
460 external void_type : llcontext -> lltype = "llvm_void_type"
462 (** [label_type c] creates a type of a basic block in the context [c]. See
463 [llvm::Type::LabelTy]. *)
464 external label_type : llcontext -> lltype = "llvm_label_type"
466 (** {7 Operations on type handles} *)
468 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
469 refined as a result of a call to {!refine_type}, the handle will be updated;
470 any bare [lltype] references will become invalid.
471 See the class [llvm::PATypeHolder]. *)
472 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
474 (** [type_of_handle tyh] resolves the type handle [tyh].
475 See the method [llvm::PATypeHolder::get()]. *)
476 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
478 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
479 concrete type [ty] in all users. Warning: This may invalidate {!lltype}
480 values! Use {!lltypehandle} to manipulate potentially abstract types. See
481 the method [llvm::Type::refineAbstractType]. *)
482 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
487 (** [type_of v] returns the type of the value [v].
488 See the method [llvm::Value::getType]. *)
489 external type_of : llvalue -> lltype = "llvm_type_of"
491 (** [value_name v] returns the name of the value [v]. For global values, this is
492 the symbol name. For instructions and basic blocks, it is the SSA register
493 name. It is meaningless for constants.
494 See the method [llvm::Value::getName]. *)
495 external value_name : llvalue -> string = "llvm_value_name"
497 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
498 [llvm::Value::setName]. *)
499 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
501 (** [dump_value v] prints the .ll representation of the value [v] to standard
502 error. See the method [llvm::Value::dump]. *)
503 external dump_value : llvalue -> unit = "llvm_dump_value"
505 (** [replace_all_uses_with old new] replaces all uses of the value [old]
506 * with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
507 external replace_all_uses_with : llvalue -> llvalue -> unit
508 = "LLVMReplaceAllUsesWith"
511 (** {7 Operations on constants of (mostly) any type} *)
513 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
514 otherwise. Similar to [llvm::isa<Constant>]. *)
515 external is_constant : llvalue -> bool = "llvm_is_constant"
517 (** [const_null ty] returns the constant null (zero) of the type [ty].
518 See the method [llvm::Constant::getNullValue]. *)
519 external const_null : lltype -> llvalue = "LLVMConstNull"
521 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
522 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
523 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
525 (** [undef ty] returns the undefined value of the type [ty].
526 See the method [llvm::UndefValue::get]. *)
527 external undef : lltype -> llvalue = "LLVMGetUndef"
529 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
530 See the method [llvm::Constant::isNullValue]. *)
531 external is_null : llvalue -> bool = "llvm_is_null"
533 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
534 otherwise. Similar to [llvm::isa<UndefValue>]. *)
535 external is_undef : llvalue -> bool = "llvm_is_undef"
538 (** {7 Operations on instructions} *)
540 (** [has_metadata i] returns whether or not the instruction [i] has any
541 metadata attached to it. See the function
542 [llvm::Instruction::hasMetadata]. *)
543 external has_metadata : llvalue -> bool = "llvm_has_metadata"
545 (** [metadata i kind] optionally returns the metadata associated with the
546 kind [kind] in the instruction [i] See the function
547 [llvm::Instruction::getMetadata]. *)
548 external metadata : llvalue -> int -> llvalue option = "llvm_metadata"
550 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
551 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
552 external set_metadata : llvalue -> int -> llvalue -> unit = "llvm_set_metadata"
554 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
555 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
556 external clear_metadata : llvalue -> int -> unit = "llvm_clear_metadata"
559 (** {7 Operations on metadata} *)
561 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
562 See the method [llvm::MDNode::get]. *)
563 external mdstring : llcontext -> string -> llvalue = "llvm_mdstring"
565 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
567 See the method [llvm::MDNode::get]. *)
568 external mdnode : llcontext -> llvalue array -> llvalue = "llvm_mdnode"
571 (** {7 Operations on scalar constants} *)
573 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
574 See the method [llvm::ConstantInt::get]. *)
575 external const_int : lltype -> int -> llvalue = "llvm_const_int"
577 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
578 [i]. See the method [llvm::ConstantInt::get]. *)
579 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
580 = "llvm_const_of_int64"
582 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
583 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
584 external const_int_of_string : lltype -> string -> int -> llvalue
585 = "llvm_const_int_of_string"
587 (** [const_float ty n] returns the floating point constant of type [ty] and
588 value [n]. See the method [llvm::ConstantFP::get]. *)
589 external const_float : lltype -> float -> llvalue = "llvm_const_float"
591 (** [const_float_of_string ty s] returns the floating point constant of type
592 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
593 external const_float_of_string : lltype -> string -> llvalue
594 = "llvm_const_float_of_string"
597 (** {7 Operations on composite constants} *)
599 (** [const_string c s] returns the constant [i8] array with the values of the
600 characters in the string [s] in the context [c]. The array is not
601 null-terminated (but see {!const_stringz}). This value can in turn be used
602 as the initializer for a global variable. See the method
603 [llvm::ConstantArray::get]. *)
604 external const_string : llcontext -> string -> llvalue = "llvm_const_string"
606 (** [const_stringz c s] returns the constant [i8] array with the values of the
607 characters in the string [s] and a null terminator in the context [c]. This
608 value can in turn be used as the initializer for a global variable.
609 See the method [llvm::ConstantArray::get]. *)
610 external const_stringz : llcontext -> string -> llvalue = "llvm_const_stringz"
612 (** [const_array ty elts] returns the constant array of type
613 [array_type ty (Array.length elts)] and containing the values [elts].
614 This value can in turn be used as the initializer for a global variable.
615 See the method [llvm::ConstantArray::get]. *)
616 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
618 (** [const_struct context elts] returns the structured constant of type
619 [struct_type (Array.map type_of elts)] and containing the values [elts]
620 in the context [context]. This value can in turn be used as the initializer
621 for a global variable. See the method [llvm::ConstantStruct::get]. *)
622 external const_struct : llcontext -> llvalue array -> llvalue
623 = "llvm_const_struct"
625 (** [const_packed_struct context elts] returns the structured constant of
626 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
627 values [elts] in the context [context]. This value can in turn be used as
628 the initializer for a global variable. See the method
629 [llvm::ConstantStruct::get]. *)
630 external const_packed_struct : llcontext -> llvalue array -> llvalue
631 = "llvm_const_packed_struct"
633 (** [const_vector elts] returns the vector constant of type
634 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
635 values [elts]. See the method [llvm::ConstantVector::get]. *)
636 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
638 (** [const_union ty v] returns the union constant of type [union_type tys] and
639 containing the value [v]. See the method [llvm::ConstantUnion::get]. *)
640 external const_union : lltype -> llvalue -> llvalue = "LLVMConstUnion"
643 (** {7 Constant expressions} *)
645 (** [align_of ty] returns the alignof constant for the type [ty]. This is
646 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
647 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
648 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
649 external align_of : lltype -> llvalue = "LLVMAlignOf"
651 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
652 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
653 (const_int i32_type 1)) i64_type], but considerably more readable.
654 See the method [llvm::ConstantExpr::getSizeOf]. *)
655 external size_of : lltype -> llvalue = "LLVMSizeOf"
657 (** [const_neg c] returns the arithmetic negation of the constant [c].
658 See the method [llvm::ConstantExpr::getNeg]. *)
659 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
661 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
662 no signed wrapping. The result is undefined if the negation overflows.
663 See the method [llvm::ConstantExpr::getNSWNeg]. *)
664 external const_nsw_neg : llvalue -> llvalue = "LLVMConstNSWNeg"
666 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
667 no unsigned wrapping. The result is undefined if the negation overflows.
668 See the method [llvm::ConstantExpr::getNUWNeg]. *)
669 external const_nuw_neg : llvalue -> llvalue = "LLVMConstNUWNeg"
671 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
672 See the method [llvm::ConstantExpr::getFNeg]. *)
673 external const_fneg : llvalue -> llvalue = "LLVMConstFNeg"
675 (** [const_not c] returns the bitwise inverse of the constant [c].
676 See the method [llvm::ConstantExpr::getNot]. *)
677 external const_not : llvalue -> llvalue = "LLVMConstNot"
679 (** [const_add c1 c2] returns the constant sum of two constants.
680 See the method [llvm::ConstantExpr::getAdd]. *)
681 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
683 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
684 signed wrapping. The result is undefined if the sum overflows.
685 See the method [llvm::ConstantExpr::getNSWAdd]. *)
686 external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd"
688 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
689 unsigned wrapping. The result is undefined if the sum overflows.
690 See the method [llvm::ConstantExpr::getNSWAdd]. *)
691 external const_nuw_add : llvalue -> llvalue -> llvalue = "LLVMConstNUWAdd"
693 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
694 See the method [llvm::ConstantExpr::getFAdd]. *)
695 external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd"
697 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
698 constants. See the method [llvm::ConstantExpr::getSub]. *)
699 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
701 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
702 no signed wrapping. The result is undefined if the sum overflows.
703 See the method [llvm::ConstantExpr::getNSWSub]. *)
704 external const_nsw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNSWSub"
706 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
707 no unsigned wrapping. The result is undefined if the sum overflows.
708 See the method [llvm::ConstantExpr::getNSWSub]. *)
709 external const_nuw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNUWSub"
711 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
712 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
713 external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub"
715 (** [const_mul c1 c2] returns the constant product of two constants.
716 See the method [llvm::ConstantExpr::getMul]. *)
717 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
719 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
720 no signed wrapping. The result is undefined if the sum overflows.
721 See the method [llvm::ConstantExpr::getNSWMul]. *)
722 external const_nsw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNSWMul"
724 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
725 no unsigned wrapping. The result is undefined if the sum overflows.
726 See the method [llvm::ConstantExpr::getNSWMul]. *)
727 external const_nuw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNUWMul"
729 (** [const_fmul c1 c2] returns the constant product of two constants floats.
730 See the method [llvm::ConstantExpr::getFMul]. *)
731 external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul"
733 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
735 See the method [llvm::ConstantExpr::getUDiv]. *)
736 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
738 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
740 See the method [llvm::ConstantExpr::getSDiv]. *)
741 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
743 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
744 signed integer constants. The result is undefined if the result is rounded
745 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
746 external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv"
748 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
750 See the method [llvm::ConstantExpr::getFDiv]. *)
751 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
753 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
754 unsigned integer constants.
755 See the method [llvm::ConstantExpr::getURem]. *)
756 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
758 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
759 signed integer constants.
760 See the method [llvm::ConstantExpr::getSRem]. *)
761 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
763 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
764 signed floating point constants.
765 See the method [llvm::ConstantExpr::getFRem]. *)
766 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
768 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
770 See the method [llvm::ConstantExpr::getAnd]. *)
771 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
773 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
775 See the method [llvm::ConstantExpr::getOr]. *)
776 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
778 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
780 See the method [llvm::ConstantExpr::getXor]. *)
781 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
783 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
784 constants, [c1 pred c2].
785 See the method [llvm::ConstantExpr::getICmp]. *)
786 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
789 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
790 point constants, [c1 pred c2].
791 See the method [llvm::ConstantExpr::getFCmp]. *)
792 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
795 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
796 constant integer [c2].
797 See the method [llvm::ConstantExpr::getShl]. *)
798 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
800 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
801 constant integer [c2] with zero extension.
802 See the method [llvm::ConstantExpr::getLShr]. *)
803 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
805 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
806 constant integer [c2] with sign extension.
807 See the method [llvm::ConstantExpr::getAShr]. *)
808 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
810 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
811 constant integers indices from the array [indices].
812 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
813 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
815 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
816 with the constant integers indices from the array [indices].
817 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
818 external const_in_bounds_gep : llvalue -> llvalue array -> llvalue
819 = "llvm_const_in_bounds_gep"
821 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
822 to the smaller integer type [ty].
823 See the method [llvm::ConstantExpr::getTrunc]. *)
824 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
826 (** [const_sext c ty] returns the constant sign extension of integer constant
827 [c] to the larger integer type [ty].
828 See the method [llvm::ConstantExpr::getSExt]. *)
829 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
831 (** [const_zext c ty] returns the constant zero extension of integer constant
832 [c] to the larger integer type [ty].
833 See the method [llvm::ConstantExpr::getZExt]. *)
834 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
836 (** [const_fptrunc c ty] returns the constant truncation of floating point
837 constant [c] to the smaller floating point type [ty].
838 See the method [llvm::ConstantExpr::getFPTrunc]. *)
839 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
841 (** [const_fpext c ty] returns the constant extension of floating point constant
842 [c] to the larger floating point type [ty].
843 See the method [llvm::ConstantExpr::getFPExt]. *)
844 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
846 (** [const_uitofp c ty] returns the constant floating point conversion of
847 unsigned integer constant [c] to the floating point type [ty].
848 See the method [llvm::ConstantExpr::getUIToFP]. *)
849 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
851 (** [const_sitofp c ty] returns the constant floating point conversion of
852 signed integer constant [c] to the floating point type [ty].
853 See the method [llvm::ConstantExpr::getSIToFP]. *)
854 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
856 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
857 floating point constant [c] to integer type [ty].
858 See the method [llvm::ConstantExpr::getFPToUI]. *)
859 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
861 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
862 floating point constant [c] to integer type [ty].
863 See the method [llvm::ConstantExpr::getFPToSI]. *)
864 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
866 (** [const_ptrtoint c ty] returns the constant integer conversion of
867 pointer constant [c] to integer type [ty].
868 See the method [llvm::ConstantExpr::getPtrToInt]. *)
869 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
871 (** [const_inttoptr c ty] returns the constant pointer conversion of
872 integer constant [c] to pointer type [ty].
873 See the method [llvm::ConstantExpr::getIntToPtr]. *)
874 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
876 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
877 to type [ty] of equal size.
878 See the method [llvm::ConstantExpr::getBitCast]. *)
879 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
881 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
882 conversion of constant [c] to type [ty].
883 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
884 external const_zext_or_bitcast : llvalue -> lltype -> llvalue
885 = "LLVMConstZExtOrBitCast"
887 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
888 conversion of constant [c] to type [ty].
889 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
890 external const_sext_or_bitcast : llvalue -> lltype -> llvalue
891 = "LLVMConstSExtOrBitCast"
893 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
894 conversion of constant [c] to type [ty].
895 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
896 external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
897 = "LLVMConstTruncOrBitCast"
899 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
900 cast conversion of constant [c] to type [ty] of equal size.
901 See the method [llvm::ConstantExpr::getPointerCast]. *)
902 external const_pointercast : llvalue -> lltype -> llvalue
903 = "LLVMConstPointerCast"
905 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
906 -> integer casts of constant [c] to type [ty].
907 See the method [llvm::ConstantExpr::getIntCast]. *)
908 external const_intcast : llvalue -> lltype -> llvalue
911 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
912 fp casts of constant [c] to type [ty].
913 See the method [llvm::ConstantExpr::getFPCast]. *)
914 external const_fpcast : llvalue -> lltype -> llvalue
917 (** [const_select cond t f] returns the constant conditional which returns value
918 [t] if the boolean constant [cond] is true and the value [f] otherwise.
919 See the method [llvm::ConstantExpr::getSelect]. *)
920 external const_select : llvalue -> llvalue -> llvalue -> llvalue
923 (** [const_extractelement vec i] returns the constant [i]th element of
924 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
925 the size of the vector.
926 See the method [llvm::ConstantExpr::getExtractElement]. *)
927 external const_extractelement : llvalue -> llvalue -> llvalue
928 = "LLVMConstExtractElement"
930 (** [const_insertelement vec v i] returns the constant vector with the same
931 elements as constant vector [v] but the [i]th element replaced by the
932 constant [v]. [v] must be a constant value with the type of the vector
933 elements. [i] must be a constant [i32] value unsigned less than the size
935 See the method [llvm::ConstantExpr::getInsertElement]. *)
936 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
937 = "LLVMConstInsertElement"
939 (** [const_shufflevector a b mask] returns a constant [shufflevector].
940 See the LLVM Language Reference for details on the [sufflevector]
942 See the method [llvm::ConstantExpr::getShuffleVector]. *)
943 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
944 = "LLVMConstShuffleVector"
946 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
947 constant aggregate [agg]. Each [idxs] must be less than the size of the
948 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
949 external const_extractvalue : llvalue -> int array -> llvalue
950 = "llvm_const_extractvalue"
952 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
953 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
954 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
955 external const_insertvalue : llvalue -> llvalue -> int array -> llvalue
956 = "llvm_const_insertvalue"
958 (** [block_address f bb] returns the address of the basic block [bb] in the
959 function [f]. See the method [llvm::BasicBlock::get]. *)
960 external block_address : llvalue -> llbasicblock -> llvalue = "LLVMBlockAddress"
963 (** {7 Operations on global variables, functions, and aliases (globals)} *)
965 (** [global_parent g] is the enclosing module of the global value [g].
966 See the method [llvm::GlobalValue::getParent]. *)
967 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
969 (** [is_declaration g] returns [true] if the global value [g] is a declaration
970 only. Returns [false] otherwise.
971 See the method [llvm::GlobalValue::isDeclaration]. *)
972 external is_declaration : llvalue -> bool = "llvm_is_declaration"
974 (** [linkage g] returns the linkage of the global value [g].
975 See the method [llvm::GlobalValue::getLinkage]. *)
976 external linkage : llvalue -> Linkage.t = "llvm_linkage"
978 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
979 See the method [llvm::GlobalValue::setLinkage]. *)
980 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
982 (** [section g] returns the linker section of the global value [g].
983 See the method [llvm::GlobalValue::getSection]. *)
984 external section : llvalue -> string = "llvm_section"
986 (** [set_section s g] sets the linker section of the global value [g] to [s].
987 See the method [llvm::GlobalValue::setSection]. *)
988 external set_section : string -> llvalue -> unit = "llvm_set_section"
990 (** [visibility g] returns the linker visibility of the global value [g].
991 See the method [llvm::GlobalValue::getVisibility]. *)
992 external visibility : llvalue -> Visibility.t = "llvm_visibility"
994 (** [set_visibility v g] sets the linker visibility of the global value [g] to
995 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
996 external set_visibility : Visibility.t -> llvalue -> unit
997 = "llvm_set_visibility"
999 (** [alignment g] returns the required alignment of the global value [g].
1000 See the method [llvm::GlobalValue::getAlignment]. *)
1001 external alignment : llvalue -> int = "llvm_alignment"
1003 (** [set_alignment n g] sets the required alignment of the global value [g] to
1004 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1005 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
1008 (** {7 Operations on global variables} *)
1010 (** [declare_global ty name m] returns a new global variable of type [ty] and
1011 with name [name] in module [m] in the default address space (0). If such a
1012 global variable already exists, it is returned. If the type of the existing
1013 global differs, then a bitcast to [ty] is returned. *)
1014 external declare_global : lltype -> string -> llmodule -> llvalue
1015 = "llvm_declare_global"
1017 (** [declare_qualified_global ty name as m] returns a new global variable of
1018 type [ty] and with name [name] in module [m] in the address space [as]. If
1019 such a global variable already exists, it is returned. If the type of the
1020 existing global differs, then a bitcast to [ty] is returned. *)
1021 external declare_qualified_global : lltype -> string -> int -> llmodule ->
1023 = "llvm_declare_qualified_global"
1025 (** [define_global name init m] returns a new global with name [name] and
1026 initializer [init] in module [m] in the default address space (0). If the
1027 named global already exists, it is renamed.
1028 See the constructor of [llvm::GlobalVariable]. *)
1029 external define_global : string -> llvalue -> llmodule -> llvalue
1030 = "llvm_define_global"
1032 (** [define_qualified_global name init as m] returns a new global with name
1033 [name] and initializer [init] in module [m] in the address space [as]. If
1034 the named global already exists, it is renamed.
1035 See the constructor of [llvm::GlobalVariable]. *)
1036 external define_qualified_global : string -> llvalue -> int -> llmodule ->
1038 = "llvm_define_qualified_global"
1040 (** [lookup_global name m] returns [Some g] if a global variable with name
1041 [name] exists in module [m]. If no such global exists, returns [None].
1042 See the [llvm::GlobalVariable] constructor. *)
1043 external lookup_global : string -> llmodule -> llvalue option
1044 = "llvm_lookup_global"
1046 (** [delete_global gv] destroys the global variable [gv].
1047 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1048 external delete_global : llvalue -> unit = "llvm_delete_global"
1050 (** [global_begin m] returns the first position in the global variable list of
1051 the module [m]. [global_begin] and [global_succ] can be used to iterate
1052 over the global list in order.
1053 See the method [llvm::Module::global_begin]. *)
1054 external global_begin : llmodule -> (llmodule, llvalue) llpos
1055 = "llvm_global_begin"
1057 (** [global_succ gv] returns the global variable list position succeeding
1059 See the method [llvm::Module::global_iterator::operator++]. *)
1060 external global_succ : llvalue -> (llmodule, llvalue) llpos
1061 = "llvm_global_succ"
1063 (** [iter_globals f m] applies function [f] to each of the global variables of
1064 module [m] in order. Tail recursive. *)
1065 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1067 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1068 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1069 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1071 (** [global_end m] returns the last position in the global variable list of the
1072 module [m]. [global_end] and [global_pred] can be used to iterate over the
1073 global list in reverse.
1074 See the method [llvm::Module::global_end]. *)
1075 external global_end : llmodule -> (llmodule, llvalue) llrev_pos
1078 (** [global_pred gv] returns the global variable list position preceding
1080 See the method [llvm::Module::global_iterator::operator--]. *)
1081 external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1082 = "llvm_global_pred"
1084 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1085 of module [m] in reverse order. Tail recursive. *)
1086 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1088 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1089 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1090 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1092 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1093 constant. Returns [false] otherwise.
1094 See the method [llvm::GlobalVariable::isConstant]. *)
1095 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
1097 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1098 [c] is [true] and not if [c] is [false].
1099 See the method [llvm::GlobalVariable::setConstant]. *)
1100 external set_global_constant : bool -> llvalue -> unit
1101 = "llvm_set_global_constant"
1103 (** [global_initializer gv] returns the initializer for the global variable
1104 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1105 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
1107 (** [set_initializer c gv] sets the initializer for the global variable
1108 [gv] to the constant [c].
1109 See the method [llvm::GlobalVariable::setInitializer]. *)
1110 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
1112 (** [remove_initializer gv] unsets the initializer for the global variable
1114 See the method [llvm::GlobalVariable::setInitializer]. *)
1115 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
1117 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1118 thread-local and [false] otherwise.
1119 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1120 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
1122 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1123 [c] is [true] and not otherwise.
1124 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1125 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
1128 (** {7 Operations on functions} *)
1130 (** [declare_function name ty m] returns a new function of type [ty] and
1131 with name [name] in module [m]. If such a function already exists,
1132 it is returned. If the type of the existing function differs, then a bitcast
1133 to [ty] is returned. *)
1134 external declare_function : string -> lltype -> llmodule -> llvalue
1135 = "llvm_declare_function"
1137 (** [define_function name ty m] creates a new function with name [name] and
1138 type [ty] in module [m]. If the named function already exists, it is
1139 renamed. An entry basic block is created in the function.
1140 See the constructor of [llvm::GlobalVariable]. *)
1141 external define_function : string -> lltype -> llmodule -> llvalue
1142 = "llvm_define_function"
1144 (** [lookup_function name m] returns [Some f] if a function with name
1145 [name] exists in module [m]. If no such function exists, returns [None].
1146 See the method [llvm::Module] constructor. *)
1147 external lookup_function : string -> llmodule -> llvalue option
1148 = "llvm_lookup_function"
1150 (** [delete_function f] destroys the function [f].
1151 See the method [llvm::Function::eraseFromParent]. *)
1152 external delete_function : llvalue -> unit = "llvm_delete_function"
1154 (** [function_begin m] returns the first position in the function list of the
1155 module [m]. [function_begin] and [function_succ] can be used to iterate over
1156 the function list in order.
1157 See the method [llvm::Module::begin]. *)
1158 external function_begin : llmodule -> (llmodule, llvalue) llpos
1159 = "llvm_function_begin"
1161 (** [function_succ gv] returns the function list position succeeding
1163 See the method [llvm::Module::iterator::operator++]. *)
1164 external function_succ : llvalue -> (llmodule, llvalue) llpos
1165 = "llvm_function_succ"
1167 (** [iter_functions f m] applies function [f] to each of the functions of module
1168 [m] in order. Tail recursive. *)
1169 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1171 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1172 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1173 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1175 (** [function_end m] returns the last position in the function list of
1176 the module [m]. [function_end] and [function_pred] can be used to iterate
1177 over the function list in reverse.
1178 See the method [llvm::Module::end]. *)
1179 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
1180 = "llvm_function_end"
1182 (** [function_pred gv] returns the function list position preceding [After gv].
1183 See the method [llvm::Module::iterator::operator--]. *)
1184 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1185 = "llvm_function_pred"
1187 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1188 module [m] in reverse order. Tail recursive. *)
1189 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1191 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1192 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1193 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1195 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1196 See the method [llvm::Function::isIntrinsic]. *)
1197 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
1199 (** [function_call_conv f] returns the calling convention of the function [f].
1200 See the method [llvm::Function::getCallingConv]. *)
1201 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
1203 (** [set_function_call_conv cc f] sets the calling convention of the function
1204 [f] to the calling convention numbered [cc].
1205 See the method [llvm::Function::setCallingConv]. *)
1206 external set_function_call_conv : int -> llvalue -> unit
1207 = "llvm_set_function_call_conv"
1209 (** [gc f] returns [Some name] if the function [f] has a garbage
1210 collection algorithm specified and [None] otherwise.
1211 See the method [llvm::Function::getGC]. *)
1212 external gc : llvalue -> string option = "llvm_gc"
1214 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1215 [gc]. See the method [llvm::Function::setGC]. *)
1216 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
1218 (** [add_function_attr f a] adds attribute [a] to the return type of function
1220 external add_function_attr : llvalue -> Attribute.t -> unit
1221 = "llvm_add_function_attr"
1223 (** [remove_function_attr f a] removes attribute [a] from the return type of
1225 external remove_function_attr : llvalue -> Attribute.t -> unit
1226 = "llvm_remove_function_attr"
1228 (** {7 Operations on params} *)
1230 (** [params f] returns the parameters of function [f].
1231 See the method [llvm::Function::getArgumentList]. *)
1232 external params : llvalue -> llvalue array = "llvm_params"
1234 (** [param f n] returns the [n]th parameter of function [f].
1235 See the method [llvm::Function::getArgumentList]. *)
1236 external param : llvalue -> int -> llvalue = "llvm_param"
1238 (** [param_parent p] returns the parent function that owns the parameter.
1239 See the method [llvm::Argument::getParent]. *)
1240 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
1242 (** [param_begin f] returns the first position in the parameter list of the
1243 function [f]. [param_begin] and [param_succ] can be used to iterate over
1244 the parameter list in order.
1245 See the method [llvm::Function::arg_begin]. *)
1246 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
1248 (** [param_succ bb] returns the parameter list position succeeding
1250 See the method [llvm::Function::arg_iterator::operator++]. *)
1251 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
1253 (** [iter_params f fn] applies function [f] to each of the parameters
1254 of function [fn] in order. Tail recursive. *)
1255 val iter_params : (llvalue -> unit) -> llvalue -> unit
1257 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1258 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1259 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1261 (** [param_end f] returns the last position in the parameter list of
1262 the function [f]. [param_end] and [param_pred] can be used to iterate
1263 over the parameter list in reverse.
1264 See the method [llvm::Function::arg_end]. *)
1265 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
1267 (** [param_pred gv] returns the function list position preceding [After gv].
1268 See the method [llvm::Function::arg_iterator::operator--]. *)
1269 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1272 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1273 of function [fn] in reverse order. Tail recursive. *)
1274 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1276 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1277 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1278 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1280 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1281 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1283 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1284 external remove_param_attr : llvalue -> Attribute.t -> unit
1285 = "llvm_remove_param_attr"
1287 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1288 external set_param_alignment : llvalue -> int -> unit
1289 = "llvm_set_param_alignment"
1291 (** {7 Operations on basic blocks} *)
1293 (** [basic_blocks fn] returns the basic blocks of the function [f].
1294 See the method [llvm::Function::getBasicBlockList]. *)
1295 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
1297 (** [entry_block fn] returns the entry basic block of the function [f].
1298 See the method [llvm::Function::getEntryBlock]. *)
1299 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1301 (** [delete_block bb] deletes the basic block [bb].
1302 See the method [llvm::BasicBlock::eraseFromParent]. *)
1303 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1305 (** [append_block c name f] creates a new basic block named [name] at the end of
1306 function [f] in the context [c].
1307 See the constructor of [llvm::BasicBlock]. *)
1308 external append_block : llcontext -> string -> llvalue -> llbasicblock
1309 = "llvm_append_block"
1311 (** [insert_block c name bb] creates a new basic block named [name] before the
1312 basic block [bb] in the context [c].
1313 See the constructor of [llvm::BasicBlock]. *)
1314 external insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1315 = "llvm_insert_block"
1317 (** [block_parent bb] returns the parent function that owns the basic block.
1318 See the method [llvm::BasicBlock::getParent]. *)
1319 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1321 (** [block_begin f] returns the first position in the basic block list of the
1322 function [f]. [block_begin] and [block_succ] can be used to iterate over
1323 the basic block list in order.
1324 See the method [llvm::Function::begin]. *)
1325 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1326 = "llvm_block_begin"
1328 (** [block_succ bb] returns the basic block list position succeeding
1330 See the method [llvm::Function::iterator::operator++]. *)
1331 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1334 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1335 of function [fn] in order. Tail recursive. *)
1336 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1338 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1339 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1340 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1342 (** [block_end f] returns the last position in the basic block list of
1343 the function [f]. [block_end] and [block_pred] can be used to iterate
1344 over the basic block list in reverse.
1345 See the method [llvm::Function::end]. *)
1346 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1349 (** [block_pred gv] returns the function list position preceding [After gv].
1350 See the method [llvm::Function::iterator::operator--]. *)
1351 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1354 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1355 of function [fn] in reverse order. Tail recursive. *)
1356 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1358 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1359 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1360 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1362 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1363 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1365 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1367 Similar to [llvm::isa<BasicBlock>]. *)
1368 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1370 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1371 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1374 (** {7 Operations on instructions} *)
1376 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1377 See the method [llvm::Instruction::getParent]. *)
1378 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1380 (** [instr_begin bb] returns the first position in the instruction list of the
1381 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1382 the instruction list in order.
1383 See the method [llvm::BasicBlock::begin]. *)
1384 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1385 = "llvm_instr_begin"
1387 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1388 See the method [llvm::BasicBlock::iterator::operator++]. *)
1389 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1392 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1393 block [bb] in order. Tail recursive. *)
1394 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1396 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1397 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1398 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1400 (** [instr_end bb] returns the last position in the instruction list of the
1401 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1402 the instruction list in reverse.
1403 See the method [llvm::BasicBlock::end]. *)
1404 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1407 (** [instr_pred i] returns the instruction list position preceding [After i].
1408 See the method [llvm::BasicBlock::iterator::operator--]. *)
1409 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1412 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1413 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1414 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1417 (** {7 Operations on call sites} *)
1419 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1420 instruction [ci], which may be one of the values from the module
1421 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1422 [llvm::InvokeInst::getCallingConv]. *)
1423 external instruction_call_conv: llvalue -> int
1424 = "llvm_instruction_call_conv"
1426 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1427 or invoke instruction [ci] to the integer [cc], which can be one of the
1428 values from the module {!CallConv}.
1429 See the method [llvm::CallInst::setCallingConv]
1430 and [llvm::InvokeInst::setCallingConv]. *)
1431 external set_instruction_call_conv: int -> llvalue -> unit
1432 = "llvm_set_instruction_call_conv"
1434 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1435 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1437 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1438 = "llvm_add_instruction_param_attr"
1440 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1441 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1443 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1444 = "llvm_remove_instruction_param_attr"
1446 (** {Operations on call instructions (only)} *)
1448 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1449 eligible for tail call optimization, [false] otherwise.
1450 See the method [llvm::CallInst::isTailCall]. *)
1451 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
1453 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1454 call optimization if [tc] is [true], clears otherwise.
1455 See the method [llvm::CallInst::setTailCall]. *)
1456 external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call"
1458 (** {7 Operations on phi nodes} *)
1460 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1461 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1462 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1463 = "llvm_add_incoming"
1465 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1466 See the method [llvm::PHINode::getIncomingValue]. *)
1467 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1471 (** {6 Instruction builders} *)
1473 (** [builder context] creates an instruction builder with no position in
1474 the context [context]. It is invalid to use this builder until its position
1475 is set with {!position_before} or {!position_at_end}. See the constructor
1476 for [llvm::LLVMBuilder]. *)
1477 external builder : llcontext -> llbuilder = "llvm_builder"
1479 (** [builder_at ip] creates an instruction builder positioned at [ip].
1480 See the constructor for [llvm::LLVMBuilder]. *)
1481 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1483 (** [builder_before ins] creates an instruction builder positioned before the
1484 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1485 val builder_before : llcontext -> llvalue -> llbuilder
1487 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1488 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1489 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1491 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1493 See the constructor for [llvm::LLVMBuilder]. *)
1494 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1495 = "llvm_position_builder"
1497 (** [position_before ins b] moves the instruction builder [b] to before the
1498 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1499 val position_before : llvalue -> llbuilder -> unit
1501 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1502 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1503 val position_at_end : llbasicblock -> llbuilder -> unit
1505 (** [insertion_block b] returns the basic block that the builder [b] is
1506 positioned to insert into. Raises [Not_Found] if the instruction builder is
1508 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1509 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1511 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1512 position specified by the instruction builder [b].
1513 See the method [llvm::LLVMBuilder::Insert]. *)
1514 external insert_into_builder : llvalue -> string -> llbuilder -> unit
1515 = "llvm_insert_into_builder"
1519 (** [set_current_debug_location b md] sets the current debug location [md] in
1521 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1522 external set_current_debug_location : llbuilder -> llvalue -> unit
1523 = "llvm_set_current_debug_location"
1525 (** [clear_current_debug_location b] clears the current debug location in the
1527 external clear_current_debug_location : llbuilder -> unit
1528 = "llvm_clear_current_debug_location"
1530 (** [current_debug_location b] returns the current debug location, or None
1531 if none is currently set.
1532 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1533 external current_debug_location : llbuilder -> llvalue option
1534 = "llvm_current_debug_location"
1536 (** [set_inst_debug_location b i] sets the current debug location of the builder
1537 [b] to the instruction [i].
1538 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1539 external set_inst_debug_location : llbuilder -> llvalue -> unit
1540 = "llvm_set_inst_debug_location"
1542 (** {7 Terminators} *)
1544 (** [build_ret_void b] creates a
1546 instruction at the position specified by the instruction builder [b].
1547 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1548 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1550 (** [build_ret v b] creates a
1552 instruction at the position specified by the instruction builder [b].
1553 See the method [llvm::LLVMBuilder::CreateRet]. *)
1554 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1556 (** [build_aggregate_ret vs b] creates a
1557 [ret {...} { %v1, %v2, ... } ]
1558 instruction at the position specified by the instruction builder [b].
1559 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1560 external build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1561 = "llvm_build_aggregate_ret"
1563 (** [build_br bb b] creates a
1565 instruction at the position specified by the instruction builder [b].
1566 See the method [llvm::LLVMBuilder::CreateBr]. *)
1567 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1569 (** [build_cond_br cond tbb fbb b] creates a
1570 [br %cond, %tbb, %fbb]
1571 instruction at the position specified by the instruction builder [b].
1572 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1573 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1574 llvalue = "llvm_build_cond_br"
1576 (** [build_switch case elsebb count b] creates an empty
1577 [switch %case, %elsebb]
1578 instruction at the position specified by the instruction builder [b] with
1579 space reserved for [count] cases.
1580 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1581 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1582 = "llvm_build_switch"
1584 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1585 when its input matches the constant [onval].
1586 See the method [llvm::SwitchInst::addCase]. **)
1587 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1590 (** [build_indirect_br addr count b] creates a
1592 instruction at the position specified by the instruction builder [b] with
1593 space reserved for [count] destinations.
1594 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1595 external build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1596 = "llvm_build_indirect_br"
1598 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1599 location for the indirectbr instruction [br].
1600 See the method [llvm::IndirectBrInst::addDestination]. **)
1601 external add_destination : llvalue -> llbasicblock -> unit
1602 = "llvm_add_destination"
1604 (** [build_invoke fn args tobb unwindbb name b] creates an
1605 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1606 instruction at the position specified by the instruction builder [b].
1607 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1608 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1609 llbasicblock -> string -> llbuilder -> llvalue
1610 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1612 (** [build_unwind b] creates an
1614 instruction at the position specified by the instruction builder [b].
1615 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1616 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1618 (** [build_unreachable b] creates an
1620 instruction at the position specified by the instruction builder [b].
1621 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1622 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1625 (** {7 Arithmetic} *)
1627 (** [build_add x y name b] creates a
1628 [%name = add %x, %y]
1629 instruction at the position specified by the instruction builder [b].
1630 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1631 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1634 (** [build_nsw_add x y name b] creates a
1635 [%name = nsw add %x, %y]
1636 instruction at the position specified by the instruction builder [b].
1637 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1638 external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1639 = "llvm_build_nsw_add"
1641 (** [build_nuw_add x y name b] creates a
1642 [%name = nuw add %x, %y]
1643 instruction at the position specified by the instruction builder [b].
1644 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1645 external build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1646 = "llvm_build_nuw_add"
1648 (** [build_fadd x y name b] creates a
1649 [%name = fadd %x, %y]
1650 instruction at the position specified by the instruction builder [b].
1651 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1652 external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1655 (** [build_sub x y name b] creates a
1656 [%name = sub %x, %y]
1657 instruction at the position specified by the instruction builder [b].
1658 See the method [llvm::LLVMBuilder::CreateSub]. *)
1659 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1662 (** [build_nsw_sub x y name b] creates a
1663 [%name = nsw sub %x, %y]
1664 instruction at the position specified by the instruction builder [b].
1665 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1666 external build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1667 = "llvm_build_nsw_sub"
1669 (** [build_nuw_sub x y name b] creates a
1670 [%name = nuw sub %x, %y]
1671 instruction at the position specified by the instruction builder [b].
1672 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1673 external build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1674 = "llvm_build_nuw_sub"
1676 (** [build_fsub x y name b] creates a
1677 [%name = fsub %x, %y]
1678 instruction at the position specified by the instruction builder [b].
1679 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1680 external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1683 (** [build_mul x y name b] creates a
1684 [%name = mul %x, %y]
1685 instruction at the position specified by the instruction builder [b].
1686 See the method [llvm::LLVMBuilder::CreateMul]. *)
1687 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1690 (** [build_nsw_mul x y name b] creates a
1691 [%name = nsw mul %x, %y]
1692 instruction at the position specified by the instruction builder [b].
1693 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1694 external build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1695 = "llvm_build_nsw_mul"
1697 (** [build_nuw_mul x y name b] creates a
1698 [%name = nuw mul %x, %y]
1699 instruction at the position specified by the instruction builder [b].
1700 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1701 external build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1702 = "llvm_build_nuw_mul"
1704 (** [build_fmul x y name b] creates a
1705 [%name = fmul %x, %y]
1706 instruction at the position specified by the instruction builder [b].
1707 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1708 external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1711 (** [build_udiv x y name b] creates a
1712 [%name = udiv %x, %y]
1713 instruction at the position specified by the instruction builder [b].
1714 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1715 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1718 (** [build_sdiv x y name b] creates a
1719 [%name = sdiv %x, %y]
1720 instruction at the position specified by the instruction builder [b].
1721 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1722 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1725 (** [build_exact_sdiv x y name b] creates a
1726 [%name = exact sdiv %x, %y]
1727 instruction at the position specified by the instruction builder [b].
1728 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1729 external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1730 = "llvm_build_exact_sdiv"
1732 (** [build_fdiv x y name b] creates a
1733 [%name = fdiv %x, %y]
1734 instruction at the position specified by the instruction builder [b].
1735 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1736 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1739 (** [build_urem x y name b] creates a
1740 [%name = urem %x, %y]
1741 instruction at the position specified by the instruction builder [b].
1742 See the method [llvm::LLVMBuilder::CreateURem]. *)
1743 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1746 (** [build_SRem x y name b] creates a
1747 [%name = srem %x, %y]
1748 instruction at the position specified by the instruction builder [b].
1749 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1750 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1753 (** [build_frem x y name b] creates a
1754 [%name = frem %x, %y]
1755 instruction at the position specified by the instruction builder [b].
1756 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1757 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1760 (** [build_shl x y name b] creates a
1761 [%name = shl %x, %y]
1762 instruction at the position specified by the instruction builder [b].
1763 See the method [llvm::LLVMBuilder::CreateShl]. *)
1764 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1767 (** [build_lshr x y name b] creates a
1768 [%name = lshr %x, %y]
1769 instruction at the position specified by the instruction builder [b].
1770 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1771 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1774 (** [build_ashr x y name b] creates a
1775 [%name = ashr %x, %y]
1776 instruction at the position specified by the instruction builder [b].
1777 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1778 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1781 (** [build_and x y name b] creates a
1782 [%name = and %x, %y]
1783 instruction at the position specified by the instruction builder [b].
1784 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1785 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1788 (** [build_or x y name b] creates a
1790 instruction at the position specified by the instruction builder [b].
1791 See the method [llvm::LLVMBuilder::CreateOr]. *)
1792 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1795 (** [build_xor x y name b] creates a
1796 [%name = xor %x, %y]
1797 instruction at the position specified by the instruction builder [b].
1798 See the method [llvm::LLVMBuilder::CreateXor]. *)
1799 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1802 (** [build_neg x name b] creates a
1804 instruction at the position specified by the instruction builder [b].
1805 [-0.0] is used for floating point types to compute the correct sign.
1806 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1807 external build_neg : llvalue -> string -> llbuilder -> llvalue
1810 (** [build_nsw_neg x name b] creates a
1811 [%name = nsw sub 0, %x]
1812 instruction at the position specified by the instruction builder [b].
1813 [-0.0] is used for floating point types to compute the correct sign.
1814 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1815 external build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1816 = "llvm_build_nsw_neg"
1818 (** [build_nuw_neg x name b] creates a
1819 [%name = nuw sub 0, %x]
1820 instruction at the position specified by the instruction builder [b].
1821 [-0.0] is used for floating point types to compute the correct sign.
1822 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1823 external build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1824 = "llvm_build_nuw_neg"
1826 (** [build_fneg x name b] creates a
1827 [%name = fsub 0, %x]
1828 instruction at the position specified by the instruction builder [b].
1829 [-0.0] is used for floating point types to compute the correct sign.
1830 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1831 external build_fneg : llvalue -> string -> llbuilder -> llvalue
1834 (** [build_xor x name b] creates a
1835 [%name = xor %x, -1]
1836 instruction at the position specified by the instruction builder [b].
1837 [-1] is the correct "all ones" value for the type of [x].
1838 See the method [llvm::LLVMBuilder::CreateXor]. *)
1839 external build_not : llvalue -> string -> llbuilder -> llvalue
1845 (** [build_alloca ty name b] creates a
1846 [%name = alloca %ty]
1847 instruction at the position specified by the instruction builder [b].
1848 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1849 external build_alloca : lltype -> string -> llbuilder -> llvalue
1850 = "llvm_build_alloca"
1852 (** [build_array_alloca ty n name b] creates a
1853 [%name = alloca %ty, %n]
1854 instruction at the position specified by the instruction builder [b].
1855 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1856 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1857 llvalue = "llvm_build_array_alloca"
1859 (** [build_load v name b] creates a
1861 instruction at the position specified by the instruction builder [b].
1862 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1863 external build_load : llvalue -> string -> llbuilder -> llvalue
1866 (** [build_store v p b] creates a
1868 instruction at the position specified by the instruction builder [b].
1869 See the method [llvm::LLVMBuilder::CreateStore]. *)
1870 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1871 = "llvm_build_store"
1873 (** [build_gep p indices name b] creates a
1874 [%name = getelementptr %p, indices...]
1875 instruction at the position specified by the instruction builder [b].
1876 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1877 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1880 (** [build_in_bounds_gep p indices name b] creates a
1881 [%name = gelementptr inbounds %p, indices...]
1882 instruction at the position specified by the instruction builder [b].
1883 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1884 external build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1885 llvalue = "llvm_build_in_bounds_gep"
1887 (** [build_struct_gep p idx name b] creates a
1888 [%name = getelementptr %p, 0, idx]
1889 instruction at the position specified by the instruction builder [b].
1890 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1891 external build_struct_gep : llvalue -> int -> string -> llbuilder ->
1892 llvalue = "llvm_build_struct_gep"
1894 (** [build_global_string str name b] creates a series of instructions that adds
1895 a global string at the position specified by the instruction builder [b].
1896 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1897 external build_global_string : string -> string -> llbuilder -> llvalue
1898 = "llvm_build_global_string"
1900 (** [build_global_stringptr str name b] creates a series of instructions that
1901 adds a global string pointer at the position specified by the instruction
1903 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1904 external build_global_stringptr : string -> string -> llbuilder -> llvalue
1905 = "llvm_build_global_stringptr"
1910 (** [build_trunc v ty name b] creates a
1911 [%name = trunc %p to %ty]
1912 instruction at the position specified by the instruction builder [b].
1913 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1914 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1915 = "llvm_build_trunc"
1917 (** [build_zext v ty name b] creates a
1918 [%name = zext %p to %ty]
1919 instruction at the position specified by the instruction builder [b].
1920 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1921 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1924 (** [build_sext v ty name b] creates a
1925 [%name = sext %p to %ty]
1926 instruction at the position specified by the instruction builder [b].
1927 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1928 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1931 (** [build_fptoui v ty name b] creates a
1932 [%name = fptoui %p to %ty]
1933 instruction at the position specified by the instruction builder [b].
1934 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1935 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1936 = "llvm_build_fptoui"
1938 (** [build_fptosi v ty name b] creates a
1939 [%name = fptosi %p to %ty]
1940 instruction at the position specified by the instruction builder [b].
1941 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1942 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1943 = "llvm_build_fptosi"
1945 (** [build_uitofp v ty name b] creates a
1946 [%name = uitofp %p to %ty]
1947 instruction at the position specified by the instruction builder [b].
1948 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1949 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1950 = "llvm_build_uitofp"
1952 (** [build_sitofp v ty name b] creates a
1953 [%name = sitofp %p to %ty]
1954 instruction at the position specified by the instruction builder [b].
1955 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1956 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1957 = "llvm_build_sitofp"
1959 (** [build_fptrunc v ty name b] creates a
1960 [%name = fptrunc %p to %ty]
1961 instruction at the position specified by the instruction builder [b].
1962 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1963 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1964 = "llvm_build_fptrunc"
1966 (** [build_fpext v ty name b] creates a
1967 [%name = fpext %p to %ty]
1968 instruction at the position specified by the instruction builder [b].
1969 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1970 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1971 = "llvm_build_fpext"
1973 (** [build_ptrtoint v ty name b] creates a
1974 [%name = prtotint %p to %ty]
1975 instruction at the position specified by the instruction builder [b].
1976 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1977 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1978 = "llvm_build_prttoint"
1980 (** [build_inttoptr v ty name b] creates a
1981 [%name = inttoptr %p to %ty]
1982 instruction at the position specified by the instruction builder [b].
1983 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1984 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1985 = "llvm_build_inttoptr"
1987 (** [build_bitcast v ty name b] creates a
1988 [%name = bitcast %p to %ty]
1989 instruction at the position specified by the instruction builder [b].
1990 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
1991 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1992 = "llvm_build_bitcast"
1994 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
1995 instruction at the position specified by the instruction builder [b].
1996 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
1997 external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
1998 llvalue = "llvm_build_zext_or_bitcast"
2000 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2001 instruction at the position specified by the instruction builder [b].
2002 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2003 external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2004 llvalue = "llvm_build_sext_or_bitcast"
2006 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2007 instruction at the position specified by the instruction builder [b].
2008 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2009 external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2010 llvalue = "llvm_build_trunc_or_bitcast"
2012 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2013 instruction at the position specified by the instruction builder [b].
2014 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2015 external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2016 = "llvm_build_pointercast"
2018 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2019 instruction at the position specified by the instruction builder [b].
2020 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2021 external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2022 = "llvm_build_intcast"
2024 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2025 instruction at the position specified by the instruction builder [b].
2026 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2027 external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2028 = "llvm_build_fpcast"
2031 (** {7 Comparisons} *)
2033 (** [build_icmp pred x y name b] creates a
2034 [%name = icmp %pred %x, %y]
2035 instruction at the position specified by the instruction builder [b].
2036 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2037 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2038 llbuilder -> llvalue = "llvm_build_icmp"
2040 (** [build_fcmp pred x y name b] creates a
2041 [%name = fcmp %pred %x, %y]
2042 instruction at the position specified by the instruction builder [b].
2043 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2044 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2045 llbuilder -> llvalue = "llvm_build_fcmp"
2048 (** {7 Miscellaneous instructions} *)
2050 (** [build_phi incoming name b] creates a
2051 [%name = phi %incoming]
2052 instruction at the position specified by the instruction builder [b].
2053 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2054 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2055 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2056 llvalue = "llvm_build_phi"
2058 (** [build_call fn args name b] creates a
2059 [%name = call %fn(args...)]
2060 instruction at the position specified by the instruction builder [b].
2061 See the method [llvm::LLVMBuilder::CreateCall]. *)
2062 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2065 (** [build_select cond thenv elsev name b] creates a
2066 [%name = select %cond, %thenv, %elsev]
2067 instruction at the position specified by the instruction builder [b].
2068 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2069 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2070 llvalue = "llvm_build_select"
2072 (** [build_va_arg valist argty name b] creates a
2073 [%name = va_arg %valist, %argty]
2074 instruction at the position specified by the instruction builder [b].
2075 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2076 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2077 = "llvm_build_va_arg"
2079 (** [build_extractelement vec i name b] creates a
2080 [%name = extractelement %vec, %i]
2081 instruction at the position specified by the instruction builder [b].
2082 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2083 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2084 llvalue = "llvm_build_extractelement"
2086 (** [build_insertelement vec elt i name b] creates a
2087 [%name = insertelement %vec, %elt, %i]
2088 instruction at the position specified by the instruction builder [b].
2089 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2090 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2091 llbuilder -> llvalue = "llvm_build_insertelement"
2093 (** [build_shufflevector veca vecb mask name b] creates a
2094 [%name = shufflevector %veca, %vecb, %mask]
2095 instruction at the position specified by the instruction builder [b].
2096 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2097 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2098 llbuilder -> llvalue = "llvm_build_shufflevector"
2100 (** [build_insertvalue agg idx name b] creates a
2101 [%name = extractvalue %agg, %idx]
2102 instruction at the position specified by the instruction builder [b].
2103 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2104 external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2105 = "llvm_build_extractvalue"
2107 (** [build_insertvalue agg val idx name b] creates a
2108 [%name = insertvalue %agg, %val, %idx]
2109 instruction at the position specified by the instruction builder [b].
2110 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2111 external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2112 llvalue = "llvm_build_insertvalue"
2114 (** [build_is_null val name b] creates a
2115 [%name = icmp eq %val, null]
2116 instruction at the position specified by the instruction builder [b].
2117 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2118 external build_is_null : llvalue -> string -> llbuilder -> llvalue
2119 = "llvm_build_is_null"
2121 (** [build_is_not_null val name b] creates a
2122 [%name = icmp ne %val, null]
2123 instruction at the position specified by the instruction builder [b].
2124 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2125 external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2126 = "llvm_build_is_not_null"
2128 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2129 the difference between two pointer values at the position specified by the
2130 instruction builder [b].
2131 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2132 external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2133 = "llvm_build_ptrdiff"
2135 (** {6 Module providers} *)
2137 module ModuleProvider : sig
2138 (** [create_module_provider m] encapsulates [m] in a module provider and takes
2139 ownership of the module. See the constructor
2140 [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
2141 external create : llmodule -> llmoduleprovider
2142 = "LLVMCreateModuleProviderForExistingModule"
2144 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
2145 the contained module. *)
2146 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
2150 (** {6 Memory buffers} *)
2152 module MemoryBuffer : sig
2153 (** [of_file p] is the memory buffer containing the contents of the file at
2154 path [p]. If the file could not be read, then [IoError msg] is
2156 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
2158 (** [stdin ()] is the memory buffer containing the contents of standard input.
2159 If standard input is empty, then [IoError msg] is raised. *)
2160 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
2162 (** Disposes of a memory buffer. *)
2163 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
2167 (** {6 Pass Managers} *)
2169 module PassManager : sig
2172 type any = [ `Module | `Function ]
2174 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2175 type of pipeline is suitable for link-time optimization and whole-module
2177 See the constructor of [llvm::PassManager]. *)
2178 external create : unit -> [ `Module ] t = "llvm_passmanager_create"
2180 (** [PassManager.create_function mp] constructs a new function-by-function
2181 pass pipeline over the module provider [mp]. It does not take ownership of
2182 [mp]. This type of pipeline is suitable for code generation and JIT
2184 See the constructor of [llvm::FunctionPassManager]. *)
2185 external create_function : llmoduleprovider -> [ `Function ] t
2186 = "LLVMCreateFunctionPassManager"
2188 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2189 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2190 any of the passes modified the module, [false] otherwise.
2191 See the [llvm::PassManager::run] method. *)
2192 external run_module : llmodule -> [ `Module ] t -> bool
2193 = "llvm_passmanager_run_module"
2195 (** [initialize fpm] initializes all of the function passes scheduled in the
2196 function pass manager [fpm]. Returns [true] if any of the passes modified
2197 the module, [false] otherwise.
2198 See the [llvm::FunctionPassManager::doInitialization] method. *)
2199 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
2201 (** [run_function f fpm] executes all of the function passes scheduled in the
2202 function pass manager [fpm] over the function [f]. Returns [true] if any
2203 of the passes modified [f], [false] otherwise.
2204 See the [llvm::FunctionPassManager::run] method. *)
2205 external run_function : llvalue -> [ `Function ] t -> bool
2206 = "llvm_passmanager_run_function"
2208 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2209 function pass manager [fpm]. Returns [true] if any of the passes
2210 modified the module, [false] otherwise.
2211 See the [llvm::FunctionPassManager::doFinalization] method. *)
2212 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
2214 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2215 the module provider.
2216 See the destructor of [llvm::BasePassManager]. *)
2217 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"