[LLVMdev] Proposed: first class packed structures

Reid Spencer rspencer at reidspencer.com
Thu Dec 7 22:38:39 PST 2006

On Thu, 2006-12-07 at 22:00 -0800, Chris Lattner wrote:
> On Dec 6, 2006, at 10:44 AM, Andrew Lenharth wrote:
> > Currently, Structure layout is left to targets, which implement them
> > according to the ABI of that platform.  While this is fine for most
> > structures, it makes packed structures very ugly.  All fields in a
> > packed type must be converted to byte arrays with casts to access
> > fields, which bloats accesses and obsfucates the types.  First class
> > support for packed types would clean up the generated code from these
> > (lowering bytecode sizes) as well as having minimal impact on
> > optimizations.

> Reid can chime in here, but it seems like there should be a more  
> efficient way to encode the packed'ness than using a whole byte per  
> struct type.  Perhaps it doesn't matter, because we will hopefully be  
> moving to per-bit encoding in the near future.

I don't thinkits worth it at this point. We have way more serious things
going on than an extra byte for a type. Consider that all ICmp/FCmp
instructions will use format0 (the largest) in anything but the smallest
of functions (less than 64 instructions). This will get naturally
cleaned up when we move to bit streams.

If you *really* want to be efficient, the *right* way to do this is to
create a new TypeID and the corresponding  class (class
PackedStructureType : public StructureType). That way it costs nothing
(the value of the TypeID indicates that its PackedStructure) and there's
no need to mess with an additional byte in the StructureType class.
But, that might be a little heavy weight :)


More information about the llvm-dev mailing list