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