forked from OSchip/llvm-project
Move CharacterLiteral, FloatingLiteral and UnaryExprOrTypeTraitExpr flags over into Stmt.
Apply the inheritance-padding trick to FloatingLiteral. Shrinks CharacterLiteral from 32 to 24 bytes and the other two from 40 to 32 bytes (x86_64). llvm-svn: 151500
This commit is contained in:
parent
441607ddcb
commit
8d550863cb
|
@ -1115,7 +1115,7 @@ public:
|
||||||
void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); }
|
void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class APFloatStorage : public APNumericStorage {
|
class APFloatStorage : private APNumericStorage {
|
||||||
public:
|
public:
|
||||||
llvm::APFloat getValue(bool IsIEEE) const {
|
llvm::APFloat getValue(bool IsIEEE) const {
|
||||||
return llvm::APFloat(getIntValue(), IsIEEE);
|
return llvm::APFloat(getIntValue(), IsIEEE);
|
||||||
|
@ -1183,28 +1183,30 @@ public:
|
||||||
private:
|
private:
|
||||||
unsigned Value;
|
unsigned Value;
|
||||||
SourceLocation Loc;
|
SourceLocation Loc;
|
||||||
unsigned Kind : 2;
|
|
||||||
public:
|
public:
|
||||||
// type should be IntTy
|
// type should be IntTy
|
||||||
CharacterLiteral(unsigned value, CharacterKind kind, QualType type,
|
CharacterLiteral(unsigned value, CharacterKind kind, QualType type,
|
||||||
SourceLocation l)
|
SourceLocation l)
|
||||||
: Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
|
: Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
|
||||||
false, false),
|
false, false),
|
||||||
Value(value), Loc(l), Kind(kind) {
|
Value(value), Loc(l) {
|
||||||
|
CharacterLiteralBits.Kind = kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Construct an empty character literal.
|
/// \brief Construct an empty character literal.
|
||||||
CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
|
CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
|
||||||
|
|
||||||
SourceLocation getLocation() const { return Loc; }
|
SourceLocation getLocation() const { return Loc; }
|
||||||
CharacterKind getKind() const { return static_cast<CharacterKind>(Kind); }
|
CharacterKind getKind() const {
|
||||||
|
return static_cast<CharacterKind>(CharacterLiteralBits.Kind);
|
||||||
|
}
|
||||||
|
|
||||||
SourceRange getSourceRange() const { return SourceRange(Loc); }
|
SourceRange getSourceRange() const { return SourceRange(Loc); }
|
||||||
|
|
||||||
unsigned getValue() const { return Value; }
|
unsigned getValue() const { return Value; }
|
||||||
|
|
||||||
void setLocation(SourceLocation Location) { Loc = Location; }
|
void setLocation(SourceLocation Location) { Loc = Location; }
|
||||||
void setKind(CharacterKind kind) { Kind = kind; }
|
void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; }
|
||||||
void setValue(unsigned Val) { Value = Val; }
|
void setValue(unsigned Val) { Value = Val; }
|
||||||
|
|
||||||
static bool classof(const Stmt *T) {
|
static bool classof(const Stmt *T) {
|
||||||
|
@ -1216,41 +1218,41 @@ public:
|
||||||
child_range children() { return child_range(); }
|
child_range children() { return child_range(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class FloatingLiteral : public Expr {
|
class FloatingLiteral : public Expr, private APFloatStorage {
|
||||||
APFloatStorage Num;
|
|
||||||
bool IsIEEE : 1; // Distinguishes between PPC128 and IEEE128.
|
|
||||||
bool IsExact : 1;
|
|
||||||
SourceLocation Loc;
|
SourceLocation Loc;
|
||||||
|
|
||||||
FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact,
|
FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact,
|
||||||
QualType Type, SourceLocation L)
|
QualType Type, SourceLocation L)
|
||||||
: Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false,
|
: Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false,
|
||||||
false, false),
|
false, false), Loc(L) {
|
||||||
IsIEEE(&C.getTargetInfo().getLongDoubleFormat() ==
|
FloatingLiteralBits.IsIEEE =
|
||||||
&llvm::APFloat::IEEEquad),
|
&C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad;
|
||||||
IsExact(isexact), Loc(L) {
|
FloatingLiteralBits.IsExact = isexact;
|
||||||
setValue(C, V);
|
setValue(C, V);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Construct an empty floating-point literal.
|
/// \brief Construct an empty floating-point literal.
|
||||||
explicit FloatingLiteral(ASTContext &C, EmptyShell Empty)
|
explicit FloatingLiteral(ASTContext &C, EmptyShell Empty)
|
||||||
: Expr(FloatingLiteralClass, Empty),
|
: Expr(FloatingLiteralClass, Empty) {
|
||||||
IsIEEE(&C.getTargetInfo().getLongDoubleFormat() ==
|
FloatingLiteralBits.IsIEEE =
|
||||||
&llvm::APFloat::IEEEquad),
|
&C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad;
|
||||||
IsExact(false) { }
|
FloatingLiteralBits.IsExact = false;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V,
|
static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V,
|
||||||
bool isexact, QualType Type, SourceLocation L);
|
bool isexact, QualType Type, SourceLocation L);
|
||||||
static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty);
|
static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty);
|
||||||
|
|
||||||
llvm::APFloat getValue() const { return Num.getValue(IsIEEE); }
|
llvm::APFloat getValue() const {
|
||||||
|
return APFloatStorage::getValue(FloatingLiteralBits.IsIEEE);
|
||||||
|
}
|
||||||
void setValue(ASTContext &C, const llvm::APFloat &Val) {
|
void setValue(ASTContext &C, const llvm::APFloat &Val) {
|
||||||
Num.setValue(C, Val);
|
APFloatStorage::setValue(C, Val);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isExact() const { return IsExact; }
|
bool isExact() const { return FloatingLiteralBits.IsExact; }
|
||||||
void setExact(bool E) { IsExact = E; }
|
void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
|
||||||
|
|
||||||
/// getValueAsApproximateDouble - This returns the value as an inaccurate
|
/// getValueAsApproximateDouble - This returns the value as an inaccurate
|
||||||
/// double. Note that this may cause loss of precision, but is useful for
|
/// double. Note that this may cause loss of precision, but is useful for
|
||||||
|
@ -1824,8 +1826,6 @@ public:
|
||||||
/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and
|
/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and
|
||||||
/// vec_step (OpenCL 1.1 6.11.12).
|
/// vec_step (OpenCL 1.1 6.11.12).
|
||||||
class UnaryExprOrTypeTraitExpr : public Expr {
|
class UnaryExprOrTypeTraitExpr : public Expr {
|
||||||
unsigned Kind : 2;
|
|
||||||
bool isType : 1; // true if operand is a type, false if an expression
|
|
||||||
union {
|
union {
|
||||||
TypeSourceInfo *Ty;
|
TypeSourceInfo *Ty;
|
||||||
Stmt *Ex;
|
Stmt *Ex;
|
||||||
|
@ -1842,7 +1842,9 @@ public:
|
||||||
TInfo->getType()->isDependentType(),
|
TInfo->getType()->isDependentType(),
|
||||||
TInfo->getType()->isInstantiationDependentType(),
|
TInfo->getType()->isInstantiationDependentType(),
|
||||||
TInfo->getType()->containsUnexpandedParameterPack()),
|
TInfo->getType()->containsUnexpandedParameterPack()),
|
||||||
Kind(ExprKind), isType(true), OpLoc(op), RParenLoc(rp) {
|
OpLoc(op), RParenLoc(rp) {
|
||||||
|
UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
|
||||||
|
UnaryExprOrTypeTraitExprBits.IsType = true;
|
||||||
Argument.Ty = TInfo;
|
Argument.Ty = TInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1855,7 +1857,9 @@ public:
|
||||||
E->isTypeDependent(),
|
E->isTypeDependent(),
|
||||||
E->isInstantiationDependent(),
|
E->isInstantiationDependent(),
|
||||||
E->containsUnexpandedParameterPack()),
|
E->containsUnexpandedParameterPack()),
|
||||||
Kind(ExprKind), isType(false), OpLoc(op), RParenLoc(rp) {
|
OpLoc(op), RParenLoc(rp) {
|
||||||
|
UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
|
||||||
|
UnaryExprOrTypeTraitExprBits.IsType = false;
|
||||||
Argument.Ex = E;
|
Argument.Ex = E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1864,11 +1868,11 @@ public:
|
||||||
: Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
|
: Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
|
||||||
|
|
||||||
UnaryExprOrTypeTrait getKind() const {
|
UnaryExprOrTypeTrait getKind() const {
|
||||||
return static_cast<UnaryExprOrTypeTrait>(Kind);
|
return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
|
||||||
}
|
}
|
||||||
void setKind(UnaryExprOrTypeTrait K) { Kind = K; }
|
void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;}
|
||||||
|
|
||||||
bool isArgumentType() const { return isType; }
|
bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
|
||||||
QualType getArgumentType() const {
|
QualType getArgumentType() const {
|
||||||
return getArgumentTypeInfo()->getType();
|
return getArgumentTypeInfo()->getType();
|
||||||
}
|
}
|
||||||
|
@ -1884,10 +1888,13 @@ public:
|
||||||
return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
|
return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
|
void setArgument(Expr *E) {
|
||||||
|
Argument.Ex = E;
|
||||||
|
UnaryExprOrTypeTraitExprBits.IsType = false;
|
||||||
|
}
|
||||||
void setArgument(TypeSourceInfo *TInfo) {
|
void setArgument(TypeSourceInfo *TInfo) {
|
||||||
Argument.Ty = TInfo;
|
Argument.Ty = TInfo;
|
||||||
isType = true;
|
UnaryExprOrTypeTraitExprBits.IsType = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the argument type, or the type of the argument expression, whichever
|
/// Gets the argument type, or the type of the argument expression, whichever
|
||||||
|
|
|
@ -159,6 +159,29 @@ protected:
|
||||||
};
|
};
|
||||||
enum { NumExprBits = 16 };
|
enum { NumExprBits = 16 };
|
||||||
|
|
||||||
|
class CharacterLiteralBitfields {
|
||||||
|
friend class CharacterLiteral;
|
||||||
|
unsigned : NumExprBits;
|
||||||
|
|
||||||
|
unsigned Kind : 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FloatingLiteralBitfields {
|
||||||
|
friend class FloatingLiteral;
|
||||||
|
unsigned : NumExprBits;
|
||||||
|
|
||||||
|
unsigned IsIEEE : 1; // Distinguishes between PPC128 and IEEE128.
|
||||||
|
unsigned IsExact : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
class UnaryExprOrTypeTraitExprBitfields {
|
||||||
|
friend class UnaryExprOrTypeTraitExpr;
|
||||||
|
unsigned : NumExprBits;
|
||||||
|
|
||||||
|
unsigned Kind : 2;
|
||||||
|
unsigned IsType : 1; // true if operand is a type, false if an expression.
|
||||||
|
};
|
||||||
|
|
||||||
class DeclRefExprBitfields {
|
class DeclRefExprBitfields {
|
||||||
friend class DeclRefExpr;
|
friend class DeclRefExpr;
|
||||||
friend class ASTStmtReader; // deserialization
|
friend class ASTStmtReader; // deserialization
|
||||||
|
@ -252,6 +275,9 @@ protected:
|
||||||
StmtBitfields StmtBits;
|
StmtBitfields StmtBits;
|
||||||
CompoundStmtBitfields CompoundStmtBits;
|
CompoundStmtBitfields CompoundStmtBits;
|
||||||
ExprBitfields ExprBits;
|
ExprBitfields ExprBits;
|
||||||
|
CharacterLiteralBitfields CharacterLiteralBits;
|
||||||
|
FloatingLiteralBitfields FloatingLiteralBits;
|
||||||
|
UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
|
||||||
DeclRefExprBitfields DeclRefExprBits;
|
DeclRefExprBitfields DeclRefExprBits;
|
||||||
CastExprBitfields CastExprBits;
|
CastExprBitfields CastExprBits;
|
||||||
CallExprBitfields CallExprBits;
|
CallExprBitfields CallExprBits;
|
||||||
|
|
Loading…
Reference in New Issue