Add a getAlignOf helper for getting the ABI alignment of a
[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 other LLVM Intermediate Representation (IR)
21     objects. See the [llvm::Module] class. *)
22 type llmodule
23
24 (** Each value in the LLVM IR has a type, an instance of [lltype]. See the
25     [llvm::Type] class. *)
26 type lltype
27
28 (** When building recursive types using {!refine_type}, [lltype] values may
29     become invalid; use [lltypehandle] to resolve this problem. See the
30     [llvm::AbstractTypeHolder] class. *)
31 type lltypehandle
32
33 (** Any value in the LLVM IR. Functions, instructions, global variables,
34     constants, and much more are all [llvalues]. See the [llvm::Value] class.
35     This type covers a wide range of subclasses. *)
36 type llvalue
37
38 (** A basic block in LLVM IR. See the [llvm::BasicBlock] class. *)
39 type llbasicblock
40
41 (** Used to generate instructions in the LLVM IR. See the [llvm::LLVMBuilder]
42     class. *)
43 type llbuilder
44
45 (** Used to provide a module to JIT or interpreter.
46     See the [llvm::ModuleProvider] class. *)
47 type llmoduleprovider
48
49 (** Used to efficiently handle large buffers of read-only binary data.
50     See the [llvm::MemoryBuffer] class. *)
51 type llmemorybuffer
52
53 (** The kind of an [lltype], the result of [classify_type ty]. See the
54     [llvm::Type::TypeID] enumeration. *)
55 module TypeKind : sig
56   type t =
57     Void
58   | Float
59   | Double
60   | X86fp80
61   | Fp128
62   | Ppc_fp128
63   | Label
64   | Integer
65   | Function
66   | Struct
67   | Array
68   | Pointer
69   | Opaque
70   | Vector
71 end
72
73 (** The linkage of a global value, accessed with {!linkage} and
74     {!set_linkage}. See [llvm::GlobalValue::LinkageTypes]. *)
75 module Linkage : sig
76   type t =
77     External
78   | Available_externally
79   | Link_once
80   | Weak
81   | Appending
82   | Internal
83   | Dllimport
84   | Dllexport
85   | External_weak
86   | Ghost
87 end
88
89 (** The linker visibility of a global value, accessed with {!visibility} and
90     {!set_visibility}. See [llvm::GlobalValue::VisibilityTypes]. *)
91 module Visibility : sig
92   type t =
93     Default
94   | Hidden
95   | Protected
96 end
97
98 (** The following calling convention values may be accessed with
99     {!function_call_conv} and {!set_function_call_conv}. Calling
100     conventions are open-ended. *)
101 module CallConv : sig
102   val c : int             (** [c] is the C calling convention. *)
103   val fast : int          (** [fast] is the calling convention to allow LLVM
104                               maximum optimization opportunities. Use only with
105                               internal linkage. *)
106   val cold : int          (** [cold] is the calling convention for
107                               callee-save. *)
108   val x86_stdcall : int   (** [x86_stdcall] is the familiar stdcall calling
109                               convention from C. *)
110   val x86_fastcall : int  (** [x86_fastcall] is the familiar fastcall calling
111                               convention from C. *)
112 end
113
114 module Attribute : sig
115   type t =
116   | Zext
117   | Sext
118   | Noreturn
119   | Inreg
120   | Structret
121   | Nounwind
122   | Noalias
123   | Byval
124   | Nest
125   | Readnone
126   | Readonly
127 end
128
129 (** The predicate for an integer comparison ([icmp]) instruction.
130     See the [llvm::ICmpInst::Predicate] enumeration. *)
131 module Icmp : sig
132   type t =
133   | Eq
134   | Ne
135   | Ugt
136   | Uge
137   | Ult
138   | Ule
139   | Sgt
140   | Sge
141   | Slt
142   | Sle
143 end
144
145 (** The predicate for a floating-point comparison ([fcmp]) instruction.
146     See the [llvm::FCmpInst::Predicate] enumeration. *)
147 module Fcmp : sig
148   type t =
149   | False
150   | Oeq
151   | Ogt
152   | Oge
153   | Olt
154   | Ole
155   | One
156   | Ord
157   | Uno
158   | Ueq
159   | Ugt
160   | Uge
161   | Ult
162   | Ule
163   | Une
164   | True
165 end
166
167
168 (** {6 Iteration} *)
169
170 (** [Before b] and [At_end a] specify positions from the start of the ['b] list
171     of [a]. [llpos] is used to specify positions in and for forward iteration
172     through the various value lists maintained by the LLVM IR. *)
173 type ('a, 'b) llpos =
174 | At_end of 'a
175 | Before of 'b
176
177 (** [After b] and [At_start a] specify positions from the end of the ['b] list
178     of [a]. [llrev_pos] is used for reverse iteration through the various value
179     lists maintained by the LLVM IR. *)
180 type ('a, 'b) llrev_pos =
181 | At_start of 'a
182 | After of 'b
183
184
185 (** {6 Exceptions} *)
186
187 exception IoError of string
188
189
190 (** {6 Modules} *)
191
192 (** [create_module id] creates a module with the supplied module ID. Modules are
193     not garbage collected; it is mandatory to call {!dispose_module} to free
194     memory. See the constructor [llvm::Module::Module]. *)
195 external create_module : string -> llmodule = "llvm_create_module"
196
197 (** [dispose_module m] destroys a module [m] and all of the IR objects it
198     contained. All references to subordinate objects are invalidated;
199     referencing them will invoke undefined behavior. See the destructor
200     [llvm::Module::~Module]. *)
201 external dispose_module : llmodule -> unit = "llvm_dispose_module"
202
203 (** [target_triple m] is the target specifier for the module [m], something like
204     [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
205 external target_triple: llmodule -> string
206                       = "llvm_target_triple"
207
208 (** [target_triple triple m] changes the target specifier for the module [m] to
209     the string [triple]. See the method [llvm::Module::setTargetTriple]. *)
210 external set_target_triple: string -> llmodule -> unit
211                           = "llvm_set_target_triple"
212
213 (** [data_layout m] is the data layout specifier for the module [m], something
214     like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
215     method [llvm::Module::getDataLayout]. *)
216 external data_layout: llmodule -> string
217                     = "llvm_data_layout"
218
219 (** [set_data_layout s m] changes the data layout specifier for the module [m]
220     to the string [s]. See the method [llvm::Module::setDataLayout]. *)
221 external set_data_layout: string -> llmodule -> unit
222                         = "llvm_set_data_layout"
223
224 (** [define_type_name name ty m] adds a named type to the module's symbol table.
225     Returns [true] if successful. If such a name already exists, then no entry
226     is added and [false] is returned. See the [llvm::Module::addTypeName]
227     method. *)
228 external define_type_name : string -> lltype -> llmodule -> bool
229                           = "llvm_add_type_name"
230
231 (** [delete_type_name name] removes a type name from the module's symbol
232     table. *)
233 external delete_type_name : string -> llmodule -> unit
234                           = "llvm_delete_type_name"
235
236 (** [dump_module m] prints the .ll representation of the module [m] to standard
237     error. See the method [llvm::Module::dump]. *)
238 external dump_module : llmodule -> unit = "llvm_dump_module"
239
240
241 (** {6 Types} *)
242
243 (** [classify_type ty] returns the {!TypeKind.t} corresponding to the type [ty].
244     See the method [llvm::Type::getTypeID]. *)
245 external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
246
247 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
248 val string_of_lltype : lltype -> string
249
250 (** {7 Operations on integer types} *)
251
252 (** The 1-bit integer type. See [llvm::Type::Int1Ty]. *)
253 val i1_type : lltype
254
255 (** The 8-bit integer type. See [llvm::Type::Int8Ty]. *)
256 val i8_type : lltype
257
258 (** The 16-bit integer type. See [llvm::Type::Int16Ty]. *)
259 val i16_type : lltype
260
261 (** The 32-bit integer type. See [llvm::Type::Int32Ty]. *)
262 val i32_type : lltype
263
264 (** The 64-bit integer type. See [llvm::Type::Int64Ty]. *)
265 val i64_type : lltype
266
267 (** [integer_type n] returns an integer type of bitwidth [n].
268     See the method [llvm::IntegerType::get]. *)
269 external integer_type : int -> lltype = "llvm_integer_type"
270
271 (** [integer_bitwidth ty] returns the number of bits in the integer type [ty].
272     See the method [llvm::IntegerType::getBitWidth]. *)
273 external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth"
274
275
276 (** {7 Operations on real types} *)
277
278 (** The IEEE 32-bit floating point type. See [llvm::Type::FloatTy]. *)
279 val float_type : lltype
280
281 (** The IEEE 64-bit floating point type. See [llvm::Type::DoubleTy]. *)
282 val double_type : lltype
283
284 (** The x87 80-bit floating point type. See [llvm::Type::X86_FP80Ty]. *)
285 val x86fp80_type : lltype
286
287 (** The IEEE 128-bit floating point type. See [llvm::Type::FP128Ty]. *)
288 val fp128_type : lltype
289
290 (** The PowerPC 128-bit floating point type. See [llvm::Type::PPC_FP128Ty]. *)
291 val ppc_fp128_type : lltype
292
293
294 (** {7 Operations on function types} *)
295
296 (** [function_type ret_ty param_tys] returns the function type returning
297     [ret_ty] and taking [param_tys] as parameters.
298     See the method [llvm::FunctionType::get]. *)
299 external function_type : lltype -> lltype array -> lltype = "llvm_function_type"
300
301 (** [va_arg_function_type ret_ty param_tys] is just like
302     [function_type ret_ty param_tys] except that it returns the function type
303     which also takes a variable number of arguments.
304     See the method [llvm::FunctionType::get]. *)
305 external var_arg_function_type : lltype -> lltype array -> lltype
306                                = "llvm_var_arg_function_type"
307
308 (** [is_var_arg fty] returns [true] if [fty] is a varargs function type, [false]
309     otherwise. See the method [llvm::FunctionType::isVarArg]. *)
310 external is_var_arg : lltype -> bool = "llvm_is_var_arg"
311
312 (** [return_type fty] gets the return type of the function type [fty].
313     See the method [llvm::FunctionType::getReturnType]. *)
314 external return_type : lltype -> lltype = "LLVMGetReturnType"
315
316 (** [param_types fty] gets the parameter types of the function type [fty].
317     See the method [llvm::FunctionType::getParamType]. *)
318 external param_types : lltype -> lltype array = "llvm_param_types"
319
320
321 (** {7 Operations on struct types} *)
322
323 (** [struct_type tys] returns the structure type containing in the types in the
324     array [tys]. See the method [llvm::StructType::get]. *)
325 external struct_type : lltype array -> lltype = "llvm_struct_type"
326
327 (** [struct_type tys] returns the packed structure type containing in the types
328     in the array [tys]. See the method [llvm::StructType::get]. *)
329 external packed_struct_type : lltype array -> lltype = "llvm_packed_struct_type"
330
331 (** [element_types sty] returns the constituent types of the struct type [sty].
332     See the method [llvm::StructType::getElementType]. *)
333 external element_types : lltype -> lltype array = "llvm_element_types"
334
335 (** [is_packed sty] returns [true] if the structure type [sty] is packed,
336     [false] otherwise. See the method [llvm::StructType::isPacked]. *)
337 external is_packed : lltype -> bool = "llvm_is_packed"
338
339
340 (** {7 Operations on pointer, vector, and array types} *)
341
342 (** [array_type ty n] returns the array type containing [n] elements of type
343     [ty]. See the method [llvm::ArrayType::get]. *)
344 external array_type : lltype -> int -> lltype = "llvm_array_type"
345
346 (** [pointer_type ty] returns the pointer type referencing objects of type
347     [ty] in the default address space (0).
348     See the method [llvm::PointerType::getUnqual]. *)
349 external pointer_type : lltype -> lltype = "llvm_pointer_type"
350
351 (** [qualified_pointer_type ty as] returns the pointer type referencing objects
352     of type [ty] in address space [as].
353     See the method [llvm::PointerType::get]. *)
354 external qualified_pointer_type : lltype -> int -> lltype
355                                 = "llvm_qualified_pointer_type"
356
357 (** [vector_type ty n] returns the array type containing [n] elements of the
358     primitive type [ty]. See the method [llvm::ArrayType::get]. *)
359 external vector_type : lltype -> int -> lltype = "llvm_vector_type"
360
361 (** [element_type ty] returns the element type of the pointer, vector, or array
362     type [ty]. See the method [llvm::SequentialType::get]. *)
363 external element_type : lltype -> lltype = "LLVMGetElementType"
364
365 (** [element_type aty] returns the element count of the array type [aty].
366     See the method [llvm::ArrayType::getNumElements]. *)
367 external array_length : lltype -> int = "llvm_array_length"
368
369 (** [address_space pty] returns the address space qualifier of the pointer type
370     [pty]. See the method [llvm::PointerType::getAddressSpace]. *)
371 external address_space : lltype -> int = "llvm_address_space"
372
373 (** [element_type ty] returns the element count of the vector type [ty].
374     See the method [llvm::VectorType::getNumElements]. *)
375 external vector_size : lltype -> int = "llvm_vector_size"
376
377
378 (** {7 Operations on other types} *)
379
380 (** [opaque_type ()] creates a new opaque type distinct from any other.
381     Opaque types are useful for building recursive types in combination with
382     {!refine_type}.
383     See [llvm::OpaqueType::get]. *)
384 external opaque_type : unit -> lltype = "llvm_opaque_type"
385
386 (** [void_type] is the type of a function which does not return any value.
387     See [llvm::Type::VoidTy]. *)
388 val void_type : lltype
389
390 (** [label_type] is the type of a basic block. See [llvm::Type::LabelTy]. *)
391 val label_type : lltype
392
393 (** {7 Operations on type handles} *)
394
395 (** [handle_to_type ty] creates a handle to the type [ty]. If [ty] is later
396     refined as a result of a call to {!refine_type}, the handle will be updated;
397     any bare [lltype] references will become invalid.
398     See the class [llvm::PATypeHolder]. *)
399 external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
400
401 (** [type_of_handle tyh] resolves the type handle [tyh].
402     See the method [llvm::PATypeHolder::get()]. *)
403 external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
404
405 (** [refine_type opaque_ty ty] replaces the abstract type [opaque_ty] with the
406     concrete type [ty] in all users. Warning: This may invalidate {!lltype}
407     values! Use {!lltypehandle} to manipulate potentially abstract types. See
408     the method [llvm::Type::refineAbstractType]. *)
409 external refine_type : lltype -> lltype -> unit = "llvm_refine_type"
410
411
412 (* {6 Values} *)
413
414 (** [type_of v] returns the type of the value [v].
415     See the method [llvm::Value::getType]. *)
416 external type_of : llvalue -> lltype = "llvm_type_of"
417
418 (** [value_name v] returns the name of the value [v]. For global values, this is
419     the symbol name. For instructions and basic blocks, it is the SSA register
420     name. It is meaningless for constants.
421     See the method [llvm::Value::getName]. *)
422 external value_name : llvalue -> string = "llvm_value_name"
423
424 (** [set_value_name n v] sets the name of the value [v] to [n]. See the method
425     [llvm::Value::setName]. *)
426 external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
427
428 (** [dump_value v] prints the .ll representation of the value [v] to standard
429     error. See the method [llvm::Value::dump]. *)
430 external dump_value : llvalue -> unit = "llvm_dump_value"
431
432
433 (** {7 Operations on constants of (mostly) any type} *)
434
435 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
436     otherwise. Similar to [llvm::isa<Constant>]. *)
437 external is_constant : llvalue -> bool = "llvm_is_constant"
438
439 (** [const_null ty] returns the constant null (zero) of the type [ty].
440     See the method [llvm::Constant::getNullValue]. *)
441 external const_null : lltype -> llvalue = "LLVMConstNull"
442
443 (** [const_all_ones ty] returns the constant '-1' of the integer or vector type
444     [ty]. See the method [llvm::Constant::getAllOnesValue]. *)
445 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
446
447 (** [undef ty] returns the undefined value of the type [ty].
448     See the method [llvm::UndefValue::get]. *)
449 external undef : lltype -> llvalue = "LLVMGetUndef"
450
451 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
452     See the method [llvm::Constant::isNullValue]. *)
453 external is_null : llvalue -> bool = "llvm_is_null"
454
455 (** [is_undef v] returns [true] if the value [v] is an undefined value, [false]
456     otherwise. Similar to [llvm::isa<UndefValue>]. *)
457 external is_undef : llvalue -> bool = "llvm_is_undef"
458
459
460 (** {7 Operations on scalar constants} *)
461
462 (** [const_int ty i] returns the integer constant of type [ty] and value [i].
463     See the method [llvm::ConstantInt::get]. *)
464 external const_int : lltype -> int -> llvalue = "llvm_const_int"
465
466 (** [const_of_int64 ty i] returns the integer constant of type [ty] and value
467     [i]. See the method [llvm::ConstantInt::get]. *)
468 external const_of_int64 : lltype -> Int64.t -> bool -> llvalue
469                         = "llvm_const_of_int64"
470
471 (** [const_float ty n] returns the floating point constant of type [ty] and
472     value [n]. See the method [llvm::ConstantInt::get]. *)
473 external const_float : lltype -> float -> llvalue = "llvm_const_float"
474
475
476 (** {7 Operations on composite constants} *)
477
478 (** [const_string s] returns the constant [i8] array with the values of the
479     characters in the string [s]. The array is not null-terminated (but see
480     {!const_stringz}). This value can in turn be used as the initializer for a
481     global variable. See the method [llvm::ConstantArray::get]. *)
482 external const_string : string -> llvalue = "llvm_const_string"
483
484 (** [const_stringz s] returns the constant [i8] array with the values of the
485     characters in the string [s] and a null terminator. This value can in turn
486     be used as the initializer for a global variable.
487     See the method [llvm::ConstantArray::get]. *)
488 external const_stringz : string -> llvalue = "llvm_const_stringz"
489
490 (** [const_array ty elts] returns the constant array of type
491     [array_type ty (Array.length elts)] and containing the values [elts].
492     This value can in turn be used as the initializer for a global variable.
493     See the method [llvm::ConstantArray::get]. *)
494 external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array"
495
496 (** [const_struct elts] returns the structured constant of type
497     [struct_type (Array.map type_of elts)] and containing the values [elts].
498     This value can in turn be used as the initializer for a global variable.
499     See the method [llvm::ConstantStruct::get]. *)
500 external const_struct : llvalue array -> llvalue = "llvm_const_struct"
501
502 (** [const_packed_struct elts] returns the structured constant of type
503     {!packed_struct_type} [(Array.map type_of elts)] and containing the values
504     [elts]. This value can in turn be used as the initializer for a global
505     variable. See the method [llvm::ConstantStruct::get]. *)
506 external const_packed_struct : llvalue array -> llvalue
507                              = "llvm_const_packed_struct"
508
509 (** [const_vector elts] returns the vector constant of type
510     [vector_type (type_of elts.(0)) (Array.length elts)] and containing the
511     values [elts]. See the method [llvm::ConstantVector::get]. *)
512 external const_vector : llvalue array -> llvalue = "llvm_const_vector"
513
514
515 (** {7 Constant expressions} *)
516
517 (** [align_of ty] returns the alignof constant for the type [ty]. This is
518     equivalent to [const_ptrtoint (const_gep (const_null (pointer_type {i8,ty}))
519     (const_int i32_type 0) (const_int i32_type 1)) i32_type], but considerably
520     more readable.  See the method [llvm::ConstantExpr::getAlignOf]. *)
521 external align_of : lltype -> llvalue = "LLVMAlignOf"
522
523 (** [size_of ty] returns the sizeof constant for the type [ty]. This is
524     equivalent to [const_ptrtoint (const_gep (const_null (pointer_type ty))
525     (const_int i32_type 1)) i64_type], but considerably more readable.
526     See the method [llvm::ConstantExpr::getSizeOf]. *)
527 external size_of : lltype -> llvalue = "LLVMSizeOf"
528
529 (** [const_neg c] returns the arithmetic negation of the constant [c].
530     See the method [llvm::ConstantExpr::getNeg]. *)
531 external const_neg : llvalue -> llvalue = "LLVMConstNeg"
532
533 (** [const_not c] returns the bitwise inverse of the constant [c].
534     See the method [llvm::ConstantExpr::getNot]. *)
535 external const_not : llvalue -> llvalue = "LLVMConstNot"
536
537 (** [const_add c1 c2] returns the constant sum of two constants.
538     See the method [llvm::ConstantExpr::getAdd]. *)
539 external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
540
541 (** [const_sub c1 c2] returns the constant difference, [c1 - c2], of two
542     constants. See the method [llvm::ConstantExpr::getSub]. *)
543 external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
544
545 (** [const_mul c1 c2] returns the constant product of two constants.
546     See the method [llvm::ConstantExpr::getMul]. *)
547 external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
548
549 (** [const_udiv c1 c2] returns the constant quotient [c1 / c2] of two unsigned
550     integer constants.
551     See the method [llvm::ConstantExpr::getUDiv]. *)
552 external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
553
554 (** [const_sdiv c1 c2] returns the constant quotient [c1 / c2] of two signed
555     integer constants.
556     See the method [llvm::ConstantExpr::]. *)
557 external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
558
559 (** [const_fdiv c1 c2] returns the constant quotient [c1 / c2] of two floating
560     point constants.
561     See the method [llvm::ConstantExpr::getFDiv]. *)
562 external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
563
564 (** [const_udiv c1 c2] returns the constant remainder [c1 MOD c2] of two
565     unsigned integer constants.
566     See the method [llvm::ConstantExpr::getURem]. *)
567 external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
568
569 (** [const_sdiv c1 c2] returns the constant remainder [c1 MOD c2] of two
570     signed integer constants.
571     See the method [llvm::ConstantExpr::getSRem]. *)
572 external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
573
574 (** [const_frem c1 c2] returns the constant remainder [c1 MOD c2] of two
575     signed floating point constants.
576     See the method [llvm::ConstantExpr::getFRem]. *)
577 external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
578
579 (** [const_and c1 c2] returns the constant bitwise [AND] of two integer
580     constants.
581     See the method [llvm::ConstantExpr::getAnd]. *)
582 external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
583
584 (** [const_or c1 c2] returns the constant bitwise [OR] of two integer
585     constants.
586     See the method [llvm::ConstantExpr::getOr]. *)
587 external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
588
589 (** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
590     constants.
591     See the method [llvm::ConstantExpr::getXor]. *)
592 external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
593
594 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
595     constants, [c1 pred c2].
596     See the method [llvm::ConstantExpr::getICmp]. *)
597 external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
598                     = "llvm_const_icmp"
599
600 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
601     point constants, [c1 pred c2].
602     See the method [llvm::ConstantExpr::getFCmp]. *)
603 external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
604                     = "llvm_const_fcmp"
605
606 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
607     constant integer [c2].
608     See the method [llvm::ConstantExpr::getShl]. *)
609 external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
610
611 (** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
612     constant integer [c2] with zero extension.
613     See the method [llvm::ConstantExpr::getLShr]. *)
614 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
615
616 (** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
617     constant integer [c2] with sign extension.
618     See the method [llvm::ConstantExpr::getAShr]. *)
619 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
620
621 (** [const_gep pc indices] returns the constant [getElementPtr] of [p1] with the
622     constant integers indices from the array [indices].
623     See the method [llvm::ConstantExpr::getGetElementPtr]. *)
624 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
625
626 (** [const_trunc c ty] returns the constant truncation of integer constant [c]
627     to the smaller integer type [ty].
628     See the method [llvm::ConstantExpr::getTrunc]. *)
629 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
630
631 (** [const_sext c ty] returns the constant sign extension of integer constant
632     [c] to the larger integer type [ty].
633     See the method [llvm::ConstantExpr::getSExt]. *)
634 external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
635
636 (** [const_zext c ty] returns the constant zero extension of integer constant
637     [c] to the larger integer type [ty].
638     See the method [llvm::ConstantExpr::getZExt]. *)
639 external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
640
641 (** [const_fptrunc c ty] returns the constant truncation of floating point
642     constant [c] to the smaller floating point type [ty].
643     See the method [llvm::ConstantExpr::getFPTrunc]. *)
644 external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
645
646 (** [const_fpext c ty] returns the constant extension of floating point constant
647     [c] to the larger floating point type [ty].
648     See the method [llvm::ConstantExpr::getFPExt]. *)
649 external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
650
651 (** [const_uitofp c ty] returns the constant floating point conversion of
652     unsigned integer constant [c] to the floating point type [ty].
653     See the method [llvm::ConstantExpr::getUIToFP]. *)
654 external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
655
656 (** [const_sitofp c ty] returns the constant floating point conversion of
657     signed integer constant [c] to the floating point type [ty].
658     See the method [llvm::ConstantExpr::getSIToFP]. *)
659 external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
660
661 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
662     floating point constant [c] to integer type [ty].
663     See the method [llvm::ConstantExpr::getFPToUI]. *)
664 external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
665
666 (** [const_fptoui c ty] returns the constant unsigned integer conversion of
667     floating point constant [c] to integer type [ty].
668     See the method [llvm::ConstantExpr::getFPToSI]. *)
669 external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
670
671 (** [const_ptrtoint c ty] returns the constant integer conversion of
672     pointer constant [c] to integer type [ty].
673     See the method [llvm::ConstantExpr::getPtrToInt]. *)
674 external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
675
676 (** [const_inttoptr c ty] returns the constant pointer conversion of
677     integer constant [c] to pointer type [ty].
678     See the method [llvm::ConstantExpr::getIntToPtr]. *)
679 external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
680
681 (** [const_bitcast c ty] returns the constant bitwise conversion of constant [c]
682     to type [ty] of equal size.
683     See the method [llvm::ConstantExpr::getBitCast]. *)
684 external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
685
686 (** [const_select cond t f] returns the constant conditional which returns value
687     [t] if the boolean constant [cond] is true and the value [f] otherwise.
688     See the method [llvm::ConstantExpr::getSelect]. *)
689 external const_select : llvalue -> llvalue -> llvalue -> llvalue
690                       = "LLVMConstSelect"
691
692 (** [const_extractelement vec i] returns the constant [i]th element of
693     constant vector [vec]. [i] must be a constant [i32] value unsigned less than
694     the size of the vector.
695     See the method [llvm::ConstantExpr::getExtractElement]. *)
696 external const_extractelement : llvalue -> llvalue -> llvalue
697                               = "LLVMConstExtractElement"
698
699 (** [const_insertelement vec v i] returns the constant vector with the same
700     elements as constant vector [v] but the [i]th element replaced by the
701     constant [v]. [v] must be a constant value with the type of the vector
702     elements. [i] must be a constant [i32] value unsigned less than the size
703     of the vector.
704     See the method [llvm::ConstantExpr::getInsertElement]. *)
705 external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
706                              = "LLVMConstInsertElement"
707
708 (** [const_shufflevector a b mask] returns a constant [shufflevector].
709     See the LLVM Language Reference for details on the [sufflevector]
710     instruction.
711     See the method [llvm::ConstantExpr::getShuffleVector]. *)
712 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
713                              = "LLVMConstShuffleVector"
714
715
716 (** {7 Operations on global variables, functions, and aliases (globals)} *)
717
718 (** [global_parent g] is the enclosing module of the global value [g].
719     See the method [llvm::GlobalValue::getParent]. *)
720 external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent"
721
722 (** [is_declaration g] returns [true] if the global value [g] is a declaration
723     only. Returns [false] otherwise.
724     See the method [llvm::GlobalValue::isDeclaration]. *)
725 external is_declaration : llvalue -> bool = "llvm_is_declaration"
726
727 (** [linkage g] returns the linkage of the global value [g].
728     See the method [llvm::GlobalValue::getLinkage]. *)
729 external linkage : llvalue -> Linkage.t = "llvm_linkage"
730
731 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
732     See the method [llvm::GlobalValue::setLinkage]. *)
733 external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
734
735 (** [section g] returns the linker section of the global value [g].
736     See the method [llvm::GlobalValue::getSection]. *)
737 external section : llvalue -> string = "llvm_section"
738
739 (** [set_section s g] sets the linker section of the global value [g] to [s].
740     See the method [llvm::GlobalValue::setSection]. *)
741 external set_section : string -> llvalue -> unit = "llvm_set_section"
742
743 (** [visibility g] returns the linker visibility of the global value [g].
744     See the method [llvm::GlobalValue::getVisibility]. *)
745 external visibility : llvalue -> Visibility.t = "llvm_visibility"
746
747 (** [set_visibility v g] sets the linker visibility of the global value [g] to
748     [v]. See the method [llvm::GlobalValue::setVisibility]. *)
749 external set_visibility : Visibility.t -> llvalue -> unit
750                         = "llvm_set_visibility"
751
752 (** [alignment g] returns the required alignment of the global value [g].
753     See the method [llvm::GlobalValue::getAlignment]. *)
754 external alignment : llvalue -> int = "llvm_alignment"
755
756 (** [set_alignment n g] sets the required alignment of the global value [g] to
757     [n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
758 external set_alignment : int -> llvalue -> unit = "llvm_set_alignment"
759
760
761 (** {7 Operations on global variables} *)
762
763 (** [declare_global ty name m] returns a new global variable of type [ty] and
764     with name [name] in module [m]. If such a global variable already exists,
765     it is returned. If the type of the existing global differs, then a bitcast
766     to [ty] is returned. *)
767 external declare_global : lltype -> string -> llmodule -> llvalue
768                         = "llvm_declare_global"
769
770 (** [define_global name init m] returns a new global with name [name] and
771     initializer [init] in module [m]. If the named global already exists, it is
772     renamed.
773     See the constructor of [llvm::GlobalVariable]. *)
774 external define_global : string -> llvalue -> llmodule -> llvalue
775                        = "llvm_define_global"
776
777 (** [lookup_global name m] returns [Some g] if a global variable with name
778     [name] exists in module [m]. If no such global exists, returns [None].
779     See the [llvm::GlobalVariable] constructor. *)
780 external lookup_global : string -> llmodule -> llvalue option
781                        = "llvm_lookup_global"
782
783 (** [delete_global gv] destroys the global variable [gv].
784     See the method [llvm::GlobalVariable::eraseFromParent]. *)
785 external delete_global : llvalue -> unit = "llvm_delete_global"
786
787 (** [global_begin m] returns the first position in the global variable list of
788     the module [m]. [global_begin] and [global_succ] can be used to iterate
789     over the global list in order.
790     See the method [llvm::Module::global_begin]. *)
791 external global_begin : llmodule -> (llmodule, llvalue) llpos
792                       = "llvm_global_begin"
793
794 (** [global_succ gv] returns the global variable list position succeeding
795     [Before gv].
796     See the method [llvm::Module::global_iterator::operator++]. *)
797 external global_succ : llvalue -> (llmodule, llvalue) llpos
798                      = "llvm_global_succ"
799
800 (** [iter_globals f m] applies function [f] to each of the global variables of
801     module [m] in order. Tail recursive. *)
802 val iter_globals : (llvalue -> unit) -> llmodule -> unit
803
804 (** [fold_left_globals f init m] is [f (... (f init g1) ...) gN] where
805     [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
806 val fold_left_globals : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
807
808 (** [global_end m] returns the last position in the global variable list of the
809     module [m]. [global_end] and [global_pred] can be used to iterate over the
810     global list in reverse.
811     See the method [llvm::Module::global_end]. *)
812 external global_end : llmodule -> (llmodule, llvalue) llrev_pos
813                     = "llvm_global_end"
814
815 (** [global_pred gv] returns the global variable list position preceding
816     [After gv].
817     See the method [llvm::Module::global_iterator::operator--]. *)
818 external global_pred : llvalue -> (llmodule, llvalue) llrev_pos
819                      = "llvm_global_pred"
820
821 (** [rev_iter_globals f m] applies function [f] to each of the global variables
822     of module [m] in reverse order. Tail recursive. *)
823 val rev_iter_globals : (llvalue -> unit) -> llmodule -> unit
824
825 (** [fold_right_globals f m init] is [f g1 (... (f gN init) ...)] where
826     [g1,...,gN] are the global variables of module [m]. Tail recursive. *)
827 val fold_right_globals : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
828
829 (** [is_global_constant gv] returns [true] if the global variabile [gv] is a
830     constant. Returns [false] otherwise.
831     See the method [llvm::GlobalVariable::isConstant]. *)
832 external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
833
834 (** [set_global_constant c gv] sets the global variable [gv] to be a constant if
835     [c] is [true] and not if [c] is [false].
836     See the method [llvm::GlobalVariable::setConstant]. *)
837 external set_global_constant : bool -> llvalue -> unit
838                              = "llvm_set_global_constant"
839
840 (** [global_initializer gv] returns the initializer for the global variable
841     [gv]. See the method [llvm::GlobalVariable::getInitializer]. *)
842 external global_initializer : llvalue -> llvalue = "LLVMGetInitializer"
843
844 (** [set_initializer c gv] sets the initializer for the global variable
845     [gv] to the constant [c].
846     See the method [llvm::GlobalVariable::setInitializer]. *)
847 external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer"
848
849 (** [remove_initializer gv] unsets the initializer for the global variable
850     [gv].
851     See the method [llvm::GlobalVariable::setInitializer]. *)
852 external remove_initializer : llvalue -> unit = "llvm_remove_initializer"
853
854 (** [is_thread_local gv] returns [true] if the global variable [gv] is
855     thread-local and [false] otherwise.
856     See the method [llvm::GlobalVariable::isThreadLocal]. *)
857 external is_thread_local : llvalue -> bool = "llvm_is_thread_local"
858
859 (** [set_thread_local c gv] sets the global variable [gv] to be thread local if
860     [c] is [true] and not otherwise.
861     See the method [llvm::GlobalVariable::setThreadLocal]. *)
862 external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local"
863
864
865 (** {7 Operations on functions} *)
866
867 (** [declare_function name ty m] returns a new function of type [ty] and
868     with name [name] in module [m]. If such a function already exists,
869     it is returned. If the type of the existing function differs, then a bitcast
870     to [ty] is returned. *)
871 external declare_function : string -> lltype -> llmodule -> llvalue
872                           = "llvm_declare_function"
873
874 (** [define_function name ty m] creates a new function with name [name] and
875     type [ty] in module [m]. If the named function already exists, it is
876     renamed. An entry basic block is created in the function.
877     See the constructor of [llvm::GlobalVariable]. *)
878 external define_function : string -> lltype -> llmodule -> llvalue
879                          = "llvm_define_function"
880
881 (** [lookup_function name m] returns [Some f] if a function with name
882     [name] exists in module [m]. If no such function exists, returns [None].
883     See the method [llvm::Module] constructor. *)
884 external lookup_function : string -> llmodule -> llvalue option
885                          = "llvm_lookup_function"
886
887 (** [delete_function f] destroys the function [f].
888     See the method [llvm::Function::eraseFromParent]. *)
889 external delete_function : llvalue -> unit = "llvm_delete_function"
890
891 (** [function_begin m] returns the first position in the function list of the
892     module [m]. [function_begin] and [function_succ] can be used to iterate over
893     the function list in order.
894     See the method [llvm::Module::begin]. *)
895 external function_begin : llmodule -> (llmodule, llvalue) llpos
896                         = "llvm_function_begin"
897
898 (** [function_succ gv] returns the function list position succeeding
899     [Before gv].
900     See the method [llvm::Module::iterator::operator++]. *)
901 external function_succ : llvalue -> (llmodule, llvalue) llpos
902                        = "llvm_function_succ"
903
904 (** [iter_functions f m] applies function [f] to each of the functions of module
905     [m] in order. Tail recursive. *)
906 val iter_functions : (llvalue -> unit) -> llmodule -> unit
907
908 (** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
909     [f1,...,fN] are the functions of module [m]. Tail recursive. *)
910 val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
911
912 (** [function_end m] returns the last position in the function list of
913     the module [m]. [function_end] and [function_pred] can be used to iterate
914     over the function list in reverse.
915     See the method [llvm::Module::end]. *)
916 external function_end : llmodule -> (llmodule, llvalue) llrev_pos
917                       = "llvm_function_end"
918
919 (** [function_pred gv] returns the function list position preceding [After gv].
920     See the method [llvm::Module::iterator::operator--]. *)
921 external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
922                        = "llvm_function_pred"
923
924 (** [rev_iter_functions f fn] applies function [f] to each of the functions of
925     module [m] in reverse order. Tail recursive. *)
926 val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
927
928 (** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
929     [f1,...,fN] are the functions of module [m]. Tail recursive. *)
930 val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
931
932 (** [is_intrinsic f] returns true if the function [f] is an intrinsic.
933     See the method [llvm::Function::isIntrinsic]. *)
934 external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
935
936 (** [function_call_conv f] returns the calling convention of the function [f].
937     See the method [llvm::Function::getCallingConv]. *)
938 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
939
940 (** [set_function_call_conv cc f] sets the calling convention of the function
941     [f] to the calling convention numbered [cc].
942     See the method [llvm::Function::setCallingConv]. *)
943 external set_function_call_conv : int -> llvalue -> unit
944                                 = "llvm_set_function_call_conv"
945
946 (** [gc f] returns [Some name] if the function [f] has a garbage
947     collection algorithm specified and [None] otherwise.
948     See the method [llvm::Function::getGC]. *)
949 external gc : llvalue -> string option = "llvm_gc"
950
951 (** [set_gc gc f] sets the collection algorithm for the function [f] to
952     [gc]. See the method [llvm::Function::setGC]. *)
953 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
954
955 (** [add_function_attr f a] adds attribute [a] to the return type of function
956     [f]. *)
957 external add_function_attr : llvalue -> Attribute.t -> unit
958                            = "llvm_add_function_attr"
959
960 (** [remove_function_attr f a] removes attribute [a] from the return type of
961     function [f]. *)
962 external remove_function_attr : llvalue -> Attribute.t -> unit
963                               = "llvm_remove_function_attr"
964
965 (** {7 Operations on params} *)
966
967 (** [params f] returns the parameters of function [f].
968     See the method [llvm::Function::getArgumentList]. *)
969 external params : llvalue -> llvalue array = "llvm_params"
970
971 (** [param f n] returns the [n]th parameter of function [f].
972     See the method [llvm::Function::getArgumentList]. *)
973 external param : llvalue -> int -> llvalue = "llvm_param"
974
975 (** [param_parent p] returns the parent function that owns the parameter.
976     See the method [llvm::Argument::getParent]. *)
977 external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
978
979 (** [param_begin f] returns the first position in the parameter list of the
980     function [f]. [param_begin] and [param_succ] can be used to iterate over
981     the parameter list in order.
982     See the method [llvm::Function::arg_begin]. *)
983 external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
984
985 (** [param_succ bb] returns the parameter list position succeeding
986     [Before bb].
987     See the method [llvm::Function::arg_iterator::operator++]. *)
988 external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
989
990 (** [iter_params f fn] applies function [f] to each of the parameters
991     of function [fn] in order. Tail recursive. *)
992 val iter_params : (llvalue -> unit) -> llvalue -> unit
993
994 (** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
995     [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
996 val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
997
998 (** [param_end f] returns the last position in the parameter list of
999     the function [f]. [param_end] and [param_pred] can be used to iterate
1000     over the parameter list in reverse.
1001     See the method [llvm::Function::arg_end]. *)
1002 external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
1003
1004 (** [param_pred gv] returns the function list position preceding [After gv].
1005     See the method [llvm::Function::arg_iterator::operator--]. *)
1006 external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
1007                     = "llvm_param_pred"
1008
1009 (** [rev_iter_params f fn] applies function [f] to each of the parameters
1010     of function [fn] in reverse order. Tail recursive. *)
1011 val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
1012
1013 (** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
1014     [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
1015 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
1016
1017 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1018 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1019
1020 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1021 external remove_param_attr : llvalue -> Attribute.t -> unit
1022                            = "llvm_remove_param_attr"
1023
1024 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1025 external set_param_alignment : llvalue -> int -> unit
1026                              = "llvm_set_param_alignment"
1027
1028 (** {7 Operations on basic blocks} *)
1029
1030 (** [basic_blocks fn] returns the basic blocks of the function [f].
1031     See the method [llvm::Function::getBasicBlockList]. *)
1032 external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
1033
1034 (** [entry_block fn] returns the entry basic block of the function [f].
1035     See the method [llvm::Function::getEntryBlock]. *)
1036 external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
1037
1038 (** [delete_block bb] deletes the basic block [bb].
1039     See the method [llvm::BasicBlock::eraseFromParent]. *)
1040 external delete_block : llbasicblock -> unit = "llvm_delete_block"
1041
1042 (** [append_block name f] creates a new basic block named [name] at the end of
1043     function [f].
1044     See the constructor of [llvm::BasicBlock]. *)
1045 external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
1046
1047 (** [insert_block name bb] creates a new basic block named [name] before the
1048     basic block [bb].
1049     See the constructor of [llvm::BasicBlock]. *)
1050 external insert_block : string -> llbasicblock -> llbasicblock
1051                       = "llvm_insert_block"
1052
1053 (** [block_parent bb] returns the parent function that owns the basic block.
1054     See the method [llvm::BasicBlock::getParent]. *)
1055 external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
1056
1057 (** [block_begin f] returns the first position in the basic block list of the
1058     function [f]. [block_begin] and [block_succ] can be used to iterate over
1059     the basic block list in order.
1060     See the method [llvm::Function::begin]. *)
1061 external block_begin : llvalue -> (llvalue, llbasicblock) llpos
1062                      = "llvm_block_begin"
1063
1064 (** [block_succ bb] returns the basic block list position succeeding
1065     [Before bb].
1066     See the method [llvm::Function::iterator::operator++]. *)
1067 external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
1068                     = "llvm_block_succ"
1069
1070 (** [iter_blocks f fn] applies function [f] to each of the basic blocks
1071     of function [fn] in order. Tail recursive. *)
1072 val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1073
1074 (** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
1075     [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1076 val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
1077
1078 (** [block_end f] returns the last position in the basic block list of
1079     the function [f]. [block_end] and [block_pred] can be used to iterate
1080     over the basic block list in reverse.
1081     See the method [llvm::Function::end]. *)
1082 external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
1083                    = "llvm_block_end"
1084
1085 (** [block_pred gv] returns the function list position preceding [After gv].
1086     See the method [llvm::Function::iterator::operator--]. *)
1087 external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
1088                     = "llvm_block_pred"
1089
1090 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
1091     of function [fn] in reverse order. Tail recursive. *)
1092 val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
1093
1094 (** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
1095     [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
1096 val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
1097
1098 (** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
1099 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
1100
1101 (** [value_is_block v] returns [true] if the value [v] is a basic block and
1102     [false] otherwise.
1103     Similar to [llvm::isa<BasicBlock>]. *)
1104 external value_is_block : llvalue -> bool = "llvm_value_is_block"
1105
1106 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
1107 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
1108
1109
1110 (** {7 Operations on instructions} *)
1111
1112 (** [instr_parent i] is the enclosing basic block of the instruction [i].
1113     See the method [llvm::Instruction::getParent]. *)
1114 external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
1115
1116 (** [instr_begin bb] returns the first position in the instruction list of the
1117     basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
1118     the instruction list in order.
1119     See the method [llvm::BasicBlock::begin]. *)
1120 external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos
1121                      = "llvm_instr_begin"
1122
1123 (** [instr_succ i] returns the instruction list position succeeding [Before i].
1124     See the method [llvm::BasicBlock::iterator::operator++]. *)
1125 external instr_succ : llvalue -> (llbasicblock, llvalue) llpos
1126                      = "llvm_instr_succ"
1127
1128 (** [iter_instrs f bb] applies function [f] to each of the instructions of basic
1129     block [bb] in order. Tail recursive. *)
1130 val iter_instrs: (llvalue -> unit) -> llbasicblock -> unit
1131
1132 (** [fold_left_instrs f init bb] is [f (... (f init g1) ...) gN] where
1133     [g1,...,gN] are the instructions of basic block [bb]. Tail recursive. *)
1134 val fold_left_instrs: ('a -> llvalue -> 'a) -> 'a -> llbasicblock -> 'a
1135
1136 (** [instr_end bb] returns the last position in the instruction list of the
1137     basic block [bb]. [instr_end] and [instr_pred] can be used to iterate over
1138     the instruction list in reverse.
1139     See the method [llvm::BasicBlock::end]. *)
1140 external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos
1141                      = "llvm_instr_end"
1142
1143 (** [instr_pred i] returns the instruction list position preceding [After i].
1144     See the method [llvm::BasicBlock::iterator::operator--]. *)
1145 external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
1146                      = "llvm_instr_pred"
1147
1148 (** [fold_right_instrs f bb init] is [f (... (f init fN) ...) f1] where
1149     [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
1150 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
1151
1152
1153 (** {7 Operations on call sites} *)
1154
1155 (** [instruction_call_conv ci] is the calling convention for the call or invoke
1156     instruction [ci], which may be one of the values from the module
1157     {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
1158     [llvm::InvokeInst::getCallingConv]. *)
1159 external instruction_call_conv: llvalue -> int
1160                               = "llvm_instruction_call_conv"
1161
1162 (** [set_instruction_call_conv cc ci] sets the calling convention for the call
1163     or invoke instruction [ci] to the integer [cc], which can be one of the
1164     values from the module {!CallConv}.
1165     See the method [llvm::CallInst::setCallingConv]
1166     and [llvm::InvokeInst::setCallingConv]. *)
1167 external set_instruction_call_conv: int -> llvalue -> unit
1168                                   = "llvm_set_instruction_call_conv"
1169
1170 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1171     parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1172     value. *)
1173 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1174   = "llvm_add_instruction_param_attr"
1175
1176 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1177     [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1178     return value. *)
1179 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1180   = "llvm_remove_instruction_param_attr"
1181
1182 (** {Operations on call instructions (only)} *)
1183
1184 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
1185     eligible for tail call optimization, [false] otherwise.
1186     See the method [llvm::CallInst::isTailCall]. *)
1187 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
1188
1189 (** [set_tail_call tc ci] flags the call instruction [ci] as eligible for tail
1190     call optimization if [tc] is [true], clears otherwise.
1191     See the method [llvm::CallInst::setTailCall]. *)
1192 external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call"
1193
1194 (** {7 Operations on phi nodes} *)
1195
1196 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
1197     with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
1198 external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
1199                       = "llvm_add_incoming"
1200
1201 (** [incoming pn] returns the list of value-block pairs for phi node [pn].
1202     See the method [llvm::PHINode::getIncomingValue]. *)
1203 external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
1204
1205
1206
1207 (** {6 Instruction builders} *)
1208
1209 (** [builder ()] creates an instruction builder with no position. It is invalid
1210     to use this builder until its position is set with {!position_before} or
1211     {!position_at_end}. See the constructor for [llvm::LLVMBuilder]. *)
1212 external builder : unit -> llbuilder = "llvm_builder"
1213
1214 (** [builder_at ip] creates an instruction builder positioned at [ip].
1215     See the constructor for [llvm::LLVMBuilder]. *)
1216 val builder_at : (llbasicblock, llvalue) llpos -> llbuilder
1217
1218 (** [builder_before ins] creates an instruction builder positioned before the
1219     instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
1220 val builder_before : llvalue -> llbuilder
1221
1222 (** [builder_at_end bb] creates an instruction builder positioned at the end of
1223     the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
1224 val builder_at_end : llbasicblock -> llbuilder
1225
1226 (** [position_builder ip bb] moves the instruction builder [bb] to the position
1227     [ip].
1228     See the constructor for [llvm::LLVMBuilder]. *)
1229 external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
1230                           = "llvm_position_builder"
1231
1232 (** [position_before ins b] moves the instruction builder [b] to before the
1233     instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1234 val position_before : llvalue -> llbuilder -> unit
1235
1236 (** [position_at_end bb b] moves the instruction builder [b] to the end of the
1237     basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1238 val position_at_end : llbasicblock -> llbuilder -> unit
1239
1240 (** [insertion_block b] returns the basic block that the builder [b] is
1241     positioned to insert into. Raises [Not_Found] if the instruction builder is
1242     uninitialized.
1243     See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
1244 external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
1245
1246
1247 (** {7 Terminators} *)
1248
1249 (** [build_ret_void b] creates a
1250     [ret void]
1251     instruction at the position specified by the instruction builder [b].
1252     See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
1253 external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
1254
1255 (** [build_ret v b] creates a
1256     [ret %v]
1257     instruction at the position specified by the instruction builder [b].
1258     See the method [llvm::LLVMBuilder::CreateRet]. *)
1259 external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
1260
1261 (** [build_br bb b] creates a
1262     [b %bb]
1263     instruction at the position specified by the instruction builder [b].
1264     See the method [llvm::LLVMBuilder::CreateBr]. *)
1265 external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
1266
1267 (** [build_cond_br cond tbb fbb b] creates a
1268     [b %cond, %tbb, %fbb]
1269     instruction at the position specified by the instruction builder [b].
1270     See the method [llvm::LLVMBuilder::CreateCondBr]. *)
1271 external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
1272                          llvalue = "llvm_build_cond_br"
1273
1274 (** [build_switch case elsebb count b] creates an empty
1275     [switch %case, %elsebb]
1276     instruction at the position specified by the instruction builder [b] with
1277     space reserved for [count] cases.
1278     See the method [llvm::LLVMBuilder::CreateSwitch]. *)
1279 external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
1280                       = "llvm_build_switch"
1281
1282 (** [add_case sw onval bb] causes switch instruction [sw] to branch to [bb]
1283     when its input matches the constant [onval].
1284     See the method [llvm::SwitchInst::addCase]. **)
1285 external add_case : llvalue -> llvalue -> llbasicblock -> unit
1286                   = "llvm_add_case"
1287
1288 (** [build_invoke fn args tobb unwindbb name b] creates an
1289     [%name = invoke %fn(args) to %tobb unwind %unwindbb]
1290     instruction at the position specified by the instruction builder [b].
1291     See the method [llvm::LLVMBuilder::CreateInvoke]. *)
1292 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
1293                         llbasicblock -> string -> llbuilder -> llvalue
1294                       = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
1295
1296 (** [build_unwind b] creates an
1297     [unwind]
1298     instruction at the position specified by the instruction builder [b].
1299     See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1300 external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
1301
1302 (** [build_unreachable b] creates an
1303     [unreachable]
1304     instruction at the position specified by the instruction builder [b].
1305     See the method [llvm::LLVMBuilder::CreateUnwind]. *)
1306 external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
1307
1308
1309 (** {7 Arithmetic} *)
1310
1311 (** [build_add x y name b] creates a
1312     [%name = add %x, %y]
1313     instruction at the position specified by the instruction builder [b].
1314     See the method [llvm::LLVMBuilder::CreateAdd]. *)
1315 external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
1316                    = "llvm_build_add"
1317
1318 (** [build_sub x y name b] creates a
1319     [%name = sub %x, %y]
1320     instruction at the position specified by the instruction builder [b].
1321     See the method [llvm::LLVMBuilder::CreateSub]. *)
1322 external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
1323                    = "llvm_build_sub"
1324
1325 (** [build_mul x y name b] creates a
1326     [%name = mul %x, %y]
1327     instruction at the position specified by the instruction builder [b].
1328     See the method [llvm::LLVMBuilder::CreateMul]. *)
1329 external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
1330                    = "llvm_build_mul"
1331
1332 (** [build_udiv x y name b] creates a
1333     [%name = udiv %x, %y]
1334     instruction at the position specified by the instruction builder [b].
1335     See the method [llvm::LLVMBuilder::CreateUDiv]. *)
1336 external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1337                     = "llvm_build_udiv"
1338
1339 (** [build_sdiv x y name b] creates a
1340     [%name = sdiv %x, %y]
1341     instruction at the position specified by the instruction builder [b].
1342     See the method [llvm::LLVMBuilder::CreateSDiv]. *)
1343 external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1344                     = "llvm_build_sdiv"
1345
1346 (** [build_fdiv x y name b] creates a
1347     [%name = fdiv %x, %y]
1348     instruction at the position specified by the instruction builder [b].
1349     See the method [llvm::LLVMBuilder::CreateFDiv]. *)
1350 external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
1351                     = "llvm_build_fdiv"
1352
1353 (** [build_urem x y name b] creates a
1354     [%name = urem %x, %y]
1355     instruction at the position specified by the instruction builder [b].
1356     See the method [llvm::LLVMBuilder::CreateURem]. *)
1357 external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1358                     = "llvm_build_urem"
1359
1360 (** [build_SRem x y name b] creates a
1361     [%name = srem %x, %y]
1362     instruction at the position specified by the instruction builder [b].
1363     See the method [llvm::LLVMBuilder::CreateSRem]. *)
1364 external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1365                     = "llvm_build_srem"
1366
1367 (** [build_frem x y name b] creates a
1368     [%name = frem %x, %y]
1369     instruction at the position specified by the instruction builder [b].
1370     See the method [llvm::LLVMBuilder::CreateFRem]. *)
1371 external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
1372                     = "llvm_build_frem"
1373
1374 (** [build_shl x y name b] creates a
1375     [%name = shl %x, %y]
1376     instruction at the position specified by the instruction builder [b].
1377     See the method [llvm::LLVMBuilder::CreateShl]. *)
1378 external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
1379                    = "llvm_build_shl"
1380
1381 (** [build_lshr x y name b] creates a
1382     [%name = lshr %x, %y]
1383     instruction at the position specified by the instruction builder [b].
1384     See the method [llvm::LLVMBuilder::CreateLShr]. *)
1385 external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1386                     = "llvm_build_lshr"
1387
1388 (** [build_ashr x y name b] creates a
1389     [%name = ashr %x, %y]
1390     instruction at the position specified by the instruction builder [b].
1391     See the method [llvm::LLVMBuilder::CreateAShr]. *)
1392 external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
1393                     = "llvm_build_ashr"
1394
1395 (** [build_and x y name b] creates a
1396     [%name = and %x, %y]
1397     instruction at the position specified by the instruction builder [b].
1398     See the method [llvm::LLVMBuilder::CreateAnd]. *)
1399 external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
1400                    = "llvm_build_and"
1401
1402 (** [build_or x y name b] creates a
1403     [%name = or %x, %y]
1404     instruction at the position specified by the instruction builder [b].
1405     See the method [llvm::LLVMBuilder::CreateOr]. *)
1406 external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
1407                   = "llvm_build_or"
1408
1409 (** [build_xor x y name b] creates a
1410     [%name = xor %x, %y]
1411     instruction at the position specified by the instruction builder [b].
1412     See the method [llvm::LLVMBuilder::CreateXor]. *)
1413 external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
1414                    = "llvm_build_xor"
1415
1416 (** [build_neg x name b] creates a
1417     [%name = sub 0, %x]
1418     instruction at the position specified by the instruction builder [b].
1419     [-0.0] is used for floating point types to compute the correct sign.
1420     See the method [llvm::LLVMBuilder::CreateNeg]. *)
1421 external build_neg : llvalue -> string -> llbuilder -> llvalue
1422                    = "llvm_build_neg"
1423
1424 (** [build_xor x name b] creates a
1425     [%name = xor %x, -1]
1426     instruction at the position specified by the instruction builder [b].
1427     [-1] is the correct "all ones" value for the type of [x].
1428     See the method [llvm::LLVMBuilder::CreateXor]. *)
1429 external build_not : llvalue -> string -> llbuilder -> llvalue
1430                    = "llvm_build_not"
1431
1432
1433 (** {7 Memory} *)
1434
1435 (** [build_malloc ty name b] creates a
1436     [%name = malloc %ty]
1437     instruction at the position specified by the instruction builder [b].
1438     See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1439 external build_malloc : lltype -> string -> llbuilder -> llvalue
1440                       = "llvm_build_malloc"
1441
1442 (** [build_array_malloc ty n name b] creates a
1443     [%name = malloc %ty, %n]
1444     instruction at the position specified by the instruction builder [b].
1445     See the method [llvm::LLVMBuilder::CreateMalloc]. *)
1446 external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
1447                               llvalue = "llvm_build_array_malloc"
1448
1449 (** [build_alloca ty name b] creates a
1450     [%name = alloca %ty]
1451     instruction at the position specified by the instruction builder [b].
1452     See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1453 external build_alloca : lltype -> string -> llbuilder -> llvalue
1454                       = "llvm_build_alloca"
1455
1456 (** [build_array_alloca ty n name b] creates a
1457     [%name = alloca %ty, %n]
1458     instruction at the position specified by the instruction builder [b].
1459     See the method [llvm::LLVMBuilder::CreateAlloca]. *)
1460 external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
1461                               llvalue = "llvm_build_array_alloca"
1462
1463 (** [build_free v b] creates a
1464     [free %v]
1465     instruction at the position specified by the instruction builder [b].
1466     See the method [llvm::LLVMBuilder::CreateFree]. *)
1467 external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
1468
1469 (** [build_load v name b] creates a
1470     [%name = load %v]
1471     instruction at the position specified by the instruction builder [b].
1472     See the method [llvm::LLVMBuilder::CreateLoad]. *)
1473 external build_load : llvalue -> string -> llbuilder -> llvalue
1474                     = "llvm_build_load"
1475
1476 (** [build_store v p b] creates a
1477     [store %v, %p]
1478     instruction at the position specified by the instruction builder [b].
1479     See the method [llvm::LLVMBuilder::CreateStore]. *)
1480 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
1481                      = "llvm_build_store"
1482
1483 (** [build_gep p indices name b] creates a
1484     [%name = gep %p, indices...]
1485     instruction at the position specified by the instruction builder [b].
1486     See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
1487 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1488                    = "llvm_build_gep"
1489
1490
1491 (** {7 Casts} *)
1492
1493 (** [build_trunc v ty name b] creates a
1494     [%name = trunc %p to %ty]
1495     instruction at the position specified by the instruction builder [b].
1496     See the method [llvm::LLVMBuilder::CreateTrunc]. *)
1497 external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1498                      = "llvm_build_trunc"
1499
1500 (** [build_zext v ty name b] creates a
1501     [%name = zext %p to %ty]
1502     instruction at the position specified by the instruction builder [b].
1503     See the method [llvm::LLVMBuilder::CreateZExt]. *)
1504 external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
1505                     = "llvm_build_zext"
1506
1507 (** [build_sext v ty name b] creates a
1508     [%name = sext %p to %ty]
1509     instruction at the position specified by the instruction builder [b].
1510     See the method [llvm::LLVMBuilder::CreateSExt]. *)
1511 external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
1512                     = "llvm_build_sext"
1513
1514 (** [build_fptoui v ty name b] creates a
1515     [%name = fptoui %p to %ty]
1516     instruction at the position specified by the instruction builder [b].
1517     See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
1518 external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
1519                       = "llvm_build_fptoui"
1520
1521 (** [build_fptosi v ty name b] creates a
1522     [%name = fptosi %p to %ty]
1523     instruction at the position specified by the instruction builder [b].
1524     See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
1525 external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
1526                       = "llvm_build_fptosi"
1527
1528 (** [build_uitofp v ty name b] creates a
1529     [%name = uitofp %p to %ty]
1530     instruction at the position specified by the instruction builder [b].
1531     See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
1532 external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1533                       = "llvm_build_uitofp"
1534
1535 (** [build_sitofp v ty name b] creates a
1536     [%name = sitofp %p to %ty]
1537     instruction at the position specified by the instruction builder [b].
1538     See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
1539 external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
1540                       = "llvm_build_sitofp"
1541
1542 (** [build_fptrunc v ty name b] creates a
1543     [%name = fptrunc %p to %ty]
1544     instruction at the position specified by the instruction builder [b].
1545     See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
1546 external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
1547                        = "llvm_build_fptrunc"
1548
1549 (** [build_fpext v ty name b] creates a
1550     [%name = fpext %p to %ty]
1551     instruction at the position specified by the instruction builder [b].
1552     See the method [llvm::LLVMBuilder::CreateFPExt]. *)
1553 external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
1554                      = "llvm_build_fpext"
1555
1556 (** [build_ptrtoint v ty name b] creates a
1557     [%name = prtotint %p to %ty]
1558     instruction at the position specified by the instruction builder [b].
1559     See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
1560 external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
1561                         = "llvm_build_prttoint"
1562
1563 (** [build_inttoptr v ty name b] creates a
1564     [%name = inttoptr %p to %ty]
1565     instruction at the position specified by the instruction builder [b].
1566     See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
1567 external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
1568                         = "llvm_build_inttoptr"
1569
1570 (** [build_bitcast v ty name b] creates a
1571     [%name = bitcast %p to %ty]
1572     instruction at the position specified by the instruction builder [b].
1573     See the method [llvm::LLVMBuilder::CreateBitcast]. *)
1574 external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
1575                        = "llvm_build_bitcast"
1576
1577
1578 (** {7 Comparisons} *)
1579
1580 (** [build_icmp pred x y name b] creates a
1581     [%name = icmp %pred %x, %y]
1582     instruction at the position specified by the instruction builder [b].
1583     See the method [llvm::LLVMBuilder::CreateICmp]. *)
1584 external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
1585                       llbuilder -> llvalue = "llvm_build_icmp"
1586
1587 (** [build_fcmp pred x y name b] creates a
1588     [%name = fcmp %pred %x, %y]
1589     instruction at the position specified by the instruction builder [b].
1590     See the method [llvm::LLVMBuilder::CreateFCmp]. *)
1591 external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
1592                       llbuilder -> llvalue = "llvm_build_fcmp"
1593
1594
1595 (** {7 Miscellaneous instructions} *)
1596
1597 (** [build_phi incoming name b] creates a
1598     [%name = phi %incoming]
1599     instruction at the position specified by the instruction builder [b].
1600     [incoming] is a list of [(llvalue, llbasicblock)] tuples.
1601     See the method [llvm::LLVMBuilder::CreatePHI]. *)
1602 external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
1603                      llvalue = "llvm_build_phi"
1604
1605 (** [build_call fn args name b] creates a
1606     [%name = call %fn(args...)]
1607     instruction at the position specified by the instruction builder [b].
1608     See the method [llvm::LLVMBuilder::CreateCall]. *)
1609 external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
1610                     = "llvm_build_call"
1611
1612 (** [build_select cond thenv elsev name b] creates a
1613     [%name = select %cond, %thenv, %elsev]
1614     instruction at the position specified by the instruction builder [b].
1615     See the method [llvm::LLVMBuilder::CreateSelect]. *)
1616 external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
1617                         llvalue = "llvm_build_select"
1618
1619 (** [build_va_arg valist argty name b] creates a
1620     [%name = va_arg %valist, %argty]
1621     instruction at the position specified by the instruction builder [b].
1622     See the method [llvm::LLVMBuilder::CreateVAArg]. *)
1623 external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
1624                       = "llvm_build_va_arg"
1625
1626 (** [build_extractelement vec i name b] creates a
1627     [%name = extractelement %vec, %i]
1628     instruction at the position specified by the instruction builder [b].
1629     See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
1630 external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
1631                                 llvalue = "llvm_build_extractelement"
1632
1633 (** [build_insertelement vec elt i name b] creates a
1634     [%name = insertelement %vec, %elt, %i]
1635     instruction at the position specified by the instruction builder [b].
1636     See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
1637 external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
1638                                llbuilder -> llvalue = "llvm_build_insertelement"
1639
1640 (** [build_shufflevector veca vecb mask name b] creates a
1641     [%name = shufflevector %veca, %vecb, %mask]
1642     instruction at the position specified by the instruction builder [b].
1643     See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
1644 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
1645                                llbuilder -> llvalue = "llvm_build_shufflevector"
1646
1647
1648 (** {6 Module providers} *)
1649
1650 module ModuleProvider : sig
1651   (** [create_module_provider m] encapsulates [m] in a module provider and takes
1652       ownership of the module. See the constructor
1653       [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
1654   external create : llmodule -> llmoduleprovider
1655                   = "LLVMCreateModuleProviderForExistingModule"
1656   
1657   (** [dispose_module_provider mp] destroys the module provider [mp] as well as
1658       the contained module. *)
1659   external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
1660 end
1661
1662
1663 (** {6 Memory buffers} *)
1664
1665 module MemoryBuffer : sig
1666   (** [of_file p] is the memory buffer containing the contents of the file at
1667       path [p]. If the file could not be read, then [IoError msg] is
1668       raised. *)
1669   external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
1670   
1671   (** [stdin ()] is the memory buffer containing the contents of standard input.
1672       If standard input is empty, then [IoError msg] is raised. *)
1673   external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
1674   
1675   (** Disposes of a memory buffer. *)
1676   external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
1677 end
1678
1679
1680 (** {6 Pass Managers} *)
1681
1682 module PassManager : sig
1683   (**  *)
1684   type 'a t
1685   type any = [ `Module | `Function ]
1686   
1687   (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
1688       type of pipeline is suitable for link-time optimization and whole-module
1689       transformations.
1690       See the constructor of [llvm::PassManager]. *)
1691   external create : unit -> [ `Module ] t = "llvm_passmanager_create"
1692   
1693   (** [PassManager.create_function mp] constructs a new function-by-function
1694       pass pipeline over the module provider [mp]. It does not take ownership of
1695       [mp]. This type of pipeline is suitable for code generation and JIT
1696       compilation tasks.
1697       See the constructor of [llvm::FunctionPassManager]. *)
1698   external create_function : llmoduleprovider -> [ `Function ] t
1699                            = "LLVMCreateFunctionPassManager"
1700   
1701   (** [run_module m pm] initializes, executes on the module [m], and finalizes
1702       all of the passes scheduled in the pass manager [pm]. Returns [true] if
1703       any of the passes modified the module, [false] otherwise.
1704       See the [llvm::PassManager::run] method. *)
1705   external run_module : llmodule -> [ `Module ] t -> bool
1706                       = "llvm_passmanager_run_module"
1707   
1708   (** [initialize fpm] initializes all of the function passes scheduled in the
1709       function pass manager [fpm]. Returns [true] if any of the passes modified
1710       the module, [false] otherwise.
1711       See the [llvm::FunctionPassManager::doInitialization] method. *)
1712   external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
1713   
1714   (** [run_function f fpm] executes all of the function passes scheduled in the
1715       function pass manager [fpm] over the function [f]. Returns [true] if any
1716       of the passes modified [f], [false] otherwise.
1717       See the [llvm::FunctionPassManager::run] method. *)
1718   external run_function : llvalue -> [ `Function ] t -> bool
1719                         = "llvm_passmanager_run_function"
1720   
1721   (** [finalize fpm] finalizes all of the function passes scheduled in in the
1722       function pass manager [fpm]. Returns [true] if any of the passes
1723       modified the module, [false] otherwise.
1724       See the [llvm::FunctionPassManager::doFinalization] method. *)
1725   external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
1726   
1727   (** Frees the memory of a pass pipeline. For function pipelines, does not free
1728       the module provider.
1729       See the destructor of [llvm::BasePassManager]. *)
1730   external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"
1731 end