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