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