Chromium Code Reviews| Index: src/compiler/types.h |
| diff --git a/src/compiler/types.h b/src/compiler/types.h |
| index ef5bec3f9de63ac179b3526a7499895179e9405a..9ddf4af9f42cec655f831b48bbb3a915948189f5 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, kNumberConstant, kTuple, kUnion, kRange }; |
| Kind kind() const { return kind_; } |
| explicit TypeBase(Kind kind) : kind_(kind) {} |
| @@ -287,6 +288,42 @@ class TypeBase { |
| // ----------------------------------------------------------------------------- |
| // Constant types. |
| +class NumberConstantType : public TypeBase { |
| + public: |
| + double Value() { return value_; } |
| + |
| + static bool IsNumberConstant(double value) { |
| + // Not an integer, not NaN, and not -0. |
| + return !std::isnan(value) && nearbyint(value) != value && |
|
mvstanton
2016/09/28 14:47:44
make sure you don't allow integers outside of smi
mvstanton
2016/10/04 11:55:55
Done.
|
| + !i::IsMinusZero(value); |
| + } |
| + |
| + private: |
| + friend class Type; |
| + friend class BitsetType; |
| + |
| + static Type* New(double value, Zone* zone) { |
| + BitsetType::bitset bitset = BitsetType::Lub(value); |
| + return AsType(new (zone->New(sizeof(NumberConstantType))) |
| + NumberConstantType(bitset, value)); |
| + } |
| + |
| + static NumberConstantType* cast(Type* type) { |
| + DCHECK(IsKind(type, kNumberConstant)); |
| + return static_cast<NumberConstantType*>(FromType(type)); |
| + } |
| + |
| + NumberConstantType(BitsetType::bitset bitset, double value) |
| + : TypeBase(kNumberConstant), bitset_(bitset), value_(value) { |
| + CHECK(IsNumberConstant(value)); |
| + } |
| + |
| + BitsetType::bitset Lub() { return bitset_; } |
| + |
|
mvstanton
2016/09/28 14:47:44
No need for bitset member.
mvstanton
2016/10/04 11:55:55
Done.
|
| + BitsetType::bitset bitset_; |
| + double value_; |
| +}; |
| + |
| class ConstantType : public TypeBase { |
| public: |
| i::Handle<i::Object> Value() { return object_; } |
| @@ -307,14 +344,18 @@ 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(!object->IsHeapNumber() || |
| + !NumberConstantType::IsNumberConstant( |
| + HeapNumber::cast(*object)->value())); |
|
mvstanton
2016/09/28 14:47:44
Confusing!
mvstanton
2016/10/04 11:55:55
Done.
|
| + } |
| BitsetType::bitset Lub() { return bitset_; } |
| BitsetType::bitset bitset_; |
| Handle<i::Object> object_; |
| }; |
| -// TODO(neis): Also cache value if numerical. |
| // ----------------------------------------------------------------------------- |
| // Range types. |
| @@ -474,6 +515,9 @@ class Type { |
| return BitsetType::New(BitsetType::UnsignedSmall()); |
| } |
| + static Type* NumberConstant(double value, Zone* zone) { |
| + return NumberConstantType::New(value, zone); |
| + } |
| static Type* Constant(i::Handle<i::Object> value, Zone* zone) { |
| return ConstantType::New(value, zone); |
| } |
| @@ -488,6 +532,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 +563,13 @@ class Type { |
| // Inspection. |
| bool IsRange() { return IsKind(TypeBase::kRange); } |
| bool IsConstant() { return IsKind(TypeBase::kConstant); } |
| + bool IsNumberConstant() { return IsKind(TypeBase::kNumberConstant); } |
| bool IsTuple() { return IsKind(TypeBase::kTuple); } |
| ConstantType* AsConstant() { return ConstantType::cast(this); } |
| + NumberConstantType* AsNumberConstant() { |
| + return NumberConstantType::cast(this); |
| + } |
| RangeType* AsRange() { return RangeType::cast(this); } |
| TupleType* AsTuple() { return TupleType::cast(this); } |
| @@ -583,6 +634,7 @@ class Type { |
| static bool Overlap(RangeType* lhs, RangeType* rhs); |
| static bool Contains(RangeType* lhs, RangeType* rhs); |
| static bool Contains(RangeType* range, ConstantType* constant); |
| + static bool Contains(RangeType* range, NumberConstantType* constant); |
| static bool Contains(RangeType* range, i::Object* val); |
| static int UpdateRange(Type* type, UnionType* result, int size, Zone* zone); |