+
+(** {7 Operations on functions} *)
+
+(** [declare_function name ty m] returns a new function of type [ty] and
+ with name [name] in module [m]. If such a function already exists,
+ it is returned. If the type of the existing function differs, then a bitcast
+ to [ty] is returned. *)
+external declare_function : string -> lltype -> llmodule -> llvalue
+ = "llvm_declare_function"
+
+(** [define_function name ty m] creates a new function with name [name] and
+ type [ty] in module [m]. If the named function already exists, it is
+ renamed. An entry basic block is created in the function.
+ See the constructor of [llvm::GlobalVariable]. *)
+external define_function : string -> lltype -> llmodule -> llvalue
+ = "llvm_define_function"
+
+(** [lookup_function name m] returns [Some f] if a function with name
+ [name] exists in module [m]. If no such function exists, returns [None].
+ See the method [llvm::Module] constructor. *)
+external lookup_function : string -> llmodule -> llvalue option
+ = "llvm_lookup_function"
+
+(** [delete_function f] destroys the function [f].
+ See the method [llvm::Function::eraseFromParent]. *)
+external delete_function : llvalue -> unit = "llvm_delete_function"
+
+(** [function_begin m] returns the first position in the function list of the
+ module [m]. [function_begin] and [function_succ] can be used to iterate over
+ the function list in order.
+ See the method [llvm::Module::begin]. *)
+external function_begin : llmodule -> (llmodule, llvalue) llpos
+ = "llvm_function_begin"
+
+(** [function_succ gv] returns the function list position succeeding
+ [Before gv].
+ See the method [llvm::Module::iterator::operator++]. *)
+external function_succ : llvalue -> (llmodule, llvalue) llpos
+ = "llvm_function_succ"
+
+(** [iter_functions f m] applies function [f] to each of the functions of module
+ [m] in order. Tail recursive. *)
+val iter_functions : (llvalue -> unit) -> llmodule -> unit
+
+(** [fold_left_function f init m] is [f (... (f init f1) ...) fN] where
+ [f1,...,fN] are the functions of module [m]. Tail recursive. *)
+val fold_left_functions : ('a -> llvalue -> 'a) -> 'a -> llmodule -> 'a
+
+(** [function_end m] returns the last position in the function list of
+ the module [m]. [function_end] and [function_pred] can be used to iterate
+ over the function list in reverse.
+ See the method [llvm::Module::end]. *)
+external function_end : llmodule -> (llmodule, llvalue) llrev_pos
+ = "llvm_function_end"
+
+(** [function_pred gv] returns the function list position preceding [After gv].
+ See the method [llvm::Module::iterator::operator--]. *)
+external function_pred : llvalue -> (llmodule, llvalue) llrev_pos
+ = "llvm_function_pred"
+
+(** [rev_iter_functions f fn] applies function [f] to each of the functions of
+ module [m] in reverse order. Tail recursive. *)
+val rev_iter_functions : (llvalue -> unit) -> llmodule -> unit
+
+(** [fold_right_functions f m init] is [f (... (f init fN) ...) f1] where
+ [f1,...,fN] are the functions of module [m]. Tail recursive. *)
+val fold_right_functions : (llvalue -> 'a -> 'a) -> llmodule -> 'a -> 'a
+
+(** [is_intrinsic f] returns true if the function [f] is an intrinsic.
+ See the method [llvm::Function::isIntrinsic]. *)
+external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic"
+
+(** [function_call_conv f] returns the calling convention of the function [f].
+ See the method [llvm::Function::getCallingConv]. *)
+external function_call_conv : llvalue -> int = "llvm_function_call_conv"
+
+(** [set_function_call_conv cc f] sets the calling convention of the function
+ [f] to the calling convention numbered [cc].
+ See the method [llvm::Function::setCallingConv]. *)
+external set_function_call_conv : int -> llvalue -> unit
+ = "llvm_set_function_call_conv"
+
+(** [collector f] returns [Some name] if the function [f] has a garbage
+ collection algorithm specified and [None] otherwise.
+ See the method [llvm::Function::getCollector]. *)
+external collector : llvalue -> string option = "llvm_collector"
+
+(** [set_collector gc f] sets the collection algorithm for the function [f] to
+ [gc]. See the method [llvm::Function::setCollector]. *)
+external set_collector : string option -> llvalue -> unit = "llvm_set_collector"
+
+
+(** {7 Operations on params} *)
+
+(** [params f] returns the parameters of function [f].
+ See the method [llvm::Function::getArgumentList]. *)
+external params : llvalue -> llvalue array = "llvm_params"
+
+(** [param f n] returns the [n]th parameter of function [f].
+ See the method [llvm::Function::getArgumentList]. *)
+external param : llvalue -> int -> llvalue = "llvm_param"
+
+(** [param_parent p] returns the parent function that owns the parameter.
+ See the method [llvm::Argument::getParent]. *)
+external param_parent : llvalue -> llvalue = "LLVMGetParamParent"
+
+(** [param_begin f] returns the first position in the parameter list of the
+ function [f]. [param_begin] and [param_succ] can be used to iterate over
+ the parameter list in order.
+ See the method [llvm::Function::arg_begin]. *)
+external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin"
+
+(** [param_succ bb] returns the parameter list position succeeding
+ [Before bb].
+ See the method [llvm::Function::arg_iterator::operator++]. *)
+external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ"
+
+(** [iter_params f fn] applies function [f] to each of the parameters
+ of function [fn] in order. Tail recursive. *)
+val iter_params : (llvalue -> unit) -> llvalue -> unit
+
+(** [fold_left_params f init fn] is [f (... (f init b1) ...) bN] where
+ [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
+val fold_left_params : ('a -> llvalue -> 'a) -> 'a -> llvalue -> 'a
+
+(** [param_end f] returns the last position in the parameter list of
+ the function [f]. [param_end] and [param_pred] can be used to iterate
+ over the parameter list in reverse.
+ See the method [llvm::Function::arg_end]. *)
+external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end"
+
+(** [param_pred gv] returns the function list position preceding [After gv].
+ See the method [llvm::Function::arg_iterator::operator--]. *)
+external param_pred : llvalue -> (llvalue, llvalue) llrev_pos
+ = "llvm_param_pred"
+
+(** [rev_iter_params f fn] applies function [f] to each of the parameters
+ of function [fn] in reverse order. Tail recursive. *)
+val rev_iter_params : (llvalue -> unit) -> llvalue -> unit
+
+(** [fold_right_params f fn init] is [f (... (f init bN) ...) b1] where
+ [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
+val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
+
+
+(** {7 Operations on basic blocks} *)
+
+(** [basic_blocks fn] returns the basic blocks of the function [f].
+ See the method [llvm::Function::getBasicBlockList]. *)
+external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks"
+
+(** [entry_block fn] returns the entry basic block of the function [f].
+ See the method [llvm::Function::getEntryBlock]. *)
+external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock"
+
+(** [delete_block bb] deletes the basic block [bb].
+ See the method [llvm::BasicBlock::eraseFromParent]. *)
+external delete_block : llbasicblock -> unit = "llvm_delete_block"
+
+(** [append_block name f] creates a new basic block named [name] at the end of
+ function [f].
+ See the constructor of [llvm::BasicBlock]. *)
+external append_block : string -> llvalue -> llbasicblock = "llvm_append_block"
+
+(** [insert_block name bb] creates a new basic block named [name] before the
+ basic block [bb].
+ See the constructor of [llvm::BasicBlock]. *)
+external insert_block : string -> llbasicblock -> llbasicblock
+ = "llvm_insert_block"
+
+(** [block_parent bb] returns the parent function that owns the basic block.
+ See the method [llvm::BasicBlock::getParent]. *)
+external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent"
+
+(** [block_begin f] returns the first position in the basic block list of the
+ function [f]. [block_begin] and [block_succ] can be used to iterate over
+ the basic block list in order.
+ See the method [llvm::Function::begin]. *)
+external block_begin : llvalue -> (llvalue, llbasicblock) llpos
+ = "llvm_block_begin"
+
+(** [block_succ bb] returns the basic block list position succeeding
+ [Before bb].
+ See the method [llvm::Function::iterator::operator++]. *)
+external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos
+ = "llvm_block_succ"
+
+(** [iter_blocks f fn] applies function [f] to each of the basic blocks
+ of function [fn] in order. Tail recursive. *)
+val iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
+
+(** [fold_left_blocks f init fn] is [f (... (f init b1) ...) bN] where
+ [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
+val fold_left_blocks : ('a -> llbasicblock -> 'a) -> 'a -> llvalue -> 'a
+
+(** [block_end f] returns the last position in the basic block list of
+ the function [f]. [block_end] and [block_pred] can be used to iterate
+ over the basic block list in reverse.
+ See the method [llvm::Function::end]. *)
+external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos
+ = "llvm_block_end"
+
+(** [block_pred gv] returns the function list position preceding [After gv].
+ See the method [llvm::Function::iterator::operator--]. *)
+external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos
+ = "llvm_block_pred"
+
+(** [rev_iter_blocks f fn] applies function [f] to each of the basic blocks
+ of function [fn] in reverse order. Tail recursive. *)
+val rev_iter_blocks : (llbasicblock -> unit) -> llvalue -> unit
+
+(** [fold_right_blocks f fn init] is [f (... (f init bN) ...) b1] where
+ [b1,...,bN] are the basic blocks of function [fn]. Tail recursive. *)
+val fold_right_blocks : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a
+
+(** [value_of_block bb] losslessly casts [bb] to an [llvalue]. *)
+external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
+
+(** [value_is_block v] returns [true] if the value [v] is a basic block and
+ [false] otherwise.
+ Similar to [llvm::isa<BasicBlock>]. *)
+external value_is_block : llvalue -> bool = "llvm_value_is_block"
+
+(** [block_of_value v] losslessly casts [v] to an [llbasicblock]. *)
+external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
+
+
+(** {7 Operations on instructions} *)
+
+(** [instr_parent i] is the enclosing basic block of the instruction [i].
+ See the method [llvm::Instruction::getParent]. *)
+external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent"
+
+
+(** {7 Operations on call sites} *)
+
+(** [instruction_call_conv ci] is the calling convention for the call or invoke
+ instruction [ci], which may be one of the values from the module
+ {!CallConv}. See the method [llvm::CallInst::getCallingConv] and
+ [llvm::InvokeInst::getCallingConv]. *)
+external instruction_call_conv: llvalue -> int
+ = "llvm_instruction_call_conv"
+
+(** [set_instruction_call_conv cc ci] sets the calling convention for the call
+ or invoke instruction [ci] to the integer [cc], which can be one of the
+ values from the module {!CallConv}.
+ See the method [llvm::CallInst::setCallingConv]
+ and [llvm::InvokeInst::setCallingConv]. *)
+external set_instruction_call_conv: int -> llvalue -> unit
+ = "llvm_set_instruction_call_conv"
+
+
+(** {7 Operations on phi nodes} *)
+
+(** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
+ with branches from [bb]. See the method [llvm::PHINode::addIncoming]. *)
+external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit
+ = "llvm_add_incoming"
+
+(** [incoming pn] returns the list of value-block pairs for phi node [pn].
+ See the method [llvm::PHINode::getIncomingValue]. *)
+external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
+
+
+
+(** {6 Instruction builders} *)
+
+(** [builder ()] creates an instruction builder with no position. It is invalid
+ to use this builder until its position is set with {!position_before} or
+ {!position_at_end}. See the constructor for [llvm::LLVMBuilder]. *)
+external builder: unit-> llbuilder
+ = "llvm_builder"
+
+(** [builder_before ins] creates an instruction builder positioned before the
+ instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
+external builder_before : llvalue -> llbuilder = "llvm_builder_before"
+
+(** [builder_at_end bb] creates an instruction builder positioned at the end of
+ the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
+external builder_at_end : llbasicblock -> llbuilder = "llvm_builder_at_end"
+
+(** [position_before ins b] moves the instruction builder [b] to before the
+ instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
+external position_before : llvalue -> llbuilder -> unit = "llvm_position_before"
+
+(** [position_at_end bb b] moves the instruction builder [b] to the end of the
+ basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
+external position_at_end : llbasicblock -> llbuilder -> unit
+ = "llvm_position_at_end"
+
+(** [insertion_block b] returns the basic block that the builder [b] is
+ positioned to insert into. Raises [Not_Found] if the instruction builder is
+ uninitialized.
+ See the method [llvm::LLVMBuilder::GetInsertBlock]. *)
+external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
+
+
+(** {7 Terminators} *)
+
+(** [build_ret_void b] creates a
+ [ret void]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateRetVoid]. *)
+external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void"
+
+(** [build_ret v b] creates a
+ [ret %v]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateRet]. *)
+external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret"
+
+(** [build_br bb b] creates a
+ [b %bb]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateBr]. *)
+external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br"
+
+(** [build_cond_br cond tbb fbb b] creates a
+ [b %cond, %tbb, %fbb]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateCondBr]. *)
+external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder ->
+ llvalue = "llvm_build_cond_br"
+
+(** [build_switch case elsebb b] creates an empty
+ [switch %case, %elsebb]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateSwitch]. *)
+external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue
+ = "llvm_build_switch"
+
+(** [build_invoke fn args tobb unwindbb name b] creates an
+ [%name = invoke %fn(args) to %tobb unwind %unwindbb]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateInvoke]. *)
+external build_invoke : llvalue -> llvalue array -> llbasicblock ->
+ llbasicblock -> string -> llbuilder -> llvalue
+ = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
+
+(** [build_unwind b] creates an
+ [unwind]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateUnwind]. *)
+external build_unwind : llbuilder -> llvalue = "llvm_build_unwind"
+
+(** [build_unreachable b] creates an
+ [unreachable]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateUnwind]. *)
+external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable"
+
+
+(** {7 Arithmetic} *)
+
+(** [build_add x y name b] creates a
+ [%name = add %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateAdd]. *)
+external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_add"
+
+(** [build_sub x y name b] creates a
+ [%name = sub %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateSub]. *)
+external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_sub"
+
+(** [build_mul x y name b] creates a
+ [%name = mul %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateMul]. *)
+external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_mul"
+
+(** [build_udiv x y name b] creates a
+ [%name = udiv %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateUDiv]. *)
+external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_udiv"
+
+(** [build_sdiv x y name b] creates a
+ [%name = sdiv %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateSDiv]. *)
+external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_sdiv"
+
+(** [build_fdiv x y name b] creates a
+ [%name = fdiv %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateFDiv]. *)
+external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_fdiv"
+
+(** [build_urem x y name b] creates a
+ [%name = urem %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateURem]. *)
+external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_urem"
+
+(** [build_SRem x y name b] creates a
+ [%name = srem %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateSRem]. *)
+external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_srem"
+
+(** [build_frem x y name b] creates a
+ [%name = frem %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateFRem]. *)
+external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_frem"
+
+(** [build_shl x y name b] creates a
+ [%name = shl %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateShl]. *)
+external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_shl"
+
+(** [build_lshr x y name b] creates a
+ [%name = lshr %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateLShr]. *)
+external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_lshr"
+
+(** [build_ashr x y name b] creates a
+ [%name = ashr %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateAShr]. *)
+external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_ashr"
+
+(** [build_and x y name b] creates a
+ [%name = and %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateAnd]. *)
+external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_and"
+
+(** [build_or x y name b] creates a
+ [%name = or %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateOr]. *)
+external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_or"
+
+(** [build_xor x y name b] creates a
+ [%name = xor %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateXor]. *)
+external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_xor"
+
+(** [build_neg x name b] creates a
+ [%name = sub 0, %x]
+ instruction at the position specified by the instruction builder [b].
+ [-0.0] is used for floating point types to compute the correct sign.
+ See the method [llvm::LLVMBuilder::CreateNeg]. *)
+external build_neg : llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_neg"
+
+(** [build_xor x name b] creates a
+ [%name = xor %x, -1]
+ instruction at the position specified by the instruction builder [b].
+ [-1] is the correct "all ones" value for the type of [x].
+ See the method [llvm::LLVMBuilder::CreateXor]. *)
+external build_not : llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_not"
+
+
+(** {7 Memory} *)
+
+(** [build_malloc ty name b] creates a
+ [%name = malloc %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateAlloca]. *)
+external build_malloc : lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_malloc"
+
+(** [build_array_malloc ty n name b] creates a
+ [%name = malloc %ty, %n]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateMalloc]. *)
+external build_array_malloc : lltype -> llvalue -> string -> llbuilder ->
+ llvalue = "llvm_build_array_malloc"
+
+(** [build_alloca ty name b] creates a
+ [%name = alloca %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateAlloca]. *)
+external build_alloca : lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_alloca"
+
+(** [build_array_alloca ty n name b] creates a
+ [%name = alloca %ty, %n]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateAlloca]. *)
+external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
+ llvalue = "llvm_build_array_alloca"
+
+(** [build_free v b] creates a
+ [free %v]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateFree]. *)
+external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free"
+
+(** [build_load v name b] creates a
+ [%name = load %v]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateLoad]. *)
+external build_load : llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_load"
+
+(** [build_store v p b] creates a
+ [store %v, %p]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateStore]. *)
+external build_store : llvalue -> llvalue -> llbuilder -> llvalue
+ = "llvm_build_store"
+
+(** [build_gep p indices name b] creates a
+ [%name = gep %p, indices...]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
+external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
+ = "llvm_build_gep"
+
+
+(** {7 Casts} *)
+
+(** [build_trunc v ty name b] creates a
+ [%name = trunc %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateTrunc]. *)
+external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_trunc"
+
+(** [build_zext v ty name b] creates a
+ [%name = zext %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateZExt]. *)
+external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_zext"
+
+(** [build_sext v ty name b] creates a
+ [%name = sext %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateSExt]. *)
+external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_sext"
+
+(** [build_fptoui v ty name b] creates a
+ [%name = fptoui %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateFPToUI]. *)
+external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_fptoui"
+
+(** [build_fptosi v ty name b] creates a
+ [%name = fptosi %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateFPToSI]. *)
+external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_fptosi"
+
+(** [build_uitofp v ty name b] creates a
+ [%name = uitofp %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateUIToFP]. *)
+external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_uitofp"
+
+(** [build_sitofp v ty name b] creates a
+ [%name = sitofp %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateSIToFP]. *)
+external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_sitofp"
+
+(** [build_fptrunc v ty name b] creates a
+ [%name = fptrunc %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateFPTrunc]. *)
+external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_fptrunc"
+
+(** [build_fpext v ty name b] creates a
+ [%name = fpext %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateFPExt]. *)
+external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_fpext"
+
+(** [build_ptrtoint v ty name b] creates a
+ [%name = prtotint %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreatePtrToInt]. *)
+external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_prttoint"
+
+(** [build_inttoptr v ty name b] creates a
+ [%name = inttoptr %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateIntToPtr]. *)
+external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_inttoptr"
+
+(** [build_bitcast v ty name b] creates a
+ [%name = bitcast %p to %ty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateBitcast]. *)
+external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_bitcast"
+
+
+(** {7 Comparisons} *)
+
+(** [build_icmp pred x y name b] creates a
+ [%name = icmp %pred %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateICmp]. *)
+external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
+ llbuilder -> llvalue = "llvm_build_icmp"
+
+(** [build_fcmp pred x y name b] creates a
+ [%name = fcmp %pred %x, %y]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateFCmp]. *)
+external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
+ llbuilder -> llvalue = "llvm_build_fcmp"
+
+
+(** {7 Miscellaneous instructions} *)
+
+(** [build_phi incoming name b] creates a
+ [%name = phi %incoming]
+ instruction at the position specified by the instruction builder [b].
+ [incoming] is a list of [(llvalue, llbasicblock)] tuples.
+ See the method [llvm::LLVMBuilder::CreatePHI]. *)
+external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder ->
+ llvalue = "llvm_build_phi"
+
+(** [build_call fn args name b] creates a
+ [%name = call %fn(args...)]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateCall]. *)
+external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue
+ = "llvm_build_call"
+
+(** [build_select cond thenv elsev name b] creates a
+ [%name = select %cond, %thenv, %elsev]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateSelect]. *)
+external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder ->
+ llvalue = "llvm_build_select"
+
+(** [build_va_arg valist argty name b] creates a
+ [%name = va_arg %valist, %argty]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateVAArg]. *)
+external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue
+ = "llvm_build_va_arg"
+
+(** [build_extractelement vec i name b] creates a
+ [%name = extractelement %vec, %i]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateExtractElement]. *)
+external build_extractelement : llvalue -> llvalue -> string -> llbuilder ->
+ llvalue = "llvm_build_extractelement"
+
+(** [build_insertelement vec elt i name b] creates a
+ [%name = insertelement %vec, %elt, %i]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateInsertElement]. *)
+external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
+ llbuilder -> llvalue = "llvm_build_insertelement"
+
+(** [build_shufflevector veca vecb mask name b] creates a
+ [%name = shufflevector %veca, %vecb, %mask]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateShuffleVector]. *)
+external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
+ llbuilder -> llvalue = "llvm_build_shufflevector"
+
+
+(** {6 Module providers} *)
+
+module ModuleProvider : sig
+ (** [create_module_provider m] encapsulates [m] in a module provider and takes
+ ownership of the module. See the constructor
+ [llvm::ExistingModuleProvider::ExistingModuleProvider]. *)
+ external create : llmodule -> llmoduleprovider
+ = "LLVMCreateModuleProviderForExistingModule"
+
+ (** [dispose_module_provider mp] destroys the module provider [mp] as well as
+ the contained module. *)
+ external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
+end
+
+
+(** {6 Memory buffers} *)
+
+module MemoryBuffer : sig
+ (** [of_file p] is the memory buffer containing the contents of the file at
+ path [p]. If the file could not be read, then [IoError msg] is
+ raised. *)
+ external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
+
+ (** [stdin ()] is the memory buffer containing the contents of standard input.
+ If standard input is empty, then [IoError msg] is raised. *)
+ external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
+
+ (** Disposes of a memory buffer. *)
+ external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
+end
+
+
+(** {6 Pass Managers} *)
+
+module PassManager : sig
+ (** *)
+ type 'a t
+ type any = [ `Module | `Function ]
+
+ (** [PassManager.create ()] constructs a new whole-module pass pipeline. This
+ type of pipeline is suitable for link-time optimization and whole-module
+ transformations.
+ See the constructor of [llvm::PassManager]. *)
+ external create : unit -> [ `Module ] t = "llvm_passmanager_create"
+
+ (** [PassManager.create_function mp] constructs a new function-by-function
+ pass pipeline over the module provider [mp]. It does not take ownership of
+ [mp]. This type of pipeline is suitable for code generation and JIT
+ compilation tasks.
+ See the constructor of [llvm::FunctionPassManager]. *)
+ external create_function : llmoduleprovider -> [ `Function ] t
+ = "LLVMCreateFunctionPassManager"
+
+ (** [run_module m pm] initializes, executes on the module [m], and finalizes
+ all of the passes scheduled in the pass manager [pm]. Returns [true] if
+ any of the passes modified the module, [false] otherwise.
+ See the [llvm::PassManager::run] method. *)
+ external run_module : llmodule -> [ `Module ] t -> bool
+ = "llvm_passmanager_run_module"
+
+ (** [initialize fpm] initializes all of the function passes scheduled in the
+ function pass manager [fpm]. Returns [true] if any of the passes modified
+ the module, [false] otherwise.
+ See the [llvm::FunctionPassManager::doInitialization] method. *)
+ external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize"
+
+ (** [run_function f fpm] executes all of the function passes scheduled in the
+ function pass manager [fpm] over the function [f]. Returns [true] if any
+ of the passes modified [f], [false] otherwise.
+ See the [llvm::FunctionPassManager::run] method. *)
+ external run_function : llvalue -> [ `Function ] t -> bool
+ = "llvm_passmanager_run_function"
+
+ (** [finalize fpm] finalizes all of the function passes scheduled in in the
+ function pass manager [fpm]. Returns [true] if any of the passes
+ modified the module, [false] otherwise.
+ See the [llvm::FunctionPassManager::doFinalization] method. *)
+ external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize"
+
+ (** Frees the memory of a pass pipeline. For function pipelines, does not free
+ the module provider.
+ See the destructor of [llvm::BasePassManager]. *)
+ external dispose : [< any ] t -> unit = "llvm_passmanager_dispose"
+end