[LLVMdev] reload of pointers after GC

Gordon Henriksen gordonhenriksen at me.com
Tue Sep 23 06:39:04 PDT 2008


Hi Scott,

On Sep 22, 2008, at 20:59, Scott Graham wrote:

> I'm using a GC that's pretty similar to the OCaml one. It records  
> stack locations using llvm.gcroot, and dumps out a frametable  
> describing the live stack offsets so that the GC runtime can walk  
> them as required. I'm on 2.3, not svn head.
>
> I'm having some trouble with pointers being cached in registers  
> across function calls (at least x86 backend, haven't tried others  
> yet).

Are you reusing the same SSA variables, or reloading from the gcroot?  
Copying collectors require that you reload before each use (or, more  
specifically, between each call that could invoke the collector). e.g.,

     ; object obj;
     %root = alloca
     call void llvm.gcroot(%root)

     ; obj = new Object;
     %obj.1 = gcalloc()
     store %obj.1 -> %obj.root

     ; danger(); // Could invoke the collector!
     call void danger()

     ; use(obj);
     %obj.2 = load %obj.root
     call void use(%obj.2) ; Not %obj.1!

     ; danger(); // Could invoke the collector!
     call void danger()

     ; use(obj);
     %obj.3 = load %obj.root
     call void use(%obj.3) ; Not %obj.2!

Of particular danger is that naive code generation for something like  
f(obj, g()) would retain an SSA value for obj over the call to g().

> It seems that simply passing the address of a stack variable to any  
> function (llvm.gcroot or otherwise)

That's the basis for the llvm.gcroot model.

> I haven't made a standalone repro .ll yet

This would be helpful.

— Gordon





More information about the llvm-dev mailing list