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