llvm.mli revision 5371aa2a1c9a4eeecffdb9ab7b2175732e49475b
1(*===-- llvm/llvm.mli - LLVM Ocaml Interface -------------------------------===* 2 * 3 * The LLVM Compiler Infrastructure 4 * 5 * This file is distributed under the University of Illinois Open Source 6 * License. See LICENSE.TXT for details. 7 * 8 *===----------------------------------------------------------------------===*) 9 10(** Core API. 11 12 This interface provides an ocaml API for the LLVM intermediate 13 representation, the classes in the VMCore library. *) 14 15 16(** {6 Abstract types} 17 18 These abstract types correlate directly to the LLVM VMCore classes. *) 19 20(** The top-level container for all LLVM global data. See the 21 [llvm::LLVMContext] class. *) 22type llcontext 23 24(** The top-level container for all other LLVM Intermediate Representation (IR) 25 objects. See the [llvm::Module] class. *) 26type llmodule 27 28(** Each value in the LLVM IR has a type, an instance of [lltype]. See the 29 [llvm::Type] class. *) 30type lltype 31 32(** When building recursive types using {!refine_type}, [lltype] values may 33 become invalid; use [lltypehandle] to resolve this problem. See the 34 [llvm::AbstractTypeHolder] class. *) 35type lltypehandle 36 37(** Any value in the LLVM IR. Functions, instructions, global variables, 38 constants, and much more are all [llvalues]. See the [llvm::Value] class. 39 This type covers a wide range of subclasses. *) 40type llvalue 41 42(** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *) 43type llbasicblock 44 45(** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder] 46 class. *) 47type llbuilder 48 49(** Used to provide a module to JIT or interpreter. 50 See the [llvm::ModuleProvider] class. *) 51type llmoduleprovider 52 53(** Used to efficiently handle large buffers of read-only binary data. 54 See the [llvm::MemoryBuffer] class. *) 55type llmemorybuffer 56 57(** The kind of an [lltype], the result of [classify_type ty]. See the 58 [llvm::Type::TypeID] enumeration. *) 59module TypeKind : sig 60 type t = 61 Void 62 | Float 63 | Double 64 | X86fp80 65 | Fp128 66 | Ppc_fp128 67 | Label 68 | Integer 69 | Function 70 | Struct 71 | Array 72 | Pointer 73 | Opaque 74 | Vector 75 | Metadata 76end 77 78(** The linkage of a global value, accessed with {!linkage} and 79 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *) 80module Linkage : sig 81 type t = 82 External 83 | Available_externally 84 | Link_once 85 | Weak 86 | Appending 87 | Internal 88 | Dllimport 89 | Dllexport 90 | External_weak 91 | Ghost 92end 93 94(** The linker visibility of a global value, accessed with {!visibility} and 95 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *) 96module Visibility : sig 97 type t = 98 Default 99 | Hidden 100 | Protected 101end 102 103(** The following calling convention values may be accessed with 104 {!function_call_conv} and {!set_function_call_conv}. Calling 105 conventions are open-ended. *) 106module CallConv : sig 107 val c : int (** [c] is the C calling convention. *) 108 val fast : int (** [fast] is the calling convention to allow LLVM 109 maximum optimization opportunities. Use only with 110 internal linkage. *) 111 val cold : int (** [cold] is the calling convention for 112 callee-save. *) 113 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling 114 convention from C. *) 115 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling 116 convention from C. *) 117end 118 119module Attribute : sig 120 type t = 121 | Zext 122 | Sext 123 | Noreturn 124 | Inreg 125 | Structret 126 | Nounwind 127 | Noalias 128 | Byval 129 | Nest 130 | Readnone 131 | Readonly 132end 133 134(** The predicate for an integer comparison ([icmp]) instruction. 135 See the [llvm::ICmpInst::Predicate] enumeration. *) 136module Icmp : sig 137 type t = 138 | Eq 139 | Ne 140 | Ugt 141 | Uge 142 | Ult 143 | Ule 144 | Sgt 145 | Sge 146 | Slt 147 | Sle 148end 149 150(** The predicate for a floating-point comparison ([fcmp]) instruction. 151 See the [llvm::FCmpInst::Predicate] enumeration. *) 152module Fcmp : sig 153 type t = 154 | False 155 | Oeq 156 | Ogt 157 | Oge 158 | Olt 159 | Ole 160 | One 161 | Ord 162 | Uno 163 | Ueq 164 | Ugt 165 | Uge 166 | Ult 167 | Ule 168 | Une 169 | True 170end 171 172 173(** {6 Iteration} *) 174 175(** [Before b] and [At_end a] specify positions from the start of the ['b] list 176 of [a]. [llpos] is used to specify positions in and for forward iteration 177 through the various value lists maintained by the LLVM IR. *) 178type ('a, 'b) llpos = 179| At_end of 'a 180| Before of 'b 181 182(** [After b] and [At_start a] specify positions from the end of the ['b] list 183 of [a]. [llrev_pos] is used for reverse iteration through the various value 184 lists maintained by the LLVM IR. *) 185type ('a, 'b) llrev_pos = 186| At_start of 'a 187| After of 'b 188 189 190(** {6 Exceptions} *) 191 192exception IoError of string 193 194 195(** {6 Contexts} *) 196 197(** [create_context ()] creates a context for storing the "global" state in 198 LLVM. See the constructor [llvm::LLVMContext]. *) 199external create_context : unit -> llcontext = "llvm_create_context" 200 201(** [destroy_context ()] destroys a context. See the destructor 202 [llvm::LLVMContext::~LLVMContext]. *) 203external dispose_context : unit -> llcontext = "llvm_dispose_context" 204 205(** See the function [llvm::getGlobalContext]. *) 206external global_context : unit -> llcontext = "llvm_global_context" 207 208 209(** {6 Modules} *) 210 211(** [create_module context id] creates a module with the supplied module ID in 212 the context [context]. Modules are not garbage collected; it is mandatory 213 to call {!dispose_module} to free memory. See the constructor 214 [llvm::Module::Module]. *) 215external create_module : llcontext -> string -> llmodule = "llvm_create_module" 216 217(** [dispose_module m] destroys a module [m] and all of the IR objects it 218 contained. All references to subordinate objects are invalidated; 219 referencing them will invoke undefined behavior. See the destructor 220 [llvm::Module::~Module]. *) 221external dispose_module : llmodule -> unit = "llvm_dispose_module" 222 223(** [target_triple m] is the target specifier for the module [m], something like 224 [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *) 225external target_triple: llmodule -> string 226 = "llvm_target_triple" 227 228(** [target_triple triple m] changes the target specifier for the module [m] to 229 the string [triple]. See the method [llvm::Module::setTargetTriple]. *) 230external set_target_triple: string -> llmodule -> unit 231 = "llvm_set_target_triple" 232 233(** [data_layout m] is the data layout specifier for the module [m], something 234 like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the 235 method [llvm::Module::getDataLayout]. *) 236external data_layout: llmodule -> string 237 = "llvm_data_layout" 238 239(** [set_data_layout s m] changes the data layout specifier for the module [m] 240 to the string [s]. See the method [llvm::Module::setDataLayout]. *) 241external set_data_layout: string -> llmodule -> unit 242 = "llvm_set_data_layout" 243 244(** [define_type_name name ty m] adds a named type to the module's symbol table. 245 Returns [true] if successful. If such a name already exists, then no entry 246 is added and [false] is returned. See the [llvm::Module::addTypeName] 247 method. *) 248external define_type_name : string -> lltype -> llmodule -> bool 249 = "llvm_add_type_name" 250 251(** [delete_type_name name] removes a type name from the module's symbol 252 table. *) 253external delete_type_name : string -> llmodule -> unit 254 = "llvm_delete_type_name" 255 256(** [dump_module m] prints the .ll representation of the module [m] to standard 257 error. See the method [llvm::Module::dump]. *) 258external dump_module : llmodule -> unit = "llvm_dump_module" 259 260 261(** {6 Types} *) 262 263(** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty]. 264 See the method [llvm::Type::getTypeID]. *) 265external classify_type : lltype -> TypeKind.t = "llvm_classify_type" 266 267(** [type_context ty] returns the {!llcontext} corresponding to the type [ty]. 268 See the method [llvm::Type::getContext]. *) 269external type_context : lltype -> llcontext = "llvm_type_context" 270 271(** [string_of_lltype ty] returns a string describing the type [ty]. *) 272val string_of_lltype : lltype -> string 273 274(** {7 Operations on integer types} *) 275 276(** The 1-bit integer type. See [llvm::Type::Int1Ty]. *) 277val i1_type : lltype 278 279(** The 8-bit integer type. See [llvm::Type::Int8Ty]. *) 280val i8_type : lltype 281 282(** The 16-bit integer type. See [llvm::Type::Int16Ty]. *) 283val i16_type : lltype 284 285(** The 32-bit integer type. See [llvm::Type::Int32Ty]. *) 286val i32_type : lltype 287 288(** The 64-bit integer type. See [llvm::Type::Int64Ty]. *) 289val i64_type : lltype 290 291(** [integer_type n] returns an integer type of bitwidth [n]. 292 See the method [llvm::IntegerType::get]. *) 293external integer_type : int -> lltype = "llvm_integer_type" 294 295(** [integer_bitwidth ty] returns the number of bits in the integer type [ty]. 296 See the method [llvm::IntegerType::getBitWidth]. *) 297external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth" 298 299 300(** {7 Operations on real types} *) 301 302(** The IEEE 32-bit floating point type. See [llvm::Type::FloatTy]. *) 303val float_type : lltype 304 305(** The IEEE 64-bit floating point type. See [llvm::Type::DoubleTy]. *) 306val double_type : lltype 307 308(** The x87 80-bit floating point type. See [llvm::Type::X86_FP80Ty]. *) 309val x86fp80_type : lltype 310 311(** The IEEE 128-bit floating point type. See [llvm::Type::FP128Ty]. *) 312val fp128_type : lltype 313 314(** The PowerPC 128-bit floating point type. See [llvm::Type::PPC_FP128Ty]. *) 315val ppc_fp128_type : lltype 316 317 318(** {7 Operations on function types} *) 319 320(** [function_type ret_ty param_tys] returns the function type returning 321 [ret_ty] and taking [param_tys] as parameters. 322 See the method [llvm::FunctionType::get]. *) 323external function_type : lltype -> lltype array -> lltype = "llvm_function_type" 324 325(** [va_arg_function_type ret_ty param_tys] is just like 326 [function_type ret_ty param_tys] except that it returns the function type 327 which also takes a variable number of arguments. 328 See the method [llvm::FunctionType::get]. *) 329external var_arg_function_type : lltype -> lltype array -> lltype 330 = "llvm_var_arg_function_type" 331 332(** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false] 333 otherwise. See the method [llvm::FunctionType::isVarArg]. *) 334external is_var_arg : lltype -> bool = "llvm_is_var_arg" 335 336(** [return_type fty] gets the return type of the function type [fty]. 337 See the method [llvm::FunctionType::getReturnType]. *) 338external return_type : lltype -> lltype = "LLVMGetReturnType" 339 340(** [param_types fty] gets the parameter types of the function type [fty]. 341 See the method [llvm::FunctionType::getParamType]. *) 342external param_types : lltype -> lltype array = "llvm_param_types" 343 344 345(** {7 Operations on struct types} *) 346 347(** [struct_type context tys] returns the structure type in the context 348 [context] containing in the types in the array [tys]. See the method 349 [llvm::StructType::get]. *) 350external struct_type : llcontext -> lltype array -> lltype 351 = "llvm_struct_type" 352 353(** [packed_struct_type context ys] returns the packed structure type in the 354 context [context] containing in the types in the array [tys]. See the method 355 [llvm::StructType::get]. *) 356external packed_struct_type : llcontext -> lltype array -> lltype 357 = "llvm_packed_struct_type" 358 359(** [element_types sty] returns the constituent types of the struct type [sty]. 360 See the method [llvm::StructType::getElementType]. *) 361external element_types : lltype -> lltype array = "llvm_element_types" 362 363(** [is_packed sty] returns [true] if the structure type [sty] is packed, 364 [false] otherwise. See the method [llvm::StructType::isPacked]. *) 365external is_packed : lltype -> bool = "llvm_is_packed" 366 367 368(** {7 Operations on pointer, vector, and array types} *) 369 370(** [array_type ty n] returns the array type containing [n] elements of type 371 [ty]. See the method [llvm::ArrayType::get]. *) 372external array_type : lltype -> int -> lltype = "llvm_array_type" 373 374(** [pointer_type ty] returns the pointer type referencing objects of type 375 [ty] in the default address space (0). 376 See the method [llvm::PointerType::getUnqual]. *) 377external pointer_type : lltype -> lltype = "llvm_pointer_type" 378 379(** [qualified_pointer_type ty as] returns the pointer type referencing objects 380 of type [ty] in address space [as]. 381 See the method [llvm::PointerType::get]. *) 382external qualified_pointer_type : lltype -> int -> lltype 383 = "llvm_qualified_pointer_type" 384 385(** [vector_type ty n] returns the array type containing [n] elements of the 386 primitive type [ty]. See the method [llvm::ArrayType::get]. *) 387external vector_type : lltype -> int -> lltype = "llvm_vector_type" 388 389(** [element_type ty] returns the element type of the pointer, vector, or array 390 type [ty]. See the method [llvm::SequentialType::get]. *) 391external element_type : lltype -> lltype = "LLVMGetElementType" 392 393(** [element_type aty] returns the element count of the array type [aty]. 394 See the method [llvm::ArrayType::getNumElements]. *) 395external array_length : lltype -> int = "llvm_array_length" 396 397(** [address_space pty] returns the address space qualifier of the pointer type 398 [pty]. See the method [llvm::PointerType::getAddressSpace]. *) 399external address_space : lltype -> int = "llvm_address_space" 400 401(** [element_type ty] returns the element count of the vector type [ty]. 402 See the method [llvm::VectorType::getNumElements]. *) 403external vector_size : lltype -> int = "llvm_vector_size" 404 405 406(** {7 Operations on other types} *) 407 408(** [opaque_type ()] creates a new opaque type distinct from any other. 409 Opaque types are useful for building recursive types in combination with 410 {!refine_type}. 411 See [llvm::OpaqueType::get]. *) 412external opaque_type : unit -> lltype = "llvm_opaque_type" 413 414(** [void_type] is the type of a function which does not return any value. 415 See [llvm::Type::VoidTy]. *) 416val void_type : lltype 417 418(** [label_type] is the type of a basic block. See [llvm::Type::LabelTy]. *) 419val label_type : lltype 420 421(** {7 Operations on type handles} *) 422 423(** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later 424 refined as a result of a call to {!refine_type}, the handle will be updated; 425 any bare [lltype] references will become invalid. 426 See the class [llvm::PATypeHolder]. *) 427external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type" 428 429(** [type_of_handle tyh] resolves the type handle [tyh]. 430 See the method [llvm::PATypeHolder::get()]. *) 431external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle" 432 433(** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the 434 concrete type [ty] in all users. Warning: This may invalidate {!lltype} 435 values! Use {!lltypehandle} to manipulate potentially abstract types. See 436 the method [llvm::Type::refineAbstractType]. *) 437external refine_type : lltype -> lltype -> unit = "llvm_refine_type" 438 439 440(* {6 Values} *) 441 442(** [type_of v] returns the type of the value [v]. 443 See the method [llvm::Value::getType]. *) 444external type_of : llvalue -> lltype = "llvm_type_of" 445 446(** [value_name v] returns the name of the value [v]. For global values, this is 447 the symbol name. For instructions and basic blocks, it is the SSA register 448 name. It is meaningless for constants. 449 See the method [llvm::Value::getName]. *) 450external value_name : llvalue -> string = "llvm_value_name" 451 452(** [set_value_name n v] sets the name of the value [v] to [n]. See the method 453 [llvm::Value::setName]. *) 454external set_value_name : string -> llvalue -> unit = "llvm_set_value_name" 455 456(** [dump_value v] prints the .ll representation of the value [v] to standard 457 error. See the method [llvm::Value::dump]. *) 458external dump_value : llvalue -> unit = "llvm_dump_value" 459 460 461(** {7 Operations on constants of (mostly) any type} *) 462 463(** [is_constant v] returns [true] if the value [v] is a constant, [false] 464 otherwise. Similar to [llvm::isa<Constant>]. *) 465external is_constant : llvalue -> bool = "llvm_is_constant" 466 467(** [const_null ty] returns the constant null (zero) of the type [ty]. 468 See the method [llvm::Constant::getNullValue]. *) 469external const_null : lltype -> llvalue = "LLVMConstNull" 470 471(** [const_all_ones ty] returns the constant '-1' of the integer or vector type 472 [ty]. See the method [llvm::Constant::getAllOnesValue]. *) 473external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes" 474 475(** [undef ty] returns the undefined value of the type [ty]. 476 See the method [llvm::UndefValue::get]. *) 477external undef : lltype -> llvalue = "LLVMGetUndef" 478 479(** [is_null v] returns [true] if the value [v] is the null (zero) value. 480 See the method [llvm::Constant::isNullValue]. *) 481external is_null : llvalue -> bool = "llvm_is_null" 482 483(** [is_undef v] returns [true] if the value [v] is an undefined value, [false] 484 otherwise. Similar to [llvm::isa<UndefValue>]. *) 485external is_undef : llvalue -> bool = "llvm_is_undef" 486 487 488(** {7 Operations on scalar constants} *) 489 490(** [const_int ty i] returns the integer constant of type [ty] and value [i]. 491 See the method [llvm::ConstantInt::get]. *) 492external const_int : lltype -> int -> llvalue = "llvm_const_int" 493 494(** [const_of_int64 ty i] returns the integer constant of type [ty] and value 495 [i]. See the method [llvm::ConstantInt::get]. *) 496external const_of_int64 : lltype -> Int64.t -> bool -> llvalue 497 = "llvm_const_of_int64" 498 499(** [const_int_of_string ty s r] returns the integer constant of type [ty] and 500 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *) 501external const_int_of_string : lltype -> string -> int -> llvalue 502 = "llvm_const_int_of_string" 503 504(** [const_float ty n] returns the floating point constant of type [ty] and 505 value [n]. See the method [llvm::ConstantFP::get]. *) 506external const_float : lltype -> float -> llvalue = "llvm_const_float" 507 508(** [const_float_of_string ty s] returns the floating point constant of type 509 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *) 510external const_float_of_string : lltype -> string -> llvalue 511 = "llvm_const_float_of_string" 512 513 514(** {7 Operations on composite constants} *) 515 516(** [const_string s] returns the constant [i8] array with the values of the 517 characters in the string [s]. The array is not null-terminated (but see 518 {!const_stringz}). This value can in turn be used as the initializer for a 519 global variable. See the method [llvm::ConstantArray::get]. *) 520external const_string : string -> llvalue = "llvm_const_string" 521 522(** [const_stringz s] returns the constant [i8] array with the values of the 523 characters in the string [s] and a null terminator. This value can in turn 524 be used as the initializer for a global variable. 525 See the method [llvm::ConstantArray::get]. *) 526external const_stringz : string -> llvalue = "llvm_const_stringz" 527 528(** [const_array ty elts] returns the constant array of type 529 [array_type ty (Array.length elts)] and containing the values [elts]. 530 This value can in turn be used as the initializer for a global variable. 531 See the method [llvm::ConstantArray::get]. *) 532external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array" 533 534(** [const_struct context elts] returns the structured constant of type 535 [struct_type (Array.map type_of elts)] and containing the values [elts] 536 in the context [context]. This value can in turn be used as the initializer 537 for a global variable. See the method [llvm::ConstantStruct::get]. *) 538external const_struct : llcontext -> llvalue array -> llvalue 539 = "llvm_const_struct" 540 541(** [const_packed_struct context elts] returns the structured constant of 542 type {!packed_struct_type} [(Array.map type_of elts)] and containing the 543 values [elts] in the context [context]. This value can in turn be used as 544 the initializer for a global variable. See the method 545 [llvm::ConstantStruct::get]. *) 546external const_packed_struct : llcontext -> llvalue array -> llvalue 547 = "llvm_const_packed_struct" 548 549(** [const_vector elts] returns the vector constant of type 550 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the 551 values [elts]. See the method [llvm::ConstantVector::get]. *) 552external const_vector : llvalue array -> llvalue = "llvm_const_vector" 553 554 555(** {7 Constant expressions} *) 556 557(** [align_of ty] returns the alignof constant for the type [ty]. This is 558 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty})) 559 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably 560 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *) 561external align_of : lltype -> llvalue = "LLVMAlignOf" 562 563(** [size_of ty] returns the sizeof constant for the type [ty]. This is 564 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty)) 565 (const_int i32_type 1)) i64_type], but considerably more readable. 566 See the method [llvm::ConstantExpr::getSizeOf]. *) 567external size_of : lltype -> llvalue = "LLVMSizeOf" 568 569(** [const_neg c] returns the arithmetic negation of the constant [c]. 570 See the method [llvm::ConstantExpr::getNeg]. *) 571external const_neg : llvalue -> llvalue = "LLVMConstNeg" 572 573(** [const_fneg c] returns the arithmetic negation of the constant float [c]. 574 See the method [llvm::ConstantExpr::getFNeg]. *) 575external const_fneg : llvalue -> llvalue = "LLVMConstFNeg" 576 577(** [const_not c] returns the bitwise inverse of the constant [c]. 578 See the method [llvm::ConstantExpr::getNot]. *) 579external const_not : llvalue -> llvalue = "LLVMConstNot" 580 581(** [const_add c1 c2] returns the constant sum of two constants. 582 See the method [llvm::ConstantExpr::getAdd]. *) 583external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd" 584 585(** [const_nsw_add c1 c2] returns the constant sum of two constants with no 586 signed wrapping. The result is undefined if the sum overflows. 587 See the method [llvm::ConstantExpr::getNSWAdd]. *) 588external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd" 589 590(** [const_fadd c1 c2] returns the constant sum of two constant floats. 591 See the method [llvm::ConstantExpr::getFAdd]. *) 592external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd" 593 594(** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two 595 constants. See the method [llvm::ConstantExpr::getSub]. *) 596external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub" 597 598(** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two 599 constant floats. See the method [llvm::ConstantExpr::getFSub]. *) 600external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub" 601 602(** [const_mul c1 c2] returns the constant product of two constants. 603 See the method [llvm::ConstantExpr::getMul]. *) 604external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul" 605 606(** [const_fmul c1 c2] returns the constant product of two constants floats. 607 See the method [llvm::ConstantExpr::getFMul]. *) 608external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul" 609 610(** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned 611 integer constants. 612 See the method [llvm::ConstantExpr::getUDiv]. *) 613external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv" 614 615(** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed 616 integer constants. 617 See the method [llvm::ConstantExpr::getSDiv]. *) 618external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv" 619 620(** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two 621 signed integer constants. The result is undefined if the result is rounded 622 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *) 623external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv" 624 625(** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating 626 point constants. 627 See the method [llvm::ConstantExpr::getFDiv]. *) 628external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv" 629 630(** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two 631 unsigned integer constants. 632 See the method [llvm::ConstantExpr::getURem]. *) 633external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem" 634 635(** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two 636 signed integer constants. 637 See the method [llvm::ConstantExpr::getSRem]. *) 638external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem" 639 640(** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two 641 signed floating point constants. 642 See the method [llvm::ConstantExpr::getFRem]. *) 643external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem" 644 645(** [const_and c1 c2] returns the constant bitwise [AND] of two integer 646 constants. 647 See the method [llvm::ConstantExpr::getAnd]. *) 648external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd" 649 650(** [const_or c1 c2] returns the constant bitwise [OR] of two integer 651 constants. 652 See the method [llvm::ConstantExpr::getOr]. *) 653external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr" 654 655(** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer 656 constants. 657 See the method [llvm::ConstantExpr::getXor]. *) 658external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor" 659 660(** [const_icmp pred c1 c2] returns the constant comparison of two integer 661 constants, [c1 pred c2]. 662 See the method [llvm::ConstantExpr::getICmp]. *) 663external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue 664 = "llvm_const_icmp" 665 666(** [const_fcmp pred c1 c2] returns the constant comparison of two floating 667 point constants, [c1 pred c2]. 668 See the method [llvm::ConstantExpr::getFCmp]. *) 669external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue 670 = "llvm_const_fcmp" 671 672(** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the 673 constant integer [c2]. 674 See the method [llvm::ConstantExpr::getShl]. *) 675external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl" 676 677(** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the 678 constant integer [c2] with zero extension. 679 See the method [llvm::ConstantExpr::getLShr]. *) 680external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr" 681 682(** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the 683 constant integer [c2] with sign extension. 684 See the method [llvm::ConstantExpr::getAShr]. *) 685external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr" 686 687(** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the 688 constant integers indices from the array [indices]. 689 See the method [llvm::ConstantExpr::getGetElementPtr]. *) 690external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep" 691 692(** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1] 693 with the constant integers indices from the array [indices]. 694 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *) 695external const_in_bounds_gep : llvalue -> llvalue array -> llvalue 696 = "llvm_const_in_bounds_gep" 697 698(** [const_trunc c ty] returns the constant truncation of integer constant [c] 699 to the smaller integer type [ty]. 700 See the method [llvm::ConstantExpr::getTrunc]. *) 701external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc" 702 703(** [const_sext c ty] returns the constant sign extension of integer constant 704 [c] to the larger integer type [ty]. 705 See the method [llvm::ConstantExpr::getSExt]. *) 706external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt" 707 708(** [const_zext c ty] returns the constant zero extension of integer constant 709 [c] to the larger integer type [ty]. 710 See the method [llvm::ConstantExpr::getZExt]. *) 711external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt" 712 713(** [const_fptrunc c ty] returns the constant truncation of floating point 714 constant [c] to the smaller floating point type [ty]. 715 See the method [llvm::ConstantExpr::getFPTrunc]. *) 716external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc" 717 718(** [const_fpext c ty] returns the constant extension of floating point constant 719 [c] to the larger floating point type [ty]. 720 See the method [llvm::ConstantExpr::getFPExt]. *) 721external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt" 722 723(** [const_uitofp c ty] returns the constant floating point conversion of 724 unsigned integer constant [c] to the floating point type [ty]. 725 See the method [llvm::ConstantExpr::getUIToFP]. *) 726external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP" 727 728(** [const_sitofp c ty] returns the constant floating point conversion of 729 signed integer constant [c] to the floating point type [ty]. 730 See the method [llvm::ConstantExpr::getSIToFP]. *) 731external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP" 732 733(** [const_fptoui c ty] returns the constant unsigned integer conversion of 734 floating point constant [c] to integer type [ty]. 735 See the method [llvm::ConstantExpr::getFPToUI]. *) 736external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI" 737 738(** [const_fptoui c ty] returns the constant unsigned integer conversion of 739 floating point constant [c] to integer type [ty]. 740 See the method [llvm::ConstantExpr::getFPToSI]. *) 741external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI" 742 743(** [const_ptrtoint c ty] returns the constant integer conversion of 744 pointer constant [c] to integer type [ty]. 745 See the method [llvm::ConstantExpr::getPtrToInt]. *) 746external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt" 747 748(** [const_inttoptr c ty] returns the constant pointer conversion of 749 integer constant [c] to pointer type [ty]. 750 See the method [llvm::ConstantExpr::getIntToPtr]. *) 751external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr" 752 753(** [const_bitcast c ty] returns the constant bitwise conversion of constant [c] 754 to type [ty] of equal size. 755 See the method [llvm::ConstantExpr::getBitCast]. *) 756external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast" 757 758(** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast 759 conversion of constant [c] to type [ty]. 760 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *) 761external const_zext_or_bitcast : llvalue -> lltype -> llvalue 762 = "LLVMConstZExtOrBitCast" 763 764(** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast 765 conversion of constant [c] to type [ty]. 766 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *) 767external const_sext_or_bitcast : llvalue -> lltype -> llvalue 768 = "LLVMConstSExtOrBitCast" 769 770(** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast 771 conversion of constant [c] to type [ty]. 772 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *) 773external const_trunc_or_bitcast : llvalue -> lltype -> llvalue 774 = "LLVMConstTruncOrBitCast" 775 776(** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int 777 cast conversion of constant [c] to type [ty] of equal size. 778 See the method [llvm::ConstantExpr::getPointerCast]. *) 779external const_pointercast : llvalue -> lltype -> llvalue 780 = "LLVMConstPointerCast" 781 782(** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer 783 -> integer casts of constant [c] to type [ty]. 784 See the method [llvm::ConstantExpr::getIntCast]. *) 785external const_intcast : llvalue -> lltype -> llvalue 786 = "LLVMConstIntCast" 787 788(** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp -> 789 fp casts of constant [c] to type [ty]. 790 See the method [llvm::ConstantExpr::getFPCast]. *) 791external const_fpcast : llvalue -> lltype -> llvalue 792 = "LLVMConstFPCast" 793 794(** [const_select cond t f] returns the constant conditional which returns value 795 [t] if the boolean constant [cond] is true and the value [f] otherwise. 796 See the method [llvm::ConstantExpr::getSelect]. *) 797external const_select : llvalue -> llvalue -> llvalue -> llvalue 798 = "LLVMConstSelect" 799 800(** [const_extractelement vec i] returns the constant [i]th element of 801 constant vector [vec]. [i] must be a constant [i32] value unsigned less than 802 the size of the vector. 803 See the method [llvm::ConstantExpr::getExtractElement]. *) 804external const_extractelement : llvalue -> llvalue -> llvalue 805 = "LLVMConstExtractElement" 806 807(** [const_insertelement vec v i] returns the constant vector with the same 808 elements as constant vector [v] but the [i]th element replaced by the 809 constant [v]. [v] must be a constant value with the type of the vector 810 elements. [i] must be a constant [i32] value unsigned less than the size 811 of the vector. 812 See the method [llvm::ConstantExpr::getInsertElement]. *) 813external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue 814 = "LLVMConstInsertElement" 815 816(** [const_shufflevector a b mask] returns a constant [shufflevector]. 817 See the LLVM Language Reference for details on the [sufflevector] 818 instruction. 819 See the method [llvm::ConstantExpr::getShuffleVector]. *) 820external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue 821 = "LLVMConstShuffleVector" 822 823(** [const_extractvalue agg idxs] returns the constant [idxs]th value of 824 constant aggregate [agg]. Each [idxs] must be less than the size of the 825 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *) 826external const_extractvalue : llvalue -> int array -> llvalue 827 = "llvm_const_extractvalue" 828 829(** [const_insertvalue agg val idxs] inserts the value [val] in the specified 830 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size 831 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *) 832external const_insertvalue : llvalue -> llvalue -> int array -> llvalue 833 = "llvm_const_insertvalue" 834 835 836(** {7 Operations on global variables, functions, and aliases (globals)} *) 837 838(** [global_parent g] is the enclosing module of the global value [g]. 839 See the method [llvm::GlobalValue::getParent]. *) 840external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent" 841 842(** [is_declaration g] returns [true] if the global value [g] is a declaration 843 only. Returns [false] otherwise. 844 See the method [llvm::GlobalValue::isDeclaration]. *) 845external is_declaration : llvalue -> bool = "llvm_is_declaration" 846 847(** [linkage g] returns the linkage of the global value [g]. 848 See the method [llvm::GlobalValue::getLinkage]. *) 849external linkage : llvalue -> Linkage.t = "llvm_linkage" 850 851(** [set_linkage l g] sets the linkage of the global value [g] to [l]. 852 See the method [llvm::GlobalValue::setLinkage]. *) 853external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage" 854 855(** [section g] returns the linker section of the global value [g]. 856 See the method [llvm::GlobalValue::getSection]. *) 857external section : llvalue -> string = "llvm_section" 858 859(** [set_section s g] sets the linker section of the global value [g] to [s]. 860 See the method [llvm::GlobalValue::setSection]. *) 861external set_section : string -> llvalue -> unit = "llvm_set_section" 862 863(** [visibility g] returns the linker visibility of the global value [g]. 864 See the method [llvm::GlobalValue::getVisibility]. *) 865external visibility : llvalue -> Visibility.t = "llvm_visibility" 866 867(** [set_visibility v g] sets the linker visibility of the global value [g] to 868 [v]. See the method [llvm::GlobalValue::setVisibility]. *) 869external set_visibility : Visibility.t -> llvalue -> unit 870 = "llvm_set_visibility" 871 872(** [alignment g] returns the required alignment of the global value [g]. 873 See the method [llvm::GlobalValue::getAlignment]. *) 874external alignment : llvalue -> int = "llvm_alignment" 875 876(** [set_alignment n g] sets the required alignment of the global value [g] to 877 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *) 878external set_alignment : int -> llvalue -> unit = "llvm_set_alignment" 879 880 881(** {7 Operations on global variables} *) 882 883(** [declare_global ty name m] returns a new global variable of type [ty] and 884 with name [name] in module [m]. If such a global variable already exists, 885 it is returned. If the type of the existing global differs, then a bitcast 886 to [ty] is returned. *) 887external declare_global : lltype -> string -> llmodule -> llvalue 888 = "llvm_declare_global" 889 890(** [define_global name init m] returns a new global with name [name] and 891 initializer [init] in module [m]. If the named global already exists, it is 892 renamed. 893 See the constructor of [llvm::GlobalVariable]. *) 894external define_global : string -> llvalue -> llmodule -> llvalue 895 = "llvm_define_global" 896 897(** [lookup_global name m] returns [Some g] if a global variable with name 898 [name] exists in module [m]. If no such global exists, returns [None]. 899 See the [llvm::GlobalVariable] constructor. *) 900external lookup_global : string -> llmodule -> llvalue option 901 = "llvm_lookup_global" 902 903(** [delete_global gv] destroys the global variable [gv]. 904 See the method [llvm::GlobalVariable::eraseFromParent]. *) 905external delete_global : llvalue -> unit = "llvm_delete_global" 906 907(** [global_begin m] returns the first position in the global variable list of 908 the module [m]. [global_begin] and [global_succ] can be used to iterate 909 over the global list in order. 910 See the method [llvm::Module::global_begin]. *) 911external global_begin : llmodule -> (llmodule, llvalue) llpos 912 = "llvm_global_begin" 913 914(** [global_succ gv] returns the global variable list position succeeding 915 [Before gv]. 916 See the method [llvm::Module::global_iterator::operator++]. *) 917external global_succ : llvalue -> (llmodule, llvalue) llpos 918 = "llvm_global_succ" 919 920(** [iter_globals f m] applies function [f] to each of the global variables of 921 module [m] in order. Tail recursive. *) 922val iter_globals : (llvalue -> unit) -> llmodule -> unit 923 924(** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where 925 [g1,...,gN] are the global variables of module [m]. Tail recursive. *) 926val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a 927 928(** [global_end m] returns the last position in the global variable list of the 929 module [m]. [global_end] and [global_pred] can be used to iterate over the 930 global list in reverse. 931 See the method [llvm::Module::global_end]. *) 932external global_end : llmodule -> (llmodule, llvalue) llrev_pos 933 = "llvm_global_end" 934 935(** [global_pred gv] returns the global variable list position preceding 936 [After gv]. 937 See the method [llvm::Module::global_iterator::operator--]. *) 938external global_pred : llvalue -> (llmodule, llvalue) llrev_pos 939 = "llvm_global_pred" 940 941(** [rev_iter_globals f m] applies function [f] to each of the global variables 942 of module [m] in reverse order. Tail recursive. *) 943val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit 944 945(** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where 946 [g1,...,gN] are the global variables of module [m]. Tail recursive. *) 947val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a 948 949(** [is_global_constant gv] returns [true] if the global variabile [gv] is a 950 constant. Returns [false] otherwise. 951 See the method [llvm::GlobalVariable::isConstant]. *) 952external is_global_constant : llvalue -> bool = "llvm_is_global_constant" 953 954(** [set_global_constant c gv] sets the global variable [gv] to be a constant if 955 [c] is [true] and not if [c] is [false]. 956 See the method [llvm::GlobalVariable::setConstant]. *) 957external set_global_constant : bool -> llvalue -> unit 958 = "llvm_set_global_constant" 959 960(** [global_initializer gv] returns the initializer for the global variable 961 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *) 962external global_initializer : llvalue -> llvalue = "LLVMGetInitializer" 963 964(** [set_initializer c gv] sets the initializer for the global variable 965 [gv] to the constant [c]. 966 See the method [llvm::GlobalVariable::setInitializer]. *) 967external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer" 968 969(** [remove_initializer gv] unsets the initializer for the global variable 970 [gv]. 971 See the method [llvm::GlobalVariable::setInitializer]. *) 972external remove_initializer : llvalue -> unit = "llvm_remove_initializer" 973 974(** [is_thread_local gv] returns [true] if the global variable [gv] is 975 thread-local and [false] otherwise. 976 See the method [llvm::GlobalVariable::isThreadLocal]. *) 977external is_thread_local : llvalue -> bool = "llvm_is_thread_local" 978 979(** [set_thread_local c gv] sets the global variable [gv] to be thread local if 980 [c] is [true] and not otherwise. 981 See the method [llvm::GlobalVariable::setThreadLocal]. *) 982external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local" 983 984 985(** {7 Operations on functions} *) 986 987(** [declare_function name ty m] returns a new function of type [ty] and 988 with name [name] in module [m]. If such a function already exists, 989 it is returned. If the type of the existing function differs, then a bitcast 990 to [ty] is returned. *) 991external declare_function : string -> lltype -> llmodule -> llvalue 992 = "llvm_declare_function" 993 994(** [define_function name ty m] creates a new function with name [name] and 995 type [ty] in module [m]. If the named function already exists, it is 996 renamed. An entry basic block is created in the function. 997 See the constructor of [llvm::GlobalVariable]. *) 998external define_function : string -> lltype -> llmodule -> llvalue 999 = "llvm_define_function" 1000 1001(** [lookup_function name m] returns [Some f] if a function with name 1002 [name] exists in module [m]. If no such function exists, returns [None]. 1003 See the method [llvm::Module] constructor. *) 1004external lookup_function : string -> llmodule -> llvalue option 1005 = "llvm_lookup_function" 1006 1007(** [delete_function f] destroys the function [f]. 1008 See the method [llvm::Function::eraseFromParent]. *) 1009external delete_function : llvalue -> unit = "llvm_delete_function" 1010 1011(** [function_begin m] returns the first position in the function list of the 1012 module [m]. [function_begin] and [function_succ] can be used to iterate over 1013 the function list in order. 1014 See the method [llvm::Module::begin]. *) 1015external function_begin : llmodule -> (llmodule, llvalue) llpos 1016 = "llvm_function_begin" 1017 1018(** [function_succ gv] returns the function list position succeeding 1019 [Before gv]. 1020 See the method [llvm::Module::iterator::operator++]. *) 1021external function_succ : llvalue -> (llmodule, llvalue) llpos 1022 = "llvm_function_succ" 1023 1024(** [iter_functions f m] applies function [f] to each of the functions of module 1025 [m] in order. Tail recursive. *) 1026val iter_functions : (llvalue -> unit) -> llmodule -> unit 1027 1028(** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where 1029 [f1,...,fN] are the functions of module [m]. Tail recursive. *) 1030val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a 1031 1032(** [function_end m] returns the last position in the function list of 1033 the module [m]. [function_end] and [function_pred] can be used to iterate 1034 over the function list in reverse. 1035 See the method [llvm::Module::end]. *) 1036external function_end : llmodule -> (llmodule, llvalue) llrev_pos 1037 = "llvm_function_end" 1038 1039(** [function_pred gv] returns the function list position preceding [After gv]. 1040 See the method [llvm::Module::iterator::operator--]. *) 1041external function_pred : llvalue -> (llmodule, llvalue) llrev_pos 1042 = "llvm_function_pred" 1043 1044(** [rev_iter_functions f fn] applies function [f] to each of the functions of 1045 module [m] in reverse order. Tail recursive. *) 1046val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit 1047 1048(** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where 1049 [f1,...,fN] are the functions of module [m]. Tail recursive. *) 1050val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a 1051 1052(** [is_intrinsic f] returns true if the function [f] is an intrinsic. 1053 See the method [llvm::Function::isIntrinsic]. *) 1054external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic" 1055 1056(** [function_call_conv f] returns the calling convention of the function [f]. 1057 See the method [llvm::Function::getCallingConv]. *) 1058external function_call_conv : llvalue -> int = "llvm_function_call_conv" 1059 1060(** [set_function_call_conv cc f] sets the calling convention of the function 1061 [f] to the calling convention numbered [cc]. 1062 See the method [llvm::Function::setCallingConv]. *) 1063external set_function_call_conv : int -> llvalue -> unit 1064 = "llvm_set_function_call_conv" 1065 1066(** [gc f] returns [Some name] if the function [f] has a garbage 1067 collection algorithm specified and [None] otherwise. 1068 See the method [llvm::Function::getGC]. *) 1069external gc : llvalue -> string option = "llvm_gc" 1070 1071(** [set_gc gc f] sets the collection algorithm for the function [f] to 1072 [gc]. See the method [llvm::Function::setGC]. *) 1073external set_gc : string option -> llvalue -> unit = "llvm_set_gc" 1074 1075(** [add_function_attr f a] adds attribute [a] to the return type of function 1076 [f]. *) 1077external add_function_attr : llvalue -> Attribute.t -> unit 1078 = "llvm_add_function_attr" 1079 1080(** [remove_function_attr f a] removes attribute [a] from the return type of 1081 function [f]. *) 1082external remove_function_attr : llvalue -> Attribute.t -> unit 1083 = "llvm_remove_function_attr" 1084 1085(** {7 Operations on params} *) 1086 1087(** [params f] returns the parameters of function [f]. 1088 See the method [llvm::Function::getArgumentList]. *) 1089external params : llvalue -> llvalue array = "llvm_params" 1090 1091(** [param f n] returns the [n]th parameter of function [f]. 1092 See the method [llvm::Function::getArgumentList]. *) 1093external param : llvalue -> int -> llvalue = "llvm_param" 1094 1095(** [param_parent p] returns the parent function that owns the parameter. 1096 See the method [llvm::Argument::getParent]. *) 1097external param_parent : llvalue -> llvalue = "LLVMGetParamParent" 1098 1099(** [param_begin f] returns the first position in the parameter list of the 1100 function [f]. [param_begin] and [param_succ] can be used to iterate over 1101 the parameter list in order. 1102 See the method [llvm::Function::arg_begin]. *) 1103external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin" 1104 1105(** [param_succ bb] returns the parameter list position succeeding 1106 [Before bb]. 1107 See the method [llvm::Function::arg_iterator::operator++]. *) 1108external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ" 1109 1110(** [iter_params f fn] applies function [f] to each of the parameters 1111 of function [fn] in order. Tail recursive. *) 1112val iter_params : (llvalue -> unit) -> llvalue -> unit 1113 1114(** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where 1115 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *) 1116val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a 1117 1118(** [param_end f] returns the last position in the parameter list of 1119 the function [f]. [param_end] and [param_pred] can be used to iterate 1120 over the parameter list in reverse. 1121 See the method [llvm::Function::arg_end]. *) 1122external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end" 1123 1124(** [param_pred gv] returns the function list position preceding [After gv]. 1125 See the method [llvm::Function::arg_iterator::operator--]. *) 1126external param_pred : llvalue -> (llvalue, llvalue) llrev_pos 1127 = "llvm_param_pred" 1128 1129(** [rev_iter_params f fn] applies function [f] to each of the parameters 1130 of function [fn] in reverse order. Tail recursive. *) 1131val rev_iter_params : (llvalue -> unit) -> llvalue -> unit 1132 1133(** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where 1134 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *) 1135val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a 1136 1137(** [add_param p a] adds attribute [a] to parameter [p]. *) 1138external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr" 1139 1140(** [remove_param_attr p a] removes attribute [a] from parameter [p]. *) 1141external remove_param_attr : llvalue -> Attribute.t -> unit 1142 = "llvm_remove_param_attr" 1143 1144(** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *) 1145external set_param_alignment : llvalue -> int -> unit 1146 = "llvm_set_param_alignment" 1147 1148(** {7 Operations on basic blocks} *) 1149 1150(** [basic_blocks fn] returns the basic blocks of the function [f]. 1151 See the method [llvm::Function::getBasicBlockList]. *) 1152external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks" 1153 1154(** [entry_block fn] returns the entry basic block of the function [f]. 1155 See the method [llvm::Function::getEntryBlock]. *) 1156external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock" 1157 1158(** [delete_block bb] deletes the basic block [bb]. 1159 See the method [llvm::BasicBlock::eraseFromParent]. *) 1160external delete_block : llbasicblock -> unit = "llvm_delete_block" 1161 1162(** [append_block name f] creates a new basic block named [name] at the end of 1163 function [f]. 1164 See the constructor of [llvm::BasicBlock]. *) 1165external append_block : string -> llvalue -> llbasicblock = "llvm_append_block" 1166 1167(** [insert_block name bb] creates a new basic block named [name] before the 1168 basic block [bb]. 1169 See the constructor of [llvm::BasicBlock]. *) 1170external insert_block : string -> llbasicblock -> llbasicblock 1171 = "llvm_insert_block" 1172 1173(** [block_parent bb] returns the parent function that owns the basic block. 1174 See the method [llvm::BasicBlock::getParent]. *) 1175external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent" 1176 1177(** [block_begin f] returns the first position in the basic block list of the 1178 function [f]. [block_begin] and [block_succ] can be used to iterate over 1179 the basic block list in order. 1180 See the method [llvm::Function::begin]. *) 1181external block_begin : llvalue -> (llvalue, llbasicblock) llpos 1182 = "llvm_block_begin" 1183 1184(** [block_succ bb] returns the basic block list position succeeding 1185 [Before bb]. 1186 See the method [llvm::Function::iterator::operator++]. *) 1187external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos 1188 = "llvm_block_succ" 1189 1190(** [iter_blocks f fn] applies function [f] to each of the basic blocks 1191 of function [fn] in order. Tail recursive. *) 1192val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit 1193 1194(** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where 1195 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *) 1196val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a 1197 1198(** [block_end f] returns the last position in the basic block list of 1199 the function [f]. [block_end] and [block_pred] can be used to iterate 1200 over the basic block list in reverse. 1201 See the method [llvm::Function::end]. *) 1202external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos 1203 = "llvm_block_end" 1204 1205(** [block_pred gv] returns the function list position preceding [After gv]. 1206 See the method [llvm::Function::iterator::operator--]. *) 1207external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos 1208 = "llvm_block_pred" 1209 1210(** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks 1211 of function [fn] in reverse order. Tail recursive. *) 1212val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit 1213 1214(** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where 1215 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *) 1216val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a 1217 1218(** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *) 1219external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue" 1220 1221(** [value_is_block v] returns [true] if the value [v] is a basic block and 1222 [false] otherwise. 1223 Similar to [llvm::isa<BasicBlock>]. *) 1224external value_is_block : llvalue -> bool = "llvm_value_is_block" 1225 1226(** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *) 1227external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock" 1228 1229 1230(** {7 Operations on instructions} *) 1231 1232(** [instr_parent i] is the enclosing basic block of the instruction [i]. 1233 See the method [llvm::Instruction::getParent]. *) 1234external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent" 1235 1236(** [instr_begin bb] returns the first position in the instruction list of the 1237 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over 1238 the instruction list in order. 1239 See the method [llvm::BasicBlock::begin]. *) 1240external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos 1241 = "llvm_instr_begin" 1242 1243(** [instr_succ i] returns the instruction list position succeeding [Before i]. 1244 See the method [llvm::BasicBlock::iterator::operator++]. *) 1245external instr_succ : llvalue -> (llbasicblock, llvalue) llpos 1246 = "llvm_instr_succ" 1247 1248(** [iter_instrs f bb] applies function [f] to each of the instructions of basic 1249 block [bb] in order. Tail recursive. *) 1250val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit 1251 1252(** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where 1253 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *) 1254val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a 1255 1256(** [instr_end bb] returns the last position in the instruction list of the 1257 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over 1258 the instruction list in reverse. 1259 See the method [llvm::BasicBlock::end]. *) 1260external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos 1261 = "llvm_instr_end" 1262 1263(** [instr_pred i] returns the instruction list position preceding [After i]. 1264 See the method [llvm::BasicBlock::iterator::operator--]. *) 1265external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos 1266 = "llvm_instr_pred" 1267 1268(** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where 1269 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *) 1270val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a 1271 1272 1273(** {7 Operations on call sites} *) 1274 1275(** [instruction_call_conv ci] is the calling convention for the call or invoke 1276 instruction [ci], which may be one of the values from the module 1277 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and 1278 [llvm::InvokeInst::getCallingConv]. *) 1279external instruction_call_conv: llvalue -> int 1280 = "llvm_instruction_call_conv" 1281 1282(** [set_instruction_call_conv cc ci] sets the calling convention for the call 1283 or invoke instruction [ci] to the integer [cc], which can be one of the 1284 values from the module {!CallConv}. 1285 See the method [llvm::CallInst::setCallingConv] 1286 and [llvm::InvokeInst::setCallingConv]. *) 1287external set_instruction_call_conv: int -> llvalue -> unit 1288 = "llvm_set_instruction_call_conv" 1289 1290(** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th 1291 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return 1292 value. *) 1293external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit 1294 = "llvm_add_instruction_param_attr" 1295 1296(** [remove_instruction_param_attr ci i a] removes attribute [a] from the 1297 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the 1298 return value. *) 1299external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit 1300 = "llvm_remove_instruction_param_attr" 1301 1302(** {Operations on call instructions (only)} *) 1303 1304(** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as 1305 eligible for tail call optimization, [false] otherwise. 1306 See the method [llvm::CallInst::isTailCall]. *) 1307external is_tail_call : llvalue -> bool = "llvm_is_tail_call" 1308 1309(** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail 1310 call optimization if [tc] is [true], clears otherwise. 1311 See the method [llvm::CallInst::setTailCall]. *) 1312external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call" 1313 1314(** {7 Operations on phi nodes} *) 1315 1316(** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use 1317 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *) 1318external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit 1319 = "llvm_add_incoming" 1320 1321(** [incoming pn] returns the list of value-block pairs for phi node [pn]. 1322 See the method [llvm::PHINode::getIncomingValue]. *) 1323external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming" 1324 1325 1326 1327(** {6 Instruction builders} *) 1328 1329(** [builder context] creates an instruction builder with no position in 1330 the context [context]. It is invalid to use this builder until its position 1331 is set with {!position_before} or {!position_at_end}. See the constructor 1332 for [llvm::LLVMBuilder]. *) 1333external builder : llcontext -> llbuilder = "llvm_builder" 1334 1335(** [builder_at ip] creates an instruction builder positioned at [ip]. 1336 See the constructor for [llvm::LLVMBuilder]. *) 1337val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder 1338 1339(** [builder_before ins] creates an instruction builder positioned before the 1340 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *) 1341val builder_before : llcontext -> llvalue -> llbuilder 1342 1343(** [builder_at_end bb] creates an instruction builder positioned at the end of 1344 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *) 1345val builder_at_end : llcontext -> llbasicblock -> llbuilder 1346 1347(** [position_builder ip bb] moves the instruction builder [bb] to the position 1348 [ip]. 1349 See the constructor for [llvm::LLVMBuilder]. *) 1350external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit 1351 = "llvm_position_builder" 1352 1353(** [position_before ins b] moves the instruction builder [b] to before the 1354 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *) 1355val position_before : llvalue -> llbuilder -> unit 1356 1357(** [position_at_end bb b] moves the instruction builder [b] to the end of the 1358 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *) 1359val position_at_end : llbasicblock -> llbuilder -> unit 1360 1361(** [insertion_block b] returns the basic block that the builder [b] is 1362 positioned to insert into. Raises [Not_Found] if the instruction builder is 1363 uninitialized. 1364 See the method [llvm::LLVMBuilder::GetInsertBlock]. *) 1365external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block" 1366 1367(** [insert_into_builder i name b] inserts the specified instruction [i] at the 1368 position specified by the instruction builder [b]. 1369 See the method [llvm::LLVMBuilder::Insert]. *) 1370external insert_into_builder : llvalue -> string -> llbuilder -> unit 1371 = "llvm_insert_into_builder" 1372 1373 1374(** {7 Terminators} *) 1375 1376(** [build_ret_void b] creates a 1377 [ret void] 1378 instruction at the position specified by the instruction builder [b]. 1379 See the method [llvm::LLVMBuilder::CreateRetVoid]. *) 1380external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void" 1381 1382(** [build_ret v b] creates a 1383 [ret %v] 1384 instruction at the position specified by the instruction builder [b]. 1385 See the method [llvm::LLVMBuilder::CreateRet]. *) 1386external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret" 1387 1388(** [build_aggregate_ret vs b] creates a 1389 [ret {...} { %v1, %v2, ... } ] 1390 instruction at the position specified by the instruction builder [b]. 1391 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *) 1392external build_aggregate_ret : llvalue array -> llbuilder -> llvalue 1393 = "llvm_build_aggregate_ret" 1394 1395(** [build_br bb b] creates a 1396 [b %bb] 1397 instruction at the position specified by the instruction builder [b]. 1398 See the method [llvm::LLVMBuilder::CreateBr]. *) 1399external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br" 1400 1401(** [build_cond_br cond tbb fbb b] creates a 1402 [b %cond, %tbb, %fbb] 1403 instruction at the position specified by the instruction builder [b]. 1404 See the method [llvm::LLVMBuilder::CreateCondBr]. *) 1405external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder -> 1406 llvalue = "llvm_build_cond_br" 1407 1408(** [build_switch case elsebb count b] creates an empty 1409 [switch %case, %elsebb] 1410 instruction at the position specified by the instruction builder [b] with 1411 space reserved for [count] cases. 1412 See the method [llvm::LLVMBuilder::CreateSwitch]. *) 1413external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue 1414 = "llvm_build_switch" 1415 1416(** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb] 1417 when its input matches the constant [onval]. 1418 See the method [llvm::SwitchInst::addCase]. **) 1419external add_case : llvalue -> llvalue -> llbasicblock -> unit 1420 = "llvm_add_case" 1421 1422(** [build_invoke fn args tobb unwindbb name b] creates an 1423 [%name = invoke %fn(args) to %tobb unwind %unwindbb] 1424 instruction at the position specified by the instruction builder [b]. 1425 See the method [llvm::LLVMBuilder::CreateInvoke]. *) 1426external build_invoke : llvalue -> llvalue array -> llbasicblock -> 1427 llbasicblock -> string -> llbuilder -> llvalue 1428 = "llvm_build_invoke_bc" "llvm_build_invoke_nat" 1429 1430(** [build_unwind b] creates an 1431 [unwind] 1432 instruction at the position specified by the instruction builder [b]. 1433 See the method [llvm::LLVMBuilder::CreateUnwind]. *) 1434external build_unwind : llbuilder -> llvalue = "llvm_build_unwind" 1435 1436(** [build_unreachable b] creates an 1437 [unreachable] 1438 instruction at the position specified by the instruction builder [b]. 1439 See the method [llvm::LLVMBuilder::CreateUnwind]. *) 1440external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable" 1441 1442 1443(** {7 Arithmetic} *) 1444 1445(** [build_add x y name b] creates a 1446 [%name = add %x, %y] 1447 instruction at the position specified by the instruction builder [b]. 1448 See the method [llvm::LLVMBuilder::CreateAdd]. *) 1449external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue 1450 = "llvm_build_add" 1451 1452(** [build_nswadd x y name b] creates a 1453 [%name = nsw add %x, %y] 1454 instruction at the position specified by the instruction builder [b]. 1455 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *) 1456external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue 1457 = "llvm_build_nsw_add" 1458 1459(** [build_fadd x y name b] creates a 1460 [%name = fadd %x, %y] 1461 instruction at the position specified by the instruction builder [b]. 1462 See the method [llvm::LLVMBuilder::CreateFAdd]. *) 1463external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue 1464 = "llvm_build_fadd" 1465 1466(** [build_sub x y name b] creates a 1467 [%name = sub %x, %y] 1468 instruction at the position specified by the instruction builder [b]. 1469 See the method [llvm::LLVMBuilder::CreateSub]. *) 1470external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1471 = "llvm_build_sub" 1472 1473(** [build_fsub x y name b] creates a 1474 [%name = fsub %x, %y] 1475 instruction at the position specified by the instruction builder [b]. 1476 See the method [llvm::LLVMBuilder::CreateFSub]. *) 1477external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1478 = "llvm_build_fsub" 1479 1480(** [build_mul x y name b] creates a 1481 [%name = mul %x, %y] 1482 instruction at the position specified by the instruction builder [b]. 1483 See the method [llvm::LLVMBuilder::CreateMul]. *) 1484external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1485 = "llvm_build_mul" 1486 1487(** [build_fmul x y name b] creates a 1488 [%name = fmul %x, %y] 1489 instruction at the position specified by the instruction builder [b]. 1490 See the method [llvm::LLVMBuilder::CreateFMul]. *) 1491external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1492 = "llvm_build_fmul" 1493 1494(** [build_udiv x y name b] creates a 1495 [%name = udiv %x, %y] 1496 instruction at the position specified by the instruction builder [b]. 1497 See the method [llvm::LLVMBuilder::CreateUDiv]. *) 1498external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1499 = "llvm_build_udiv" 1500 1501(** [build_sdiv x y name b] creates a 1502 [%name = sdiv %x, %y] 1503 instruction at the position specified by the instruction builder [b]. 1504 See the method [llvm::LLVMBuilder::CreateSDiv]. *) 1505external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1506 = "llvm_build_sdiv" 1507 1508(** [build_exact_sdiv x y name b] creates a 1509 [%name = exact sdiv %x, %y] 1510 instruction at the position specified by the instruction builder [b]. 1511 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *) 1512external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1513 = "llvm_build_exact_sdiv" 1514 1515(** [build_fdiv x y name b] creates a 1516 [%name = fdiv %x, %y] 1517 instruction at the position specified by the instruction builder [b]. 1518 See the method [llvm::LLVMBuilder::CreateFDiv]. *) 1519external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1520 = "llvm_build_fdiv" 1521 1522(** [build_urem x y name b] creates a 1523 [%name = urem %x, %y] 1524 instruction at the position specified by the instruction builder [b]. 1525 See the method [llvm::LLVMBuilder::CreateURem]. *) 1526external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1527 = "llvm_build_urem" 1528 1529(** [build_SRem x y name b] creates a 1530 [%name = srem %x, %y] 1531 instruction at the position specified by the instruction builder [b]. 1532 See the method [llvm::LLVMBuilder::CreateSRem]. *) 1533external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1534 = "llvm_build_srem" 1535 1536(** [build_frem x y name b] creates a 1537 [%name = frem %x, %y] 1538 instruction at the position specified by the instruction builder [b]. 1539 See the method [llvm::LLVMBuilder::CreateFRem]. *) 1540external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1541 = "llvm_build_frem" 1542 1543(** [build_shl x y name b] creates a 1544 [%name = shl %x, %y] 1545 instruction at the position specified by the instruction builder [b]. 1546 See the method [llvm::LLVMBuilder::CreateShl]. *) 1547external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue 1548 = "llvm_build_shl" 1549 1550(** [build_lshr x y name b] creates a 1551 [%name = lshr %x, %y] 1552 instruction at the position specified by the instruction builder [b]. 1553 See the method [llvm::LLVMBuilder::CreateLShr]. *) 1554external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue 1555 = "llvm_build_lshr" 1556 1557(** [build_ashr x y name b] creates a 1558 [%name = ashr %x, %y] 1559 instruction at the position specified by the instruction builder [b]. 1560 See the method [llvm::LLVMBuilder::CreateAShr]. *) 1561external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue 1562 = "llvm_build_ashr" 1563 1564(** [build_and x y name b] creates a 1565 [%name = and %x, %y] 1566 instruction at the position specified by the instruction builder [b]. 1567 See the method [llvm::LLVMBuilder::CreateAnd]. *) 1568external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue 1569 = "llvm_build_and" 1570 1571(** [build_or x y name b] creates a 1572 [%name = or %x, %y] 1573 instruction at the position specified by the instruction builder [b]. 1574 See the method [llvm::LLVMBuilder::CreateOr]. *) 1575external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue 1576 = "llvm_build_or" 1577 1578(** [build_xor x y name b] creates a 1579 [%name = xor %x, %y] 1580 instruction at the position specified by the instruction builder [b]. 1581 See the method [llvm::LLVMBuilder::CreateXor]. *) 1582external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue 1583 = "llvm_build_xor" 1584 1585(** [build_neg x name b] creates a 1586 [%name = sub 0, %x] 1587 instruction at the position specified by the instruction builder [b]. 1588 [-0.0] is used for floating point types to compute the correct sign. 1589 See the method [llvm::LLVMBuilder::CreateNeg]. *) 1590external build_neg : llvalue -> string -> llbuilder -> llvalue 1591 = "llvm_build_neg" 1592 1593(** [build_xor x name b] creates a 1594 [%name = xor %x, -1] 1595 instruction at the position specified by the instruction builder [b]. 1596 [-1] is the correct "all ones" value for the type of [x]. 1597 See the method [llvm::LLVMBuilder::CreateXor]. *) 1598external build_not : llvalue -> string -> llbuilder -> llvalue 1599 = "llvm_build_not" 1600 1601 1602(** {7 Memory} *) 1603 1604(** [build_malloc ty name b] creates a 1605 [%name = malloc %ty] 1606 instruction at the position specified by the instruction builder [b]. 1607 See the method [llvm::LLVMBuilder::CreateAlloca]. *) 1608external build_malloc : lltype -> string -> llbuilder -> llvalue 1609 = "llvm_build_malloc" 1610 1611(** [build_array_malloc ty n name b] creates a 1612 [%name = malloc %ty, %n] 1613 instruction at the position specified by the instruction builder [b]. 1614 See the method [llvm::LLVMBuilder::CreateMalloc]. *) 1615external build_array_malloc : lltype -> llvalue -> string -> llbuilder -> 1616 llvalue = "llvm_build_array_malloc" 1617 1618(** [build_alloca ty name b] creates a 1619 [%name = alloca %ty] 1620 instruction at the position specified by the instruction builder [b]. 1621 See the method [llvm::LLVMBuilder::CreateAlloca]. *) 1622external build_alloca : lltype -> string -> llbuilder -> llvalue 1623 = "llvm_build_alloca" 1624 1625(** [build_array_alloca ty n name b] creates a 1626 [%name = alloca %ty, %n] 1627 instruction at the position specified by the instruction builder [b]. 1628 See the method [llvm::LLVMBuilder::CreateAlloca]. *) 1629external build_array_alloca : lltype -> llvalue -> string -> llbuilder -> 1630 llvalue = "llvm_build_array_alloca" 1631 1632(** [build_free v b] creates a 1633 [free %v] 1634 instruction at the position specified by the instruction builder [b]. 1635 See the method [llvm::LLVMBuilder::CreateFree]. *) 1636external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free" 1637 1638(** [build_load v name b] creates a 1639 [%name = load %v] 1640 instruction at the position specified by the instruction builder [b]. 1641 See the method [llvm::LLVMBuilder::CreateLoad]. *) 1642external build_load : llvalue -> string -> llbuilder -> llvalue 1643 = "llvm_build_load" 1644 1645(** [build_store v p b] creates a 1646 [store %v, %p] 1647 instruction at the position specified by the instruction builder [b]. 1648 See the method [llvm::LLVMBuilder::CreateStore]. *) 1649external build_store : llvalue -> llvalue -> llbuilder -> llvalue 1650 = "llvm_build_store" 1651 1652(** [build_gep p indices name b] creates a 1653 [%name = getelementptr %p, indices...] 1654 instruction at the position specified by the instruction builder [b]. 1655 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *) 1656external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue 1657 = "llvm_build_gep" 1658 1659(** [build_in_bounds_gep p indices name b] creates a 1660 [%name = gelementptr inbounds %p, indices...] 1661 instruction at the position specified by the instruction builder [b]. 1662 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *) 1663external build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder -> 1664 llvalue = "llvm_build_in_bounds_gep" 1665 1666(** [build_struct_gep p idx name b] creates a 1667 [%name = getelementptr %p, 0, idx] 1668 instruction at the position specified by the instruction builder [b]. 1669 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *) 1670external build_struct_gep : llvalue -> int -> string -> llbuilder -> 1671 llvalue = "llvm_build_struct_gep" 1672 1673(** [build_global_string str name b] creates a series of instructions that adds 1674 a global string at the position specified by the instruction builder [b]. 1675 See the method [llvm::LLVMBuilder::CreateGlobalString]. *) 1676external build_global_string : string -> string -> llbuilder -> llvalue 1677 = "llvm_build_global_string" 1678 1679(** [build_global_stringptr str name b] creates a series of instructions that 1680 adds a global string pointer at the position specified by the instruction 1681 builder [b]. 1682 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *) 1683external build_global_stringptr : string -> string -> llbuilder -> llvalue 1684 = "llvm_build_global_stringptr" 1685 1686 1687(** {7 Casts} *) 1688 1689(** [build_trunc v ty name b] creates a 1690 [%name = trunc %p to %ty] 1691 instruction at the position specified by the instruction builder [b]. 1692 See the method [llvm::LLVMBuilder::CreateTrunc]. *) 1693external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue 1694 = "llvm_build_trunc" 1695 1696(** [build_zext v ty name b] creates a 1697 [%name = zext %p to %ty] 1698 instruction at the position specified by the instruction builder [b]. 1699 See the method [llvm::LLVMBuilder::CreateZExt]. *) 1700external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue 1701 = "llvm_build_zext" 1702 1703(** [build_sext v ty name b] creates a 1704 [%name = sext %p to %ty] 1705 instruction at the position specified by the instruction builder [b]. 1706 See the method [llvm::LLVMBuilder::CreateSExt]. *) 1707external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue 1708 = "llvm_build_sext" 1709 1710(** [build_fptoui v ty name b] creates a 1711 [%name = fptoui %p to %ty] 1712 instruction at the position specified by the instruction builder [b]. 1713 See the method [llvm::LLVMBuilder::CreateFPToUI]. *) 1714external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue 1715 = "llvm_build_fptoui" 1716 1717(** [build_fptosi v ty name b] creates a 1718 [%name = fptosi %p to %ty] 1719 instruction at the position specified by the instruction builder [b]. 1720 See the method [llvm::LLVMBuilder::CreateFPToSI]. *) 1721external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue 1722 = "llvm_build_fptosi" 1723 1724(** [build_uitofp v ty name b] creates a 1725 [%name = uitofp %p to %ty] 1726 instruction at the position specified by the instruction builder [b]. 1727 See the method [llvm::LLVMBuilder::CreateUIToFP]. *) 1728external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue 1729 = "llvm_build_uitofp" 1730 1731(** [build_sitofp v ty name b] creates a 1732 [%name = sitofp %p to %ty] 1733 instruction at the position specified by the instruction builder [b]. 1734 See the method [llvm::LLVMBuilder::CreateSIToFP]. *) 1735external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue 1736 = "llvm_build_sitofp" 1737 1738(** [build_fptrunc v ty name b] creates a 1739 [%name = fptrunc %p to %ty] 1740 instruction at the position specified by the instruction builder [b]. 1741 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *) 1742external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue 1743 = "llvm_build_fptrunc" 1744 1745(** [build_fpext v ty name b] creates a 1746 [%name = fpext %p to %ty] 1747 instruction at the position specified by the instruction builder [b]. 1748 See the method [llvm::LLVMBuilder::CreateFPExt]. *) 1749external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue 1750 = "llvm_build_fpext" 1751 1752(** [build_ptrtoint v ty name b] creates a 1753 [%name = prtotint %p to %ty] 1754 instruction at the position specified by the instruction builder [b]. 1755 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *) 1756external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue 1757 = "llvm_build_prttoint" 1758 1759(** [build_inttoptr v ty name b] creates a 1760 [%name = inttoptr %p to %ty] 1761 instruction at the position specified by the instruction builder [b]. 1762 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *) 1763external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue 1764 = "llvm_build_inttoptr" 1765 1766(** [build_bitcast v ty name b] creates a 1767 [%name = bitcast %p to %ty] 1768 instruction at the position specified by the instruction builder [b]. 1769 See the method [llvm::LLVMBuilder::CreateBitCast]. *) 1770external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue 1771 = "llvm_build_bitcast" 1772 1773(** [build_zext_or_bitcast v ty name b] creates a zext or bitcast 1774 instruction at the position specified by the instruction builder [b]. 1775 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *) 1776external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 1777 llvalue = "llvm_build_zext_or_bitcast" 1778 1779(** [build_sext_or_bitcast v ty name b] creates a sext or bitcast 1780 instruction at the position specified by the instruction builder [b]. 1781 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *) 1782external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 1783 llvalue = "llvm_build_sext_or_bitcast" 1784 1785(** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast 1786 instruction at the position specified by the instruction builder [b]. 1787 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *) 1788external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 1789 llvalue = "llvm_build_trunc_or_bitcast" 1790 1791(** [build_pointercast v ty name b] creates a bitcast or pointer-to-int 1792 instruction at the position specified by the instruction builder [b]. 1793 See the method [llvm::LLVMBuilder::CreatePointerCast]. *) 1794external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue 1795 = "llvm_build_pointercast" 1796 1797(** [build_intcast v ty name b] creates a zext, bitcast, or trunc 1798 instruction at the position specified by the instruction builder [b]. 1799 See the method [llvm::LLVMBuilder::CreateIntCast]. *) 1800external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue 1801 = "llvm_build_intcast" 1802 1803(** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc 1804 instruction at the position specified by the instruction builder [b]. 1805 See the method [llvm::LLVMBuilder::CreateFPCast]. *) 1806external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue 1807 = "llvm_build_fpcast" 1808 1809 1810(** {7 Comparisons} *) 1811 1812(** [build_icmp pred x y name b] creates a 1813 [%name = icmp %pred %x, %y] 1814 instruction at the position specified by the instruction builder [b]. 1815 See the method [llvm::LLVMBuilder::CreateICmp]. *) 1816external build_icmp : Icmp.t -> llvalue -> llvalue -> string -> 1817 llbuilder -> llvalue = "llvm_build_icmp" 1818 1819(** [build_fcmp pred x y name b] creates a 1820 [%name = fcmp %pred %x, %y] 1821 instruction at the position specified by the instruction builder [b]. 1822 See the method [llvm::LLVMBuilder::CreateFCmp]. *) 1823external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string -> 1824 llbuilder -> llvalue = "llvm_build_fcmp" 1825 1826 1827(** {7 Miscellaneous instructions} *) 1828 1829(** [build_phi incoming name b] creates a 1830 [%name = phi %incoming] 1831 instruction at the position specified by the instruction builder [b]. 1832 [incoming] is a list of [(llvalue, llbasicblock)] tuples. 1833 See the method [llvm::LLVMBuilder::CreatePHI]. *) 1834external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder -> 1835 llvalue = "llvm_build_phi" 1836 1837(** [build_call fn args name b] creates a 1838 [%name = call %fn(args...)] 1839 instruction at the position specified by the instruction builder [b]. 1840 See the method [llvm::LLVMBuilder::CreateCall]. *) 1841external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue 1842 = "llvm_build_call" 1843 1844(** [build_select cond thenv elsev name b] creates a 1845 [%name = select %cond, %thenv, %elsev] 1846 instruction at the position specified by the instruction builder [b]. 1847 See the method [llvm::LLVMBuilder::CreateSelect]. *) 1848external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder -> 1849 llvalue = "llvm_build_select" 1850 1851(** [build_va_arg valist argty name b] creates a 1852 [%name = va_arg %valist, %argty] 1853 instruction at the position specified by the instruction builder [b]. 1854 See the method [llvm::LLVMBuilder::CreateVAArg]. *) 1855external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue 1856 = "llvm_build_va_arg" 1857 1858(** [build_extractelement vec i name b] creates a 1859 [%name = extractelement %vec, %i] 1860 instruction at the position specified by the instruction builder [b]. 1861 See the method [llvm::LLVMBuilder::CreateExtractElement]. *) 1862external build_extractelement : llvalue -> llvalue -> string -> llbuilder -> 1863 llvalue = "llvm_build_extractelement" 1864 1865(** [build_insertelement vec elt i name b] creates a 1866 [%name = insertelement %vec, %elt, %i] 1867 instruction at the position specified by the instruction builder [b]. 1868 See the method [llvm::LLVMBuilder::CreateInsertElement]. *) 1869external build_insertelement : llvalue -> llvalue -> llvalue -> string -> 1870 llbuilder -> llvalue = "llvm_build_insertelement" 1871 1872(** [build_shufflevector veca vecb mask name b] creates a 1873 [%name = shufflevector %veca, %vecb, %mask] 1874 instruction at the position specified by the instruction builder [b]. 1875 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *) 1876external build_shufflevector : llvalue -> llvalue -> llvalue -> string -> 1877 llbuilder -> llvalue = "llvm_build_shufflevector" 1878 1879(** [build_insertvalue agg idx name b] creates a 1880 [%name = extractvalue %agg, %idx] 1881 instruction at the position specified by the instruction builder [b]. 1882 See the method [llvm::LLVMBuilder::CreateExtractValue]. *) 1883external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue 1884 = "llvm_build_extractvalue" 1885 1886(** [build_insertvalue agg val idx name b] creates a 1887 [%name = insertvalue %agg, %val, %idx] 1888 instruction at the position specified by the instruction builder [b]. 1889 See the method [llvm::LLVMBuilder::CreateInsertValue]. *) 1890external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder -> 1891 llvalue = "llvm_build_insertvalue" 1892 1893(** [build_is_null val name b] creates a 1894 [%name = icmp eq %val, null] 1895 instruction at the position specified by the instruction builder [b]. 1896 See the method [llvm::LLVMBuilder::CreateIsNull]. *) 1897external build_is_null : llvalue -> string -> llbuilder -> llvalue 1898 = "llvm_build_is_null" 1899 1900(** [build_is_not_null val name b] creates a 1901 [%name = icmp ne %val, null] 1902 instruction at the position specified by the instruction builder [b]. 1903 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *) 1904external build_is_not_null : llvalue -> string -> llbuilder -> llvalue 1905 = "llvm_build_is_not_null" 1906 1907(** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure 1908 the difference between two pointer values at the position specified by the 1909 instruction builder [b]. 1910 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *) 1911external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue 1912 = "llvm_build_ptrdiff" 1913 1914(** {6 Module providers} *) 1915 1916module ModuleProvider : sig 1917 (** [create_module_provider m] encapsulates [m] in a module provider and takes 1918 ownership of the module. See the constructor 1919 [llvm::ExistingModuleProvider::ExistingModuleProvider]. *) 1920 external create : llmodule -> llmoduleprovider 1921 = "LLVMCreateModuleProviderForExistingModule" 1922 1923 (** [dispose_module_provider mp] destroys the module provider [mp] as well as 1924 the contained module. *) 1925 external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider" 1926end 1927 1928 1929(** {6 Memory buffers} *) 1930 1931module MemoryBuffer : sig 1932 (** [of_file p] is the memory buffer containing the contents of the file at 1933 path [p]. If the file could not be read, then [IoError msg] is 1934 raised. *) 1935 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file" 1936 1937 (** [stdin ()] is the memory buffer containing the contents of standard input. 1938 If standard input is empty, then [IoError msg] is raised. *) 1939 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin" 1940 1941 (** Disposes of a memory buffer. *) 1942 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose" 1943end 1944 1945 1946(** {6 Pass Managers} *) 1947 1948module PassManager : sig 1949 (** *) 1950 type 'a t 1951 type any = [ `Module | `Function ] 1952 1953 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This 1954 type of pipeline is suitable for link-time optimization and whole-module 1955 transformations. 1956 See the constructor of [llvm::PassManager]. *) 1957 external create : unit -> [ `Module ] t = "llvm_passmanager_create" 1958 1959 (** [PassManager.create_function mp] constructs a new function-by-function 1960 pass pipeline over the module provider [mp]. It does not take ownership of 1961 [mp]. This type of pipeline is suitable for code generation and JIT 1962 compilation tasks. 1963 See the constructor of [llvm::FunctionPassManager]. *) 1964 external create_function : llmoduleprovider -> [ `Function ] t 1965 = "LLVMCreateFunctionPassManager" 1966 1967 (** [run_module m pm] initializes, executes on the module [m], and finalizes 1968 all of the passes scheduled in the pass manager [pm]. Returns [true] if 1969 any of the passes modified the module, [false] otherwise. 1970 See the [llvm::PassManager::run] method. *) 1971 external run_module : llmodule -> [ `Module ] t -> bool 1972 = "llvm_passmanager_run_module" 1973 1974 (** [initialize fpm] initializes all of the function passes scheduled in the 1975 function pass manager [fpm]. Returns [true] if any of the passes modified 1976 the module, [false] otherwise. 1977 See the [llvm::FunctionPassManager::doInitialization] method. *) 1978 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize" 1979 1980 (** [run_function f fpm] executes all of the function passes scheduled in the 1981 function pass manager [fpm] over the function [f]. Returns [true] if any 1982 of the passes modified [f], [false] otherwise. 1983 See the [llvm::FunctionPassManager::run] method. *) 1984 external run_function : llvalue -> [ `Function ] t -> bool 1985 = "llvm_passmanager_run_function" 1986 1987 (** [finalize fpm] finalizes all of the function passes scheduled in in the 1988 function pass manager [fpm]. Returns [true] if any of the passes 1989 modified the module, [false] otherwise. 1990 See the [llvm::FunctionPassManager::doFinalization] method. *) 1991 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize" 1992 1993 (** Frees the memory of a pass pipeline. For function pipelines, does not free 1994 the module provider. 1995 See the destructor of [llvm::BasePassManager]. *) 1996 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose" 1997end 1998