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