From 23ec04c959c8048648ad3bc16c1d8e88619cdbbd Mon Sep 17 00:00:00 2001 From: Bruno Ricci Date: Fri, 16 Nov 2018 17:38:35 +0000 Subject: [PATCH] [AST][NFC] Pack CXXThisExpr Use the newly available space in the bit-fields of Stmt. This saves 8 bytes per CXXThisExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347064 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ExprCXX.h | 29 ++++++++++++++--------------- include/clang/AST/Stmt.h | 13 +++++++++++++ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 1529551e33..94fba581c1 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -962,29 +962,28 @@ public: /// }; /// \endcode class CXXThisExpr : public Expr { - SourceLocation Loc; - bool Implicit : 1; - public: - CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) - : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary, + CXXThisExpr(SourceLocation L, QualType Ty, bool IsImplicit) + : Expr(CXXThisExprClass, Ty, VK_RValue, OK_Ordinary, // 'this' is type-dependent if the class type of the enclosing // member function is dependent (C++ [temp.dep.expr]p2) - Type->isDependentType(), Type->isDependentType(), - Type->isInstantiationDependentType(), - /*ContainsUnexpandedParameterPack=*/false), - Loc(L), Implicit(isImplicit) {} + Ty->isDependentType(), Ty->isDependentType(), + Ty->isInstantiationDependentType(), + /*ContainsUnexpandedParameterPack=*/false) { + CXXThisExprBits.IsImplicit = IsImplicit; + CXXThisExprBits.Loc = L; + } CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} - SourceLocation getLocation() const { return Loc; } - void setLocation(SourceLocation L) { Loc = L; } + SourceLocation getLocation() const { return CXXThisExprBits.Loc; } + void setLocation(SourceLocation L) { CXXThisExprBits.Loc = L; } - SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } - SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } + SourceLocation getBeginLoc() const { return getLocation(); } + SourceLocation getEndLoc() const { return getLocation(); } - bool isImplicit() const { return Implicit; } - void setImplicit(bool I) { Implicit = I; } + bool isImplicit() const { return CXXThisExprBits.IsImplicit; } + void setImplicit(bool I) { CXXThisExprBits.IsImplicit = I; } static bool classof(const Stmt *T) { return T->getStmtClass() == CXXThisExprClass; diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 37616207c0..b3394a81f4 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -523,6 +523,18 @@ protected: SourceLocation Loc; }; + class CXXThisExprBitfields { + friend class CXXThisExpr; + + unsigned : NumExprBits; + + /// Whether this is an implicit "this". + unsigned IsImplicit : 1; + + /// The location of the "this". + SourceLocation Loc; + }; + class TypeTraitExprBitfields { friend class ASTStmtReader; friend class ASTStmtWriter; @@ -623,6 +635,7 @@ protected: // C++ Expressions CXXBoolLiteralExprBitfields CXXBoolLiteralExprBits; CXXNullPtrLiteralExprBitfields CXXNullPtrLiteralExprBits; + CXXThisExprBitfields CXXThisExprBits; TypeTraitExprBitfields TypeTraitExprBits; ExprWithCleanupsBitfields ExprWithCleanupsBits; -- 2.40.0