Chromium Code Reviews| Index: src/compiler/types.cc |
| diff --git a/src/compiler/types.cc b/src/compiler/types.cc |
| index 43d2f804837b1ce596b0c8a7235e63dc11b18b49..a375ffb50c6652e07e7bb3d8f1b94bc5174b05cd 100644 |
| --- a/src/compiler/types.cc |
| +++ b/src/compiler/types.cc |
| @@ -62,6 +62,12 @@ bool Type::Contains(RangeType* lhs, ConstantType* rhs) { |
| rhs->Value()->Number() <= lhs->Max(); |
| } |
| +bool Type::Contains(RangeType* lhs, NumberConstantType* rhs) { |
| + DisallowHeapAllocation no_allocation; |
| + return IsInteger(rhs->Value()) && lhs->Min() <= rhs->Value() && |
|
mvstanton
2016/09/28 14:47:44
Actually don't do this - a numberconstant is NEVER
mvstanton
2016/10/04 11:55:55
Done.
|
| + rhs->Value() <= lhs->Max(); |
| +} |
| + |
| bool Type::Contains(RangeType* range, i::Object* val) { |
| DisallowHeapAllocation no_allocation; |
| return IsInteger(val) && range->Min() <= val->Number() && |
| @@ -83,6 +89,7 @@ double Type::Min() { |
| } |
| if (this->IsRange()) return this->AsRange()->Min(); |
| if (this->IsConstant()) return this->AsConstant()->Value()->Number(); |
| + if (this->IsNumberConstant()) return this->AsNumberConstant()->Value(); |
| UNREACHABLE(); |
| return 0; |
| } |
| @@ -99,6 +106,7 @@ double Type::Max() { |
| } |
| if (this->IsRange()) return this->AsRange()->Max(); |
| if (this->IsConstant()) return this->AsConstant()->Value()->Number(); |
| + if (this->IsNumberConstant()) return this->AsNumberConstant()->Value(); |
| UNREACHABLE(); |
| return 0; |
| } |
| @@ -140,6 +148,7 @@ Type::bitset BitsetType::Lub(Type* type) { |
| return bitset; |
| } |
| if (type->IsConstant()) return type->AsConstant()->Lub(); |
| + if (type->IsNumberConstant()) return type->AsNumberConstant()->Lub(); |
| if (type->IsRange()) return type->AsRange()->Lub(); |
| if (type->IsTuple()) return kOtherInternal; |
| UNREACHABLE(); |
| @@ -399,6 +408,11 @@ bool Type::SimplyEquals(Type* that) { |
| return that->IsConstant() && |
| *this->AsConstant()->Value() == *that->AsConstant()->Value(); |
| } |
| + if (this->IsNumberConstant()) { |
| + return that->IsNumberConstant() && |
| + this->AsNumberConstant()->Value() == |
| + that->AsNumberConstant()->Value(); |
| + } |
| if (this->IsTuple()) { |
| if (!that->IsTuple()) return false; |
| TupleType* this_tuple = this->AsTuple(); |
| @@ -484,6 +498,9 @@ bool Type::Maybe(Type* that) { |
| if (that->IsConstant()) { |
| return Contains(this->AsRange(), that->AsConstant()); |
| } |
| + if (that->IsNumberConstant()) { |
| + return Contains(this->AsRange(), that->AsNumberConstant()); |
| + } |
| if (that->IsRange()) { |
| return Overlap(this->AsRange(), that->AsRange()); |
| } |
| @@ -676,6 +693,10 @@ int Type::IntersectAux(Type* lhs, Type* rhs, UnionType* result, int size, |
| if (rhs->IsConstant() && Contains(lhs->AsRange(), rhs->AsConstant())) { |
| return AddToUnion(rhs, result, size, zone); |
| } |
| + if (rhs->IsNumberConstant() && |
| + Contains(lhs->AsRange(), rhs->AsNumberConstant())) { |
| + return AddToUnion(rhs, result, size, zone); |
|
mvstanton
2016/09/28 14:47:44
leave this out, because a range cannot contain a n
mvstanton
2016/10/04 11:55:55
Done.
|
| + } |
| if (rhs->IsRange()) { |
| RangeType::Limits lim = RangeType::Limits::Intersect( |
| RangeType::Limits(lhs->AsRange()), RangeType::Limits(rhs->AsRange())); |
| @@ -743,6 +764,20 @@ Type* Type::NormalizeRangeAndBitset(Type* range, bitset* bits, Zone* zone) { |
| return RangeType::New(range_min, range_max, zone); |
| } |
| +Type* Type::NewConstant(i::Handle<i::Object> value, Zone* zone) { |
| + if (IsInteger(*value)) { |
| + double v = value->IsSmi() ? Smi::cast(*value)->value() |
| + : HeapNumber::cast(*value)->value(); |
| + return Range(v, v, zone); |
| + } else if (value->IsHeapNumber()) { |
| + double v = HeapNumber::cast(*value)->value(); |
| + if (NumberConstantType::IsNumberConstant(v)) { |
| + return NumberConstant(v, zone); |
| + } |
| + } |
| + return Constant(value, zone); |
|
mvstanton
2016/09/28 14:47:44
drive by comment - shouldn't we canonicalize NaN a
mvstanton
2016/10/04 11:55:55
Done.
|
| +} |
|
mvstanton
2016/09/28 14:47:44
Also, a separate CL to land after would make sure
|
| + |
| Type* Type::Union(Type* type1, Type* type2, Zone* zone) { |
| // Fast case: bit sets. |
| if (type1->IsBitset() && type2->IsBitset()) { |
| @@ -833,12 +868,9 @@ Type* Type::NormalizeUnion(Type* union_type, int size, Zone* zone) { |
| return union_type; |
| } |
| -// ----------------------------------------------------------------------------- |
| -// Iteration. |
| - |
| int Type::NumConstants() { |
| DisallowHeapAllocation no_allocation; |
| - if (this->IsConstant()) { |
| + if (this->IsConstant() || this->IsNumberConstant()) { |
| return 1; |
| } else if (this->IsUnion()) { |
| int result = 0; |
| @@ -907,6 +939,8 @@ void Type::PrintTo(std::ostream& os) { |
| BitsetType::Print(os, this->AsBitset()); |
| } else if (this->IsConstant()) { |
| os << "Constant(" << Brief(*this->AsConstant()->Value()) << ")"; |
| + } else if (this->IsNumberConstant()) { |
| + os << "NumberConstant(" << this->AsNumberConstant()->Value() << ")"; |
| } else if (this->IsRange()) { |
| std::ostream::fmtflags saved_flags = os.setf(std::ios::fixed); |
| std::streamsize saved_precision = os.precision(0); |