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