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

Side by Side Diff: src/types.cc

Issue 904863002: [turbofan] Separate representation type operations from the semantic types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix intersection to be pointwise Created 5 years, 10 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
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 <iomanip> 5 #include <iomanip>
6 6
7 #include "src/types.h" 7 #include "src/types.h"
8 8
9 #include "src/ostreams.h" 9 #include "src/ostreams.h"
10 #include "src/types-inl.h" 10 #include "src/types-inl.h"
(...skipping 10 matching lines...) Expand all
21 // Range-related helper functions. 21 // Range-related helper functions.
22 22
23 // The result may be invalid (max < min). 23 // The result may be invalid (max < min).
24 template<class Config> 24 template<class Config>
25 typename TypeImpl<Config>::Limits TypeImpl<Config>::Intersect( 25 typename TypeImpl<Config>::Limits TypeImpl<Config>::Intersect(
26 Limits lhs, Limits rhs) { 26 Limits lhs, Limits rhs) {
27 DisallowHeapAllocation no_allocation; 27 DisallowHeapAllocation no_allocation;
28 Limits result(lhs); 28 Limits result(lhs);
29 if (lhs.min < rhs.min) result.min = rhs.min; 29 if (lhs.min < rhs.min) result.min = rhs.min;
30 if (lhs.max > rhs.max) result.max = rhs.max; 30 if (lhs.max > rhs.max) result.max = rhs.max;
31 result.representation = lhs.representation & rhs.representation;
32 return result; 31 return result;
33 } 32 }
34 33
35 34
36 template <class Config> 35 template <class Config>
37 bool TypeImpl<Config>::IsEmpty(Limits lim) { 36 bool TypeImpl<Config>::IsEmpty(Limits lim) {
38 return lim.min > lim.max; 37 return lim.min > lim.max;
39 } 38 }
40 39
41 40
42 template <class Config> 41 template <class Config>
43 typename TypeImpl<Config>::Limits TypeImpl<Config>::Union(Limits lhs, 42 typename TypeImpl<Config>::Limits TypeImpl<Config>::Union(Limits lhs,
44 Limits rhs) { 43 Limits rhs) {
45 DisallowHeapAllocation no_allocation; 44 DisallowHeapAllocation no_allocation;
45 if (IsEmpty(lhs)) return rhs;
46 if (IsEmpty(rhs)) return lhs;
46 Limits result(lhs); 47 Limits result(lhs);
47 if (lhs.min > rhs.min) result.min = rhs.min; 48 if (lhs.min > rhs.min) result.min = rhs.min;
48 if (lhs.max < rhs.max) result.max = rhs.max; 49 if (lhs.max < rhs.max) result.max = rhs.max;
49 result.representation = lhs.representation | rhs.representation;
50 return result; 50 return result;
51 } 51 }
52 52
53 53
54 template<class Config> 54 template<class Config>
55 bool TypeImpl<Config>::Overlap( 55 bool TypeImpl<Config>::Overlap(
56 typename TypeImpl<Config>::RangeType* lhs, 56 typename TypeImpl<Config>::RangeType* lhs,
57 typename TypeImpl<Config>::RangeType* rhs) { 57 typename TypeImpl<Config>::RangeType* rhs) {
58 DisallowHeapAllocation no_allocation; 58 DisallowHeapAllocation no_allocation;
59 typename TypeImpl<Config>::Limits lim = Intersect(Limits(lhs), Limits(rhs)); 59 typename TypeImpl<Config>::Limits lim = Intersect(Limits(lhs), Limits(rhs));
60 return lim.min <= lim.max; 60 return lim.min <= lim.max;
61 } 61 }
62 62
63 63
64 template<class Config> 64 template<class Config>
65 bool TypeImpl<Config>::Contains( 65 bool TypeImpl<Config>::Contains(
66 typename TypeImpl<Config>::RangeType* lhs, 66 typename TypeImpl<Config>::RangeType* lhs,
67 typename TypeImpl<Config>::RangeType* rhs) { 67 typename TypeImpl<Config>::RangeType* rhs) {
68 DisallowHeapAllocation no_allocation; 68 DisallowHeapAllocation no_allocation;
69 return BitsetType::Is(rhs->Bound(), lhs->Bound()) && 69 return lhs->Min() <= rhs->Min() && rhs->Max() <= lhs->Max();
70 lhs->Min() <= rhs->Min() && rhs->Max() <= lhs->Max();
71 } 70 }
72 71
73 72
74 template <class Config> 73 template <class Config>
75 bool TypeImpl<Config>::Contains(typename TypeImpl<Config>::RangeType* lhs, 74 bool TypeImpl<Config>::Contains(typename TypeImpl<Config>::RangeType* lhs,
76 typename TypeImpl<Config>::ConstantType* rhs) { 75 typename TypeImpl<Config>::ConstantType* rhs) {
77 DisallowHeapAllocation no_allocation; 76 DisallowHeapAllocation no_allocation;
78 return IsInteger(*rhs->Value()) && 77 return IsInteger(*rhs->Value()) &&
79 BitsetType::Is(rhs->Bound()->AsBitset(), lhs->Bound()) &&
80 lhs->Min() <= rhs->Value()->Number() && 78 lhs->Min() <= rhs->Value()->Number() &&
81 rhs->Value()->Number() <= lhs->Max(); 79 rhs->Value()->Number() <= lhs->Max();
82 } 80 }
83 81
84 82
85 template<class Config> 83 template<class Config>
86 bool TypeImpl<Config>::Contains( 84 bool TypeImpl<Config>::Contains(
87 typename TypeImpl<Config>::RangeType* range, i::Object* val) { 85 typename TypeImpl<Config>::RangeType* range, i::Object* val) {
88 DisallowHeapAllocation no_allocation; 86 DisallowHeapAllocation no_allocation;
89 return IsInteger(val) && 87 return IsInteger(val) &&
90 BitsetType::Is(BitsetType::Lub(val), range->Bound()) &&
91 range->Min() <= val->Number() && val->Number() <= range->Max(); 88 range->Min() <= val->Number() && val->Number() <= range->Max();
92 } 89 }
93 90
94 91
95 // ----------------------------------------------------------------------------- 92 // -----------------------------------------------------------------------------
96 // Min and Max computation. 93 // Min and Max computation.
97 94
98 template<class Config> 95 template<class Config>
99 double TypeImpl<Config>::Min() { 96 double TypeImpl<Config>::Min() {
100 DCHECK(this->Is(Number())); 97 DCHECK(this->SemanticIs(Number()));
101 if (this->IsBitset()) return BitsetType::Min(this->AsBitset()); 98 if (this->IsBitset()) return BitsetType::Min(this->AsBitset());
102 if (this->IsUnion()) { 99 if (this->IsUnion()) {
103 double min = +V8_INFINITY; 100 double min = +V8_INFINITY;
104 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { 101 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
105 min = std::min(min, this->AsUnion()->Get(i)->Min()); 102 min = std::min(min, this->AsUnion()->Get(i)->Min());
106 } 103 }
107 return min; 104 return min;
108 } 105 }
109 if (this->IsRange()) return this->AsRange()->Min(); 106 if (this->IsRange()) return this->AsRange()->Min();
110 if (this->IsConstant()) return this->AsConstant()->Value()->Number(); 107 if (this->IsConstant()) return this->AsConstant()->Value()->Number();
111 UNREACHABLE(); 108 UNREACHABLE();
112 return 0; 109 return 0;
113 } 110 }
114 111
115 112
116 template<class Config> 113 template<class Config>
117 double TypeImpl<Config>::Max() { 114 double TypeImpl<Config>::Max() {
118 DCHECK(this->Is(Number())); 115 DCHECK(this->SemanticIs(Number()));
119 if (this->IsBitset()) return BitsetType::Max(this->AsBitset()); 116 if (this->IsBitset()) return BitsetType::Max(this->AsBitset());
120 if (this->IsUnion()) { 117 if (this->IsUnion()) {
121 double max = -V8_INFINITY; 118 double max = -V8_INFINITY;
122 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { 119 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
123 max = std::max(max, this->AsUnion()->Get(i)->Max()); 120 max = std::max(max, this->AsUnion()->Get(i)->Max());
124 } 121 }
125 return max; 122 return max;
126 } 123 }
127 if (this->IsRange()) return this->AsRange()->Max(); 124 if (this->IsRange()) return this->AsRange()->Max();
128 if (this->IsConstant()) return this->AsConstant()->Value()->Number(); 125 if (this->IsConstant()) return this->AsConstant()->Value()->Number();
129 UNREACHABLE(); 126 UNREACHABLE();
130 return 0; 127 return 0;
131 } 128 }
132 129
133 130
134 // ----------------------------------------------------------------------------- 131 // -----------------------------------------------------------------------------
135 // Glb and lub computation. 132 // Glb and lub computation.
136 133
137 134
138 // The largest bitset subsumed by this type. 135 // The largest bitset subsumed by this type.
139 template<class Config> 136 template<class Config>
140 typename TypeImpl<Config>::bitset 137 typename TypeImpl<Config>::bitset
141 TypeImpl<Config>::BitsetType::Glb(TypeImpl* type) { 138 TypeImpl<Config>::BitsetType::Glb(TypeImpl* type) {
142 DisallowHeapAllocation no_allocation; 139 DisallowHeapAllocation no_allocation;
140 // Fast case.
143 if (type->IsBitset()) { 141 if (type->IsBitset()) {
144 return type->AsBitset(); 142 return type->AsBitset();
145 } else if (type->IsUnion()) { 143 } else if (type->IsUnion()) {
146 SLOW_DCHECK(type->AsUnion()->Wellformed()); 144 SLOW_DCHECK(type->AsUnion()->Wellformed());
147 return type->AsUnion()->Get(0)->BitsetGlb() | 145 return type->AsUnion()->Get(0)->BitsetGlb() |
148 type->AsUnion()->Get(1)->BitsetGlb(); // Shortcut. 146 SEMANTIC(type->AsUnion()->Get(1)->BitsetGlb()); // Shortcut.
149 } else if (type->IsRange()) { 147 } else if (type->IsRange()) {
150 bitset glb = SEMANTIC( 148 bitset glb = SEMANTIC(
151 BitsetType::Glb(type->AsRange()->Min(), type->AsRange()->Max())); 149 BitsetType::Glb(type->AsRange()->Min(), type->AsRange()->Max()));
152 if (glb == 0) { 150 return glb | REPRESENTATION(type->BitsetLub());
153 return kNone;
154 } else {
155 return glb | REPRESENTATION(type->BitsetLub());
156 }
157 } else { 151 } else {
158 // (The remaining BitsetGlb's are None anyway). 152 return type->GetRepresentation();
159 return kNone;
160 } 153 }
161 } 154 }
162 155
163 156
164 // The smallest bitset subsuming this type. 157 // The smallest bitset subsuming this type.
165 template<class Config> 158 template<class Config>
166 typename TypeImpl<Config>::bitset 159 typename TypeImpl<Config>::bitset
167 TypeImpl<Config>::BitsetType::Lub(TypeImpl* type) { 160 TypeImpl<Config>::BitsetType::Lub(TypeImpl* type) {
168 DisallowHeapAllocation no_allocation; 161 DisallowHeapAllocation no_allocation;
169 if (type->IsBitset()) return type->AsBitset(); 162 if (type->IsBitset()) return type->AsBitset();
170 if (type->IsUnion()) { 163 if (type->IsUnion()) {
171 int bitset = kNone; 164 // Take the representation from the first element.
rossberg 2015/02/11 12:34:10 Nit: add "..., which always is a bitset."
Jarin 2015/02/11 16:10:47 Done.
165 int bitset = type->AsUnion()->Get(0)->BitsetLub();
172 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) { 166 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) {
173 bitset |= type->AsUnion()->Get(i)->BitsetLub(); 167 // Other elements only contribute the semantic part.
rossberg 2015/02/11 12:34:10 Nit: either "contribute to the" or "contribute the
Jarin 2015/02/11 16:10:47 Done.
168 bitset |= SEMANTIC(type->AsUnion()->Get(i)->BitsetLub());
174 } 169 }
175 return bitset; 170 return bitset;
176 } 171 }
177 if (type->IsClass()) { 172 if (type->IsClass()) {
178 // Little hack to avoid the need for a region for handlification here... 173 // Little hack to avoid the need for a region for handlification here...
179 return Config::is_class(type) ? Lub(*Config::as_class(type)) : 174 return Config::is_class(type) ? Lub(*Config::as_class(type)) :
180 type->AsClass()->Bound(NULL)->AsBitset(); 175 type->AsClass()->Bound(NULL)->AsBitset();
181 } 176 }
182 if (type->IsConstant()) return type->AsConstant()->Bound()->AsBitset(); 177 if (type->IsConstant()) return type->AsConstant()->Bound()->AsBitset();
183 if (type->IsRange()) return type->AsRange()->Bound(); 178 if (type->IsRange()) return type->AsRange()->Bound();
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 // in the greatest lower bound. (There is also the small trouble 395 // in the greatest lower bound. (There is also the small trouble
401 // of kOtherNumber having a range hole, which we can conveniently 396 // of kOtherNumber having a range hole, which we can conveniently
402 // ignore here.) 397 // ignore here.)
403 return glb & ~(SEMANTIC(kOtherNumber)); 398 return glb & ~(SEMANTIC(kOtherNumber));
404 } 399 }
405 400
406 401
407 template <class Config> 402 template <class Config>
408 double TypeImpl<Config>::BitsetType::Min(bitset bits) { 403 double TypeImpl<Config>::BitsetType::Min(bitset bits) {
409 DisallowHeapAllocation no_allocation; 404 DisallowHeapAllocation no_allocation;
410 DCHECK(Is(bits, kNumber)); 405 DCHECK(Is(SEMANTIC(bits), kNumber));
411 const Boundary* mins = Boundaries(); 406 const Boundary* mins = Boundaries();
412 bool mz = SEMANTIC(bits & kMinusZero); 407 bool mz = SEMANTIC(bits & kMinusZero);
413 for (size_t i = 0; i < BoundariesSize(); ++i) { 408 for (size_t i = 0; i < BoundariesSize(); ++i) {
414 if (Is(SEMANTIC(mins[i].bits), bits)) { 409 if (Is(SEMANTIC(mins[i].bits), bits)) {
415 return mz ? std::min(0.0, mins[i].min) : mins[i].min; 410 return mz ? std::min(0.0, mins[i].min) : mins[i].min;
416 } 411 }
417 } 412 }
418 if (mz) return 0; 413 if (mz) return 0;
419 return std::numeric_limits<double>::quiet_NaN(); 414 return std::numeric_limits<double>::quiet_NaN();
420 } 415 }
421 416
422 417
423 template<class Config> 418 template<class Config>
424 double TypeImpl<Config>::BitsetType::Max(bitset bits) { 419 double TypeImpl<Config>::BitsetType::Max(bitset bits) {
425 DisallowHeapAllocation no_allocation; 420 DisallowHeapAllocation no_allocation;
426 DCHECK(Is(bits, kNumber)); 421 DCHECK(Is(SEMANTIC(bits), kNumber));
427 const Boundary* mins = Boundaries(); 422 const Boundary* mins = Boundaries();
428 bool mz = SEMANTIC(bits & kMinusZero); 423 bool mz = SEMANTIC(bits & kMinusZero);
429 if (BitsetType::Is(SEMANTIC(mins[BoundariesSize() - 1].bits), bits)) { 424 if (BitsetType::Is(SEMANTIC(mins[BoundariesSize() - 1].bits), bits)) {
430 return +V8_INFINITY; 425 return +V8_INFINITY;
431 } 426 }
432 for (size_t i = BoundariesSize() - 1; i-- > 0;) { 427 for (size_t i = BoundariesSize() - 1; i-- > 0;) {
433 if (Is(SEMANTIC(mins[i].bits), bits)) { 428 if (Is(SEMANTIC(mins[i].bits), bits)) {
434 return mz ? 429 return mz ?
435 std::max(0.0, mins[i+1].min - 1) : mins[i+1].min - 1; 430 std::max(0.0, mins[i+1].min - 1) : mins[i+1].min - 1;
436 } 431 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 for (int i = 0, n = this_fun->Arity(); i < n; ++i) { 470 for (int i = 0, n = this_fun->Arity(); i < n; ++i) {
476 if (!this_fun->Parameter(i)->Equals(that_fun->Parameter(i))) return false; 471 if (!this_fun->Parameter(i)->Equals(that_fun->Parameter(i))) return false;
477 } 472 }
478 return true; 473 return true;
479 } 474 }
480 UNREACHABLE(); 475 UNREACHABLE();
481 return false; 476 return false;
482 } 477 }
483 478
484 479
480 template <class Config>
481 typename TypeImpl<Config>::bitset TypeImpl<Config>::GetRepresentation() {
482 return REPRESENTATION(this->BitsetLub());
483 }
484
485
485 // Check if [this] <= [that]. 486 // Check if [this] <= [that].
486 template<class Config> 487 template<class Config>
487 bool TypeImpl<Config>::SlowIs(TypeImpl* that) { 488 bool TypeImpl<Config>::SlowIs(TypeImpl* that) {
488 DisallowHeapAllocation no_allocation; 489 DisallowHeapAllocation no_allocation;
489 490
491 // Fast bitset cases
490 if (that->IsBitset()) { 492 if (that->IsBitset()) {
491 return BitsetType::Is(this->BitsetLub(), that->AsBitset()); 493 return BitsetType::Is(this->BitsetLub(), that->AsBitset());
492 } 494 }
495
493 if (this->IsBitset()) { 496 if (this->IsBitset()) {
494 return BitsetType::Is(this->AsBitset(), that->BitsetGlb()); 497 return BitsetType::Is(this->AsBitset(), that->BitsetGlb());
495 } 498 }
496 499
500 // Check the representations.
501 if (!BitsetType::Is(GetRepresentation(), that->GetRepresentation())) {
502 return false;
503 }
504
505 // Check the semantic part.
506 return SemanticIs(that);
507 }
508
509
510 // Check if SEMANTIC([this]) <= SEMANTIC([that]). The result of the method
511 // should be independent of the representation axis of the types.
512 template <class Config>
513 bool TypeImpl<Config>::SemanticIs(TypeImpl* that) {
514 DisallowHeapAllocation no_allocation;
515
516 if (this == that) return true;
517
518 if (that->IsBitset()) {
519 return BitsetType::Is(SEMANTIC(this->BitsetLub()), that->AsBitset());
rossberg 2015/02/11 12:34:10 Don't you need SEMANTIC on 'that' as well?
Jarin 2015/02/11 16:10:47 I do not think so. That is purely because the repr
rossberg 2015/02/12 14:39:15 Ah, right.
520 }
521 if (this->IsBitset()) {
522 return BitsetType::Is(SEMANTIC(this->AsBitset()), that->BitsetGlb());
rossberg 2015/02/11 12:34:10 Similarly here?
Jarin 2015/02/11 16:10:47 See above.
523 }
524
497 // (T1 \/ ... \/ Tn) <= T if (T1 <= T) /\ ... /\ (Tn <= T) 525 // (T1 \/ ... \/ Tn) <= T if (T1 <= T) /\ ... /\ (Tn <= T)
498 if (this->IsUnion()) { 526 if (this->IsUnion()) {
499 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { 527 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
500 if (!this->AsUnion()->Get(i)->Is(that)) return false; 528 if (!this->AsUnion()->Get(i)->SemanticIs(that)) return false;
501 } 529 }
502 return true; 530 return true;
503 } 531 }
504 532
505 // T <= (T1 \/ ... \/ Tn) if (T <= T1) \/ ... \/ (T <= Tn) 533 // T <= (T1 \/ ... \/ Tn) if (T <= T1) \/ ... \/ (T <= Tn)
506 if (that->IsUnion()) { 534 if (that->IsUnion()) {
507 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) { 535 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) {
508 if (this->Is(that->AsUnion()->Get(i))) return true; 536 if (this->SemanticIs(that->AsUnion()->Get(i)->unhandle())) return true;
509 if (i > 1 && this->IsRange()) return false; // Shortcut. 537 if (i > 1 && this->IsRange()) return false; // Shortcut.
510 } 538 }
511 return false; 539 return false;
512 } 540 }
513 541
514 if (that->IsRange()) { 542 if (that->IsRange()) {
515 return (this->IsRange() && Contains(that->AsRange(), this->AsRange())) || 543 return (this->IsRange() && Contains(that->AsRange(), this->AsRange())) ||
516 (this->IsConstant() && 544 (this->IsConstant() &&
517 Contains(that->AsRange(), this->AsConstant())); 545 Contains(that->AsRange(), this->AsConstant()));
518 } 546 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } 579 }
552 return true; 580 return true;
553 } 581 }
554 582
555 583
556 // Check if [this] and [that] overlap. 584 // Check if [this] and [that] overlap.
557 template<class Config> 585 template<class Config>
558 bool TypeImpl<Config>::Maybe(TypeImpl* that) { 586 bool TypeImpl<Config>::Maybe(TypeImpl* that) {
559 DisallowHeapAllocation no_allocation; 587 DisallowHeapAllocation no_allocation;
560 588
589 // Take care of the representation part (and also approximate
590 // the semantic part).
591 if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub()))
592 return false;
593
594 return SemanticMaybe(that);
595 }
596
597 template <class Config>
598 bool TypeImpl<Config>::SemanticMaybe(TypeImpl* that) {
599 DisallowHeapAllocation no_allocation;
600
561 // (T1 \/ ... \/ Tn) overlaps T if (T1 overlaps T) \/ ... \/ (Tn overlaps T) 601 // (T1 \/ ... \/ Tn) overlaps T if (T1 overlaps T) \/ ... \/ (Tn overlaps T)
562 if (this->IsUnion()) { 602 if (this->IsUnion()) {
563 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { 603 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
564 if (this->AsUnion()->Get(i)->Maybe(that)) return true; 604 if (this->AsUnion()->Get(i)->SemanticMaybe(that)) return true;
565 } 605 }
566 return false; 606 return false;
567 } 607 }
568 608
569 // T overlaps (T1 \/ ... \/ Tn) if (T overlaps T1) \/ ... \/ (T overlaps Tn) 609 // T overlaps (T1 \/ ... \/ Tn) if (T overlaps T1) \/ ... \/ (T overlaps Tn)
570 if (that->IsUnion()) { 610 if (that->IsUnion()) {
571 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) { 611 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) {
572 if (this->Maybe(that->AsUnion()->Get(i))) return true; 612 if (this->SemanticMaybe(that->AsUnion()->Get(i)->unhandle())) return true;
573 } 613 }
574 return false; 614 return false;
575 } 615 }
576 616
577 if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub())) 617 if (!BitsetType::SemanticIsInhabited(this->BitsetLub() & that->BitsetLub()))
578 return false; 618 return false;
579 619
580 if (this->IsBitset() && that->IsBitset()) return true; 620 if (this->IsBitset() && that->IsBitset()) return true;
581 621
582 if (this->IsClass() != that->IsClass()) return true; 622 if (this->IsClass() != that->IsClass()) return true;
583 623
584 if (this->IsRange()) { 624 if (this->IsRange()) {
585 if (that->IsConstant()) { 625 if (that->IsConstant()) {
586 return Contains(this->AsRange(), that->AsConstant()); 626 return Contains(this->AsRange(), that->AsConstant());
587 } 627 }
588 if (that->IsRange()) { 628 if (that->IsRange()) {
589 return Overlap(this->AsRange(), that->AsRange()); 629 return Overlap(this->AsRange(), that->AsRange());
590 } 630 }
591 if (that->IsBitset()) { 631 if (that->IsBitset()) {
592 bitset number_bits = BitsetType::NumberBits(that->AsBitset()); 632 bitset number_bits = BitsetType::NumberBits(that->AsBitset());
593 if (number_bits == BitsetType::kNone) { 633 if (number_bits == BitsetType::kNone) {
594 return false; 634 return false;
595 } 635 }
596 double min = std::max(BitsetType::Min(number_bits), this->Min()); 636 double min = std::max(BitsetType::Min(number_bits), this->Min());
597 double max = std::min(BitsetType::Max(number_bits), this->Max()); 637 double max = std::min(BitsetType::Max(number_bits), this->Max());
598 return min <= max; 638 return min <= max;
599 } 639 }
600 } 640 }
601 if (that->IsRange()) { 641 if (that->IsRange()) {
602 return that->Maybe(this); // This case is handled above. 642 return that->SemanticMaybe(this); // This case is handled above.
603 } 643 }
604 644
605 if (this->IsBitset() || that->IsBitset()) return true; 645 if (this->IsBitset() || that->IsBitset()) return true;
606 646
607 return this->SimplyEquals(that); 647 return this->SimplyEquals(that);
608 } 648 }
609 649
610 650
611 // Return the range in [this], or [NULL]. 651 // Return the range in [this], or [NULL].
612 template<class Config> 652 template<class Config>
(...skipping 19 matching lines...) Expand all
632 } 672 }
633 return BitsetType::New(BitsetType::Lub(value))->Is(this); 673 return BitsetType::New(BitsetType::Lub(value))->Is(this);
634 } 674 }
635 675
636 676
637 template<class Config> 677 template<class Config>
638 bool TypeImpl<Config>::UnionType::Wellformed() { 678 bool TypeImpl<Config>::UnionType::Wellformed() {
639 DisallowHeapAllocation no_allocation; 679 DisallowHeapAllocation no_allocation;
640 // This checks the invariants of the union representation: 680 // This checks the invariants of the union representation:
641 // 1. There are at least two elements. 681 // 1. There are at least two elements.
642 // 2. At most one element is a bitset, and it must be the first one. 682 // 2. The first element is a bitset, no other element is a bitset.
643 // 3. At most one element is a range, and it must be the second one 683 // 3. At most one element is a range, and it must be the second one
644 // (even when the first element is not a bitset). 684 // (even when the first element is not a bitset).
rossberg 2015/02/11 12:34:10 This line is obsolete now.
Jarin 2015/02/11 16:10:47 Done.
645 // 4. No element is itself a union. 685 // 4. No element is itself a union.
646 // 5. No element is a subtype of any other. 686 // 5. No element (except the bitset) is a subtype of any other.
647 // 6. If there is a range, then the bitset type does not contain 687 // 6. If there is a range, then the bitset type does not contain
648 // plain number bits. 688 // plain number bits.
649 DCHECK(this->Length() >= 2); // (1) 689 DCHECK(this->Length() >= 2); // (1)
650 690 DCHECK(this->Get(0)->IsBitset()); // (2a)
651 bitset number_bits = this->Get(0)->IsBitset()
652 ? BitsetType::NumberBits(this->Get(0)->AsBitset()) : 0;
653 USE(number_bits);
654 691
655 for (int i = 0; i < this->Length(); ++i) { 692 for (int i = 0; i < this->Length(); ++i) {
656 if (i != 0) DCHECK(!this->Get(i)->IsBitset()); // (2) 693 if (i != 0) DCHECK(!this->Get(i)->IsBitset()); // (2b)
657 if (i != 1) DCHECK(!this->Get(i)->IsRange()); // (3) 694 if (i != 1) DCHECK(!this->Get(i)->IsRange()); // (3)
658 DCHECK(!this->Get(i)->IsUnion()); // (4) 695 DCHECK(!this->Get(i)->IsUnion()); // (4)
659 for (int j = 0; j < this->Length(); ++j) { 696 for (int j = 0; j < this->Length(); ++j) {
660 if (i != j) DCHECK(!this->Get(i)->Is(this->Get(j))); // (5) 697 if (i != j && i != 0)
698 DCHECK(!this->Get(i)->SemanticIs(this->Get(j)->unhandle())); // (5)
661 } 699 }
662 } 700 }
663 DCHECK(!this->Get(1)->IsRange() || (number_bits == 0)); // (6) 701 DCHECK(!this->Get(1)->IsRange() ||
702 (BitsetType::NumberBits(this->Get(0)->AsBitset()) ==
703 BitsetType::kNone)); // (6)
664 return true; 704 return true;
665 } 705 }
666 706
667 707
668 // ----------------------------------------------------------------------------- 708 // -----------------------------------------------------------------------------
669 // Union and intersection 709 // Union and intersection
670 710
671 711
672 static bool AddIsSafe(int x, int y) { 712 static bool AddIsSafe(int x, int y) {
673 return x >= 0 ? 713 return x >= 0 ?
674 y <= std::numeric_limits<int>::max() - x : 714 y <= std::numeric_limits<int>::max() - x :
675 y >= std::numeric_limits<int>::min() - x; 715 y >= std::numeric_limits<int>::min() - x;
676 } 716 }
677 717
678 718
679 template<class Config> 719 template<class Config>
680 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Intersect( 720 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Intersect(
681 TypeHandle type1, TypeHandle type2, Region* region) { 721 TypeHandle type1, TypeHandle type2, Region* region) {
682 bitset bits = type1->BitsetGlb() & type2->BitsetGlb();
683 if (!BitsetType::IsInhabited(bits)) bits = BitsetType::kNone;
684 722
685 // Fast case: bit sets. 723 // Fast case: bit sets.
686 if (type1->IsBitset() && type2->IsBitset()) { 724 if (type1->IsBitset() && type2->IsBitset()) {
687 return BitsetType::New(bits, region); 725 return BitsetType::New(type1->AsBitset() & type2->AsBitset(), region);
688 } 726 }
689 727
690 // Fast case: top or bottom types. 728 // Fast case: top or bottom types.
691 if (type1->IsNone() || type2->IsAny()) return type1; // Shortcut. 729 if (type1->IsNone() || type2->IsAny()) return type1; // Shortcut.
692 if (type2->IsNone() || type1->IsAny()) return type2; // Shortcut. 730 if (type2->IsNone() || type1->IsAny()) return type2; // Shortcut.
693 731
694 // Semi-fast case. 732 // Semi-fast case.
695 if (type1->Is(type2)) return type1; 733 if (type1->Is(type2)) return type1;
696 if (type2->Is(type1)) return type2; 734 if (type2->Is(type1)) return type2;
697 735
698 // Slow case: create union. 736 // Slow case: create union.
737
738 // Figure out the representation of the result first.
739 // The rest of the method should not change this representation and
740 // it should make any decisions based on representations (i.e.,
rossberg 2015/02/11 12:34:10 "should not make"?
Jarin 2015/02/11 16:10:47 Done.
741 // it should only use the semantic part of types).
742 const bitset representation =
743 type1->GetRepresentation() & type2->GetRepresentation();
744
745 // Semantic subtyping check - this is needed for consistency with the
746 // semi-fast case above - we should behave the same way regardless of
747 // representations. Intersection with a universal bitset should only update
748 // the representations.
749 if (type1->SemanticIs(type2->unhandle())) {
750 type2 = Any(region);
751 } else if (type2->SemanticIs(type1->unhandle())) {
752 type1 = Any(region);
753 }
754
755 bitset bits =
756 SEMANTIC(type1->BitsetGlb() & type2->BitsetGlb()) | representation;
699 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1; 757 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1;
700 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; 758 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1;
701 if (!AddIsSafe(size1, size2)) return Any(region); 759 if (!AddIsSafe(size1, size2)) return Any(region);
702 int size = size1 + size2; 760 int size = size1 + size2;
703 if (!AddIsSafe(size, 2)) return Any(region); 761 if (!AddIsSafe(size, 2)) return Any(region);
704 size += 2; 762 size += 2;
705 UnionHandle result = UnionType::New(size, region); 763 UnionHandle result = UnionType::New(size, region);
706 size = 0; 764 size = 0;
707 765
708 // Deal with bitsets. 766 // Deal with bitsets.
709 result->Set(size++, BitsetType::New(bits, region)); 767 result->Set(size++, BitsetType::New(bits, region));
710 // Insert a placeholder for the range.
711 result->Set(size++, None(region));
712 768
713 Limits lims = Limits::Empty(region); 769 Limits lims = Limits::Empty(region);
714 size = IntersectAux(type1, type2, result, size, &lims, region); 770 size = IntersectAux(type1, type2, result, size, &lims, region);
715 771
716 // If the range is not empty, then insert it into the union and 772 // If the range is not empty, then insert it into the union and
717 // remove the number bits from the bitset. 773 // remove the number bits from the bitset.
718 if (!IsEmpty(lims)) { 774 if (!IsEmpty(lims)) {
719 size = UpdateRange(RangeType::New(lims, region), result, size, region); 775 size = UpdateRange(RangeType::New(lims, representation, region), result,
776 size, region);
720 777
721 // Remove the number bits. 778 // Remove the number bits.
722 bitset number_bits = BitsetType::NumberBits(bits); 779 bitset number_bits = BitsetType::NumberBits(bits);
723 bits &= ~number_bits; 780 bits &= ~number_bits;
724 if (SEMANTIC(bits) == BitsetType::kNone) {
725 bits = BitsetType::kNone;
726 }
727 result->Set(0, BitsetType::New(bits, region)); 781 result->Set(0, BitsetType::New(bits, region));
728 } 782 }
729 return NormalizeUnion(result, size); 783 return NormalizeUnion(result, size);
730 } 784 }
731 785
732 786
733 template<class Config> 787 template<class Config>
734 int TypeImpl<Config>::UpdateRange( 788 int TypeImpl<Config>::UpdateRange(
735 RangeHandle range, UnionHandle result, int size, Region* region) { 789 RangeHandle range, UnionHandle result, int size, Region* region) {
736 TypeHandle old_range = result->Get(1); 790 if (size == 1) {
737 DCHECK(old_range->IsRange() || old_range->IsNone()); 791 result->Set(size++, range);
738 if (range->Is(old_range)) return size; 792 } else {
739 if (!old_range->Is(range->unhandle())) { 793 // Make space for the range.
740 range = RangeType::New( 794 result->Set(size++, result->Get(1));
741 Union(Limits(range->AsRange()), Limits(old_range->AsRange())), region); 795 result->Set(1, range);
742 } 796 }
743 result->Set(1, range);
744 797
745 // Remove any components that just got subsumed. 798 // Remove any components that just got subsumed.
746 for (int i = 2; i < size; ) { 799 for (int i = 2; i < size; ) {
747 if (result->Get(i)->Is(range->unhandle())) { 800 if (result->Get(i)->SemanticIs(range->unhandle())) {
748 result->Set(i, result->Get(--size)); 801 result->Set(i, result->Get(--size));
749 } else { 802 } else {
750 ++i; 803 ++i;
751 } 804 }
752 } 805 }
753 return size; 806 return size;
754 } 807 }
755 808
756 809
757 template <class Config> 810 template <class Config>
758 typename TypeImpl<Config>::Limits TypeImpl<Config>::ToLimits(bitset bits, 811 typename TypeImpl<Config>::Limits TypeImpl<Config>::ToLimits(bitset bits,
759 Region* region) { 812 Region* region) {
760 bitset representation = REPRESENTATION(bits);
761 bitset number_bits = BitsetType::NumberBits(bits); 813 bitset number_bits = BitsetType::NumberBits(bits);
762 814
763 if (representation == BitsetType::kNone && number_bits == BitsetType::kNone) { 815 if (number_bits == BitsetType::kNone) {
764 return Limits::Empty(region); 816 return Limits::Empty(region);
765 } 817 }
766 818
767 return Limits(BitsetType::Min(number_bits), BitsetType::Max(number_bits), 819 return Limits(BitsetType::Min(number_bits), BitsetType::Max(number_bits));
768 representation);
769 } 820 }
770 821
771 822
772 template <class Config> 823 template <class Config>
773 typename TypeImpl<Config>::Limits TypeImpl<Config>::IntersectRangeAndBitset( 824 typename TypeImpl<Config>::Limits TypeImpl<Config>::IntersectRangeAndBitset(
774 TypeHandle range, TypeHandle bitset, Region* region) { 825 TypeHandle range, TypeHandle bitset, Region* region) {
775 Limits range_lims(range->AsRange()); 826 Limits range_lims(range->AsRange());
776 Limits bitset_lims = ToLimits(bitset->AsBitset(), region); 827 Limits bitset_lims = ToLimits(bitset->AsBitset(), region);
777 return Intersect(range_lims, bitset_lims); 828 return Intersect(range_lims, bitset_lims);
778 } 829 }
(...skipping 11 matching lines...) Expand all
790 return size; 841 return size;
791 } 842 }
792 if (rhs->IsUnion()) { 843 if (rhs->IsUnion()) {
793 for (int i = 0, n = rhs->AsUnion()->Length(); i < n; ++i) { 844 for (int i = 0, n = rhs->AsUnion()->Length(); i < n; ++i) {
794 size = 845 size =
795 IntersectAux(lhs, rhs->AsUnion()->Get(i), result, size, lims, region); 846 IntersectAux(lhs, rhs->AsUnion()->Get(i), result, size, lims, region);
796 } 847 }
797 return size; 848 return size;
798 } 849 }
799 850
800 if (!BitsetType::IsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) { 851 if (!BitsetType::SemanticIsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) {
801 return size; 852 return size;
802 } 853 }
803 854
804 if (lhs->IsRange()) { 855 if (lhs->IsRange()) {
805 if (rhs->IsBitset()) { 856 if (rhs->IsBitset()) {
806 Limits lim = IntersectRangeAndBitset(lhs, rhs, region); 857 Limits lim = IntersectRangeAndBitset(lhs, rhs, region);
807 858
808 if (!IsEmpty(lim)) { 859 if (!IsEmpty(lim)) {
809 *lims = Union(lim, *lims); 860 *lims = Union(lim, *lims);
810 } 861 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 RangeHandle range, bitset* bits, Region* region) { 901 RangeHandle range, bitset* bits, Region* region) {
851 // Fast path: If the bitset does not mention numbers, we can just keep the 902 // Fast path: If the bitset does not mention numbers, we can just keep the
852 // range. 903 // range.
853 bitset number_bits = BitsetType::NumberBits(*bits); 904 bitset number_bits = BitsetType::NumberBits(*bits);
854 if (number_bits == 0) { 905 if (number_bits == 0) {
855 return range; 906 return range;
856 } 907 }
857 908
858 // If the range is contained within the bitset, return an empty range 909 // If the range is contained within the bitset, return an empty range
859 // (but make sure we take the representation). 910 // (but make sure we take the representation).
860 bitset range_lub = range->BitsetLub(); 911 bitset range_lub = SEMANTIC(range->BitsetLub());
861 if (BitsetType::Is(BitsetType::NumberBits(range_lub), *bits)) { 912 if (BitsetType::Is(BitsetType::NumberBits(range_lub), *bits)) {
862 *bits |= range_lub;
863 return None(region); 913 return None(region);
864 } 914 }
865 915
866 // Slow path: reconcile the bitset range and the range. 916 // Slow path: reconcile the bitset range and the range.
867 double bitset_min = BitsetType::Min(number_bits); 917 double bitset_min = BitsetType::Min(number_bits);
868 double bitset_max = BitsetType::Max(number_bits); 918 double bitset_max = BitsetType::Max(number_bits);
869 919
870 double range_min = range->Min(); 920 double range_min = range->Min();
871 double range_max = range->Max(); 921 double range_max = range->Max();
872 922
873 bitset range_representation = REPRESENTATION(range->BitsetLub());
874 bitset bits_representation = REPRESENTATION(*bits);
875 bitset representation =
876 (bits_representation | range_representation) & BitsetType::kNumber;
877
878 // Remove the number bits from the bitset, they would just confuse us now. 923 // Remove the number bits from the bitset, they would just confuse us now.
879 *bits &= ~number_bits; 924 *bits &= ~number_bits;
880 if (bits_representation == *bits) {
881 *bits = BitsetType::kNone;
882 }
883 925
884 if (representation == range_representation && range_min <= bitset_min && 926 if (range_min <= bitset_min && range_max >= bitset_max) {
885 range_max >= bitset_max) {
886 // Bitset is contained within the range, just return the range. 927 // Bitset is contained within the range, just return the range.
887 return range; 928 return range;
888 } 929 }
889 930
890 if (bitset_min < range_min) { 931 if (bitset_min < range_min) {
891 range_min = bitset_min; 932 range_min = bitset_min;
892 } 933 }
893 if (bitset_max > range_max) { 934 if (bitset_max > range_max) {
894 range_max = bitset_max; 935 range_max = bitset_max;
895 } 936 }
896 return RangeType::New(range_min, range_max, 937 return RangeType::New(range_min, range_max,
897 BitsetType::New(representation, region), region); 938 BitsetType::New(BitsetType::kNone, region), region);
898 } 939 }
899 940
900 941
901 template<class Config> 942 template<class Config>
902 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union( 943 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union(
903 TypeHandle type1, TypeHandle type2, Region* region) { 944 TypeHandle type1, TypeHandle type2, Region* region) {
904
905 // Fast case: bit sets. 945 // Fast case: bit sets.
906 if (type1->IsBitset() && type2->IsBitset()) { 946 if (type1->IsBitset() && type2->IsBitset()) {
907 return BitsetType::New(type1->AsBitset() | type2->AsBitset(), region); 947 return BitsetType::New(type1->AsBitset() | type2->AsBitset(), region);
908 } 948 }
909 949
910 // Fast case: top or bottom types. 950 // Fast case: top or bottom types.
911 if (type1->IsAny() || type2->IsNone()) return type1; 951 if (type1->IsAny() || type2->IsNone()) return type1;
912 if (type2->IsAny() || type1->IsNone()) return type2; 952 if (type2->IsAny() || type1->IsNone()) return type2;
913 953
914 // Semi-fast case. 954 // Semi-fast case.
915 if (type1->Is(type2)) return type2; 955 if (type1->Is(type2)) return type2;
916 if (type2->Is(type1)) return type1; 956 if (type2->Is(type1)) return type1;
917 957
958 // Figure out the representation of the result.
959 // The rest of the method should not change this representation and
960 // it should make any decisions based on representations (i.e.,
961 // it should only use the semantic part of types).
962 const bitset representation =
963 type1->GetRepresentation() | type2->GetRepresentation();
964
918 // Slow case: create union. 965 // Slow case: create union.
919 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1; 966 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1;
920 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; 967 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1;
921 if (!AddIsSafe(size1, size2)) return Any(region); 968 if (!AddIsSafe(size1, size2)) return Any(region);
922 int size = size1 + size2; 969 int size = size1 + size2;
923 if (!AddIsSafe(size, 2)) return Any(region); 970 if (!AddIsSafe(size, 2)) return Any(region);
924 size += 2; 971 size += 2;
925 UnionHandle result = UnionType::New(size, region); 972 UnionHandle result = UnionType::New(size, region);
926 size = 0; 973 size = 0;
927 974
928 // Compute the new bitset. 975 // Compute the new bitset.
929 bitset new_bitset = type1->BitsetGlb() | type2->BitsetGlb(); 976 bitset new_bitset = SEMANTIC(type1->BitsetGlb() | type2->BitsetGlb());
930 977
931 // Deal with ranges. 978 // Deal with ranges.
932 TypeHandle range = None(region); 979 TypeHandle range = None(region);
933 RangeType* range1 = type1->GetRange(); 980 RangeType* range1 = type1->GetRange();
934 RangeType* range2 = type2->GetRange(); 981 RangeType* range2 = type2->GetRange();
935 if (range1 != NULL && range2 != NULL) { 982 if (range1 != NULL && range2 != NULL) {
936 Limits lims = Union(Limits(range1), Limits(range2)); 983 Limits lims = Union(Limits(range1), Limits(range2));
937 RangeHandle union_range = RangeType::New(lims, region); 984 RangeHandle union_range = RangeType::New(lims, representation, region);
938 range = NormalizeRangeAndBitset(union_range, &new_bitset, region); 985 range = NormalizeRangeAndBitset(union_range, &new_bitset, region);
939 } else if (range1 != NULL) { 986 } else if (range1 != NULL) {
940 range = NormalizeRangeAndBitset(handle(range1), &new_bitset, region); 987 range = NormalizeRangeAndBitset(handle(range1), &new_bitset, region);
941 } else if (range2 != NULL) { 988 } else if (range2 != NULL) {
942 range = NormalizeRangeAndBitset(handle(range2), &new_bitset, region); 989 range = NormalizeRangeAndBitset(handle(range2), &new_bitset, region);
943 } 990 }
991 new_bitset = SEMANTIC(new_bitset) | representation;
944 TypeHandle bits = BitsetType::New(new_bitset, region); 992 TypeHandle bits = BitsetType::New(new_bitset, region);
945 result->Set(size++, bits); 993 result->Set(size++, bits);
946 result->Set(size++, range); 994 if (!range->IsNone()) {
995 result->Set(size++, range);
rossberg 2015/02/11 12:34:10 Nit: single line
Jarin 2015/02/11 16:10:47 Done.
996 }
947 997
948 size = AddToUnion(type1, result, size, region); 998 size = AddToUnion(type1, result, size, region);
949 size = AddToUnion(type2, result, size, region); 999 size = AddToUnion(type2, result, size, region);
950 return NormalizeUnion(result, size); 1000 return NormalizeUnion(result, size);
951 } 1001 }
952 1002
953 1003
954 // Add [type] to [result] unless [type] is bitset, range, or already subsumed. 1004 // Add [type] to [result] unless [type] is bitset, range, or already subsumed.
955 // Return new size of [result]. 1005 // Return new size of [result].
956 template<class Config> 1006 template<class Config>
957 int TypeImpl<Config>::AddToUnion( 1007 int TypeImpl<Config>::AddToUnion(
958 TypeHandle type, UnionHandle result, int size, Region* region) { 1008 TypeHandle type, UnionHandle result, int size, Region* region) {
959 if (type->IsBitset() || type->IsRange()) return size; 1009 if (type->IsBitset() || type->IsRange()) return size;
960 if (type->IsUnion()) { 1010 if (type->IsUnion()) {
961 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) { 1011 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) {
962 size = AddToUnion(type->AsUnion()->Get(i), result, size, region); 1012 size = AddToUnion(type->AsUnion()->Get(i), result, size, region);
963 } 1013 }
964 return size; 1014 return size;
965 } 1015 }
966 for (int i = 0; i < size; ++i) { 1016 for (int i = 0; i < size; ++i) {
967 if (type->Is(result->Get(i))) return size; 1017 if (type->SemanticIs(result->Get(i)->unhandle())) return size;
968 } 1018 }
969 result->Set(size++, type); 1019 result->Set(size++, type);
970 return size; 1020 return size;
971 } 1021 }
972 1022
973 1023
974 template<class Config> 1024 template<class Config>
975 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NormalizeUnion( 1025 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NormalizeUnion(
976 UnionHandle unioned, int size) { 1026 UnionHandle unioned, int size) {
977 DCHECK(size >= 2); 1027 DCHECK(size >= 1);
978 // If range is subsumed by bitset, use its place for a different type. 1028 DCHECK(unioned->Get(0)->IsBitset());
979 if (unioned->Get(1)->Is(unioned->Get(0))) { 1029 // If the union has just one element, return it.
980 unioned->Set(1, unioned->Get(--size)); 1030 if (size == 1) {
1031 return unioned->Get(0);
981 } 1032 }
982 // If bitset is None, use its place for a different type. 1033 bitset bits = unioned->Get(0)->AsBitset();
983 if (size >= 2 && unioned->Get(0)->IsNone()) { 1034 // If the union only consists of a range, we can get rid of the union.
984 unioned->Set(0, unioned->Get(--size)); 1035 if (size == 2 && SEMANTIC(bits) == BitsetType::kNone) {
1036 bitset representation = REPRESENTATION(bits);
1037 if (representation == unioned->Get(1)->GetRepresentation()) {
1038 return unioned->Get(1);
1039 }
1040 // TODO(jarin) If the element at 1 is range of constant, slap
1041 // the representation on it and return that.
985 } 1042 }
986 if (size == 1) return unioned->Get(0);
987 unioned->Shrink(size); 1043 unioned->Shrink(size);
988 SLOW_DCHECK(unioned->Wellformed()); 1044 SLOW_DCHECK(unioned->Wellformed());
989 return unioned; 1045 return unioned;
990 } 1046 }
991 1047
992 1048
993 // ----------------------------------------------------------------------------- 1049 // -----------------------------------------------------------------------------
994 // Iteration. 1050 // Iteration.
995 1051
996 template<class Config> 1052 template<class Config>
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; 1343 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>;
1288 1344
1289 template TypeImpl<ZoneTypeConfig>::TypeHandle 1345 template TypeImpl<ZoneTypeConfig>::TypeHandle
1290 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( 1346 TypeImpl<ZoneTypeConfig>::Convert<HeapType>(
1291 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); 1347 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*);
1292 template TypeImpl<HeapTypeConfig>::TypeHandle 1348 template TypeImpl<HeapTypeConfig>::TypeHandle
1293 TypeImpl<HeapTypeConfig>::Convert<Type>( 1349 TypeImpl<HeapTypeConfig>::Convert<Type>(
1294 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); 1350 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*);
1295 1351
1296 } } // namespace v8::internal 1352 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698