[LLVMdev] ocaml+llvm
Alain Frisch
alain.frisch at lexifi.com
Sun Aug 19 23:04:30 PDT 2007
Chris Lattner wrote:
> On Aug 14, 2007, at 3:24 AM, Gordon Henriksen wrote:
>> I'm not sure you want to incorporate ocaml's runtime per se; its
>> object model is very unique. :) How do you envision LLVM GC support
>> going?
>
> No idea - I know little about the ocaml GC. I assumed it was generic
> enough to be reused in other contexts. If not, then disregard my
> comments.
The OCaml GC is quite generic. Basically it exposes a model where values
all uniformly represented by a N-bit machine word (N=32 or 64) which
can denote either a (N-1)-bit integer (with the lsb set to 1), a pointer
to a block controlled by the GC, or a pointer outside the GC area
(though the last possibility is considered bad style).
A GC block comes with a 1-word header that describes its length and also
contain a small 8-bit tag (plus a few bits for the GC). In OCaml, the
tag is used in particular to store the constructor for union types
(discriminated sums), but the runtime system is really agnostic about
the meaning of the tag except for a few special values which denote
special kinds of blocks such as:
- byte buffers (not traced by the GC, used to represent OCaml strings),
- custom blocks (native data not controlled by the GC, plus a pointer to
a table of custom functions to implement finalization and generic
operations like equality/hashing/serialization),
- lazy pointers (the GC is able to shortcut chains of forwarding
pointers to forced values),
- arrays of weak pointers,...
Of course, this model makes some assumptions, but it could certainly be
useful to support languages other than OCaml!
-- Alain
More information about the llvm-dev
mailing list