Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_TYPES_H_ | 5 #ifndef V8_TYPES_H_ |
| 6 #define V8_TYPES_H_ | 6 #define V8_TYPES_H_ |
| 7 | 7 |
| 8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
| 9 #include "src/factory.h" | 9 #include "src/factory.h" |
| 10 #include "src/handles.h" | 10 #include "src/handles.h" |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ | 342 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ |
| 343 static TypeImpl* type() { \ | 343 static TypeImpl* type() { \ |
| 344 return BitsetType::New(BitsetType::k##type); \ | 344 return BitsetType::New(BitsetType::k##type); \ |
| 345 } \ | 345 } \ |
| 346 static TypeHandle type(Region* region) { \ | 346 static TypeHandle type(Region* region) { \ |
| 347 return BitsetType::New(BitsetType::k##type, region); \ | 347 return BitsetType::New(BitsetType::k##type, region); \ |
| 348 } | 348 } |
| 349 PROPER_BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) | 349 PROPER_BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) |
| 350 #undef DEFINE_TYPE_CONSTRUCTOR | 350 #undef DEFINE_TYPE_CONSTRUCTOR |
| 351 | 351 |
| 352 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ | |
| 353 static TypeImpl* Mask##type##ForTesting() { \ | |
| 354 return BitsetType::New(BitsetType::k##type); \ | |
| 355 } \ | |
| 356 static TypeHandle Mask##type##ForTesting(Region* region) { \ | |
| 357 return BitsetType::New(BitsetType::k##type, region); \ | |
| 358 } | |
| 359 MASK_BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) | |
| 360 #undef DEFINE_TYPE_CONSTRUCTOR | |
| 361 | |
| 352 static TypeImpl* SignedSmall() { | 362 static TypeImpl* SignedSmall() { |
| 353 return BitsetType::New(BitsetType::SignedSmall()); | 363 return BitsetType::New(BitsetType::SignedSmall()); |
| 354 } | 364 } |
| 355 static TypeHandle SignedSmall(Region* region) { | 365 static TypeHandle SignedSmall(Region* region) { |
| 356 return BitsetType::New(BitsetType::SignedSmall(), region); | 366 return BitsetType::New(BitsetType::SignedSmall(), region); |
| 357 } | 367 } |
| 358 static TypeImpl* UnsignedSmall() { | 368 static TypeImpl* UnsignedSmall() { |
| 359 return BitsetType::New(BitsetType::UnsignedSmall()); | 369 return BitsetType::New(BitsetType::UnsignedSmall()); |
| 360 } | 370 } |
| 361 static TypeHandle UnsignedSmall(Region* region) { | 371 static TypeHandle UnsignedSmall(Region* region) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 bool IsAny() { return this == Any(); } | 566 bool IsAny() { return this == Any(); } |
| 557 bool IsBitset() { return Config::is_bitset(this); } | 567 bool IsBitset() { return Config::is_bitset(this); } |
| 558 bool IsUnion() { return Config::is_struct(this, StructuralType::kUnionTag); } | 568 bool IsUnion() { return Config::is_struct(this, StructuralType::kUnionTag); } |
| 559 | 569 |
| 560 bitset AsBitset() { | 570 bitset AsBitset() { |
| 561 DCHECK(this->IsBitset()); | 571 DCHECK(this->IsBitset()); |
| 562 return static_cast<BitsetType*>(this)->Bitset(); | 572 return static_cast<BitsetType*>(this)->Bitset(); |
| 563 } | 573 } |
| 564 UnionType* AsUnion() { return UnionType::cast(this); } | 574 UnionType* AsUnion() { return UnionType::cast(this); } |
| 565 | 575 |
| 576 bitset GetRepresentation(); | |
|
rossberg
2015/02/11 12:34:11
Nit: drop the "Get"
Jarin
2015/02/11 16:10:47
Done.
| |
| 577 | |
| 566 // Auxiliary functions. | 578 // Auxiliary functions. |
| 579 bool SemanticMaybe(TypeImpl* that); | |
| 567 | 580 |
| 568 bitset BitsetGlb() { return BitsetType::Glb(this); } | 581 bitset BitsetGlb() { return BitsetType::Glb(this); } |
| 569 bitset BitsetLub() { return BitsetType::Lub(this); } | 582 bitset BitsetLub() { return BitsetType::Lub(this); } |
| 570 | 583 |
| 571 bool SlowIs(TypeImpl* that); | 584 bool SlowIs(TypeImpl* that); |
| 585 bool SemanticIs(TypeImpl* that); | |
| 572 | 586 |
| 573 static bool IsInteger(double x) { | 587 static bool IsInteger(double x) { |
| 574 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. | 588 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. |
| 575 } | 589 } |
| 576 static bool IsInteger(i::Object* x) { | 590 static bool IsInteger(i::Object* x) { |
| 577 return x->IsNumber() && IsInteger(x->Number()); | 591 return x->IsNumber() && IsInteger(x->Number()); |
| 578 } | 592 } |
| 579 | 593 |
| 580 struct Limits { | 594 struct Limits { |
| 581 double min; | 595 double min; |
| 582 double max; | 596 double max; |
| 583 bitset representation; | 597 Limits(double min, double max) : min(min), max(max) {} |
| 584 Limits(double min, double max, bitset representation) | 598 explicit Limits(RangeType* range) : min(range->Min()), max(range->Max()) {} |
| 585 : min(min), max(max), representation(representation) {} | 599 static Limits Empty(Region* region) { return Limits(1, 0); } |
| 586 explicit Limits(RangeType* range) | |
| 587 : min(range->Min()), | |
| 588 max(range->Max()), | |
| 589 representation(REPRESENTATION(range->Bound())) {} | |
| 590 static Limits Empty(Region* region) { | |
| 591 return Limits(1, 0, BitsetType::kNone); | |
| 592 } | |
| 593 }; | 600 }; |
| 594 | 601 |
| 595 static bool IsEmpty(Limits lim); | 602 static bool IsEmpty(Limits lim); |
| 596 static Limits Intersect(Limits lhs, Limits rhs); | 603 static Limits Intersect(Limits lhs, Limits rhs); |
| 597 static Limits Union(Limits lhs, Limits rhs); | 604 static Limits Union(Limits lhs, Limits rhs); |
| 598 static bool Overlap(RangeType* lhs, RangeType* rhs); | 605 static bool Overlap(RangeType* lhs, RangeType* rhs); |
| 599 static bool Contains(RangeType* lhs, RangeType* rhs); | 606 static bool Contains(RangeType* lhs, RangeType* rhs); |
| 600 static bool Contains(RangeType* range, ConstantType* constant); | 607 static bool Contains(RangeType* range, ConstantType* constant); |
| 601 static bool Contains(RangeType* range, i::Object* val); | 608 static bool Contains(RangeType* range, i::Object* val); |
| 602 | 609 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 bitset Bitset() { return Config::as_bitset(this); } | 649 bitset Bitset() { return Config::as_bitset(this); } |
| 643 | 650 |
| 644 static TypeImpl* New(bitset bits) { | 651 static TypeImpl* New(bitset bits) { |
| 645 if (FLAG_enable_slow_asserts) CheckNumberBits(bits); | 652 if (FLAG_enable_slow_asserts) CheckNumberBits(bits); |
| 646 return Config::from_bitset(bits); | 653 return Config::from_bitset(bits); |
| 647 } | 654 } |
| 648 static TypeHandle New(bitset bits, Region* region) { | 655 static TypeHandle New(bitset bits, Region* region) { |
| 649 if (FLAG_enable_slow_asserts) CheckNumberBits(bits); | 656 if (FLAG_enable_slow_asserts) CheckNumberBits(bits); |
| 650 return Config::from_bitset(bits, region); | 657 return Config::from_bitset(bits, region); |
| 651 } | 658 } |
| 652 // TODO(neis): Eventually allow again for types with empty semantics | |
| 653 // part and modify intersection and possibly subtyping accordingly. | |
| 654 | 659 |
| 655 static bool IsInhabited(bitset bits) { | 660 static bool IsInhabited(bitset bits) { |
| 656 return bits & kSemantic; | 661 return SEMANTIC(bits) != kNone && REPRESENTATION(bits) != kNone; |
| 662 } | |
| 663 | |
| 664 static bool SemanticIsInhabited(bitset bits) { | |
| 665 return SEMANTIC(bits) != kNone; | |
| 657 } | 666 } |
| 658 | 667 |
| 659 static bool Is(bitset bits1, bitset bits2) { | 668 static bool Is(bitset bits1, bitset bits2) { |
| 660 return (bits1 | bits2) == bits2; | 669 return (bits1 | bits2) == bits2; |
| 661 } | 670 } |
| 662 | 671 |
| 663 static double Min(bitset); | 672 static double Min(bitset); |
| 664 static double Max(bitset); | 673 static double Max(bitset); |
| 665 | 674 |
| 666 static bitset Glb(TypeImpl* type); // greatest lower bound that's a bitset | 675 static bitset Glb(TypeImpl* type); // greatest lower bound that's a bitset |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 848 typename Config::template Handle<typename Config::Range>::type range = | 857 typename Config::template Handle<typename Config::Range>::type range = |
| 849 Config::range_create(region); | 858 Config::range_create(region); |
| 850 | 859 |
| 851 bitset bits = SEMANTIC(BitsetType::Lub(min, max)) | representation_bits; | 860 bitset bits = SEMANTIC(BitsetType::Lub(min, max)) | representation_bits; |
| 852 Config::range_set_bitset(range, bits); | 861 Config::range_set_bitset(range, bits); |
| 853 Config::range_set_double(range, 0, min, region); | 862 Config::range_set_double(range, 0, min, region); |
| 854 Config::range_set_double(range, 1, max, region); | 863 Config::range_set_double(range, 1, max, region); |
| 855 return Config::template cast<RangeType>(Config::from_range(range)); | 864 return Config::template cast<RangeType>(Config::from_range(range)); |
| 856 } | 865 } |
| 857 | 866 |
| 858 static RangeHandle New(Limits lim, Region* region) { | 867 static RangeHandle New(Limits lim, bitset representation, Region* region) { |
| 859 return New(lim.min, lim.max, BitsetType::New(lim.representation, region), | 868 return New(lim.min, lim.max, BitsetType::New(representation, region), |
| 860 region); | 869 region); |
| 861 } | 870 } |
| 862 | 871 |
| 863 static RangeType* cast(TypeImpl* type) { | 872 static RangeType* cast(TypeImpl* type) { |
| 864 DCHECK(type->IsRange()); | 873 DCHECK(type->IsRange()); |
| 865 return static_cast<RangeType*>(type); | 874 return static_cast<RangeType*>(type); |
| 866 } | 875 } |
| 867 }; | 876 }; |
| 868 // TODO(neis): Also cache min and max values. | 877 // TODO(neis): Also cache min and max values. |
| 869 // TODO(neis): Allow restricting the representation. | |
| 870 | 878 |
| 871 | 879 |
| 872 // ----------------------------------------------------------------------------- | 880 // ----------------------------------------------------------------------------- |
| 873 // Context types. | 881 // Context types. |
| 874 | 882 |
| 875 template<class Config> | 883 template<class Config> |
| 876 class TypeImpl<Config>::ContextType : public StructuralType { | 884 class TypeImpl<Config>::ContextType : public StructuralType { |
| 877 public: | 885 public: |
| 878 TypeHandle Outer() { return this->Get(0); } | 886 TypeHandle Outer() { return this->Get(0); } |
| 879 | 887 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1149 bool Narrows(BoundsImpl that) { | 1157 bool Narrows(BoundsImpl that) { |
| 1150 return that.lower->Is(this->lower) && this->upper->Is(that.upper); | 1158 return that.lower->Is(this->lower) && this->upper->Is(that.upper); |
| 1151 } | 1159 } |
| 1152 }; | 1160 }; |
| 1153 | 1161 |
| 1154 typedef BoundsImpl<ZoneTypeConfig> Bounds; | 1162 typedef BoundsImpl<ZoneTypeConfig> Bounds; |
| 1155 | 1163 |
| 1156 } } // namespace v8::internal | 1164 } } // namespace v8::internal |
| 1157 | 1165 |
| 1158 #endif // V8_TYPES_H_ | 1166 #endif // V8_TYPES_H_ |
| OLD | NEW |