[LLVMdev] getting closer!

Gordon Henriksen gordonhenriksen at mac.com
Tue Apr 22 17:43:19 PDT 2008


On Apr 22, 2008, at 20:19, Terence Parr wrote:

> On Apr 22, 2008, at 3:27 PM, Gordon Henriksen wrote:
>
>>> 1. How do I know the offset (due to alignment/padding by LLVM) of  
>>> a pointer within an object using {...} struct type?  GEP  
>>> instruction gets an address, of course, but how does my C  
>>> collector compute these.  Do I need to make a metadata struct and  
>>> fill it with GEP instructions?  I guess that makes sense.
>>
>> You can use a constant expression to compute this. Specifically:
>>
>> i32 ptrtoint(gep %mytype* null, i32 0, i32 ??? to i32)
>>
>> Where ??? is the number of the field within the struct. (Could be a  
>> list of indices.)
>
> Wow!  Cool trick. I have verified that this and the next works.   
> BTW, I had no idea that that nested notation was possible! How did I  
> miss that in the documentation...

This is not possible for instructions (which must be in SSA form). You  
can only use it for constants.

http://llvm.org/docs/LangRef.html#constantexprs

See also the ConstantExpr class.

>
>> ConstantExpr has a helper similar to sizeOf(Type*) which build this  
>> expression.
>
> I'm always using the pure text input headline generating everything  
> from Java...

Normally I'd say that's masochism, but you may have a handle on text  
templates. :)

>> For example, something like this:
>
> [snip]
>
> Oooooooh! man!  that is exactly what I was looking for.  hooray!   
> Input/Output pairs are the best way to learn this stuff as far as I  
> can tell.
>
> I believe I have enough from this to construct a collector using the  
> "shadow-stack" mechanism.  thanks so much!


Excellent!

— Gordon





More information about the llvm-dev mailing list