This is an archive of the discontinued LLVM Phabricator instance.

[AST][1/4] Move the bit-fields from TagDecl, EnumDecl and RecordDecl into DeclContext
ClosedPublic

Authored by bricci on Jul 24 2018, 7:32 AM.

Details

Summary

DeclContext has a little less than 8 bytes free due to the alignment
requirements on 64 bits archs. This set of patches moves the
bit-fields from classes deriving from DeclContext into DeclContext.

On 32 bits archs this increases the size of DeclContext by 4 bytes
but this is balanced by an equal or larger reduction in the size
of the classes deriving from it.

On 64 bits archs the size of DeclContext stays the same but
most of the classes deriving from it shrink by 8/16 bytes.
(-print-stats diff here https://reviews.llvm.org/D49728)
When doing an -fsyntax-only on all of Boost this result
in a 3.6% reduction in the size of all Decls and
a 1% reduction in the run time due to the lower cache
miss rate.

For now CXXRecordDecl is not touched but there is
an easy 6 (if I count correctly) bytes gain available there
by moving some bits from DefinitionData into the free
space of DeclContext. This will be the subject of another patch.

This patch sequence also enable the possibility of refactoring
FunctionDecl: To save space some bits from classes deriving from
FunctionDecl were moved to FunctionDecl. This resulted in a
lot of stuff in FunctionDecl which do not belong logically to it.
After this set of patches however it is just a simple matter of
adding a SomethingDeclBitfields in DeclContext and moving the
bits to it from FunctionDecl.

This first patch introduces the anonymous union in DeclContext
and all the *DeclBitfields classes holding the bit-fields, and moves
the bits from TagDecl, EnumDecl and RecordDecl into DeclContext.

This patch is followed by https://reviews.llvm.org/D49732,
https://reviews.llvm.org/D49733 and https://reviews.llvm.org/D49734.

Diff Detail

Repository
rC Clang

Event Timeline

bricci created this revision.Jul 24 2018, 7:32 AM
bricci edited the summary of this revision. (Show Details)Jul 24 2018, 7:51 AM
bricci edited the summary of this revision. (Show Details)Jul 24 2018, 8:03 AM

added some inline comments

include/clang/AST/DeclBase.h
1664

uint64_t is used here because we will always store more than 32 bits
but less than 64 bits in these SomethingDeclBitfields.

1959

This declaration has no corresponding definition and is unused.
Therefore I removed it but if this is more appropriate for another
patch I will do the necessary changes.

bricci updated this revision to Diff 157052.Jul 24 2018, 8:52 AM

updated some some comments in DeclContext

bricci marked an inline comment as done.Jul 24 2018, 9:43 AM

remove the inline comment about uint64_t.

This seems like a patch with a good direction, I generally think that this change doesn't change the readability of the code (and generally matches the structure of other code in clang). It is generally a mechanical change, though I'd suggest running clang-format (https://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting) along this patch.

include/clang/AST/Decl.h
3126

The setters that you've moved change the accessibility of these variables. I'd much prefer we maintain the protected/privateness of these. In a few of these cases, they shouldn't be modified outside of the Decl itself

3164

These two should also be documented.

3602

While you're reflowing this, put a new line between teh definitions throughout the patch (of ones where you're modifying them).

include/clang/AST/DeclBase.h
1253

While this documentation change is appreciated, I believe it would fit better in a separate patch.

1473

The newlines in this comment feel strange, did you run clang-format on these?

1764

s/save/saves

2335

'externally visible'?

2401

Again, externally visible?

lib/AST/DeclBase.cpp
991

Is there value to having these static-asserts in the constructor here? It seems that it would go best under the 'union' that includes all of these.

bricci updated this revision to Diff 157063.Jul 24 2018, 9:51 AM
  • removed some unrelated change
  • add a comment about why uint64_t instead of unsigned
bricci edited the summary of this revision. (Show Details)Jul 24 2018, 10:33 AM
bricci edited the summary of this revision. (Show Details)Jul 24 2018, 11:24 AM
bricci edited the summary of this revision. (Show Details)Jul 24 2018, 11:29 AM
bricci updated this revision to Diff 157231.Jul 25 2018, 5:25 AM
bricci marked 10 inline comments as done.

address @erichkeane comments:

  • ran clang-format on changed parts
  • made the setters setNumPositiveBits, setNumPositiveBits, setScoped, setScopedUsingClassTag and setFixed in EnumDecl private.
  • made the setters setBeingDefined and setBeingDefined in TagDecl protected
  • moved the static_asserts to the anonymous union
  • factored out the doc update of DeclBase. This is now https://reviews.llvm.org/D49790
  • various typos

This looks acceptable to me. I'd like to get @rsmith or @rnk to approve the approach though.

It might be better to wait just after the upcoming release branch in any case
since even though it is all NFC this causes a bit of churn.

bricci updated this revision to Diff 157288.Jul 25 2018, 9:52 AM
  • clang-format on the changes in the .cpp files

I've not done a full review, but the approach here looks good, thanks!

erichkeane added inline comments.Jul 26 2018, 6:46 AM
include/clang/AST/Decl.h
3338

This is the same comment as 3330, perhaps a copy/paste error?

lib/AST/Decl.cpp
3893

This cast is jarring. C-Style casts shouldn't be used (i realize it is in the source), and I'm not sure it is necessary here. Can you try removing the cast entirely?

bricci updated this revision to Diff 157522.Jul 26 2018, 10:21 AM
bricci marked 2 inline comments as done.
  • Re-based: r337978 [ODRHash] Support hashing enums added an ODRHash to EnumDecl which conflicts with these changes. The corresponding flag HasODRHash has been put into EnumDeclBitfields.
  • The ugly IntegerType = (const Type *)nullptr; has been cleaned to IntegerType = nullptr; I guess the intent was to disambiguate between the two possible operator= but there is a special case for nullptr so this is not needed since const Type * is the first element of the pair.
  • Made hasNeedToReconcileExternalVisibleStorage, hasLazyLocalLexicalLookups and hasLazyExternalLexicalLookups private. This match what was originally the case with the private bit-fields. This also requires making ASTWriter a friend of DeclContext (as was the case before).
  • Fixed some comments in EnumDecl.
erichkeane accepted this revision.Jul 26 2018, 11:14 AM
This revision is now accepted and ready to land.Jul 26 2018, 11:14 AM
bricci updated this revision to Diff 158498.Aug 1 2018, 4:21 AM

rebased after the great whitespace trimming

@erichkeane do you have any additional comments regarding this set of patches ?
I retested them on top of trunk and did not find any problem.

This revision was automatically updated to reflect the committed changes.