+
+(** [build_insertvalue agg idx name b] creates a
+ [%name = extractvalue %agg, %idx]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateExtractValue]. *)
+external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue
+ = "llvm_build_extractvalue"
+
+(** [build_insertvalue agg val idx name b] creates a
+ [%name = insertvalue %agg, %val, %idx]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateInsertValue]. *)
+external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder ->
+ llvalue = "llvm_build_insertvalue"
+
+(** [build_is_null val name b] creates a
+ [%name = icmp eq %val, null]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateIsNull]. *)
+external build_is_null : llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_is_null"
+
+(** [build_is_not_null val name b] creates a
+ [%name = icmp ne %val, null]
+ instruction at the position specified by the instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreateIsNotNull]. *)
+external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_is_not_null"
+
+(** [build_ptrdiff lhs rhs name b] creates a series of instructions that measure
+ the difference between two pointer values at the position specified by the
+ instruction builder [b].
+ See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
+external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue
+ = "llvm_build_ptrdiff"
+
+(** {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