Chromium Code Reviews| Index: src/compiler/types.h |
| diff --git a/src/compiler/types.h b/src/compiler/types.h |
| index ef5bec3f9de63ac179b3526a7499895179e9405a..786dcabf062227b6688e0845e1950a0dd2b4670d 100644 |
| --- a/src/compiler/types.h |
| +++ b/src/compiler/types.h |
| @@ -7,6 +7,7 @@ |
| #include "src/conversions.h" |
| #include "src/handles.h" |
| +#include "src/objects-inl.h" |
| #include "src/objects.h" |
| #include "src/ostreams.h" |
| @@ -263,7 +264,7 @@ class TypeBase { |
| protected: |
| friend class Type; |
| - enum Kind { kConstant, kTuple, kUnion, kRange }; |
| + enum Kind { kConstant, kOtherNumberConstant, kTuple, kUnion, kRange }; |
| Kind kind() const { return kind_; } |
| explicit TypeBase(Kind kind) : kind_(kind) {} |
| @@ -287,6 +288,50 @@ class TypeBase { |
| // ----------------------------------------------------------------------------- |
| // Constant types. |
| +class OtherNumberConstantType : public TypeBase { |
| + public: |
| + double Value() { return value_; } |
| + |
| + static bool IsInteger(double x) { |
| + return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. |
| + } |
| + |
| + static bool IsOtherNumberConstant(double value) { |
| + // Not an integer, not NaN, and not -0. |
| + return !std::isnan(value) && !IsInteger(value) && !i::IsMinusZero(value); |
|
Jarin
2016/10/04 13:14:55
IsInteger => Type::IsInteger (and remove the IsInt
mvstanton
2016/10/05 13:51:10
Let me keep this for now, I wouldn't be able to in
|
| + } |
| + |
| + static bool IsOtherNumberConstant(Object* value) { |
| + if (value->IsHeapNumber()) { |
| + return IsOtherNumberConstant(HeapNumber::cast(value)->value()); |
|
Jarin
2016/10/04 13:14:55
Nit:
return value->IsHeapNumber() &&
IsOther
mvstanton
2016/10/05 13:51:10
Done.
|
| + } |
| + return false; |
| + } |
| + |
| + private: |
| + friend class Type; |
| + friend class BitsetType; |
| + |
| + static Type* New(double value, Zone* zone) { |
| + return AsType(new (zone->New(sizeof(OtherNumberConstantType))) |
| + OtherNumberConstantType(value)); |
| + } |
| + |
| + static OtherNumberConstantType* cast(Type* type) { |
| + DCHECK(IsKind(type, kOtherNumberConstant)); |
| + return static_cast<OtherNumberConstantType*>(FromType(type)); |
| + } |
| + |
| + OtherNumberConstantType(double value) |
| + : TypeBase(kOtherNumberConstant), value_(value) { |
| + CHECK(IsOtherNumberConstant(value)); |
| + } |
| + |
| + BitsetType::bitset Lub() { return BitsetType::kOtherNumber; } |
| + |
| + double value_; |
| +}; |
| + |
| class ConstantType : public TypeBase { |
|
Jarin
2016/10/04 13:14:55
Maybe ConstantType => HeapConstantType?
mvstanton
2016/10/05 13:51:10
Done.
|
| public: |
| i::Handle<i::Object> Value() { return object_; } |
| @@ -307,14 +352,16 @@ class ConstantType : public TypeBase { |
| } |
| ConstantType(BitsetType::bitset bitset, i::Handle<i::Object> object) |
| - : TypeBase(kConstant), bitset_(bitset), object_(object) {} |
| + : TypeBase(kConstant), bitset_(bitset), object_(object) { |
| + CHECK(!object->IsSmi()); // Smis should always be RangeTypes. |
| + CHECK(!OtherNumberConstantType::IsOtherNumberConstant(*object)); |
| + } |
| BitsetType::bitset Lub() { return bitset_; } |
| BitsetType::bitset bitset_; |
| Handle<i::Object> object_; |
| }; |
| -// TODO(neis): Also cache value if numerical. |
| // ----------------------------------------------------------------------------- |
| // Range types. |
| @@ -474,6 +521,9 @@ class Type { |
| return BitsetType::New(BitsetType::UnsignedSmall()); |
| } |
| + static Type* OtherNumberConstant(double value, Zone* zone) { |
| + return OtherNumberConstantType::New(value, zone); |
| + } |
| static Type* Constant(i::Handle<i::Object> value, Zone* zone) { |
|
Jarin
2016/10/04 13:14:55
Maybe Constant => HeapConstant?
mvstanton
2016/10/05 13:51:10
Done.
|
| return ConstantType::New(value, zone); |
| } |
| @@ -488,6 +538,9 @@ class Type { |
| return tuple; |
| } |
| + // NewConstant is a factory that returns Constant, Range or Number. |
| + static Type* NewConstant(i::Handle<i::Object> value, Zone* zone); |
| + |
| static Type* Union(Type* type1, Type* type2, Zone* zone); |
| static Type* Intersect(Type* type1, Type* type2, Zone* zone); |
| @@ -516,9 +569,15 @@ class Type { |
| // Inspection. |
| bool IsRange() { return IsKind(TypeBase::kRange); } |
| bool IsConstant() { return IsKind(TypeBase::kConstant); } |
|
Jarin
2016/10/04 13:14:55
IsHeapConstant?
mvstanton
2016/10/05 13:51:10
Done.
|
| + bool IsOtherNumberConstant() { |
| + return IsKind(TypeBase::kOtherNumberConstant); |
| + } |
| bool IsTuple() { return IsKind(TypeBase::kTuple); } |
| ConstantType* AsConstant() { return ConstantType::cast(this); } |
| + OtherNumberConstantType* AsOtherNumberConstant() { |
| + return OtherNumberConstantType::cast(this); |
| + } |
| RangeType* AsRange() { return RangeType::cast(this); } |
| TupleType* AsTuple() { return TupleType::cast(this); } |