Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Side by Side Diff: src/types.cc

Issue 600713003: Move union length computation out of loops. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "src/types.h" 5 #include "src/types.h"
6 6
7 #include "src/ostreams.h" 7 #include "src/ostreams.h"
8 #include "src/types-inl.h" 8 #include "src/types-inl.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 // ----------------------------------------------------------------------------- 74 // -----------------------------------------------------------------------------
75 // Min and Max computation. 75 // Min and Max computation.
76 76
77 template<class Config> 77 template<class Config>
78 double TypeImpl<Config>::Min() { 78 double TypeImpl<Config>::Min() {
79 DCHECK(this->Is(Number())); 79 DCHECK(this->Is(Number()));
80 if (this->IsBitset()) return BitsetType::Min(this->AsBitset()); 80 if (this->IsBitset()) return BitsetType::Min(this->AsBitset());
81 if (this->IsUnion()) { 81 if (this->IsUnion()) {
82 double min = +V8_INFINITY; 82 double min = +V8_INFINITY;
83 for (int i = 0; i < this->AsUnion()->Length(); ++i) { 83 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
84 min = std::min(min, this->AsUnion()->Get(i)->Min()); 84 min = std::min(min, this->AsUnion()->Get(i)->Min());
85 } 85 }
86 return min; 86 return min;
87 } 87 }
88 if (this->IsRange()) return this->AsRange()->Min()->Number(); 88 if (this->IsRange()) return this->AsRange()->Min()->Number();
89 if (this->IsConstant()) return this->AsConstant()->Value()->Number(); 89 if (this->IsConstant()) return this->AsConstant()->Value()->Number();
90 UNREACHABLE(); 90 UNREACHABLE();
91 return 0; 91 return 0;
92 } 92 }
93 93
94 94
95 template<class Config> 95 template<class Config>
96 double TypeImpl<Config>::Max() { 96 double TypeImpl<Config>::Max() {
97 DCHECK(this->Is(Number())); 97 DCHECK(this->Is(Number()));
98 if (this->IsBitset()) return BitsetType::Max(this->AsBitset()); 98 if (this->IsBitset()) return BitsetType::Max(this->AsBitset());
99 if (this->IsUnion()) { 99 if (this->IsUnion()) {
100 double max = -V8_INFINITY; 100 double max = -V8_INFINITY;
101 for (int i = 0; i < this->AsUnion()->Length(); ++i) { 101 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
102 max = std::max(max, this->AsUnion()->Get(i)->Max()); 102 max = std::max(max, this->AsUnion()->Get(i)->Max());
103 } 103 }
104 return max; 104 return max;
105 } 105 }
106 if (this->IsRange()) return this->AsRange()->Max()->Number(); 106 if (this->IsRange()) return this->AsRange()->Max()->Number();
107 if (this->IsConstant()) return this->AsConstant()->Value()->Number(); 107 if (this->IsConstant()) return this->AsConstant()->Value()->Number();
108 UNREACHABLE(); 108 UNREACHABLE();
109 return 0; 109 return 0;
110 } 110 }
111 111
(...skipping 20 matching lines...) Expand all
132 132
133 133
134 // The smallest bitset subsuming this type. 134 // The smallest bitset subsuming this type.
135 template<class Config> 135 template<class Config>
136 typename TypeImpl<Config>::bitset 136 typename TypeImpl<Config>::bitset
137 TypeImpl<Config>::BitsetType::Lub(TypeImpl* type) { 137 TypeImpl<Config>::BitsetType::Lub(TypeImpl* type) {
138 DisallowHeapAllocation no_allocation; 138 DisallowHeapAllocation no_allocation;
139 if (type->IsBitset()) return type->AsBitset(); 139 if (type->IsBitset()) return type->AsBitset();
140 if (type->IsUnion()) { 140 if (type->IsUnion()) {
141 int bitset = kNone; 141 int bitset = kNone;
142 for (int i = 0; i < type->AsUnion()->Length(); ++i) { 142 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) {
143 bitset |= type->AsUnion()->Get(i)->BitsetLub(); 143 bitset |= type->AsUnion()->Get(i)->BitsetLub();
144 } 144 }
145 return bitset; 145 return bitset;
146 } 146 }
147 if (type->IsClass()) { 147 if (type->IsClass()) {
148 // Little hack to avoid the need for a region for handlification here... 148 // Little hack to avoid the need for a region for handlification here...
149 return Config::is_class(type) ? Lub(*Config::as_class(type)) : 149 return Config::is_class(type) ? Lub(*Config::as_class(type)) :
150 type->AsClass()->Bound(NULL)->AsBitset(); 150 type->AsClass()->Bound(NULL)->AsBitset();
151 } 151 }
152 if (type->IsConstant()) return type->AsConstant()->Bound()->AsBitset(); 152 if (type->IsConstant()) return type->AsConstant()->Bound()->AsBitset();
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 412 }
413 if (this->IsFunction()) { 413 if (this->IsFunction()) {
414 if (!that->IsFunction()) return false; 414 if (!that->IsFunction()) return false;
415 FunctionType* this_fun = this->AsFunction(); 415 FunctionType* this_fun = this->AsFunction();
416 FunctionType* that_fun = that->AsFunction(); 416 FunctionType* that_fun = that->AsFunction();
417 if (this_fun->Arity() != that_fun->Arity() || 417 if (this_fun->Arity() != that_fun->Arity() ||
418 !this_fun->Result()->Equals(that_fun->Result()) || 418 !this_fun->Result()->Equals(that_fun->Result()) ||
419 !this_fun->Receiver()->Equals(that_fun->Receiver())) { 419 !this_fun->Receiver()->Equals(that_fun->Receiver())) {
420 return false; 420 return false;
421 } 421 }
422 for (int i = 0; i < this_fun->Arity(); ++i) { 422 for (int i = 0, n = this_fun->Arity(); i < n; ++i) {
423 if (!this_fun->Parameter(i)->Equals(that_fun->Parameter(i))) return false; 423 if (!this_fun->Parameter(i)->Equals(that_fun->Parameter(i))) return false;
424 } 424 }
425 return true; 425 return true;
426 } 426 }
427 UNREACHABLE(); 427 UNREACHABLE();
428 return false; 428 return false;
429 } 429 }
430 430
431 431
432 // Check if [this] <= [that]. 432 // Check if [this] <= [that].
433 template<class Config> 433 template<class Config>
434 bool TypeImpl<Config>::SlowIs(TypeImpl* that) { 434 bool TypeImpl<Config>::SlowIs(TypeImpl* that) {
435 DisallowHeapAllocation no_allocation; 435 DisallowHeapAllocation no_allocation;
436 436
437 if (that->IsBitset()) { 437 if (that->IsBitset()) {
438 return BitsetType::Is(this->BitsetLub(), that->AsBitset()); 438 return BitsetType::Is(this->BitsetLub(), that->AsBitset());
439 } 439 }
440 if (this->IsBitset()) { 440 if (this->IsBitset()) {
441 return BitsetType::Is(this->AsBitset(), that->BitsetGlb()); 441 return BitsetType::Is(this->AsBitset(), that->BitsetGlb());
442 } 442 }
443 443
444 // (T1 \/ ... \/ Tn) <= T if (T1 <= T) /\ ... /\ (Tn <= T) 444 // (T1 \/ ... \/ Tn) <= T if (T1 <= T) /\ ... /\ (Tn <= T)
445 if (this->IsUnion()) { 445 if (this->IsUnion()) {
446 UnionHandle unioned = handle(this->AsUnion()); 446 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
447 for (int i = 0; i < unioned->Length(); ++i) { 447 if (!this->AsUnion()->Get(i)->Is(that)) return false;
448 if (!unioned->Get(i)->Is(that)) return false;
449 } 448 }
450 return true; 449 return true;
451 } 450 }
452 451
453 // T <= (T1 \/ ... \/ Tn) if (T <= T1) \/ ... \/ (T <= Tn) 452 // T <= (T1 \/ ... \/ Tn) if (T <= T1) \/ ... \/ (T <= Tn)
454 if (that->IsUnion()) { 453 if (that->IsUnion()) {
455 for (int i = 0; i < that->AsUnion()->Length(); ++i) { 454 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) {
456 if (this->Is(that->AsUnion()->Get(i))) return true; 455 if (this->Is(that->AsUnion()->Get(i))) return true;
457 if (i > 1 && this->IsRange()) return false; // Shortcut. 456 if (i > 1 && this->IsRange()) return false; // Shortcut.
458 } 457 }
459 return false; 458 return false;
460 } 459 }
461 460
462 if (that->IsRange()) { 461 if (that->IsRange()) {
463 return (this->IsRange() && Contains(that->AsRange(), this->AsRange())) 462 return (this->IsRange() && Contains(that->AsRange(), this->AsRange()))
464 || (this->IsConstant() && 463 || (this->IsConstant() &&
465 Contains(that->AsRange(), *this->AsConstant()->Value())); 464 Contains(that->AsRange(), *this->AsConstant()->Value()));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 } 499 }
501 500
502 501
503 // Check if [this] and [that] overlap. 502 // Check if [this] and [that] overlap.
504 template<class Config> 503 template<class Config>
505 bool TypeImpl<Config>::Maybe(TypeImpl* that) { 504 bool TypeImpl<Config>::Maybe(TypeImpl* that) {
506 DisallowHeapAllocation no_allocation; 505 DisallowHeapAllocation no_allocation;
507 506
508 // (T1 \/ ... \/ Tn) overlaps T if (T1 overlaps T) \/ ... \/ (Tn overlaps T) 507 // (T1 \/ ... \/ Tn) overlaps T if (T1 overlaps T) \/ ... \/ (Tn overlaps T)
509 if (this->IsUnion()) { 508 if (this->IsUnion()) {
510 UnionHandle unioned = handle(this->AsUnion()); 509 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
511 for (int i = 0; i < unioned->Length(); ++i) { 510 if (this->AsUnion()->Get(i)->Maybe(that)) return true;
512 if (unioned->Get(i)->Maybe(that)) return true;
513 } 511 }
514 return false; 512 return false;
515 } 513 }
516 514
517 // T overlaps (T1 \/ ... \/ Tn) if (T overlaps T1) \/ ... \/ (T overlaps Tn) 515 // T overlaps (T1 \/ ... \/ Tn) if (T overlaps T1) \/ ... \/ (T overlaps Tn)
518 if (that->IsUnion()) { 516 if (that->IsUnion()) {
519 for (int i = 0; i < that->AsUnion()->Length(); ++i) { 517 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) {
520 if (this->Maybe(that->AsUnion()->Get(i))) return true; 518 if (this->Maybe(that->AsUnion()->Get(i))) return true;
521 } 519 }
522 return false; 520 return false;
523 } 521 }
524 522
525 if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub())) 523 if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub()))
526 return false; 524 return false;
527 if (this->IsBitset() || that->IsBitset()) return true; 525 if (this->IsBitset() || that->IsBitset()) return true;
528 526
529 if (this->IsClass() != that->IsClass()) return true; 527 if (this->IsClass() != that->IsClass()) return true;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 } 674 }
677 return size; 675 return size;
678 } 676 }
679 677
680 678
681 template<class Config> 679 template<class Config>
682 int TypeImpl<Config>::IntersectAux( 680 int TypeImpl<Config>::IntersectAux(
683 TypeHandle lhs, TypeHandle rhs, 681 TypeHandle lhs, TypeHandle rhs,
684 UnionHandle result, int size, Region* region) { 682 UnionHandle result, int size, Region* region) {
685 if (lhs->IsUnion()) { 683 if (lhs->IsUnion()) {
686 for (int i = 0; i < lhs->AsUnion()->Length(); ++i) { 684 for (int i = 0, n = lhs->AsUnion()->Length(); i < n; ++i) {
687 size = IntersectAux(lhs->AsUnion()->Get(i), rhs, result, size, region); 685 size = IntersectAux(lhs->AsUnion()->Get(i), rhs, result, size, region);
688 } 686 }
689 return size; 687 return size;
690 } 688 }
691 if (rhs->IsUnion()) { 689 if (rhs->IsUnion()) {
692 for (int i = 0; i < rhs->AsUnion()->Length(); ++i) { 690 for (int i = 0, n = rhs->AsUnion()->Length(); i < n; ++i) {
693 size = IntersectAux(lhs, rhs->AsUnion()->Get(i), result, size, region); 691 size = IntersectAux(lhs, rhs->AsUnion()->Get(i), result, size, region);
694 } 692 }
695 return size; 693 return size;
696 } 694 }
697 695
698 if (!BitsetType::IsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) { 696 if (!BitsetType::IsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) {
699 return size; 697 return size;
700 } 698 }
701 699
702 if (lhs->IsRange()) { 700 if (lhs->IsRange()) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 } 784 }
787 785
788 786
789 // Add [type] to [result] unless [type] is bitset, range, or already subsumed. 787 // Add [type] to [result] unless [type] is bitset, range, or already subsumed.
790 // Return new size of [result]. 788 // Return new size of [result].
791 template<class Config> 789 template<class Config>
792 int TypeImpl<Config>::AddToUnion( 790 int TypeImpl<Config>::AddToUnion(
793 TypeHandle type, UnionHandle result, int size, Region* region) { 791 TypeHandle type, UnionHandle result, int size, Region* region) {
794 if (type->IsBitset() || type->IsRange()) return size; 792 if (type->IsBitset() || type->IsRange()) return size;
795 if (type->IsUnion()) { 793 if (type->IsUnion()) {
796 for (int i = 0; i < type->AsUnion()->Length(); ++i) { 794 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) {
797 size = AddToUnion(type->AsUnion()->Get(i), result, size, region); 795 size = AddToUnion(type->AsUnion()->Get(i), result, size, region);
798 } 796 }
799 return size; 797 return size;
800 } 798 }
801 for (int i = 0; i < size; ++i) { 799 for (int i = 0; i < size; ++i) {
802 if (type->Is(result->Get(i))) return size; 800 if (type->Is(result->Get(i))) return size;
803 } 801 }
804 result->Set(size++, type); 802 result->Set(size++, type);
805 return size; 803 return size;
806 } 804 }
(...skipping 20 matching lines...) Expand all
827 825
828 // ----------------------------------------------------------------------------- 826 // -----------------------------------------------------------------------------
829 // Iteration. 827 // Iteration.
830 828
831 template<class Config> 829 template<class Config>
832 int TypeImpl<Config>::NumClasses() { 830 int TypeImpl<Config>::NumClasses() {
833 DisallowHeapAllocation no_allocation; 831 DisallowHeapAllocation no_allocation;
834 if (this->IsClass()) { 832 if (this->IsClass()) {
835 return 1; 833 return 1;
836 } else if (this->IsUnion()) { 834 } else if (this->IsUnion()) {
837 UnionHandle unioned = handle(this->AsUnion());
838 int result = 0; 835 int result = 0;
839 for (int i = 0; i < unioned->Length(); ++i) { 836 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
840 if (unioned->Get(i)->IsClass()) ++result; 837 if (this->AsUnion()->Get(i)->IsClass()) ++result;
841 } 838 }
842 return result; 839 return result;
843 } else { 840 } else {
844 return 0; 841 return 0;
845 } 842 }
846 } 843 }
847 844
848 845
849 template<class Config> 846 template<class Config>
850 int TypeImpl<Config>::NumConstants() { 847 int TypeImpl<Config>::NumConstants() {
851 DisallowHeapAllocation no_allocation; 848 DisallowHeapAllocation no_allocation;
852 if (this->IsConstant()) { 849 if (this->IsConstant()) {
853 return 1; 850 return 1;
854 } else if (this->IsUnion()) { 851 } else if (this->IsUnion()) {
855 UnionHandle unioned = handle(this->AsUnion());
856 int result = 0; 852 int result = 0;
857 for (int i = 0; i < unioned->Length(); ++i) { 853 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
858 if (unioned->Get(i)->IsConstant()) ++result; 854 if (this->AsUnion()->Get(i)->IsConstant()) ++result;
859 } 855 }
860 return result; 856 return result;
861 } else { 857 } else {
862 return 0; 858 return 0;
863 } 859 }
864 } 860 }
865 861
866 862
867 template<class Config> template<class T> 863 template<class Config> template<class T>
868 typename TypeImpl<Config>::TypeHandle 864 typename TypeImpl<Config>::TypeHandle
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 i::Handle<T> TypeImpl<Config>::Iterator<T>::Current() { 906 i::Handle<T> TypeImpl<Config>::Iterator<T>::Current() {
911 return TypeImplIteratorAux<Config, T>::current(get_type()); 907 return TypeImplIteratorAux<Config, T>::current(get_type());
912 } 908 }
913 909
914 910
915 template<class Config> template<class T> 911 template<class Config> template<class T>
916 void TypeImpl<Config>::Iterator<T>::Advance() { 912 void TypeImpl<Config>::Iterator<T>::Advance() {
917 DisallowHeapAllocation no_allocation; 913 DisallowHeapAllocation no_allocation;
918 ++index_; 914 ++index_;
919 if (type_->IsUnion()) { 915 if (type_->IsUnion()) {
920 UnionHandle unioned = Config::template cast<UnionType>(type_); 916 for (int n = type_->AsUnion()->Length(); index_ < n; ++index_) {
921 for (; index_ < unioned->Length(); ++index_) { 917 if (matches(type_->AsUnion()->Get(index_))) return;
922 if (matches(unioned->Get(index_))) return;
923 } 918 }
924 } else if (index_ == 0 && matches(type_)) { 919 } else if (index_ == 0 && matches(type_)) {
925 return; 920 return;
926 } 921 }
927 index_ = -1; 922 index_ = -1;
928 } 923 }
929 924
930 925
931 // ----------------------------------------------------------------------------- 926 // -----------------------------------------------------------------------------
932 // Conversion between low-level representations. 927 // Conversion between low-level representations.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 << ")"; 1045 << ")";
1051 } else if (this->IsRange()) { 1046 } else if (this->IsRange()) {
1052 os << "Range(" << this->AsRange()->Min()->Number() 1047 os << "Range(" << this->AsRange()->Min()->Number()
1053 << ", " << this->AsRange()->Max()->Number() << ")"; 1048 << ", " << this->AsRange()->Max()->Number() << ")";
1054 } else if (this->IsContext()) { 1049 } else if (this->IsContext()) {
1055 os << "Context("; 1050 os << "Context(";
1056 this->AsContext()->Outer()->PrintTo(os, dim); 1051 this->AsContext()->Outer()->PrintTo(os, dim);
1057 os << ")"; 1052 os << ")";
1058 } else if (this->IsUnion()) { 1053 } else if (this->IsUnion()) {
1059 os << "("; 1054 os << "(";
1060 UnionHandle unioned = handle(this->AsUnion()); 1055 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
1061 for (int i = 0; i < unioned->Length(); ++i) { 1056 TypeHandle type_i = this->AsUnion()->Get(i);
1062 TypeHandle type_i = unioned->Get(i);
1063 if (i > 0) os << " | "; 1057 if (i > 0) os << " | ";
1064 type_i->PrintTo(os, dim); 1058 type_i->PrintTo(os, dim);
1065 } 1059 }
1066 os << ")"; 1060 os << ")";
1067 } else if (this->IsArray()) { 1061 } else if (this->IsArray()) {
1068 os << "Array("; 1062 os << "Array(";
1069 AsArray()->Element()->PrintTo(os, dim); 1063 AsArray()->Element()->PrintTo(os, dim);
1070 os << ")"; 1064 os << ")";
1071 } else if (this->IsFunction()) { 1065 } else if (this->IsFunction()) {
1072 if (!this->AsFunction()->Receiver()->IsAny()) { 1066 if (!this->AsFunction()->Receiver()->IsAny()) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; 1113 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>;
1120 1114
1121 template TypeImpl<ZoneTypeConfig>::TypeHandle 1115 template TypeImpl<ZoneTypeConfig>::TypeHandle
1122 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( 1116 TypeImpl<ZoneTypeConfig>::Convert<HeapType>(
1123 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); 1117 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*);
1124 template TypeImpl<HeapTypeConfig>::TypeHandle 1118 template TypeImpl<HeapTypeConfig>::TypeHandle
1125 TypeImpl<HeapTypeConfig>::Convert<Type>( 1119 TypeImpl<HeapTypeConfig>::Convert<Type>(
1126 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); 1120 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*);
1127 1121
1128 } } // namespace v8::internal 1122 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698