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 (** Used to store users and usees of values. See the [llvm::Use] class. *)
45 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *)
48 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
52 (** Used to efficiently handle large buffers of read-only binary data.
53 See the [llvm::MemoryBuffer] class. *)
56 (** The kind of an [lltype], the result of [classify_type ty]. See the
57 [llvm::Type::TypeID] enumeration. *)
78 (** The linkage of a global value, accessed with {!linkage} and
79 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
83 | Available_externally
99 (** The linker visibility of a global value, accessed with {!visibility} and
100 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
101 module Visibility : sig
108 (** The following calling convention values may be accessed with
109 {!function_call_conv} and {!set_function_call_conv}. Calling
110 conventions are open-ended. *)
111 module CallConv : sig
112 val c : int (** [c] is the C calling convention. *)
113 val fast : int (** [fast] is the calling convention to allow LLVM
114 maximum optimization opportunities. Use only with
116 val cold : int (** [cold] is the calling convention for
118 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling
119 convention from C. *)
120 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
121 convention from C. *)
124 module Attribute : sig
149 (** The predicate for an integer comparison ([icmp]) instruction.
150 See the [llvm::ICmpInst::Predicate] enumeration. *)
165 (** The predicate for a floating-point comparison ([fcmp]) instruction.
166 See the [llvm::FCmpInst::Predicate] enumeration. *)
190 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
191 of [a]. [llpos] is used to specify positions in and for forward iteration
192 through the various value lists maintained by the LLVM IR. *)
193 type ('a, 'b) llpos =
197 (** [After b] and [At_start a] specify positions from the end of the ['b] list
198 of [a]. [llrev_pos] is used for reverse iteration through the various value
199 lists maintained by the LLVM IR. *)
200 type ('a, 'b) llrev_pos =
205 (** {6 Exceptions} *)
207 exception IoError of string
212 (** [create_context ()] creates a context for storing the "global" state in
213 LLVM. See the constructor [llvm::LLVMContext]. *)
214 external create_context : unit -> llcontext = "llvm_create_context"
216 (** [destroy_context ()] destroys a context. See the destructor
217 [llvm::LLVMContext::~LLVMContext]. *)
218 external dispose_context : llcontext -> unit = "llvm_dispose_context"
220 (** See the function [llvm::getGlobalContext]. *)
221 external global_context : unit -> llcontext = "llvm_global_context"
223 (** [mdkind_id context name] returns the MDKind ID that corresponds to the
224 name [name] in the context [context]. See the function
225 [llvm::LLVMContext::getMDKindID]. *)
226 external mdkind_id : llcontext -> string -> int = "llvm_mdkind_id"
231 (** [create_module context id] creates a module with the supplied module ID in
232 the context [context]. Modules are not garbage collected; it is mandatory
233 to call {!dispose_module} to free memory. See the constructor
234 [llvm::Module::Module]. *)
235 external create_module : llcontext -> string -> llmodule = "llvm_create_module"
237 (** [dispose_module m] destroys a module [m] and all of the IR objects it
238 contained. All references to subordinate objects are invalidated;
239 referencing them will invoke undefined behavior. See the destructor
240 [llvm::Module::~Module]. *)
241 external dispose_module : llmodule -> unit = "llvm_dispose_module"
243 (** [target_triple m] is the target specifier for the module [m], something like
244 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
245 external target_triple: llmodule -> string
246 = "llvm_target_triple"
248 (** [target_triple triple m] changes the target specifier for the module [m] to
249 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
250 external set_target_triple: string -> llmodule -> unit
251 = "llvm_set_target_triple"
253 (** [data_layout m] is the data layout specifier for the module [m], something
254 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
255 method [llvm::Module::getDataLayout]. *)
256 external data_layout: llmodule -> string
259 (** [set_data_layout s m] changes the data layout specifier for the module [m]
260 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
261 external set_data_layout: string -> llmodule -> unit
262 = "llvm_set_data_layout"
264 (** [define_type_name name ty m] adds a named type to the module's symbol table.
265 Returns [true] if successful. If such a name already exists, then no entry
266 is added and [false] is returned. See the [llvm::Module::addTypeName]
268 external define_type_name : string -> lltype -> llmodule -> bool
269 = "llvm_add_type_name"
271 (** [delete_type_name name] removes a type name from the module's symbol
273 external delete_type_name : string -> llmodule -> unit
274 = "llvm_delete_type_name"
276 (** [type_by_name m n] returns the type in the module [m] named [n], or [None]
277 if it does not exist. See the method [llvm::Module::getTypeByName]. *)
278 external type_by_name : llmodule -> string -> lltype option
279 = "llvm_type_by_name"
281 (** [dump_module m] prints the .ll representation of the module [m] to standard
282 error. See the method [llvm::Module::dump]. *)
283 external dump_module : llmodule -> unit = "llvm_dump_module"
288 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
289 See the method [llvm::Type::getTypeID]. *)
290 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
292 (** [type_context ty] returns the {!llcontext} corresponding to the type [ty].
293 See the method [llvm::Type::getContext]. *)
294 external type_context : lltype -> llcontext = "llvm_type_context"
296 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
297 val string_of_lltype : lltype -> string
299 (** {7 Operations on integer types} *)
301 (** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See
302 [llvm::Type::Int1Ty]. *)
303 external i1_type : llcontext -> lltype = "llvm_i1_type"
305 (** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See
306 [llvm::Type::Int8Ty]. *)
307 external i8_type : llcontext -> lltype = "llvm_i8_type"
309 (** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See
310 [llvm::Type::Int16Ty]. *)
311 external i16_type : llcontext -> lltype = "llvm_i16_type"
313 (** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See
314 [llvm::Type::Int32Ty]. *)
315 external i32_type : llcontext -> lltype = "llvm_i32_type"
317 (** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See
318 [llvm::Type::Int64Ty]. *)
319 external i64_type : llcontext -> lltype = "llvm_i64_type"
321 (** [integer_type c n] returns an integer type of bitwidth [n] in the context
322 [c]. See the method [llvm::IntegerType::get]. *)
323 external integer_type : llcontext -> int -> lltype = "llvm_integer_type"
325 (** [integer_bitwidth c ty] returns the number of bits in the integer type [ty]
326 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *)
327 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
330 (** {7 Operations on real types} *)
332 (** [float_type c] returns the IEEE 32-bit floating point type in the context
333 [c]. See [llvm::Type::FloatTy]. *)
334 external float_type : llcontext -> lltype = "llvm_float_type"
336 (** [double_type c] returns the IEEE 64-bit floating point type in the context
337 [c]. See [llvm::Type::DoubleTy]. *)
338 external double_type : llcontext -> lltype = "llvm_double_type"
340 (** [x86fp80_type c] returns the x87 80-bit floating point type in the context
341 [c]. See [llvm::Type::X86_FP80Ty]. *)
342 external x86fp80_type : llcontext -> lltype = "llvm_x86fp80_type"
344 (** [fp128_type c] returns the IEEE 128-bit floating point type in the context
345 [c]. See [llvm::Type::FP128Ty]. *)
346 external fp128_type : llcontext -> lltype = "llvm_fp128_type"
348 (** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the
349 context [c]. See [llvm::Type::PPC_FP128Ty]. *)
350 external ppc_fp128_type : llcontext -> lltype = "llvm_ppc_fp128_type"
353 (** {7 Operations on function types} *)
355 (** [function_type ret_ty param_tys] returns the function type returning
356 [ret_ty] and taking [param_tys] as parameters.
357 See the method [llvm::FunctionType::get]. *)
358 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
360 (** [va_arg_function_type ret_ty param_tys] is just like
361 [function_type ret_ty param_tys] except that it returns the function type
362 which also takes a variable number of arguments.
363 See the method [llvm::FunctionType::get]. *)
364 external var_arg_function_type : lltype -> lltype array -> lltype
365 = "llvm_var_arg_function_type"
367 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
368 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
369 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
371 (** [return_type fty] gets the return type of the function type [fty].
372 See the method [llvm::FunctionType::getReturnType]. *)
373 external return_type : lltype -> lltype = "LLVMGetReturnType"
375 (** [param_types fty] gets the parameter types of the function type [fty].
376 See the method [llvm::FunctionType::getParamType]. *)
377 external param_types : lltype -> lltype array = "llvm_param_types"
380 (** {7 Operations on struct types} *)
382 (** [struct_type context tys] returns the structure type in the context
383 [context] containing in the types in the array [tys]. See the method
384 [llvm::StructType::get]. *)
385 external struct_type : llcontext -> lltype array -> lltype
388 (** [packed_struct_type context ys] returns the packed structure type in the
389 context [context] containing in the types in the array [tys]. See the method
390 [llvm::StructType::get]. *)
391 external packed_struct_type : llcontext -> lltype array -> lltype
392 = "llvm_packed_struct_type"
394 (** [struct_element_types sty] returns the constituent types of the struct type
395 [sty]. See the method [llvm::StructType::getElementType]. *)
396 external struct_element_types : lltype -> lltype array
397 = "llvm_struct_element_types"
399 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
400 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
401 external is_packed : lltype -> bool = "llvm_is_packed"
404 (** {7 Operations on union types} *)
406 (** [union_type context tys] returns the union type in the context [context]
407 containing the types in the array [tys]. See the method
408 [llvm::UnionType::get] *)
409 external union_type : llcontext -> lltype array -> lltype = "llvm_union_type"
411 (** [union_element_types uty] returns the constituent types of the union type
412 [uty]. See the method [llvm::UnionType::getElementType]. *)
413 external union_element_types : lltype -> lltype array
414 = "llvm_union_element_types"
417 (** {7 Operations on pointer, vector, and array types} *)
419 (** [array_type ty n] returns the array type containing [n] elements of type
420 [ty]. See the method [llvm::ArrayType::get]. *)
421 external array_type : lltype -> int -> lltype = "llvm_array_type"
423 (** [pointer_type ty] returns the pointer type referencing objects of type
424 [ty] in the default address space (0).
425 See the method [llvm::PointerType::getUnqual]. *)
426 external pointer_type : lltype -> lltype = "llvm_pointer_type"
428 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
429 of type [ty] in address space [as].
430 See the method [llvm::PointerType::get]. *)
431 external qualified_pointer_type : lltype -> int -> lltype
432 = "llvm_qualified_pointer_type"
434 (** [vector_type ty n] returns the array type containing [n] elements of the
435 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
436 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
438 (** [element_type ty] returns the element type of the pointer, vector, or array
439 type [ty]. See the method [llvm::SequentialType::get]. *)
440 external element_type : lltype -> lltype = "LLVMGetElementType"
442 (** [element_type aty] returns the element count of the array type [aty].
443 See the method [llvm::ArrayType::getNumElements]. *)
444 external array_length : lltype -> int = "llvm_array_length"
446 (** [address_space pty] returns the address space qualifier of the pointer type
447 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
448 external address_space : lltype -> int = "llvm_address_space"
450 (** [element_type ty] returns the element count of the vector type [ty].
451 See the method [llvm::VectorType::getNumElements]. *)
452 external vector_size : lltype -> int = "llvm_vector_size"
455 (** {7 Operations on other types} *)
457 (** [opaque_type c] creates a new opaque type distinct from any other in the
458 context [c]. Opaque types are useful for building recursive types in
459 combination with {!refine_type}. See [llvm::OpaqueType::get]. *)
460 external opaque_type : llcontext -> lltype = "llvm_opaque_type"
462 (** [void_type c] creates a type of a function which does not return any
463 value in the context [c]. See [llvm::Type::VoidTy]. *)
464 external void_type : llcontext -> lltype = "llvm_void_type"
466 (** [label_type c] creates a type of a basic block in the context [c]. See
467 [llvm::Type::LabelTy]. *)
468 external label_type : llcontext -> lltype = "llvm_label_type"
470 (** {7 Operations on type handles} *)
472 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
473 refined as a result of a call to {!refine_type}, the handle will be updated;
474 any bare [lltype] references will become invalid.
475 See the class [llvm::PATypeHolder]. *)
476 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
478 (** [type_of_handle tyh] resolves the type handle [tyh].
479 See the method [llvm::PATypeHolder::get()]. *)
480 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
482 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
483 concrete type [ty] in all users. Warning: This may invalidate {!lltype}
484 values! Use {!lltypehandle} to manipulate potentially abstract types. See
485 the method [llvm::Type::refineAbstractType]. *)
486 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
491 (** [type_of v] returns the type of the value [v].
492 See the method [llvm::Value::getType]. *)
493 external type_of : llvalue -> lltype = "llvm_type_of"
495 (** [value_name v] returns the name of the value [v]. For global values, this is
496 the symbol name. For instructions and basic blocks, it is the SSA register
497 name. It is meaningless for constants.
498 See the method [llvm::Value::getName]. *)
499 external value_name : llvalue -> string = "llvm_value_name"
501 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
502 [llvm::Value::setName]. *)
503 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
505 (** [dump_value v] prints the .ll representation of the value [v] to standard
506 error. See the method [llvm::Value::dump]. *)
507 external dump_value : llvalue -> unit = "llvm_dump_value"
509 (** [replace_all_uses_with old new] replaces all uses of the value [old]
510 * with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
511 external replace_all_uses_with : llvalue -> llvalue -> unit
512 = "LLVMReplaceAllUsesWith"
517 (** [use_begin v] returns the first position in the use list for the value [v].
518 [use_begin] and [use_succ] can e used to iterate over the use list in order.
519 See the method [llvm::Value::use_begin]. *)
520 external use_begin : llvalue -> lluse option = "llvm_use_begin"
522 (** [use_succ u] returns the use list position succeeding [u].
523 See the method [llvm::use_value_iterator::operator++]. *)
524 external use_succ : lluse -> lluse option = "llvm_use_succ"
526 (** [user u] returns the user of the use [u].
527 See the method [llvm::Use::getUser]. *)
528 external user : lluse -> llvalue = "llvm_user"
530 (** [used_value u] returns the usee of the use [u].
531 See the method [llvm::Use::getUsedValue]. *)
532 external used_value : lluse -> llvalue = "llvm_used_value"
534 (** [iter_uses f v] applies function [f] to each of the users of the value [v]
535 in order. Tail recursive. *)
536 val iter_uses : (lluse -> unit) -> llvalue -> unit
538 (** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where
539 [u1,...,uN] are the users of the value [v]. Tail recursive. *)
540 val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a
542 (** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where
543 [u1,...,uN] are the users of the value [v]. Not tail recursive. *)
544 val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
549 (** [operand v i] returns the operand at index [i] for the value [v]. See the
550 method [llvm::User::getOperand]. *)
551 external operand : llvalue -> int -> llvalue = "llvm_operand"
554 (** {7 Operations on constants of (mostly) any type} *)
556 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
557 otherwise. Similar to [llvm::isa<Constant>]. *)
558 external is_constant : llvalue -> bool = "llvm_is_constant"
560 (** [const_null ty] returns the constant null (zero) of the type [ty].
561 See the method [llvm::Constant::getNullValue]. *)
562 external const_null : lltype -> llvalue = "LLVMConstNull"
564 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
565 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
566 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
568 (** [const_pointer_null ty] returns the constant null (zero) pointer of the type
569 [ty]. See the method [llvm::ConstantPointerNull::get]. *)
570 external const_pointer_null : lltype -> llvalue = "LLVMConstPointerNull"
572 (** [undef ty] returns the undefined value of the type [ty].
573 See the method [llvm::UndefValue::get]. *)
574 external undef : lltype -> llvalue = "LLVMGetUndef"
576 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
577 See the method [llvm::Constant::isNullValue]. *)
578 external is_null : llvalue -> bool = "llvm_is_null"
580 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
581 otherwise. Similar to [llvm::isa<UndefValue>]. *)
582 external is_undef : llvalue -> bool = "llvm_is_undef"
585 (** {7 Operations on instructions} *)
587 (** [has_metadata i] returns whether or not the instruction [i] has any
588 metadata attached to it. See the function
589 [llvm::Instruction::hasMetadata]. *)
590 external has_metadata : llvalue -> bool = "llvm_has_metadata"
592 (** [metadata i kind] optionally returns the metadata associated with the
593 kind [kind] in the instruction [i] See the function
594 [llvm::Instruction::getMetadata]. *)
595 external metadata : llvalue -> int -> llvalue option = "llvm_metadata"
597 (** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the
598 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
599 external set_metadata : llvalue -> int -> llvalue -> unit = "llvm_set_metadata"
601 (** [clear_metadata i kind] clears the metadata of kind [kind] in the
602 instruction [i]. See the function [llvm::Instruction::setMetadata]. *)
603 external clear_metadata : llvalue -> int -> unit = "llvm_clear_metadata"
606 (** {7 Operations on metadata} *)
608 (** [mdstring c s] returns the MDString of the string [s] in the context [c].
609 See the method [llvm::MDNode::get]. *)
610 external mdstring : llcontext -> string -> llvalue = "llvm_mdstring"
612 (** [mdnode c elts] returns the MDNode containing the values [elts] in the
614 See the method [llvm::MDNode::get]. *)
615 external mdnode : llcontext -> llvalue array -> llvalue = "llvm_mdnode"
618 (** {7 Operations on scalar constants} *)
620 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
621 See the method [llvm::ConstantInt::get]. *)
622 external const_int : lltype -> int -> llvalue = "llvm_const_int"
624 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
625 [i]. See the method [llvm::ConstantInt::get]. *)
626 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
627 = "llvm_const_of_int64"
629 (** [const_int_of_string ty s r] returns the integer constant of type [ty] and
630 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *)
631 external const_int_of_string : lltype -> string -> int -> llvalue
632 = "llvm_const_int_of_string"
634 (** [const_float ty n] returns the floating point constant of type [ty] and
635 value [n]. See the method [llvm::ConstantFP::get]. *)
636 external const_float : lltype -> float -> llvalue = "llvm_const_float"
638 (** [const_float_of_string ty s] returns the floating point constant of type
639 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *)
640 external const_float_of_string : lltype -> string -> llvalue
641 = "llvm_const_float_of_string"
644 (** {7 Operations on composite constants} *)
646 (** [const_string c s] returns the constant [i8] array with the values of the
647 characters in the string [s] in the context [c]. The array is not
648 null-terminated (but see {!const_stringz}). This value can in turn be used
649 as the initializer for a global variable. See the method
650 [llvm::ConstantArray::get]. *)
651 external const_string : llcontext -> string -> llvalue = "llvm_const_string"
653 (** [const_stringz c s] returns the constant [i8] array with the values of the
654 characters in the string [s] and a null terminator in the context [c]. This
655 value can in turn be used as the initializer for a global variable.
656 See the method [llvm::ConstantArray::get]. *)
657 external const_stringz : llcontext -> string -> llvalue = "llvm_const_stringz"
659 (** [const_array ty elts] returns the constant array of type
660 [array_type ty (Array.length elts)] and containing the values [elts].
661 This value can in turn be used as the initializer for a global variable.
662 See the method [llvm::ConstantArray::get]. *)
663 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
665 (** [const_struct context elts] returns the structured constant of type
666 [struct_type (Array.map type_of elts)] and containing the values [elts]
667 in the context [context]. This value can in turn be used as the initializer
668 for a global variable. See the method [llvm::ConstantStruct::get]. *)
669 external const_struct : llcontext -> llvalue array -> llvalue
670 = "llvm_const_struct"
672 (** [const_packed_struct context elts] returns the structured constant of
673 type {!packed_struct_type} [(Array.map type_of elts)] and containing the
674 values [elts] in the context [context]. This value can in turn be used as
675 the initializer for a global variable. See the method
676 [llvm::ConstantStruct::get]. *)
677 external const_packed_struct : llcontext -> llvalue array -> llvalue
678 = "llvm_const_packed_struct"
680 (** [const_vector elts] returns the vector constant of type
681 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
682 values [elts]. See the method [llvm::ConstantVector::get]. *)
683 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
685 (** [const_union ty v] returns the union constant of type [union_type tys] and
686 containing the value [v]. See the method [llvm::ConstantUnion::get]. *)
687 external const_union : lltype -> llvalue -> llvalue = "LLVMConstUnion"
690 (** {7 Constant expressions} *)
692 (** [align_of ty] returns the alignof constant for the type [ty]. This is
693 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
694 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
695 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *)
696 external align_of : lltype -> llvalue = "LLVMAlignOf"
698 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
699 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
700 (const_int i32_type 1)) i64_type], but considerably more readable.
701 See the method [llvm::ConstantExpr::getSizeOf]. *)
702 external size_of : lltype -> llvalue = "LLVMSizeOf"
704 (** [const_neg c] returns the arithmetic negation of the constant [c].
705 See the method [llvm::ConstantExpr::getNeg]. *)
706 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
708 (** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with
709 no signed wrapping. The result is undefined if the negation overflows.
710 See the method [llvm::ConstantExpr::getNSWNeg]. *)
711 external const_nsw_neg : llvalue -> llvalue = "LLVMConstNSWNeg"
713 (** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with
714 no unsigned wrapping. The result is undefined if the negation overflows.
715 See the method [llvm::ConstantExpr::getNUWNeg]. *)
716 external const_nuw_neg : llvalue -> llvalue = "LLVMConstNUWNeg"
718 (** [const_fneg c] returns the arithmetic negation of the constant float [c].
719 See the method [llvm::ConstantExpr::getFNeg]. *)
720 external const_fneg : llvalue -> llvalue = "LLVMConstFNeg"
722 (** [const_not c] returns the bitwise inverse of the constant [c].
723 See the method [llvm::ConstantExpr::getNot]. *)
724 external const_not : llvalue -> llvalue = "LLVMConstNot"
726 (** [const_add c1 c2] returns the constant sum of two constants.
727 See the method [llvm::ConstantExpr::getAdd]. *)
728 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
730 (** [const_nsw_add c1 c2] returns the constant sum of two constants with no
731 signed wrapping. The result is undefined if the sum overflows.
732 See the method [llvm::ConstantExpr::getNSWAdd]. *)
733 external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd"
735 (** [const_nuw_add c1 c2] returns the constant sum of two constants with no
736 unsigned wrapping. The result is undefined if the sum overflows.
737 See the method [llvm::ConstantExpr::getNSWAdd]. *)
738 external const_nuw_add : llvalue -> llvalue -> llvalue = "LLVMConstNUWAdd"
740 (** [const_fadd c1 c2] returns the constant sum of two constant floats.
741 See the method [llvm::ConstantExpr::getFAdd]. *)
742 external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd"
744 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
745 constants. See the method [llvm::ConstantExpr::getSub]. *)
746 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
748 (** [const_nsw_sub c1 c2] returns the constant difference of two constants with
749 no signed wrapping. The result is undefined if the sum overflows.
750 See the method [llvm::ConstantExpr::getNSWSub]. *)
751 external const_nsw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNSWSub"
753 (** [const_nuw_sub c1 c2] returns the constant difference of two constants with
754 no unsigned wrapping. The result is undefined if the sum overflows.
755 See the method [llvm::ConstantExpr::getNSWSub]. *)
756 external const_nuw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNUWSub"
758 (** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two
759 constant floats. See the method [llvm::ConstantExpr::getFSub]. *)
760 external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub"
762 (** [const_mul c1 c2] returns the constant product of two constants.
763 See the method [llvm::ConstantExpr::getMul]. *)
764 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
766 (** [const_nsw_mul c1 c2] returns the constant product of two constants with
767 no signed wrapping. The result is undefined if the sum overflows.
768 See the method [llvm::ConstantExpr::getNSWMul]. *)
769 external const_nsw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNSWMul"
771 (** [const_nuw_mul c1 c2] returns the constant product of two constants with
772 no unsigned wrapping. The result is undefined if the sum overflows.
773 See the method [llvm::ConstantExpr::getNSWMul]. *)
774 external const_nuw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNUWMul"
776 (** [const_fmul c1 c2] returns the constant product of two constants floats.
777 See the method [llvm::ConstantExpr::getFMul]. *)
778 external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul"
780 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
782 See the method [llvm::ConstantExpr::getUDiv]. *)
783 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
785 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
787 See the method [llvm::ConstantExpr::getSDiv]. *)
788 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
790 (** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two
791 signed integer constants. The result is undefined if the result is rounded
792 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *)
793 external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv"
795 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
797 See the method [llvm::ConstantExpr::getFDiv]. *)
798 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
800 (** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two
801 unsigned integer constants.
802 See the method [llvm::ConstantExpr::getURem]. *)
803 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
805 (** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two
806 signed integer constants.
807 See the method [llvm::ConstantExpr::getSRem]. *)
808 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
810 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
811 signed floating point constants.
812 See the method [llvm::ConstantExpr::getFRem]. *)
813 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
815 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
817 See the method [llvm::ConstantExpr::getAnd]. *)
818 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
820 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
822 See the method [llvm::ConstantExpr::getOr]. *)
823 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
825 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
827 See the method [llvm::ConstantExpr::getXor]. *)
828 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
830 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
831 constants, [c1 pred c2].
832 See the method [llvm::ConstantExpr::getICmp]. *)
833 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
836 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
837 point constants, [c1 pred c2].
838 See the method [llvm::ConstantExpr::getFCmp]. *)
839 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
842 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
843 constant integer [c2].
844 See the method [llvm::ConstantExpr::getShl]. *)
845 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
847 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
848 constant integer [c2] with zero extension.
849 See the method [llvm::ConstantExpr::getLShr]. *)
850 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
852 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
853 constant integer [c2] with sign extension.
854 See the method [llvm::ConstantExpr::getAShr]. *)
855 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
857 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
858 constant integers indices from the array [indices].
859 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
860 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
862 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1]
863 with the constant integers indices from the array [indices].
864 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
865 external const_in_bounds_gep : llvalue -> llvalue array -> llvalue
866 = "llvm_const_in_bounds_gep"
868 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
869 to the smaller integer type [ty].
870 See the method [llvm::ConstantExpr::getTrunc]. *)
871 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
873 (** [const_sext c ty] returns the constant sign extension of integer constant
874 [c] to the larger integer type [ty].
875 See the method [llvm::ConstantExpr::getSExt]. *)
876 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
878 (** [const_zext c ty] returns the constant zero extension of integer constant
879 [c] to the larger integer type [ty].
880 See the method [llvm::ConstantExpr::getZExt]. *)
881 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
883 (** [const_fptrunc c ty] returns the constant truncation of floating point
884 constant [c] to the smaller floating point type [ty].
885 See the method [llvm::ConstantExpr::getFPTrunc]. *)
886 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
888 (** [const_fpext c ty] returns the constant extension of floating point constant
889 [c] to the larger floating point type [ty].
890 See the method [llvm::ConstantExpr::getFPExt]. *)
891 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
893 (** [const_uitofp c ty] returns the constant floating point conversion of
894 unsigned integer constant [c] to the floating point type [ty].
895 See the method [llvm::ConstantExpr::getUIToFP]. *)
896 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
898 (** [const_sitofp c ty] returns the constant floating point conversion of
899 signed integer constant [c] to the floating point type [ty].
900 See the method [llvm::ConstantExpr::getSIToFP]. *)
901 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
903 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
904 floating point constant [c] to integer type [ty].
905 See the method [llvm::ConstantExpr::getFPToUI]. *)
906 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
908 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
909 floating point constant [c] to integer type [ty].
910 See the method [llvm::ConstantExpr::getFPToSI]. *)
911 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
913 (** [const_ptrtoint c ty] returns the constant integer conversion of
914 pointer constant [c] to integer type [ty].
915 See the method [llvm::ConstantExpr::getPtrToInt]. *)
916 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
918 (** [const_inttoptr c ty] returns the constant pointer conversion of
919 integer constant [c] to pointer type [ty].
920 See the method [llvm::ConstantExpr::getIntToPtr]. *)
921 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
923 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
924 to type [ty] of equal size.
925 See the method [llvm::ConstantExpr::getBitCast]. *)
926 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
928 (** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast
929 conversion of constant [c] to type [ty].
930 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *)
931 external const_zext_or_bitcast : llvalue -> lltype -> llvalue
932 = "LLVMConstZExtOrBitCast"
934 (** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast
935 conversion of constant [c] to type [ty].
936 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *)
937 external const_sext_or_bitcast : llvalue -> lltype -> llvalue
938 = "LLVMConstSExtOrBitCast"
940 (** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast
941 conversion of constant [c] to type [ty].
942 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *)
943 external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
944 = "LLVMConstTruncOrBitCast"
946 (** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int
947 cast conversion of constant [c] to type [ty] of equal size.
948 See the method [llvm::ConstantExpr::getPointerCast]. *)
949 external const_pointercast : llvalue -> lltype -> llvalue
950 = "LLVMConstPointerCast"
952 (** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer
953 -> integer casts of constant [c] to type [ty].
954 See the method [llvm::ConstantExpr::getIntCast]. *)
955 external const_intcast : llvalue -> lltype -> llvalue
958 (** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
959 fp casts of constant [c] to type [ty].
960 See the method [llvm::ConstantExpr::getFPCast]. *)
961 external const_fpcast : llvalue -> lltype -> llvalue
964 (** [const_select cond t f] returns the constant conditional which returns value
965 [t] if the boolean constant [cond] is true and the value [f] otherwise.
966 See the method [llvm::ConstantExpr::getSelect]. *)
967 external const_select : llvalue -> llvalue -> llvalue -> llvalue
970 (** [const_extractelement vec i] returns the constant [i]th element of
971 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
972 the size of the vector.
973 See the method [llvm::ConstantExpr::getExtractElement]. *)
974 external const_extractelement : llvalue -> llvalue -> llvalue
975 = "LLVMConstExtractElement"
977 (** [const_insertelement vec v i] returns the constant vector with the same
978 elements as constant vector [v] but the [i]th element replaced by the
979 constant [v]. [v] must be a constant value with the type of the vector
980 elements. [i] must be a constant [i32] value unsigned less than the size
982 See the method [llvm::ConstantExpr::getInsertElement]. *)
983 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
984 = "LLVMConstInsertElement"
986 (** [const_shufflevector a b mask] returns a constant [shufflevector].
987 See the LLVM Language Reference for details on the [sufflevector]
989 See the method [llvm::ConstantExpr::getShuffleVector]. *)
990 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
991 = "LLVMConstShuffleVector"
993 (** [const_extractvalue agg idxs] returns the constant [idxs]th value of
994 constant aggregate [agg]. Each [idxs] must be less than the size of the
995 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
996 external const_extractvalue : llvalue -> int array -> llvalue
997 = "llvm_const_extractvalue"
999 (** [const_insertvalue agg val idxs] inserts the value [val] in the specified
1000 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size
1001 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)
1002 external const_insertvalue : llvalue -> llvalue -> int array -> llvalue
1003 = "llvm_const_insertvalue"
1005 (** [const_inline_asm ty asm con side align] inserts a inline assembly string.
1006 See the method [llvm::InlineAsm::get]. *)
1007 external const_inline_asm : lltype -> string -> string -> bool -> bool ->
1009 = "llvm_const_inline_asm"
1011 (** [block_address f bb] returns the address of the basic block [bb] in the
1012 function [f]. See the method [llvm::BasicBlock::get]. *)
1013 external block_address : llvalue -> llbasicblock -> llvalue = "LLVMBlockAddress"
1016 (** {7 Operations on global variables, functions, and aliases (globals)} *)
1018 (** [global_parent g] is the enclosing module of the global value [g].
1019 See the method [llvm::GlobalValue::getParent]. *)
1020 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
1022 (** [is_declaration g] returns [true] if the global value [g] is a declaration
1023 only. Returns [false] otherwise.
1024 See the method [llvm::GlobalValue::isDeclaration]. *)
1025 external is_declaration : llvalue -> bool = "llvm_is_declaration"
1027 (** [linkage g] returns the linkage of the global value [g].
1028 See the method [llvm::GlobalValue::getLinkage]. *)
1029 external linkage : llvalue -> Linkage.t = "llvm_linkage"
1031 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
1032 See the method [llvm::GlobalValue::setLinkage]. *)
1033 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
1035 (** [section g] returns the linker section of the global value [g].
1036 See the method [llvm::GlobalValue::getSection]. *)
1037 external section : llvalue -> string = "llvm_section"
1039 (** [set_section s g] sets the linker section of the global value [g] to [s].
1040 See the method [llvm::GlobalValue::setSection]. *)
1041 external set_section : string -> llvalue -> unit = "llvm_set_section"
1043 (** [visibility g] returns the linker visibility of the global value [g].
1044 See the method [llvm::GlobalValue::getVisibility]. *)
1045 external visibility : llvalue -> Visibility.t = "llvm_visibility"
1047 (** [set_visibility v g] sets the linker visibility of the global value [g] to
1048 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
1049 external set_visibility : Visibility.t -> llvalue -> unit
1050 = "llvm_set_visibility"
1052 (** [alignment g] returns the required alignment of the global value [g].
1053 See the method [llvm::GlobalValue::getAlignment]. *)
1054 external alignment : llvalue -> int = "llvm_alignment"
1056 (** [set_alignment n g] sets the required alignment of the global value [g] to
1057 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
1058 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
1061 (** {7 Operations on global variables} *)
1063 (** [declare_global ty name m] returns a new global variable of type [ty] and
1064 with name [name] in module [m] in the default address space (0). If such a
1065 global variable already exists, it is returned. If the type of the existing
1066 global differs, then a bitcast to [ty] is returned. *)
1067 external declare_global : lltype -> string -> llmodule -> llvalue
1068 = "llvm_declare_global"
1070 (** [declare_qualified_global ty name addrspace m] returns a new global variable
1071 of type [ty] and with name [name] in module [m] in the address space
1072 [addrspace]. If such a global variable already exists, it is returned. If
1073 the type of the existing global differs, then a bitcast to [ty] is
1075 external declare_qualified_global : lltype -> string -> int -> llmodule ->
1077 = "llvm_declare_qualified_global"
1079 (** [define_global name init m] returns a new global with name [name] and
1080 initializer [init] in module [m] in the default address space (0). If the
1081 named global already exists, it is renamed.
1082 See the constructor of [llvm::GlobalVariable]. *)
1083 external define_global : string -> llvalue -> llmodule -> llvalue
1084 = "llvm_define_global"
1086 (** [define_qualified_global name init addrspace m] returns a new global with
1087 name [name] and initializer [init] in module [m] in the address space
1088 [addrspace]. If the named global already exists, it is renamed.
1089 See the constructor of [llvm::GlobalVariable]. *)
1090 external define_qualified_global : string -> llvalue -> int -> llmodule ->
1092 = "llvm_define_qualified_global"
1094 (** [lookup_global name m] returns [Some g] if a global variable with name
1095 [name] exists in module [m]. If no such global exists, returns [None].
1096 See the [llvm::GlobalVariable] constructor. *)
1097 external lookup_global : string -> llmodule -> llvalue option
1098 = "llvm_lookup_global"
1100 (** [delete_global gv] destroys the global variable [gv].
1101 See the method [llvm::GlobalVariable::eraseFromParent]. *)
1102 external delete_global : llvalue -> unit = "llvm_delete_global"
1104 (** [global_begin m] returns the first position in the global variable list of
1105 the module [m]. [global_begin] and [global_succ] can be used to iterate
1106 over the global list in order.
1107 See the method [llvm::Module::global_begin]. *)
1108 external global_begin : llmodule -> (llmodule, llvalue) llpos
1109 = "llvm_global_begin"
1111 (** [global_succ gv] returns the global variable list position succeeding
1113 See the method [llvm::Module::global_iterator::operator++]. *)
1114 external global_succ : llvalue -> (llmodule, llvalue) llpos
1115 = "llvm_global_succ"
1117 (** [iter_globals f m] applies function [f] to each of the global variables of
1118 module [m] in order. Tail recursive. *)
1119 val iter_globals : (llvalue -> unit) -> llmodule -> unit
1121 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
1122 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1123 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1125 (** [global_end m] returns the last position in the global variable list of the
1126 module [m]. [global_end] and [global_pred] can be used to iterate over the
1127 global list in reverse.
1128 See the method [llvm::Module::global_end]. *)
1129 external global_end : llmodule -> (llmodule, llvalue) llrev_pos
1132 (** [global_pred gv] returns the global variable list position preceding
1134 See the method [llvm::Module::global_iterator::operator--]. *)
1135 external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
1136 = "llvm_global_pred"
1138 (** [rev_iter_globals f m] applies function [f] to each of the global variables
1139 of module [m] in reverse order. Tail recursive. *)
1140 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
1142 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
1143 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
1144 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1146 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
1147 constant. Returns [false] otherwise.
1148 See the method [llvm::GlobalVariable::isConstant]. *)
1149 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
1151 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
1152 [c] is [true] and not if [c] is [false].
1153 See the method [llvm::GlobalVariable::setConstant]. *)
1154 external set_global_constant : bool -> llvalue -> unit
1155 = "llvm_set_global_constant"
1157 (** [global_initializer gv] returns the initializer for the global variable
1158 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
1159 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
1161 (** [set_initializer c gv] sets the initializer for the global variable
1162 [gv] to the constant [c].
1163 See the method [llvm::GlobalVariable::setInitializer]. *)
1164 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
1166 (** [remove_initializer gv] unsets the initializer for the global variable
1168 See the method [llvm::GlobalVariable::setInitializer]. *)
1169 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
1171 (** [is_thread_local gv] returns [true] if the global variable [gv] is
1172 thread-local and [false] otherwise.
1173 See the method [llvm::GlobalVariable::isThreadLocal]. *)
1174 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
1176 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
1177 [c] is [true] and not otherwise.
1178 See the method [llvm::GlobalVariable::setThreadLocal]. *)
1179 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
1182 (** {7 Operations on aliases} *)
1184 (** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and
1185 the aliasee [a] with the name [n].
1186 See the constructor for [llvm::GlobalAlias]. *)
1187 external add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
1191 (** {7 Operations on functions} *)
1193 (** [declare_function name ty m] returns a new function of type [ty] and
1194 with name [name] in module [m]. If such a function already exists,
1195 it is returned. If the type of the existing function differs, then a bitcast
1196 to [ty] is returned. *)
1197 external declare_function : string -> lltype -> llmodule -> llvalue
1198 = "llvm_declare_function"
1200 (** [define_function name ty m] creates a new function with name [name] and
1201 type [ty] in module [m]. If the named function already exists, it is
1202 renamed. An entry basic block is created in the function.
1203 See the constructor of [llvm::GlobalVariable]. *)
1204 external define_function : string -> lltype -> llmodule -> llvalue
1205 = "llvm_define_function"
1207 (** [lookup_function name m] returns [Some f] if a function with name
1208 [name] exists in module [m]. If no such function exists, returns [None].
1209 See the method [llvm::Module] constructor. *)
1210 external lookup_function : string -> llmodule -> llvalue option
1211 = "llvm_lookup_function"
1213 (** [delete_function f] destroys the function [f].
1214 See the method [llvm::Function::eraseFromParent]. *)
1215 external delete_function : llvalue -> unit = "llvm_delete_function"
1217 (** [function_begin m] returns the first position in the function list of the
1218 module [m]. [function_begin] and [function_succ] can be used to iterate over
1219 the function list in order.
1220 See the method [llvm::Module::begin]. *)
1221 external function_begin : llmodule -> (llmodule, llvalue) llpos
1222 = "llvm_function_begin"
1224 (** [function_succ gv] returns the function list position succeeding
1226 See the method [llvm::Module::iterator::operator++]. *)
1227 external function_succ : llvalue -> (llmodule, llvalue) llpos
1228 = "llvm_function_succ"
1230 (** [iter_functions f m] applies function [f] to each of the functions of module
1231 [m] in order. Tail recursive. *)
1232 val iter_functions : (llvalue -> unit) -> llmodule -> unit
1234 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
1235 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1236 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
1238 (** [function_end m] returns the last position in the function list of
1239 the module [m]. [function_end] and [function_pred] can be used to iterate
1240 over the function list in reverse.
1241 See the method [llvm::Module::end]. *)
1242 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
1243 = "llvm_function_end"
1245 (** [function_pred gv] returns the function list position preceding [After gv].
1246 See the method [llvm::Module::iterator::operator--]. *)
1247 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
1248 = "llvm_function_pred"
1250 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
1251 module [m] in reverse order. Tail recursive. *)
1252 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
1254 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
1255 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
1256 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
1258 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
1259 See the method [llvm::Function::isIntrinsic]. *)
1260 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
1262 (** [function_call_conv f] returns the calling convention of the function [f].
1263 See the method [llvm::Function::getCallingConv]. *)
1264 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
1266 (** [set_function_call_conv cc f] sets the calling convention of the function
1267 [f] to the calling convention numbered [cc].
1268 See the method [llvm::Function::setCallingConv]. *)
1269 external set_function_call_conv : int -> llvalue -> unit
1270 = "llvm_set_function_call_conv"
1272 (** [gc f] returns [Some name] if the function [f] has a garbage
1273 collection algorithm specified and [None] otherwise.
1274 See the method [llvm::Function::getGC]. *)
1275 external gc : llvalue -> string option = "llvm_gc"
1277 (** [set_gc gc f] sets the collection algorithm for the function [f] to
1278 [gc]. See the method [llvm::Function::setGC]. *)
1279 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
1281 (** [add_function_attr f a] adds attribute [a] to the return type of function
1283 external add_function_attr : llvalue -> Attribute.t -> unit
1284 = "llvm_add_function_attr"
1286 (** [remove_function_attr f a] removes attribute [a] from the return type of
1288 external remove_function_attr : llvalue -> Attribute.t -> unit
1289 = "llvm_remove_function_attr"
1291 (** {7 Operations on params} *)
1293 (** [params f] returns the parameters of function [f].
1294 See the method [llvm::Function::getArgumentList]. *)
1295 external params : llvalue -> llvalue array = "llvm_params"
1297 (** [param f n] returns the [n]th parameter of function [f].
1298 See the method [llvm::Function::getArgumentList]. *)
1299 external param : llvalue -> int -> llvalue = "llvm_param"
1301 (** [param_parent p] returns the parent function that owns the parameter.
1302 See the method [llvm::Argument::getParent]. *)
1303 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
1305 (** [param_begin f] returns the first position in the parameter list of the
1306 function [f]. [param_begin] and [param_succ] can be used to iterate over
1307 the parameter list in order.
1308 See the method [llvm::Function::arg_begin]. *)
1309 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
1311 (** [param_succ bb] returns the parameter list position succeeding
1313 See the method [llvm::Function::arg_iterator::operator++]. *)
1314 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
1316 (** [iter_params f fn] applies function [f] to each of the parameters
1317 of function [fn] in order. Tail recursive. *)
1318 val iter_params : (llvalue -> unit) -> llvalue -> unit
1320 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
1321 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1322 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
1324 (** [param_end f] returns the last position in the parameter list of
1325 the function [f]. [param_end] and [param_pred] can be used to iterate
1326 over the parameter list in reverse.
1327 See the method [llvm::Function::arg_end]. *)
1328 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
1330 (** [param_pred gv] returns the function list position preceding [After gv].
1331 See the method [llvm::Function::arg_iterator::operator--]. *)
1332 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1335 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1336 of function [fn] in reverse order. Tail recursive. *)
1337 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1339 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1340 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1341 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1343 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1344 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1346 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1347 external remove_param_attr : llvalue -> Attribute.t -> unit
1348 = "llvm_remove_param_attr"
1350 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1351 external set_param_alignment : llvalue -> int -> unit
1352 = "llvm_set_param_alignment"
1354 (** {7 Operations on basic blocks} *)
1356 (** [basic_blocks fn] returns the basic blocks of the function [f].
1357 See the method [llvm::Function::getBasicBlockList]. *)
1358 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
1360 (** [entry_block fn] returns the entry basic block of the function [f].
1361 See the method [llvm::Function::getEntryBlock]. *)
1362 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1364 (** [delete_block bb] deletes the basic block [bb].
1365 See the method [llvm::BasicBlock::eraseFromParent]. *)
1366 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1368 (** [append_block c name f] creates a new basic block named [name] at the end of
1369 function [f] in the context [c].
1370 See the constructor of [llvm::BasicBlock]. *)
1371 external append_block : llcontext -> string -> llvalue -> llbasicblock
1372 = "llvm_append_block"
1374 (** [insert_block c name bb] creates a new basic block named [name] before the
1375 basic block [bb] in the context [c].
1376 See the constructor of [llvm::BasicBlock]. *)
1377 external insert_block : llcontext -> string -> llbasicblock -> llbasicblock
1378 = "llvm_insert_block"
1380 (** [block_parent bb] returns the parent function that owns the basic block.
1381 See the method [llvm::BasicBlock::getParent]. *)
1382 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1384 (** [block_begin f] returns the first position in the basic block list of the
1385 function [f]. [block_begin] and [block_succ] can be used to iterate over
1386 the basic block list in order.
1387 See the method [llvm::Function::begin]. *)
1388 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1389 = "llvm_block_begin"
1391 (** [block_succ bb] returns the basic block list position succeeding
1393 See the method [llvm::Function::iterator::operator++]. *)
1394 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1397 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1398 of function [fn] in order. Tail recursive. *)
1399 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1401 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1402 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1403 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1405 (** [block_end f] returns the last position in the basic block list of
1406 the function [f]. [block_end] and [block_pred] can be used to iterate
1407 over the basic block list in reverse.
1408 See the method [llvm::Function::end]. *)
1409 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1412 (** [block_pred gv] returns the function list position preceding [After gv].
1413 See the method [llvm::Function::iterator::operator--]. *)
1414 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1417 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1418 of function [fn] in reverse order. Tail recursive. *)
1419 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1421 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1422 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1423 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1425 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1426 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1428 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1430 Similar to [llvm::isa<BasicBlock>]. *)
1431 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1433 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1434 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1437 (** {7 Operations on instructions} *)
1439 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1440 See the method [llvm::Instruction::getParent]. *)
1441 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1443 (** [instr_begin bb] returns the first position in the instruction list of the
1444 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1445 the instruction list in order.
1446 See the method [llvm::BasicBlock::begin]. *)
1447 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1448 = "llvm_instr_begin"
1450 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1451 See the method [llvm::BasicBlock::iterator::operator++]. *)
1452 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1455 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1456 block [bb] in order. Tail recursive. *)
1457 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1459 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1460 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1461 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1463 (** [instr_end bb] returns the last position in the instruction list of the
1464 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1465 the instruction list in reverse.
1466 See the method [llvm::BasicBlock::end]. *)
1467 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1470 (** [instr_pred i] returns the instruction list position preceding [After i].
1471 See the method [llvm::BasicBlock::iterator::operator--]. *)
1472 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1475 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1476 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1477 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1480 (** {7 Operations on call sites} *)
1482 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1483 instruction [ci], which may be one of the values from the module
1484 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1485 [llvm::InvokeInst::getCallingConv]. *)
1486 external instruction_call_conv: llvalue -> int
1487 = "llvm_instruction_call_conv"
1489 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1490 or invoke instruction [ci] to the integer [cc], which can be one of the
1491 values from the module {!CallConv}.
1492 See the method [llvm::CallInst::setCallingConv]
1493 and [llvm::InvokeInst::setCallingConv]. *)
1494 external set_instruction_call_conv: int -> llvalue -> unit
1495 = "llvm_set_instruction_call_conv"
1497 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1498 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1500 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1501 = "llvm_add_instruction_param_attr"
1503 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1504 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1506 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1507 = "llvm_remove_instruction_param_attr"
1509 (** {Operations on call instructions (only)} *)
1511 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1512 eligible for tail call optimization, [false] otherwise.
1513 See the method [llvm::CallInst::isTailCall]. *)
1514 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
1516 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1517 call optimization if [tc] is [true], clears otherwise.
1518 See the method [llvm::CallInst::setTailCall]. *)
1519 external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call"
1521 (** {7 Operations on phi nodes} *)
1523 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1524 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1525 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1526 = "llvm_add_incoming"
1528 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1529 See the method [llvm::PHINode::getIncomingValue]. *)
1530 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1534 (** {6 Instruction builders} *)
1536 (** [builder context] creates an instruction builder with no position in
1537 the context [context]. It is invalid to use this builder until its position
1538 is set with {!position_before} or {!position_at_end}. See the constructor
1539 for [llvm::LLVMBuilder]. *)
1540 external builder : llcontext -> llbuilder = "llvm_builder"
1542 (** [builder_at ip] creates an instruction builder positioned at [ip].
1543 See the constructor for [llvm::LLVMBuilder]. *)
1544 val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
1546 (** [builder_before ins] creates an instruction builder positioned before the
1547 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1548 val builder_before : llcontext -> llvalue -> llbuilder
1550 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1551 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1552 val builder_at_end : llcontext -> llbasicblock -> llbuilder
1554 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1556 See the constructor for [llvm::LLVMBuilder]. *)
1557 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1558 = "llvm_position_builder"
1560 (** [position_before ins b] moves the instruction builder [b] to before the
1561 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1562 val position_before : llvalue -> llbuilder -> unit
1564 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1565 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1566 val position_at_end : llbasicblock -> llbuilder -> unit
1568 (** [insertion_block b] returns the basic block that the builder [b] is
1569 positioned to insert into. Raises [Not_Found] if the instruction builder is
1571 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1572 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1574 (** [insert_into_builder i name b] inserts the specified instruction [i] at the
1575 position specified by the instruction builder [b].
1576 See the method [llvm::LLVMBuilder::Insert]. *)
1577 external insert_into_builder : llvalue -> string -> llbuilder -> unit
1578 = "llvm_insert_into_builder"
1582 (** [set_current_debug_location b md] sets the current debug location [md] in
1584 See the method [llvm::IRBuilder::SetDebugLocation]. *)
1585 external set_current_debug_location : llbuilder -> llvalue -> unit
1586 = "llvm_set_current_debug_location"
1588 (** [clear_current_debug_location b] clears the current debug location in the
1590 external clear_current_debug_location : llbuilder -> unit
1591 = "llvm_clear_current_debug_location"
1593 (** [current_debug_location b] returns the current debug location, or None
1594 if none is currently set.
1595 See the method [llvm::IRBuilder::GetDebugLocation]. *)
1596 external current_debug_location : llbuilder -> llvalue option
1597 = "llvm_current_debug_location"
1599 (** [set_inst_debug_location b i] sets the current debug location of the builder
1600 [b] to the instruction [i].
1601 See the method [llvm::IRBuilder::SetInstDebugLocation]. *)
1602 external set_inst_debug_location : llbuilder -> llvalue -> unit
1603 = "llvm_set_inst_debug_location"
1605 (** {7 Terminators} *)
1607 (** [build_ret_void b] creates a
1609 instruction at the position specified by the instruction builder [b].
1610 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1611 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1613 (** [build_ret v b] creates a
1615 instruction at the position specified by the instruction builder [b].
1616 See the method [llvm::LLVMBuilder::CreateRet]. *)
1617 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1619 (** [build_aggregate_ret vs b] creates a
1620 [ret {...} { %v1, %v2, ... } ]
1621 instruction at the position specified by the instruction builder [b].
1622 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *)
1623 external build_aggregate_ret : llvalue array -> llbuilder -> llvalue
1624 = "llvm_build_aggregate_ret"
1626 (** [build_br bb b] creates a
1628 instruction at the position specified by the instruction builder [b].
1629 See the method [llvm::LLVMBuilder::CreateBr]. *)
1630 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1632 (** [build_cond_br cond tbb fbb b] creates a
1633 [br %cond, %tbb, %fbb]
1634 instruction at the position specified by the instruction builder [b].
1635 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1636 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1637 llvalue = "llvm_build_cond_br"
1639 (** [build_switch case elsebb count b] creates an empty
1640 [switch %case, %elsebb]
1641 instruction at the position specified by the instruction builder [b] with
1642 space reserved for [count] cases.
1643 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1644 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1645 = "llvm_build_switch"
1647 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1648 when its input matches the constant [onval].
1649 See the method [llvm::SwitchInst::addCase]. **)
1650 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1653 (** [build_indirect_br addr count b] creates a
1655 instruction at the position specified by the instruction builder [b] with
1656 space reserved for [count] destinations.
1657 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *)
1658 external build_indirect_br : llvalue -> int -> llbuilder -> llvalue
1659 = "llvm_build_indirect_br"
1661 (** [add_destination br bb] adds the basic block [bb] as a possible branch
1662 location for the indirectbr instruction [br].
1663 See the method [llvm::IndirectBrInst::addDestination]. **)
1664 external add_destination : llvalue -> llbasicblock -> unit
1665 = "llvm_add_destination"
1667 (** [build_invoke fn args tobb unwindbb name b] creates an
1668 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1669 instruction at the position specified by the instruction builder [b].
1670 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1671 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1672 llbasicblock -> string -> llbuilder -> llvalue
1673 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1675 (** [build_unwind b] creates an
1677 instruction at the position specified by the instruction builder [b].
1678 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1679 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1681 (** [build_unreachable b] creates an
1683 instruction at the position specified by the instruction builder [b].
1684 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1685 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1688 (** {7 Arithmetic} *)
1690 (** [build_add x y name b] creates a
1691 [%name = add %x, %y]
1692 instruction at the position specified by the instruction builder [b].
1693 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1694 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1697 (** [build_nsw_add x y name b] creates a
1698 [%name = nsw add %x, %y]
1699 instruction at the position specified by the instruction builder [b].
1700 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *)
1701 external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1702 = "llvm_build_nsw_add"
1704 (** [build_nuw_add x y name b] creates a
1705 [%name = nuw add %x, %y]
1706 instruction at the position specified by the instruction builder [b].
1707 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *)
1708 external build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1709 = "llvm_build_nuw_add"
1711 (** [build_fadd x y name b] creates a
1712 [%name = fadd %x, %y]
1713 instruction at the position specified by the instruction builder [b].
1714 See the method [llvm::LLVMBuilder::CreateFAdd]. *)
1715 external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue
1718 (** [build_sub x y name b] creates a
1719 [%name = sub %x, %y]
1720 instruction at the position specified by the instruction builder [b].
1721 See the method [llvm::LLVMBuilder::CreateSub]. *)
1722 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1725 (** [build_nsw_sub x y name b] creates a
1726 [%name = nsw sub %x, %y]
1727 instruction at the position specified by the instruction builder [b].
1728 See the method [llvm::LLVMBuilder::CreateNSWSub]. *)
1729 external build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1730 = "llvm_build_nsw_sub"
1732 (** [build_nuw_sub x y name b] creates a
1733 [%name = nuw sub %x, %y]
1734 instruction at the position specified by the instruction builder [b].
1735 See the method [llvm::LLVMBuilder::CreateNUWSub]. *)
1736 external build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1737 = "llvm_build_nuw_sub"
1739 (** [build_fsub x y name b] creates a
1740 [%name = fsub %x, %y]
1741 instruction at the position specified by the instruction builder [b].
1742 See the method [llvm::LLVMBuilder::CreateFSub]. *)
1743 external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1746 (** [build_mul x y name b] creates a
1747 [%name = mul %x, %y]
1748 instruction at the position specified by the instruction builder [b].
1749 See the method [llvm::LLVMBuilder::CreateMul]. *)
1750 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1753 (** [build_nsw_mul x y name b] creates a
1754 [%name = nsw mul %x, %y]
1755 instruction at the position specified by the instruction builder [b].
1756 See the method [llvm::LLVMBuilder::CreateNSWMul]. *)
1757 external build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1758 = "llvm_build_nsw_mul"
1760 (** [build_nuw_mul x y name b] creates a
1761 [%name = nuw mul %x, %y]
1762 instruction at the position specified by the instruction builder [b].
1763 See the method [llvm::LLVMBuilder::CreateNUWMul]. *)
1764 external build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1765 = "llvm_build_nuw_mul"
1767 (** [build_fmul x y name b] creates a
1768 [%name = fmul %x, %y]
1769 instruction at the position specified by the instruction builder [b].
1770 See the method [llvm::LLVMBuilder::CreateFMul]. *)
1771 external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1774 (** [build_udiv x y name b] creates a
1775 [%name = udiv %x, %y]
1776 instruction at the position specified by the instruction builder [b].
1777 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1778 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1781 (** [build_sdiv x y name b] creates a
1782 [%name = sdiv %x, %y]
1783 instruction at the position specified by the instruction builder [b].
1784 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1785 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1788 (** [build_exact_sdiv x y name b] creates a
1789 [%name = exact sdiv %x, %y]
1790 instruction at the position specified by the instruction builder [b].
1791 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *)
1792 external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1793 = "llvm_build_exact_sdiv"
1795 (** [build_fdiv x y name b] creates a
1796 [%name = fdiv %x, %y]
1797 instruction at the position specified by the instruction builder [b].
1798 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1799 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1802 (** [build_urem x y name b] creates a
1803 [%name = urem %x, %y]
1804 instruction at the position specified by the instruction builder [b].
1805 See the method [llvm::LLVMBuilder::CreateURem]. *)
1806 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1809 (** [build_SRem x y name b] creates a
1810 [%name = srem %x, %y]
1811 instruction at the position specified by the instruction builder [b].
1812 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1813 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1816 (** [build_frem x y name b] creates a
1817 [%name = frem %x, %y]
1818 instruction at the position specified by the instruction builder [b].
1819 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1820 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1823 (** [build_shl x y name b] creates a
1824 [%name = shl %x, %y]
1825 instruction at the position specified by the instruction builder [b].
1826 See the method [llvm::LLVMBuilder::CreateShl]. *)
1827 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1830 (** [build_lshr x y name b] creates a
1831 [%name = lshr %x, %y]
1832 instruction at the position specified by the instruction builder [b].
1833 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1834 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1837 (** [build_ashr x y name b] creates a
1838 [%name = ashr %x, %y]
1839 instruction at the position specified by the instruction builder [b].
1840 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1841 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1844 (** [build_and x y name b] creates a
1845 [%name = and %x, %y]
1846 instruction at the position specified by the instruction builder [b].
1847 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1848 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1851 (** [build_or x y name b] creates a
1853 instruction at the position specified by the instruction builder [b].
1854 See the method [llvm::LLVMBuilder::CreateOr]. *)
1855 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1858 (** [build_xor x y name b] creates a
1859 [%name = xor %x, %y]
1860 instruction at the position specified by the instruction builder [b].
1861 See the method [llvm::LLVMBuilder::CreateXor]. *)
1862 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1865 (** [build_neg x name b] creates a
1867 instruction at the position specified by the instruction builder [b].
1868 [-0.0] is used for floating point types to compute the correct sign.
1869 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1870 external build_neg : llvalue -> string -> llbuilder -> llvalue
1873 (** [build_nsw_neg x name b] creates a
1874 [%name = nsw sub 0, %x]
1875 instruction at the position specified by the instruction builder [b].
1876 [-0.0] is used for floating point types to compute the correct sign.
1877 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1878 external build_nsw_neg : llvalue -> string -> llbuilder -> llvalue
1879 = "llvm_build_nsw_neg"
1881 (** [build_nuw_neg x name b] creates a
1882 [%name = nuw sub 0, %x]
1883 instruction at the position specified by the instruction builder [b].
1884 [-0.0] is used for floating point types to compute the correct sign.
1885 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1886 external build_nuw_neg : llvalue -> string -> llbuilder -> llvalue
1887 = "llvm_build_nuw_neg"
1889 (** [build_fneg x name b] creates a
1890 [%name = fsub 0, %x]
1891 instruction at the position specified by the instruction builder [b].
1892 [-0.0] is used for floating point types to compute the correct sign.
1893 See the method [llvm::LLVMBuilder::CreateFNeg]. *)
1894 external build_fneg : llvalue -> string -> llbuilder -> llvalue
1897 (** [build_xor x name b] creates a
1898 [%name = xor %x, -1]
1899 instruction at the position specified by the instruction builder [b].
1900 [-1] is the correct "all ones" value for the type of [x].
1901 See the method [llvm::LLVMBuilder::CreateXor]. *)
1902 external build_not : llvalue -> string -> llbuilder -> llvalue
1908 (** [build_alloca ty name b] creates a
1909 [%name = alloca %ty]
1910 instruction at the position specified by the instruction builder [b].
1911 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1912 external build_alloca : lltype -> string -> llbuilder -> llvalue
1913 = "llvm_build_alloca"
1915 (** [build_array_alloca ty n name b] creates a
1916 [%name = alloca %ty, %n]
1917 instruction at the position specified by the instruction builder [b].
1918 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1919 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1920 llvalue = "llvm_build_array_alloca"
1922 (** [build_load v name b] creates a
1924 instruction at the position specified by the instruction builder [b].
1925 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1926 external build_load : llvalue -> string -> llbuilder -> llvalue
1929 (** [build_store v p b] creates a
1931 instruction at the position specified by the instruction builder [b].
1932 See the method [llvm::LLVMBuilder::CreateStore]. *)
1933 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1934 = "llvm_build_store"
1936 (** [build_gep p indices name b] creates a
1937 [%name = getelementptr %p, indices...]
1938 instruction at the position specified by the instruction builder [b].
1939 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1940 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1943 (** [build_in_bounds_gep p indices name b] creates a
1944 [%name = gelementptr inbounds %p, indices...]
1945 instruction at the position specified by the instruction builder [b].
1946 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
1947 external build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
1948 llvalue = "llvm_build_in_bounds_gep"
1950 (** [build_struct_gep p idx name b] creates a
1951 [%name = getelementptr %p, 0, idx]
1952 instruction at the position specified by the instruction builder [b].
1953 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
1954 external build_struct_gep : llvalue -> int -> string -> llbuilder ->
1955 llvalue = "llvm_build_struct_gep"
1957 (** [build_global_string str name b] creates a series of instructions that adds
1958 a global string at the position specified by the instruction builder [b].
1959 See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
1960 external build_global_string : string -> string -> llbuilder -> llvalue
1961 = "llvm_build_global_string"
1963 (** [build_global_stringptr str name b] creates a series of instructions that
1964 adds a global string pointer at the position specified by the instruction
1966 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *)
1967 external build_global_stringptr : string -> string -> llbuilder -> llvalue
1968 = "llvm_build_global_stringptr"
1973 (** [build_trunc v ty name b] creates a
1974 [%name = trunc %p to %ty]
1975 instruction at the position specified by the instruction builder [b].
1976 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1977 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1978 = "llvm_build_trunc"
1980 (** [build_zext v ty name b] creates a
1981 [%name = zext %p to %ty]
1982 instruction at the position specified by the instruction builder [b].
1983 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1984 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1987 (** [build_sext v ty name b] creates a
1988 [%name = sext %p to %ty]
1989 instruction at the position specified by the instruction builder [b].
1990 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1991 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1994 (** [build_fptoui v ty name b] creates a
1995 [%name = fptoui %p to %ty]
1996 instruction at the position specified by the instruction builder [b].
1997 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1998 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1999 = "llvm_build_fptoui"
2001 (** [build_fptosi v ty name b] creates a
2002 [%name = fptosi %p to %ty]
2003 instruction at the position specified by the instruction builder [b].
2004 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
2005 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
2006 = "llvm_build_fptosi"
2008 (** [build_uitofp v ty name b] creates a
2009 [%name = uitofp %p to %ty]
2010 instruction at the position specified by the instruction builder [b].
2011 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
2012 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2013 = "llvm_build_uitofp"
2015 (** [build_sitofp v ty name b] creates a
2016 [%name = sitofp %p to %ty]
2017 instruction at the position specified by the instruction builder [b].
2018 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
2019 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
2020 = "llvm_build_sitofp"
2022 (** [build_fptrunc v ty name b] creates a
2023 [%name = fptrunc %p to %ty]
2024 instruction at the position specified by the instruction builder [b].
2025 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
2026 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
2027 = "llvm_build_fptrunc"
2029 (** [build_fpext v ty name b] creates a
2030 [%name = fpext %p to %ty]
2031 instruction at the position specified by the instruction builder [b].
2032 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
2033 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
2034 = "llvm_build_fpext"
2036 (** [build_ptrtoint v ty name b] creates a
2037 [%name = prtotint %p to %ty]
2038 instruction at the position specified by the instruction builder [b].
2039 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
2040 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
2041 = "llvm_build_prttoint"
2043 (** [build_inttoptr v ty name b] creates a
2044 [%name = inttoptr %p to %ty]
2045 instruction at the position specified by the instruction builder [b].
2046 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
2047 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
2048 = "llvm_build_inttoptr"
2050 (** [build_bitcast v ty name b] creates a
2051 [%name = bitcast %p to %ty]
2052 instruction at the position specified by the instruction builder [b].
2053 See the method [llvm::LLVMBuilder::CreateBitCast]. *)
2054 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2055 = "llvm_build_bitcast"
2057 (** [build_zext_or_bitcast v ty name b] creates a zext or bitcast
2058 instruction at the position specified by the instruction builder [b].
2059 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2060 external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2061 llvalue = "llvm_build_zext_or_bitcast"
2063 (** [build_sext_or_bitcast v ty name b] creates a sext or bitcast
2064 instruction at the position specified by the instruction builder [b].
2065 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *)
2066 external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2067 llvalue = "llvm_build_sext_or_bitcast"
2069 (** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast
2070 instruction at the position specified by the instruction builder [b].
2071 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *)
2072 external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder ->
2073 llvalue = "llvm_build_trunc_or_bitcast"
2075 (** [build_pointercast v ty name b] creates a bitcast or pointer-to-int
2076 instruction at the position specified by the instruction builder [b].
2077 See the method [llvm::LLVMBuilder::CreatePointerCast]. *)
2078 external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue
2079 = "llvm_build_pointercast"
2081 (** [build_intcast v ty name b] creates a zext, bitcast, or trunc
2082 instruction at the position specified by the instruction builder [b].
2083 See the method [llvm::LLVMBuilder::CreateIntCast]. *)
2084 external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2085 = "llvm_build_intcast"
2087 (** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc
2088 instruction at the position specified by the instruction builder [b].
2089 See the method [llvm::LLVMBuilder::CreateFPCast]. *)
2090 external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue
2091 = "llvm_build_fpcast"
2094 (** {7 Comparisons} *)
2096 (** [build_icmp pred x y name b] creates a
2097 [%name = icmp %pred %x, %y]
2098 instruction at the position specified by the instruction builder [b].
2099 See the method [llvm::LLVMBuilder::CreateICmp]. *)
2100 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
2101 llbuilder -> llvalue = "llvm_build_icmp"
2103 (** [build_fcmp pred x y name b] creates a
2104 [%name = fcmp %pred %x, %y]
2105 instruction at the position specified by the instruction builder [b].
2106 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
2107 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
2108 llbuilder -> llvalue = "llvm_build_fcmp"
2111 (** {7 Miscellaneous instructions} *)
2113 (** [build_phi incoming name b] creates a
2114 [%name = phi %incoming]
2115 instruction at the position specified by the instruction builder [b].
2116 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
2117 See the method [llvm::LLVMBuilder::CreatePHI]. *)
2118 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
2119 llvalue = "llvm_build_phi"
2121 (** [build_call fn args name b] creates a
2122 [%name = call %fn(args...)]
2123 instruction at the position specified by the instruction builder [b].
2124 See the method [llvm::LLVMBuilder::CreateCall]. *)
2125 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
2128 (** [build_select cond thenv elsev name b] creates a
2129 [%name = select %cond, %thenv, %elsev]
2130 instruction at the position specified by the instruction builder [b].
2131 See the method [llvm::LLVMBuilder::CreateSelect]. *)
2132 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
2133 llvalue = "llvm_build_select"
2135 (** [build_va_arg valist argty name b] creates a
2136 [%name = va_arg %valist, %argty]
2137 instruction at the position specified by the instruction builder [b].
2138 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
2139 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
2140 = "llvm_build_va_arg"
2142 (** [build_extractelement vec i name b] creates a
2143 [%name = extractelement %vec, %i]
2144 instruction at the position specified by the instruction builder [b].
2145 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
2146 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
2147 llvalue = "llvm_build_extractelement"
2149 (** [build_insertelement vec elt i name b] creates a
2150 [%name = insertelement %vec, %elt, %i]
2151 instruction at the position specified by the instruction builder [b].
2152 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
2153 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
2154 llbuilder -> llvalue = "llvm_build_insertelement"
2156 (** [build_shufflevector veca vecb mask name b] creates a
2157 [%name = shufflevector %veca, %vecb, %mask]
2158 instruction at the position specified by the instruction builder [b].
2159 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
2160 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
2161 llbuilder -> llvalue = "llvm_build_shufflevector"
2163 (** [build_insertvalue agg idx name b] creates a
2164 [%name = extractvalue %agg, %idx]
2165 instruction at the position specified by the instruction builder [b].
2166 See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
2167 external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
2168 = "llvm_build_extractvalue"
2170 (** [build_insertvalue agg val idx name b] creates a
2171 [%name = insertvalue %agg, %val, %idx]
2172 instruction at the position specified by the instruction builder [b].
2173 See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
2174 external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
2175 llvalue = "llvm_build_insertvalue"
2177 (** [build_is_null val name b] creates a
2178 [%name = icmp eq %val, null]
2179 instruction at the position specified by the instruction builder [b].
2180 See the method [llvm::LLVMBuilder::CreateIsNull]. *)
2181 external build_is_null : llvalue -> string -> llbuilder -> llvalue
2182 = "llvm_build_is_null"
2184 (** [build_is_not_null val name b] creates a
2185 [%name = icmp ne %val, null]
2186 instruction at the position specified by the instruction builder [b].
2187 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
2188 external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
2189 = "llvm_build_is_not_null"
2191 (** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
2192 the difference between two pointer values at the position specified by the
2193 instruction builder [b].
2194 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
2195 external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
2196 = "llvm_build_ptrdiff"
2199 (** {6 Memory buffers} *)
2201 module MemoryBuffer : sig
2202 (** [of_file p] is the memory buffer containing the contents of the file at
2203 path [p]. If the file could not be read, then [IoError msg] is
2205 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
2207 (** [stdin ()] is the memory buffer containing the contents of standard input.
2208 If standard input is empty, then [IoError msg] is raised. *)
2209 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
2211 (** Disposes of a memory buffer. *)
2212 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
2216 (** {6 Pass Managers} *)
2218 module PassManager : sig
2221 type any = [ `Module | `Function ]
2223 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
2224 type of pipeline is suitable for link-time optimization and whole-module
2226 See the constructor of [llvm::PassManager]. *)
2227 external create : unit -> [ `Module ] t = "llvm_passmanager_create"
2229 (** [PassManager.create_function m] constructs a new function-by-function
2230 pass pipeline over the module [m]. It does not take ownership of [m].
2231 This type of pipeline is suitable for code generation and JIT compilation
2233 See the constructor of [llvm::FunctionPassManager]. *)
2234 external create_function : llmodule -> [ `Function ] t
2235 = "LLVMCreateFunctionPassManager"
2237 (** [run_module m pm] initializes, executes on the module [m], and finalizes
2238 all of the passes scheduled in the pass manager [pm]. Returns [true] if
2239 any of the passes modified the module, [false] otherwise.
2240 See the [llvm::PassManager::run] method. *)
2241 external run_module : llmodule -> [ `Module ] t -> bool
2242 = "llvm_passmanager_run_module"
2244 (** [initialize fpm] initializes all of the function passes scheduled in the
2245 function pass manager [fpm]. Returns [true] if any of the passes modified
2246 the module, [false] otherwise.
2247 See the [llvm::FunctionPassManager::doInitialization] method. *)
2248 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
2250 (** [run_function f fpm] executes all of the function passes scheduled in the
2251 function pass manager [fpm] over the function [f]. Returns [true] if any
2252 of the passes modified [f], [false] otherwise.
2253 See the [llvm::FunctionPassManager::run] method. *)
2254 external run_function : llvalue -> [ `Function ] t -> bool
2255 = "llvm_passmanager_run_function"
2257 (** [finalize fpm] finalizes all of the function passes scheduled in in the
2258 function pass manager [fpm]. Returns [true] if any of the passes
2259 modified the module, [false] otherwise.
2260 See the [llvm::FunctionPassManager::doFinalization] method. *)
2261 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
2263 (** Frees the memory of a pass pipeline. For function pipelines, does not free
2265 See the destructor of [llvm::BasePassManager]. *)
2266 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"