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