llvm.mli revision 7c72c927c5c26806651113d9ee1dfb7aa5cb62c2
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(** Any value in the LLVM IR. Functions, instructions, global variables, 33 constants, and much more are all [llvalues]. See the [llvm::Value] class. 34 This type covers a wide range of subclasses. *) 35type llvalue 36 37(** Used to store users and usees of values. See the [llvm::Use] class. *) 38type lluse 39 40(** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *) 41type llbasicblock 42 43(** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder] 44 class. *) 45type llbuilder 46 47(** Used to efficiently handle large buffers of read-only binary data. 48 See the [llvm::MemoryBuffer] class. *) 49type llmemorybuffer 50 51(** The kind of an [lltype], the result of [classify_type ty]. See the 52 [llvm::Type::TypeID] enumeration. *) 53module TypeKind : sig 54 type t = 55 Void 56 | Float 57 | Double 58 | X86fp80 59 | Fp128 60 | Ppc_fp128 61 | Label 62 | Integer 63 | Function 64 | Struct 65 | Array 66 | Pointer 67 | Vector 68 | Metadata 69end 70 71(** The linkage of a global value, accessed with {!linkage} and 72 {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *) 73module Linkage : sig 74 type t = 75 External 76 | Available_externally 77 | Link_once 78 | Link_once_odr 79 | Weak 80 | Weak_odr 81 | Appending 82 | Internal 83 | Private 84 | Dllimport 85 | Dllexport 86 | External_weak 87 | Ghost 88 | Common 89 | Linker_private 90end 91 92(** The linker visibility of a global value, accessed with {!visibility} and 93 {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *) 94module Visibility : sig 95 type t = 96 Default 97 | Hidden 98 | Protected 99end 100 101(** The following calling convention values may be accessed with 102 {!function_call_conv} and {!set_function_call_conv}. Calling 103 conventions are open-ended. *) 104module CallConv : sig 105 val c : int (** [c] is the C calling convention. *) 106 val fast : int (** [fast] is the calling convention to allow LLVM 107 maximum optimization opportunities. Use only with 108 internal linkage. *) 109 val cold : int (** [cold] is the calling convention for 110 callee-save. *) 111 val x86_stdcall : int (** [x86_stdcall] is the familiar stdcall calling 112 convention from C. *) 113 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling 114 convention from C. *) 115end 116 117module Attribute : sig 118 type t = 119 | Zext 120 | Sext 121 | Noreturn 122 | Inreg 123 | Structret 124 | Nounwind 125 | Noalias 126 | Byval 127 | Nest 128 | Readnone 129 | Readonly 130 | Noinline 131 | Alwaysinline 132 | Optsize 133 | Ssp 134 | Sspreq 135 | Alignment of int 136 | Nocapture 137 | Noredzone 138 | Noimplicitfloat 139 | Naked 140 | Inlinehint 141 | Stackalignment of int 142end 143 144(** The predicate for an integer comparison ([icmp]) instruction. 145 See the [llvm::ICmpInst::Predicate] enumeration. *) 146module Icmp : sig 147 type t = 148 | Eq 149 | Ne 150 | Ugt 151 | Uge 152 | Ult 153 | Ule 154 | Sgt 155 | Sge 156 | Slt 157 | Sle 158end 159 160(** The predicate for a floating-point comparison ([fcmp]) instruction. 161 See the [llvm::FCmpInst::Predicate] enumeration. *) 162module Fcmp : sig 163 type t = 164 | False 165 | Oeq 166 | Ogt 167 | Oge 168 | Olt 169 | Ole 170 | One 171 | Ord 172 | Uno 173 | Ueq 174 | Ugt 175 | Uge 176 | Ult 177 | Ule 178 | Une 179 | True 180end 181 182 183(** {6 Iteration} *) 184 185(** [Before b] and [At_end a] specify positions from the start of the ['b] list 186 of [a]. [llpos] is used to specify positions in and for forward iteration 187 through the various value lists maintained by the LLVM IR. *) 188type ('a, 'b) llpos = 189| At_end of 'a 190| Before of 'b 191 192(** [After b] and [At_start a] specify positions from the end of the ['b] list 193 of [a]. [llrev_pos] is used for reverse iteration through the various value 194 lists maintained by the LLVM IR. *) 195type ('a, 'b) llrev_pos = 196| At_start of 'a 197| After of 'b 198 199 200(** {6 Exceptions} *) 201 202exception IoError of string 203 204 205(** {6 Contexts} *) 206 207(** [create_context ()] creates a context for storing the "global" state in 208 LLVM. See the constructor [llvm::LLVMContext]. *) 209val create_context : unit -> llcontext 210 211(** [destroy_context ()] destroys a context. See the destructor 212 [llvm::LLVMContext::~LLVMContext]. *) 213val dispose_context : llcontext -> unit 214 215(** See the function [llvm::getGlobalContext]. *) 216val global_context : unit -> llcontext 217 218(** [mdkind_id context name] returns the MDKind ID that corresponds to the 219 name [name] in the context [context]. See the function 220 [llvm::LLVMContext::getMDKindID]. *) 221val mdkind_id : llcontext -> string -> int 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]. *) 230val create_module : llcontext -> string -> llmodule 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]. *) 236val dispose_module : llmodule -> unit 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]. *) 240val target_triple: llmodule -> string 241 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]. *) 245val set_target_triple: string -> llmodule -> unit 246 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]. *) 251val data_layout: llmodule -> string 252 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]. *) 256val set_data_layout: string -> llmodule -> unit 257 258(** [dump_module m] prints the .ll representation of the module [m] to standard 259 error. See the method [llvm::Module::dump]. *) 260val dump_module : llmodule -> unit 261 262(** [set_module_inline_asm m asm] sets the inline assembler for the module. See 263 the method [llvm::Module::setModuleInlineAsm]. *) 264val set_module_inline_asm : llmodule -> string -> unit 265 266 267 268(** {6 Types} *) 269 270(** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty]. 271 See the method [llvm::Type::getTypeID]. *) 272val classify_type : lltype -> TypeKind.t 273 274(** [type_context ty] returns the {!llcontext} corresponding to the type [ty]. 275 See the method [llvm::Type::getContext]. *) 276val type_context : lltype -> llcontext 277 278(** [string_of_lltype ty] returns a string describing the type [ty]. *) 279val string_of_lltype : lltype -> string 280 281(** {7 Operations on integer types} *) 282 283(** [i1_type c] returns an integer type of bitwidth 1 in the context [c]. See 284 [llvm::Type::Int1Ty]. *) 285val i1_type : llcontext -> lltype 286 287(** [i8_type c] returns an integer type of bitwidth 8 in the context [c]. See 288 [llvm::Type::Int8Ty]. *) 289val i8_type : llcontext -> lltype 290 291(** [i16_type c] returns an integer type of bitwidth 16 in the context [c]. See 292 [llvm::Type::Int16Ty]. *) 293val i16_type : llcontext -> lltype 294 295(** [i32_type c] returns an integer type of bitwidth 32 in the context [c]. See 296 [llvm::Type::Int32Ty]. *) 297val i32_type : llcontext -> lltype 298 299(** [i64_type c] returns an integer type of bitwidth 64 in the context [c]. See 300 [llvm::Type::Int64Ty]. *) 301val i64_type : llcontext -> lltype 302 303(** [integer_type c n] returns an integer type of bitwidth [n] in the context 304 [c]. See the method [llvm::IntegerType::get]. *) 305val integer_type : llcontext -> int -> lltype 306 307(** [integer_bitwidth c ty] returns the number of bits in the integer type [ty] 308 in the context [c]. See the method [llvm::IntegerType::getBitWidth]. *) 309val integer_bitwidth : lltype -> int 310 311 312(** {7 Operations on real types} *) 313 314(** [float_type c] returns the IEEE 32-bit floating point type in the context 315 [c]. See [llvm::Type::FloatTy]. *) 316val float_type : llcontext -> lltype 317 318(** [double_type c] returns the IEEE 64-bit floating point type in the context 319 [c]. See [llvm::Type::DoubleTy]. *) 320val double_type : llcontext -> lltype 321 322(** [x86fp80_type c] returns the x87 80-bit floating point type in the context 323 [c]. See [llvm::Type::X86_FP80Ty]. *) 324val x86fp80_type : llcontext -> lltype 325 326(** [fp128_type c] returns the IEEE 128-bit floating point type in the context 327 [c]. See [llvm::Type::FP128Ty]. *) 328val fp128_type : llcontext -> lltype 329 330(** [ppc_fp128_type c] returns the PowerPC 128-bit floating point type in the 331 context [c]. See [llvm::Type::PPC_FP128Ty]. *) 332val ppc_fp128_type : llcontext -> lltype 333 334 335(** {7 Operations on function types} *) 336 337(** [function_type ret_ty param_tys] returns the function type returning 338 [ret_ty] and taking [param_tys] as parameters. 339 See the method [llvm::FunctionType::get]. *) 340val function_type : lltype -> lltype array -> lltype 341 342(** [va_arg_function_type ret_ty param_tys] is just like 343 [function_type ret_ty param_tys] except that it returns the function type 344 which also takes a variable number of arguments. 345 See the method [llvm::FunctionType::get]. *) 346val var_arg_function_type : lltype -> lltype array -> lltype 347 348 349(** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false] 350 otherwise. See the method [llvm::FunctionType::isVarArg]. *) 351val is_var_arg : lltype -> bool 352 353(** [return_type fty] gets the return type of the function type [fty]. 354 See the method [llvm::FunctionType::getReturnType]. *) 355val return_type : lltype -> lltype 356 357(** [param_types fty] gets the parameter types of the function type [fty]. 358 See the method [llvm::FunctionType::getParamType]. *) 359val param_types : lltype -> lltype array 360 361 362(** {7 Operations on struct types} *) 363 364(** [struct_type context tys] returns the structure type in the context 365 [context] containing in the types in the array [tys]. See the method 366 [llvm::StructType::get]. *) 367val struct_type : llcontext -> lltype array -> lltype 368 369 370(** [packed_struct_type context ys] returns the packed structure type in the 371 context [context] containing in the types in the array [tys]. See the method 372 [llvm::StructType::get]. *) 373val packed_struct_type : llcontext -> lltype array -> lltype 374 375 376(** [struct_element_types sty] returns the constituent types of the struct type 377 [sty]. See the method [llvm::StructType::getElementType]. *) 378val struct_element_types : lltype -> lltype array 379 380 381(** [is_packed sty] returns [true] if the structure type [sty] is packed, 382 [false] otherwise. See the method [llvm::StructType::isPacked]. *) 383val is_packed : lltype -> bool 384 385 386(** {7 Operations on pointer, vector, and array types} *) 387 388(** [array_type ty n] returns the array type containing [n] elements of type 389 [ty]. See the method [llvm::ArrayType::get]. *) 390val array_type : lltype -> int -> lltype 391 392(** [pointer_type ty] returns the pointer type referencing objects of type 393 [ty] in the default address space (0). 394 See the method [llvm::PointerType::getUnqual]. *) 395val pointer_type : lltype -> lltype 396 397(** [qualified_pointer_type ty as] returns the pointer type referencing objects 398 of type [ty] in address space [as]. 399 See the method [llvm::PointerType::get]. *) 400val qualified_pointer_type : lltype -> int -> lltype 401 402 403(** [vector_type ty n] returns the array type containing [n] elements of the 404 primitive type [ty]. See the method [llvm::ArrayType::get]. *) 405val vector_type : lltype -> int -> lltype 406 407(** [element_type ty] returns the element type of the pointer, vector, or array 408 type [ty]. See the method [llvm::SequentialType::get]. *) 409val element_type : lltype -> lltype 410 411(** [element_type aty] returns the element count of the array type [aty]. 412 See the method [llvm::ArrayType::getNumElements]. *) 413val array_length : lltype -> int 414 415(** [address_space pty] returns the address space qualifier of the pointer type 416 [pty]. See the method [llvm::PointerType::getAddressSpace]. *) 417val address_space : lltype -> int 418 419(** [element_type ty] returns the element count of the vector type [ty]. 420 See the method [llvm::VectorType::getNumElements]. *) 421val vector_size : lltype -> int 422 423 424(** {7 Operations on other types} *) 425 426(** [void_type c] creates a type of a function which does not return any 427 value in the context [c]. See [llvm::Type::VoidTy]. *) 428val void_type : llcontext -> lltype 429 430(** [label_type c] creates a type of a basic block in the context [c]. See 431 [llvm::Type::LabelTy]. *) 432val label_type : llcontext -> lltype 433 434(* {6 Values} *) 435 436(** [type_of v] returns the type of the value [v]. 437 See the method [llvm::Value::getType]. *) 438val type_of : llvalue -> lltype 439 440(** [value_name v] returns the name of the value [v]. For global values, this is 441 the symbol name. For instructions and basic blocks, it is the SSA register 442 name. It is meaningless for constants. 443 See the method [llvm::Value::getName]. *) 444val value_name : llvalue -> string 445 446(** [set_value_name n v] sets the name of the value [v] to [n]. See the method 447 [llvm::Value::setName]. *) 448val set_value_name : string -> llvalue -> unit 449 450(** [dump_value v] prints the .ll representation of the value [v] to standard 451 error. See the method [llvm::Value::dump]. *) 452val dump_value : llvalue -> unit 453 454(** [replace_all_uses_with old new] replaces all uses of the value [old] 455 * with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *) 456val replace_all_uses_with : llvalue -> llvalue -> unit 457 458 459 460(* {6 Uses} *) 461 462(** [use_begin v] returns the first position in the use list for the value [v]. 463 [use_begin] and [use_succ] can e used to iterate over the use list in order. 464 See the method [llvm::Value::use_begin]. *) 465val use_begin : llvalue -> lluse option 466 467(** [use_succ u] returns the use list position succeeding [u]. 468 See the method [llvm::use_value_iterator::operator++]. *) 469val use_succ : lluse -> lluse option 470 471(** [user u] returns the user of the use [u]. 472 See the method [llvm::Use::getUser]. *) 473val user : lluse -> llvalue 474 475(** [used_value u] returns the usee of the use [u]. 476 See the method [llvm::Use::getUsedValue]. *) 477val used_value : lluse -> llvalue 478 479(** [iter_uses f v] applies function [f] to each of the users of the value [v] 480 in order. Tail recursive. *) 481val iter_uses : (lluse -> unit) -> llvalue -> unit 482 483(** [fold_left_uses f init v] is [f (... (f init u1) ...) uN] where 484 [u1,...,uN] are the users of the value [v]. Tail recursive. *) 485val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a 486 487(** [fold_right_uses f v init] is [f u1 (... (f uN init) ...)] where 488 [u1,...,uN] are the users of the value [v]. Not tail recursive. *) 489val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a 490 491 492(* {6 Users} *) 493 494(** [operand v i] returns the operand at index [i] for the value [v]. See the 495 method [llvm::User::getOperand]. *) 496val operand : llvalue -> int -> llvalue 497 498(** [set_operand v i o] sets the operand of the value [v] at the index [i] to 499 the value [o]. 500 See the method [llvm::User::setOperand]. *) 501val set_operand : llvalue -> int -> llvalue -> unit 502 503(** [num_operands v] returns the number of operands for the value [v]. 504 See the method [llvm::User::getNumOperands]. *) 505val num_operands : llvalue -> int 506 507(** {7 Operations on constants of (mostly) any type} *) 508 509(** [is_constant v] returns [true] if the value [v] is a constant, [false] 510 otherwise. Similar to [llvm::isa<Constant>]. *) 511val is_constant : llvalue -> bool 512 513(** [const_null ty] returns the constant null (zero) of the type [ty]. 514 See the method [llvm::Constant::getNullValue]. *) 515val const_null : lltype -> llvalue 516 517(** [const_all_ones ty] returns the constant '-1' of the integer or vector type 518 [ty]. See the method [llvm::Constant::getAllOnesValue]. *) 519val const_all_ones : (*int|vec*)lltype -> llvalue 520 521(** [const_pointer_null ty] returns the constant null (zero) pointer of the type 522 [ty]. See the method [llvm::ConstantPointerNull::get]. *) 523val const_pointer_null : lltype -> llvalue 524 525(** [undef ty] returns the undefined value of the type [ty]. 526 See the method [llvm::UndefValue::get]. *) 527val undef : lltype -> llvalue 528 529(** [is_null v] returns [true] if the value [v] is the null (zero) value. 530 See the method [llvm::Constant::isNullValue]. *) 531val is_null : llvalue -> bool 532 533(** [is_undef v] returns [true] if the value [v] is an undefined value, [false] 534 otherwise. Similar to [llvm::isa<UndefValue>]. *) 535val is_undef : llvalue -> bool 536 537 538(** {7 Operations on instructions} *) 539 540(** [has_metadata i] returns whether or not the instruction [i] has any 541 metadata attached to it. See the function 542 [llvm::Instruction::hasMetadata]. *) 543val has_metadata : llvalue -> bool 544 545(** [metadata i kind] optionally returns the metadata associated with the 546 kind [kind] in the instruction [i] See the function 547 [llvm::Instruction::getMetadata]. *) 548val metadata : llvalue -> int -> llvalue option 549 550(** [set_metadata i kind md] sets the metadata [md] of kind [kind] in the 551 instruction [i]. See the function [llvm::Instruction::setMetadata]. *) 552val set_metadata : llvalue -> int -> llvalue -> unit 553 554(** [clear_metadata i kind] clears the metadata of kind [kind] in the 555 instruction [i]. See the function [llvm::Instruction::setMetadata]. *) 556val clear_metadata : llvalue -> int -> unit 557 558 559(** {7 Operations on metadata} *) 560 561(** [mdstring c s] returns the MDString of the string [s] in the context [c]. 562 See the method [llvm::MDNode::get]. *) 563val mdstring : llcontext -> string -> llvalue 564 565(** [mdnode c elts] returns the MDNode containing the values [elts] in the 566 context [c]. 567 See the method [llvm::MDNode::get]. *) 568val mdnode : llcontext -> llvalue array -> llvalue 569 570 571(** {7 Operations on scalar constants} *) 572 573(** [const_int ty i] returns the integer constant of type [ty] and value [i]. 574 See the method [llvm::ConstantInt::get]. *) 575val const_int : lltype -> int -> llvalue 576 577(** [const_of_int64 ty i] returns the integer constant of type [ty] and value 578 [i]. See the method [llvm::ConstantInt::get]. *) 579val const_of_int64 : lltype -> Int64.t -> bool -> llvalue 580 581 582(** [const_int_of_string ty s r] returns the integer constant of type [ty] and 583 * value [s], with the radix [r]. See the method [llvm::ConstantInt::get]. *) 584val const_int_of_string : lltype -> string -> int -> llvalue 585 586 587(** [const_float ty n] returns the floating point constant of type [ty] and 588 value [n]. See the method [llvm::ConstantFP::get]. *) 589val const_float : lltype -> float -> llvalue 590 591(** [const_float_of_string ty s] returns the floating point constant of type 592 [ty] and value [n]. See the method [llvm::ConstantFP::get]. *) 593val const_float_of_string : lltype -> string -> llvalue 594 595 596 597(** {7 Operations on composite constants} *) 598 599(** [const_string c s] returns the constant [i8] array with the values of the 600 characters in the string [s] in the context [c]. The array is not 601 null-terminated (but see {!const_stringz}). This value can in turn be used 602 as the initializer for a global variable. See the method 603 [llvm::ConstantArray::get]. *) 604val const_string : llcontext -> string -> llvalue 605 606(** [const_stringz c s] returns the constant [i8] array with the values of the 607 characters in the string [s] and a null terminator in the context [c]. This 608 value can in turn be used as the initializer for a global variable. 609 See the method [llvm::ConstantArray::get]. *) 610val const_stringz : llcontext -> string -> llvalue 611 612(** [const_array ty elts] returns the constant array of type 613 [array_type ty (Array.length elts)] and containing the values [elts]. 614 This value can in turn be used as the initializer for a global variable. 615 See the method [llvm::ConstantArray::get]. *) 616val const_array : lltype -> llvalue array -> llvalue 617 618(** [const_struct context elts] returns the structured constant of type 619 [struct_type (Array.map type_of elts)] and containing the values [elts] 620 in the context [context]. This value can in turn be used as the initializer 621 for a global variable. See the method [llvm::ConstantStruct::get]. *) 622val const_struct : llcontext -> llvalue array -> llvalue 623 624 625(** [const_packed_struct context elts] returns the structured constant of 626 type {!packed_struct_type} [(Array.map type_of elts)] and containing the 627 values [elts] in the context [context]. This value can in turn be used as 628 the initializer for a global variable. See the method 629 [llvm::ConstantStruct::get]. *) 630val const_packed_struct : llcontext -> llvalue array -> llvalue 631 632 633(** [const_vector elts] returns the vector constant of type 634 [vector_type (type_of elts.(0)) (Array.length elts)] and containing the 635 values [elts]. See the method [llvm::ConstantVector::get]. *) 636val const_vector : llvalue array -> llvalue 637 638 639(** {7 Constant expressions} *) 640 641(** [align_of ty] returns the alignof constant for the type [ty]. This is 642 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty})) 643 (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably 644 more readable. See the method [llvm::ConstantExpr::getAlignOf]. *) 645val align_of : lltype -> llvalue 646 647(** [size_of ty] returns the sizeof constant for the type [ty]. This is 648 equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty)) 649 (const_int i32_type 1)) i64_type], but considerably more readable. 650 See the method [llvm::ConstantExpr::getSizeOf]. *) 651val size_of : lltype -> llvalue 652 653(** [const_neg c] returns the arithmetic negation of the constant [c]. 654 See the method [llvm::ConstantExpr::getNeg]. *) 655val const_neg : llvalue -> llvalue 656 657(** [const_nsw_neg c] returns the arithmetic negation of the constant [c] with 658 no signed wrapping. The result is undefined if the negation overflows. 659 See the method [llvm::ConstantExpr::getNSWNeg]. *) 660val const_nsw_neg : llvalue -> llvalue 661 662(** [const_nuw_neg c] returns the arithmetic negation of the constant [c] with 663 no unsigned wrapping. The result is undefined if the negation overflows. 664 See the method [llvm::ConstantExpr::getNUWNeg]. *) 665val const_nuw_neg : llvalue -> llvalue 666 667(** [const_fneg c] returns the arithmetic negation of the constant float [c]. 668 See the method [llvm::ConstantExpr::getFNeg]. *) 669val const_fneg : llvalue -> llvalue 670 671(** [const_not c] returns the bitwise inverse of the constant [c]. 672 See the method [llvm::ConstantExpr::getNot]. *) 673val const_not : llvalue -> llvalue 674 675(** [const_add c1 c2] returns the constant sum of two constants. 676 See the method [llvm::ConstantExpr::getAdd]. *) 677val const_add : llvalue -> llvalue -> llvalue 678 679(** [const_nsw_add c1 c2] returns the constant sum of two constants with no 680 signed wrapping. The result is undefined if the sum overflows. 681 See the method [llvm::ConstantExpr::getNSWAdd]. *) 682val const_nsw_add : llvalue -> llvalue -> llvalue 683 684(** [const_nuw_add c1 c2] returns the constant sum of two constants with no 685 unsigned wrapping. The result is undefined if the sum overflows. 686 See the method [llvm::ConstantExpr::getNSWAdd]. *) 687val const_nuw_add : llvalue -> llvalue -> llvalue 688 689(** [const_fadd c1 c2] returns the constant sum of two constant floats. 690 See the method [llvm::ConstantExpr::getFAdd]. *) 691val const_fadd : llvalue -> llvalue -> llvalue 692 693(** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two 694 constants. See the method [llvm::ConstantExpr::getSub]. *) 695val const_sub : llvalue -> llvalue -> llvalue 696 697(** [const_nsw_sub c1 c2] returns the constant difference of two constants with 698 no signed wrapping. The result is undefined if the sum overflows. 699 See the method [llvm::ConstantExpr::getNSWSub]. *) 700val const_nsw_sub : llvalue -> llvalue -> llvalue 701 702(** [const_nuw_sub c1 c2] returns the constant difference of two constants with 703 no unsigned wrapping. The result is undefined if the sum overflows. 704 See the method [llvm::ConstantExpr::getNSWSub]. *) 705val const_nuw_sub : llvalue -> llvalue -> llvalue 706 707(** [const_fsub c1 c2] returns the constant difference, [c1 - c2], of two 708 constant floats. See the method [llvm::ConstantExpr::getFSub]. *) 709val const_fsub : llvalue -> llvalue -> llvalue 710 711(** [const_mul c1 c2] returns the constant product of two constants. 712 See the method [llvm::ConstantExpr::getMul]. *) 713val const_mul : llvalue -> llvalue -> llvalue 714 715(** [const_nsw_mul c1 c2] returns the constant product of two constants with 716 no signed wrapping. The result is undefined if the sum overflows. 717 See the method [llvm::ConstantExpr::getNSWMul]. *) 718val const_nsw_mul : llvalue -> llvalue -> llvalue 719 720(** [const_nuw_mul c1 c2] returns the constant product of two constants with 721 no unsigned wrapping. The result is undefined if the sum overflows. 722 See the method [llvm::ConstantExpr::getNSWMul]. *) 723val const_nuw_mul : llvalue -> llvalue -> llvalue 724 725(** [const_fmul c1 c2] returns the constant product of two constants floats. 726 See the method [llvm::ConstantExpr::getFMul]. *) 727val const_fmul : llvalue -> llvalue -> llvalue 728 729(** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned 730 integer constants. 731 See the method [llvm::ConstantExpr::getUDiv]. *) 732val const_udiv : llvalue -> llvalue -> llvalue 733 734(** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed 735 integer constants. 736 See the method [llvm::ConstantExpr::getSDiv]. *) 737val const_sdiv : llvalue -> llvalue -> llvalue 738 739(** [const_exact_sdiv c1 c2] returns the constant quotient [c1 / c2] of two 740 signed integer constants. The result is undefined if the result is rounded 741 or overflows. See the method [llvm::ConstantExpr::getExactSDiv]. *) 742val const_exact_sdiv : llvalue -> llvalue -> llvalue 743 744(** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating 745 point constants. 746 See the method [llvm::ConstantExpr::getFDiv]. *) 747val const_fdiv : llvalue -> llvalue -> llvalue 748 749(** [const_urem c1 c2] returns the constant remainder [c1 MOD c2] of two 750 unsigned integer constants. 751 See the method [llvm::ConstantExpr::getURem]. *) 752val const_urem : llvalue -> llvalue -> llvalue 753 754(** [const_srem c1 c2] returns the constant remainder [c1 MOD c2] of two 755 signed integer constants. 756 See the method [llvm::ConstantExpr::getSRem]. *) 757val const_srem : llvalue -> llvalue -> llvalue 758 759(** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two 760 signed floating point constants. 761 See the method [llvm::ConstantExpr::getFRem]. *) 762val const_frem : llvalue -> llvalue -> llvalue 763 764(** [const_and c1 c2] returns the constant bitwise [AND] of two integer 765 constants. 766 See the method [llvm::ConstantExpr::getAnd]. *) 767val const_and : llvalue -> llvalue -> llvalue 768 769(** [const_or c1 c2] returns the constant bitwise [OR] of two integer 770 constants. 771 See the method [llvm::ConstantExpr::getOr]. *) 772val const_or : llvalue -> llvalue -> llvalue 773 774(** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer 775 constants. 776 See the method [llvm::ConstantExpr::getXor]. *) 777val const_xor : llvalue -> llvalue -> llvalue 778 779(** [const_icmp pred c1 c2] returns the constant comparison of two integer 780 constants, [c1 pred c2]. 781 See the method [llvm::ConstantExpr::getICmp]. *) 782val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue 783 784 785(** [const_fcmp pred c1 c2] returns the constant comparison of two floating 786 point constants, [c1 pred c2]. 787 See the method [llvm::ConstantExpr::getFCmp]. *) 788val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue 789 790 791(** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the 792 constant integer [c2]. 793 See the method [llvm::ConstantExpr::getShl]. *) 794val const_shl : llvalue -> llvalue -> llvalue 795 796(** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the 797 constant integer [c2] with zero extension. 798 See the method [llvm::ConstantExpr::getLShr]. *) 799val const_lshr : llvalue -> llvalue -> llvalue 800 801(** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the 802 constant integer [c2] with sign extension. 803 See the method [llvm::ConstantExpr::getAShr]. *) 804val const_ashr : llvalue -> llvalue -> llvalue 805 806(** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the 807 constant integers indices from the array [indices]. 808 See the method [llvm::ConstantExpr::getGetElementPtr]. *) 809val const_gep : llvalue -> llvalue array -> llvalue 810 811(** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [p1] 812 with the constant integers indices from the array [indices]. 813 See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *) 814val const_in_bounds_gep : llvalue -> llvalue array -> llvalue 815 816 817(** [const_trunc c ty] returns the constant truncation of integer constant [c] 818 to the smaller integer type [ty]. 819 See the method [llvm::ConstantExpr::getTrunc]. *) 820val const_trunc : llvalue -> lltype -> llvalue 821 822(** [const_sext c ty] returns the constant sign extension of integer constant 823 [c] to the larger integer type [ty]. 824 See the method [llvm::ConstantExpr::getSExt]. *) 825val const_sext : llvalue -> lltype -> llvalue 826 827(** [const_zext c ty] returns the constant zero extension of integer constant 828 [c] to the larger integer type [ty]. 829 See the method [llvm::ConstantExpr::getZExt]. *) 830val const_zext : llvalue -> lltype -> llvalue 831 832(** [const_fptrunc c ty] returns the constant truncation of floating point 833 constant [c] to the smaller floating point type [ty]. 834 See the method [llvm::ConstantExpr::getFPTrunc]. *) 835val const_fptrunc : llvalue -> lltype -> llvalue 836 837(** [const_fpext c ty] returns the constant extension of floating point constant 838 [c] to the larger floating point type [ty]. 839 See the method [llvm::ConstantExpr::getFPExt]. *) 840val const_fpext : llvalue -> lltype -> llvalue 841 842(** [const_uitofp c ty] returns the constant floating point conversion of 843 unsigned integer constant [c] to the floating point type [ty]. 844 See the method [llvm::ConstantExpr::getUIToFP]. *) 845val const_uitofp : llvalue -> lltype -> llvalue 846 847(** [const_sitofp c ty] returns the constant floating point conversion of 848 signed integer constant [c] to the floating point type [ty]. 849 See the method [llvm::ConstantExpr::getSIToFP]. *) 850val const_sitofp : llvalue -> lltype -> llvalue 851 852(** [const_fptoui c ty] returns the constant unsigned integer conversion of 853 floating point constant [c] to integer type [ty]. 854 See the method [llvm::ConstantExpr::getFPToUI]. *) 855val const_fptoui : llvalue -> lltype -> llvalue 856 857(** [const_fptoui c ty] returns the constant unsigned integer conversion of 858 floating point constant [c] to integer type [ty]. 859 See the method [llvm::ConstantExpr::getFPToSI]. *) 860val const_fptosi : llvalue -> lltype -> llvalue 861 862(** [const_ptrtoint c ty] returns the constant integer conversion of 863 pointer constant [c] to integer type [ty]. 864 See the method [llvm::ConstantExpr::getPtrToInt]. *) 865val const_ptrtoint : llvalue -> lltype -> llvalue 866 867(** [const_inttoptr c ty] returns the constant pointer conversion of 868 integer constant [c] to pointer type [ty]. 869 See the method [llvm::ConstantExpr::getIntToPtr]. *) 870val const_inttoptr : llvalue -> lltype -> llvalue 871 872(** [const_bitcast c ty] returns the constant bitwise conversion of constant [c] 873 to type [ty] of equal size. 874 See the method [llvm::ConstantExpr::getBitCast]. *) 875val const_bitcast : llvalue -> lltype -> llvalue 876 877(** [const_zext_or_bitcast c ty] returns a constant zext or bitwise cast 878 conversion of constant [c] to type [ty]. 879 See the method [llvm::ConstantExpr::getZExtOrBitCast]. *) 880val const_zext_or_bitcast : llvalue -> lltype -> llvalue 881 882 883(** [const_sext_or_bitcast c ty] returns a constant sext or bitwise cast 884 conversion of constant [c] to type [ty]. 885 See the method [llvm::ConstantExpr::getSExtOrBitCast]. *) 886val const_sext_or_bitcast : llvalue -> lltype -> llvalue 887 888 889(** [const_trunc_or_bitcast c ty] returns a constant trunc or bitwise cast 890 conversion of constant [c] to type [ty]. 891 See the method [llvm::ConstantExpr::getTruncOrBitCast]. *) 892val const_trunc_or_bitcast : llvalue -> lltype -> llvalue 893 894 895(** [const_pointercast c ty] returns a constant bitcast or a pointer-to-int 896 cast conversion of constant [c] to type [ty] of equal size. 897 See the method [llvm::ConstantExpr::getPointerCast]. *) 898val const_pointercast : llvalue -> lltype -> llvalue 899 900 901(** [const_intcast c ty] returns a constant zext, bitcast, or trunc for integer 902 -> integer casts of constant [c] to type [ty]. 903 See the method [llvm::ConstantExpr::getIntCast]. *) 904val const_intcast : llvalue -> lltype -> llvalue 905 906 907(** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp -> 908 fp casts of constant [c] to type [ty]. 909 See the method [llvm::ConstantExpr::getFPCast]. *) 910val const_fpcast : llvalue -> lltype -> llvalue 911 912 913(** [const_select cond t f] returns the constant conditional which returns value 914 [t] if the boolean constant [cond] is true and the value [f] otherwise. 915 See the method [llvm::ConstantExpr::getSelect]. *) 916val const_select : llvalue -> llvalue -> llvalue -> llvalue 917 918 919(** [const_extractelement vec i] returns the constant [i]th element of 920 constant vector [vec]. [i] must be a constant [i32] value unsigned less than 921 the size of the vector. 922 See the method [llvm::ConstantExpr::getExtractElement]. *) 923val const_extractelement : llvalue -> llvalue -> llvalue 924 925 926(** [const_insertelement vec v i] returns the constant vector with the same 927 elements as constant vector [v] but the [i]th element replaced by the 928 constant [v]. [v] must be a constant value with the type of the vector 929 elements. [i] must be a constant [i32] value unsigned less than the size 930 of the vector. 931 See the method [llvm::ConstantExpr::getInsertElement]. *) 932val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue 933 934 935(** [const_shufflevector a b mask] returns a constant [shufflevector]. 936 See the LLVM Language Reference for details on the [shufflevector] 937 instruction. 938 See the method [llvm::ConstantExpr::getShuffleVector]. *) 939val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue 940 941 942(** [const_extractvalue agg idxs] returns the constant [idxs]th value of 943 constant aggregate [agg]. Each [idxs] must be less than the size of the 944 aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *) 945val const_extractvalue : llvalue -> int array -> llvalue 946 947 948(** [const_insertvalue agg val idxs] inserts the value [val] in the specified 949 indexs [idxs] in the aggegate [agg]. Each [idxs] must be less than the size 950 of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *) 951val const_insertvalue : llvalue -> llvalue -> int array -> llvalue 952 953 954(** [const_inline_asm ty asm con side align] inserts a inline assembly string. 955 See the method [llvm::InlineAsm::get]. *) 956val const_inline_asm : lltype -> string -> string -> bool -> bool -> 957 llvalue 958 959 960(** [block_address f bb] returns the address of the basic block [bb] in the 961 function [f]. See the method [llvm::BasicBlock::get]. *) 962val block_address : llvalue -> llbasicblock -> llvalue 963 964 965(** {7 Operations on global variables, functions, and aliases (globals)} *) 966 967(** [global_parent g] is the enclosing module of the global value [g]. 968 See the method [llvm::GlobalValue::getParent]. *) 969val global_parent : llvalue -> llmodule 970 971(** [is_declaration g] returns [true] if the global value [g] is a declaration 972 only. Returns [false] otherwise. 973 See the method [llvm::GlobalValue::isDeclaration]. *) 974val is_declaration : llvalue -> bool 975 976(** [linkage g] returns the linkage of the global value [g]. 977 See the method [llvm::GlobalValue::getLinkage]. *) 978val linkage : llvalue -> Linkage.t 979 980(** [set_linkage l g] sets the linkage of the global value [g] to [l]. 981 See the method [llvm::GlobalValue::setLinkage]. *) 982val set_linkage : Linkage.t -> llvalue -> unit 983 984(** [section g] returns the linker section of the global value [g]. 985 See the method [llvm::GlobalValue::getSection]. *) 986val section : llvalue -> string 987 988(** [set_section s g] sets the linker section of the global value [g] to [s]. 989 See the method [llvm::GlobalValue::setSection]. *) 990val set_section : string -> llvalue -> unit 991 992(** [visibility g] returns the linker visibility of the global value [g]. 993 See the method [llvm::GlobalValue::getVisibility]. *) 994val visibility : llvalue -> Visibility.t 995 996(** [set_visibility v g] sets the linker visibility of the global value [g] to 997 [v]. See the method [llvm::GlobalValue::setVisibility]. *) 998val set_visibility : Visibility.t -> llvalue -> unit 999 1000 1001(** [alignment g] returns the required alignment of the global value [g]. 1002 See the method [llvm::GlobalValue::getAlignment]. *) 1003val alignment : llvalue -> int 1004 1005(** [set_alignment n g] sets the required alignment of the global value [g] to 1006 [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *) 1007val set_alignment : int -> llvalue -> unit 1008 1009 1010(** {7 Operations on global variables} *) 1011 1012(** [declare_global ty name m] returns a new global variable of type [ty] and 1013 with name [name] in module [m] in the default address space (0). If such a 1014 global variable already exists, it is returned. If the type of the existing 1015 global differs, then a bitcast to [ty] is returned. *) 1016val declare_global : lltype -> string -> llmodule -> llvalue 1017 1018 1019(** [declare_qualified_global ty name addrspace m] returns a new global variable 1020 of type [ty] and with name [name] in module [m] in the address space 1021 [addrspace]. If such a global variable already exists, it is returned. If 1022 the type of the existing global differs, then a bitcast to [ty] is 1023 returned. *) 1024val declare_qualified_global : lltype -> string -> int -> llmodule -> 1025 llvalue 1026 1027 1028(** [define_global name init m] returns a new global with name [name] and 1029 initializer [init] in module [m] in the default address space (0). If the 1030 named global already exists, it is renamed. 1031 See the constructor of [llvm::GlobalVariable]. *) 1032val define_global : string -> llvalue -> llmodule -> llvalue 1033 1034 1035(** [define_qualified_global name init addrspace m] returns a new global with 1036 name [name] and initializer [init] in module [m] in the address space 1037 [addrspace]. If the named global already exists, it is renamed. 1038 See the constructor of [llvm::GlobalVariable]. *) 1039val define_qualified_global : string -> llvalue -> int -> llmodule -> 1040 llvalue 1041 1042 1043(** [lookup_global name m] returns [Some g] if a global variable with name 1044 [name] exists in module [m]. If no such global exists, returns [None]. 1045 See the [llvm::GlobalVariable] constructor. *) 1046val lookup_global : string -> llmodule -> llvalue option 1047 1048 1049(** [delete_global gv] destroys the global variable [gv]. 1050 See the method [llvm::GlobalVariable::eraseFromParent]. *) 1051val delete_global : llvalue -> unit 1052 1053(** [global_begin m] returns the first position in the global variable list of 1054 the module [m]. [global_begin] and [global_succ] can be used to iterate 1055 over the global list in order. 1056 See the method [llvm::Module::global_begin]. *) 1057val global_begin : llmodule -> (llmodule, llvalue) llpos 1058 1059 1060(** [global_succ gv] returns the global variable list position succeeding 1061 [Before gv]. 1062 See the method [llvm::Module::global_iterator::operator++]. *) 1063val global_succ : llvalue -> (llmodule, llvalue) llpos 1064 1065 1066(** [iter_globals f m] applies function [f] to each of the global variables of 1067 module [m] in order. Tail recursive. *) 1068val iter_globals : (llvalue -> unit) -> llmodule -> unit 1069 1070(** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where 1071 [g1,...,gN] are the global variables of module [m]. Tail recursive. *) 1072val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a 1073 1074(** [global_end m] returns the last position in the global variable list of the 1075 module [m]. [global_end] and [global_pred] can be used to iterate over the 1076 global list in reverse. 1077 See the method [llvm::Module::global_end]. *) 1078val global_end : llmodule -> (llmodule, llvalue) llrev_pos 1079 1080 1081(** [global_pred gv] returns the global variable list position preceding 1082 [After gv]. 1083 See the method [llvm::Module::global_iterator::operator--]. *) 1084val global_pred : llvalue -> (llmodule, llvalue) llrev_pos 1085 1086 1087(** [rev_iter_globals f m] applies function [f] to each of the global variables 1088 of module [m] in reverse order. Tail recursive. *) 1089val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit 1090 1091(** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where 1092 [g1,...,gN] are the global variables of module [m]. Tail recursive. *) 1093val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a 1094 1095(** [is_global_constant gv] returns [true] if the global variabile [gv] is a 1096 constant. Returns [false] otherwise. 1097 See the method [llvm::GlobalVariable::isConstant]. *) 1098val is_global_constant : llvalue -> bool 1099 1100(** [set_global_constant c gv] sets the global variable [gv] to be a constant if 1101 [c] is [true] and not if [c] is [false]. 1102 See the method [llvm::GlobalVariable::setConstant]. *) 1103val set_global_constant : bool -> llvalue -> unit 1104 1105 1106(** [global_initializer gv] returns the initializer for the global variable 1107 [gv]. See the method [llvm::GlobalVariable::getInitializer]. *) 1108val global_initializer : llvalue -> llvalue 1109 1110(** [set_initializer c gv] sets the initializer for the global variable 1111 [gv] to the constant [c]. 1112 See the method [llvm::GlobalVariable::setInitializer]. *) 1113val set_initializer : llvalue -> llvalue -> unit 1114 1115(** [remove_initializer gv] unsets the initializer for the global variable 1116 [gv]. 1117 See the method [llvm::GlobalVariable::setInitializer]. *) 1118val remove_initializer : llvalue -> unit 1119 1120(** [is_thread_local gv] returns [true] if the global variable [gv] is 1121 thread-local and [false] otherwise. 1122 See the method [llvm::GlobalVariable::isThreadLocal]. *) 1123val is_thread_local : llvalue -> bool 1124 1125(** [set_thread_local c gv] sets the global variable [gv] to be thread local if 1126 [c] is [true] and not otherwise. 1127 See the method [llvm::GlobalVariable::setThreadLocal]. *) 1128val set_thread_local : bool -> llvalue -> unit 1129 1130 1131(** {7 Operations on aliases} *) 1132 1133(** [add_alias m t a n] inserts an alias in the module [m] with the type [t] and 1134 the aliasee [a] with the name [n]. 1135 See the constructor for [llvm::GlobalAlias]. *) 1136val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue 1137 1138 1139 1140(** {7 Operations on functions} *) 1141 1142(** [declare_function name ty m] returns a new function of type [ty] and 1143 with name [name] in module [m]. If such a function already exists, 1144 it is returned. If the type of the existing function differs, then a bitcast 1145 to [ty] is returned. *) 1146val declare_function : string -> lltype -> llmodule -> llvalue 1147 1148 1149(** [define_function name ty m] creates a new function with name [name] and 1150 type [ty] in module [m]. If the named function already exists, it is 1151 renamed. An entry basic block is created in the function. 1152 See the constructor of [llvm::GlobalVariable]. *) 1153val define_function : string -> lltype -> llmodule -> llvalue 1154 1155 1156(** [lookup_function name m] returns [Some f] if a function with name 1157 [name] exists in module [m]. If no such function exists, returns [None]. 1158 See the method [llvm::Module] constructor. *) 1159val lookup_function : string -> llmodule -> llvalue option 1160 1161 1162(** [delete_function f] destroys the function [f]. 1163 See the method [llvm::Function::eraseFromParent]. *) 1164val delete_function : llvalue -> unit 1165 1166(** [function_begin m] returns the first position in the function list of the 1167 module [m]. [function_begin] and [function_succ] can be used to iterate over 1168 the function list in order. 1169 See the method [llvm::Module::begin]. *) 1170val function_begin : llmodule -> (llmodule, llvalue) llpos 1171 1172 1173(** [function_succ gv] returns the function list position succeeding 1174 [Before gv]. 1175 See the method [llvm::Module::iterator::operator++]. *) 1176val function_succ : llvalue -> (llmodule, llvalue) llpos 1177 1178 1179(** [iter_functions f m] applies function [f] to each of the functions of module 1180 [m] in order. Tail recursive. *) 1181val iter_functions : (llvalue -> unit) -> llmodule -> unit 1182 1183(** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where 1184 [f1,...,fN] are the functions of module [m]. Tail recursive. *) 1185val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a 1186 1187(** [function_end m] returns the last position in the function list of 1188 the module [m]. [function_end] and [function_pred] can be used to iterate 1189 over the function list in reverse. 1190 See the method [llvm::Module::end]. *) 1191val function_end : llmodule -> (llmodule, llvalue) llrev_pos 1192 1193 1194(** [function_pred gv] returns the function list position preceding [After gv]. 1195 See the method [llvm::Module::iterator::operator--]. *) 1196val function_pred : llvalue -> (llmodule, llvalue) llrev_pos 1197 1198 1199(** [rev_iter_functions f fn] applies function [f] to each of the functions of 1200 module [m] in reverse order. Tail recursive. *) 1201val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit 1202 1203(** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where 1204 [f1,...,fN] are the functions of module [m]. Tail recursive. *) 1205val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a 1206 1207(** [is_intrinsic f] returns true if the function [f] is an intrinsic. 1208 See the method [llvm::Function::isIntrinsic]. *) 1209val is_intrinsic : llvalue -> bool 1210 1211(** [function_call_conv f] returns the calling convention of the function [f]. 1212 See the method [llvm::Function::getCallingConv]. *) 1213val function_call_conv : llvalue -> int 1214 1215(** [set_function_call_conv cc f] sets the calling convention of the function 1216 [f] to the calling convention numbered [cc]. 1217 See the method [llvm::Function::setCallingConv]. *) 1218val set_function_call_conv : int -> llvalue -> unit 1219 1220 1221(** [gc f] returns [Some name] if the function [f] has a garbage 1222 collection algorithm specified and [None] otherwise. 1223 See the method [llvm::Function::getGC]. *) 1224val gc : llvalue -> string option 1225 1226(** [set_gc gc f] sets the collection algorithm for the function [f] to 1227 [gc]. See the method [llvm::Function::setGC]. *) 1228val set_gc : string option -> llvalue -> unit 1229 1230(** [add_function_attr f a] adds attribute [a] to the return type of function 1231 [f]. *) 1232val add_function_attr : llvalue -> Attribute.t -> unit 1233 1234(** [remove_function_attr f a] removes attribute [a] from the return type of 1235 function [f]. *) 1236val remove_function_attr : llvalue -> Attribute.t -> unit 1237 1238(** {7 Operations on params} *) 1239 1240(** [params f] returns the parameters of function [f]. 1241 See the method [llvm::Function::getArgumentList]. *) 1242val params : llvalue -> llvalue array 1243 1244(** [param f n] returns the [n]th parameter of function [f]. 1245 See the method [llvm::Function::getArgumentList]. *) 1246val param : llvalue -> int -> llvalue 1247 1248(** [param_parent p] returns the parent function that owns the parameter. 1249 See the method [llvm::Argument::getParent]. *) 1250val param_parent : llvalue -> llvalue 1251 1252(** [param_begin f] returns the first position in the parameter list of the 1253 function [f]. [param_begin] and [param_succ] can be used to iterate over 1254 the parameter list in order. 1255 See the method [llvm::Function::arg_begin]. *) 1256val param_begin : llvalue -> (llvalue, llvalue) llpos 1257 1258(** [param_succ bb] returns the parameter list position succeeding 1259 [Before bb]. 1260 See the method [llvm::Function::arg_iterator::operator++]. *) 1261val param_succ : llvalue -> (llvalue, llvalue) llpos 1262 1263(** [iter_params f fn] applies function [f] to each of the parameters 1264 of function [fn] in order. Tail recursive. *) 1265val iter_params : (llvalue -> unit) -> llvalue -> unit 1266 1267(** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where 1268 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *) 1269val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a 1270 1271(** [param_end f] returns the last position in the parameter list of 1272 the function [f]. [param_end] and [param_pred] can be used to iterate 1273 over the parameter list in reverse. 1274 See the method [llvm::Function::arg_end]. *) 1275val param_end : llvalue -> (llvalue, llvalue) llrev_pos 1276 1277(** [param_pred gv] returns the function list position preceding [After gv]. 1278 See the method [llvm::Function::arg_iterator::operator--]. *) 1279val param_pred : llvalue -> (llvalue, llvalue) llrev_pos 1280 1281 1282(** [rev_iter_params f fn] applies function [f] to each of the parameters 1283 of function [fn] in reverse order. Tail recursive. *) 1284val rev_iter_params : (llvalue -> unit) -> llvalue -> unit 1285 1286(** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where 1287 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *) 1288val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a 1289 1290(** [add_param p a] adds attribute [a] to parameter [p]. *) 1291val add_param_attr : llvalue -> Attribute.t -> unit 1292 1293(** [remove_param_attr p a] removes attribute [a] from parameter [p]. *) 1294val remove_param_attr : llvalue -> Attribute.t -> unit 1295 1296(** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *) 1297val set_param_alignment : llvalue -> int -> unit 1298 1299 1300(** {7 Operations on basic blocks} *) 1301 1302(** [basic_blocks fn] returns the basic blocks of the function [f]. 1303 See the method [llvm::Function::getBasicBlockList]. *) 1304val basic_blocks : llvalue -> llbasicblock array 1305 1306(** [entry_block fn] returns the entry basic block of the function [f]. 1307 See the method [llvm::Function::getEntryBlock]. *) 1308val entry_block : llvalue -> llbasicblock 1309 1310(** [delete_block bb] deletes the basic block [bb]. 1311 See the method [llvm::BasicBlock::eraseFromParent]. *) 1312val delete_block : llbasicblock -> unit 1313 1314(** [append_block c name f] creates a new basic block named [name] at the end of 1315 function [f] in the context [c]. 1316 See the constructor of [llvm::BasicBlock]. *) 1317val append_block : llcontext -> string -> llvalue -> llbasicblock 1318 1319 1320(** [insert_block c name bb] creates a new basic block named [name] before the 1321 basic block [bb] in the context [c]. 1322 See the constructor of [llvm::BasicBlock]. *) 1323val insert_block : llcontext -> string -> llbasicblock -> llbasicblock 1324 1325 1326(** [block_parent bb] returns the parent function that owns the basic block. 1327 See the method [llvm::BasicBlock::getParent]. *) 1328val block_parent : llbasicblock -> llvalue 1329 1330(** [block_begin f] returns the first position in the basic block list of the 1331 function [f]. [block_begin] and [block_succ] can be used to iterate over 1332 the basic block list in order. 1333 See the method [llvm::Function::begin]. *) 1334val block_begin : llvalue -> (llvalue, llbasicblock) llpos 1335 1336 1337(** [block_succ bb] returns the basic block list position succeeding 1338 [Before bb]. 1339 See the method [llvm::Function::iterator::operator++]. *) 1340val block_succ : llbasicblock -> (llvalue, llbasicblock) llpos 1341 1342 1343(** [iter_blocks f fn] applies function [f] to each of the basic blocks 1344 of function [fn] in order. Tail recursive. *) 1345val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit 1346 1347(** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where 1348 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *) 1349val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a 1350 1351(** [block_end f] returns the last position in the basic block list of 1352 the function [f]. [block_end] and [block_pred] can be used to iterate 1353 over the basic block list in reverse. 1354 See the method [llvm::Function::end]. *) 1355val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos 1356 1357 1358(** [block_pred gv] returns the function list position preceding [After gv]. 1359 See the method [llvm::Function::iterator::operator--]. *) 1360val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos 1361 1362 1363(** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks 1364 of function [fn] in reverse order. Tail recursive. *) 1365val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit 1366 1367(** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where 1368 [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *) 1369val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a 1370 1371(** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *) 1372val value_of_block : llbasicblock -> llvalue 1373 1374(** [value_is_block v] returns [true] if the value [v] is a basic block and 1375 [false] otherwise. 1376 Similar to [llvm::isa<BasicBlock>]. *) 1377val value_is_block : llvalue -> bool 1378 1379(** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *) 1380val block_of_value : llvalue -> llbasicblock 1381 1382 1383(** {7 Operations on instructions} *) 1384 1385(** [instr_parent i] is the enclosing basic block of the instruction [i]. 1386 See the method [llvm::Instruction::getParent]. *) 1387val instr_parent : llvalue -> llbasicblock 1388 1389(** [instr_begin bb] returns the first position in the instruction list of the 1390 basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over 1391 the instruction list in order. 1392 See the method [llvm::BasicBlock::begin]. *) 1393val instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos 1394 1395 1396(** [instr_succ i] returns the instruction list position succeeding [Before i]. 1397 See the method [llvm::BasicBlock::iterator::operator++]. *) 1398val instr_succ : llvalue -> (llbasicblock, llvalue) llpos 1399 1400 1401(** [iter_instrs f bb] applies function [f] to each of the instructions of basic 1402 block [bb] in order. Tail recursive. *) 1403val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit 1404 1405(** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where 1406 [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *) 1407val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a 1408 1409(** [instr_end bb] returns the last position in the instruction list of the 1410 basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over 1411 the instruction list in reverse. 1412 See the method [llvm::BasicBlock::end]. *) 1413val instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos 1414 1415 1416(** [instr_pred i] returns the instruction list position preceding [After i]. 1417 See the method [llvm::BasicBlock::iterator::operator--]. *) 1418val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos 1419 1420 1421(** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where 1422 [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *) 1423val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a 1424 1425 1426(** {7 Operations on call sites} *) 1427 1428(** [instruction_call_conv ci] is the calling convention for the call or invoke 1429 instruction [ci], which may be one of the values from the module 1430 {!CallConv}. See the method [llvm::CallInst::getCallingConv] and 1431 [llvm::InvokeInst::getCallingConv]. *) 1432val instruction_call_conv: llvalue -> int 1433 1434 1435(** [set_instruction_call_conv cc ci] sets the calling convention for the call 1436 or invoke instruction [ci] to the integer [cc], which can be one of the 1437 values from the module {!CallConv}. 1438 See the method [llvm::CallInst::setCallingConv] 1439 and [llvm::InvokeInst::setCallingConv]. *) 1440val set_instruction_call_conv: int -> llvalue -> unit 1441 1442 1443(** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th 1444 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return 1445 value. *) 1446val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit 1447 1448(** [remove_instruction_param_attr ci i a] removes attribute [a] from the 1449 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the 1450 return value. *) 1451val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit 1452 1453(** {Operations on call instructions (only)} *) 1454 1455(** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as 1456 eligible for tail call optimization, [false] otherwise. 1457 See the method [llvm::CallInst::isTailCall]. *) 1458val is_tail_call : llvalue -> bool 1459 1460(** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail 1461 call optimization if [tc] is [true], clears otherwise. 1462 See the method [llvm::CallInst::setTailCall]. *) 1463val set_tail_call : bool -> llvalue -> unit 1464 1465(** {7 Operations on phi nodes} *) 1466 1467(** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use 1468 with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *) 1469val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit 1470 1471 1472(** [incoming pn] returns the list of value-block pairs for phi node [pn]. 1473 See the method [llvm::PHINode::getIncomingValue]. *) 1474val incoming : llvalue -> (llvalue * llbasicblock) list 1475 1476 1477 1478(** {6 Instruction builders} *) 1479 1480(** [builder context] creates an instruction builder with no position in 1481 the context [context]. It is invalid to use this builder until its position 1482 is set with {!position_before} or {!position_at_end}. See the constructor 1483 for [llvm::LLVMBuilder]. *) 1484val builder : llcontext -> llbuilder 1485 1486(** [builder_at ip] creates an instruction builder positioned at [ip]. 1487 See the constructor for [llvm::LLVMBuilder]. *) 1488val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder 1489 1490(** [builder_before ins] creates an instruction builder positioned before the 1491 instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *) 1492val builder_before : llcontext -> llvalue -> llbuilder 1493 1494(** [builder_at_end bb] creates an instruction builder positioned at the end of 1495 the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *) 1496val builder_at_end : llcontext -> llbasicblock -> llbuilder 1497 1498(** [position_builder ip bb] moves the instruction builder [bb] to the position 1499 [ip]. 1500 See the constructor for [llvm::LLVMBuilder]. *) 1501val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit 1502 1503 1504(** [position_before ins b] moves the instruction builder [b] to before the 1505 instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *) 1506val position_before : llvalue -> llbuilder -> unit 1507 1508(** [position_at_end bb b] moves the instruction builder [b] to the end of the 1509 basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *) 1510val position_at_end : llbasicblock -> llbuilder -> unit 1511 1512(** [insertion_block b] returns the basic block that the builder [b] is 1513 positioned to insert into. Raises [Not_Found] if the instruction builder is 1514 uninitialized. 1515 See the method [llvm::LLVMBuilder::GetInsertBlock]. *) 1516val insertion_block : llbuilder -> llbasicblock 1517 1518(** [insert_into_builder i name b] inserts the specified instruction [i] at the 1519 position specified by the instruction builder [b]. 1520 See the method [llvm::LLVMBuilder::Insert]. *) 1521val insert_into_builder : llvalue -> string -> llbuilder -> unit 1522 1523 1524(** {7 Metadata} *) 1525 1526(** [set_current_debug_location b md] sets the current debug location [md] in 1527 the builder [b]. 1528 See the method [llvm::IRBuilder::SetDebugLocation]. *) 1529val set_current_debug_location : llbuilder -> llvalue -> unit 1530 1531 1532(** [clear_current_debug_location b] clears the current debug location in the 1533 builder [b]. *) 1534val clear_current_debug_location : llbuilder -> unit 1535 1536 1537(** [current_debug_location b] returns the current debug location, or None 1538 if none is currently set. 1539 See the method [llvm::IRBuilder::GetDebugLocation]. *) 1540val current_debug_location : llbuilder -> llvalue option 1541 1542 1543(** [set_inst_debug_location b i] sets the current debug location of the builder 1544 [b] to the instruction [i]. 1545 See the method [llvm::IRBuilder::SetInstDebugLocation]. *) 1546val set_inst_debug_location : llbuilder -> llvalue -> unit 1547 1548 1549(** {7 Terminators} *) 1550 1551(** [build_ret_void b] creates a 1552 [ret void] 1553 instruction at the position specified by the instruction builder [b]. 1554 See the method [llvm::LLVMBuilder::CreateRetVoid]. *) 1555val build_ret_void : llbuilder -> llvalue 1556 1557(** [build_ret v b] creates a 1558 [ret %v] 1559 instruction at the position specified by the instruction builder [b]. 1560 See the method [llvm::LLVMBuilder::CreateRet]. *) 1561val build_ret : llvalue -> llbuilder -> llvalue 1562 1563(** [build_aggregate_ret vs b] creates a 1564 [ret {...} { %v1, %v2, ... } ] 1565 instruction at the position specified by the instruction builder [b]. 1566 See the method [llvm::LLVMBuilder::CreateAggregateRet]. *) 1567val build_aggregate_ret : llvalue array -> llbuilder -> llvalue 1568 1569 1570(** [build_br bb b] creates a 1571 [br %bb] 1572 instruction at the position specified by the instruction builder [b]. 1573 See the method [llvm::LLVMBuilder::CreateBr]. *) 1574val build_br : llbasicblock -> llbuilder -> llvalue 1575 1576(** [build_cond_br cond tbb fbb b] creates a 1577 [br %cond, %tbb, %fbb] 1578 instruction at the position specified by the instruction builder [b]. 1579 See the method [llvm::LLVMBuilder::CreateCondBr]. *) 1580val build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder -> 1581 llvalue 1582 1583(** [build_switch case elsebb count b] creates an empty 1584 [switch %case, %elsebb] 1585 instruction at the position specified by the instruction builder [b] with 1586 space reserved for [count] cases. 1587 See the method [llvm::LLVMBuilder::CreateSwitch]. *) 1588val build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue 1589 1590 1591(** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb] 1592 when its input matches the constant [onval]. 1593 See the method [llvm::SwitchInst::addCase]. **) 1594val add_case : llvalue -> llvalue -> llbasicblock -> unit 1595 1596 1597(** [build_indirect_br addr count b] creates a 1598 [indirectbr %addr] 1599 instruction at the position specified by the instruction builder [b] with 1600 space reserved for [count] destinations. 1601 See the method [llvm::LLVMBuilder::CreateIndirectBr]. *) 1602val build_indirect_br : llvalue -> int -> llbuilder -> llvalue 1603 1604 1605(** [add_destination br bb] adds the basic block [bb] as a possible branch 1606 location for the indirectbr instruction [br]. 1607 See the method [llvm::IndirectBrInst::addDestination]. **) 1608val add_destination : llvalue -> llbasicblock -> unit 1609 1610 1611(** [build_invoke fn args tobb unwindbb name b] creates an 1612 [%name = invoke %fn(args) to %tobb unwind %unwindbb] 1613 instruction at the position specified by the instruction builder [b]. 1614 See the method [llvm::LLVMBuilder::CreateInvoke]. *) 1615val build_invoke : llvalue -> llvalue array -> llbasicblock -> 1616 llbasicblock -> string -> llbuilder -> llvalue 1617 1618 1619(** [build_unwind b] creates an 1620 [unwind] 1621 instruction at the position specified by the instruction builder [b]. 1622 See the method [llvm::LLVMBuilder::CreateUnwind]. *) 1623val build_unwind : llbuilder -> llvalue 1624 1625(** [build_unreachable b] creates an 1626 [unreachable] 1627 instruction at the position specified by the instruction builder [b]. 1628 See the method [llvm::LLVMBuilder::CreateUnwind]. *) 1629val build_unreachable : llbuilder -> llvalue 1630 1631 1632(** {7 Arithmetic} *) 1633 1634(** [build_add x y name b] creates a 1635 [%name = add %x, %y] 1636 instruction at the position specified by the instruction builder [b]. 1637 See the method [llvm::LLVMBuilder::CreateAdd]. *) 1638val build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue 1639 1640 1641(** [build_nsw_add x y name b] creates a 1642 [%name = nsw add %x, %y] 1643 instruction at the position specified by the instruction builder [b]. 1644 See the method [llvm::LLVMBuilder::CreateNSWAdd]. *) 1645val build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue 1646 1647 1648(** [build_nuw_add x y name b] creates a 1649 [%name = nuw add %x, %y] 1650 instruction at the position specified by the instruction builder [b]. 1651 See the method [llvm::LLVMBuilder::CreateNUWAdd]. *) 1652val build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue 1653 1654 1655(** [build_fadd x y name b] creates a 1656 [%name = fadd %x, %y] 1657 instruction at the position specified by the instruction builder [b]. 1658 See the method [llvm::LLVMBuilder::CreateFAdd]. *) 1659val build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue 1660 1661 1662(** [build_sub x y name b] creates a 1663 [%name = sub %x, %y] 1664 instruction at the position specified by the instruction builder [b]. 1665 See the method [llvm::LLVMBuilder::CreateSub]. *) 1666val build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1667 1668 1669(** [build_nsw_sub x y name b] creates a 1670 [%name = nsw sub %x, %y] 1671 instruction at the position specified by the instruction builder [b]. 1672 See the method [llvm::LLVMBuilder::CreateNSWSub]. *) 1673val build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1674 1675 1676(** [build_nuw_sub x y name b] creates a 1677 [%name = nuw sub %x, %y] 1678 instruction at the position specified by the instruction builder [b]. 1679 See the method [llvm::LLVMBuilder::CreateNUWSub]. *) 1680val build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1681 1682 1683(** [build_fsub x y name b] creates a 1684 [%name = fsub %x, %y] 1685 instruction at the position specified by the instruction builder [b]. 1686 See the method [llvm::LLVMBuilder::CreateFSub]. *) 1687val build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1688 1689 1690(** [build_mul x y name b] creates a 1691 [%name = mul %x, %y] 1692 instruction at the position specified by the instruction builder [b]. 1693 See the method [llvm::LLVMBuilder::CreateMul]. *) 1694val build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1695 1696 1697(** [build_nsw_mul x y name b] creates a 1698 [%name = nsw mul %x, %y] 1699 instruction at the position specified by the instruction builder [b]. 1700 See the method [llvm::LLVMBuilder::CreateNSWMul]. *) 1701val build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1702 1703 1704(** [build_nuw_mul x y name b] creates a 1705 [%name = nuw mul %x, %y] 1706 instruction at the position specified by the instruction builder [b]. 1707 See the method [llvm::LLVMBuilder::CreateNUWMul]. *) 1708val build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1709 1710 1711(** [build_fmul x y name b] creates a 1712 [%name = fmul %x, %y] 1713 instruction at the position specified by the instruction builder [b]. 1714 See the method [llvm::LLVMBuilder::CreateFMul]. *) 1715val build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1716 1717 1718(** [build_udiv x y name b] creates a 1719 [%name = udiv %x, %y] 1720 instruction at the position specified by the instruction builder [b]. 1721 See the method [llvm::LLVMBuilder::CreateUDiv]. *) 1722val build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1723 1724 1725(** [build_sdiv x y name b] creates a 1726 [%name = sdiv %x, %y] 1727 instruction at the position specified by the instruction builder [b]. 1728 See the method [llvm::LLVMBuilder::CreateSDiv]. *) 1729val build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1730 1731 1732(** [build_exact_sdiv x y name b] creates a 1733 [%name = exact sdiv %x, %y] 1734 instruction at the position specified by the instruction builder [b]. 1735 See the method [llvm::LLVMBuilder::CreateExactSDiv]. *) 1736val build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1737 1738 1739(** [build_fdiv x y name b] creates a 1740 [%name = fdiv %x, %y] 1741 instruction at the position specified by the instruction builder [b]. 1742 See the method [llvm::LLVMBuilder::CreateFDiv]. *) 1743val build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1744 1745 1746(** [build_urem x y name b] creates a 1747 [%name = urem %x, %y] 1748 instruction at the position specified by the instruction builder [b]. 1749 See the method [llvm::LLVMBuilder::CreateURem]. *) 1750val build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1751 1752 1753(** [build_SRem x y name b] creates a 1754 [%name = srem %x, %y] 1755 instruction at the position specified by the instruction builder [b]. 1756 See the method [llvm::LLVMBuilder::CreateSRem]. *) 1757val build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1758 1759 1760(** [build_frem x y name b] creates a 1761 [%name = frem %x, %y] 1762 instruction at the position specified by the instruction builder [b]. 1763 See the method [llvm::LLVMBuilder::CreateFRem]. *) 1764val build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1765 1766 1767(** [build_shl x y name b] creates a 1768 [%name = shl %x, %y] 1769 instruction at the position specified by the instruction builder [b]. 1770 See the method [llvm::LLVMBuilder::CreateShl]. *) 1771val build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue 1772 1773 1774(** [build_lshr x y name b] creates a 1775 [%name = lshr %x, %y] 1776 instruction at the position specified by the instruction builder [b]. 1777 See the method [llvm::LLVMBuilder::CreateLShr]. *) 1778val build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue 1779 1780 1781(** [build_ashr x y name b] creates a 1782 [%name = ashr %x, %y] 1783 instruction at the position specified by the instruction builder [b]. 1784 See the method [llvm::LLVMBuilder::CreateAShr]. *) 1785val build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue 1786 1787 1788(** [build_and x y name b] creates a 1789 [%name = and %x, %y] 1790 instruction at the position specified by the instruction builder [b]. 1791 See the method [llvm::LLVMBuilder::CreateAnd]. *) 1792val build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue 1793 1794 1795(** [build_or x y name b] creates a 1796 [%name = or %x, %y] 1797 instruction at the position specified by the instruction builder [b]. 1798 See the method [llvm::LLVMBuilder::CreateOr]. *) 1799val build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue 1800 1801 1802(** [build_xor x y name b] creates a 1803 [%name = xor %x, %y] 1804 instruction at the position specified by the instruction builder [b]. 1805 See the method [llvm::LLVMBuilder::CreateXor]. *) 1806val build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue 1807 1808 1809(** [build_neg x name b] creates a 1810 [%name = sub 0, %x] 1811 instruction at the position specified by the instruction builder [b]. 1812 [-0.0] is used for floating point types to compute the correct sign. 1813 See the method [llvm::LLVMBuilder::CreateNeg]. *) 1814val build_neg : llvalue -> string -> llbuilder -> llvalue 1815 1816 1817(** [build_nsw_neg x name b] creates a 1818 [%name = nsw sub 0, %x] 1819 instruction at the position specified by the instruction builder [b]. 1820 [-0.0] is used for floating point types to compute the correct sign. 1821 See the method [llvm::LLVMBuilder::CreateNeg]. *) 1822val build_nsw_neg : llvalue -> string -> llbuilder -> llvalue 1823 1824 1825(** [build_nuw_neg x name b] creates a 1826 [%name = nuw sub 0, %x] 1827 instruction at the position specified by the instruction builder [b]. 1828 [-0.0] is used for floating point types to compute the correct sign. 1829 See the method [llvm::LLVMBuilder::CreateNeg]. *) 1830val build_nuw_neg : llvalue -> string -> llbuilder -> llvalue 1831 1832 1833(** [build_fneg x name b] creates a 1834 [%name = fsub 0, %x] 1835 instruction at the position specified by the instruction builder [b]. 1836 [-0.0] is used for floating point types to compute the correct sign. 1837 See the method [llvm::LLVMBuilder::CreateFNeg]. *) 1838val build_fneg : llvalue -> string -> llbuilder -> llvalue 1839 1840 1841(** [build_xor x name b] creates a 1842 [%name = xor %x, -1] 1843 instruction at the position specified by the instruction builder [b]. 1844 [-1] is the correct "all ones" value for the type of [x]. 1845 See the method [llvm::LLVMBuilder::CreateXor]. *) 1846val build_not : llvalue -> string -> llbuilder -> llvalue 1847 1848 1849 1850(** {7 Memory} *) 1851 1852(** [build_alloca ty name b] creates a 1853 [%name = alloca %ty] 1854 instruction at the position specified by the instruction builder [b]. 1855 See the method [llvm::LLVMBuilder::CreateAlloca]. *) 1856val build_alloca : lltype -> string -> llbuilder -> llvalue 1857 1858 1859(** [build_array_alloca ty n name b] creates a 1860 [%name = alloca %ty, %n] 1861 instruction at the position specified by the instruction builder [b]. 1862 See the method [llvm::LLVMBuilder::CreateAlloca]. *) 1863val build_array_alloca : lltype -> llvalue -> string -> llbuilder -> 1864 llvalue 1865 1866(** [build_load v name b] creates a 1867 [%name = load %v] 1868 instruction at the position specified by the instruction builder [b]. 1869 See the method [llvm::LLVMBuilder::CreateLoad]. *) 1870val build_load : llvalue -> string -> llbuilder -> llvalue 1871 1872 1873(** [build_store v p b] creates a 1874 [store %v, %p] 1875 instruction at the position specified by the instruction builder [b]. 1876 See the method [llvm::LLVMBuilder::CreateStore]. *) 1877val build_store : llvalue -> llvalue -> llbuilder -> llvalue 1878 1879 1880(** [build_gep p indices name b] creates a 1881 [%name = getelementptr %p, indices...] 1882 instruction at the position specified by the instruction builder [b]. 1883 See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *) 1884val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue 1885 1886 1887(** [build_in_bounds_gep p indices name b] creates a 1888 [%name = gelementptr inbounds %p, indices...] 1889 instruction at the position specified by the instruction builder [b]. 1890 See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *) 1891val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder -> 1892 llvalue 1893 1894(** [build_struct_gep p idx name b] creates a 1895 [%name = getelementptr %p, 0, idx] 1896 instruction at the position specified by the instruction builder [b]. 1897 See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *) 1898val build_struct_gep : llvalue -> int -> string -> llbuilder -> 1899 llvalue 1900 1901(** [build_global_string str name b] creates a series of instructions that adds 1902 a global string at the position specified by the instruction builder [b]. 1903 See the method [llvm::LLVMBuilder::CreateGlobalString]. *) 1904val build_global_string : string -> string -> llbuilder -> llvalue 1905 1906 1907(** [build_global_stringptr str name b] creates a series of instructions that 1908 adds a global string pointer at the position specified by the instruction 1909 builder [b]. 1910 See the method [llvm::LLVMBuilder::CreateGlobalStringPtr]. *) 1911val build_global_stringptr : string -> string -> llbuilder -> llvalue 1912 1913 1914 1915(** {7 Casts} *) 1916 1917(** [build_trunc v ty name b] creates a 1918 [%name = trunc %p to %ty] 1919 instruction at the position specified by the instruction builder [b]. 1920 See the method [llvm::LLVMBuilder::CreateTrunc]. *) 1921val build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue 1922 1923 1924(** [build_zext v ty name b] creates a 1925 [%name = zext %p to %ty] 1926 instruction at the position specified by the instruction builder [b]. 1927 See the method [llvm::LLVMBuilder::CreateZExt]. *) 1928val build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue 1929 1930 1931(** [build_sext v ty name b] creates a 1932 [%name = sext %p to %ty] 1933 instruction at the position specified by the instruction builder [b]. 1934 See the method [llvm::LLVMBuilder::CreateSExt]. *) 1935val build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue 1936 1937 1938(** [build_fptoui v ty name b] creates a 1939 [%name = fptoui %p to %ty] 1940 instruction at the position specified by the instruction builder [b]. 1941 See the method [llvm::LLVMBuilder::CreateFPToUI]. *) 1942val build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue 1943 1944 1945(** [build_fptosi v ty name b] creates a 1946 [%name = fptosi %p to %ty] 1947 instruction at the position specified by the instruction builder [b]. 1948 See the method [llvm::LLVMBuilder::CreateFPToSI]. *) 1949val build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue 1950 1951 1952(** [build_uitofp v ty name b] creates a 1953 [%name = uitofp %p to %ty] 1954 instruction at the position specified by the instruction builder [b]. 1955 See the method [llvm::LLVMBuilder::CreateUIToFP]. *) 1956val build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue 1957 1958 1959(** [build_sitofp v ty name b] creates a 1960 [%name = sitofp %p to %ty] 1961 instruction at the position specified by the instruction builder [b]. 1962 See the method [llvm::LLVMBuilder::CreateSIToFP]. *) 1963val build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue 1964 1965 1966(** [build_fptrunc v ty name b] creates a 1967 [%name = fptrunc %p to %ty] 1968 instruction at the position specified by the instruction builder [b]. 1969 See the method [llvm::LLVMBuilder::CreateFPTrunc]. *) 1970val build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue 1971 1972 1973(** [build_fpext v ty name b] creates a 1974 [%name = fpext %p to %ty] 1975 instruction at the position specified by the instruction builder [b]. 1976 See the method [llvm::LLVMBuilder::CreateFPExt]. *) 1977val build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue 1978 1979 1980(** [build_ptrtoint v ty name b] creates a 1981 [%name = prtotint %p to %ty] 1982 instruction at the position specified by the instruction builder [b]. 1983 See the method [llvm::LLVMBuilder::CreatePtrToInt]. *) 1984val build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue 1985 1986 1987(** [build_inttoptr v ty name b] creates a 1988 [%name = inttoptr %p to %ty] 1989 instruction at the position specified by the instruction builder [b]. 1990 See the method [llvm::LLVMBuilder::CreateIntToPtr]. *) 1991val build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue 1992 1993 1994(** [build_bitcast v ty name b] creates a 1995 [%name = bitcast %p to %ty] 1996 instruction at the position specified by the instruction builder [b]. 1997 See the method [llvm::LLVMBuilder::CreateBitCast]. *) 1998val build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue 1999 2000 2001(** [build_zext_or_bitcast v ty name b] creates a zext or bitcast 2002 instruction at the position specified by the instruction builder [b]. 2003 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *) 2004val build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 2005 llvalue 2006 2007(** [build_sext_or_bitcast v ty name b] creates a sext or bitcast 2008 instruction at the position specified by the instruction builder [b]. 2009 See the method [llvm::LLVMBuilder::CreateSExtOrBitCast]. *) 2010val build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 2011 llvalue 2012 2013(** [build_trunc_or_bitcast v ty name b] creates a trunc or bitcast 2014 instruction at the position specified by the instruction builder [b]. 2015 See the method [llvm::LLVMBuilder::CreateZExtOrBitCast]. *) 2016val build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 2017 llvalue 2018 2019(** [build_pointercast v ty name b] creates a bitcast or pointer-to-int 2020 instruction at the position specified by the instruction builder [b]. 2021 See the method [llvm::LLVMBuilder::CreatePointerCast]. *) 2022val build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue 2023 2024 2025(** [build_intcast v ty name b] creates a zext, bitcast, or trunc 2026 instruction at the position specified by the instruction builder [b]. 2027 See the method [llvm::LLVMBuilder::CreateIntCast]. *) 2028val build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue 2029 2030 2031(** [build_fpcast v ty name b] creates a fpext, bitcast, or fptrunc 2032 instruction at the position specified by the instruction builder [b]. 2033 See the method [llvm::LLVMBuilder::CreateFPCast]. *) 2034val build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue 2035 2036 2037 2038(** {7 Comparisons} *) 2039 2040(** [build_icmp pred x y name b] creates a 2041 [%name = icmp %pred %x, %y] 2042 instruction at the position specified by the instruction builder [b]. 2043 See the method [llvm::LLVMBuilder::CreateICmp]. *) 2044val build_icmp : Icmp.t -> llvalue -> llvalue -> string -> 2045 llbuilder -> llvalue 2046 2047(** [build_fcmp pred x y name b] creates a 2048 [%name = fcmp %pred %x, %y] 2049 instruction at the position specified by the instruction builder [b]. 2050 See the method [llvm::LLVMBuilder::CreateFCmp]. *) 2051val build_fcmp : Fcmp.t -> llvalue -> llvalue -> string -> 2052 llbuilder -> llvalue 2053 2054 2055(** {7 Miscellaneous instructions} *) 2056 2057(** [build_phi incoming name b] creates a 2058 [%name = phi %incoming] 2059 instruction at the position specified by the instruction builder [b]. 2060 [incoming] is a list of [(llvalue, llbasicblock)] tuples. 2061 See the method [llvm::LLVMBuilder::CreatePHI]. *) 2062val build_phi : (llvalue * llbasicblock) list -> string -> llbuilder -> 2063 llvalue 2064 2065(** [build_call fn args name b] creates a 2066 [%name = call %fn(args...)] 2067 instruction at the position specified by the instruction builder [b]. 2068 See the method [llvm::LLVMBuilder::CreateCall]. *) 2069val build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue 2070 2071 2072(** [build_select cond thenv elsev name b] creates a 2073 [%name = select %cond, %thenv, %elsev] 2074 instruction at the position specified by the instruction builder [b]. 2075 See the method [llvm::LLVMBuilder::CreateSelect]. *) 2076val build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder -> 2077 llvalue 2078 2079(** [build_va_arg valist argty name b] creates a 2080 [%name = va_arg %valist, %argty] 2081 instruction at the position specified by the instruction builder [b]. 2082 See the method [llvm::LLVMBuilder::CreateVAArg]. *) 2083val build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue 2084 2085 2086(** [build_extractelement vec i name b] creates a 2087 [%name = extractelement %vec, %i] 2088 instruction at the position specified by the instruction builder [b]. 2089 See the method [llvm::LLVMBuilder::CreateExtractElement]. *) 2090val build_extractelement : llvalue -> llvalue -> string -> llbuilder -> 2091 llvalue 2092 2093(** [build_insertelement vec elt i name b] creates a 2094 [%name = insertelement %vec, %elt, %i] 2095 instruction at the position specified by the instruction builder [b]. 2096 See the method [llvm::LLVMBuilder::CreateInsertElement]. *) 2097val build_insertelement : llvalue -> llvalue -> llvalue -> string -> 2098 llbuilder -> llvalue 2099 2100(** [build_shufflevector veca vecb mask name b] creates a 2101 [%name = shufflevector %veca, %vecb, %mask] 2102 instruction at the position specified by the instruction builder [b]. 2103 See the method [llvm::LLVMBuilder::CreateShuffleVector]. *) 2104val build_shufflevector : llvalue -> llvalue -> llvalue -> string -> 2105 llbuilder -> llvalue 2106 2107(** [build_insertvalue agg idx name b] creates a 2108 [%name = extractvalue %agg, %idx] 2109 instruction at the position specified by the instruction builder [b]. 2110 See the method [llvm::LLVMBuilder::CreateExtractValue]. *) 2111val build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue 2112 2113 2114(** [build_insertvalue agg val idx name b] creates a 2115 [%name = insertvalue %agg, %val, %idx] 2116 instruction at the position specified by the instruction builder [b]. 2117 See the method [llvm::LLVMBuilder::CreateInsertValue]. *) 2118val build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder -> 2119 llvalue 2120 2121(** [build_is_null val name b] creates a 2122 [%name = icmp eq %val, null] 2123 instruction at the position specified by the instruction builder [b]. 2124 See the method [llvm::LLVMBuilder::CreateIsNull]. *) 2125val build_is_null : llvalue -> string -> llbuilder -> llvalue 2126 2127 2128(** [build_is_not_null val name b] creates a 2129 [%name = icmp ne %val, null] 2130 instruction at the position specified by the instruction builder [b]. 2131 See the method [llvm::LLVMBuilder::CreateIsNotNull]. *) 2132val build_is_not_null : llvalue -> string -> llbuilder -> llvalue 2133 2134 2135(** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure 2136 the difference between two pointer values at the position specified by the 2137 instruction builder [b]. 2138 See the method [llvm::LLVMBuilder::CreatePtrDiff]. *) 2139val build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue 2140 2141 2142 2143(** {6 Memory buffers} *) 2144 2145module MemoryBuffer : sig 2146 (** [of_file p] is the memory buffer containing the contents of the file at 2147 path [p]. If the file could not be read, then [IoError msg] is 2148 raised. *) 2149 val of_file : string -> llmemorybuffer 2150 2151 (** [stdin ()] is the memory buffer containing the contents of standard input. 2152 If standard input is empty, then [IoError msg] is raised. *) 2153 val of_stdin : unit -> llmemorybuffer 2154 2155 (** Disposes of a memory buffer. *) 2156 val dispose : llmemorybuffer -> unit 2157end 2158 2159 2160(** {6 Pass Managers} *) 2161 2162module PassManager : sig 2163 (** *) 2164 type 'a t 2165 type any = [ `Module | `Function ] 2166 2167 (** [PassManager.create ()] constructs a new whole-module pass pipeline. This 2168 type of pipeline is suitable for link-time optimization and whole-module 2169 transformations. 2170 See the constructor of [llvm::PassManager]. *) 2171 val create : unit -> [ `Module ] t 2172 2173 (** [PassManager.create_function m] constructs a new function-by-function 2174 pass pipeline over the module [m]. It does not take ownership of [m]. 2175 This type of pipeline is suitable for code generation and JIT compilation 2176 tasks. 2177 See the constructor of [llvm::FunctionPassManager]. *) 2178 val create_function : llmodule -> [ `Function ] t 2179 2180 2181 (** [run_module m pm] initializes, executes on the module [m], and finalizes 2182 all of the passes scheduled in the pass manager [pm]. Returns [true] if 2183 any of the passes modified the module, [false] otherwise. 2184 See the [llvm::PassManager::run] method. *) 2185 val run_module : llmodule -> [ `Module ] t -> bool 2186 2187 2188 (** [initialize fpm] initializes all of the function passes scheduled in the 2189 function pass manager [fpm]. Returns [true] if any of the passes modified 2190 the module, [false] otherwise. 2191 See the [llvm::FunctionPassManager::doInitialization] method. *) 2192 val initialize : [ `Function ] t -> bool 2193 2194 (** [run_function f fpm] executes all of the function passes scheduled in the 2195 function pass manager [fpm] over the function [f]. Returns [true] if any 2196 of the passes modified [f], [false] otherwise. 2197 See the [llvm::FunctionPassManager::run] method. *) 2198 val run_function : llvalue -> [ `Function ] t -> bool 2199 2200 2201 (** [finalize fpm] finalizes all of the function passes scheduled in in the 2202 function pass manager [fpm]. Returns [true] if any of the passes 2203 modified the module, [false] otherwise. 2204 See the [llvm::FunctionPassManager::doFinalization] method. *) 2205 val finalize : [ `Function ] t -> bool 2206 2207 (** Frees the memory of a pass pipeline. For function pipelines, does not free 2208 the module. 2209 See the destructor of [llvm::BasePassManager]. *) 2210 val dispose : [< any ] t -> unit 2211end 2212