From: Bruno Ricci Date: Sat, 17 Nov 2018 13:02:47 +0000 (+0000) Subject: [AST][NFC] Pack CXXDefaultInitExpr X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9722ecff031a94ce5f8bf1844f5c8abe9991735;p=clang [AST][NFC] Pack CXXDefaultInitExpr Use the newly available space in the bit-fields of Stmt. This saves one pointer per CXXDefaultInitExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347138 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 3a1755d86a..a525490092 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -1123,26 +1123,23 @@ public: /// (C++11 [class.base.init]p8) or in aggregate initialization /// (C++1y [dcl.init.aggr]p7). class CXXDefaultInitExpr : public Expr { + friend class ASTReader; + friend class ASTStmtReader; + /// The field whose default is being used. FieldDecl *Field; - /// The location where the default initializer expression was used. - SourceLocation Loc; - - CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, FieldDecl *Field, - QualType T); + CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc, + FieldDecl *Field, QualType Ty); CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {} public: - friend class ASTReader; - friend class ASTStmtReader; - /// \p Field is the non-static data member whose default initializer is used /// by this expression. - static CXXDefaultInitExpr *Create(const ASTContext &C, SourceLocation Loc, + static CXXDefaultInitExpr *Create(const ASTContext &Ctx, SourceLocation Loc, FieldDecl *Field) { - return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType()); + return new (Ctx) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType()); } /// Get the field whose initializer will be used. @@ -1159,8 +1156,8 @@ public: return Field->getInClassInitializer(); } - SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } - SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } + SourceLocation getBeginLoc() const { return CXXDefaultInitExprBits.Loc; } + SourceLocation getEndLoc() const { return CXXDefaultInitExprBits.Loc; } static bool classof(const Stmt *T) { return T->getStmtClass() == CXXDefaultInitExprClass; diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 258678bdd1..4dd7ab79f7 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -558,6 +558,16 @@ protected: SourceLocation Loc; }; + class CXXDefaultInitExprBitfields { + friend class ASTStmtReader; + friend class CXXDefaultInitExpr; + + unsigned : NumExprBits; + + /// The location where the default initializer expression was used. + SourceLocation Loc; + }; + class TypeTraitExprBitfields { friend class ASTStmtReader; friend class ASTStmtWriter; @@ -661,6 +671,7 @@ protected: CXXThisExprBitfields CXXThisExprBits; CXXThrowExprBitfields CXXThrowExprBits; CXXDefaultArgExprBitfields CXXDefaultArgExprBits; + CXXDefaultInitExprBitfields CXXDefaultInitExprBits; TypeTraitExprBitfields TypeTraitExprBits; ExprWithCleanupsBitfields ExprWithCleanupsBits; diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 00a460758e..a58b0f7fa2 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -749,14 +749,15 @@ const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const { return cast(getCalleeDecl())->getLiteralIdentifier(); } -CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, - FieldDecl *Field, QualType T) - : Expr(CXXDefaultInitExprClass, T.getNonLValueExprType(C), - T->isLValueReferenceType() ? VK_LValue : T->isRValueReferenceType() +CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc, + FieldDecl *Field, QualType Ty) + : Expr(CXXDefaultInitExprClass, Ty.getNonLValueExprType(Ctx), + Ty->isLValueReferenceType() ? VK_LValue : Ty->isRValueReferenceType() ? VK_XValue : VK_RValue, /*FIXME*/ OK_Ordinary, false, false, false, false), - Field(Field), Loc(Loc) { + Field(Field) { + CXXDefaultInitExprBits.Loc = Loc; assert(Field->hasInClassInitializer()); } diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index cf39ccc5e0..db790c5ebf 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -1487,7 +1487,7 @@ void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { void ASTStmtReader::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { VisitExpr(E); E->Field = ReadDeclAs(); - E->Loc = ReadSourceLocation(); + E->CXXDefaultInitExprBits.Loc = ReadSourceLocation(); } void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {