Skip to content

Commit f92f31c

Browse files
author
Erich Keane
committedAug 1, 2018
[AST][1/4] Move the bit-fields from TagDecl, EnumDecl and RecordDecl into DeclContext
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. Differential Revision: https://reviews.llvm.org/D49729 Patch By: bricci llvm-svn: 338630
1 parent 7f33094 commit f92f31c

File tree

9 files changed

+775
-312
lines changed

9 files changed

+775
-312
lines changed
 

‎clang/include/clang/AST/Decl.h

+129-175
Large diffs are not rendered by default.

‎clang/include/clang/AST/DeclBase.h

+519-65
Large diffs are not rendered by default.

‎clang/lib/AST/Decl.cpp

+55-20
Original file line numberDiff line numberDiff line change
@@ -3767,6 +3767,22 @@ void FieldDecl::setCapturedVLAType(const VariableArrayType *VLAType) {
37673767
// TagDecl Implementation
37683768
//===----------------------------------------------------------------------===//
37693769

3770+
TagDecl::TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3771+
SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3772+
SourceLocation StartL)
3773+
: TypeDecl(DK, DC, L, Id, StartL), DeclContext(DK), redeclarable_base(C),
3774+
TypedefNameDeclOrQualifier((TypedefNameDecl *)nullptr) {
3775+
assert((DK != Enum || TK == TTK_Enum) &&
3776+
"EnumDecl not matched with TTK_Enum");
3777+
setPreviousDecl(PrevDecl);
3778+
setTagKind(TK);
3779+
setCompleteDefinition(false);
3780+
setBeingDefined(false);
3781+
setEmbeddedInDeclarator(false);
3782+
setFreeStanding(false);
3783+
setCompleteDefinitionRequired(false);
3784+
}
3785+
37703786
SourceLocation TagDecl::getOuterLocStart() const {
37713787
return getTemplateOrInnerLocStart(this);
37723788
}
@@ -3789,7 +3805,7 @@ void TagDecl::setTypedefNameForAnonDecl(TypedefNameDecl *TDD) {
37893805
}
37903806

37913807
void TagDecl::startDefinition() {
3792-
IsBeingDefined = true;
3808+
setBeingDefined(true);
37933809

37943810
if (auto *D = dyn_cast<CXXRecordDecl>(this)) {
37953811
struct CXXRecordDecl::DefinitionData *Data =
@@ -3804,8 +3820,8 @@ void TagDecl::completeDefinition() {
38043820
cast<CXXRecordDecl>(this)->hasDefinition()) &&
38053821
"definition completed but not started");
38063822

3807-
IsCompleteDefinition = true;
3808-
IsBeingDefined = false;
3823+
setCompleteDefinition(true);
3824+
setBeingDefined(false);
38093825

38103826
if (ASTMutationListener *L = getASTMutationListener())
38113827
L->CompletedTagDefinition(this);
@@ -3816,7 +3832,7 @@ TagDecl *TagDecl::getDefinition() const {
38163832
return const_cast<TagDecl *>(this);
38173833

38183834
// If it's possible for us to have an out-of-date definition, check now.
3819-
if (MayHaveOutOfDateDef) {
3835+
if (mayHaveOutOfDateDef()) {
38203836
if (IdentifierInfo *II = getIdentifier()) {
38213837
if (II->isOutOfDate()) {
38223838
updateOutOfDate(*II);
@@ -3869,6 +3885,21 @@ void TagDecl::setTemplateParameterListsInfo(
38693885
// EnumDecl Implementation
38703886
//===----------------------------------------------------------------------===//
38713887

3888+
EnumDecl::EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3889+
SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
3890+
bool Scoped, bool ScopedUsingClassTag, bool Fixed)
3891+
: TagDecl(Enum, TTK_Enum, C, DC, IdLoc, Id, PrevDecl, StartLoc) {
3892+
assert(Scoped || !ScopedUsingClassTag);
3893+
IntegerType = nullptr;
3894+
setNumPositiveBits(0);
3895+
setNumNegativeBits(0);
3896+
setScoped(Scoped);
3897+
setScopedUsingClassTag(ScopedUsingClassTag);
3898+
setFixed(Fixed);
3899+
setHasODRHash(false);
3900+
ODRHash = 0;
3901+
}
3902+
38723903
void EnumDecl::anchor() {}
38733904

38743905
EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC,
@@ -3878,7 +3909,7 @@ EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC,
38783909
bool IsScopedUsingClassTag, bool IsFixed) {
38793910
auto *Enum = new (C, DC) EnumDecl(C, DC, StartLoc, IdLoc, Id, PrevDecl,
38803911
IsScoped, IsScopedUsingClassTag, IsFixed);
3881-
Enum->MayHaveOutOfDateDef = C.getLangOpts().Modules;
3912+
Enum->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
38823913
C.getTypeDeclType(Enum, PrevDecl);
38833914
return Enum;
38843915
}
@@ -3887,7 +3918,7 @@ EnumDecl *EnumDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
38873918
EnumDecl *Enum =
38883919
new (C, ID) EnumDecl(C, nullptr, SourceLocation(), SourceLocation(),
38893920
nullptr, nullptr, false, false, false);
3890-
Enum->MayHaveOutOfDateDef = C.getLangOpts().Modules;
3921+
Enum->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
38913922
return Enum;
38923923
}
38933924

@@ -3971,12 +4002,12 @@ void EnumDecl::setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
39714002
}
39724003

39734004
unsigned EnumDecl::getODRHash() {
3974-
if (HasODRHash)
4005+
if (hasODRHash())
39754006
return ODRHash;
39764007

39774008
class ODRHash Hash;
39784009
Hash.AddEnumDecl(this);
3979-
HasODRHash = true;
4010+
setHasODRHash(true);
39804011
ODRHash = Hash.CalculateHash();
39814012
return ODRHash;
39824013
}
@@ -3989,22 +4020,26 @@ RecordDecl::RecordDecl(Kind DK, TagKind TK, const ASTContext &C,
39894020
DeclContext *DC, SourceLocation StartLoc,
39904021
SourceLocation IdLoc, IdentifierInfo *Id,
39914022
RecordDecl *PrevDecl)
3992-
: TagDecl(DK, TK, C, DC, IdLoc, Id, PrevDecl, StartLoc),
3993-
HasFlexibleArrayMember(false), AnonymousStructOrUnion(false),
3994-
HasObjectMember(false), HasVolatileMember(false),
3995-
LoadedFieldsFromExternalStorage(false),
3996-
NonTrivialToPrimitiveDefaultInitialize(false),
3997-
NonTrivialToPrimitiveCopy(false), NonTrivialToPrimitiveDestroy(false),
3998-
ParamDestroyedInCallee(false), ArgPassingRestrictions(APK_CanPassInRegs) {
3999-
assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
4023+
: TagDecl(DK, TK, C, DC, IdLoc, Id, PrevDecl, StartLoc) {
4024+
assert(classof(static_cast<Decl *>(this)) && "Invalid Kind!");
4025+
setHasFlexibleArrayMember(false);
4026+
setAnonymousStructOrUnion(false);
4027+
setHasObjectMember(false);
4028+
setHasVolatileMember(false);
4029+
setHasLoadedFieldsFromExternalStorage(false);
4030+
setNonTrivialToPrimitiveDefaultInitialize(false);
4031+
setNonTrivialToPrimitiveCopy(false);
4032+
setNonTrivialToPrimitiveDestroy(false);
4033+
setParamDestroyedInCallee(false);
4034+
setArgPassingRestrictions(APK_CanPassInRegs);
40004035
}
40014036

40024037
RecordDecl *RecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC,
40034038
SourceLocation StartLoc, SourceLocation IdLoc,
40044039
IdentifierInfo *Id, RecordDecl* PrevDecl) {
40054040
RecordDecl *R = new (C, DC) RecordDecl(Record, TK, C, DC,
40064041
StartLoc, IdLoc, Id, PrevDecl);
4007-
R->MayHaveOutOfDateDef = C.getLangOpts().Modules;
4042+
R->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
40084043

40094044
C.getTypeDeclType(R, PrevDecl);
40104045
return R;
@@ -4014,7 +4049,7 @@ RecordDecl *RecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
40144049
RecordDecl *R =
40154050
new (C, ID) RecordDecl(Record, TTK_Struct, C, nullptr, SourceLocation(),
40164051
SourceLocation(), nullptr, nullptr);
4017-
R->MayHaveOutOfDateDef = C.getLangOpts().Modules;
4052+
R->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
40184053
return R;
40194054
}
40204055

@@ -4038,7 +4073,7 @@ void RecordDecl::setCapturedRecord() {
40384073
}
40394074

40404075
RecordDecl::field_iterator RecordDecl::field_begin() const {
4041-
if (hasExternalLexicalStorage() && !LoadedFieldsFromExternalStorage)
4076+
if (hasExternalLexicalStorage() && !hasLoadedFieldsFromExternalStorage())
40424077
LoadFieldsFromExternalStorage();
40434078

40444079
return field_iterator(decl_iterator(FirstDecl));
@@ -4066,7 +4101,7 @@ void RecordDecl::LoadFieldsFromExternalStorage() const {
40664101
ExternalASTSource::Deserializing TheFields(Source);
40674102

40684103
SmallVector<Decl*, 64> Decls;
4069-
LoadedFieldsFromExternalStorage = true;
4104+
setHasLoadedFieldsFromExternalStorage(true);
40704105
Source->FindExternalLexicalDecls(this, [](Decl::Kind K) {
40714106
return FieldDecl::classofKind(K) || IndirectFieldDecl::classofKind(K);
40724107
}, Decls);

0 commit comments

Comments
 (0)
Please sign in to comment.