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