[LLVMdev] LLVM and managed languages

Jon Harrop jonathandeanharrop at googlemail.com
Tue Dec 6 03:40:43 PST 2011

Talin wrote:
> Jon wrote:
> > Talin wrote:
> > > Garbage collection is still way too difficult.
> >
> > This is completely untrue.
> I'm afraid I'm going to have to disagree...

I failed to get my point across. You're still talking about the difficulty
of using LLVM's GC support. I was talking about circumventing it. The shadow
stack HLVM uses does not work as you describe and it makes no use of LLVM's
GC support, e.g. the llvm.gcroot() intrinsic. This is precisely why it is so
much easier to write a working accurate garbage collector as I described. It
doesn't have to be hard. You made a rod for your own back by choosing to use
LLVM's own GC support.

> This avoids the need to update a global variable

Or you could change the calling convention to pass the shadow stack pointer

> ...you have to re-implement it for each different processor

Not with the approach HLVM uses, which is completely platform and
architecture agnostic.

> None of the rest of what I'm about to say would make any difference if I
> using shadow stack. That's not where the problems lie.

That is not true. I believe because you are using "shadow stack" to refer
only to the shadow stack that LLVM provides and not to the concept in

> The main problem, as I see it, is the design of the llvm.gcroot()

HLVM does not use llvm.gcroot() so any design flaws in it are circumvented.

> A second problem is that you are required to explicitly declare as stack
root not
> only your local variables, but any intermediate results of expression. In
> words, the "root-ness" of a value doesn't automatically follow along with
> value, as it would with a type-based approach. The result is that the
> ends up generating horrible, horrible code that is littered with extra
allocas, calls
> to llvm.gcroot(), and lots of extra loads and stores.

Again, that problem does not exist with the approach HLVM uses. It does no
unnecessary allocas and makes no calls to llvm.gcroot() at all.

> A third problem is that the optimizer *has* to know about garbage
> because the optimizer can do things that might invalidate your garbage
> collector's assumptions.

And again, that problem does not exist with the approach HLVM uses. Its
generated code is basically a valid C program so a correct optimizer cannot
break it by violating its assumptions because there are no such assumptions.

> I don't know what you mean by "highly experimental GC support".

I mean it is not tried and tested. How many people have built working
garbage collectors using LLVM's support?

> Increasing performance is only half of the story. The other half is making
> easy to use.

HLVM's approach is very easy to use. Therefore, improved LLVM GC support
would only be valuable if it generated significantly more efficient code. In
theory it should be more efficient but that has not yet been demonstrated.


More information about the llvm-dev mailing list