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