[OCaml] Documentation
[oota-llvm.git] / bindings / ocaml / llvm / llvm.mli
index c2e83788091289dad0953f74ae2986d881e1bf01..8d08c0a83b4ba48a064df8e8ee2ada114530eae8 100644 (file)
@@ -67,6 +67,7 @@ module TypeKind : sig
   | Pointer
   | Vector
   | Metadata
+  | X86_mmx
 end
 
 (** The linkage of a global value, accessed with {!linkage} and
@@ -77,6 +78,7 @@ module Linkage : sig
   | Available_externally
   | Link_once
   | Link_once_odr
+  | Link_once_odr_auto_hide
   | Weak
   | Weak_odr
   | Appending
@@ -88,6 +90,7 @@ module Linkage : sig
   | Ghost
   | Common
   | Linker_private
+  | Linker_private_weak
 end
 
 (** The linker visibility of a global value, accessed with {!visibility} and
@@ -115,6 +118,8 @@ module CallConv : sig
                               convention from C. *)
 end
 
+(** The attribute kind of a function parameter, result or the function itself.
+    See [llvm::Attribute::AttrKind]. *)
 module Attribute : sig
   type t =
   | Zext
@@ -252,7 +257,57 @@ module Opcode : sig
   | AtomicRMW
   | Resume
   | LandingPad
-  | Unwind
+end
+
+(** The type of a clause of a [landingpad] instruction.
+    See [llvm::LandingPadInst::ClauseType]. *)
+module LandingPadClauseTy : sig
+  type t =
+  | Catch
+  | Filter
+end
+
+(** The thread local mode of a global value, accessed with {!thread_local_mode}
+    and {!set_thread_local_mode}.
+    See [llvm::GlobalVariable::ThreadLocalMode]. *)
+module ThreadLocalMode : sig
+  type t =
+  | None
+  | GeneralDynamic
+  | LocalDynamic
+  | InitialExec
+  | LocalExec
+end
+
+(** The ordering of an atomic [load], [store], [cmpxchg], [atomicrmw] or
+    [fence] instruction. See [llvm::AtomicOrdering]. *)
+module AtomicOrdering : sig
+  type t =
+  | NotAtomic
+  | Unordered
+  | Monotonic
+  | Invalid (* removed due to API changes *)
+  | Acquire
+  | Release
+  | AcqiureRelease
+  | SequentiallyConsistent
+end
+
+(** The opcode of an [atomicrmw] instruction.
+    See [llvm::AtomicRMWInst::BinOp]. *)
+module AtomicRMWBinOp : sig
+  type t =
+  | Xchg
+  | Add
+  | Sub
+  | And
+  | Nand
+  | Or
+  | Xor
+  | Max
+  | Min
+  | UMax
+  | UMin
 end
 
 (** The kind of an [llvalue], the result of [classify_value v].
@@ -358,6 +413,14 @@ val set_data_layout: string -> llmodule -> unit
     error. See the method [llvm::Module::dump]. *)
 val dump_module : llmodule -> unit
 
+(** [print_module f m] prints the .ll representation of the module [m]
+    to file [f]. See the method [llvm::Module::print]. *)
+val print_module : string -> llmodule -> unit
+
+(** [string_of_llmodule m] returns the .ll representation of the module [m]
+    as a string. See the method [llvm::Module::print]. *)
+val string_of_llmodule : llmodule -> string
+
 (** [set_module_inline_asm m asm] sets the inline assembler for the module. See
     the method [llvm::Module::setModuleInlineAsm]. *)
 val set_module_inline_asm : llmodule -> string -> unit
@@ -382,6 +445,10 @@ val type_is_sized : lltype -> bool
     See the method [llvm::Type::getContext]. *)
 val type_context : lltype -> llcontext
 
+(** [dump_type ty] prints the .ll representation of the type [ty] to standard
+    error. See the method [llvm::Type::dump]. *)
+val dump_type : lltype -> unit
+
 (** [string_of_lltype ty] returns a string describing the type [ty]. *)
 val string_of_lltype : lltype -> string
 
@@ -552,6 +619,10 @@ val void_type : llcontext -> lltype
     [llvm::Type::LabelTy]. *)
 val label_type : llcontext -> lltype
 
+(** [x86_mmx_type c] returns the x86 64-bit MMX register type in the
+    context [c]. See [llvm::Type::X86_MMXTy]. *)
+val x86_mmx_type : llcontext -> lltype
+
 (** [type_by_name m name] returns the specified type from the current module
     if it exists.
     See the method [llvm::Module::getTypeByName] *)
@@ -564,6 +635,7 @@ val type_by_name : llmodule -> string -> lltype option
     See the method [llvm::Value::getType]. *)
 val type_of : llvalue -> lltype
 
+(** [classify_value v] returns the kind of the value [v]. *)
 val classify_value : llvalue -> ValueKind.t
 
 (** [value_name v] returns the name of the value [v]. For global values, this is
@@ -663,6 +735,8 @@ val is_null : llvalue -> bool
     otherwise. Similar to [llvm::isa<UndefValue>]. *)
 val is_undef : llvalue -> bool
 
+(** [constexpr_opcode v] returns an [Opcode.t] corresponding to constexpr
+    value [v], or [Opcode.Invalid] if [v] is not a constexpr. *)
 val constexpr_opcode : llvalue -> Opcode.t
 
 
@@ -702,11 +776,18 @@ val mdnode : llcontext -> llvalue array -> llvalue
     See the method [llvm::MDString::getString] *)
 val get_mdstring : llvalue -> string option
 
-(** [get_named_metadata m name] return all the MDNodes belonging to the named
+(** [get_named_metadata m name] returns all the MDNodes belonging to the named
     metadata (if any).
     See the method [llvm::NamedMDNode::getOperand]. *)
 val get_named_metadata : llmodule -> string -> llvalue array
 
+(** [add_named_metadata_operand m name v] adds [v] as the last operand of
+    metadata named [name] in module [m]. If the metadata does not exist,
+    it is created.
+    See the methods [llvm::Module::getNamedMetadata()] and
+    [llvm::MDNode::addOperand()]. *)
+val add_named_metadata_operand : llmodule -> string -> llvalue -> unit
+
 
 (** {7 Operations on scalar constants} *)
 
@@ -1243,6 +1324,26 @@ val is_thread_local : llvalue -> bool
     See the method [llvm::GlobalVariable::setThreadLocal]. *)
 val set_thread_local : bool -> llvalue -> unit
 
+(** [is_thread_local gv] returns the thread local mode of the global
+    variable [gv].
+    See the method [llvm::GlobalVariable::getThreadLocalMode]. *)
+val thread_local_mode : llvalue -> ThreadLocalMode.t
+
+(** [set_thread_local c gv] sets the thread local mode of the global
+    variable [gv].
+    See the method [llvm::GlobalVariable::setThreadLocalMode]. *)
+val set_thread_local_mode : ThreadLocalMode.t -> llvalue -> unit
+
+(** [is_externally_initialized gv] returns [true] if the global
+    variable [gv] is externally initialized and [false] otherwise.
+    See the method [llvm::GlobalVariable::isExternallyInitialized]. *)
+val is_externally_initialized : llvalue -> bool
+
+(** [set_externally_initialized c gv] sets the global variable [gv] to be
+    externally initialized if [c] is [true] and not otherwise.
+    See the method [llvm::GlobalVariable::setExternallyInitialized]. *)
+val set_externally_initialized : bool -> llvalue -> unit
+
 
 (** {7 Operations on aliases} *)
 
@@ -1338,6 +1439,10 @@ val set_gc : string option -> llvalue -> unit
     [f]. *)
 val add_function_attr : llvalue -> Attribute.t -> unit
 
+(** [add_target_dependent_function_attr f a] adds target-dependent attribute
+    [a] to function [f]. *)
+val add_target_dependent_function_attr : llvalue -> string -> string -> unit
+
 (** [function_attr f] returns the function attribute for the function [f].
     See the method [llvm::Function::getAttributes] *)
 val function_attr : llvalue -> Attribute.t list
@@ -1427,6 +1532,18 @@ val entry_block : llvalue -> llbasicblock
     See the method [llvm::BasicBlock::eraseFromParent]. *)
 val delete_block : llbasicblock -> unit
 
+(** [remove_block bb] removes the basic block [bb] from its parent function.
+    See the method [llvm::BasicBlock::removeFromParent]. *)
+val remove_block : llbasicblock -> unit
+
+(** [move_block_before pos bb] moves the basic block [bb] before [pos].
+    See the method [llvm::BasicBlock::moveBefore]. *)
+val move_block_before : llbasicblock -> llbasicblock -> unit
+
+(** [move_block_after pos bb] moves the basic block [bb] after [pos].
+    See the method [llvm::BasicBlock::moveAfter]. *)
+val move_block_after : llbasicblock -> llbasicblock -> unit
+
 (** [append_block c name f] creates a new basic block named [name] at the end of
     function [f] in the context [c].
     See the constructor of [llvm::BasicBlock]. *)
@@ -1466,10 +1583,11 @@ val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
     See the method [llvm::Function::end]. *)
 val block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
 
-(** [block_pred gv] returns the function list position preceding [After gv].
+(** [block_pred bb] returns the basic block list position preceding [After bb].
     See the method [llvm::Function::iterator::operator--]. *)
 val block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
 
+(** [block_terminator bb] returns the terminator of the basic block [bb]. *)
 val block_terminator : llbasicblock -> llvalue option
 
 (** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
@@ -1498,6 +1616,10 @@ val block_of_value : llvalue -> llbasicblock
     See the method [llvm::Instruction::getParent]. *)
 val instr_parent : llvalue -> llbasicblock
 
+(** [delete_instruction i] deletes the instruction [i].
+ * See the method [llvm::Instruction::eraseFromParent]. *)
+val delete_instruction : llvalue -> unit
+
 (** [instr_begin bb] returns the first position in the instruction list of the
     basic block [bb]. [instr_begin] and [instr_succ] can be used to iterate over
     the instruction list in order.
@@ -1530,8 +1652,12 @@ val instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos
     [f1,...,fN] are the instructions of basic block [bb]. Tail recursive. *)
 val fold_right_instrs: (llvalue -> 'a -> 'a) -> llbasicblock -> 'a -> 'a
 
+(** [inst_opcode i] returns the [Opcode.t] corresponding to instruction [i],
+    or [Opcode.Invalid] if [i] is not an instruction. *)
 val instr_opcode : llvalue -> Opcode.t
 
+(** [icmp_predicate i] returns the [Icmp.t] corresponding to an [icmp]
+    instruction [i]. *)
 val icmp_predicate : llvalue -> Icmp.t option
 
 
@@ -1561,7 +1687,7 @@ val add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
 val remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
 
 
-(** {Operations on call instructions (only)} *)
+(** {Operations on call instructions (only)} *)
 
 (** [is_tail_call ci] is [true] if the call instruction [ci] is flagged as
     eligible for tail call optimization, [false] otherwise.
@@ -1574,6 +1700,21 @@ val is_tail_call : llvalue -> bool
 val set_tail_call : bool -> llvalue -> unit
 
 
+(** {7 Operations on load/store instructions (only)} *)
+
+(** [is_volatile i] is [true] if the load or store instruction [i] is marked
+    as volatile.
+    See the methods [llvm::LoadInst::isVolatile] and
+    [llvm::StoreInst::isVolatile]. *)
+val is_volatile : llvalue -> bool
+
+(** [set_volatile v i] marks the load or store instruction [i] as volatile
+    if [v] is [true], unmarks otherwise.
+    See the methods [llvm::LoadInst::setVolatile] and
+    [llvm::StoreInst::setVolatile]. *)
+val set_volatile : bool -> llvalue -> unit
+
+
 (** {7 Operations on phi nodes} *)
 
 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
@@ -1584,9 +1725,6 @@ val add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
     See the method [llvm::PHINode::getIncomingValue]. *)
 val incoming : llvalue -> (llvalue * llbasicblock) list
 
-(** [delete_instruction i] deletes the instruction [i].
- * See the method [llvm::Instruction::eraseFromParent]. *)
-val delete_instruction : llvalue -> unit
 
 
 (** {6 Instruction builders} *)
@@ -1982,6 +2120,14 @@ val build_load : llvalue -> string -> llbuilder -> llvalue
     See the method [llvm::LLVMBuilder::CreateStore]. *)
 val build_store : llvalue -> llvalue -> llbuilder -> llvalue
 
+(** [build_atomicrmw op ptr val o st b] creates an [atomicrmw] instruction with
+    operation [op] performed on pointer [ptr] and value [val] with ordering [o]
+    and singlethread flag set to [st] at the position specified by
+    the instruction builder [b].
+    See the method [llvm::IRBuilder::CreateAtomicRMW]. *)
+val build_atomicrmw : AtomicRMWBinOp.t -> llvalue -> llvalue ->
+                      AtomicOrdering.t -> bool -> string -> llbuilder -> llvalue
+
 (** [build_gep p indices name b] creates a
     [%name = getelementptr %p, indices...]
     instruction at the position specified by the instruction builder [b].