From 67994cee66b59a8db8309a5e05c2a08a26d7fcc3 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 19 May 2015 00:57:16 +0000 Subject: [PATCH] [AST] Put VarDeclBitfields on a diet VarDeclBitfields contained bits which are never present in parameters. Split these out so that ParmVarDeclBitfields wouldn't grow past 32-bits if another field was added. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237648 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 128 ++++++++++++++++++---------- lib/AST/Decl.cpp | 2 + lib/Serialization/ASTReaderDecl.cpp | 16 ++-- lib/Serialization/ASTWriterDecl.cpp | 23 ++--- 4 files changed, 104 insertions(+), 65 deletions(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index b6f45c3fae..451f9da1b6 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -39,6 +39,7 @@ class LabelStmt; class MemberSpecializationInfo; class Module; class NestedNameSpecifier; +class ParmVarDecl; class Stmt; class StringLiteral; class TemplateArgumentList; @@ -747,37 +748,8 @@ private: unsigned SClass : 3; unsigned TSCSpec : 2; unsigned InitStyle : 2; - - /// \brief Whether this variable is the exception variable in a C++ catch - /// or an Objective-C @catch statement. - unsigned ExceptionVar : 1; - - /// \brief Whether this local variable could be allocated in the return - /// slot of its function, enabling the named return value optimization - /// (NRVO). - unsigned NRVOVariable : 1; - - /// \brief Whether this variable is the for-range-declaration in a C++0x - /// for-range statement. - unsigned CXXForRangeDecl : 1; - - /// \brief Whether this variable is an ARC pseudo-__strong - /// variable; see isARCPseudoStrong() for details. - unsigned ARCPseudoStrong : 1; - - /// \brief Whether this variable is (C++0x) constexpr. - unsigned IsConstexpr : 1; - - /// \brief Whether this variable is the implicit variable for a lambda - /// init-capture. - unsigned IsInitCapture : 1; - - /// \brief Whether this local extern variable's previous declaration was - /// declared in the same block scope. This controls whether we should merge - /// the type of this declaration with its previous declaration. - unsigned PreviousDeclInSameBlockScope : 1; }; - enum { NumVarDeclBits = 14 }; + enum { NumVarDeclBits = 7 }; friend class ASTDeclReader; friend class StmtIteratorBase; @@ -813,10 +785,47 @@ protected: unsigned ParameterIndex : NumParameterIndexBits; }; + class NonParmVarDeclBitfields { + friend class VarDecl; + friend class ASTDeclReader; + + unsigned : NumVarDeclBits; + + /// \brief Whether this variable is the exception variable in a C++ catch + /// or an Objective-C @catch statement. + unsigned ExceptionVar : 1; + + /// \brief Whether this local variable could be allocated in the return + /// slot of its function, enabling the named return value optimization + /// (NRVO). + unsigned NRVOVariable : 1; + + /// \brief Whether this variable is the for-range-declaration in a C++0x + /// for-range statement. + unsigned CXXForRangeDecl : 1; + + /// \brief Whether this variable is an ARC pseudo-__strong + /// variable; see isARCPseudoStrong() for details. + unsigned ARCPseudoStrong : 1; + + /// \brief Whether this variable is (C++0x) constexpr. + unsigned IsConstexpr : 1; + + /// \brief Whether this variable is the implicit variable for a lambda + /// init-capture. + unsigned IsInitCapture : 1; + + /// \brief Whether this local extern variable's previous declaration was + /// declared in the same block scope. This controls whether we should merge + /// the type of this declaration with its previous declaration. + unsigned PreviousDeclInSameBlockScope : 1; + }; + union { unsigned AllBits; VarDeclBitfields VarDeclBits; ParmVarDeclBitfields ParmVarDeclBits; + NonParmVarDeclBitfields NonParmVarDeclBits; }; VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, @@ -1169,9 +1178,12 @@ public: /// \brief Determine whether this variable is the exception variable in a /// C++ catch statememt or an Objective-C \@catch statement. bool isExceptionVariable() const { - return VarDeclBits.ExceptionVar; + return isa(this) ? false : NonParmVarDeclBits.ExceptionVar; + } + void setExceptionVariable(bool EV) { + assert(!isa(this)); + NonParmVarDeclBits.ExceptionVar = EV; } - void setExceptionVariable(bool EV) { VarDeclBits.ExceptionVar = EV; } /// \brief Determine whether this local variable can be used with the named /// return value optimization (NRVO). @@ -1183,36 +1195,64 @@ public: /// return slot when returning from the function. Within the function body, /// each return that returns the NRVO object will have this variable as its /// NRVO candidate. - bool isNRVOVariable() const { return VarDeclBits.NRVOVariable; } - void setNRVOVariable(bool NRVO) { VarDeclBits.NRVOVariable = NRVO; } + bool isNRVOVariable() const { + return isa(this) ? false : NonParmVarDeclBits.NRVOVariable; + } + void setNRVOVariable(bool NRVO) { + assert(!isa(this)); + NonParmVarDeclBits.NRVOVariable = NRVO; + } /// \brief Determine whether this variable is the for-range-declaration in /// a C++0x for-range statement. - bool isCXXForRangeDecl() const { return VarDeclBits.CXXForRangeDecl; } - void setCXXForRangeDecl(bool FRD) { VarDeclBits.CXXForRangeDecl = FRD; } + bool isCXXForRangeDecl() const { + return isa(this) ? false : NonParmVarDeclBits.CXXForRangeDecl; + } + void setCXXForRangeDecl(bool FRD) { + assert(!isa(this)); + NonParmVarDeclBits.CXXForRangeDecl = FRD; + } /// \brief Determine whether this variable is an ARC pseudo-__strong /// variable. A pseudo-__strong variable has a __strong-qualified /// type but does not actually retain the object written into it. /// Generally such variables are also 'const' for safety. - bool isARCPseudoStrong() const { return VarDeclBits.ARCPseudoStrong; } - void setARCPseudoStrong(bool ps) { VarDeclBits.ARCPseudoStrong = ps; } + bool isARCPseudoStrong() const { + return isa(this) ? false : NonParmVarDeclBits.ARCPseudoStrong; + } + void setARCPseudoStrong(bool ps) { + assert(!isa(this)); + NonParmVarDeclBits.ARCPseudoStrong = ps; + } /// Whether this variable is (C++11) constexpr. - bool isConstexpr() const { return VarDeclBits.IsConstexpr; } - void setConstexpr(bool IC) { VarDeclBits.IsConstexpr = IC; } + bool isConstexpr() const { + return isa(this) ? false : NonParmVarDeclBits.IsConstexpr; + } + void setConstexpr(bool IC) { + assert(!isa(this)); + NonParmVarDeclBits.IsConstexpr = IC; + } /// Whether this variable is the implicit variable for a lambda init-capture. - bool isInitCapture() const { return VarDeclBits.IsInitCapture; } - void setInitCapture(bool IC) { VarDeclBits.IsInitCapture = IC; } + bool isInitCapture() const { + return isa(this) ? false : NonParmVarDeclBits.IsInitCapture; + } + void setInitCapture(bool IC) { + assert(!isa(this)); + NonParmVarDeclBits.IsInitCapture = IC; + } /// Whether this local extern variable declaration's previous declaration /// was declared in the same block scope. Only correct in C++. bool isPreviousDeclInSameBlockScope() const { - return VarDeclBits.PreviousDeclInSameBlockScope; + return isa(this) + ? false + : NonParmVarDeclBits.PreviousDeclInSameBlockScope; } void setPreviousDeclInSameBlockScope(bool Same) { - VarDeclBits.PreviousDeclInSameBlockScope = Same; + assert(!isa(this)); + NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same; } /// \brief If this variable is an instantiated static data member of a diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 4a8eaaf99a..8eff4c4427 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1775,6 +1775,8 @@ VarDecl::VarDecl(Kind DK, ASTContext &C, DeclContext *DC, "VarDeclBitfields too large!"); static_assert(sizeof(ParmVarDeclBitfields) <= sizeof(unsigned), "ParmVarDeclBitfields too large!"); + static_assert(sizeof(NonParmVarDeclBitfields) <= sizeof(unsigned), + "NonParmVarDeclBitfields too large!"); AllBits = 0; VarDeclBits.SClass = SC; // Everything else is implicitly initialized to false. diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index ed684537a6..fe55459b8a 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1063,13 +1063,15 @@ ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { VD->VarDeclBits.SClass = (StorageClass)Record[Idx++]; VD->VarDeclBits.TSCSpec = Record[Idx++]; VD->VarDeclBits.InitStyle = Record[Idx++]; - VD->VarDeclBits.ExceptionVar = Record[Idx++]; - VD->VarDeclBits.NRVOVariable = Record[Idx++]; - VD->VarDeclBits.CXXForRangeDecl = Record[Idx++]; - VD->VarDeclBits.ARCPseudoStrong = Record[Idx++]; - VD->VarDeclBits.IsConstexpr = Record[Idx++]; - VD->VarDeclBits.IsInitCapture = Record[Idx++]; - VD->VarDeclBits.PreviousDeclInSameBlockScope = Record[Idx++]; + if (!isa(VD)) { + VD->NonParmVarDeclBits.ExceptionVar = Record[Idx++]; + VD->NonParmVarDeclBits.NRVOVariable = Record[Idx++]; + VD->NonParmVarDeclBits.CXXForRangeDecl = Record[Idx++]; + VD->NonParmVarDeclBits.ARCPseudoStrong = Record[Idx++]; + VD->NonParmVarDeclBits.IsConstexpr = Record[Idx++]; + VD->NonParmVarDeclBits.IsInitCapture = Record[Idx++]; + VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record[Idx++]; + } Linkage VarLinkage = Linkage(Record[Idx++]); VD->setCachedLinkage(VarLinkage); diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 608aa598cf..0fa4f936a3 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -790,13 +790,15 @@ void ASTDeclWriter::VisitVarDecl(VarDecl *D) { Record.push_back(D->getStorageClass()); Record.push_back(D->getTSCSpec()); Record.push_back(D->getInitStyle()); - Record.push_back(D->isExceptionVariable()); - Record.push_back(D->isNRVOVariable()); - Record.push_back(D->isCXXForRangeDecl()); - Record.push_back(D->isARCPseudoStrong()); - Record.push_back(D->isConstexpr()); - Record.push_back(D->isInitCapture()); - Record.push_back(D->isPreviousDeclInSameBlockScope()); + if (!isa(D)) { + Record.push_back(D->isExceptionVariable()); + Record.push_back(D->isNRVOVariable()); + Record.push_back(D->isCXXForRangeDecl()); + Record.push_back(D->isARCPseudoStrong()); + Record.push_back(D->isConstexpr()); + Record.push_back(D->isInitCapture()); + Record.push_back(D->isPreviousDeclInSameBlockScope()); + } Record.push_back(D->getLinkageInternal()); if (D->getInit()) { @@ -1738,13 +1740,6 @@ void ASTWriter::WriteDeclAbbrevs() { Abv->Add(BitCodeAbbrevOp(0)); // StorageClass Abv->Add(BitCodeAbbrevOp(0)); // getTSCSpec Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer - Abv->Add(BitCodeAbbrevOp(0)); // isExceptionVariable - Abv->Add(BitCodeAbbrevOp(0)); // isNRVOVariable - Abv->Add(BitCodeAbbrevOp(0)); // isCXXForRangeDecl - Abv->Add(BitCodeAbbrevOp(0)); // isARCPseudoStrong - Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr - Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture - Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope Abv->Add(BitCodeAbbrevOp(0)); // Linkage Abv->Add(BitCodeAbbrevOp(0)); // HasInit Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo -- 2.50.1