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