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. *)
152 (** {6 Exceptions} *)
154 exception IoError of string
159 (** [create_module id] creates a module with the supplied module ID. Modules are
160 not garbage collected; it is mandatory to call {!dispose_module} to free
161 memory. See the constructor [llvm::Module::Module]. *)
162 external create_module : string -> llmodule = "llvm_create_module"
164 (** [dispose_module m] destroys a module [m] and all of the IR objects it
165 contained. All references to subordinate objects are invalidated;
166 referencing them will invoke undefined behavior. See the destructor
167 [llvm::Module::~Module]. *)
168 external dispose_module : llmodule -> unit = "llvm_dispose_module"
170 (** [target_triple m] is the target specifier for the module [m], something like
171 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
172 external target_triple: llmodule -> string
173 = "llvm_target_triple"
175 (** [target_triple triple m] changes the target specifier for the module [m] to
176 the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
177 external set_target_triple: string -> llmodule -> unit
178 = "llvm_set_target_triple"
180 (** [data_layout m] is the data layout specifier for the module [m], something
181 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
182 method [llvm::Module::getDataLayout]. *)
183 external data_layout: llmodule -> string
186 (** [set_data_layout s m] changes the data layout specifier for the module [m]
187 to the string [s]. See the method [llvm::Module::setDataLayout]. *)
188 external set_data_layout: string -> llmodule -> unit
189 = "llvm_set_data_layout"
191 (** [define_type_name name ty m] adds a named type to the module's symbol table.
192 Returns [true] if successful. If such a name already exists, then no entry
193 is added and [false] is returned. See the [llvm::Module::addTypeName]
195 external define_type_name : string -> lltype -> llmodule -> bool
196 = "llvm_add_type_name"
198 (** [delete_type_name name] removes a type name from the module's symbol
200 external delete_type_name : string -> llmodule -> unit
201 = "llvm_delete_type_name"
203 (** [dump_module m] prints the .ll representation of the module [m] to standard
204 error. See the method [llvm::Module::dump]. *)
205 external dump_module : llmodule -> unit = "llvm_dump_module"
210 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
211 See the method [llvm::Type::getTypeID]. *)
212 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
214 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
215 val string_of_lltype : lltype -> string
217 (** {7 Operations on integer types} *)
219 (** The 1-bit integer type. See [llvm::Type::Int1Ty]. *)
222 (** The 8-bit integer type. See [llvm::Type::Int8Ty]. *)
225 (** The 16-bit integer type. See [llvm::Type::Int16Ty]. *)
226 val i16_type : lltype
228 (** The 32-bit integer type. See [llvm::Type::Int32Ty]. *)
229 val i32_type : lltype
231 (** The 64-bit integer type. See [llvm::Type::Int64Ty]. *)
232 val i64_type : lltype
234 (** [integer_type n] returns an integer type of bitwidth [n].
235 See the method [llvm::IntegerType::get]. *)
236 external integer_type : int -> lltype = "llvm_integer_type"
238 (** [integer_bitwidth ty] returns the number of bits in the integer type [ty].
239 See the method [llvm::IntegerType::getBitWidth]. *)
240 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
243 (** {7 Operations on real types} *)
245 (** The IEEE 32-bit floating point type. See [llvm::Type::FloatTy]. *)
246 val float_type : lltype
248 (** The IEEE 64-bit floating point type. See [llvm::Type::DoubleTy]. *)
249 val double_type : lltype
251 (** The x87 80-bit floating point type. See [llvm::Type::X86_FP80Ty]. *)
252 val x86fp80_type : lltype
254 (** The IEEE 128-bit floating point type. See [llvm::Type::FP128Ty]. *)
255 val fp128_type : lltype
257 (** The PowerPC 128-bit floating point type. See [llvm::Type::PPC_FP128Ty]. *)
258 val ppc_fp128_type : lltype
261 (** {7 Operations on function types} *)
263 (** [function_type ret_ty param_tys] returns the function type returning
264 [ret_ty] and taking [param_tys] as parameters.
265 See the method [llvm::FunctionType::get]. *)
266 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
268 (** [va_arg_function_type ret_ty param_tys] is just like
269 [function_type ret_ty param_tys] except that it returns the function type
270 which also takes a variable number of arguments.
271 See the method [llvm::FunctionType::get]. *)
272 external var_arg_function_type : lltype -> lltype array -> lltype
273 = "llvm_var_arg_function_type"
275 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
276 otherwise. See the method [llvm::FunctionType::isVarArg]. *)
277 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
279 (** [return_type fty] gets the return type of the function type [fty].
280 See the method [llvm::FunctionType::getReturnType]. *)
281 external return_type : lltype -> lltype = "LLVMGetReturnType"
283 (** [param_types fty] gets the parameter types of the function type [fty].
284 See the method [llvm::FunctionType::getParamType]. *)
285 external param_types : lltype -> lltype array = "llvm_param_types"
288 (** {7 Operations on struct types} *)
290 (** [struct_type tys] returns the structure type containing in the types in the
291 array [tys]. See the method [llvm::StructType::get]. *)
292 external struct_type : lltype array -> lltype = "llvm_struct_type"
294 (** [struct_type tys] returns the packed structure type containing in the types
295 in the array [tys]. See the method [llvm::StructType::get]. *)
296 external packed_struct_type : lltype array -> lltype = "llvm_packed_struct_type"
298 (** [element_types sty] returns the constituent types of the struct type [sty].
299 See the method [llvm::StructType::getElementType]. *)
300 external element_types : lltype -> lltype array = "llvm_element_types"
302 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
303 [false] otherwise. See the method [llvm::StructType::isPacked]. *)
304 external is_packed : lltype -> bool = "llvm_is_packed"
307 (** {7 Operations on pointer, vector, and array types} *)
309 (** [array_type ty n] returns the array type containing [n] elements of type
310 [ty]. See the method [llvm::ArrayType::get]. *)
311 external array_type : lltype -> int -> lltype = "llvm_array_type"
313 (** [pointer_type ty] returns the pointer type referencing objects of type
314 [ty] in the default address space (0).
315 See the method [llvm::PointerType::getUnqual]. *)
316 external pointer_type : lltype -> lltype = "llvm_pointer_type"
318 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
319 of type [ty] in address space [as].
320 See the method [llvm::PointerType::get]. *)
321 external qualified_pointer_type : lltype -> int -> lltype
322 = "llvm_qualified_pointer_type"
324 (** [vector_type ty n] returns the array type containing [n] elements of the
325 primitive type [ty]. See the method [llvm::ArrayType::get]. *)
326 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
328 (** [element_type ty] returns the element type of the pointer, vector, or array
329 type [ty]. See the method [llvm::SequentialType::get]. *)
330 external element_type : lltype -> lltype = "LLVMGetElementType"
332 (** [element_type aty] returns the element count of the array type [aty].
333 See the method [llvm::ArrayType::getNumElements]. *)
334 external array_length : lltype -> int = "llvm_array_length"
336 (** [address_space pty] returns the address space qualifier of the pointer type
337 [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
338 external address_space : lltype -> int = "llvm_address_space"
340 (** [element_type ty] returns the element count of the vector type [ty].
341 See the method [llvm::VectorType::getNumElements]. *)
342 external vector_size : lltype -> int = "llvm_vector_size"
345 (** {7 Operations on other types} *)
347 (** [opaque_type ()] creates a new opaque type distinct from any other.
348 Opaque types are useful for building recursive types in combination with
350 See [llvm::OpaqueType::get]. *)
351 external opaque_type : unit -> lltype = "llvm_opaque_type"
353 (** [void_type] is the type of a function which does not return any value.
354 See [llvm::Type::VoidTy]. *)
355 val void_type : lltype
357 (** [label_type] is the type of a basic block. See [llvm::Type::LabelTy]. *)
358 val label_type : lltype
360 (** {7 Operations on type handles} *)
362 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
363 refined as a result of a call to {!refine_type}, the handle will be updated;
364 any bare [lltype] references will become invalid.
365 See the class [llvm::PATypeHolder]. *)
366 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
368 (** [type_of_handle tyh] resolves the type handle [tyh].
369 See the method [llvm::PATypeHolder::get()]. *)
370 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
372 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
373 concrete type [ty] in all users. Warning: This may invalidate {!lltype}
374 values! Use {!lltypehandle} to manipulate potentially abstract types. See
375 the method [llvm::Type::refineAbstractType]. *)
376 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
381 (** [type_of v] returns the type of the value [v].
382 See the method [llvm::Value::getType]. *)
383 external type_of : llvalue -> lltype = "llvm_type_of"
385 (** [value_name v] returns the name of the value [v]. For global values, this is
386 the symbol name. For instructions and basic blocks, it is the SSA register
387 name. It is meaningless for constants.
388 See the method [llvm::Value::getName]. *)
389 external value_name : llvalue -> string = "llvm_value_name"
391 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
392 [llvm::Value::setName]. *)
393 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
395 (** [dump_value v] prints the .ll representation of the value [v] to standard
396 error. See the method [llvm::Value::dump]. *)
397 external dump_value : llvalue -> unit = "llvm_dump_value"
400 (** {7 Operations on constants of (mostly) any type} *)
402 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
403 otherwise. Similar to [llvm::isa<Constant>]. *)
404 external is_constant : llvalue -> bool = "llvm_is_constant"
406 (** [const_null ty] returns the constant null (zero) of the type [ty].
407 See the method [llvm::Constant::getNullValue]. *)
408 external const_null : lltype -> llvalue = "LLVMConstNull"
410 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
411 [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
412 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
414 (** [undef ty] returns the undefined value of the type [ty].
415 See the method [llvm::UndefValue::get]. *)
416 external undef : lltype -> llvalue = "LLVMGetUndef"
418 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
419 See the method [llvm::Constant::isNullValue]. *)
420 external is_null : llvalue -> bool = "llvm_is_null"
422 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
423 otherwise. Similar to [llvm::isa<UndefValue>]. *)
424 external is_undef : llvalue -> bool = "llvm_is_undef"
427 (** {7 Operations on scalar constants} *)
429 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
430 See the method [llvm::ConstantInt::get]. *)
431 external const_int : lltype -> int -> llvalue = "llvm_const_int"
433 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
434 [i]. See the method [llvm::ConstantInt::get]. *)
435 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
436 = "llvm_const_of_int64"
438 (** [const_float ty n] returns the floating point constant of type [ty] and
439 value [n]. See the method [llvm::ConstantInt::get]. *)
440 external const_float : lltype -> float -> llvalue = "llvm_const_float"
443 (** {7 Operations on composite constants} *)
445 (** [const_string s] returns the constant [i8] array with the values of the
446 characters in the string [s]. The array is not null-terminated (but see
447 {!const_stringz}). This value can in turn be used as the initializer for a
448 global variable. See the method [llvm::ConstantArray::get]. *)
449 external const_string : string -> llvalue = "llvm_const_string"
451 (** [const_stringz s] returns the constant [i8] array with the values of the
452 characters in the string [s] and a null terminator. This value can in turn
453 be used as the initializer for a global variable.
454 See the method [llvm::ConstantArray::get]. *)
455 external const_stringz : string -> llvalue = "llvm_const_stringz"
457 (** [const_array ty elts] returns the constant array of type
458 [array_type ty (Array.length elts)] and containing the values [elts].
459 This value can in turn be used as the initializer for a global variable.
460 See the method [llvm::ConstantArray::get]. *)
461 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
463 (** [const_struct elts] returns the structured constant of type
464 [struct_type (Array.map type_of elts)] and containing the values [elts].
465 This value can in turn be used as the initializer for a global variable.
466 See the method [llvm::ConstantStruct::get]. *)
467 external const_struct : llvalue array -> llvalue = "llvm_const_struct"
469 (** [const_packed_struct elts] returns the structured constant of type
470 {!packed_struct_type} [(Array.map type_of elts)] and containing the values
471 [elts]. This value can in turn be used as the initializer for a global
472 variable. See the method [llvm::ConstantStruct::get]. *)
473 external const_packed_struct : llvalue array -> llvalue
474 = "llvm_const_packed_struct"
476 (** [const_vector elts] returns the vector constant of type
477 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
478 values [elts]. See the method [llvm::ConstantVector::get]. *)
479 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
482 (** {7 Constant expressions} *)
484 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
485 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
486 (const_int i64_type 1)) i64_type], but considerably more readable.
487 See the method [llvm::ConstantExpr::getSizeOf]. *)
488 external size_of : lltype -> llvalue = "LLVMSizeOf"
490 (** [const_neg c] returns the arithmetic negation of the constant [c].
491 See the method [llvm::ConstantExpr::getNeg]. *)
492 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
494 (** [const_not c] returns the bitwise inverse of the constant [c].
495 See the method [llvm::ConstantExpr::getNot]. *)
496 external const_not : llvalue -> llvalue = "LLVMConstNot"
498 (** [const_add c1 c2] returns the constant sum of two constants.
499 See the method [llvm::ConstantExpr::getAdd]. *)
500 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
502 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
503 constants. See the method [llvm::ConstantExpr::getSub]. *)
504 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
506 (** [const_mul c1 c2] returns the constant product of two constants.
507 See the method [llvm::ConstantExpr::getMul]. *)
508 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
510 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
512 See the method [llvm::ConstantExpr::getUDiv]. *)
513 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
515 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
517 See the method [llvm::ConstantExpr::]. *)
518 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
520 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
522 See the method [llvm::ConstantExpr::getFDiv]. *)
523 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
525 (** [const_udiv c1 c2] returns the constant remainder [c1 MOD c2] of two
526 unsigned integer constants.
527 See the method [llvm::ConstantExpr::getURem]. *)
528 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
530 (** [const_sdiv c1 c2] returns the constant remainder [c1 MOD c2] of two
531 signed integer constants.
532 See the method [llvm::ConstantExpr::getSRem]. *)
533 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
535 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
536 signed floating point constants.
537 See the method [llvm::ConstantExpr::getFRem]. *)
538 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
540 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
542 See the method [llvm::ConstantExpr::getAnd]. *)
543 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
545 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
547 See the method [llvm::ConstantExpr::getOr]. *)
548 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
550 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
552 See the method [llvm::ConstantExpr::getXor]. *)
553 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
555 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
556 constants, [c1 pred c2].
557 See the method [llvm::ConstantExpr::getICmp]. *)
558 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
561 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
562 point constants, [c1 pred c2].
563 See the method [llvm::ConstantExpr::getFCmp]. *)
564 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
567 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
568 constant integer [c2].
569 See the method [llvm::ConstantExpr::getShl]. *)
570 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
572 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
573 constant integer [c2] with zero extension.
574 See the method [llvm::ConstantExpr::getLShr]. *)
575 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
577 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
578 constant integer [c2] with sign extension.
579 See the method [llvm::ConstantExpr::getAShr]. *)
580 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
582 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
583 constant integers indices from the array [indices].
584 See the method [llvm::ConstantExpr::getGetElementPtr]. *)
585 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
587 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
588 to the smaller integer type [ty].
589 See the method [llvm::ConstantExpr::getTrunc]. *)
590 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
592 (** [const_sext c ty] returns the constant sign extension of integer constant
593 [c] to the larger integer type [ty].
594 See the method [llvm::ConstantExpr::getSExt]. *)
595 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
597 (** [const_zext c ty] returns the constant zero extension of integer constant
598 [c] to the larger integer type [ty].
599 See the method [llvm::ConstantExpr::getZExt]. *)
600 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
602 (** [const_fptrunc c ty] returns the constant truncation of floating point
603 constant [c] to the smaller floating point type [ty].
604 See the method [llvm::ConstantExpr::getFPTrunc]. *)
605 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
607 (** [const_fpext c ty] returns the constant extension of floating point constant
608 [c] to the larger floating point type [ty].
609 See the method [llvm::ConstantExpr::getFPExt]. *)
610 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
612 (** [const_uitofp c ty] returns the constant floating point conversion of
613 unsigned integer constant [c] to the floating point type [ty].
614 See the method [llvm::ConstantExpr::getUIToFP]. *)
615 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
617 (** [const_sitofp c ty] returns the constant floating point conversion of
618 signed integer constant [c] to the floating point type [ty].
619 See the method [llvm::ConstantExpr::getSIToFP]. *)
620 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
622 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
623 floating point constant [c] to integer type [ty].
624 See the method [llvm::ConstantExpr::getFPToUI]. *)
625 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
627 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
628 floating point constant [c] to integer type [ty].
629 See the method [llvm::ConstantExpr::getFPToSI]. *)
630 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
632 (** [const_ptrtoint c ty] returns the constant integer conversion of
633 pointer constant [c] to integer type [ty].
634 See the method [llvm::ConstantExpr::getPtrToInt]. *)
635 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
637 (** [const_inttoptr c ty] returns the constant pointer conversion of
638 integer constant [c] to pointer type [ty].
639 See the method [llvm::ConstantExpr::getIntToPtr]. *)
640 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
642 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
643 to type [ty] of equal size.
644 See the method [llvm::ConstantExpr::getBitCast]. *)
645 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
647 (** [const_select cond t f] returns the constant conditional which returns value
648 [t] if the boolean constant [cond] is true and the value [f] otherwise.
649 See the method [llvm::ConstantExpr::getSelect]. *)
650 external const_select : llvalue -> llvalue -> llvalue -> llvalue
653 (** [const_extractelement vec i] returns the constant [i]th element of
654 constant vector [vec]. [i] must be a constant [i32] value unsigned less than
655 the size of the vector.
656 See the method [llvm::ConstantExpr::getExtractElement]. *)
657 external const_extractelement : llvalue -> llvalue -> llvalue
658 = "LLVMConstExtractElement"
660 (** [const_insertelement vec v i] returns the constant vector with the same
661 elements as constant vector [v] but the [i]th element replaced by the
662 constant [v]. [v] must be a constant value with the type of the vector
663 elements. [i] must be a constant [i32] value unsigned less than the size
665 See the method [llvm::ConstantExpr::getInsertElement]. *)
666 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
667 = "LLVMConstInsertElement"
669 (** [const_shufflevector a b mask] returns a constant [shufflevector].
670 See the LLVM Language Reference for details on the [sufflevector]
672 See the method [llvm::ConstantExpr::getShuffleVector]. *)
673 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
674 = "LLVMConstShuffleVector"
677 (** {7 Operations on global variables, functions, and aliases (globals)} *)
679 (** [global_parent g] is the enclosing module of the global value [g].
680 See the method [llvm::GlobalValue::getParent]. *)
681 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
683 (** [is_declaration g] returns [true] if the global value [g] is a declaration
684 only. Returns [false] otherwise.
685 See the method [llvm::GlobalValue::isDeclaration]. *)
686 external is_declaration : llvalue -> bool = "llvm_is_declaration"
688 (** [linkage g] returns the linkage of the global value [g].
689 See the method [llvm::GlobalValue::getLinkage]. *)
690 external linkage : llvalue -> Linkage.t = "llvm_linkage"
692 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
693 See the method [llvm::GlobalValue::setLinkage]. *)
694 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
696 (** [section g] returns the linker section of the global value [g].
697 See the method [llvm::GlobalValue::getSection]. *)
698 external section : llvalue -> string = "llvm_section"
700 (** [set_section s g] sets the linker section of the global value [g] to [s].
701 See the method [llvm::GlobalValue::setSection]. *)
702 external set_section : string -> llvalue -> unit = "llvm_set_section"
704 (** [visibility g] returns the linker visibility of the global value [g].
705 See the method [llvm::GlobalValue::getVisibility]. *)
706 external visibility : llvalue -> Visibility.t = "llvm_visibility"
708 (** [set_visibility v g] sets the linker visibility of the global value [g] to
709 [v]. See the method [llvm::GlobalValue::setVisibility]. *)
710 external set_visibility : Visibility.t -> llvalue -> unit
711 = "llvm_set_visibility"
713 (** [alignment g] returns the required alignment of the global value [g].
714 See the method [llvm::GlobalValue::getAlignment]. *)
715 external alignment : llvalue -> int = "llvm_alignment"
717 (** [set_alignment n g] sets the required alignment of the global value [g] to
718 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
719 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
722 (** {7 Operations on global variables} *)
724 (** [declare_global ty name m] returns a new global variable of type [ty] and
725 with name [name] in module [m]. If such a global variable already exists,
726 it is returned. If the type of the existing global differs, then a bitcast
727 to [ty] is returned. *)
728 external declare_global : lltype -> string -> llmodule -> llvalue
729 = "llvm_declare_global"
731 (** [define_global name init m] returns a new global with name [name] and
732 initializer [init] in module [m]. If the named global already exists, it is
734 See the constructor of [llvm::GlobalVariable]. *)
735 external define_global : string -> llvalue -> llmodule -> llvalue
736 = "llvm_define_global"
738 (** [lookup_global name m] returns [Some g] if a global variable with name
739 [name] exists in module [m]. If no such global exists, returns [None].
740 See the [llvm::GlobalVariable] constructor. *)
741 external lookup_global : string -> llmodule -> llvalue option
742 = "llvm_lookup_global"
744 (** [delete_global gv] destroys the global variable [gv].
745 See the method [llvm::GlobalVariable::eraseFromParent]. *)
746 external delete_global : llvalue -> unit = "llvm_delete_global"
748 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
749 constant. Returns [false] otherwise.
750 See the method [llvm::GlobalVariable::isConstant]. *)
751 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
753 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
754 [c] is [true] and not if [c] is [false].
755 See the method [llvm::GlobalVariable::setConstant]. *)
756 external set_global_constant : bool -> llvalue -> unit
757 = "llvm_set_global_constant"
759 (** [has_initializer gv] returns [true] if the global variable [gv] has an
760 initializer and [false] otherwise.
761 See the method [llvm::GlobalVariable::hasInitializer]. *)
762 external has_initializer : llvalue -> bool = "llvm_has_initializer"
764 (** [global_initializer gv] returns the initializer for the global variable
765 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
766 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
768 (** [set_initializer c gv] sets the initializer for the global variable
769 [gv] to the constant [c].
770 See the method [llvm::GlobalVariable::setInitializer]. *)
771 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
773 (** [remove_initializer gv] unsets the initializer for the global variable
775 See the method [llvm::GlobalVariable::setInitializer]. *)
776 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
778 (** [is_thread_local gv] returns [true] if the global variable [gv] is
779 thread-local and [false] otherwise.
780 See the method [llvm::GlobalVariable::isThreadLocal]. *)
781 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
783 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
784 [c] is [true] and not otherwise.
785 See the method [llvm::GlobalVariable::setThreadLocal]. *)
786 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
789 (** {7 Operations on functions} *)
791 (** [declare_function name ty m] returns a new function of type [ty] and
792 with name [name] in module [m]. If such a function already exists,
793 it is returned. If the type of the existing function differs, then a bitcast
794 to [ty] is returned. *)
795 external declare_function : string -> lltype -> llmodule -> llvalue
796 = "llvm_declare_function"
798 (** [define_function name ty m] creates a new function with name [name] and
799 type [ty] in module [m]. If the named function already exists, it is
800 renamed. An entry basic block is created in the function.
801 See the constructor of [llvm::GlobalVariable]. *)
802 external define_function : string -> lltype -> llmodule -> llvalue
803 = "llvm_define_function"
805 (** [lookup_function name m] returns [Some f] if a function with name
806 [name] exists in module [m]. If no such function exists, returns [None].
807 See the method [llvm::Module] constructor. *)
808 external lookup_function : string -> llmodule -> llvalue option
809 = "llvm_lookup_function"
811 (** [delete_function f] destroys the function [f].
812 See the method [llvm::Function::eraseFromParent]. *)
813 external delete_function : llvalue -> unit = "llvm_delete_function"
815 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
816 See the method [llvm::Function::isIntrinsic]. *)
817 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
819 (** [function_call_conv f] returns the calling convention of the function [f].
820 See the method [llvm::Function::getCallingConv]. *)
821 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
823 (** [set_function_call_conv cc f] sets the calling convention of the function
824 [f] to the calling convention numbered [cc].
825 See the method [llvm::Function::setCallingConv]. *)
826 external set_function_call_conv : int -> llvalue -> unit
827 = "llvm_set_function_call_conv"
829 (** [collector f] returns [Some name] if the function [f] has a garbage
830 collection algorithm specified and [None] otherwise.
831 See the method [llvm::Function::getCollector]. *)
832 external collector : llvalue -> string option = "llvm_collector"
834 (** [set_collector gc f] sets the collection algorithm for the function [f] to
835 [gc]. See the method [llvm::Function::setCollector]. *)
836 external set_collector : string option -> llvalue -> unit = "llvm_set_collector"
839 (** {7 Operations on params} *)
841 (** [params f] returns the parameters of function [f].
842 See the method [llvm::Function::getArgumentList]. *)
843 external params : llvalue -> llvalue array = "llvm_params"
845 (** [param f n] returns the [n]th parameter of function [f].
846 See the method [llvm::Function::getArgumentList]. *)
847 external param : llvalue -> int -> llvalue = "llvm_param"
849 (** [param_parent p] returns the parent function that owns the parameter.
850 See the method [llvm::Argument::getParent]. *)
851 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
854 (** {7 Operations on basic blocks} *)
856 (** [basic_blocks fn] returns the basic blocks of the function [f].
857 See the method [llvm::Function::getBasicBlockList]. *)
858 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
860 (** [entry_block fn] returns the entry basic block of the function [f].
861 See the method [llvm::Function::getEntryBlock]. *)
862 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
864 (** [delete_block bb] deletes the basic block [bb].
865 See the method [llvm::BasicBlock::eraseFromParent]. *)
866 external delete_block : llbasicblock -> unit = "llvm_delete_block"
868 (** [append_block name f] creates a new basic block named [name] at the end of
870 See the constructor of [llvm::BasicBlock]. *)
871 external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
873 (** [insert_block name bb] creates a new basic block named [name] before the
875 See the constructor of [llvm::BasicBlock]. *)
876 external insert_block : string -> llbasicblock -> llbasicblock
877 = "llvm_insert_block"
879 (** [block_parent bb] returns the parent function that owns the basic block.
880 See the method [llvm::BasicBlock::getParent]. *)
881 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
883 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
884 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
886 (** [value_is_block v] returns [true] if the value [v] is a basic block and
888 Similar to [llvm::isa<BasicBlock>]. *)
889 external value_is_block : llvalue -> bool = "llvm_value_is_block"
891 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
892 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
895 (** {7 Operations on instructions} *)
897 (** [instr_parent i] is the enclosing basic block of the instruction [i].
898 See the method [llvm::Instruction::getParent]. *)
899 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
902 (** {7 Operations on call sites} *)
904 (** [instruction_call_conv ci] is the calling convention for the call or invoke
905 instruction [ci], which may be one of the values from the module
906 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
907 [llvm::InvokeInst::getCallingConv]. *)
908 external instruction_call_conv: llvalue -> int
909 = "llvm_instruction_call_conv"
911 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
912 or invoke instruction [ci] to the integer [cc], which can be one of the
913 values from the module {!CallConv}.
914 See the method [llvm::CallInst::setCallingConv]
915 and [llvm::InvokeInst::setCallingConv]. *)
916 external set_instruction_call_conv: int -> llvalue -> unit
917 = "llvm_set_instruction_call_conv"
920 (** {7 Operations on phi nodes} *)
922 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
923 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
924 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
925 = "llvm_add_incoming"
927 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
928 See the method [llvm::PHINode::getIncomingValue]. *)
929 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
933 (** {6 Instruction builders} *)
935 (** [builder ()] creates an instruction builder with no position. It is invalid
936 to use this builder until its position is set with {!position_before} or
937 {!position_at_end}. See the constructor for [llvm::LLVMBuilder]. *)
938 external builder: unit-> llbuilder
941 (** [builder_before ins] creates an instruction builder positioned before the
942 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
943 external builder_before : llvalue -> llbuilder = "llvm_builder_before"
945 (** [builder_at_end bb] creates an instruction builder positioned at the end of
946 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
947 external builder_at_end : llbasicblock -> llbuilder = "llvm_builder_at_end"
949 (** [position_before ins b] moves the instruction builder [b] to before the
950 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
951 external position_before : llvalue -> llbuilder -> unit = "llvm_position_before"
953 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
954 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
955 external position_at_end : llbasicblock -> llbuilder -> unit
956 = "llvm_position_at_end"
958 (** [insertion_block b] returns the basic block that the builder [b] is
959 positioned to insert into. Raises [Not_Found] if the instruction builder is
961 See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
962 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
965 (** {7 Terminators} *)
967 (** [build_ret_void b] creates a
969 instruction at the position specified by the instruction builder [b].
970 See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
971 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
973 (** [build_ret v b] creates a
975 instruction at the position specified by the instruction builder [b].
976 See the method [llvm::LLVMBuilder::CreateRet]. *)
977 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
979 (** [build_br bb b] creates a
981 instruction at the position specified by the instruction builder [b].
982 See the method [llvm::LLVMBuilder::CreateBr]. *)
983 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
985 (** [build_cond_br cond tbb fbb b] creates a
986 [b %cond, %tbb, %fbb]
987 instruction at the position specified by the instruction builder [b].
988 See the method [llvm::LLVMBuilder::CreateCondBr]. *)
989 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
990 llvalue = "llvm_build_cond_br"
992 (** [build_switch case elsebb b] creates an empty
993 [switch %case, %elsebb]
994 instruction at the position specified by the instruction builder [b].
995 See the method [llvm::LLVMBuilder::CreateSwitch]. *)
996 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
997 = "llvm_build_switch"
999 (** [build_invoke fn args tobb unwindbb name b] creates an
1000 [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1001 instruction at the position specified by the instruction builder [b].
1002 See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1003 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1004 llbasicblock -> string -> llbuilder -> llvalue
1005 = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1007 (** [build_unwind b] creates an
1009 instruction at the position specified by the instruction builder [b].
1010 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1011 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1013 (** [build_unreachable b] creates an
1015 instruction at the position specified by the instruction builder [b].
1016 See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1017 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1020 (** {7 Arithmetic} *)
1022 (** [build_add x y name b] creates a
1023 [%name = add %x, %y]
1024 instruction at the position specified by the instruction builder [b].
1025 See the method [llvm::LLVMBuilder::CreateAdd]. *)
1026 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1029 (** [build_sub x y name b] creates a
1030 [%name = sub %x, %y]
1031 instruction at the position specified by the instruction builder [b].
1032 See the method [llvm::LLVMBuilder::CreateSub]. *)
1033 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1036 (** [build_mul x y name b] creates a
1037 [%name = mul %x, %y]
1038 instruction at the position specified by the instruction builder [b].
1039 See the method [llvm::LLVMBuilder::CreateMul]. *)
1040 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1043 (** [build_udiv x y name b] creates a
1044 [%name = udiv %x, %y]
1045 instruction at the position specified by the instruction builder [b].
1046 See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1047 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1050 (** [build_sdiv x y name b] creates a
1051 [%name = sdiv %x, %y]
1052 instruction at the position specified by the instruction builder [b].
1053 See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1054 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1057 (** [build_fdiv x y name b] creates a
1058 [%name = fdiv %x, %y]
1059 instruction at the position specified by the instruction builder [b].
1060 See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1061 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1064 (** [build_urem x y name b] creates a
1065 [%name = urem %x, %y]
1066 instruction at the position specified by the instruction builder [b].
1067 See the method [llvm::LLVMBuilder::CreateURem]. *)
1068 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1071 (** [build_SRem x y name b] creates a
1072 [%name = srem %x, %y]
1073 instruction at the position specified by the instruction builder [b].
1074 See the method [llvm::LLVMBuilder::CreateSRem]. *)
1075 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1078 (** [build_frem x y name b] creates a
1079 [%name = frem %x, %y]
1080 instruction at the position specified by the instruction builder [b].
1081 See the method [llvm::LLVMBuilder::CreateFRem]. *)
1082 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1085 (** [build_shl x y name b] creates a
1086 [%name = shl %x, %y]
1087 instruction at the position specified by the instruction builder [b].
1088 See the method [llvm::LLVMBuilder::CreateShl]. *)
1089 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1092 (** [build_lshr x y name b] creates a
1093 [%name = lshr %x, %y]
1094 instruction at the position specified by the instruction builder [b].
1095 See the method [llvm::LLVMBuilder::CreateLShr]. *)
1096 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1099 (** [build_ashr x y name b] creates a
1100 [%name = ashr %x, %y]
1101 instruction at the position specified by the instruction builder [b].
1102 See the method [llvm::LLVMBuilder::CreateAShr]. *)
1103 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1106 (** [build_and x y name b] creates a
1107 [%name = and %x, %y]
1108 instruction at the position specified by the instruction builder [b].
1109 See the method [llvm::LLVMBuilder::CreateAnd]. *)
1110 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1113 (** [build_or x y name b] creates a
1115 instruction at the position specified by the instruction builder [b].
1116 See the method [llvm::LLVMBuilder::CreateOr]. *)
1117 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1120 (** [build_xor x y name b] creates a
1121 [%name = xor %x, %y]
1122 instruction at the position specified by the instruction builder [b].
1123 See the method [llvm::LLVMBuilder::CreateXor]. *)
1124 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1127 (** [build_neg x name b] creates a
1129 instruction at the position specified by the instruction builder [b].
1130 [-0.0] is used for floating point types to compute the correct sign.
1131 See the method [llvm::LLVMBuilder::CreateNeg]. *)
1132 external build_neg : llvalue -> string -> llbuilder -> llvalue
1135 (** [build_xor x name b] creates a
1136 [%name = xor %x, -1]
1137 instruction at the position specified by the instruction builder [b].
1138 [-1] is the correct "all ones" value for the type of [x].
1139 See the method [llvm::LLVMBuilder::CreateXor]. *)
1140 external build_not : llvalue -> string -> llbuilder -> llvalue
1146 (** [build_malloc ty name b] creates a
1147 [%name = malloc %ty]
1148 instruction at the position specified by the instruction builder [b].
1149 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1150 external build_malloc : lltype -> string -> llbuilder -> llvalue
1151 = "llvm_build_malloc"
1153 (** [build_array_malloc ty n name b] creates a
1154 [%name = malloc %ty, %n]
1155 instruction at the position specified by the instruction builder [b].
1156 See the method [llvm::LLVMBuilder::CreateMalloc]. *)
1157 external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1158 llvalue = "llvm_build_array_malloc"
1160 (** [build_alloca ty name b] creates a
1161 [%name = alloca %ty]
1162 instruction at the position specified by the instruction builder [b].
1163 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1164 external build_alloca : lltype -> string -> llbuilder -> llvalue
1165 = "llvm_build_alloca"
1167 (** [build_array_alloca ty n name b] creates a
1168 [%name = alloca %ty, %n]
1169 instruction at the position specified by the instruction builder [b].
1170 See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1171 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1172 llvalue = "llvm_build_array_alloca"
1174 (** [build_free v b] creates a
1176 instruction at the position specified by the instruction builder [b].
1177 See the method [llvm::LLVMBuilder::CreateFree]. *)
1178 external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1180 (** [build_load v name b] creates a
1182 instruction at the position specified by the instruction builder [b].
1183 See the method [llvm::LLVMBuilder::CreateLoad]. *)
1184 external build_load : llvalue -> string -> llbuilder -> llvalue
1187 (** [build_store v p b] creates a
1189 instruction at the position specified by the instruction builder [b].
1190 See the method [llvm::LLVMBuilder::CreateStore]. *)
1191 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1192 = "llvm_build_store"
1194 (** [build_gep p indices name b] creates a
1195 [%name = gep %p, indices...]
1196 instruction at the position specified by the instruction builder [b].
1197 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1198 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1204 (** [build_trunc v ty name b] creates a
1205 [%name = trunc %p to %ty]
1206 instruction at the position specified by the instruction builder [b].
1207 See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1208 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1209 = "llvm_build_trunc"
1211 (** [build_zext v ty name b] creates a
1212 [%name = zext %p to %ty]
1213 instruction at the position specified by the instruction builder [b].
1214 See the method [llvm::LLVMBuilder::CreateZExt]. *)
1215 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1218 (** [build_sext v ty name b] creates a
1219 [%name = sext %p to %ty]
1220 instruction at the position specified by the instruction builder [b].
1221 See the method [llvm::LLVMBuilder::CreateSExt]. *)
1222 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1225 (** [build_fptoui v ty name b] creates a
1226 [%name = fptoui %p to %ty]
1227 instruction at the position specified by the instruction builder [b].
1228 See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1229 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1230 = "llvm_build_fptoui"
1232 (** [build_fptosi v ty name b] creates a
1233 [%name = fptosi %p to %ty]
1234 instruction at the position specified by the instruction builder [b].
1235 See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1236 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1237 = "llvm_build_fptosi"
1239 (** [build_uitofp v ty name b] creates a
1240 [%name = uitofp %p to %ty]
1241 instruction at the position specified by the instruction builder [b].
1242 See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1243 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1244 = "llvm_build_uitofp"
1246 (** [build_sitofp v ty name b] creates a
1247 [%name = sitofp %p to %ty]
1248 instruction at the position specified by the instruction builder [b].
1249 See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1250 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1251 = "llvm_build_sitofp"
1253 (** [build_fptrunc v ty name b] creates a
1254 [%name = fptrunc %p to %ty]
1255 instruction at the position specified by the instruction builder [b].
1256 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1257 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1258 = "llvm_build_fptrunc"
1260 (** [build_fpext v ty name b] creates a
1261 [%name = fpext %p to %ty]
1262 instruction at the position specified by the instruction builder [b].
1263 See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1264 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1265 = "llvm_build_fpext"
1267 (** [build_ptrtoint v ty name b] creates a
1268 [%name = prtotint %p to %ty]
1269 instruction at the position specified by the instruction builder [b].
1270 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1271 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1272 = "llvm_build_prttoint"
1274 (** [build_inttoptr v ty name b] creates a
1275 [%name = inttoptr %p to %ty]
1276 instruction at the position specified by the instruction builder [b].
1277 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1278 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1279 = "llvm_build_inttoptr"
1281 (** [build_bitcast v ty name b] creates a
1282 [%name = bitcast %p to %ty]
1283 instruction at the position specified by the instruction builder [b].
1284 See the method [llvm::LLVMBuilder::CreateBitcast]. *)
1285 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1286 = "llvm_build_bitcast"
1289 (** {7 Comparisons} *)
1291 (** [build_icmp pred x y name b] creates a
1292 [%name = icmp %pred %x, %y]
1293 instruction at the position specified by the instruction builder [b].
1294 See the method [llvm::LLVMBuilder::CreateICmp]. *)
1295 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1296 llbuilder -> llvalue = "llvm_build_icmp"
1298 (** [build_fcmp pred x y name b] creates a
1299 [%name = fcmp %pred %x, %y]
1300 instruction at the position specified by the instruction builder [b].
1301 See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1302 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1303 llbuilder -> llvalue = "llvm_build_fcmp"
1306 (** {7 Miscellaneous instructions} *)
1308 (** [build_phi incoming name b] creates a
1309 [%name = phi %incoming]
1310 instruction at the position specified by the instruction builder [b].
1311 [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1312 See the method [llvm::LLVMBuilder::CreatePHI]. *)
1313 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1314 llvalue = "llvm_build_phi"
1316 (** [build_call fn args name b] creates a
1317 [%name = call %fn(args...)]
1318 instruction at the position specified by the instruction builder [b].
1319 See the method [llvm::LLVMBuilder::CreateCall]. *)
1320 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1323 (** [build_select cond thenv elsev name b] creates a
1324 [%name = select %cond, %thenv, %elsev]
1325 instruction at the position specified by the instruction builder [b].
1326 See the method [llvm::LLVMBuilder::CreateSelect]. *)
1327 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1328 llvalue = "llvm_build_select"
1330 (** [build_va_arg valist argty name b] creates a
1331 [%name = va_arg %valist, %argty]
1332 instruction at the position specified by the instruction builder [b].
1333 See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1334 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1335 = "llvm_build_va_arg"
1337 (** [build_extractelement vec i name b] creates a
1338 [%name = extractelement %vec, %i]
1339 instruction at the position specified by the instruction builder [b].
1340 See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1341 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1342 llvalue = "llvm_build_extractelement"
1344 (** [build_insertelement vec elt i name b] creates a
1345 [%name = insertelement %vec, %elt, %i]
1346 instruction at the position specified by the instruction builder [b].
1347 See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1348 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1349 llbuilder -> llvalue = "llvm_build_insertelement"
1351 (** [build_shufflevector veca vecb mask name b] creates a
1352 [%name = shufflevector %veca, %vecb, %mask]
1353 instruction at the position specified by the instruction builder [b].
1354 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1355 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1356 llbuilder -> llvalue = "llvm_build_shufflevector"
1359 (** {6 Module providers} *)
1361 module ModuleProvider : sig
1362 (** [create_module_provider m] encapsulates [m] in a module provider and takes
1363 ownership of the module. See the constructor
1364 [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
1365 external create : llmodule -> llmoduleprovider
1366 = "LLVMCreateModuleProviderForExistingModule"
1368 (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1369 the contained module. *)
1370 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1374 (** {6 Memory buffers} *)
1376 module MemoryBuffer : sig
1377 (** [of_file p] is the memory buffer containing the contents of the file at
1378 path [p]. If the file could not be read, then [IoError msg] is
1380 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1382 (** [stdin ()] is the memory buffer containing the contents of standard input.
1383 If standard input is empty, then [IoError msg] is raised. *)
1384 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1386 (** Disposes of a memory buffer. *)
1387 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
1391 (** {6 Pass Managers} *)
1393 module PassManager : sig
1396 type any = [ `Module | `Function ]
1398 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
1399 type of pipeline is suitable for link-time optimization and whole-module
1401 See the constructor of [llvm::PassManager]. *)
1402 external create : unit -> [ `Module ] t = "llvm_passmanager_create"
1404 (** [PassManager.create_function mp] constructs a new function-by-function
1405 pass pipeline over the module provider [mp]. It does not take ownership of
1406 [mp]. This type of pipeline is suitable for code generation and JIT
1408 See the constructor of [llvm::FunctionPassManager]. *)
1409 external create_function : llmoduleprovider -> [ `Function ] t
1410 = "LLVMCreateFunctionPassManager"
1412 (** [run_module m pm] initializes, executes on the module [m], and finalizes
1413 all of the passes scheduled in the pass manager [pm]. Returns [true] if
1414 any of the passes modified the module, [false] otherwise.
1415 See the [llvm::PassManager::run] method. *)
1416 external run_module : llmodule -> [ `Module ] t -> bool
1417 = "llvm_passmanager_run_module"
1419 (** [initialize fpm] initializes all of the function passes scheduled in the
1420 function pass manager [fpm]. Returns [true] if any of the passes modified
1421 the module, [false] otherwise.
1422 See the [llvm::FunctionPassManager::doInitialization] method. *)
1423 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
1425 (** [run_function f fpm] executes all of the function passes scheduled in the
1426 function pass manager [fpm] over the function [f]. Returns [true] if any
1427 of the passes modified [f], [false] otherwise.
1428 See the [llvm::FunctionPassManager::run] method. *)
1429 external run_function : llvalue -> [ `Function ] t -> bool
1430 = "llvm_passmanager_run_function"
1432 (** [finalize fpm] finalizes all of the function passes scheduled in in the
1433 function pass manager [fpm]. Returns [true] if any of the passes
1434 modified the module, [false] otherwise.
1435 See the [llvm::FunctionPassManager::doFinalization] method. *)
1436 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
1438 (** Frees the memory of a pass pipeline. For function pipelines, does not free
1439 the module provider.
1440 See the destructor of [llvm::BasePassManager]. *)
1441 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"