Module Hlvm


module Hlvm: sig .. end
High-Level Virtual Machine (HLVM).

The design and implementation of this high-performance garbage collected virtual machine is described in detail in the OCaml Journal articles "Building a Virtual Machine with LLVM" from January to March 2009.


module Options: sig .. end
module Type: sig .. end
module Expr: sig .. end
module List: sig .. end
Definitions related to the list type.
val enable_tail_call_opt : unit -> unit
Binding to a function that enables TCO in LLVM.
val llcontext : Llvm.llcontext
val void_type : Llvm.lltype
val struct_type : Llvm.lltype array -> Llvm.lltype
val i1_type : Llvm.lltype
val i8_type : Llvm.lltype
val i32_type : Llvm.lltype
val i64_type : Llvm.lltype
val float_type : Llvm.lltype
val double_type : Llvm.lltype
val mk_struct : < bb : Llvm.llbuilder; .. > -> Llvm.llvalue list -> Llvm.llvalue
Create an aggregate register (a struct) containing the given llvalues.
val extractvalue : < bb : Llvm.llbuilder; .. > -> Llvm.llvalue -> int -> Llvm.llvalue
val string_type : Llvm.lltype
Type of a C-compatible null-terminated string.
val int_type : Llvm.lltype
Type of a native int.
val is_struct : [< `Array of 'a
| `Bool
| `Float
| `Function of 'b
| `Int
| `Reference
| `Struct of 'c
| `Unit ] ->
bool
Is the given type represented by a struct.
val is_ref_type : [< `Array of 'a
| `Bool
| `Float
| `Function of 'b
| `Int
| `Reference
| `Struct of 'c
| `Unit ] ->
bool
Is the given type a reference type.
module Ref: sig .. end
Layout of a reference type.
val lltype_of : Type.t -> Llvm.lltype
Convert a type from our type system into LLVM's type system.
val function_type_of : ?pass_tl:bool -> Type.t list * Type.t -> Llvm.lltype
Representation of function pointers.
val struct_type_of : Type.t list -> Llvm.lltype
Representation of structs.
module RTType: sig .. end
Run-time types.
val print_type_of : Llvm.llvalue -> unit
val int : int -> Llvm.llvalue
Create an LLVM native int.
val unit : Llvm.llvalue
LLVM value used to represent the value () of the type unit.
val int8 : int -> Llvm.llvalue
Create an LLVM 8-bit int.
val int32 : int -> Llvm.llvalue
Create an LLVM 32-bit int.
val float64 : float -> Llvm.llvalue
Create an LLVM 64-bit float.
val null : Llvm.llvalue
LLVM representation of the NULL pointer.
val null_of : ([< `Array of 'a
| `Bool
| `Float
| `Function of Type.t list * Type.t
| `Int
| `Reference
| `Struct of 'a list
| `Unit ]
as 'a) ->
Expr.t
Create a default value of the given type.
val find : string -> (string * 'a) list -> 'a
Search for a binding and give a comprehensible error if it is not found.
val m : Llvm.llmodule
Global LLVM module.
val mp : Llvm.llmoduleprovider
Global LLVM module provider.
val ee : Llvm_executionengine.ExecutionEngine.t
Global LLVM execution engine.
val (<--) : Llvm.llvalue * Type.t -> (Expr.t -> Expr.t) -> Expr.t
module Seq: sig .. end
Type used to represent stacks and unordered sequences (bags).
module State: sig .. end
Run/suspend state used for individial threads and global objective to cooperatively synchronize for the stop-the-world GC phase.
module ThreadLocal: sig .. end
Representation of thread-local data.
module ThreadGlobal: sig .. end
Global thread data including the thread-local data of every mutator thread.
val enter_blocking_section : unit -> Expr.t
val leave_blocking_section : unit -> Expr.t
val lockMutex : Expr.t -> Expr.t
val visit_stack : Llvm.llvalue
The visit stack is an array of unvisited reference types.
val n_visit : Llvm.llvalue
Number of unvisited references on the visit stack.
val allocated_mutex : Llvm.llvalue
val allocated : Llvm.llvalue
The allocated list is an array of reference types.
val n_allocated : Llvm.llvalue
Number of allocated references.
val quota : Llvm.llvalue
Number of allocations required to incur a garbage collection.
module Extern: sig .. end
val suspend_time : Llvm.llvalue
LLVM global to store the total time spent in the suspend phase.
val mark_time : Llvm.llvalue
LLVM global to store the total time spent in the mark phase.
val sweep_time : Llvm.llvalue
LLVM global to store the total time spent in the sweep phase.
val cc : int
Default calling convention used by HLVM.

type vars = {
   vals : (string * (Llvm.llvalue * Type.t)) list;
}
Mapping from bound variable names to their LLVM values and HLVM types.
val vars : vars Pervasives.ref
Default variable bindings.
val types : (string, Llvm.llvalue * Type.t) Hashtbl.t
Bound types (including internal types such as wrapper reference types for arrays).
val functions : (string, Llvm.llvalue) Hashtbl.t
Container of internal functions such as visitors to traverse the heap.
val find_type : string -> Llvm.llvalue * Type.t
Search for a type with the given name from the
val add_val : string * (Llvm.llvalue * Type.t) -> vars -> vars
Bind a new variable.
val push : < bb : Llvm.llbuilder; bitcast : Llvm.llvalue -> Llvm.lltype -> 'a;
load : 'a -> Llvm.llvalue list -> Llvm.llvalue;
store : 'a -> Llvm.llvalue list -> Llvm.llvalue -> unit; .. > ->
'a -> 'a -> Llvm.llvalue -> unit
Push a reference type onto the shadow stack.
val get_stack : < bitcast : 'a -> Llvm.lltype -> 'b; gep : 'b -> Llvm.llvalue list -> 'c;
thread_local : 'a; .. > ->
'c * 'c
Get pointers to the stack depth and stack.
val gc_restore : < bitcast : 'a -> Llvm.lltype -> 'b; gep : 'b -> Llvm.llvalue list -> 'c;
odepth : 'd; store : 'c -> Llvm.llvalue list -> 'd -> unit;
thread_local : 'a; .. > ->
unit
Restore the shadow stack by resetting its depth to an older value.
class state : bool -> Llvm.llvalue -> object .. end
Create a state object that encapsulates our interface for emitting LLVM instructions.
val mk_state : ?pass_tl:bool -> Llvm.llvalue -> state
Create a state object and save the current shadow stack depth.
val uniq : string -> string
Create a unique string based upon the given string.
exception Returned
Exception raised after the return expression is compiled.
type t = [ `Expr of Expr.t
| `Extern of string * Type.t list * Type.t
| `Function of
string * (string * Type.t) list * Type.t * Expr.t
| `Type of string * Type.t
| `UnsafeFunction of
string * (string * Type.t) list * Type.t * Expr.t ]
Top-level definitions.
val type_check : string -> Type.t -> Type.t -> unit
Helper function for type checking.
val string_cache : (string, Llvm.llvalue) Hashtbl.t
Constant string literals are memoized here.
val mk_string : string -> Llvm.llvalue
Memoize a string.
val eval_functions : Llvm.llvalue list Pervasives.ref
List of functions that have been evaluated. The "main" function generated for standalone computation calls each of these functions in turn.
val run_function : Llvm.llvalue -> unit
Register a function and execute it.
val gc_push : Expr.t -> Expr.t
val gc_check : Expr.t
val llty_null : Llvm.llvalue option Pervasives.ref
val expr : vars ->
state -> Expr.t -> state * (Llvm.llvalue * Type.t)
Compile an expression in the context of current vars into the given LLVM state.
val expr_aux : vars ->
state -> Expr.t -> state * (Llvm.llvalue * Type.t)
val expr2 : vars ->
state ->
Expr.t ->
Expr.t ->
state * (Llvm.llvalue * Type.t) * (Llvm.llvalue * Type.t)
Compile two expressions.
val expr3 : vars ->
state ->
Expr.t ->
Expr.t ->
Expr.t ->
state * (Llvm.llvalue * Type.t) * (Llvm.llvalue * Type.t) *
(Llvm.llvalue * Type.t)
Compile three expressions.
val exprs : vars ->
state ->
Expr.t list -> state * (Llvm.llvalue list * Type.t list)
Compile a list of expressions.
val return : vars -> state -> Expr.t -> Type.t -> unit
Compile an expression and return from it, marking any calls in tail position as tail calls.
val gc_root : vars -> state -> Llvm.llvalue Lazy.t -> Type.t -> state
Register all reference types in the given value as live roots for the GC.
val gc_alloc : vars -> state -> Llvm.llvalue -> state
Register an allocated value if necessary.
val defun : ?pass_tl:bool ->
vars ->
int ->
string ->
(string * Type.t) list ->
Type.t -> (vars -> state -> unit) -> vars
Define a function with the given calling convention, name, arguments and return type using the function argument "k" to fill in the body of the defined function.
val def : vars ->
[< `Expr of Expr.t
| `Extern of string * Type.t list * Type.t
| `Function of
string * (string * Type.t) list * Type.t * Expr.t
| `Type of string * Type.t
| `UnsafeFunction of
string * (string * Type.t) list * Type.t * Expr.t
> `Type `UnsafeFunction ] ->
vars
Compile a top-level definition.
val def_visit : vars -> string -> string -> Type.t -> Llvm.llvalue
Define a function to traverse a reference.
val visit : vars -> Expr.t -> Type.t -> Expr.t * vars
Generate an expression that applies the function "f" to every value of a reference type in the value "v".
val def_visit_array : vars -> Type.t -> Llvm.llvalue
Define a function that visits every value of a reference type in an array.
val def_print : vars -> string -> string -> Type.t -> Llvm.llvalue
Define a function to print a boxed value.
val def_print_array : vars -> Type.t -> Llvm.llvalue
Define a function to print an array.
val mk_type : vars ->
Type.t -> vars * (string * (Llvm.llvalue * Type.t))
Create and memoize a reference type. Used to create wrapper reference types.
val mk_array_type : Type.t -> Llvm.llvalue
Create and memoize an array type.
val init_type : string -> Llvm.llvalue -> Llvm.llvalue -> Llvm.llvalue -> unit
Compile and run code to initialize the contents of a new type.
val mk_fun : ?debug:bool ->
?pass_tl:bool ->
vars ->
int ->
string ->
(string * Type.t) list -> Type.t -> Expr.t -> Llvm.llvalue
Create and memoize a function. Used to create visitor functions, print functions and array fill functions.
val fill : vars -> Type.t -> Expr.t
Define a function to fill an array of the given type.
val seq_remove : (Expr.t -> Expr.t -> Expr.t) -> Type.t -> Expr.t
Define a function to remove an element from a bag using linear search.
val init : unit -> vars
Dynamically load the runtime and initialize the shadow stack and GC.
val boot : unit -> t list
val vars : vars Pervasives.ref
Bound variables.
val eval : [< `Expr of Expr.t
| `Extern of string * Type.t list * Type.t
| `Function of
string * (string * Type.t) list * Type.t * Expr.t
| `Type of string * Type.t
| `UnsafeFunction of
string * (string * Type.t) list * Type.t * Expr.t
> `Type `UnsafeFunction ] ->
unit
Evaluate a statement, updating the bound variables.
val save : unit -> unit
Save everything that has been evaluated as a standalone program.