[LLVMdev] Extending GC infrastructure for roots in SSA values

David Chisnall David.Chisnall at cl.cam.ac.uk
Sun Dec 30 02:17:25 PST 2012


On 30 Dec 2012, at 01:54, Talin wrote:

> I completely agree with your point about wanting to be able to attach GC metadata to a type (rather than attaching it to a value, as is done now). In the past, there have been two objections to this approach: first, the overhead that would be added to the Pointer type - the vast majority of LLVM users don't want to have to pay an extra 4-8 bytes per Pointer type. And second, that all of the optimization passes would have to be updated so as to not do illegal transformations on a GC type.

There are two other alternatives:

- Use address spaces to separate garbage-collected from non-garbage-collected pointers.  There is (was?) a plan to add an address space cast instruction and explicitly disallow bitcasts of pointers between address spaces.  This would mean that you could have one address space for GC roots, one for GC-allocated memory and enforce the casts in your front end.  Optimisations would then not be allowed to change the address space of any pointers, so the GC status would be preserved.  GC-aware allocations may insert explicit address space casts, where appropriate.

- Add a new GC'd pointer type, which is an entirely separate type.  This might make sense, as you ideally want GC'd pointers to be treated differently from others (e.g. you may not want pointers to the starts of allocations to be removed)

For languages like OCaml, you also want to be able to do escape analysis on GC'd pointers to get good performance (so you don't bother tracing ones that can't possibly escape).  This ideally requires a pass that will recursively and automatically apply nocapture attributes to arguments.  In functional languages, this ends up being almost all allocations, so you can allocate them either on the stack or on a separate bump-the-pointer allocator and delete them on function return by just resetting the pointer.  This means that you would want to be able to have transforms that lowered GC'd pointers to stack or heap pointers.

In some implementations, GC'd pointers are fat pointers, so they should not be represented as PointerType in the IR or as iPTR in the back end.

David



More information about the llvm-dev mailing list