1(*===-- llvm/llvm.ml - LLVM OCaml Interface -------------------------------===* 2 * 3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 * See https://llvm.org/LICENSE.txt for license information. 5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 * 7 *===----------------------------------------------------------------------===*) 8 9 10type llcontext 11type llmodule 12type lltype 13type llvalue 14type lluse 15type llbasicblock 16type llbuilder 17type llattrkind 18type llattribute 19type llmemorybuffer 20type llmdkind 21 22exception FeatureDisabled of string 23 24let () = Callback.register_exception "Llvm.FeatureDisabled" (FeatureDisabled "") 25 26module TypeKind = struct 27 type t = 28 | Void 29 | Half 30 | Float 31 | Double 32 | X86fp80 33 | Fp128 34 | Ppc_fp128 35 | Label 36 | Integer 37 | Function 38 | Struct 39 | Array 40 | Pointer 41 | Vector 42 | Metadata 43 | X86_mmx 44 | Token 45end 46 47module Linkage = struct 48 type t = 49 | External 50 | Available_externally 51 | Link_once 52 | Link_once_odr 53 | Link_once_odr_auto_hide 54 | Weak 55 | Weak_odr 56 | Appending 57 | Internal 58 | Private 59 | Dllimport 60 | Dllexport 61 | External_weak 62 | Ghost 63 | Common 64 | Linker_private 65 | Linker_private_weak 66end 67 68module Visibility = struct 69 type t = 70 | Default 71 | Hidden 72 | Protected 73end 74 75module DLLStorageClass = struct 76 type t = 77 | Default 78 | DLLImport 79 | DLLExport 80end 81 82module CallConv = struct 83 let c = 0 84 let fast = 8 85 let cold = 9 86 let x86_stdcall = 64 87 let x86_fastcall = 65 88end 89 90module AttrRepr = struct 91 type t = 92 | Enum of llattrkind * int64 93 | String of string * string 94end 95 96module AttrIndex = struct 97 type t = 98 | Function 99 | Return 100 | Param of int 101 102 let to_int index = 103 match index with 104 | Function -> -1 105 | Return -> 0 106 | Param(n) -> 1 + n 107end 108 109module Attribute = struct 110 type t = 111 | Zext 112 | Sext 113 | Noreturn 114 | Inreg 115 | Structret 116 | Nounwind 117 | Noalias 118 | Byval 119 | Nest 120 | Readnone 121 | Readonly 122 | Noinline 123 | Alwaysinline 124 | Optsize 125 | Ssp 126 | Sspreq 127 | Alignment of int 128 | Nocapture 129 | Noredzone 130 | Noimplicitfloat 131 | Naked 132 | Inlinehint 133 | Stackalignment of int 134 | ReturnsTwice 135 | UWTable 136 | NonLazyBind 137end 138 139module Icmp = struct 140 type t = 141 | Eq 142 | Ne 143 | Ugt 144 | Uge 145 | Ult 146 | Ule 147 | Sgt 148 | Sge 149 | Slt 150 | Sle 151end 152 153module Fcmp = struct 154 type t = 155 | False 156 | Oeq 157 | Ogt 158 | Oge 159 | Olt 160 | Ole 161 | One 162 | Ord 163 | Uno 164 | Ueq 165 | Ugt 166 | Uge 167 | Ult 168 | Ule 169 | Une 170 | True 171end 172 173module Opcode = struct 174 type t = 175 | Invalid (* not an instruction *) 176 (* Terminator Instructions *) 177 | Ret 178 | Br 179 | Switch 180 | IndirectBr 181 | Invoke 182 | Invalid2 183 | Unreachable 184 (* Standard Binary Operators *) 185 | Add 186 | FAdd 187 | Sub 188 | FSub 189 | Mul 190 | FMul 191 | UDiv 192 | SDiv 193 | FDiv 194 | URem 195 | SRem 196 | FRem 197 (* Logical Operators *) 198 | Shl 199 | LShr 200 | AShr 201 | And 202 | Or 203 | Xor 204 (* Memory Operators *) 205 | Alloca 206 | Load 207 | Store 208 | GetElementPtr 209 (* Cast Operators *) 210 | Trunc 211 | ZExt 212 | SExt 213 | FPToUI 214 | FPToSI 215 | UIToFP 216 | SIToFP 217 | FPTrunc 218 | FPExt 219 | PtrToInt 220 | IntToPtr 221 | BitCast 222 (* Other Operators *) 223 | ICmp 224 | FCmp 225 | PHI 226 | Call 227 | Select 228 | UserOp1 229 | UserOp2 230 | VAArg 231 | ExtractElement 232 | InsertElement 233 | ShuffleVector 234 | ExtractValue 235 | InsertValue 236 | Fence 237 | AtomicCmpXchg 238 | AtomicRMW 239 | Resume 240 | LandingPad 241 | AddrSpaceCast 242 | CleanupRet 243 | CatchRet 244 | CatchPad 245 | CleanupPad 246 | CatchSwitch 247 | FNeg 248 | CallBr 249end 250 251module LandingPadClauseTy = struct 252 type t = 253 | Catch 254 | Filter 255end 256 257module ThreadLocalMode = struct 258 type t = 259 | None 260 | GeneralDynamic 261 | LocalDynamic 262 | InitialExec 263 | LocalExec 264end 265 266module AtomicOrdering = struct 267 type t = 268 | NotAtomic 269 | Unordered 270 | Monotonic 271 | Invalid 272 | Acquire 273 | Release 274 | AcqiureRelease 275 | SequentiallyConsistent 276end 277 278module AtomicRMWBinOp = struct 279 type t = 280 | Xchg 281 | Add 282 | Sub 283 | And 284 | Nand 285 | Or 286 | Xor 287 | Max 288 | Min 289 | UMax 290 | UMin 291end 292 293module ValueKind = struct 294 type t = 295 | NullValue 296 | Argument 297 | BasicBlock 298 | InlineAsm 299 | MDNode 300 | MDString 301 | BlockAddress 302 | ConstantAggregateZero 303 | ConstantArray 304 | ConstantDataArray 305 | ConstantDataVector 306 | ConstantExpr 307 | ConstantFP 308 | ConstantInt 309 | ConstantPointerNull 310 | ConstantStruct 311 | ConstantVector 312 | Function 313 | GlobalAlias 314 | GlobalIFunc 315 | GlobalVariable 316 | UndefValue 317 | Instruction of Opcode.t 318end 319 320module DiagnosticSeverity = struct 321 type t = 322 | Error 323 | Warning 324 | Remark 325 | Note 326end 327 328exception IoError of string 329 330let () = Callback.register_exception "Llvm.IoError" (IoError "") 331 332external install_fatal_error_handler : (string -> unit) -> unit 333 = "llvm_install_fatal_error_handler" 334external reset_fatal_error_handler : unit -> unit 335 = "llvm_reset_fatal_error_handler" 336external enable_pretty_stacktrace : unit -> unit 337 = "llvm_enable_pretty_stacktrace" 338external parse_command_line_options : ?overview:string -> string array -> unit 339 = "llvm_parse_command_line_options" 340 341type ('a, 'b) llpos = 342| At_end of 'a 343| Before of 'b 344 345type ('a, 'b) llrev_pos = 346| At_start of 'a 347| After of 'b 348 349 350(*===-- Context error handling --------------------------------------------===*) 351module Diagnostic = struct 352 type t 353 354 external description : t -> string = "llvm_get_diagnostic_description" 355 external severity : t -> DiagnosticSeverity.t 356 = "llvm_get_diagnostic_severity" 357end 358 359external set_diagnostic_handler 360 : llcontext -> (Diagnostic.t -> unit) option -> unit 361 = "llvm_set_diagnostic_handler" 362 363(*===-- Contexts ----------------------------------------------------------===*) 364external create_context : unit -> llcontext = "llvm_create_context" 365external dispose_context : llcontext -> unit = "llvm_dispose_context" 366external global_context : unit -> llcontext = "llvm_global_context" 367external mdkind_id : llcontext -> string -> llmdkind = "llvm_mdkind_id" 368 369(*===-- Attributes --------------------------------------------------------===*) 370exception UnknownAttribute of string 371 372let () = Callback.register_exception "Llvm.UnknownAttribute" 373 (UnknownAttribute "") 374 375external enum_attr_kind : string -> llattrkind = "llvm_enum_attr_kind" 376external llvm_create_enum_attr : llcontext -> llattrkind -> int64 -> 377 llattribute 378 = "llvm_create_enum_attr_by_kind" 379external is_enum_attr : llattribute -> bool = "llvm_is_enum_attr" 380external get_enum_attr_kind : llattribute -> llattrkind 381 = "llvm_get_enum_attr_kind" 382external get_enum_attr_value : llattribute -> int64 383 = "llvm_get_enum_attr_value" 384external llvm_create_string_attr : llcontext -> string -> string -> 385 llattribute 386 = "llvm_create_string_attr" 387external is_string_attr : llattribute -> bool = "llvm_is_string_attr" 388external get_string_attr_kind : llattribute -> string 389 = "llvm_get_string_attr_kind" 390external get_string_attr_value : llattribute -> string 391 = "llvm_get_string_attr_value" 392 393let create_enum_attr context name value = 394 llvm_create_enum_attr context (enum_attr_kind name) value 395let create_string_attr context kind value = 396 llvm_create_string_attr context kind value 397 398let attr_of_repr context repr = 399 match repr with 400 | AttrRepr.Enum(kind, value) -> llvm_create_enum_attr context kind value 401 | AttrRepr.String(key, value) -> llvm_create_string_attr context key value 402 403let repr_of_attr attr = 404 if is_enum_attr attr then 405 AttrRepr.Enum(get_enum_attr_kind attr, get_enum_attr_value attr) 406 else if is_string_attr attr then 407 AttrRepr.String(get_string_attr_kind attr, get_string_attr_value attr) 408 else assert false 409 410(*===-- Modules -----------------------------------------------------------===*) 411external create_module : llcontext -> string -> llmodule = "llvm_create_module" 412external dispose_module : llmodule -> unit = "llvm_dispose_module" 413external target_triple: llmodule -> string 414 = "llvm_target_triple" 415external set_target_triple: string -> llmodule -> unit 416 = "llvm_set_target_triple" 417external data_layout: llmodule -> string 418 = "llvm_data_layout" 419external set_data_layout: string -> llmodule -> unit 420 = "llvm_set_data_layout" 421external dump_module : llmodule -> unit = "llvm_dump_module" 422external print_module : string -> llmodule -> unit = "llvm_print_module" 423external string_of_llmodule : llmodule -> string = "llvm_string_of_llmodule" 424external set_module_inline_asm : llmodule -> string -> unit 425 = "llvm_set_module_inline_asm" 426external module_context : llmodule -> llcontext = "LLVMGetModuleContext" 427 428(*===-- Types -------------------------------------------------------------===*) 429external classify_type : lltype -> TypeKind.t = "llvm_classify_type" 430external type_context : lltype -> llcontext = "llvm_type_context" 431external type_is_sized : lltype -> bool = "llvm_type_is_sized" 432external dump_type : lltype -> unit = "llvm_dump_type" 433external string_of_lltype : lltype -> string = "llvm_string_of_lltype" 434 435(*--... Operations on integer types ........................................--*) 436external i1_type : llcontext -> lltype = "llvm_i1_type" 437external i8_type : llcontext -> lltype = "llvm_i8_type" 438external i16_type : llcontext -> lltype = "llvm_i16_type" 439external i32_type : llcontext -> lltype = "llvm_i32_type" 440external i64_type : llcontext -> lltype = "llvm_i64_type" 441 442external integer_type : llcontext -> int -> lltype = "llvm_integer_type" 443external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth" 444 445(*--... Operations on real types ...........................................--*) 446external float_type : llcontext -> lltype = "llvm_float_type" 447external double_type : llcontext -> lltype = "llvm_double_type" 448external x86fp80_type : llcontext -> lltype = "llvm_x86fp80_type" 449external fp128_type : llcontext -> lltype = "llvm_fp128_type" 450external ppc_fp128_type : llcontext -> lltype = "llvm_ppc_fp128_type" 451 452(*--... Operations on function types .......................................--*) 453external function_type : lltype -> lltype array -> lltype = "llvm_function_type" 454external var_arg_function_type : lltype -> lltype array -> lltype 455 = "llvm_var_arg_function_type" 456external is_var_arg : lltype -> bool = "llvm_is_var_arg" 457external return_type : lltype -> lltype = "LLVMGetReturnType" 458external param_types : lltype -> lltype array = "llvm_param_types" 459 460(*--... Operations on struct types .........................................--*) 461external struct_type : llcontext -> lltype array -> lltype = "llvm_struct_type" 462external packed_struct_type : llcontext -> lltype array -> lltype 463 = "llvm_packed_struct_type" 464external struct_name : lltype -> string option = "llvm_struct_name" 465external named_struct_type : llcontext -> string -> lltype = 466 "llvm_named_struct_type" 467external struct_set_body : lltype -> lltype array -> bool -> unit = 468 "llvm_struct_set_body" 469external struct_element_types : lltype -> lltype array 470 = "llvm_struct_element_types" 471external is_packed : lltype -> bool = "llvm_is_packed" 472external is_opaque : lltype -> bool = "llvm_is_opaque" 473external is_literal : lltype -> bool = "llvm_is_literal" 474 475(*--... Operations on pointer, vector, and array types .....................--*) 476 477external subtypes : lltype -> lltype array = "llvm_subtypes" 478external array_type : lltype -> int -> lltype = "llvm_array_type" 479external pointer_type : lltype -> lltype = "llvm_pointer_type" 480external qualified_pointer_type : lltype -> int -> lltype 481 = "llvm_qualified_pointer_type" 482external vector_type : lltype -> int -> lltype = "llvm_vector_type" 483 484external element_type : lltype -> lltype = "LLVMGetElementType" 485external array_length : lltype -> int = "llvm_array_length" 486external address_space : lltype -> int = "llvm_address_space" 487external vector_size : lltype -> int = "llvm_vector_size" 488 489(*--... Operations on other types ..........................................--*) 490external void_type : llcontext -> lltype = "llvm_void_type" 491external label_type : llcontext -> lltype = "llvm_label_type" 492external x86_mmx_type : llcontext -> lltype = "llvm_x86_mmx_type" 493external type_by_name : llmodule -> string -> lltype option = "llvm_type_by_name" 494 495external classify_value : llvalue -> ValueKind.t = "llvm_classify_value" 496(*===-- Values ------------------------------------------------------------===*) 497external type_of : llvalue -> lltype = "llvm_type_of" 498external value_name : llvalue -> string = "llvm_value_name" 499external set_value_name : string -> llvalue -> unit = "llvm_set_value_name" 500external dump_value : llvalue -> unit = "llvm_dump_value" 501external string_of_llvalue : llvalue -> string = "llvm_string_of_llvalue" 502external replace_all_uses_with : llvalue -> llvalue -> unit 503 = "llvm_replace_all_uses_with" 504 505(*--... Operations on uses .................................................--*) 506external use_begin : llvalue -> lluse option = "llvm_use_begin" 507external use_succ : lluse -> lluse option = "llvm_use_succ" 508external user : lluse -> llvalue = "llvm_user" 509external used_value : lluse -> llvalue = "llvm_used_value" 510 511let iter_uses f v = 512 let rec aux = function 513 | None -> () 514 | Some u -> 515 f u; 516 aux (use_succ u) 517 in 518 aux (use_begin v) 519 520let fold_left_uses f init v = 521 let rec aux init u = 522 match u with 523 | None -> init 524 | Some u -> aux (f init u) (use_succ u) 525 in 526 aux init (use_begin v) 527 528let fold_right_uses f v init = 529 let rec aux u init = 530 match u with 531 | None -> init 532 | Some u -> f u (aux (use_succ u) init) 533 in 534 aux (use_begin v) init 535 536 537(*--... Operations on users ................................................--*) 538external operand : llvalue -> int -> llvalue = "llvm_operand" 539external operand_use : llvalue -> int -> lluse = "llvm_operand_use" 540external set_operand : llvalue -> int -> llvalue -> unit = "llvm_set_operand" 541external num_operands : llvalue -> int = "llvm_num_operands" 542external indices : llvalue -> int array = "llvm_indices" 543 544(*--... Operations on constants of (mostly) any type .......................--*) 545external is_constant : llvalue -> bool = "llvm_is_constant" 546external const_null : lltype -> llvalue = "LLVMConstNull" 547external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes" 548external const_pointer_null : lltype -> llvalue = "LLVMConstPointerNull" 549external undef : lltype -> llvalue = "LLVMGetUndef" 550external is_null : llvalue -> bool = "llvm_is_null" 551external is_undef : llvalue -> bool = "llvm_is_undef" 552external constexpr_opcode : llvalue -> Opcode.t = "llvm_constexpr_get_opcode" 553 554(*--... Operations on instructions .........................................--*) 555external has_metadata : llvalue -> bool = "llvm_has_metadata" 556external metadata : llvalue -> llmdkind -> llvalue option = "llvm_metadata" 557external set_metadata : llvalue -> llmdkind -> llvalue -> unit = "llvm_set_metadata" 558external clear_metadata : llvalue -> llmdkind -> unit = "llvm_clear_metadata" 559 560(*--... Operations on metadata .......,.....................................--*) 561external mdstring : llcontext -> string -> llvalue = "llvm_mdstring" 562external mdnode : llcontext -> llvalue array -> llvalue = "llvm_mdnode" 563external mdnull : llcontext -> llvalue = "llvm_mdnull" 564external get_mdstring : llvalue -> string option = "llvm_get_mdstring" 565external get_mdnode_operands : llvalue -> llvalue array 566 = "llvm_get_mdnode_operands" 567external get_named_metadata : llmodule -> string -> llvalue array 568 = "llvm_get_namedmd" 569external add_named_metadata_operand : llmodule -> string -> llvalue -> unit 570 = "llvm_append_namedmd" 571 572(*--... Operations on scalar constants .....................................--*) 573external const_int : lltype -> int -> llvalue = "llvm_const_int" 574external const_of_int64 : lltype -> Int64.t -> bool -> llvalue 575 = "llvm_const_of_int64" 576external int64_of_const : llvalue -> Int64.t option 577 = "llvm_int64_of_const" 578external const_int_of_string : lltype -> string -> int -> llvalue 579 = "llvm_const_int_of_string" 580external const_float : lltype -> float -> llvalue = "llvm_const_float" 581external float_of_const : llvalue -> float option 582 = "llvm_float_of_const" 583external const_float_of_string : lltype -> string -> llvalue 584 = "llvm_const_float_of_string" 585 586(*--... Operations on composite constants ..................................--*) 587external const_string : llcontext -> string -> llvalue = "llvm_const_string" 588external const_stringz : llcontext -> string -> llvalue = "llvm_const_stringz" 589external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array" 590external const_struct : llcontext -> llvalue array -> llvalue 591 = "llvm_const_struct" 592external const_named_struct : lltype -> llvalue array -> llvalue 593 = "llvm_const_named_struct" 594external const_packed_struct : llcontext -> llvalue array -> llvalue 595 = "llvm_const_packed_struct" 596external const_vector : llvalue array -> llvalue = "llvm_const_vector" 597external string_of_const : llvalue -> string option = "llvm_string_of_const" 598external const_element : llvalue -> int -> llvalue = "llvm_const_element" 599 600(*--... Constant expressions ...............................................--*) 601external align_of : lltype -> llvalue = "LLVMAlignOf" 602external size_of : lltype -> llvalue = "LLVMSizeOf" 603external const_neg : llvalue -> llvalue = "LLVMConstNeg" 604external const_nsw_neg : llvalue -> llvalue = "LLVMConstNSWNeg" 605external const_nuw_neg : llvalue -> llvalue = "LLVMConstNUWNeg" 606external const_fneg : llvalue -> llvalue = "LLVMConstFNeg" 607external const_not : llvalue -> llvalue = "LLVMConstNot" 608external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd" 609external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd" 610external const_nuw_add : llvalue -> llvalue -> llvalue = "LLVMConstNUWAdd" 611external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd" 612external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub" 613external const_nsw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNSWSub" 614external const_nuw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNUWSub" 615external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub" 616external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul" 617external const_nsw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNSWMul" 618external const_nuw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNUWMul" 619external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul" 620external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv" 621external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv" 622external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv" 623external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv" 624external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem" 625external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem" 626external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem" 627external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd" 628external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr" 629external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor" 630external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue 631 = "llvm_const_icmp" 632external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue 633 = "llvm_const_fcmp" 634external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl" 635external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr" 636external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr" 637external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep" 638external const_in_bounds_gep : llvalue -> llvalue array -> llvalue 639 = "llvm_const_in_bounds_gep" 640external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc" 641external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt" 642external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt" 643external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc" 644external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt" 645external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP" 646external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP" 647external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI" 648external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI" 649external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt" 650external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr" 651external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast" 652external const_zext_or_bitcast : llvalue -> lltype -> llvalue 653 = "LLVMConstZExtOrBitCast" 654external const_sext_or_bitcast : llvalue -> lltype -> llvalue 655 = "LLVMConstSExtOrBitCast" 656external const_trunc_or_bitcast : llvalue -> lltype -> llvalue 657 = "LLVMConstTruncOrBitCast" 658external const_pointercast : llvalue -> lltype -> llvalue 659 = "LLVMConstPointerCast" 660external const_intcast : llvalue -> lltype -> is_signed:bool -> llvalue 661 = "llvm_const_intcast" 662external const_fpcast : llvalue -> lltype -> llvalue = "LLVMConstFPCast" 663external const_select : llvalue -> llvalue -> llvalue -> llvalue 664 = "LLVMConstSelect" 665external const_extractelement : llvalue -> llvalue -> llvalue 666 = "LLVMConstExtractElement" 667external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue 668 = "LLVMConstInsertElement" 669external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue 670 = "LLVMConstShuffleVector" 671external const_extractvalue : llvalue -> int array -> llvalue 672 = "llvm_const_extractvalue" 673external const_insertvalue : llvalue -> llvalue -> int array -> llvalue 674 = "llvm_const_insertvalue" 675external const_inline_asm : lltype -> string -> string -> bool -> bool -> 676 llvalue 677 = "llvm_const_inline_asm" 678external block_address : llvalue -> llbasicblock -> llvalue = "LLVMBlockAddress" 679 680(*--... Operations on global variables, functions, and aliases (globals) ...--*) 681external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent" 682external is_declaration : llvalue -> bool = "llvm_is_declaration" 683external linkage : llvalue -> Linkage.t = "llvm_linkage" 684external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage" 685external unnamed_addr : llvalue -> bool = "llvm_unnamed_addr" 686external set_unnamed_addr : bool -> llvalue -> unit = "llvm_set_unnamed_addr" 687external section : llvalue -> string = "llvm_section" 688external set_section : string -> llvalue -> unit = "llvm_set_section" 689external visibility : llvalue -> Visibility.t = "llvm_visibility" 690external set_visibility : Visibility.t -> llvalue -> unit = "llvm_set_visibility" 691external dll_storage_class : llvalue -> DLLStorageClass.t = "llvm_dll_storage_class" 692external set_dll_storage_class : DLLStorageClass.t -> llvalue -> unit = "llvm_set_dll_storage_class" 693external alignment : llvalue -> int = "llvm_alignment" 694external set_alignment : int -> llvalue -> unit = "llvm_set_alignment" 695external is_global_constant : llvalue -> bool = "llvm_is_global_constant" 696external set_global_constant : bool -> llvalue -> unit 697 = "llvm_set_global_constant" 698 699(*--... Operations on global variables .....................................--*) 700external declare_global : lltype -> string -> llmodule -> llvalue 701 = "llvm_declare_global" 702external declare_qualified_global : lltype -> string -> int -> llmodule -> 703 llvalue 704 = "llvm_declare_qualified_global" 705external define_global : string -> llvalue -> llmodule -> llvalue 706 = "llvm_define_global" 707external define_qualified_global : string -> llvalue -> int -> llmodule -> 708 llvalue 709 = "llvm_define_qualified_global" 710external lookup_global : string -> llmodule -> llvalue option 711 = "llvm_lookup_global" 712external delete_global : llvalue -> unit = "llvm_delete_global" 713external global_initializer : llvalue -> llvalue = "LLVMGetInitializer" 714external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer" 715external remove_initializer : llvalue -> unit = "llvm_remove_initializer" 716external is_thread_local : llvalue -> bool = "llvm_is_thread_local" 717external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local" 718external thread_local_mode : llvalue -> ThreadLocalMode.t 719 = "llvm_thread_local_mode" 720external set_thread_local_mode : ThreadLocalMode.t -> llvalue -> unit 721 = "llvm_set_thread_local_mode" 722external is_externally_initialized : llvalue -> bool 723 = "llvm_is_externally_initialized" 724external set_externally_initialized : bool -> llvalue -> unit 725 = "llvm_set_externally_initialized" 726external global_begin : llmodule -> (llmodule, llvalue) llpos 727 = "llvm_global_begin" 728external global_succ : llvalue -> (llmodule, llvalue) llpos 729 = "llvm_global_succ" 730external global_end : llmodule -> (llmodule, llvalue) llrev_pos 731 = "llvm_global_end" 732external global_pred : llvalue -> (llmodule, llvalue) llrev_pos 733 = "llvm_global_pred" 734 735let rec iter_global_range f i e = 736 if i = e then () else 737 match i with 738 | At_end _ -> raise (Invalid_argument "Invalid global variable range.") 739 | Before bb -> 740 f bb; 741 iter_global_range f (global_succ bb) e 742 743let iter_globals f m = 744 iter_global_range f (global_begin m) (At_end m) 745 746let rec fold_left_global_range f init i e = 747 if i = e then init else 748 match i with 749 | At_end _ -> raise (Invalid_argument "Invalid global variable range.") 750 | Before bb -> fold_left_global_range f (f init bb) (global_succ bb) e 751 752let fold_left_globals f init m = 753 fold_left_global_range f init (global_begin m) (At_end m) 754 755let rec rev_iter_global_range f i e = 756 if i = e then () else 757 match i with 758 | At_start _ -> raise (Invalid_argument "Invalid global variable range.") 759 | After bb -> 760 f bb; 761 rev_iter_global_range f (global_pred bb) e 762 763let rev_iter_globals f m = 764 rev_iter_global_range f (global_end m) (At_start m) 765 766let rec fold_right_global_range f i e init = 767 if i = e then init else 768 match i with 769 | At_start _ -> raise (Invalid_argument "Invalid global variable range.") 770 | After bb -> fold_right_global_range f (global_pred bb) e (f bb init) 771 772let fold_right_globals f m init = 773 fold_right_global_range f (global_end m) (At_start m) init 774 775(*--... Operations on aliases ..............................................--*) 776external add_alias : llmodule -> lltype -> llvalue -> string -> llvalue 777 = "llvm_add_alias" 778 779(*--... Operations on functions ............................................--*) 780external declare_function : string -> lltype -> llmodule -> llvalue 781 = "llvm_declare_function" 782external define_function : string -> lltype -> llmodule -> llvalue 783 = "llvm_define_function" 784external lookup_function : string -> llmodule -> llvalue option 785 = "llvm_lookup_function" 786external delete_function : llvalue -> unit = "llvm_delete_function" 787external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic" 788external function_call_conv : llvalue -> int = "llvm_function_call_conv" 789external set_function_call_conv : int -> llvalue -> unit 790 = "llvm_set_function_call_conv" 791external gc : llvalue -> string option = "llvm_gc" 792external set_gc : string option -> llvalue -> unit = "llvm_set_gc" 793external function_begin : llmodule -> (llmodule, llvalue) llpos 794 = "llvm_function_begin" 795external function_succ : llvalue -> (llmodule, llvalue) llpos 796 = "llvm_function_succ" 797external function_end : llmodule -> (llmodule, llvalue) llrev_pos 798 = "llvm_function_end" 799external function_pred : llvalue -> (llmodule, llvalue) llrev_pos 800 = "llvm_function_pred" 801 802let rec iter_function_range f i e = 803 if i = e then () else 804 match i with 805 | At_end _ -> raise (Invalid_argument "Invalid function range.") 806 | Before fn -> 807 f fn; 808 iter_function_range f (function_succ fn) e 809 810let iter_functions f m = 811 iter_function_range f (function_begin m) (At_end m) 812 813let rec fold_left_function_range f init i e = 814 if i = e then init else 815 match i with 816 | At_end _ -> raise (Invalid_argument "Invalid function range.") 817 | Before fn -> fold_left_function_range f (f init fn) (function_succ fn) e 818 819let fold_left_functions f init m = 820 fold_left_function_range f init (function_begin m) (At_end m) 821 822let rec rev_iter_function_range f i e = 823 if i = e then () else 824 match i with 825 | At_start _ -> raise (Invalid_argument "Invalid function range.") 826 | After fn -> 827 f fn; 828 rev_iter_function_range f (function_pred fn) e 829 830let rev_iter_functions f m = 831 rev_iter_function_range f (function_end m) (At_start m) 832 833let rec fold_right_function_range f i e init = 834 if i = e then init else 835 match i with 836 | At_start _ -> raise (Invalid_argument "Invalid function range.") 837 | After fn -> fold_right_function_range f (function_pred fn) e (f fn init) 838 839let fold_right_functions f m init = 840 fold_right_function_range f (function_end m) (At_start m) init 841 842external llvm_add_function_attr : llvalue -> llattribute -> int -> unit 843 = "llvm_add_function_attr" 844external llvm_function_attrs : llvalue -> int -> llattribute array 845 = "llvm_function_attrs" 846external llvm_remove_enum_function_attr : llvalue -> llattrkind -> int -> unit 847 = "llvm_remove_enum_function_attr" 848external llvm_remove_string_function_attr : llvalue -> string -> int -> unit 849 = "llvm_remove_string_function_attr" 850 851let add_function_attr f a i = 852 llvm_add_function_attr f a (AttrIndex.to_int i) 853let function_attrs f i = 854 llvm_function_attrs f (AttrIndex.to_int i) 855let remove_enum_function_attr f k i = 856 llvm_remove_enum_function_attr f k (AttrIndex.to_int i) 857let remove_string_function_attr f k i = 858 llvm_remove_string_function_attr f k (AttrIndex.to_int i) 859 860(*--... Operations on params ...............................................--*) 861external params : llvalue -> llvalue array = "llvm_params" 862external param : llvalue -> int -> llvalue = "llvm_param" 863external param_parent : llvalue -> llvalue = "LLVMGetParamParent" 864external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin" 865external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ" 866external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end" 867external param_pred : llvalue -> (llvalue, llvalue) llrev_pos ="llvm_param_pred" 868 869let rec iter_param_range f i e = 870 if i = e then () else 871 match i with 872 | At_end _ -> raise (Invalid_argument "Invalid parameter range.") 873 | Before p -> 874 f p; 875 iter_param_range f (param_succ p) e 876 877let iter_params f fn = 878 iter_param_range f (param_begin fn) (At_end fn) 879 880let rec fold_left_param_range f init i e = 881 if i = e then init else 882 match i with 883 | At_end _ -> raise (Invalid_argument "Invalid parameter range.") 884 | Before p -> fold_left_param_range f (f init p) (param_succ p) e 885 886let fold_left_params f init fn = 887 fold_left_param_range f init (param_begin fn) (At_end fn) 888 889let rec rev_iter_param_range f i e = 890 if i = e then () else 891 match i with 892 | At_start _ -> raise (Invalid_argument "Invalid parameter range.") 893 | After p -> 894 f p; 895 rev_iter_param_range f (param_pred p) e 896 897let rev_iter_params f fn = 898 rev_iter_param_range f (param_end fn) (At_start fn) 899 900let rec fold_right_param_range f init i e = 901 if i = e then init else 902 match i with 903 | At_start _ -> raise (Invalid_argument "Invalid parameter range.") 904 | After p -> fold_right_param_range f (f p init) (param_pred p) e 905 906let fold_right_params f fn init = 907 fold_right_param_range f init (param_end fn) (At_start fn) 908 909(*--... Operations on basic blocks .........................................--*) 910external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue" 911external value_is_block : llvalue -> bool = "llvm_value_is_block" 912external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock" 913external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent" 914external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks" 915external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock" 916external delete_block : llbasicblock -> unit = "llvm_delete_block" 917external remove_block : llbasicblock -> unit = "llvm_remove_block" 918external move_block_before : llbasicblock -> llbasicblock -> unit 919 = "llvm_move_block_before" 920external move_block_after : llbasicblock -> llbasicblock -> unit 921 = "llvm_move_block_after" 922external append_block : llcontext -> string -> llvalue -> llbasicblock 923 = "llvm_append_block" 924external insert_block : llcontext -> string -> llbasicblock -> llbasicblock 925 = "llvm_insert_block" 926external block_begin : llvalue -> (llvalue, llbasicblock) llpos 927 = "llvm_block_begin" 928external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos 929 = "llvm_block_succ" 930external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos 931 = "llvm_block_end" 932external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos 933 = "llvm_block_pred" 934external block_terminator : llbasicblock -> llvalue option = 935 "llvm_block_terminator" 936 937let rec iter_block_range f i e = 938 if i = e then () else 939 match i with 940 | At_end _ -> raise (Invalid_argument "Invalid block range.") 941 | Before bb -> 942 f bb; 943 iter_block_range f (block_succ bb) e 944 945let iter_blocks f fn = 946 iter_block_range f (block_begin fn) (At_end fn) 947 948let rec fold_left_block_range f init i e = 949 if i = e then init else 950 match i with 951 | At_end _ -> raise (Invalid_argument "Invalid block range.") 952 | Before bb -> fold_left_block_range f (f init bb) (block_succ bb) e 953 954let fold_left_blocks f init fn = 955 fold_left_block_range f init (block_begin fn) (At_end fn) 956 957let rec rev_iter_block_range f i e = 958 if i = e then () else 959 match i with 960 | At_start _ -> raise (Invalid_argument "Invalid block range.") 961 | After bb -> 962 f bb; 963 rev_iter_block_range f (block_pred bb) e 964 965let rev_iter_blocks f fn = 966 rev_iter_block_range f (block_end fn) (At_start fn) 967 968let rec fold_right_block_range f init i e = 969 if i = e then init else 970 match i with 971 | At_start _ -> raise (Invalid_argument "Invalid block range.") 972 | After bb -> fold_right_block_range f (f bb init) (block_pred bb) e 973 974let fold_right_blocks f fn init = 975 fold_right_block_range f init (block_end fn) (At_start fn) 976 977(*--... Operations on instructions .........................................--*) 978external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent" 979external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos 980 = "llvm_instr_begin" 981external instr_succ : llvalue -> (llbasicblock, llvalue) llpos 982 = "llvm_instr_succ" 983external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos 984 = "llvm_instr_end" 985external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos 986 = "llvm_instr_pred" 987 988external instr_opcode : llvalue -> Opcode.t = "llvm_instr_get_opcode" 989external icmp_predicate : llvalue -> Icmp.t option = "llvm_instr_icmp_predicate" 990external fcmp_predicate : llvalue -> Fcmp.t option = "llvm_instr_fcmp_predicate" 991external instr_clone : llvalue -> llvalue = "llvm_instr_clone" 992 993let rec iter_instrs_range f i e = 994 if i = e then () else 995 match i with 996 | At_end _ -> raise (Invalid_argument "Invalid instruction range.") 997 | Before i -> 998 f i; 999 iter_instrs_range f (instr_succ i) e 1000 1001let iter_instrs f bb = 1002 iter_instrs_range f (instr_begin bb) (At_end bb) 1003 1004let rec fold_left_instrs_range f init i e = 1005 if i = e then init else 1006 match i with 1007 | At_end _ -> raise (Invalid_argument "Invalid instruction range.") 1008 | Before i -> fold_left_instrs_range f (f init i) (instr_succ i) e 1009 1010let fold_left_instrs f init bb = 1011 fold_left_instrs_range f init (instr_begin bb) (At_end bb) 1012 1013let rec rev_iter_instrs_range f i e = 1014 if i = e then () else 1015 match i with 1016 | At_start _ -> raise (Invalid_argument "Invalid instruction range.") 1017 | After i -> 1018 f i; 1019 rev_iter_instrs_range f (instr_pred i) e 1020 1021let rev_iter_instrs f bb = 1022 rev_iter_instrs_range f (instr_end bb) (At_start bb) 1023 1024let rec fold_right_instr_range f i e init = 1025 if i = e then init else 1026 match i with 1027 | At_start _ -> raise (Invalid_argument "Invalid instruction range.") 1028 | After i -> fold_right_instr_range f (instr_pred i) e (f i init) 1029 1030let fold_right_instrs f bb init = 1031 fold_right_instr_range f (instr_end bb) (At_start bb) init 1032 1033 1034(*--... Operations on call sites ...........................................--*) 1035external instruction_call_conv: llvalue -> int 1036 = "llvm_instruction_call_conv" 1037external set_instruction_call_conv: int -> llvalue -> unit 1038 = "llvm_set_instruction_call_conv" 1039 1040external llvm_add_call_site_attr : llvalue -> llattribute -> int -> unit 1041 = "llvm_add_call_site_attr" 1042external llvm_call_site_attrs : llvalue -> int -> llattribute array 1043 = "llvm_call_site_attrs" 1044external llvm_remove_enum_call_site_attr : llvalue -> llattrkind -> int -> unit 1045 = "llvm_remove_enum_call_site_attr" 1046external llvm_remove_string_call_site_attr : llvalue -> string -> int -> unit 1047 = "llvm_remove_string_call_site_attr" 1048 1049let add_call_site_attr f a i = 1050 llvm_add_call_site_attr f a (AttrIndex.to_int i) 1051let call_site_attrs f i = 1052 llvm_call_site_attrs f (AttrIndex.to_int i) 1053let remove_enum_call_site_attr f k i = 1054 llvm_remove_enum_call_site_attr f k (AttrIndex.to_int i) 1055let remove_string_call_site_attr f k i = 1056 llvm_remove_string_call_site_attr f k (AttrIndex.to_int i) 1057 1058(*--... Operations on call and invoke instructions (only) ..................--*) 1059external num_arg_operands : llvalue -> int = "llvm_num_arg_operands" 1060external is_tail_call : llvalue -> bool = "llvm_is_tail_call" 1061external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call" 1062external get_normal_dest : llvalue -> llbasicblock = "LLVMGetNormalDest" 1063external get_unwind_dest : llvalue -> llbasicblock = "LLVMGetUnwindDest" 1064 1065(*--... Operations on load/store instructions (only) .......................--*) 1066external is_volatile : llvalue -> bool = "llvm_is_volatile" 1067external set_volatile : bool -> llvalue -> unit = "llvm_set_volatile" 1068 1069(*--... Operations on terminators ..........................................--*) 1070 1071let is_terminator llv = 1072 let open ValueKind in 1073 let open Opcode in 1074 match classify_value llv with 1075 | Instruction (Br | IndirectBr | Invoke | Resume | Ret | Switch | Unreachable) 1076 -> true 1077 | _ -> false 1078 1079external successor : llvalue -> int -> llbasicblock = "llvm_successor" 1080external set_successor : llvalue -> int -> llbasicblock -> unit 1081 = "llvm_set_successor" 1082external num_successors : llvalue -> int = "llvm_num_successors" 1083 1084let successors llv = 1085 if not (is_terminator llv) then 1086 raise (Invalid_argument "Llvm.successors can only be used on terminators") 1087 else 1088 Array.init (num_successors llv) (successor llv) 1089 1090let iter_successors f llv = 1091 if not (is_terminator llv) then 1092 raise (Invalid_argument "Llvm.iter_successors can only be used on terminators") 1093 else 1094 for i = 0 to num_successors llv - 1 do 1095 f (successor llv i) 1096 done 1097 1098let fold_successors f llv z = 1099 if not (is_terminator llv) then 1100 raise (Invalid_argument "Llvm.fold_successors can only be used on terminators") 1101 else 1102 let n = num_successors llv in 1103 let rec aux i acc = 1104 if i >= n then acc 1105 else begin 1106 let llb = successor llv i in 1107 aux (i+1) (f llb acc) 1108 end 1109 in aux 0 z 1110 1111 1112(*--... Operations on branches .............................................--*) 1113external condition : llvalue -> llvalue = "llvm_condition" 1114external set_condition : llvalue -> llvalue -> unit 1115 = "llvm_set_condition" 1116external is_conditional : llvalue -> bool = "llvm_is_conditional" 1117 1118let get_branch llv = 1119 if classify_value llv <> ValueKind.Instruction Opcode.Br then 1120 None 1121 else if is_conditional llv then 1122 Some (`Conditional (condition llv, successor llv 0, successor llv 1)) 1123 else 1124 Some (`Unconditional (successor llv 0)) 1125 1126(*--... Operations on phi nodes ............................................--*) 1127external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit 1128 = "llvm_add_incoming" 1129external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming" 1130 1131external delete_instruction : llvalue -> unit = "llvm_delete_instruction" 1132 1133(*===-- Instruction builders ----------------------------------------------===*) 1134external builder : llcontext -> llbuilder = "llvm_builder" 1135external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit 1136 = "llvm_position_builder" 1137external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block" 1138external insert_into_builder : llvalue -> string -> llbuilder -> unit 1139 = "llvm_insert_into_builder" 1140 1141let builder_at context ip = 1142 let b = builder context in 1143 position_builder ip b; 1144 b 1145 1146let builder_before context i = builder_at context (Before i) 1147let builder_at_end context bb = builder_at context (At_end bb) 1148 1149let position_before i = position_builder (Before i) 1150let position_at_end bb = position_builder (At_end bb) 1151 1152 1153(*--... Metadata ...........................................................--*) 1154external set_current_debug_location : llbuilder -> llvalue -> unit 1155 = "llvm_set_current_debug_location" 1156external clear_current_debug_location : llbuilder -> unit 1157 = "llvm_clear_current_debug_location" 1158external current_debug_location : llbuilder -> llvalue option 1159 = "llvm_current_debug_location" 1160external set_inst_debug_location : llbuilder -> llvalue -> unit 1161 = "llvm_set_inst_debug_location" 1162 1163 1164(*--... Terminators ........................................................--*) 1165external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void" 1166external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret" 1167external build_aggregate_ret : llvalue array -> llbuilder -> llvalue 1168 = "llvm_build_aggregate_ret" 1169external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br" 1170external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder -> 1171 llvalue = "llvm_build_cond_br" 1172external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue 1173 = "llvm_build_switch" 1174external build_malloc : lltype -> string -> llbuilder -> llvalue = 1175 "llvm_build_malloc" 1176external build_array_malloc : lltype -> llvalue -> string -> llbuilder -> 1177 llvalue = "llvm_build_array_malloc" 1178external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free" 1179external add_case : llvalue -> llvalue -> llbasicblock -> unit 1180 = "llvm_add_case" 1181external switch_default_dest : llvalue -> llbasicblock = 1182 "LLVMGetSwitchDefaultDest" 1183external build_indirect_br : llvalue -> int -> llbuilder -> llvalue 1184 = "llvm_build_indirect_br" 1185external add_destination : llvalue -> llbasicblock -> unit 1186 = "llvm_add_destination" 1187external build_invoke : llvalue -> llvalue array -> llbasicblock -> 1188 llbasicblock -> string -> llbuilder -> llvalue 1189 = "llvm_build_invoke_bc" "llvm_build_invoke_nat" 1190external build_landingpad : lltype -> llvalue -> int -> string -> llbuilder -> 1191 llvalue = "llvm_build_landingpad" 1192external is_cleanup : llvalue -> bool = "llvm_is_cleanup" 1193external set_cleanup : llvalue -> bool -> unit = "llvm_set_cleanup" 1194external add_clause : llvalue -> llvalue -> unit = "llvm_add_clause" 1195external build_resume : llvalue -> llbuilder -> llvalue = "llvm_build_resume" 1196external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable" 1197 1198(*--... Arithmetic .........................................................--*) 1199external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue 1200 = "llvm_build_add" 1201external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue 1202 = "llvm_build_nsw_add" 1203external build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue 1204 = "llvm_build_nuw_add" 1205external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue 1206 = "llvm_build_fadd" 1207external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1208 = "llvm_build_sub" 1209external build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1210 = "llvm_build_nsw_sub" 1211external build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1212 = "llvm_build_nuw_sub" 1213external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1214 = "llvm_build_fsub" 1215external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1216 = "llvm_build_mul" 1217external build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1218 = "llvm_build_nsw_mul" 1219external build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1220 = "llvm_build_nuw_mul" 1221external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1222 = "llvm_build_fmul" 1223external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1224 = "llvm_build_udiv" 1225external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1226 = "llvm_build_sdiv" 1227external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1228 = "llvm_build_exact_sdiv" 1229external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1230 = "llvm_build_fdiv" 1231external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1232 = "llvm_build_urem" 1233external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1234 = "llvm_build_srem" 1235external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1236 = "llvm_build_frem" 1237external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue 1238 = "llvm_build_shl" 1239external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue 1240 = "llvm_build_lshr" 1241external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue 1242 = "llvm_build_ashr" 1243external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue 1244 = "llvm_build_and" 1245external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue 1246 = "llvm_build_or" 1247external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue 1248 = "llvm_build_xor" 1249external build_neg : llvalue -> string -> llbuilder -> llvalue 1250 = "llvm_build_neg" 1251external build_nsw_neg : llvalue -> string -> llbuilder -> llvalue 1252 = "llvm_build_nsw_neg" 1253external build_nuw_neg : llvalue -> string -> llbuilder -> llvalue 1254 = "llvm_build_nuw_neg" 1255external build_fneg : llvalue -> string -> llbuilder -> llvalue 1256 = "llvm_build_fneg" 1257external build_not : llvalue -> string -> llbuilder -> llvalue 1258 = "llvm_build_not" 1259 1260(*--... Memory .............................................................--*) 1261external build_alloca : lltype -> string -> llbuilder -> llvalue 1262 = "llvm_build_alloca" 1263external build_array_alloca : lltype -> llvalue -> string -> llbuilder -> 1264 llvalue = "llvm_build_array_alloca" 1265external build_load : llvalue -> string -> llbuilder -> llvalue 1266 = "llvm_build_load" 1267external build_store : llvalue -> llvalue -> llbuilder -> llvalue 1268 = "llvm_build_store" 1269external build_atomicrmw : AtomicRMWBinOp.t -> llvalue -> llvalue -> 1270 AtomicOrdering.t -> bool -> string -> llbuilder -> 1271 llvalue 1272 = "llvm_build_atomicrmw_bytecode" 1273 "llvm_build_atomicrmw_native" 1274external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue 1275 = "llvm_build_gep" 1276external build_in_bounds_gep : llvalue -> llvalue array -> string -> 1277 llbuilder -> llvalue = "llvm_build_in_bounds_gep" 1278external build_struct_gep : llvalue -> int -> string -> llbuilder -> llvalue 1279 = "llvm_build_struct_gep" 1280 1281external build_global_string : string -> string -> llbuilder -> llvalue 1282 = "llvm_build_global_string" 1283external build_global_stringptr : string -> string -> llbuilder -> llvalue 1284 = "llvm_build_global_stringptr" 1285 1286(*--... Casts ..............................................................--*) 1287external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue 1288 = "llvm_build_trunc" 1289external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue 1290 = "llvm_build_zext" 1291external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue 1292 = "llvm_build_sext" 1293external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue 1294 = "llvm_build_fptoui" 1295external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue 1296 = "llvm_build_fptosi" 1297external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue 1298 = "llvm_build_uitofp" 1299external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue 1300 = "llvm_build_sitofp" 1301external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue 1302 = "llvm_build_fptrunc" 1303external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue 1304 = "llvm_build_fpext" 1305external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue 1306 = "llvm_build_prttoint" 1307external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue 1308 = "llvm_build_inttoptr" 1309external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue 1310 = "llvm_build_bitcast" 1311external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 1312 llvalue = "llvm_build_zext_or_bitcast" 1313external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 1314 llvalue = "llvm_build_sext_or_bitcast" 1315external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 1316 llvalue = "llvm_build_trunc_or_bitcast" 1317external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue 1318 = "llvm_build_pointercast" 1319external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue 1320 = "llvm_build_intcast" 1321external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue 1322 = "llvm_build_fpcast" 1323 1324(*--... Comparisons ........................................................--*) 1325external build_icmp : Icmp.t -> llvalue -> llvalue -> string -> 1326 llbuilder -> llvalue = "llvm_build_icmp" 1327external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string -> 1328 llbuilder -> llvalue = "llvm_build_fcmp" 1329 1330(*--... Miscellaneous instructions .........................................--*) 1331external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder -> 1332 llvalue = "llvm_build_phi" 1333external build_empty_phi : lltype -> string -> llbuilder -> llvalue 1334 = "llvm_build_empty_phi" 1335external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue 1336 = "llvm_build_call" 1337external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder -> 1338 llvalue = "llvm_build_select" 1339external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue 1340 = "llvm_build_va_arg" 1341external build_extractelement : llvalue -> llvalue -> string -> llbuilder -> 1342 llvalue = "llvm_build_extractelement" 1343external build_insertelement : llvalue -> llvalue -> llvalue -> string -> 1344 llbuilder -> llvalue = "llvm_build_insertelement" 1345external build_shufflevector : llvalue -> llvalue -> llvalue -> string -> 1346 llbuilder -> llvalue = "llvm_build_shufflevector" 1347external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue 1348 = "llvm_build_extractvalue" 1349external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder -> 1350 llvalue = "llvm_build_insertvalue" 1351 1352external build_is_null : llvalue -> string -> llbuilder -> llvalue 1353 = "llvm_build_is_null" 1354external build_is_not_null : llvalue -> string -> llbuilder -> llvalue 1355 = "llvm_build_is_not_null" 1356external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue 1357 = "llvm_build_ptrdiff" 1358external build_freeze : llvalue -> string -> llbuilder -> llvalue 1359 = "llvm_build_freeze" 1360 1361 1362(*===-- Memory buffers ----------------------------------------------------===*) 1363 1364module MemoryBuffer = struct 1365 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file" 1366 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin" 1367 external of_string : ?name:string -> string -> llmemorybuffer 1368 = "llvm_memorybuffer_of_string" 1369 external as_string : llmemorybuffer -> string = "llvm_memorybuffer_as_string" 1370 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose" 1371end 1372 1373 1374(*===-- Pass Manager ------------------------------------------------------===*) 1375 1376module PassManager = struct 1377 type 'a t 1378 type any = [ `Module | `Function ] 1379 external create : unit -> [ `Module ] t = "llvm_passmanager_create" 1380 external create_function : llmodule -> [ `Function ] t 1381 = "LLVMCreateFunctionPassManager" 1382 external run_module : llmodule -> [ `Module ] t -> bool 1383 = "llvm_passmanager_run_module" 1384 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize" 1385 external run_function : llvalue -> [ `Function ] t -> bool 1386 = "llvm_passmanager_run_function" 1387 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize" 1388 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose" 1389end 1390