<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
  <title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
On 04/27/10 00:20, Talin wrote:
<blockquote
 cite="mid:j2sd1b71f831004261520z87e07360ja841d98b0bdc0626@mail.gmail.com"
 type="cite">On Mon, Apr 26, 2010 at 12:44 AM, Paul Melis <span
 dir="ltr"><<a moz-do-not-send="true"
 href="mailto:llvm@assumetheposition.nl">llvm@assumetheposition.nl</a>></span>
wrote:<br>
  <div class="gmail_quote">
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
    <div>
    <div class="h5">Hi,<br>
    <br>
Talin wrote:<br>
> I'm a little confused as to the rules for the arguments to
llvm.gcroot,<br>
> which says it must be a pointer alloca. I'm not sure whether that
means it<br>
> must be an alloca (which is always a pointer by definition) or an
alloca<br>
> *of* a pointer.<br>
    <br>
I'm pretty sure it should be "alloca of a pointer", as the first
argument<br>
of llvm.gcroot has type i8**.<br>
    <br>
However, <a moz-do-not-send="true"
 href="http://llvm.org/docs/GarbageCollection.html#gcroot"
 target="_blank">http://llvm.org/docs/GarbageCollection.html#gcroot</a>,
isn't<br>
completely clear on this:<br>
    <br>
"The first argument must be a value referring to an alloca instruction
or<br>
a bitcast of an alloca."<br>
    <br>
This last sentence seems to rule out passing GEPs on alloca's to
llvm.gcroot.<br>
    <br>
> What I am trying to figure out is how to declare roots contained
in value<br>
> types. Suppose for example I have a small struct which contains
several<br>
> garbage-collectable references. This struct is a local variable,
so it's<br>
> contained in a block of memory which has been allocated via
alloca. Now, I<br>
> don't want to add the struct itself as a root, since it isn't
allocated on<br>
> the heap. But I want to declare the fields within the struct -
which are<br>
> GEPs from the alloca pointer - as roots, since they are references
to<br>
> objects on the heap.<br>
    <br>
As reasonable as the above sounds, I don't think you can mark roots<br>
contained in structs. But if I'm wrong I'd love to know ;-)  Perhaps you<br>
can ask the LDC devs how/if they handle this case, as it seems you can<br>
allocate a class instance on the stack in D.<br>
    <br>
    </div>
    </div>
  </blockquote>
  <div>Ugh. If all roots have to be singleton pointers, not embedded
within a larger structure, then I'm not sure that what I want to do is
even possible.</div>
  </div>
</blockquote>
In principle you could probably mark the alloca's of your value structs
as gcroots. Then during collection you would have to make sure you
recognize the value types so you don't move/deallocate/... them during
a collection. That would still give you the option to trace all live
objects by simply traversing the fields of a value struct. You would
only have to do this for value structs (indirectly) containing
references. Does that make sense?<br>
<br>
BTW, I checked the LDC sources, they don't use LLVM's GC support, but
use their own GC stuff in D, so no clues there...<br>
<br>
Regards,<br>
Paul<br>
</body>
</html>