This is an archive of the discontinued LLVM Phabricator instance.

[AST] Pack the bit-fields of FunctionProtoType into Type.
ClosedPublic

Authored by riccibruno on Oct 1 2018, 11:37 AM.

Details

Summary

Move the bit-fields of FunctionProtoType into FunctionTypeBitfields. This cuts the
size of FunctionProtoType by a pointer. Additionally use llvm::TrailingObjects instead
of manually doing the casts + arithmetic.

This patch is bigger then what could be expected for the following reasons:

  1. As discussed before in D50631 it would be nice if there was some space left in FunctionTypeBitfields for future additions. This patch introduces an extra structure FunctionTypeExtraBitfields which is supposed to hold uncommon bits and is stored in a trailing object. The number of exception types NumExceptions is moved to this struct. As of this patch this trailing struct will only be allocated if we have > 0 types in a dynamic exception specification.
  1. TrailingObjects cannot (at least I think it cannot) handle repeated types. Therefore the QualType representing an exception type is wrapped in a struct ExceptionType. The ExceptionType * is then reinterpret_cast'd to QualType * which I think is fine since QualType and ExceptionType are standard-layout classes (but please correct me if wrong).
  1. TrailingObjects needs the definition of the various trailing classes. Therefore ExtParameterInfo, ExceptionType and FunctionTypeExtraBitfields are put in FunctionType.

Diff Detail

Repository
rL LLVM

Event Timeline

riccibruno created this revision.Oct 1 2018, 11:37 AM
rjmccall accepted this revision.Oct 1 2018, 11:48 AM

The reinterpret_cast is legal because it's dynamic storage that's never actually accessed as an ExceptionType. IIRC there are reasonable-sounding strict-aliasing arguments about the validity of doing pointer arithmetic using pointers of the wrong type for the objects stored there, but they've always come with a "and if we actually enforced the rules that way, we'd completely break the world" disclaimer.

I agree with all the changes you've made here; thank you for seeing this through.

This revision is now accepted and ready to land.Oct 1 2018, 11:48 AM
This revision was automatically updated to reflect the committed changes.