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