From: Bruno Ricci Date: Thu, 15 Nov 2018 14:12:51 +0000 (+0000) Subject: [AST] Pack BinaryOperator X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a167b3c3f7920ec7767ef72df2060ceaef21badf;p=platform%2Fupstream%2Fllvm.git [AST] Pack BinaryOperator Use the newly available space in the bit-fields of Stmt. This saves 8 bytes per BinaryOperator. Differential Revision: https://reviews.llvm.org/D54526 Reviewed By: dblaikie llvm-svn: 346954 --- diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index d588879..93798d0 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -3187,20 +3187,11 @@ public: /// "+" resolves to an overloaded operator, CXXOperatorCallExpr will /// be used to express the computation. class BinaryOperator : public Expr { -public: - typedef BinaryOperatorKind Opcode; - -private: - unsigned Opc : 6; - - // This is only meaningful for operations on floating point types and 0 - // otherwise. - unsigned FPFeatures : 3; - SourceLocation OpLoc; - enum { LHS, RHS, END_EXPR }; - Stmt* SubExprs[END_EXPR]; + Stmt *SubExprs[END_EXPR]; + public: + typedef BinaryOperatorKind Opcode; BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, @@ -3211,8 +3202,10 @@ public: (lhs->isInstantiationDependent() || rhs->isInstantiationDependent()), (lhs->containsUnexpandedParameterPack() || - rhs->containsUnexpandedParameterPack())), - Opc(opc), FPFeatures(FPFeatures.getInt()), OpLoc(opLoc) { + rhs->containsUnexpandedParameterPack())) { + BinaryOperatorBits.Opc = opc; + BinaryOperatorBits.FPFeatures = FPFeatures.getInt(); + BinaryOperatorBits.OpLoc = opLoc; SubExprs[LHS] = lhs; SubExprs[RHS] = rhs; assert(!isCompoundAssignmentOp() && @@ -3220,15 +3213,18 @@ public: } /// Construct an empty binary operator. - explicit BinaryOperator(EmptyShell Empty) - : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } + explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) { + BinaryOperatorBits.Opc = BO_Comma; + } - SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; } - SourceLocation getOperatorLoc() const { return OpLoc; } - void setOperatorLoc(SourceLocation L) { OpLoc = L; } + SourceLocation getExprLoc() const { return getOperatorLoc(); } + SourceLocation getOperatorLoc() const { return BinaryOperatorBits.OpLoc; } + void setOperatorLoc(SourceLocation L) { BinaryOperatorBits.OpLoc = L; } - Opcode getOpcode() const { return static_cast(Opc); } - void setOpcode(Opcode O) { Opc = O; } + Opcode getOpcode() const { + return static_cast(BinaryOperatorBits.Opc); + } + void setOpcode(Opcode Opc) { BinaryOperatorBits.Opc = Opc; } Expr *getLHS() const { return cast(SubExprs[LHS]); } void setLHS(Expr *E) { SubExprs[LHS] = E; } @@ -3257,7 +3253,11 @@ public: static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); /// predicates to categorize the respective opcodes. - bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } + static bool isPtrMemOp(Opcode Opc) { + return Opc == BO_PtrMemD || Opc == BO_PtrMemI; + } + bool isPtrMemOp() const { return isPtrMemOp(getOpcode()); } + static bool isMultiplicativeOp(Opcode Opc) { return Opc >= BO_Mul && Opc <= BO_Rem; } @@ -3356,21 +3356,23 @@ public: // Set the FP contractability status of this operator. Only meaningful for // operations on floating point types. - void setFPFeatures(FPOptions F) { FPFeatures = F.getInt(); } + void setFPFeatures(FPOptions F) { + BinaryOperatorBits.FPFeatures = F.getInt(); + } - FPOptions getFPFeatures() const { return FPOptions(FPFeatures); } + FPOptions getFPFeatures() const { + return FPOptions(BinaryOperatorBits.FPFeatures); + } // Get the FP contractability status of this operator. Only meaningful for // operations on floating point types. bool isFPContractableWithinStatement() const { - return FPOptions(FPFeatures).allowFPContractWithinStatement(); + return getFPFeatures().allowFPContractWithinStatement(); } // Get the FENV_ACCESS status of this operator. Only meaningful for // operations on floating point types. - bool isFEnvAccessOn() const { - return FPOptions(FPFeatures).allowFEnvAccess(); - } + bool isFEnvAccessOn() const { return getFPFeatures().allowFEnvAccess(); } protected: BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, @@ -3382,14 +3384,17 @@ protected: (lhs->isInstantiationDependent() || rhs->isInstantiationDependent()), (lhs->containsUnexpandedParameterPack() || - rhs->containsUnexpandedParameterPack())), - Opc(opc), FPFeatures(FPFeatures.getInt()), OpLoc(opLoc) { + rhs->containsUnexpandedParameterPack())) { + BinaryOperatorBits.Opc = opc; + BinaryOperatorBits.FPFeatures = FPFeatures.getInt(); + BinaryOperatorBits.OpLoc = opLoc; SubExprs[LHS] = lhs; SubExprs[RHS] = rhs; } - BinaryOperator(StmtClass SC, EmptyShell Empty) - : Expr(SC, Empty), Opc(BO_MulAssign) { } + BinaryOperator(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) { + BinaryOperatorBits.Opc = BO_MulAssign; + } }; /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h index fcbeaab..cd2effb 100644 --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -442,6 +442,17 @@ protected: unsigned BasePathIsEmpty : 1; }; + class BinaryOperatorBitfields { + friend class BinaryOperator; + + unsigned : NumExprBits; + + unsigned Opc : 6; + unsigned FPFeatures : 3; + + SourceLocation OpLoc; + }; + class InitListExprBitfields { friend class InitListExpr; @@ -558,6 +569,7 @@ protected: CallExprBitfields CallExprBits; MemberExprBitfields MemberExprBits; CastExprBitfields CastExprBits; + BinaryOperatorBitfields BinaryOperatorBits; InitListExprBitfields InitListExprBits; PseudoObjectExprBitfields PseudoObjectExprBits;