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