source: parabix-LLVM/llvm_git/bindings/ocaml/llvm/llvm.mli @ 4078

Last change on this file since 4078 was 4078, checked in by linmengl, 5 years ago

checkin llvm-meng source

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