[LLVMdev] Primitive types

Vladimir Prus ghost at cs.msu.su
Fri Jun 18 09:03:01 PDT 2004


Chris Lattner wrote:

> > There are a couple of things that I'd like to ask. First, if
> > isPrimitiveType()  returns false, that the fact that getPrimitiveID
> > returns reasonable value is quite strange. Maybe, the method is better
> > called just getID, since it can get id for both primitive and derived
> > types.
>
> You're right, getPrimitiveID seems misnamed.  It should be named
> getTypeID()  or something.

Ok, thanks for changing that in code.

> > Second, why getPrimitiveSize() returns 0? In seems that LLVM knows the
> > size a pointer occupies (at least it puts in in LLVM assembly), so why
> > not return it? For me, that would be quite convenient -- I would only
> > check that type passed to a function has size of either 4 or 8 bytes and
> > that would catch both primitives and pointers.
>
> It returns zero because it's not a primitive type :), and because it
> doesn't know the size at that point.  All primitive types have fixed sizes
> independent of the target machine (a 32-bit int is always 4 bytes), so
> this method makes sense for primitives.  For derived types, a variety of
> target-specific properties can effect the size of objects (field
> alignment, structure layout rules, etc).
>
> Because of this, all of this information is encapsulated in the TargetData
> structure.  It can tell you the size of an arbitrary type, field offsets,
> etc.  If you're working in the context of an LLVM pass, you just
> addRequired<TargetData> and getAnalysis<TargetData> when needed (there are
> lots of examples in the source base).

Thanks, I'll use this.

- Volodya




More information about the llvm-dev mailing list