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