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