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