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