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 other LLVM Intermediate Representation (IR)
21 objects. See the [llvm::Module] class. *)
24 (** Each value in the LLVM IR has a type, an instance of [lltype]. See the
25 [llvm::Type] class. *)
28 (** When building recursive types using {!refine_type}, [lltype] values may
29 become invalid; use [lltypehandle] to resolve this problem. See the
30 [llvm::AbstractTypeHolder] class. *)
33 (** Any value in the LLVM IR. Functions, instructions, global variables,
34 constants, and much more are all [llvalues]. See the [llvm::Value] class.
35 This type covers a wide range of subclasses. *)
38 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *)
41 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
45 (** Used to provide a module to JIT or interpreter.
46 See the [llvm::ModuleProvider] class. *)
49 (** Used to efficiently handle large buffers of read-only binary data.
50 See the [llvm::MemoryBuffer] class. *)
53 (** The kind of an [lltype], the result of [classify_type ty]. See the
54 [llvm::Type::TypeID] enumeration. *)
73 (** The linkage of a global value, accessed with {!linkage} and
74 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
88 (** The linker visibility of a global value, accessed with {!visibility} and
89 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
90 module Visibility : sig
97 (** The following calling convention values may be accessed with
98 {!function_call_conv} and {!set_function_call_conv}. Calling
99 conventions are open-ended. *)
100 module CallConv : sig
101 val c : int (** [c] is the C calling convention. *)
102 val fast : int (** [fast] is the calling convention to allow LLVM
103 maximum optimization opportunities. Use only with
105 val cold : int (** [cold] is the calling convention for
107 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling
108 convention from C. *)
109 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
110 convention from C. *)
113 (** The predicate for an integer comparison ([icmp]) instruction.
114 See the [llvm::ICmpInst::Predicate] enumeration. *)
129 (** The predicate for a floating-point comparison ([fcmp]) instruction.
130 See the [llvm::FCmpInst::Predicate] enumeration. *)
154 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
155 of [a]. [llpos] is used to specify positions in and for forward iteration
156 through the various value lists maintained by the LLVM IR. *)
157 type ('a, 'b) llpos =
161 (** [After b] and [At_start a] specify positions from the end of the ['b] list
162 of [a]. [llrev_pos] is used for reverse iteration through the various value
163 lists maintained by the LLVM IR. *)
164 type ('a, 'b) llrev_pos =
169 (** {6 Exceptions} *)
171 exception IoError of string
176 (** [create_module id] creates a module with the supplied module ID. Modules are
177 not garbage collected; it is mandatory to call {!dispose_module} to free
178 memory. See the constructor [llvm::Module::Module]. *)
179 external create_module : string -> llmodule = "llvm_create_module"
181 (** [dispose_module m] destroys a module [m] and all of the IR objects it
182 contained. All references to subordinate objects are invalidated;
183 referencing them will invoke undefined behavior. See the destructor
184 [llvm::Module::~Module]. *)
185 external dispose_module : llmodule -> unit = "llvm_dispose_module"
187 (** [target_triple m] is the target specifier for the module [m], something like
188 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
189 external target_triple: llmodule -> string
190 = "llvm_target_triple"
192 (** [target_triple triple m] changes the target specifier for the module [m] to
193 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
194 external set_target_triple: string -> llmodule -> unit
195 = "llvm_set_target_triple"
197 (** [data_layout m] is the data layout specifier for the module [m], something
198 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
199 method [llvm::Module::getDataLayout]. *)
200 external data_layout: llmodule -> string
203 (** [set_data_layout s m] changes the data layout specifier for the module [m]
204 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
205 external set_data_layout: string -> llmodule -> unit
206 = "llvm_set_data_layout"
208 (** [define_type_name name ty m] adds a named type to the module's symbol table.
209 Returns [true] if successful. If such a name already exists, then no entry
210 is added and [false] is returned. See the [llvm::Module::addTypeName]
212 external define_type_name : string -> lltype -> llmodule -> bool
213 = "llvm_add_type_name"
215 (** [delete_type_name name] removes a type name from the module's symbol
217 external delete_type_name : string -> llmodule -> unit
218 = "llvm_delete_type_name"
220 (** [dump_module m] prints the .ll representation of the module [m] to standard
221 error. See the method [llvm::Module::dump]. *)
222 external dump_module : llmodule -> unit = "llvm_dump_module"
227 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
228 See the method [llvm::Type::getTypeID]. *)
229 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
231 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
232 val string_of_lltype : lltype -> string
234 (** {7 Operations on integer types} *)
236 (** The 1-bit integer type. See [llvm::Type::Int1Ty]. *)
239 (** The 8-bit integer type. See [llvm::Type::Int8Ty]. *)
242 (** The 16-bit integer type. See [llvm::Type::Int16Ty]. *)
243 val i16_type : lltype
245 (** The 32-bit integer type. See [llvm::Type::Int32Ty]. *)
246 val i32_type : lltype
248 (** The 64-bit integer type. See [llvm::Type::Int64Ty]. *)
249 val i64_type : lltype
251 (** [integer_type n] returns an integer type of bitwidth [n].
252 See the method [llvm::IntegerType::get]. *)
253 external integer_type : int -> lltype = "llvm_integer_type"
255 (** [integer_bitwidth ty] returns the number of bits in the integer type [ty].
256 See the method [llvm::IntegerType::getBitWidth]. *)
257 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
260 (** {7 Operations on real types} *)
262 (** The IEEE 32-bit floating point type. See [llvm::Type::FloatTy]. *)
263 val float_type : lltype
265 (** The IEEE 64-bit floating point type. See [llvm::Type::DoubleTy]. *)
266 val double_type : lltype
268 (** The x87 80-bit floating point type. See [llvm::Type::X86_FP80Ty]. *)
269 val x86fp80_type : lltype
271 (** The IEEE 128-bit floating point type. See [llvm::Type::FP128Ty]. *)
272 val fp128_type : lltype
274 (** The PowerPC 128-bit floating point type. See [llvm::Type::PPC_FP128Ty]. *)
275 val ppc_fp128_type : lltype
278 (** {7 Operations on function types} *)
280 (** [function_type ret_ty param_tys] returns the function type returning
281 [ret_ty] and taking [param_tys] as parameters.
282 See the method [llvm::FunctionType::get]. *)
283 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
285 (** [va_arg_function_type ret_ty param_tys] is just like
286 [function_type ret_ty param_tys] except that it returns the function type
287 which also takes a variable number of arguments.
288 See the method [llvm::FunctionType::get]. *)
289 external var_arg_function_type : lltype -> lltype array -> lltype
290 = "llvm_var_arg_function_type"
292 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
293 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
294 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
296 (** [return_type fty] gets the return type of the function type [fty].
297 See the method [llvm::FunctionType::getReturnType]. *)
298 external return_type : lltype -> lltype = "LLVMGetReturnType"
300 (** [param_types fty] gets the parameter types of the function type [fty].
301 See the method [llvm::FunctionType::getParamType]. *)
302 external param_types : lltype -> lltype array = "llvm_param_types"
305 (** {7 Operations on struct types} *)
307 (** [struct_type tys] returns the structure type containing in the types in the
308 array [tys]. See the method [llvm::StructType::get]. *)
309 external struct_type : lltype array -> lltype = "llvm_struct_type"
311 (** [struct_type tys] returns the packed structure type containing in the types
312 in the array [tys]. See the method [llvm::StructType::get]. *)
313 external packed_struct_type : lltype array -> lltype = "llvm_packed_struct_type"
315 (** [element_types sty] returns the constituent types of the struct type [sty].
316 See the method [llvm::StructType::getElementType]. *)
317 external element_types : lltype -> lltype array = "llvm_element_types"
319 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
320 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
321 external is_packed : lltype -> bool = "llvm_is_packed"
324 (** {7 Operations on pointer, vector, and array types} *)
326 (** [array_type ty n] returns the array type containing [n] elements of type
327 [ty]. See the method [llvm::ArrayType::get]. *)
328 external array_type : lltype -> int -> lltype = "llvm_array_type"
330 (** [pointer_type ty] returns the pointer type referencing objects of type
331 [ty] in the default address space (0).
332 See the method [llvm::PointerType::getUnqual]. *)
333 external pointer_type : lltype -> lltype = "llvm_pointer_type"
335 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
336 of type [ty] in address space [as].
337 See the method [llvm::PointerType::get]. *)
338 external qualified_pointer_type : lltype -> int -> lltype
339 = "llvm_qualified_pointer_type"
341 (** [vector_type ty n] returns the array type containing [n] elements of the
342 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
343 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
345 (** [element_type ty] returns the element type of the pointer, vector, or array
346 type [ty]. See the method [llvm::SequentialType::get]. *)
347 external element_type : lltype -> lltype = "LLVMGetElementType"
349 (** [element_type aty] returns the element count of the array type [aty].
350 See the method [llvm::ArrayType::getNumElements]. *)
351 external array_length : lltype -> int = "llvm_array_length"
353 (** [address_space pty] returns the address space qualifier of the pointer type
354 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
355 external address_space : lltype -> int = "llvm_address_space"
357 (** [element_type ty] returns the element count of the vector type [ty].
358 See the method [llvm::VectorType::getNumElements]. *)
359 external vector_size : lltype -> int = "llvm_vector_size"
362 (** {7 Operations on other types} *)
364 (** [opaque_type ()] creates a new opaque type distinct from any other.
365 Opaque types are useful for building recursive types in combination with
367 See [llvm::OpaqueType::get]. *)
368 external opaque_type : unit -> lltype = "llvm_opaque_type"
370 (** [void_type] is the type of a function which does not return any value.
371 See [llvm::Type::VoidTy]. *)
372 val void_type : lltype
374 (** [label_type] is the type of a basic block. See [llvm::Type::LabelTy]. *)
375 val label_type : lltype
377 (** {7 Operations on type handles} *)
379 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
380 refined as a result of a call to {!refine_type}, the handle will be updated;
381 any bare [lltype] references will become invalid.
382 See the class [llvm::PATypeHolder]. *)
383 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
385 (** [type_of_handle tyh] resolves the type handle [tyh].
386 See the method [llvm::PATypeHolder::get()]. *)
387 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
389 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
390 concrete type [ty] in all users. Warning: This may invalidate {!lltype}
391 values! Use {!lltypehandle} to manipulate potentially abstract types. See
392 the method [llvm::Type::refineAbstractType]. *)
393 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
398 (** [type_of v] returns the type of the value [v].
399 See the method [llvm::Value::getType]. *)
400 external type_of : llvalue -> lltype = "llvm_type_of"
402 (** [value_name v] returns the name of the value [v]. For global values, this is
403 the symbol name. For instructions and basic blocks, it is the SSA register
404 name. It is meaningless for constants.
405 See the method [llvm::Value::getName]. *)
406 external value_name : llvalue -> string = "llvm_value_name"
408 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
409 [llvm::Value::setName]. *)
410 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
412 (** [dump_value v] prints the .ll representation of the value [v] to standard
413 error. See the method [llvm::Value::dump]. *)
414 external dump_value : llvalue -> unit = "llvm_dump_value"
417 (** {7 Operations on constants of (mostly) any type} *)
419 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
420 otherwise. Similar to [llvm::isa<Constant>]. *)
421 external is_constant : llvalue -> bool = "llvm_is_constant"
423 (** [const_null ty] returns the constant null (zero) of the type [ty].
424 See the method [llvm::Constant::getNullValue]. *)
425 external const_null : lltype -> llvalue = "LLVMConstNull"
427 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
428 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
429 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
431 (** [undef ty] returns the undefined value of the type [ty].
432 See the method [llvm::UndefValue::get]. *)
433 external undef : lltype -> llvalue = "LLVMGetUndef"
435 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
436 See the method [llvm::Constant::isNullValue]. *)
437 external is_null : llvalue -> bool = "llvm_is_null"
439 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
440 otherwise. Similar to [llvm::isa<UndefValue>]. *)
441 external is_undef : llvalue -> bool = "llvm_is_undef"
444 (** {7 Operations on scalar constants} *)
446 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
447 See the method [llvm::ConstantInt::get]. *)
448 external const_int : lltype -> int -> llvalue = "llvm_const_int"
450 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
451 [i]. See the method [llvm::ConstantInt::get]. *)
452 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
453 = "llvm_const_of_int64"
455 (** [const_float ty n] returns the floating point constant of type [ty] and
456 value [n]. See the method [llvm::ConstantInt::get]. *)
457 external const_float : lltype -> float -> llvalue = "llvm_const_float"
460 (** {7 Operations on composite constants} *)
462 (** [const_string s] returns the constant [i8] array with the values of the
463 characters in the string [s]. The array is not null-terminated (but see
464 {!const_stringz}). This value can in turn be used as the initializer for a
465 global variable. See the method [llvm::ConstantArray::get]. *)
466 external const_string : string -> llvalue = "llvm_const_string"
468 (** [const_stringz s] returns the constant [i8] array with the values of the
469 characters in the string [s] and a null terminator. This value can in turn
470 be used as the initializer for a global variable.
471 See the method [llvm::ConstantArray::get]. *)
472 external const_stringz : string -> llvalue = "llvm_const_stringz"
474 (** [const_array ty elts] returns the constant array of type
475 [array_type ty (Array.length elts)] and containing the values [elts].
476 This value can in turn be used as the initializer for a global variable.
477 See the method [llvm::ConstantArray::get]. *)
478 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
480 (** [const_struct elts] returns the structured constant of type
481 [struct_type (Array.map type_of elts)] and containing the values [elts].
482 This value can in turn be used as the initializer for a global variable.
483 See the method [llvm::ConstantStruct::get]. *)
484 external const_struct : llvalue array -> llvalue = "llvm_const_struct"
486 (** [const_packed_struct elts] returns the structured constant of type
487 {!packed_struct_type} [(Array.map type_of elts)] and containing the values
488 [elts]. This value can in turn be used as the initializer for a global
489 variable. See the method [llvm::ConstantStruct::get]. *)
490 external const_packed_struct : llvalue array -> llvalue
491 = "llvm_const_packed_struct"
493 (** [const_vector elts] returns the vector constant of type
494 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
495 values [elts]. See the method [llvm::ConstantVector::get]. *)
496 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
499 (** {7 Constant expressions} *)
501 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
502 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
503 (const_int i64_type 1)) i64_type], but considerably more readable.
504 See the method [llvm::ConstantExpr::getSizeOf]. *)
505 external size_of : lltype -> llvalue = "LLVMSizeOf"
507 (** [const_neg c] returns the arithmetic negation of the constant [c].
508 See the method [llvm::ConstantExpr::getNeg]. *)
509 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
511 (** [const_not c] returns the bitwise inverse of the constant [c].
512 See the method [llvm::ConstantExpr::getNot]. *)
513 external const_not : llvalue -> llvalue = "LLVMConstNot"
515 (** [const_add c1 c2] returns the constant sum of two constants.
516 See the method [llvm::ConstantExpr::getAdd]. *)
517 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
519 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
520 constants. See the method [llvm::ConstantExpr::getSub]. *)
521 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
523 (** [const_mul c1 c2] returns the constant product of two constants.
524 See the method [llvm::ConstantExpr::getMul]. *)
525 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
527 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
529 See the method [llvm::ConstantExpr::getUDiv]. *)
530 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
532 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
534 See the method [llvm::ConstantExpr::]. *)
535 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
537 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
539 See the method [llvm::ConstantExpr::getFDiv]. *)
540 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
542 (** [const_udiv c1 c2] returns the constant remainder [c1 MOD c2] of two
543 unsigned integer constants.
544 See the method [llvm::ConstantExpr::getURem]. *)
545 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
547 (** [const_sdiv c1 c2] returns the constant remainder [c1 MOD c2] of two
548 signed integer constants.
549 See the method [llvm::ConstantExpr::getSRem]. *)
550 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
552 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
553 signed floating point constants.
554 See the method [llvm::ConstantExpr::getFRem]. *)
555 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
557 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
559 See the method [llvm::ConstantExpr::getAnd]. *)
560 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
562 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
564 See the method [llvm::ConstantExpr::getOr]. *)
565 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
567 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
569 See the method [llvm::ConstantExpr::getXor]. *)
570 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
572 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
573 constants, [c1 pred c2].
574 See the method [llvm::ConstantExpr::getICmp]. *)
575 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
578 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
579 point constants, [c1 pred c2].
580 See the method [llvm::ConstantExpr::getFCmp]. *)
581 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
584 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
585 constant integer [c2].
586 See the method [llvm::ConstantExpr::getShl]. *)
587 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
589 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
590 constant integer [c2] with zero extension.
591 See the method [llvm::ConstantExpr::getLShr]. *)
592 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
594 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
595 constant integer [c2] with sign extension.
596 See the method [llvm::ConstantExpr::getAShr]. *)
597 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
599 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
600 constant integers indices from the array [indices].
601 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
602 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
604 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
605 to the smaller integer type [ty].
606 See the method [llvm::ConstantExpr::getTrunc]. *)
607 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
609 (** [const_sext c ty] returns the constant sign extension of integer constant
610 [c] to the larger integer type [ty].
611 See the method [llvm::ConstantExpr::getSExt]. *)
612 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
614 (** [const_zext c ty] returns the constant zero extension of integer constant
615 [c] to the larger integer type [ty].
616 See the method [llvm::ConstantExpr::getZExt]. *)
617 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
619 (** [const_fptrunc c ty] returns the constant truncation of floating point
620 constant [c] to the smaller floating point type [ty].
621 See the method [llvm::ConstantExpr::getFPTrunc]. *)
622 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
624 (** [const_fpext c ty] returns the constant extension of floating point constant
625 [c] to the larger floating point type [ty].
626 See the method [llvm::ConstantExpr::getFPExt]. *)
627 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
629 (** [const_uitofp c ty] returns the constant floating point conversion of
630 unsigned integer constant [c] to the floating point type [ty].
631 See the method [llvm::ConstantExpr::getUIToFP]. *)
632 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
634 (** [const_sitofp c ty] returns the constant floating point conversion of
635 signed integer constant [c] to the floating point type [ty].
636 See the method [llvm::ConstantExpr::getSIToFP]. *)
637 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
639 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
640 floating point constant [c] to integer type [ty].
641 See the method [llvm::ConstantExpr::getFPToUI]. *)
642 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
644 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
645 floating point constant [c] to integer type [ty].
646 See the method [llvm::ConstantExpr::getFPToSI]. *)
647 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
649 (** [const_ptrtoint c ty] returns the constant integer conversion of
650 pointer constant [c] to integer type [ty].
651 See the method [llvm::ConstantExpr::getPtrToInt]. *)
652 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
654 (** [const_inttoptr c ty] returns the constant pointer conversion of
655 integer constant [c] to pointer type [ty].
656 See the method [llvm::ConstantExpr::getIntToPtr]. *)
657 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
659 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
660 to type [ty] of equal size.
661 See the method [llvm::ConstantExpr::getBitCast]. *)
662 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
664 (** [const_select cond t f] returns the constant conditional which returns value
665 [t] if the boolean constant [cond] is true and the value [f] otherwise.
666 See the method [llvm::ConstantExpr::getSelect]. *)
667 external const_select : llvalue -> llvalue -> llvalue -> llvalue
670 (** [const_extractelement vec i] returns the constant [i]th element of
671 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
672 the size of the vector.
673 See the method [llvm::ConstantExpr::getExtractElement]. *)
674 external const_extractelement : llvalue -> llvalue -> llvalue
675 = "LLVMConstExtractElement"
677 (** [const_insertelement vec v i] returns the constant vector with the same
678 elements as constant vector [v] but the [i]th element replaced by the
679 constant [v]. [v] must be a constant value with the type of the vector
680 elements. [i] must be a constant [i32] value unsigned less than the size
682 See the method [llvm::ConstantExpr::getInsertElement]. *)
683 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
684 = "LLVMConstInsertElement"
686 (** [const_shufflevector a b mask] returns a constant [shufflevector].
687 See the LLVM Language Reference for details on the [sufflevector]
689 See the method [llvm::ConstantExpr::getShuffleVector]. *)
690 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
691 = "LLVMConstShuffleVector"
694 (** {7 Operations on global variables, functions, and aliases (globals)} *)
696 (** [global_parent g] is the enclosing module of the global value [g].
697 See the method [llvm::GlobalValue::getParent]. *)
698 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
700 (** [is_declaration g] returns [true] if the global value [g] is a declaration
701 only. Returns [false] otherwise.
702 See the method [llvm::GlobalValue::isDeclaration]. *)
703 external is_declaration : llvalue -> bool = "llvm_is_declaration"
705 (** [linkage g] returns the linkage of the global value [g].
706 See the method [llvm::GlobalValue::getLinkage]. *)
707 external linkage : llvalue -> Linkage.t = "llvm_linkage"
709 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
710 See the method [llvm::GlobalValue::setLinkage]. *)
711 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
713 (** [section g] returns the linker section of the global value [g].
714 See the method [llvm::GlobalValue::getSection]. *)
715 external section : llvalue -> string = "llvm_section"
717 (** [set_section s g] sets the linker section of the global value [g] to [s].
718 See the method [llvm::GlobalValue::setSection]. *)
719 external set_section : string -> llvalue -> unit = "llvm_set_section"
721 (** [visibility g] returns the linker visibility of the global value [g].
722 See the method [llvm::GlobalValue::getVisibility]. *)
723 external visibility : llvalue -> Visibility.t = "llvm_visibility"
725 (** [set_visibility v g] sets the linker visibility of the global value [g] to
726 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
727 external set_visibility : Visibility.t -> llvalue -> unit
728 = "llvm_set_visibility"
730 (** [alignment g] returns the required alignment of the global value [g].
731 See the method [llvm::GlobalValue::getAlignment]. *)
732 external alignment : llvalue -> int = "llvm_alignment"
734 (** [set_alignment n g] sets the required alignment of the global value [g] to
735 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
736 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
739 (** {7 Operations on global variables} *)
741 (** [declare_global ty name m] returns a new global variable of type [ty] and
742 with name [name] in module [m]. If such a global variable already exists,
743 it is returned. If the type of the existing global differs, then a bitcast
744 to [ty] is returned. *)
745 external declare_global : lltype -> string -> llmodule -> llvalue
746 = "llvm_declare_global"
748 (** [define_global name init m] returns a new global with name [name] and
749 initializer [init] in module [m]. If the named global already exists, it is
751 See the constructor of [llvm::GlobalVariable]. *)
752 external define_global : string -> llvalue -> llmodule -> llvalue
753 = "llvm_define_global"
755 (** [lookup_global name m] returns [Some g] if a global variable with name
756 [name] exists in module [m]. If no such global exists, returns [None].
757 See the [llvm::GlobalVariable] constructor. *)
758 external lookup_global : string -> llmodule -> llvalue option
759 = "llvm_lookup_global"
761 (** [delete_global gv] destroys the global variable [gv].
762 See the method [llvm::GlobalVariable::eraseFromParent]. *)
763 external delete_global : llvalue -> unit = "llvm_delete_global"
765 (** [global_begin m] returns the first position in the global variable list of
766 the module [m]. [global_begin] and [global_succ] can be used to iterate
767 over the global list in order.
768 See the method [llvm::Module::global_begin]. *)
769 external global_begin : llmodule -> (llmodule, llvalue) llpos
770 = "llvm_global_begin"
772 (** [global_succ gv] returns the global variable list position succeeding
774 See the method [llvm::Module::global_iterator::operator++]. *)
775 external global_succ : llvalue -> (llmodule, llvalue) llpos
778 (** [iter_globals f m] applies function [f] to each of the global variables of
779 module [m] in order. Tail recursive. *)
780 val iter_globals : (llvalue -> unit) -> llmodule -> unit
782 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
783 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
784 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
786 (** [global_end m] returns the last position in the global variable list of the
787 module [m]. [global_end] and [global_pred] can be used to iterate over the
788 global list in reverse.
789 See the method [llvm::Module::global_end]. *)
790 external global_end : llmodule -> (llmodule, llvalue) llrev_pos
793 (** [global_pred gv] returns the global variable list position preceding
795 See the method [llvm::Module::global_iterator::operator--]. *)
796 external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
799 (** [rev_iter_globals f m] applies function [f] to each of the global variables
800 of module [m] in reverse order. Tail recursive. *)
801 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
803 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
804 [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
805 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
807 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
808 constant. Returns [false] otherwise.
809 See the method [llvm::GlobalVariable::isConstant]. *)
810 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
812 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
813 [c] is [true] and not if [c] is [false].
814 See the method [llvm::GlobalVariable::setConstant]. *)
815 external set_global_constant : bool -> llvalue -> unit
816 = "llvm_set_global_constant"
818 (** [has_initializer gv] returns [true] if the global variable [gv] has an
819 initializer and [false] otherwise.
820 See the method [llvm::GlobalVariable::hasInitializer]. *)
821 external has_initializer : llvalue -> bool = "llvm_has_initializer"
823 (** [global_initializer gv] returns the initializer for the global variable
824 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
825 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
827 (** [set_initializer c gv] sets the initializer for the global variable
828 [gv] to the constant [c].
829 See the method [llvm::GlobalVariable::setInitializer]. *)
830 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
832 (** [remove_initializer gv] unsets the initializer for the global variable
834 See the method [llvm::GlobalVariable::setInitializer]. *)
835 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
837 (** [is_thread_local gv] returns [true] if the global variable [gv] is
838 thread-local and [false] otherwise.
839 See the method [llvm::GlobalVariable::isThreadLocal]. *)
840 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
842 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
843 [c] is [true] and not otherwise.
844 See the method [llvm::GlobalVariable::setThreadLocal]. *)
845 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
848 (** {7 Operations on functions} *)
850 (** [declare_function name ty m] returns a new function of type [ty] and
851 with name [name] in module [m]. If such a function already exists,
852 it is returned. If the type of the existing function differs, then a bitcast
853 to [ty] is returned. *)
854 external declare_function : string -> lltype -> llmodule -> llvalue
855 = "llvm_declare_function"
857 (** [define_function name ty m] creates a new function with name [name] and
858 type [ty] in module [m]. If the named function already exists, it is
859 renamed. An entry basic block is created in the function.
860 See the constructor of [llvm::GlobalVariable]. *)
861 external define_function : string -> lltype -> llmodule -> llvalue
862 = "llvm_define_function"
864 (** [lookup_function name m] returns [Some f] if a function with name
865 [name] exists in module [m]. If no such function exists, returns [None].
866 See the method [llvm::Module] constructor. *)
867 external lookup_function : string -> llmodule -> llvalue option
868 = "llvm_lookup_function"
870 (** [delete_function f] destroys the function [f].
871 See the method [llvm::Function::eraseFromParent]. *)
872 external delete_function : llvalue -> unit = "llvm_delete_function"
874 (** [function_begin m] returns the first position in the function list of the
875 module [m]. [function_begin] and [function_succ] can be used to iterate over
876 the function list in order.
877 See the method [llvm::Module::begin]. *)
878 external function_begin : llmodule -> (llmodule, llvalue) llpos
879 = "llvm_function_begin"
881 (** [function_succ gv] returns the function list position succeeding
883 See the method [llvm::Module::iterator::operator++]. *)
884 external function_succ : llvalue -> (llmodule, llvalue) llpos
885 = "llvm_function_succ"
887 (** [iter_functions f m] applies function [f] to each of the functions of module
888 [m] in order. Tail recursive. *)
889 val iter_functions : (llvalue -> unit) -> llmodule -> unit
891 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
892 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
893 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
895 (** [function_end m] returns the last position in the function list of
896 the module [m]. [function_end] and [function_pred] can be used to iterate
897 over the function list in reverse.
898 See the method [llvm::Module::end]. *)
899 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
900 = "llvm_function_end"
902 (** [function_pred gv] returns the function list position preceding [After gv].
903 See the method [llvm::Module::iterator::operator--]. *)
904 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
905 = "llvm_function_pred"
907 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
908 module [m] in reverse order. Tail recursive. *)
909 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
911 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
912 [f1,...,fN] are the functions of module [m]. Tail recursive. *)
913 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
915 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
916 See the method [llvm::Function::isIntrinsic]. *)
917 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
919 (** [function_call_conv f] returns the calling convention of the function [f].
920 See the method [llvm::Function::getCallingConv]. *)
921 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
923 (** [set_function_call_conv cc f] sets the calling convention of the function
924 [f] to the calling convention numbered [cc].
925 See the method [llvm::Function::setCallingConv]. *)
926 external set_function_call_conv : int -> llvalue -> unit
927 = "llvm_set_function_call_conv"
929 (** [collector f] returns [Some name] if the function [f] has a garbage
930 collection algorithm specified and [None] otherwise.
931 See the method [llvm::Function::getCollector]. *)
932 external collector : llvalue -> string option = "llvm_collector"
934 (** [set_collector gc f] sets the collection algorithm for the function [f] to
935 [gc]. See the method [llvm::Function::setCollector]. *)
936 external set_collector : string option -> llvalue -> unit = "llvm_set_collector"
939 (** {7 Operations on params} *)
941 (** [params f] returns the parameters of function [f].
942 See the method [llvm::Function::getArgumentList]. *)
943 external params : llvalue -> llvalue array = "llvm_params"
945 (** [param f n] returns the [n]th parameter of function [f].
946 See the method [llvm::Function::getArgumentList]. *)
947 external param : llvalue -> int -> llvalue = "llvm_param"
949 (** [param_parent p] returns the parent function that owns the parameter.
950 See the method [llvm::Argument::getParent]. *)
951 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
953 (** [param_begin f] returns the first position in the parameter list of the
954 function [f]. [param_begin] and [param_succ] can be used to iterate over
955 the parameter list in order.
956 See the method [llvm::Function::arg_begin]. *)
957 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
959 (** [param_succ bb] returns the parameter list position succeeding
961 See the method [llvm::Function::arg_iterator::operator++]. *)
962 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
964 (** [iter_params f fn] applies function [f] to each of the parameters
965 of function [fn] in order. Tail recursive. *)
966 val iter_params : (llvalue -> unit) -> llvalue -> unit
968 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
969 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
970 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
972 (** [param_end f] returns the last position in the parameter list of
973 the function [f]. [param_end] and [param_pred] can be used to iterate
974 over the parameter list in reverse.
975 See the method [llvm::Function::arg_end]. *)
976 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
978 (** [param_pred gv] returns the function list position preceding [After gv].
979 See the method [llvm::Function::arg_iterator::operator--]. *)
980 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
983 (** [rev_iter_params f fn] applies function [f] to each of the parameters
984 of function [fn] in reverse order. Tail recursive. *)
985 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
987 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
988 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
989 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
992 (** {7 Operations on basic blocks} *)
994 (** [basic_blocks fn] returns the basic blocks of the function [f].
995 See the method [llvm::Function::getBasicBlockList]. *)
996 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
998 (** [entry_block fn] returns the entry basic block of the function [f].
999 See the method [llvm::Function::getEntryBlock]. *)
1000 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1002 (** [delete_block bb] deletes the basic block [bb].
1003 See the method [llvm::BasicBlock::eraseFromParent]. *)
1004 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1006 (** [append_block name f] creates a new basic block named [name] at the end of
1008 See the constructor of [llvm::BasicBlock]. *)
1009 external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
1011 (** [insert_block name bb] creates a new basic block named [name] before the
1013 See the constructor of [llvm::BasicBlock]. *)
1014 external insert_block : string -> llbasicblock -> llbasicblock
1015 = "llvm_insert_block"
1017 (** [block_parent bb] returns the parent function that owns the basic block.
1018 See the method [llvm::BasicBlock::getParent]. *)
1019 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1021 (** [block_begin f] returns the first position in the basic block list of the
1022 function [f]. [block_begin] and [block_succ] can be used to iterate over
1023 the basic block list in order.
1024 See the method [llvm::Function::begin]. *)
1025 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1026 = "llvm_block_begin"
1028 (** [block_succ bb] returns the basic block list position succeeding
1030 See the method [llvm::Function::iterator::operator++]. *)
1031 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1034 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1035 of function [fn] in order. Tail recursive. *)
1036 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1038 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1039 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1040 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1042 (** [block_end f] returns the last position in the basic block list of
1043 the function [f]. [block_end] and [block_pred] can be used to iterate
1044 over the basic block list in reverse.
1045 See the method [llvm::Function::end]. *)
1046 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1049 (** [block_pred gv] returns the function list position preceding [After gv].
1050 See the method [llvm::Function::iterator::operator--]. *)
1051 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1054 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1055 of function [fn] in reverse order. Tail recursive. *)
1056 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1058 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1059 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1060 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1062 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1063 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1065 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1067 Similar to [llvm::isa<BasicBlock>]. *)
1068 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1070 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1071 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1074 (** {7 Operations on instructions} *)
1076 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1077 See the method [llvm::Instruction::getParent]. *)
1078 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1080 (** [instr_begin bb] returns the first position in the instruction list of the
1081 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1082 the instruction list in order.
1083 See the method [llvm::BasicBlock::begin]. *)
1084 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1085 = "llvm_instr_begin"
1087 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1088 See the method [llvm::BasicBlock::iterator::operator++]. *)
1089 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1092 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1093 block [bb] in order. Tail recursive. *)
1094 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1096 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1097 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1098 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1100 (** [instr_end bb] returns the last position in the instruction list of the
1101 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1102 the instruction list in reverse.
1103 See the method [llvm::BasicBlock::end]. *)
1104 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1107 (** [instr_pred i] returns the instruction list position preceding [After i].
1108 See the method [llvm::BasicBlock::iterator::operator--]. *)
1109 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1112 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1113 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1114 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1117 (** {7 Operations on call sites} *)
1119 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1120 instruction [ci], which may be one of the values from the module
1121 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1122 [llvm::InvokeInst::getCallingConv]. *)
1123 external instruction_call_conv: llvalue -> int
1124 = "llvm_instruction_call_conv"
1126 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1127 or invoke instruction [ci] to the integer [cc], which can be one of the
1128 values from the module {!CallConv}.
1129 See the method [llvm::CallInst::setCallingConv]
1130 and [llvm::InvokeInst::setCallingConv]. *)
1131 external set_instruction_call_conv: int -> llvalue -> unit
1132 = "llvm_set_instruction_call_conv"
1135 (** {7 Operations on phi nodes} *)
1137 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1138 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1139 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1140 = "llvm_add_incoming"
1142 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1143 See the method [llvm::PHINode::getIncomingValue]. *)
1144 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1148 (** {6 Instruction builders} *)
1150 (** [builder ()] creates an instruction builder with no position. It is invalid
1151 to use this builder until its position is set with {!position_before} or
1152 {!position_at_end}. See the constructor for [llvm::LLVMBuilder]. *)
1153 external builder : unit -> llbuilder = "llvm_builder"
1155 (** [builder_at ip] creates an instruction builder positioned at [ip].
1156 See the constructor for [llvm::LLVMBuilder]. *)
1157 val builder_at : (llbasicblock, llvalue) llpos -> llbuilder
1159 (** [builder_before ins] creates an instruction builder positioned before the
1160 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1161 val builder_before : llvalue -> llbuilder
1163 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1164 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1165 val builder_at_end : llbasicblock -> llbuilder
1167 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1169 See the constructor for [llvm::LLVMBuilder]. *)
1170 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1171 = "llvm_position_builder"
1173 (** [position_before ins b] moves the instruction builder [b] to before the
1174 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1175 val position_before : llvalue -> llbuilder -> unit
1177 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1178 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1179 val position_at_end : llbasicblock -> llbuilder -> unit
1181 (** [insertion_block b] returns the basic block that the builder [b] is
1182 positioned to insert into. Raises [Not_Found] if the instruction builder is
1184 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1185 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1188 (** {7 Terminators} *)
1190 (** [build_ret_void b] creates a
1192 instruction at the position specified by the instruction builder [b].
1193 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1194 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1196 (** [build_ret v b] creates a
1198 instruction at the position specified by the instruction builder [b].
1199 See the method [llvm::LLVMBuilder::CreateRet]. *)
1200 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1202 (** [build_br bb b] creates a
1204 instruction at the position specified by the instruction builder [b].
1205 See the method [llvm::LLVMBuilder::CreateBr]. *)
1206 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1208 (** [build_cond_br cond tbb fbb b] creates a
1209 [b %cond, %tbb, %fbb]
1210 instruction at the position specified by the instruction builder [b].
1211 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1212 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1213 llvalue = "llvm_build_cond_br"
1215 (** [build_switch case elsebb count b] creates an empty
1216 [switch %case, %elsebb]
1217 instruction at the position specified by the instruction builder [b] with
1218 space reserved for [count] cases.
1219 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1220 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1221 = "llvm_build_switch"
1223 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1224 when its input matches the constant [onval].
1225 See the method [llvm::SwitchInst::addCase]. **)
1226 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1229 (** [build_invoke fn args tobb unwindbb name b] creates an
1230 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1231 instruction at the position specified by the instruction builder [b].
1232 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1233 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1234 llbasicblock -> string -> llbuilder -> llvalue
1235 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1237 (** [build_unwind b] creates an
1239 instruction at the position specified by the instruction builder [b].
1240 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1241 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1243 (** [build_unreachable b] creates an
1245 instruction at the position specified by the instruction builder [b].
1246 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1247 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1250 (** {7 Arithmetic} *)
1252 (** [build_add x y name b] creates a
1253 [%name = add %x, %y]
1254 instruction at the position specified by the instruction builder [b].
1255 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1256 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1259 (** [build_sub x y name b] creates a
1260 [%name = sub %x, %y]
1261 instruction at the position specified by the instruction builder [b].
1262 See the method [llvm::LLVMBuilder::CreateSub]. *)
1263 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1266 (** [build_mul x y name b] creates a
1267 [%name = mul %x, %y]
1268 instruction at the position specified by the instruction builder [b].
1269 See the method [llvm::LLVMBuilder::CreateMul]. *)
1270 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1273 (** [build_udiv x y name b] creates a
1274 [%name = udiv %x, %y]
1275 instruction at the position specified by the instruction builder [b].
1276 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1277 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1280 (** [build_sdiv x y name b] creates a
1281 [%name = sdiv %x, %y]
1282 instruction at the position specified by the instruction builder [b].
1283 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1284 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1287 (** [build_fdiv x y name b] creates a
1288 [%name = fdiv %x, %y]
1289 instruction at the position specified by the instruction builder [b].
1290 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1291 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1294 (** [build_urem x y name b] creates a
1295 [%name = urem %x, %y]
1296 instruction at the position specified by the instruction builder [b].
1297 See the method [llvm::LLVMBuilder::CreateURem]. *)
1298 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1301 (** [build_SRem x y name b] creates a
1302 [%name = srem %x, %y]
1303 instruction at the position specified by the instruction builder [b].
1304 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1305 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1308 (** [build_frem x y name b] creates a
1309 [%name = frem %x, %y]
1310 instruction at the position specified by the instruction builder [b].
1311 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1312 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1315 (** [build_shl x y name b] creates a
1316 [%name = shl %x, %y]
1317 instruction at the position specified by the instruction builder [b].
1318 See the method [llvm::LLVMBuilder::CreateShl]. *)
1319 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1322 (** [build_lshr x y name b] creates a
1323 [%name = lshr %x, %y]
1324 instruction at the position specified by the instruction builder [b].
1325 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1326 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1329 (** [build_ashr x y name b] creates a
1330 [%name = ashr %x, %y]
1331 instruction at the position specified by the instruction builder [b].
1332 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1333 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1336 (** [build_and x y name b] creates a
1337 [%name = and %x, %y]
1338 instruction at the position specified by the instruction builder [b].
1339 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1340 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1343 (** [build_or x y name b] creates a
1345 instruction at the position specified by the instruction builder [b].
1346 See the method [llvm::LLVMBuilder::CreateOr]. *)
1347 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1350 (** [build_xor x y name b] creates a
1351 [%name = xor %x, %y]
1352 instruction at the position specified by the instruction builder [b].
1353 See the method [llvm::LLVMBuilder::CreateXor]. *)
1354 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1357 (** [build_neg x name b] creates a
1359 instruction at the position specified by the instruction builder [b].
1360 [-0.0] is used for floating point types to compute the correct sign.
1361 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1362 external build_neg : llvalue -> string -> llbuilder -> llvalue
1365 (** [build_xor x name b] creates a
1366 [%name = xor %x, -1]
1367 instruction at the position specified by the instruction builder [b].
1368 [-1] is the correct "all ones" value for the type of [x].
1369 See the method [llvm::LLVMBuilder::CreateXor]. *)
1370 external build_not : llvalue -> string -> llbuilder -> llvalue
1376 (** [build_malloc ty name b] creates a
1377 [%name = malloc %ty]
1378 instruction at the position specified by the instruction builder [b].
1379 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1380 external build_malloc : lltype -> string -> llbuilder -> llvalue
1381 = "llvm_build_malloc"
1383 (** [build_array_malloc ty n name b] creates a
1384 [%name = malloc %ty, %n]
1385 instruction at the position specified by the instruction builder [b].
1386 See the method [llvm::LLVMBuilder::CreateMalloc]. *)
1387 external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1388 llvalue = "llvm_build_array_malloc"
1390 (** [build_alloca ty name b] creates a
1391 [%name = alloca %ty]
1392 instruction at the position specified by the instruction builder [b].
1393 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1394 external build_alloca : lltype -> string -> llbuilder -> llvalue
1395 = "llvm_build_alloca"
1397 (** [build_array_alloca ty n name b] creates a
1398 [%name = alloca %ty, %n]
1399 instruction at the position specified by the instruction builder [b].
1400 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1401 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1402 llvalue = "llvm_build_array_alloca"
1404 (** [build_free v b] creates a
1406 instruction at the position specified by the instruction builder [b].
1407 See the method [llvm::LLVMBuilder::CreateFree]. *)
1408 external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1410 (** [build_load v name b] creates a
1412 instruction at the position specified by the instruction builder [b].
1413 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1414 external build_load : llvalue -> string -> llbuilder -> llvalue
1417 (** [build_store v p b] creates a
1419 instruction at the position specified by the instruction builder [b].
1420 See the method [llvm::LLVMBuilder::CreateStore]. *)
1421 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1422 = "llvm_build_store"
1424 (** [build_gep p indices name b] creates a
1425 [%name = gep %p, indices...]
1426 instruction at the position specified by the instruction builder [b].
1427 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1428 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1434 (** [build_trunc v ty name b] creates a
1435 [%name = trunc %p to %ty]
1436 instruction at the position specified by the instruction builder [b].
1437 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1438 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1439 = "llvm_build_trunc"
1441 (** [build_zext v ty name b] creates a
1442 [%name = zext %p to %ty]
1443 instruction at the position specified by the instruction builder [b].
1444 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1445 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1448 (** [build_sext v ty name b] creates a
1449 [%name = sext %p to %ty]
1450 instruction at the position specified by the instruction builder [b].
1451 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1452 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1455 (** [build_fptoui v ty name b] creates a
1456 [%name = fptoui %p to %ty]
1457 instruction at the position specified by the instruction builder [b].
1458 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1459 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1460 = "llvm_build_fptoui"
1462 (** [build_fptosi v ty name b] creates a
1463 [%name = fptosi %p to %ty]
1464 instruction at the position specified by the instruction builder [b].
1465 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1466 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1467 = "llvm_build_fptosi"
1469 (** [build_uitofp v ty name b] creates a
1470 [%name = uitofp %p to %ty]
1471 instruction at the position specified by the instruction builder [b].
1472 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1473 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1474 = "llvm_build_uitofp"
1476 (** [build_sitofp v ty name b] creates a
1477 [%name = sitofp %p to %ty]
1478 instruction at the position specified by the instruction builder [b].
1479 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1480 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1481 = "llvm_build_sitofp"
1483 (** [build_fptrunc v ty name b] creates a
1484 [%name = fptrunc %p to %ty]
1485 instruction at the position specified by the instruction builder [b].
1486 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1487 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1488 = "llvm_build_fptrunc"
1490 (** [build_fpext v ty name b] creates a
1491 [%name = fpext %p to %ty]
1492 instruction at the position specified by the instruction builder [b].
1493 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1494 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1495 = "llvm_build_fpext"
1497 (** [build_ptrtoint v ty name b] creates a
1498 [%name = prtotint %p to %ty]
1499 instruction at the position specified by the instruction builder [b].
1500 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1501 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1502 = "llvm_build_prttoint"
1504 (** [build_inttoptr v ty name b] creates a
1505 [%name = inttoptr %p to %ty]
1506 instruction at the position specified by the instruction builder [b].
1507 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1508 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1509 = "llvm_build_inttoptr"
1511 (** [build_bitcast v ty name b] creates a
1512 [%name = bitcast %p to %ty]
1513 instruction at the position specified by the instruction builder [b].
1514 See the method [llvm::LLVMBuilder::CreateBitcast]. *)
1515 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1516 = "llvm_build_bitcast"
1519 (** {7 Comparisons} *)
1521 (** [build_icmp pred x y name b] creates a
1522 [%name = icmp %pred %x, %y]
1523 instruction at the position specified by the instruction builder [b].
1524 See the method [llvm::LLVMBuilder::CreateICmp]. *)
1525 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1526 llbuilder -> llvalue = "llvm_build_icmp"
1528 (** [build_fcmp pred x y name b] creates a
1529 [%name = fcmp %pred %x, %y]
1530 instruction at the position specified by the instruction builder [b].
1531 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1532 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1533 llbuilder -> llvalue = "llvm_build_fcmp"
1536 (** {7 Miscellaneous instructions} *)
1538 (** [build_phi incoming name b] creates a
1539 [%name = phi %incoming]
1540 instruction at the position specified by the instruction builder [b].
1541 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1542 See the method [llvm::LLVMBuilder::CreatePHI]. *)
1543 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1544 llvalue = "llvm_build_phi"
1546 (** [build_call fn args name b] creates a
1547 [%name = call %fn(args...)]
1548 instruction at the position specified by the instruction builder [b].
1549 See the method [llvm::LLVMBuilder::CreateCall]. *)
1550 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1553 (** [build_select cond thenv elsev name b] creates a
1554 [%name = select %cond, %thenv, %elsev]
1555 instruction at the position specified by the instruction builder [b].
1556 See the method [llvm::LLVMBuilder::CreateSelect]. *)
1557 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1558 llvalue = "llvm_build_select"
1560 (** [build_va_arg valist argty name b] creates a
1561 [%name = va_arg %valist, %argty]
1562 instruction at the position specified by the instruction builder [b].
1563 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1564 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1565 = "llvm_build_va_arg"
1567 (** [build_extractelement vec i name b] creates a
1568 [%name = extractelement %vec, %i]
1569 instruction at the position specified by the instruction builder [b].
1570 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1571 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1572 llvalue = "llvm_build_extractelement"
1574 (** [build_insertelement vec elt i name b] creates a
1575 [%name = insertelement %vec, %elt, %i]
1576 instruction at the position specified by the instruction builder [b].
1577 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1578 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1579 llbuilder -> llvalue = "llvm_build_insertelement"
1581 (** [build_shufflevector veca vecb mask name b] creates a
1582 [%name = shufflevector %veca, %vecb, %mask]
1583 instruction at the position specified by the instruction builder [b].
1584 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1585 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1586 llbuilder -> llvalue = "llvm_build_shufflevector"
1589 (** {6 Module providers} *)
1591 module ModuleProvider : sig
1592 (** [create_module_provider m] encapsulates [m] in a module provider and takes
1593 ownership of the module. See the constructor
1594 [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
1595 external create : llmodule -> llmoduleprovider
1596 = "LLVMCreateModuleProviderForExistingModule"
1598 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1599 the contained module. *)
1600 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1604 (** {6 Memory buffers} *)
1606 module MemoryBuffer : sig
1607 (** [of_file p] is the memory buffer containing the contents of the file at
1608 path [p]. If the file could not be read, then [IoError msg] is
1610 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1612 (** [stdin ()] is the memory buffer containing the contents of standard input.
1613 If standard input is empty, then [IoError msg] is raised. *)
1614 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1616 (** Disposes of a memory buffer. *)
1617 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
1621 (** {6 Pass Managers} *)
1623 module PassManager : sig
1626 type any = [ `Module | `Function ]
1628 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
1629 type of pipeline is suitable for link-time optimization and whole-module
1631 See the constructor of [llvm::PassManager]. *)
1632 external create : unit -> [ `Module ] t = "llvm_passmanager_create"
1634 (** [PassManager.create_function mp] constructs a new function-by-function
1635 pass pipeline over the module provider [mp]. It does not take ownership of
1636 [mp]. This type of pipeline is suitable for code generation and JIT
1638 See the constructor of [llvm::FunctionPassManager]. *)
1639 external create_function : llmoduleprovider -> [ `Function ] t
1640 = "LLVMCreateFunctionPassManager"
1642 (** [run_module m pm] initializes, executes on the module [m], and finalizes
1643 all of the passes scheduled in the pass manager [pm]. Returns [true] if
1644 any of the passes modified the module, [false] otherwise.
1645 See the [llvm::PassManager::run] method. *)
1646 external run_module : llmodule -> [ `Module ] t -> bool
1647 = "llvm_passmanager_run_module"
1649 (** [initialize fpm] initializes all of the function passes scheduled in the
1650 function pass manager [fpm]. Returns [true] if any of the passes modified
1651 the module, [false] otherwise.
1652 See the [llvm::FunctionPassManager::doInitialization] method. *)
1653 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
1655 (** [run_function f fpm] executes all of the function passes scheduled in the
1656 function pass manager [fpm] over the function [f]. Returns [true] if any
1657 of the passes modified [f], [false] otherwise.
1658 See the [llvm::FunctionPassManager::run] method. *)
1659 external run_function : llvalue -> [ `Function ] t -> bool
1660 = "llvm_passmanager_run_function"
1662 (** [finalize fpm] finalizes all of the function passes scheduled in in the
1663 function pass manager [fpm]. Returns [true] if any of the passes
1664 modified the module, [false] otherwise.
1665 See the [llvm::FunctionPassManager::doFinalization] method. *)
1666 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
1668 (** Frees the memory of a pass pipeline. For function pipelines, does not free
1669 the module provider.
1670 See the destructor of [llvm::BasePassManager]. *)
1671 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"