|Run-time monomorphization email@example.com (Jon Harrop) (2007-12-05)|
|From:||Jon Harrop <firstname.lastname@example.org>|
|Date:||Wed, 05 Dec 2007 11:25:46 +0000|
|Organization:||Flying Frog Consultancy Ltd.|
Some compilers like Stalin (for Scheme) and MLton (for SML) use
whole-program optimizations to completely remove the run-time cost of
polymorphism. In contrast, languages like OCaml often suffer a 2x slowdown
due to polymorphism in performance critical functions (due to run-time
dispatch inserted into inner loops and not hoisted) that must then be
If I'm using LLVM to JIT compile code for an OCaml-like language, can I
monomorphize function definitions on the fly easily?
May I conjecture how:
. Fetching a handle to a function "f" at its call site uses a
. The application "get f" is memoized with respect to the instantiations of
the type variables of "f" used at its call site.
Consider the example:
val List.fold_left : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
let sum_int = List.fold_left (+) 0
let sum_float = List.fold_left (+.) 0.
The call to "List.fold_left" inside "sum_int" uses 'a = 'b = int and a
version of "List.fold_left" is JIT compiled specifically for those types.
Similarly for "sum_float" with 'a = 'b = float.
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Return to the
Search the comp.compilers archives again.