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