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