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