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