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