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