From: Benjamin Kramer Date: Fri, 26 Jan 2018 14:14:11 +0000 (+0000) Subject: [AST] Use bit packing to reduce sizeof(TypedefNameDecl) from 88 to 80. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0763d20f307e6aa5c30656a0c8755d9503dd905d;p=clang [AST] Use bit packing to reduce sizeof(TypedefNameDecl) from 88 to 80. We can stash the cached transparent tag bit in existing pointer padding. Everything coming out of ASTContext is always aligned to a multiple of 8, so we have 8 spare bits. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@323528 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index b3eb7750f5..8302c57385 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -2814,12 +2814,12 @@ public: /// Base class for declarations which introduce a typedef-name. class TypedefNameDecl : public TypeDecl, public Redeclarable { using ModedTInfo = std::pair; - llvm::PointerUnion MaybeModedTInfo; - // FIXME: This can be packed into the bitfields in Decl. - /// If 0, we have not computed IsTransparentTag. - /// Otherwise, IsTransparentTag is (CacheIsTransparentTag >> 1). - mutable unsigned CacheIsTransparentTag : 2; + /// If int part is 0, we have not computed IsTransparentTag. + /// Otherwise, IsTransparentTag is (getInt() >> 1). + mutable llvm::PointerIntPair< + llvm::PointerUnion, 2> + MaybeModedTInfo; void anchor() override; @@ -2828,7 +2828,7 @@ protected: SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo) : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C), - MaybeModedTInfo(TInfo), CacheIsTransparentTag(0) {} + MaybeModedTInfo(TInfo, 0) {} using redeclarable_base = Redeclarable; @@ -2855,26 +2855,29 @@ public: using redeclarable_base::getMostRecentDecl; using redeclarable_base::isFirstDecl; - bool isModed() const { return MaybeModedTInfo.is(); } + bool isModed() const { + return MaybeModedTInfo.getPointer().is(); + } TypeSourceInfo *getTypeSourceInfo() const { - return isModed() - ? MaybeModedTInfo.get()->first - : MaybeModedTInfo.get(); + return isModed() ? MaybeModedTInfo.getPointer().get()->first + : MaybeModedTInfo.getPointer().get(); } QualType getUnderlyingType() const { - return isModed() - ? MaybeModedTInfo.get()->second - : MaybeModedTInfo.get()->getType(); + return isModed() ? MaybeModedTInfo.getPointer().get()->second + : MaybeModedTInfo.getPointer() + .get() + ->getType(); } void setTypeSourceInfo(TypeSourceInfo *newType) { - MaybeModedTInfo = newType; + MaybeModedTInfo.setPointer(newType); } void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) { - MaybeModedTInfo = new (getASTContext()) ModedTInfo(unmodedTSI, modedTy); + MaybeModedTInfo.setPointer(new (getASTContext(), 8) + ModedTInfo(unmodedTSI, modedTy)); } /// Retrieves the canonical declaration of this typedef-name. @@ -2891,8 +2894,8 @@ public: /// Determines if this typedef shares a name and spelling location with its /// underlying tag type, as is the case with the NS_ENUM macro. bool isTransparentTag() const { - if (CacheIsTransparentTag) - return CacheIsTransparentTag & 0x2; + if (MaybeModedTInfo.getInt()) + return MaybeModedTInfo.getInt() & 0x2; return isTransparentTagSlow(); } diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index f8010695c9..9c73ee7ede 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -4372,9 +4372,7 @@ bool TypedefNameDecl::isTransparentTagSlow() const { }; bool isTransparent = determineIsTransparent(); - CacheIsTransparentTag = 1; - if (isTransparent) - CacheIsTransparentTag |= 0x2; + MaybeModedTInfo.setInt((isTransparent << 1) | 1); return isTransparent; }