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 #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 Loading... | |
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->Number() < rhs.min->Number()) result.min = rhs.min; | 29 if (lhs.min->Number() < rhs.min->Number()) result.min = rhs.min; |
30 if (lhs.max->Number() > rhs.max->Number()) result.max = rhs.max; | 30 if (lhs.max->Number() > rhs.max->Number()) result.max = rhs.max; |
31 result.representation = lhs.representation & rhs.representation; | |
31 return result; | 32 return result; |
32 } | 33 } |
33 | 34 |
34 | 35 |
35 template<class Config> | 36 template <class Config> |
36 typename TypeImpl<Config>::Limits TypeImpl<Config>::Union( | 37 bool TypeImpl<Config>::IsEmpty(Limits lim) { |
37 Limits lhs, Limits rhs) { | 38 return lim.min->Number() > lim.max->Number(); |
39 } | |
40 | |
41 | |
42 template <class Config> | |
43 typename TypeImpl<Config>::Limits TypeImpl<Config>::Union(Limits lhs, | |
44 Limits rhs) { | |
38 DisallowHeapAllocation no_allocation; | 45 DisallowHeapAllocation no_allocation; |
39 Limits result(lhs); | 46 Limits result(lhs); |
40 if (lhs.min->Number() > rhs.min->Number()) result.min = rhs.min; | 47 if (lhs.min->Number() > rhs.min->Number()) result.min = rhs.min; |
41 if (lhs.max->Number() < rhs.max->Number()) result.max = rhs.max; | 48 if (lhs.max->Number() < rhs.max->Number()) result.max = rhs.max; |
49 result.representation = lhs.representation | rhs.representation; | |
42 return result; | 50 return result; |
43 } | 51 } |
44 | 52 |
45 | 53 |
46 template<class Config> | 54 template<class Config> |
47 bool TypeImpl<Config>::Overlap( | 55 bool TypeImpl<Config>::Overlap( |
48 typename TypeImpl<Config>::RangeType* lhs, | 56 typename TypeImpl<Config>::RangeType* lhs, |
49 typename TypeImpl<Config>::RangeType* rhs) { | 57 typename TypeImpl<Config>::RangeType* rhs) { |
50 DisallowHeapAllocation no_allocation; | 58 DisallowHeapAllocation no_allocation; |
51 typename TypeImpl<Config>::Limits lim = Intersect(Limits(lhs), Limits(rhs)); | 59 typename TypeImpl<Config>::Limits lim = Intersect(Limits(lhs), Limits(rhs)); |
52 return lim.min->Number() <= lim.max->Number(); | 60 return lim.min->Number() <= lim.max->Number(); |
53 } | 61 } |
54 | 62 |
55 | 63 |
56 template<class Config> | 64 template<class Config> |
57 bool TypeImpl<Config>::Contains( | 65 bool TypeImpl<Config>::Contains( |
58 typename TypeImpl<Config>::RangeType* lhs, | 66 typename TypeImpl<Config>::RangeType* lhs, |
59 typename TypeImpl<Config>::RangeType* rhs) { | 67 typename TypeImpl<Config>::RangeType* rhs) { |
60 DisallowHeapAllocation no_allocation; | 68 DisallowHeapAllocation no_allocation; |
61 return lhs->Min()->Number() <= rhs->Min()->Number() | 69 return rhs->Bound()->Is(lhs->Bound()) && |
62 && rhs->Max()->Number() <= lhs->Max()->Number(); | 70 lhs->Min()->Number() <= rhs->Min()->Number() && |
71 rhs->Max()->Number() <= lhs->Max()->Number(); | |
63 } | 72 } |
64 | 73 |
65 | 74 |
75 template <class Config> | |
76 bool TypeImpl<Config>::Contains(typename TypeImpl<Config>::RangeType* lhs, | |
77 typename TypeImpl<Config>::ConstantType* rhs) { | |
78 DisallowHeapAllocation no_allocation; | |
79 return IsInteger(*rhs->Value()) && rhs->Bound()->Is(lhs->Bound()) && | |
80 lhs->Min()->Number() <= rhs->Value()->Number() && | |
81 rhs->Value()->Number() <= lhs->Max()->Number(); | |
82 } | |
83 | |
84 | |
66 template<class Config> | 85 template<class Config> |
67 bool TypeImpl<Config>::Contains( | 86 bool TypeImpl<Config>::Contains( |
68 typename TypeImpl<Config>::RangeType* range, i::Object* val) { | 87 typename TypeImpl<Config>::RangeType* range, i::Object* val) { |
69 DisallowHeapAllocation no_allocation; | 88 DisallowHeapAllocation no_allocation; |
70 return IsInteger(val) | 89 return IsInteger(val) && |
71 && range->Min()->Number() <= val->Number() | 90 BitsetType::Is(BitsetType::Lub(val), range->Bound()->AsBitset()) && |
72 && val->Number() <= range->Max()->Number(); | 91 range->Min()->Number() <= val->Number() && |
92 val->Number() <= range->Max()->Number(); | |
73 } | 93 } |
74 | 94 |
75 | 95 |
76 // ----------------------------------------------------------------------------- | 96 // ----------------------------------------------------------------------------- |
77 // Min and Max computation. | 97 // Min and Max computation. |
78 | 98 |
79 template<class Config> | 99 template<class Config> |
80 double TypeImpl<Config>::Min() { | 100 double TypeImpl<Config>::Min() { |
81 DCHECK(this->Is(Number())); | 101 DCHECK(this->Is(Number())); |
82 if (this->IsBitset()) return BitsetType::Min(this->AsBitset()); | 102 if (this->IsBitset()) return BitsetType::Min(this->AsBitset()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 | 138 |
119 // The largest bitset subsumed by this type. | 139 // The largest bitset subsumed by this type. |
120 template<class Config> | 140 template<class Config> |
121 typename TypeImpl<Config>::bitset | 141 typename TypeImpl<Config>::bitset |
122 TypeImpl<Config>::BitsetType::Glb(TypeImpl* type) { | 142 TypeImpl<Config>::BitsetType::Glb(TypeImpl* type) { |
123 DisallowHeapAllocation no_allocation; | 143 DisallowHeapAllocation no_allocation; |
124 if (type->IsBitset()) { | 144 if (type->IsBitset()) { |
125 return type->AsBitset(); | 145 return type->AsBitset(); |
126 } else if (type->IsUnion()) { | 146 } else if (type->IsUnion()) { |
127 SLOW_DCHECK(type->AsUnion()->Wellformed()); | 147 SLOW_DCHECK(type->AsUnion()->Wellformed()); |
128 return type->AsUnion()->Get(0)->BitsetGlb(); // Shortcut. | 148 return type->AsUnion()->Get(0)->BitsetGlb() | |
149 type->AsUnion()->Get(1)->BitsetGlb(); // Shortcut. | |
150 } else if (type->IsRange()) { | |
151 bitset glb = SEMANTIC(BitsetType::Glb(type->AsRange()->Min()->Number(), | |
152 type->AsRange()->Max()->Number())); | |
153 if (glb == 0) { | |
154 return kNone; | |
155 } else { | |
156 return glb | REPRESENTATION(type->BitsetLub()); | |
157 } | |
158 } else { | |
129 // (The remaining BitsetGlb's are None anyway). | 159 // (The remaining BitsetGlb's are None anyway). |
130 } else { | |
131 return kNone; | 160 return kNone; |
132 } | 161 } |
133 } | 162 } |
134 | 163 |
135 | 164 |
136 // The smallest bitset subsuming this type. | 165 // The smallest bitset subsuming this type. |
137 template<class Config> | 166 template<class Config> |
138 typename TypeImpl<Config>::bitset | 167 typename TypeImpl<Config>::bitset |
139 TypeImpl<Config>::BitsetType::Lub(TypeImpl* type) { | 168 TypeImpl<Config>::BitsetType::Lub(TypeImpl* type) { |
140 DisallowHeapAllocation no_allocation; | 169 DisallowHeapAllocation no_allocation; |
141 if (type->IsBitset()) return type->AsBitset(); | 170 if (type->IsBitset()) return type->AsBitset(); |
142 if (type->IsUnion()) { | 171 if (type->IsUnion()) { |
143 int bitset = kNone; | 172 int bitset = kNone; |
144 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) { | 173 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) { |
145 bitset |= type->AsUnion()->Get(i)->BitsetLub(); | 174 bitset |= type->AsUnion()->Get(i)->BitsetLub(); |
146 } | 175 } |
147 return bitset; | 176 return bitset; |
148 } | 177 } |
149 if (type->IsClass()) { | 178 if (type->IsClass()) { |
150 // Little hack to avoid the need for a region for handlification here... | 179 // Little hack to avoid the need for a region for handlification here... |
151 return Config::is_class(type) ? Lub(*Config::as_class(type)) : | 180 return Config::is_class(type) ? Lub(*Config::as_class(type)) : |
152 type->AsClass()->Bound(NULL)->AsBitset(); | 181 type->AsClass()->Bound(NULL)->AsBitset(); |
153 } | 182 } |
154 if (type->IsConstant()) return type->AsConstant()->Bound()->AsBitset(); | 183 if (type->IsConstant()) return type->AsConstant()->Bound()->AsBitset(); |
155 if (type->IsRange()) return type->AsRange()->BitsetLub(); | 184 if (type->IsRange()) return type->AsRange()->Bound()->AsBitset(); |
156 if (type->IsContext()) return kInternal & kTaggedPointer; | 185 if (type->IsContext()) return kInternal & kTaggedPointer; |
157 if (type->IsArray()) return kArray; | 186 if (type->IsArray()) return kArray; |
158 if (type->IsFunction()) return kOtherObject; // TODO(rossberg): kFunction | 187 if (type->IsFunction()) return kOtherObject; // TODO(rossberg): kFunction |
159 UNREACHABLE(); | 188 UNREACHABLE(); |
160 return kNone; | 189 return kNone; |
161 } | 190 } |
162 | 191 |
163 | 192 |
164 template<class Config> | 193 template<class Config> |
165 typename TypeImpl<Config>::bitset | 194 typename TypeImpl<Config>::bitset |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 typename TypeImpl<Config>::bitset | 306 typename TypeImpl<Config>::bitset |
278 TypeImpl<Config>::BitsetType::Lub(double value) { | 307 TypeImpl<Config>::BitsetType::Lub(double value) { |
279 DisallowHeapAllocation no_allocation; | 308 DisallowHeapAllocation no_allocation; |
280 if (i::IsMinusZero(value)) return kMinusZero; | 309 if (i::IsMinusZero(value)) return kMinusZero; |
281 if (std::isnan(value)) return kNaN; | 310 if (std::isnan(value)) return kNaN; |
282 if (IsUint32Double(value) || IsInt32Double(value)) return Lub(value, value); | 311 if (IsUint32Double(value) || IsInt32Double(value)) return Lub(value, value); |
283 return kPlainNumber; | 312 return kPlainNumber; |
284 } | 313 } |
285 | 314 |
286 | 315 |
287 // Minimum values of regular numeric bitsets when SmiValuesAre31Bits. | 316 // Minimum values of regular numeric bitsets. |
288 template <class Config> | 317 template <class Config> |
289 const typename TypeImpl<Config>::BitsetType::BitsetMin | 318 const typename TypeImpl<Config>::BitsetType::Boundary |
290 TypeImpl<Config>::BitsetType::BitsetMins31[] = { | 319 TypeImpl<Config>::BitsetType::BoundariesArray[] = { |
291 {kOtherNumber, -V8_INFINITY}, | 320 {kPlainNumber, -V8_INFINITY}, |
292 {kOtherSigned32, kMinInt}, | 321 {kNegative32, kMinInt}, |
293 {kNegativeSignedSmall, -0x40000000}, | 322 {kNegative31, -0x40000000}, |
294 {kUnsignedSmall, 0}, | 323 {kUnsigned30, 0}, |
295 {kOtherUnsigned31, 0x40000000}, | 324 {kUnsigned31, 0x40000000}, |
296 {kOtherUnsigned32, 0x80000000}, | 325 {kUnsigned32, 0x80000000}, |
297 {kOtherNumber, static_cast<double>(kMaxUInt32) + 1}}; | 326 {kPlainNumber, static_cast<double>(kMaxUInt32) + 1} |
327 }; | |
298 | 328 |
299 | 329 |
300 // Minimum values of regular numeric bitsets when SmiValuesAre32Bits. | |
301 // OtherSigned32 and OtherUnsigned31 are empty (see the diagrams in types.h). | |
302 template <class Config> | 330 template <class Config> |
303 const typename TypeImpl<Config>::BitsetType::BitsetMin | 331 const typename TypeImpl<Config>::BitsetType::Boundary* |
304 TypeImpl<Config>::BitsetType::BitsetMins32[] = { | 332 TypeImpl<Config>::BitsetType::Boundaries() { |
305 {kOtherNumber, -V8_INFINITY}, | 333 return BoundariesArray; |
306 {kNegativeSignedSmall, kMinInt}, | 334 } |
307 {kUnsignedSmall, 0}, | 335 |
308 {kOtherUnsigned32, 0x80000000}, | 336 |
309 {kOtherNumber, static_cast<double>(kMaxUInt32) + 1}}; | 337 template <class Config> |
338 size_t TypeImpl<Config>::BitsetType::BoundariesSize() { | |
339 // Windows doesn't like arraysize here. | |
340 // return arraysize(BoundariesArray); | |
341 return 7; | |
342 } | |
310 | 343 |
311 | 344 |
312 template<class Config> | 345 template<class Config> |
313 typename TypeImpl<Config>::bitset | 346 typename TypeImpl<Config>::bitset |
314 TypeImpl<Config>::BitsetType::Lub(double min, double max) { | 347 TypeImpl<Config>::BitsetType::Lub(double min, double max) { |
315 DisallowHeapAllocation no_allocation; | 348 DisallowHeapAllocation no_allocation; |
316 int lub = kNone; | 349 int lub = kNone; |
317 const BitsetMin* mins = BitsetMins(); | 350 const Boundary* mins = Boundaries(); |
318 | 351 |
319 // Make sure the min-max range touches 0, so we are guaranteed no holes | 352 // Make sure the min-max range touches 0, so we are guaranteed no holes |
320 // in unions of valid bitsets. | 353 // in unions of valid bitsets. |
321 if (max < -1) max = -1; | 354 if (max < -1) max = -1; |
322 if (min > 0) min = 0; | 355 if (min > 0) min = 0; |
323 | 356 |
324 for (size_t i = 1; i < BitsetMinsSize(); ++i) { | 357 for (size_t i = 1; i < BoundariesSize(); ++i) { |
325 if (min < mins[i].min) { | 358 if (min < mins[i].min) { |
326 lub |= mins[i-1].bits; | 359 lub |= mins[i-1].bits; |
327 if (max < mins[i].min) return lub; | 360 if (max < mins[i].min) return lub; |
328 } | 361 } |
329 } | 362 } |
330 return lub |= mins[BitsetMinsSize()-1].bits; | 363 return lub |= mins[BoundariesSize() - 1].bits; |
331 } | 364 } |
332 | 365 |
333 | 366 |
334 template<class Config> | 367 template <class Config> |
368 typename TypeImpl<Config>::bitset TypeImpl<Config>::BitsetType::NumberBits( | |
369 bitset bits) { | |
370 return SEMANTIC(bits & kPlainNumber); | |
371 } | |
372 | |
373 | |
374 template <class Config> | |
375 void TypeImpl<Config>::BitsetType::CheckNumberBits(bitset bits) { | |
376 // Check that the bitset does not contain any holes in number ranges. | |
377 bitset number_bits = NumberBits(bits); | |
378 if (number_bits != 0) { | |
379 bitset lub = SEMANTIC(Lub(Min(number_bits), Max(number_bits))); | |
380 CHECK(lub == number_bits); | |
381 } | |
382 } | |
383 | |
384 template <class Config> | |
385 typename TypeImpl<Config>::bitset TypeImpl<Config>::BitsetType::Glb( | |
386 double min, double max) { | |
387 DisallowHeapAllocation no_allocation; | |
388 int glb = kNone; | |
389 const Boundary* mins = Boundaries(); | |
390 | |
391 // If the range does not touch 0, the bound is empty. | |
392 if (max < -1 || min > 0) return glb; | |
393 | |
394 for (size_t i = 1; i + 1 < BoundariesSize(); ++i) { | |
395 if (min <= mins[i].min) { | |
396 if (max + 1 < mins[i + 1].min) break; | |
397 glb |= mins[i].bits; | |
398 } | |
399 } | |
400 // OtherNumber also contains float numbers, so it can never be | |
401 // in the greatest lower bound. (There is also the small trouble | |
402 // of kOtherNumber having a range hole, which we can conveniently | |
403 // ignore here.) | |
404 return glb & ~(SEMANTIC(kOtherNumber)); | |
405 } | |
406 | |
407 | |
408 template <class Config> | |
335 double TypeImpl<Config>::BitsetType::Min(bitset bits) { | 409 double TypeImpl<Config>::BitsetType::Min(bitset bits) { |
336 DisallowHeapAllocation no_allocation; | 410 DisallowHeapAllocation no_allocation; |
337 DCHECK(Is(bits, kNumber)); | 411 DCHECK(Is(bits, kNumber)); |
338 const BitsetMin* mins = BitsetMins(); | 412 const Boundary* mins = Boundaries(); |
339 bool mz = SEMANTIC(bits & kMinusZero); | 413 bool mz = SEMANTIC(bits & kMinusZero); |
340 for (size_t i = 0; i < BitsetMinsSize(); ++i) { | 414 for (size_t i = 0; i < BoundariesSize(); ++i) { |
341 if (Is(SEMANTIC(mins[i].bits), bits)) { | 415 if (Is(SEMANTIC(mins[i].bits), bits)) { |
342 return mz ? std::min(0.0, mins[i].min) : mins[i].min; | 416 return mz ? std::min(0.0, mins[i].min) : mins[i].min; |
343 } | 417 } |
344 } | 418 } |
345 if (mz) return 0; | 419 if (mz) return 0; |
346 return std::numeric_limits<double>::quiet_NaN(); | 420 return std::numeric_limits<double>::quiet_NaN(); |
347 } | 421 } |
348 | 422 |
349 | 423 |
350 template<class Config> | 424 template<class Config> |
351 double TypeImpl<Config>::BitsetType::Max(bitset bits) { | 425 double TypeImpl<Config>::BitsetType::Max(bitset bits) { |
352 DisallowHeapAllocation no_allocation; | 426 DisallowHeapAllocation no_allocation; |
353 DCHECK(Is(bits, kNumber)); | 427 DCHECK(Is(bits, kNumber)); |
354 const BitsetMin* mins = BitsetMins(); | 428 const Boundary* mins = Boundaries(); |
355 bool mz = SEMANTIC(bits & kMinusZero); | 429 bool mz = SEMANTIC(bits & kMinusZero); |
356 if (BitsetType::Is(mins[BitsetMinsSize()-1].bits, bits)) { | 430 if (BitsetType::Is(SEMANTIC(mins[BoundariesSize() - 1].bits), bits)) { |
357 return +V8_INFINITY; | 431 return +V8_INFINITY; |
358 } | 432 } |
359 for (size_t i = BitsetMinsSize()-1; i-- > 0; ) { | 433 for (size_t i = BoundariesSize() - 1; i-- > 0;) { |
360 if (Is(SEMANTIC(mins[i].bits), bits)) { | 434 if (Is(SEMANTIC(mins[i].bits), bits)) { |
361 return mz ? | 435 return mz ? |
362 std::max(0.0, mins[i+1].min - 1) : mins[i+1].min - 1; | 436 std::max(0.0, mins[i+1].min - 1) : mins[i+1].min - 1; |
363 } | 437 } |
364 } | 438 } |
365 if (mz) return 0; | 439 if (mz) return 0; |
366 return std::numeric_limits<double>::quiet_NaN(); | 440 return std::numeric_limits<double>::quiet_NaN(); |
367 } | 441 } |
368 | 442 |
369 | 443 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 // T <= (T1 \/ ... \/ Tn) if (T <= T1) \/ ... \/ (T <= Tn) | 506 // T <= (T1 \/ ... \/ Tn) if (T <= T1) \/ ... \/ (T <= Tn) |
433 if (that->IsUnion()) { | 507 if (that->IsUnion()) { |
434 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) { | 508 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) { |
435 if (this->Is(that->AsUnion()->Get(i))) return true; | 509 if (this->Is(that->AsUnion()->Get(i))) return true; |
436 if (i > 1 && this->IsRange()) return false; // Shortcut. | 510 if (i > 1 && this->IsRange()) return false; // Shortcut. |
437 } | 511 } |
438 return false; | 512 return false; |
439 } | 513 } |
440 | 514 |
441 if (that->IsRange()) { | 515 if (that->IsRange()) { |
442 return (this->IsRange() && Contains(that->AsRange(), this->AsRange())) | 516 return (this->IsRange() && Contains(that->AsRange(), this->AsRange())) || |
443 || (this->IsConstant() && | 517 (this->IsConstant() && |
444 Contains(that->AsRange(), *this->AsConstant()->Value())); | 518 Contains(that->AsRange(), this->AsConstant())); |
445 } | 519 } |
446 if (this->IsRange()) return false; | 520 if (this->IsRange()) return false; |
447 | 521 |
448 return this->SimplyEquals(that); | 522 return this->SimplyEquals(that); |
449 } | 523 } |
450 | 524 |
451 | 525 |
452 template<class Config> | 526 template<class Config> |
453 bool TypeImpl<Config>::NowIs(TypeImpl* that) { | 527 bool TypeImpl<Config>::NowIs(TypeImpl* that) { |
454 DisallowHeapAllocation no_allocation; | 528 DisallowHeapAllocation no_allocation; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 // T overlaps (T1 \/ ... \/ Tn) if (T overlaps T1) \/ ... \/ (T overlaps Tn) | 570 // T overlaps (T1 \/ ... \/ Tn) if (T overlaps T1) \/ ... \/ (T overlaps Tn) |
497 if (that->IsUnion()) { | 571 if (that->IsUnion()) { |
498 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) { | 572 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) { |
499 if (this->Maybe(that->AsUnion()->Get(i))) return true; | 573 if (this->Maybe(that->AsUnion()->Get(i))) return true; |
500 } | 574 } |
501 return false; | 575 return false; |
502 } | 576 } |
503 | 577 |
504 if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub())) | 578 if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub())) |
505 return false; | 579 return false; |
506 if (this->IsBitset() || that->IsBitset()) return true; | 580 |
581 if (this->IsBitset() && that->IsBitset()) return true; | |
507 | 582 |
508 if (this->IsClass() != that->IsClass()) return true; | 583 if (this->IsClass() != that->IsClass()) return true; |
509 | 584 |
510 if (this->IsRange()) { | 585 if (this->IsRange()) { |
511 if (that->IsConstant()) { | 586 if (that->IsConstant()) { |
512 return Contains(this->AsRange(), *that->AsConstant()->Value()); | 587 return Contains(this->AsRange(), that->AsConstant()); |
513 } | 588 } |
514 return that->IsRange() && Overlap(this->AsRange(), that->AsRange()); | 589 if (that->IsRange()) { |
590 return Overlap(this->AsRange(), that->AsRange()); | |
591 } | |
592 if (that->IsBitset()) { | |
593 bitset number_bits = BitsetType::NumberBits(that->AsBitset()); | |
594 if (number_bits == BitsetType::kNone) { | |
595 return false; | |
596 } | |
597 double min = std::max(BitsetType::Min(number_bits), this->Min()); | |
598 double max = std::min(BitsetType::Max(number_bits), this->Max()); | |
599 return min <= max; | |
600 } | |
515 } | 601 } |
516 if (that->IsRange()) { | 602 if (that->IsRange()) { |
517 if (this->IsConstant()) { | 603 return that->Maybe(this); // This case is handled above. |
518 return Contains(that->AsRange(), *this->AsConstant()->Value()); | |
519 } | |
520 return this->IsRange() && Overlap(this->AsRange(), that->AsRange()); | |
521 } | 604 } |
522 | 605 |
606 if (this->IsBitset() || that->IsBitset()) return true; | |
607 | |
523 return this->SimplyEquals(that); | 608 return this->SimplyEquals(that); |
524 } | 609 } |
525 | 610 |
526 | 611 |
527 // Return the range in [this], or [NULL]. | 612 // Return the range in [this], or [NULL]. |
528 template<class Config> | 613 template<class Config> |
529 typename TypeImpl<Config>::RangeType* TypeImpl<Config>::GetRange() { | 614 typename TypeImpl<Config>::RangeType* TypeImpl<Config>::GetRange() { |
530 DisallowHeapAllocation no_allocation; | 615 DisallowHeapAllocation no_allocation; |
531 if (this->IsRange()) return this->AsRange(); | 616 if (this->IsRange()) return this->AsRange(); |
532 if (this->IsUnion() && this->AsUnion()->Get(1)->IsRange()) { | 617 if (this->IsUnion() && this->AsUnion()->Get(1)->IsRange()) { |
(...skipping 20 matching lines...) Expand all Loading... | |
553 template<class Config> | 638 template<class Config> |
554 bool TypeImpl<Config>::UnionType::Wellformed() { | 639 bool TypeImpl<Config>::UnionType::Wellformed() { |
555 DisallowHeapAllocation no_allocation; | 640 DisallowHeapAllocation no_allocation; |
556 // This checks the invariants of the union representation: | 641 // This checks the invariants of the union representation: |
557 // 1. There are at least two elements. | 642 // 1. There are at least two elements. |
558 // 2. At most one element is a bitset, and it must be the first one. | 643 // 2. At most one element is a bitset, and it must be the first one. |
559 // 3. At most one element is a range, and it must be the second one | 644 // 3. At most one element is a range, and it must be the second one |
560 // (even when the first element is not a bitset). | 645 // (even when the first element is not a bitset). |
561 // 4. No element is itself a union. | 646 // 4. No element is itself a union. |
562 // 5. No element is a subtype of any other. | 647 // 5. No element is a subtype of any other. |
648 // 6. If there is a range, then the bitset type does not contain | |
649 // plain number bits. | |
563 DCHECK(this->Length() >= 2); // (1) | 650 DCHECK(this->Length() >= 2); // (1) |
651 | |
652 bitset number_bits = this->Get(0)->IsBitset() | |
653 ? BitsetType::NumberBits(this->Get(0)->AsBitset()) : 0; | |
654 USE(number_bits); | |
655 | |
564 for (int i = 0; i < this->Length(); ++i) { | 656 for (int i = 0; i < this->Length(); ++i) { |
565 if (i != 0) DCHECK(!this->Get(i)->IsBitset()); // (2) | 657 if (i != 0) DCHECK(!this->Get(i)->IsBitset()); // (2) |
566 if (i != 1) DCHECK(!this->Get(i)->IsRange()); // (3) | 658 if (i != 1) DCHECK(!this->Get(i)->IsRange()); // (3) |
567 DCHECK(!this->Get(i)->IsUnion()); // (4) | 659 DCHECK(!this->Get(i)->IsUnion()); // (4) |
568 for (int j = 0; j < this->Length(); ++j) { | 660 for (int j = 0; j < this->Length(); ++j) { |
569 if (i != j) DCHECK(!this->Get(i)->Is(this->Get(j))); // (5) | 661 if (i != j) DCHECK(!this->Get(i)->Is(this->Get(j))); // (5) |
570 } | 662 } |
571 } | 663 } |
664 DCHECK(!this->Get(1)->IsRange() || (number_bits == 0)); // (6) | |
572 return true; | 665 return true; |
573 } | 666 } |
574 | 667 |
575 | 668 |
576 // ----------------------------------------------------------------------------- | 669 // ----------------------------------------------------------------------------- |
577 // Union and intersection | 670 // Union and intersection |
578 | 671 |
579 | 672 |
580 static bool AddIsSafe(int x, int y) { | 673 static bool AddIsSafe(int x, int y) { |
581 return x >= 0 ? | 674 return x >= 0 ? |
(...skipping 26 matching lines...) Expand all Loading... | |
608 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; | 701 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; |
609 if (!AddIsSafe(size1, size2)) return Any(region); | 702 if (!AddIsSafe(size1, size2)) return Any(region); |
610 int size = size1 + size2; | 703 int size = size1 + size2; |
611 if (!AddIsSafe(size, 2)) return Any(region); | 704 if (!AddIsSafe(size, 2)) return Any(region); |
612 size += 2; | 705 size += 2; |
613 UnionHandle result = UnionType::New(size, region); | 706 UnionHandle result = UnionType::New(size, region); |
614 size = 0; | 707 size = 0; |
615 | 708 |
616 // Deal with bitsets. | 709 // Deal with bitsets. |
617 result->Set(size++, BitsetType::New(bits, region)); | 710 result->Set(size++, BitsetType::New(bits, region)); |
711 // Insert a placeholder for the range. | |
712 result->Set(size++, None(region)); | |
618 | 713 |
619 // Deal with ranges. | 714 Limits lims = Limits::Empty(region); |
620 TypeHandle range = None(region); | 715 size = IntersectAux(type1, type2, result, size, &lims, region); |
621 RangeType* range1 = type1->GetRange(); | 716 |
622 RangeType* range2 = type2->GetRange(); | 717 // If the range is not empty, then insert it into the union and |
623 if (range1 != NULL && range2 != NULL) { | 718 // remove the number bits from the bitset. |
624 Limits lim = Intersect(Limits(range1), Limits(range2)); | 719 if (!IsEmpty(lims)) { |
625 if (lim.min->Number() <= lim.max->Number()) { | 720 size = UpdateRange(RangeType::New(lims, region), result, size, region); |
626 range = RangeType::New(lim, region); | 721 |
722 // Remove the number bits. | |
723 bitset number_bits = BitsetType::NumberBits(bits); | |
724 bits &= ~number_bits; | |
725 if (SEMANTIC(bits) == BitsetType::kNone) { | |
726 bits = BitsetType::kNone; | |
627 } | 727 } |
728 result->Set(0, BitsetType::New(bits, region)); | |
628 } | 729 } |
629 result->Set(size++, range); | |
630 | |
631 size = IntersectAux(type1, type2, result, size, region); | |
632 return NormalizeUnion(result, size); | 730 return NormalizeUnion(result, size); |
633 } | 731 } |
634 | 732 |
635 | 733 |
636 template<class Config> | 734 template<class Config> |
637 int TypeImpl<Config>::UpdateRange( | 735 int TypeImpl<Config>::UpdateRange( |
638 RangeHandle range, UnionHandle result, int size, Region* region) { | 736 RangeHandle range, UnionHandle result, int size, Region* region) { |
639 TypeHandle old_range = result->Get(1); | 737 TypeHandle old_range = result->Get(1); |
640 DCHECK(old_range->IsRange() || old_range->IsNone()); | 738 DCHECK(old_range->IsRange() || old_range->IsNone()); |
641 if (range->Is(old_range)) return size; | 739 if (range->Is(old_range)) return size; |
642 if (!old_range->Is(range->unhandle())) { | 740 if (!old_range->Is(range->unhandle())) { |
643 range = RangeType::New( | 741 range = RangeType::New( |
644 Union(Limits(range->AsRange()), Limits(old_range->AsRange())), region); | 742 Union(Limits(range->AsRange()), Limits(old_range->AsRange())), region); |
645 } | 743 } |
646 result->Set(1, range); | 744 result->Set(1, range); |
647 | 745 |
648 // Remove any components that just got subsumed. | 746 // Remove any components that just got subsumed. |
649 for (int i = 2; i < size; ) { | 747 for (int i = 2; i < size; ) { |
650 if (result->Get(i)->Is(range->unhandle())) { | 748 if (result->Get(i)->Is(range->unhandle())) { |
651 result->Set(i, result->Get(--size)); | 749 result->Set(i, result->Get(--size)); |
652 } else { | 750 } else { |
653 ++i; | 751 ++i; |
654 } | 752 } |
655 } | 753 } |
656 return size; | 754 return size; |
657 } | 755 } |
658 | 756 |
659 | 757 |
660 template<class Config> | 758 template <class Config> |
661 int TypeImpl<Config>::IntersectAux( | 759 typename TypeImpl<Config>::Limits TypeImpl<Config>::ToLimits(bitset bits, |
662 TypeHandle lhs, TypeHandle rhs, | 760 Region* region) { |
663 UnionHandle result, int size, Region* region) { | 761 bitset representation = REPRESENTATION(bits); |
762 bitset number_bits = BitsetType::NumberBits(bits); | |
763 | |
764 if (representation == BitsetType::kNone && number_bits == BitsetType::kNone) { | |
765 return Limits::Empty(region); | |
766 } | |
767 | |
768 double bitset_min = BitsetType::Min(number_bits); | |
769 double bitset_max = BitsetType::Max(number_bits); | |
770 | |
771 // TODO(jarin) Get rid of the heap numbers. | |
772 i::Factory* f = i::Isolate::Current()->factory(); | |
Benedikt Meurer
2015/01/27 18:13:47
Urghs...this is awefull...but I guess we can live
| |
773 | |
774 return Limits(f->NewNumber(bitset_min), f->NewNumber(bitset_max), | |
775 representation); | |
776 } | |
777 | |
778 | |
779 template <class Config> | |
780 typename TypeImpl<Config>::Limits TypeImpl<Config>::IntersectRangeAndBitset( | |
781 TypeHandle range, TypeHandle bitset, Region* region) { | |
782 Limits range_lims(range->AsRange()); | |
783 Limits bitset_lims = ToLimits(bitset->AsBitset(), region); | |
784 return Intersect(range_lims, bitset_lims); | |
785 } | |
786 | |
787 | |
788 template <class Config> | |
789 int TypeImpl<Config>::IntersectAux(TypeHandle lhs, TypeHandle rhs, | |
790 UnionHandle result, int size, Limits* lims, | |
791 Region* region) { | |
664 if (lhs->IsUnion()) { | 792 if (lhs->IsUnion()) { |
665 for (int i = 0, n = lhs->AsUnion()->Length(); i < n; ++i) { | 793 for (int i = 0, n = lhs->AsUnion()->Length(); i < n; ++i) { |
666 size = IntersectAux(lhs->AsUnion()->Get(i), rhs, result, size, region); | 794 size = |
795 IntersectAux(lhs->AsUnion()->Get(i), rhs, result, size, lims, region); | |
667 } | 796 } |
668 return size; | 797 return size; |
669 } | 798 } |
670 if (rhs->IsUnion()) { | 799 if (rhs->IsUnion()) { |
671 for (int i = 0, n = rhs->AsUnion()->Length(); i < n; ++i) { | 800 for (int i = 0, n = rhs->AsUnion()->Length(); i < n; ++i) { |
672 size = IntersectAux(lhs, rhs->AsUnion()->Get(i), result, size, region); | 801 size = |
802 IntersectAux(lhs, rhs->AsUnion()->Get(i), result, size, lims, region); | |
673 } | 803 } |
674 return size; | 804 return size; |
675 } | 805 } |
676 | 806 |
677 if (!BitsetType::IsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) { | 807 if (!BitsetType::IsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) { |
678 return size; | 808 return size; |
679 } | 809 } |
680 | 810 |
681 if (lhs->IsRange()) { | 811 if (lhs->IsRange()) { |
682 if (rhs->IsBitset() || rhs->IsClass()) { | 812 if (rhs->IsBitset()) { |
683 return UpdateRange( | 813 Limits lim = IntersectRangeAndBitset(lhs, rhs, region); |
684 Config::template cast<RangeType>(lhs), result, size, region); | 814 |
815 if (!IsEmpty(lim)) { | |
816 *lims = Union(lim, *lims); | |
817 } | |
818 return size; | |
685 } | 819 } |
686 if (rhs->IsConstant() && | 820 if (rhs->IsClass()) { |
687 Contains(lhs->AsRange(), *rhs->AsConstant()->Value())) { | 821 *lims = Union(Limits(lhs->AsRange()), *lims); |
822 } | |
823 if (rhs->IsConstant() && Contains(lhs->AsRange(), rhs->AsConstant())) { | |
688 return AddToUnion(rhs, result, size, region); | 824 return AddToUnion(rhs, result, size, region); |
689 } | 825 } |
826 if (rhs->IsRange()) { | |
827 Limits lim = Intersect(Limits(lhs->AsRange()), Limits(rhs->AsRange())); | |
828 if (!IsEmpty(lim)) { | |
829 *lims = Union(lim, *lims); | |
830 } | |
831 } | |
690 return size; | 832 return size; |
691 } | 833 } |
692 if (rhs->IsRange()) { | 834 if (rhs->IsRange()) { |
693 if (lhs->IsBitset() || lhs->IsClass()) { | 835 // This case is handled symmetrically above. |
694 return UpdateRange( | 836 return IntersectAux(rhs, lhs, result, size, lims, region); |
695 Config::template cast<RangeType>(rhs), result, size, region); | |
696 } | |
697 if (lhs->IsConstant() && | |
698 Contains(rhs->AsRange(), *lhs->AsConstant()->Value())) { | |
699 return AddToUnion(lhs, result, size, region); | |
700 } | |
701 return size; | |
702 } | 837 } |
703 | |
704 if (lhs->IsBitset() || rhs->IsBitset()) { | 838 if (lhs->IsBitset() || rhs->IsBitset()) { |
705 return AddToUnion(lhs->IsBitset() ? rhs : lhs, result, size, region); | 839 return AddToUnion(lhs->IsBitset() ? rhs : lhs, result, size, region); |
706 } | 840 } |
707 if (lhs->IsClass() != rhs->IsClass()) { | 841 if (lhs->IsClass() != rhs->IsClass()) { |
708 return AddToUnion(lhs->IsClass() ? rhs : lhs, result, size, region); | 842 return AddToUnion(lhs->IsClass() ? rhs : lhs, result, size, region); |
709 } | 843 } |
710 if (lhs->SimplyEquals(rhs->unhandle())) { | 844 if (lhs->SimplyEquals(rhs->unhandle())) { |
711 return AddToUnion(lhs, result, size, region); | 845 return AddToUnion(lhs, result, size, region); |
712 } | 846 } |
713 return size; | 847 return size; |
714 } | 848 } |
715 | 849 |
716 | 850 |
851 // Make sure that we produce a well-formed range and bitset: | |
852 // If the range is non-empty, the number bits in the bitset should be | |
853 // clear. Moreover, if we have a canonical range (such as Signed32(), | |
854 // we want to produce a bitset rather than a range. | |
855 template <class Config> | |
856 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NormalizeRangeAndBitset( | |
857 RangeHandle range, bitset* bits, Region* region) { | |
858 // Fast path: If the bitset does not mention numbers, we can just keep the | |
859 // range. | |
860 bitset number_bits = BitsetType::NumberBits(*bits); | |
861 if (number_bits == 0) { | |
862 return range; | |
863 } | |
864 | |
865 // If the range is contained within the bitset, return an empty range | |
866 // (but make sure we take the representation). | |
867 bitset range_lub = range->BitsetLub(); | |
868 if (BitsetType::Is(BitsetType::NumberBits(range_lub), *bits)) { | |
869 *bits |= range_lub; | |
870 return None(region); | |
871 } | |
872 | |
873 // Slow path: reconcile the bitset range and the range. | |
874 double bitset_min = BitsetType::Min(number_bits); | |
875 double bitset_max = BitsetType::Max(number_bits); | |
876 | |
877 i::Handle<i::Object> range_min_obj = range->Min(); | |
878 i::Handle<i::Object> range_max_obj = range->Max(); | |
879 double range_min = range_min_obj->Number(); | |
880 double range_max = range_max_obj->Number(); | |
881 | |
882 bitset range_representation = REPRESENTATION(range->BitsetLub()); | |
883 bitset bits_representation = REPRESENTATION(*bits); | |
884 bitset representation = | |
885 (bits_representation | range_representation) & BitsetType::kNumber; | |
886 | |
887 // Remove the number bits from the bitset, they would just confuse us now. | |
888 *bits &= ~number_bits; | |
889 if (bits_representation == *bits) { | |
890 *bits = BitsetType::kNone; | |
891 } | |
892 | |
893 if (representation == range_representation && range_min <= bitset_min && | |
894 range_max >= bitset_max) { | |
895 // Bitset is contained within the range, just return the range. | |
896 return range; | |
897 } | |
898 | |
899 if (bitset_min < range_min) { | |
900 // TODO(jarin) Get rid of the heap numbers. | |
901 range_min_obj = i::Isolate::Current()->factory()->NewNumber(bitset_min); | |
902 } | |
903 if (bitset_max > range_max) { | |
904 // TODO(jarin) Get rid of the heap numbers. | |
905 range_max_obj = i::Isolate::Current()->factory()->NewNumber(bitset_max); | |
906 } | |
907 return RangeType::New(range_min_obj, range_max_obj, | |
908 BitsetType::New(representation, region), region); | |
909 } | |
910 | |
911 | |
717 template<class Config> | 912 template<class Config> |
718 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union( | 913 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union( |
719 TypeHandle type1, TypeHandle type2, Region* region) { | 914 TypeHandle type1, TypeHandle type2, Region* region) { |
720 | 915 |
721 // Fast case: bit sets. | 916 // Fast case: bit sets. |
722 if (type1->IsBitset() && type2->IsBitset()) { | 917 if (type1->IsBitset() && type2->IsBitset()) { |
723 return BitsetType::New(type1->AsBitset() | type2->AsBitset(), region); | 918 return BitsetType::New(type1->AsBitset() | type2->AsBitset(), region); |
724 } | 919 } |
725 | 920 |
726 // Fast case: top or bottom types. | 921 // Fast case: top or bottom types. |
727 if (type1->IsAny() || type2->IsNone()) return type1; | 922 if (type1->IsAny() || type2->IsNone()) return type1; |
728 if (type2->IsAny() || type1->IsNone()) return type2; | 923 if (type2->IsAny() || type1->IsNone()) return type2; |
729 | 924 |
730 // Semi-fast case. | 925 // Semi-fast case. |
731 if (type1->Is(type2)) return type2; | 926 if (type1->Is(type2)) return type2; |
732 if (type2->Is(type1)) return type1; | 927 if (type2->Is(type1)) return type1; |
733 | 928 |
734 // Slow case: create union. | 929 // Slow case: create union. |
735 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1; | 930 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1; |
736 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; | 931 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; |
737 if (!AddIsSafe(size1, size2)) return Any(region); | 932 if (!AddIsSafe(size1, size2)) return Any(region); |
738 int size = size1 + size2; | 933 int size = size1 + size2; |
739 if (!AddIsSafe(size, 2)) return Any(region); | 934 if (!AddIsSafe(size, 2)) return Any(region); |
740 size += 2; | 935 size += 2; |
741 UnionHandle result = UnionType::New(size, region); | 936 UnionHandle result = UnionType::New(size, region); |
742 size = 0; | 937 size = 0; |
743 | 938 |
744 // Deal with bitsets. | 939 // Compute the new bitset. |
745 TypeHandle bits = BitsetType::New( | 940 bitset new_bitset = type1->BitsetGlb() | type2->BitsetGlb(); |
746 type1->BitsetGlb() | type2->BitsetGlb(), region); | |
747 result->Set(size++, bits); | |
748 | 941 |
749 // Deal with ranges. | 942 // Deal with ranges. |
750 TypeHandle range = None(region); | 943 TypeHandle range = None(region); |
751 RangeType* range1 = type1->GetRange(); | 944 RangeType* range1 = type1->GetRange(); |
752 RangeType* range2 = type2->GetRange(); | 945 RangeType* range2 = type2->GetRange(); |
753 if (range1 != NULL && range2 != NULL) { | 946 if (range1 != NULL && range2 != NULL) { |
754 range = RangeType::New(Union(Limits(range1), Limits(range2)), region); | 947 Limits lims = Union(Limits(range1), Limits(range2)); |
948 RangeHandle union_range = RangeType::New(lims, region); | |
949 range = NormalizeRangeAndBitset(union_range, &new_bitset, region); | |
755 } else if (range1 != NULL) { | 950 } else if (range1 != NULL) { |
756 range = handle(range1); | 951 range = NormalizeRangeAndBitset(handle(range1), &new_bitset, region); |
757 } else if (range2 != NULL) { | 952 } else if (range2 != NULL) { |
758 range = handle(range2); | 953 range = NormalizeRangeAndBitset(handle(range2), &new_bitset, region); |
759 } | 954 } |
955 TypeHandle bits = BitsetType::New(new_bitset, region); | |
956 result->Set(size++, bits); | |
760 result->Set(size++, range); | 957 result->Set(size++, range); |
761 | 958 |
762 size = AddToUnion(type1, result, size, region); | 959 size = AddToUnion(type1, result, size, region); |
763 size = AddToUnion(type2, result, size, region); | 960 size = AddToUnion(type2, result, size, region); |
764 return NormalizeUnion(result, size); | 961 return NormalizeUnion(result, size); |
765 } | 962 } |
766 | 963 |
767 | 964 |
768 // Add [type] to [result] unless [type] is bitset, range, or already subsumed. | 965 // Add [type] to [result] unless [type] is bitset, range, or already subsumed. |
769 // Return new size of [result]. | 966 // Return new size of [result]. |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert( | 1109 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert( |
913 typename OtherType::TypeHandle type, Region* region) { | 1110 typename OtherType::TypeHandle type, Region* region) { |
914 if (type->IsBitset()) { | 1111 if (type->IsBitset()) { |
915 return BitsetType::New(type->AsBitset(), region); | 1112 return BitsetType::New(type->AsBitset(), region); |
916 } else if (type->IsClass()) { | 1113 } else if (type->IsClass()) { |
917 return ClassType::New(type->AsClass()->Map(), region); | 1114 return ClassType::New(type->AsClass()->Map(), region); |
918 } else if (type->IsConstant()) { | 1115 } else if (type->IsConstant()) { |
919 return ConstantType::New(type->AsConstant()->Value(), region); | 1116 return ConstantType::New(type->AsConstant()->Value(), region); |
920 } else if (type->IsRange()) { | 1117 } else if (type->IsRange()) { |
921 return RangeType::New( | 1118 return RangeType::New( |
922 type->AsRange()->Min(), type->AsRange()->Max(), region); | 1119 type->AsRange()->Min(), type->AsRange()->Max(), |
1120 BitsetType::New(REPRESENTATION(type->BitsetLub()), region), region); | |
923 } else if (type->IsContext()) { | 1121 } else if (type->IsContext()) { |
924 TypeHandle outer = Convert<OtherType>(type->AsContext()->Outer(), region); | 1122 TypeHandle outer = Convert<OtherType>(type->AsContext()->Outer(), region); |
925 return ContextType::New(outer, region); | 1123 return ContextType::New(outer, region); |
926 } else if (type->IsUnion()) { | 1124 } else if (type->IsUnion()) { |
927 int length = type->AsUnion()->Length(); | 1125 int length = type->AsUnion()->Length(); |
928 UnionHandle unioned = UnionType::New(length, region); | 1126 UnionHandle unioned = UnionType::New(length, region); |
929 for (int i = 0; i < length; ++i) { | 1127 for (int i = 0; i < length; ++i) { |
930 TypeHandle t = Convert<OtherType>(type->AsUnion()->Get(i), region); | 1128 TypeHandle t = Convert<OtherType>(type->AsUnion()->Get(i), region); |
931 unioned->Set(i, t); | 1129 unioned->Set(i, t); |
932 } | 1130 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
978 template <class Config> | 1176 template <class Config> |
979 void TypeImpl<Config>::BitsetType::Print(std::ostream& os, // NOLINT | 1177 void TypeImpl<Config>::BitsetType::Print(std::ostream& os, // NOLINT |
980 bitset bits) { | 1178 bitset bits) { |
981 DisallowHeapAllocation no_allocation; | 1179 DisallowHeapAllocation no_allocation; |
982 const char* name = Name(bits); | 1180 const char* name = Name(bits); |
983 if (name != NULL) { | 1181 if (name != NULL) { |
984 os << name; | 1182 os << name; |
985 return; | 1183 return; |
986 } | 1184 } |
987 | 1185 |
1186 // clang-format off | |
988 static const bitset named_bitsets[] = { | 1187 static const bitset named_bitsets[] = { |
989 #define BITSET_CONSTANT(type, value) REPRESENTATION(k##type), | 1188 #define BITSET_CONSTANT(type, value) REPRESENTATION(k##type), |
990 REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT) | 1189 REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT) |
991 #undef BITSET_CONSTANT | 1190 #undef BITSET_CONSTANT |
992 | 1191 |
993 #define BITSET_CONSTANT(type, value) SEMANTIC(k##type), | 1192 #define BITSET_CONSTANT(type, value) SEMANTIC(k##type), |
994 INTERNAL_BITSET_TYPE_LIST(BITSET_CONSTANT) | 1193 INTERNAL_BITSET_TYPE_LIST(BITSET_CONSTANT) |
995 SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT) | 1194 SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT) |
996 #undef BITSET_CONSTANT | 1195 #undef BITSET_CONSTANT |
997 }; | 1196 }; |
1197 // clang-format on | |
998 | 1198 |
999 bool is_first = true; | 1199 bool is_first = true; |
1000 os << "("; | 1200 os << "("; |
1001 for (int i(arraysize(named_bitsets) - 1); bits != 0 && i >= 0; --i) { | 1201 for (int i(arraysize(named_bitsets) - 1); bits != 0 && i >= 0; --i) { |
1002 bitset subset = named_bitsets[i]; | 1202 bitset subset = named_bitsets[i]; |
1003 if ((bits & subset) == subset) { | 1203 if ((bits & subset) == subset) { |
1004 if (!is_first) os << " | "; | 1204 if (!is_first) os << " | "; |
1005 is_first = false; | 1205 is_first = false; |
1006 os << Name(subset); | 1206 os << Name(subset); |
1007 bits -= subset; | 1207 bits -= subset; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1098 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; | 1298 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; |
1099 | 1299 |
1100 template TypeImpl<ZoneTypeConfig>::TypeHandle | 1300 template TypeImpl<ZoneTypeConfig>::TypeHandle |
1101 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( | 1301 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( |
1102 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); | 1302 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); |
1103 template TypeImpl<HeapTypeConfig>::TypeHandle | 1303 template TypeImpl<HeapTypeConfig>::TypeHandle |
1104 TypeImpl<HeapTypeConfig>::Convert<Type>( | 1304 TypeImpl<HeapTypeConfig>::Convert<Type>( |
1105 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); | 1305 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); |
1106 | 1306 |
1107 } } // namespace v8::internal | 1307 } } // namespace v8::internal |
OLD | NEW |