Skip to content

Commit a167b3c

Browse files
committedNov 15, 2018
[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
1 parent 4c74253 commit a167b3c

File tree

2 files changed

+49
-32
lines changed

2 files changed

+49
-32
lines changed
 

‎clang/include/clang/AST/Expr.h

+37-32
Original file line numberDiff line numberDiff line change
@@ -3187,20 +3187,11 @@ class CStyleCastExpr final
31873187
/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
31883188
/// be used to express the computation.
31893189
class BinaryOperator : public Expr {
3190-
public:
3191-
typedef BinaryOperatorKind Opcode;
3192-
3193-
private:
3194-
unsigned Opc : 6;
3195-
3196-
// This is only meaningful for operations on floating point types and 0
3197-
// otherwise.
3198-
unsigned FPFeatures : 3;
3199-
SourceLocation OpLoc;
3200-
32013190
enum { LHS, RHS, END_EXPR };
3202-
Stmt* SubExprs[END_EXPR];
3191+
Stmt *SubExprs[END_EXPR];
3192+
32033193
public:
3194+
typedef BinaryOperatorKind Opcode;
32043195

32053196
BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
32063197
ExprValueKind VK, ExprObjectKind OK,
@@ -3211,24 +3202,29 @@ class BinaryOperator : public Expr {
32113202
(lhs->isInstantiationDependent() ||
32123203
rhs->isInstantiationDependent()),
32133204
(lhs->containsUnexpandedParameterPack() ||
3214-
rhs->containsUnexpandedParameterPack())),
3215-
Opc(opc), FPFeatures(FPFeatures.getInt()), OpLoc(opLoc) {
3205+
rhs->containsUnexpandedParameterPack())) {
3206+
BinaryOperatorBits.Opc = opc;
3207+
BinaryOperatorBits.FPFeatures = FPFeatures.getInt();
3208+
BinaryOperatorBits.OpLoc = opLoc;
32163209
SubExprs[LHS] = lhs;
32173210
SubExprs[RHS] = rhs;
32183211
assert(!isCompoundAssignmentOp() &&
32193212
"Use CompoundAssignOperator for compound assignments");
32203213
}
32213214

32223215
/// Construct an empty binary operator.
3223-
explicit BinaryOperator(EmptyShell Empty)
3224-
: Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { }
3216+
explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) {
3217+
BinaryOperatorBits.Opc = BO_Comma;
3218+
}
32253219

3226-
SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; }
3227-
SourceLocation getOperatorLoc() const { return OpLoc; }
3228-
void setOperatorLoc(SourceLocation L) { OpLoc = L; }
3220+
SourceLocation getExprLoc() const { return getOperatorLoc(); }
3221+
SourceLocation getOperatorLoc() const { return BinaryOperatorBits.OpLoc; }
3222+
void setOperatorLoc(SourceLocation L) { BinaryOperatorBits.OpLoc = L; }
32293223

3230-
Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
3231-
void setOpcode(Opcode O) { Opc = O; }
3224+
Opcode getOpcode() const {
3225+
return static_cast<Opcode>(BinaryOperatorBits.Opc);
3226+
}
3227+
void setOpcode(Opcode Opc) { BinaryOperatorBits.Opc = Opc; }
32323228

32333229
Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
32343230
void setLHS(Expr *E) { SubExprs[LHS] = E; }
@@ -3257,7 +3253,11 @@ class BinaryOperator : public Expr {
32573253
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
32583254

32593255
/// predicates to categorize the respective opcodes.
3260-
bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; }
3256+
static bool isPtrMemOp(Opcode Opc) {
3257+
return Opc == BO_PtrMemD || Opc == BO_PtrMemI;
3258+
}
3259+
bool isPtrMemOp() const { return isPtrMemOp(getOpcode()); }
3260+
32613261
static bool isMultiplicativeOp(Opcode Opc) {
32623262
return Opc >= BO_Mul && Opc <= BO_Rem;
32633263
}
@@ -3356,21 +3356,23 @@ class BinaryOperator : public Expr {
33563356

33573357
// Set the FP contractability status of this operator. Only meaningful for
33583358
// operations on floating point types.
3359-
void setFPFeatures(FPOptions F) { FPFeatures = F.getInt(); }
3359+
void setFPFeatures(FPOptions F) {
3360+
BinaryOperatorBits.FPFeatures = F.getInt();
3361+
}
33603362

3361-
FPOptions getFPFeatures() const { return FPOptions(FPFeatures); }
3363+
FPOptions getFPFeatures() const {
3364+
return FPOptions(BinaryOperatorBits.FPFeatures);
3365+
}
33623366

33633367
// Get the FP contractability status of this operator. Only meaningful for
33643368
// operations on floating point types.
33653369
bool isFPContractableWithinStatement() const {
3366-
return FPOptions(FPFeatures).allowFPContractWithinStatement();
3370+
return getFPFeatures().allowFPContractWithinStatement();
33673371
}
33683372

33693373
// Get the FENV_ACCESS status of this operator. Only meaningful for
33703374
// operations on floating point types.
3371-
bool isFEnvAccessOn() const {
3372-
return FPOptions(FPFeatures).allowFEnvAccess();
3373-
}
3375+
bool isFEnvAccessOn() const { return getFPFeatures().allowFEnvAccess(); }
33743376

33753377
protected:
33763378
BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
@@ -3382,14 +3384,17 @@ class BinaryOperator : public Expr {
33823384
(lhs->isInstantiationDependent() ||
33833385
rhs->isInstantiationDependent()),
33843386
(lhs->containsUnexpandedParameterPack() ||
3385-
rhs->containsUnexpandedParameterPack())),
3386-
Opc(opc), FPFeatures(FPFeatures.getInt()), OpLoc(opLoc) {
3387+
rhs->containsUnexpandedParameterPack())) {
3388+
BinaryOperatorBits.Opc = opc;
3389+
BinaryOperatorBits.FPFeatures = FPFeatures.getInt();
3390+
BinaryOperatorBits.OpLoc = opLoc;
33873391
SubExprs[LHS] = lhs;
33883392
SubExprs[RHS] = rhs;
33893393
}
33903394

3391-
BinaryOperator(StmtClass SC, EmptyShell Empty)
3392-
: Expr(SC, Empty), Opc(BO_MulAssign) { }
3395+
BinaryOperator(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
3396+
BinaryOperatorBits.Opc = BO_MulAssign;
3397+
}
33933398
};
33943399

33953400
/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep

‎clang/include/clang/AST/Stmt.h

+12
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,17 @@ class alignas(void *) Stmt {
442442
unsigned BasePathIsEmpty : 1;
443443
};
444444

445+
class BinaryOperatorBitfields {
446+
friend class BinaryOperator;
447+
448+
unsigned : NumExprBits;
449+
450+
unsigned Opc : 6;
451+
unsigned FPFeatures : 3;
452+
453+
SourceLocation OpLoc;
454+
};
455+
445456
class InitListExprBitfields {
446457
friend class InitListExpr;
447458

@@ -558,6 +569,7 @@ class alignas(void *) Stmt {
558569
CallExprBitfields CallExprBits;
559570
MemberExprBitfields MemberExprBits;
560571
CastExprBitfields CastExprBits;
572+
BinaryOperatorBitfields BinaryOperatorBits;
561573
InitListExprBitfields InitListExprBits;
562574
PseudoObjectExprBitfields PseudoObjectExprBits;
563575

0 commit comments

Comments
 (0)
Please sign in to comment.