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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 | 538 |
529 enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM }; | 539 enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM }; |
530 | 540 |
531 void PrintTo(std::ostream& os, PrintDimension dim = BOTH_DIMS); // NOLINT | 541 void PrintTo(std::ostream& os, PrintDimension dim = BOTH_DIMS); // NOLINT |
532 | 542 |
533 #ifdef DEBUG | 543 #ifdef DEBUG |
534 void Print(); | 544 void Print(); |
535 #endif | 545 #endif |
536 | 546 |
537 bool IsUnionForTesting() { return IsUnion(); } | 547 bool IsUnionForTesting() { return IsUnion(); } |
| 548 bitset GetRepresentationForTesting() { return GetRepresentation(); } |
538 | 549 |
539 protected: | 550 protected: |
540 // Friends. | 551 // Friends. |
541 | 552 |
542 template<class> friend class Iterator; | 553 template<class> friend class Iterator; |
543 template<class> friend class TypeImpl; | 554 template<class> friend class TypeImpl; |
544 | 555 |
545 // Handle conversion. | 556 // Handle conversion. |
546 | 557 |
547 template<class T> | 558 template<class T> |
548 static typename Config::template Handle<T>::type handle(T* type) { | 559 static typename Config::template Handle<T>::type handle(T* type) { |
549 return Config::handle(type); | 560 return Config::handle(type); |
550 } | 561 } |
551 TypeImpl* unhandle() { return this; } | 562 TypeImpl* unhandle() { return this; } |
552 | 563 |
553 // Internal inspection. | 564 // Internal inspection. |
554 | 565 |
555 bool IsNone() { return this == None(); } | 566 bool IsNone() { return this == None(); } |
556 bool IsAny() { return this == Any(); } | 567 bool IsAny() { return this == Any(); } |
557 bool IsBitset() { return Config::is_bitset(this); } | 568 bool IsBitset() { return Config::is_bitset(this); } |
558 bool IsUnion() { return Config::is_struct(this, StructuralType::kUnionTag); } | 569 bool IsUnion() { return Config::is_struct(this, StructuralType::kUnionTag); } |
559 | 570 |
560 bitset AsBitset() { | 571 bitset AsBitset() { |
561 DCHECK(this->IsBitset()); | 572 DCHECK(this->IsBitset()); |
562 return static_cast<BitsetType*>(this)->Bitset(); | 573 return static_cast<BitsetType*>(this)->Bitset(); |
563 } | 574 } |
564 UnionType* AsUnion() { return UnionType::cast(this); } | 575 UnionType* AsUnion() { return UnionType::cast(this); } |
565 | 576 |
| 577 bitset GetRepresentation(); |
| 578 |
566 // Auxiliary functions. | 579 // Auxiliary functions. |
| 580 bool SemanticMaybe(TypeImpl* that); |
567 | 581 |
568 bitset BitsetGlb() { return BitsetType::Glb(this); } | 582 bitset BitsetGlb() { return BitsetType::Glb(this); } |
569 bitset BitsetLub() { return BitsetType::Lub(this); } | 583 bitset BitsetLub() { return BitsetType::Lub(this); } |
570 | 584 |
571 bool SlowIs(TypeImpl* that); | 585 bool SlowIs(TypeImpl* that); |
| 586 bool SemanticIs(TypeImpl* that); |
572 | 587 |
573 static bool IsInteger(double x) { | 588 static bool IsInteger(double x) { |
574 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. | 589 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. |
575 } | 590 } |
576 static bool IsInteger(i::Object* x) { | 591 static bool IsInteger(i::Object* x) { |
577 return x->IsNumber() && IsInteger(x->Number()); | 592 return x->IsNumber() && IsInteger(x->Number()); |
578 } | 593 } |
579 | 594 |
580 struct Limits { | 595 struct Limits { |
581 double min; | 596 double min; |
582 double max; | 597 double max; |
583 bitset representation; | 598 Limits(double min, double max) : min(min), max(max) {} |
584 Limits(double min, double max, bitset representation) | 599 explicit Limits(RangeType* range) : min(range->Min()), max(range->Max()) {} |
585 : min(min), max(max), representation(representation) {} | 600 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 }; | 601 }; |
594 | 602 |
595 static bool IsEmpty(Limits lim); | 603 static bool IsEmpty(Limits lim); |
596 static Limits Intersect(Limits lhs, Limits rhs); | 604 static Limits Intersect(Limits lhs, Limits rhs); |
597 static Limits Union(Limits lhs, Limits rhs); | 605 static Limits Union(Limits lhs, Limits rhs); |
598 static bool Overlap(RangeType* lhs, RangeType* rhs); | 606 static bool Overlap(RangeType* lhs, RangeType* rhs); |
599 static bool Contains(RangeType* lhs, RangeType* rhs); | 607 static bool Contains(RangeType* lhs, RangeType* rhs); |
600 static bool Contains(RangeType* range, ConstantType* constant); | 608 static bool Contains(RangeType* range, ConstantType* constant); |
601 static bool Contains(RangeType* range, i::Object* val); | 609 static bool Contains(RangeType* range, i::Object* val); |
602 | 610 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 bitset Bitset() { return Config::as_bitset(this); } | 650 bitset Bitset() { return Config::as_bitset(this); } |
643 | 651 |
644 static TypeImpl* New(bitset bits) { | 652 static TypeImpl* New(bitset bits) { |
645 if (FLAG_enable_slow_asserts) CheckNumberBits(bits); | 653 if (FLAG_enable_slow_asserts) CheckNumberBits(bits); |
646 return Config::from_bitset(bits); | 654 return Config::from_bitset(bits); |
647 } | 655 } |
648 static TypeHandle New(bitset bits, Region* region) { | 656 static TypeHandle New(bitset bits, Region* region) { |
649 if (FLAG_enable_slow_asserts) CheckNumberBits(bits); | 657 if (FLAG_enable_slow_asserts) CheckNumberBits(bits); |
650 return Config::from_bitset(bits, region); | 658 return Config::from_bitset(bits, region); |
651 } | 659 } |
652 // TODO(neis): Eventually allow again for types with empty semantics | |
653 // part and modify intersection and possibly subtyping accordingly. | |
654 | 660 |
655 static bool IsInhabited(bitset bits) { | 661 static bool IsInhabited(bitset bits) { |
656 return bits & kSemantic; | 662 return SEMANTIC(bits) != kNone && REPRESENTATION(bits) != kNone; |
| 663 } |
| 664 |
| 665 static bool SemanticIsInhabited(bitset bits) { |
| 666 return SEMANTIC(bits) != kNone; |
657 } | 667 } |
658 | 668 |
659 static bool Is(bitset bits1, bitset bits2) { | 669 static bool Is(bitset bits1, bitset bits2) { |
660 return (bits1 | bits2) == bits2; | 670 return (bits1 | bits2) == bits2; |
661 } | 671 } |
662 | 672 |
663 static double Min(bitset); | 673 static double Min(bitset); |
664 static double Max(bitset); | 674 static double Max(bitset); |
665 | 675 |
666 static bitset Glb(TypeImpl* type); // greatest lower bound that's a bitset | 676 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 = | 858 typename Config::template Handle<typename Config::Range>::type range = |
849 Config::range_create(region); | 859 Config::range_create(region); |
850 | 860 |
851 bitset bits = SEMANTIC(BitsetType::Lub(min, max)) | representation_bits; | 861 bitset bits = SEMANTIC(BitsetType::Lub(min, max)) | representation_bits; |
852 Config::range_set_bitset(range, bits); | 862 Config::range_set_bitset(range, bits); |
853 Config::range_set_double(range, 0, min, region); | 863 Config::range_set_double(range, 0, min, region); |
854 Config::range_set_double(range, 1, max, region); | 864 Config::range_set_double(range, 1, max, region); |
855 return Config::template cast<RangeType>(Config::from_range(range)); | 865 return Config::template cast<RangeType>(Config::from_range(range)); |
856 } | 866 } |
857 | 867 |
858 static RangeHandle New(Limits lim, Region* region) { | 868 static RangeHandle New(Limits lim, bitset representation, Region* region) { |
859 return New(lim.min, lim.max, BitsetType::New(lim.representation, region), | 869 return New(lim.min, lim.max, BitsetType::New(representation, region), |
860 region); | 870 region); |
861 } | 871 } |
862 | 872 |
863 static RangeType* cast(TypeImpl* type) { | 873 static RangeType* cast(TypeImpl* type) { |
864 DCHECK(type->IsRange()); | 874 DCHECK(type->IsRange()); |
865 return static_cast<RangeType*>(type); | 875 return static_cast<RangeType*>(type); |
866 } | 876 } |
867 }; | 877 }; |
868 // TODO(neis): Also cache min and max values. | 878 // TODO(neis): Also cache min and max values. |
869 // TODO(neis): Allow restricting the representation. | |
870 | 879 |
871 | 880 |
872 // ----------------------------------------------------------------------------- | 881 // ----------------------------------------------------------------------------- |
873 // Context types. | 882 // Context types. |
874 | 883 |
875 template<class Config> | 884 template<class Config> |
876 class TypeImpl<Config>::ContextType : public StructuralType { | 885 class TypeImpl<Config>::ContextType : public StructuralType { |
877 public: | 886 public: |
878 TypeHandle Outer() { return this->Get(0); } | 887 TypeHandle Outer() { return this->Get(0); } |
879 | 888 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 bool Narrows(BoundsImpl that) { | 1158 bool Narrows(BoundsImpl that) { |
1150 return that.lower->Is(this->lower) && this->upper->Is(that.upper); | 1159 return that.lower->Is(this->lower) && this->upper->Is(that.upper); |
1151 } | 1160 } |
1152 }; | 1161 }; |
1153 | 1162 |
1154 typedef BoundsImpl<ZoneTypeConfig> Bounds; | 1163 typedef BoundsImpl<ZoneTypeConfig> Bounds; |
1155 | 1164 |
1156 } } // namespace v8::internal | 1165 } } // namespace v8::internal |
1157 | 1166 |
1158 #endif // V8_TYPES_H_ | 1167 #endif // V8_TYPES_H_ |
OLD | NEW |