r323528 - [AST] Use bit packing to reduce sizeof(TypedefNameDecl) from 88 to 80.
Vlad Tsyrklevich via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 26 12:01:36 PST 2018
This change has broken a number of buildbots, e.g.
http://lab.llvm.org:8011/builders/sanitizer-windows/builds/23163
On Fri, Jan 26, 2018 at 6:15 AM Benjamin Kramer via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> Author: d0k
> Date: Fri Jan 26 06:14:11 2018
> New Revision: 323528
>
> URL: http://llvm.org/viewvc/llvm-project?rev=323528&view=rev
> Log:
> [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.
>
> Modified:
> cfe/trunk/include/clang/AST/Decl.h
> cfe/trunk/lib/AST/Decl.cpp
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=323528&r1=323527&r2=323528&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Fri Jan 26 06:14:11 2018
> @@ -2814,12 +2814,12 @@ public:
> /// Base class for declarations which introduce a typedef-name.
> class TypedefNameDecl : public TypeDecl, public
> Redeclarable<TypedefNameDecl> {
> using ModedTInfo = std::pair<TypeSourceInfo *, QualType>;
> - llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *> 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<TypeSourceInfo *, ModedTInfo *>, 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<TypedefNameDecl>;
>
> @@ -2855,26 +2855,29 @@ public:
> using redeclarable_base::getMostRecentDecl;
> using redeclarable_base::isFirstDecl;
>
> - bool isModed() const { return MaybeModedTInfo.is<ModedTInfo*>(); }
> + bool isModed() const {
> + return MaybeModedTInfo.getPointer().is<ModedTInfo *>();
> + }
>
> TypeSourceInfo *getTypeSourceInfo() const {
> - return isModed()
> - ? MaybeModedTInfo.get<ModedTInfo*>()->first
> - : MaybeModedTInfo.get<TypeSourceInfo*>();
> + return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo
> *>()->first
> + : MaybeModedTInfo.getPointer().get<TypeSourceInfo
> *>();
> }
>
> QualType getUnderlyingType() const {
> - return isModed()
> - ? MaybeModedTInfo.get<ModedTInfo*>()->second
> - : MaybeModedTInfo.get<TypeSourceInfo*>()->getType();
> + return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo
> *>()->second
> + : MaybeModedTInfo.getPointer()
> + .get<TypeSourceInfo *>()
> + ->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();
> }
>
>
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=323528&r1=323527&r2=323528&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/Decl.cpp (original)
> +++ cfe/trunk/lib/AST/Decl.cpp Fri Jan 26 06:14:11 2018
> @@ -4372,9 +4372,7 @@ bool TypedefNameDecl::isTransparentTagSl
> };
>
> bool isTransparent = determineIsTransparent();
> - CacheIsTransparentTag = 1;
> - if (isTransparent)
> - CacheIsTransparentTag |= 0x2;
> + MaybeModedTInfo.setInt((isTransparent << 1) | 1);
> return isTransparent;
> }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180126/b6abe392/attachment.html>
More information about the cfe-commits
mailing list