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