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