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