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