<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jun 13, 2009, at 3:54 AM, Wesley W. Terpstra wrote:</div><blockquote type="cite"><div>Currently I just represent %c as i8*. I assume that this can have<br>consequences in terms of aliasing. I tried opaque*, but llvm-as didn't<br>like that. Is there any way to better represent the type %c to LLVM?<br></div></blockquote><div><br></div><div>I assume this is for tagged sums.</div><div><br></div><div>Logically, what you want is a distinct LLVM type for every ML union type</div><div>and each of its constructors. Unfortunately, LLVM does structural</div><div>uniquing of types, so that won't work. What you <i>can</i> do is abuse address</div><div>spaces, giving every distinct type its own address space and casting</div><div>back and forth between address spaces as necessary.</div><div><br></div><blockquote type="cite"><div>Is there any way to express that a pointer is actually a pointer to an<br>interior element of a type? Something like %opt_33_in_heap =<br>%opt_33_with_header:1 ?<br></div></blockquote><div><br></div><div>Something like an ungetelementptr? No, sorry. That would be a</div><div>pretty nice extension, though obviously unsound, of course.</div><div><br></div><blockquote type="cite"><div>Currently when I want to read the header of an %opt_33, I cast it to a<br>i32* and then use getelementptr -1. Is there a better way?<br></div></blockquote><div><br></div>I think it depends on (1) exactly how your runtime environment lays out</div><div>the header and (2) whether you're trying to create portable IR (as opposed</div><div>to creating IR portably).</div><div><br></div><div>Personally, I would create a struct type (hereafter "HeaderType") for the</div><div>entire GC header; when you want to access a header field, just cast the</div><div>base pointer to i8*, subtract the allocation size of HeaderType, cast the</div><div>result to HeaderType*, and getelementptr from there. That doesn't</div><div>make portable IR, of course, but in the absence of an ungetelementptr</div><div>instruction, I'm not sure how you could do that better.</div><div><br></div><div>You can portably get the allocation size of a type using</div><div>TargetData::getTypeSizeInBits().</div><div><div><br></div><div>John.</div></div></body></html>