Chromium Code Reviews| 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) { | |
| 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 | 333 |
| 298 | 334 |
| 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> | 335 template <class Config> |
| 302 const typename TypeImpl<Config>::BitsetType::BitsetMin | 336 const typename TypeImpl<Config>::BitsetType::BitsetBoundary* |
| 303 TypeImpl<Config>::BitsetType::BitsetMins32[] = { | 337 TypeImpl<Config>::BitsetType::BitsetBoundaries() { |
| 304 {kOtherNumber, -V8_INFINITY}, | 338 return BitsetBoundariesArray; |
| 305 {kNegativeSignedSmall, kMinInt}, | 339 } |
| 306 {kUnsignedSmall, 0}, | 340 |
| 307 {kOtherUnsigned32, 0x80000000}, | 341 |
| 308 {kOtherNumber, static_cast<double>(kMaxUInt32) + 1}}; | 342 template <class Config> |
| 343 size_t TypeImpl<Config>::BitsetType::BitsetBoundariesSize() { | |
| 344 return arraysize(BitsetBoundariesArray); | |
| 345 } | |
| 309 | 346 |
| 310 | 347 |
| 311 template<class Config> | 348 template<class Config> |
| 312 typename TypeImpl<Config>::bitset | 349 typename TypeImpl<Config>::bitset |
| 313 TypeImpl<Config>::BitsetType::Lub(double min, double max) { | 350 TypeImpl<Config>::BitsetType::Lub(double min, double max) { |
| 314 DisallowHeapAllocation no_allocation; | 351 DisallowHeapAllocation no_allocation; |
| 315 int lub = kNone; | 352 int lub = kNone; |
| 316 const BitsetMin* mins = BitsetMins(); | 353 const BitsetBoundary* mins = BitsetBoundaries(); |
| 317 | 354 |
| 318 // Make sure the min-max range touches 0, so we are guaranteed no holes | 355 // Make sure the min-max range touches 0, so we are guaranteed no holes |
| 319 // in unions of valid bitsets. | 356 // in unions of valid bitsets. |
| 320 if (max < -1) max = -1; | 357 if (max < -1) max = -1; |
| 321 if (min > 0) min = 0; | 358 if (min > 0) min = 0; |
| 322 | 359 |
| 323 for (size_t i = 1; i < BitsetMinsSize(); ++i) { | 360 for (size_t i = 1; i < BitsetBoundariesSize(); ++i) { |
| 324 if (min < mins[i].min) { | 361 if (min < mins[i].min) { |
| 325 lub |= mins[i-1].bits; | 362 lub |= mins[i-1].bits; |
| 326 if (max < mins[i].min) return lub; | 363 if (max < mins[i].min) return lub; |
| 327 } | 364 } |
| 328 } | 365 } |
| 329 return lub |= mins[BitsetMinsSize()-1].bits; | 366 return lub |= mins[BitsetBoundariesSize() - 1].bits; |
| 330 } | 367 } |
| 331 | 368 |
| 332 | 369 |
| 333 template<class Config> | 370 template <class Config> |
| 371 typename TypeImpl<Config>::bitset | |
| 372 TypeImpl<Config>::BitsetType::SignedSmallBits() { | |
| 373 return i::SmiValuesAre31Bits() ? kSigned31 : kSigned32; | |
| 374 } | |
| 375 | |
| 376 | |
| 377 template <class Config> | |
| 378 typename TypeImpl<Config>::bitset | |
| 379 TypeImpl<Config>::BitsetType::UnsignedSmallBits() { | |
| 380 return i::SmiValuesAre31Bits() ? kUnsigned30 : kUnsigned31; | |
| 381 } | |
| 382 | |
| 383 | |
| 384 template <class Config> | |
| 385 typename TypeImpl<Config>::bitset TypeImpl<Config>::BitsetType::NumberBits( | |
| 386 bitset bits) { | |
| 387 return SEMANTIC(bits & kPlainNumber); | |
| 388 } | |
| 389 | |
| 390 | |
| 391 template <class Config> | |
| 392 void TypeImpl<Config>::BitsetType::CheckNumberBits(bitset bits) { | |
| 393 // Check that the bitset does not contain any holes in number ranges. | |
| 394 bitset number_bits = NumberBits(bits); | |
| 395 if (number_bits != 0) { | |
| 396 bitset lub = SEMANTIC(Lub(Min(number_bits), Max(number_bits))); | |
| 397 CHECK(lub == number_bits); | |
| 398 } | |
| 399 } | |
| 400 | |
| 401 template <class Config> | |
| 402 typename TypeImpl<Config>::bitset TypeImpl<Config>::BitsetType::Glb( | |
| 403 double min, double max) { | |
| 404 DisallowHeapAllocation no_allocation; | |
| 405 int glb = kNone; | |
| 406 const BitsetBoundary* mins = BitsetBoundaries(); | |
| 407 | |
| 408 // If the range does not touch 0, the bound is empty. | |
| 409 if (max < -1 || min > 0) return glb; | |
| 410 | |
| 411 for (size_t i = 1; i + 1 < BitsetBoundariesSize(); ++i) { | |
| 412 if (min <= mins[i].min) { | |
| 413 if (max + 1 < mins[i + 1].min) break; | |
| 414 glb |= mins[i].bits; | |
| 415 } | |
| 416 } | |
| 417 // OtherNumber also contains float numbers, so it can never be | |
| 418 // in the greatest lower bound. (There is also the small trouble | |
| 419 // of kOtherNumber having a range hole, which we can conveniently | |
| 420 // ignore here.) | |
| 421 return glb & ~(SEMANTIC(kOtherNumber)); | |
| 422 } | |
| 423 | |
| 424 | |
| 425 template <class Config> | |
| 334 double TypeImpl<Config>::BitsetType::Min(bitset bits) { | 426 double TypeImpl<Config>::BitsetType::Min(bitset bits) { |
| 335 DisallowHeapAllocation no_allocation; | 427 DisallowHeapAllocation no_allocation; |
| 336 DCHECK(Is(bits, kNumber)); | 428 DCHECK(Is(bits, kNumber)); |
| 337 const BitsetMin* mins = BitsetMins(); | 429 const BitsetBoundary* mins = BitsetBoundaries(); |
| 338 bool mz = SEMANTIC(bits & kMinusZero); | 430 bool mz = SEMANTIC(bits & kMinusZero); |
| 339 for (size_t i = 0; i < BitsetMinsSize(); ++i) { | 431 for (size_t i = 0; i < BitsetBoundariesSize(); ++i) { |
| 340 if (Is(SEMANTIC(mins[i].bits), bits)) { | 432 if (Is(SEMANTIC(mins[i].bits), bits)) { |
| 341 return mz ? std::min(0.0, mins[i].min) : mins[i].min; | 433 return mz ? std::min(0.0, mins[i].min) : mins[i].min; |
| 342 } | 434 } |
| 343 } | 435 } |
| 344 if (mz) return 0; | 436 if (mz) return 0; |
| 345 return base::OS::nan_value(); | 437 return base::OS::nan_value(); |
| 346 } | 438 } |
| 347 | 439 |
| 348 | 440 |
| 349 template<class Config> | 441 template<class Config> |
| 350 double TypeImpl<Config>::BitsetType::Max(bitset bits) { | 442 double TypeImpl<Config>::BitsetType::Max(bitset bits) { |
| 351 DisallowHeapAllocation no_allocation; | 443 DisallowHeapAllocation no_allocation; |
| 352 DCHECK(Is(bits, kNumber)); | 444 DCHECK(Is(bits, kNumber)); |
| 353 const BitsetMin* mins = BitsetMins(); | 445 const BitsetBoundary* mins = BitsetBoundaries(); |
| 354 bool mz = SEMANTIC(bits & kMinusZero); | 446 bool mz = SEMANTIC(bits & kMinusZero); |
| 355 if (BitsetType::Is(mins[BitsetMinsSize()-1].bits, bits)) { | 447 if (BitsetType::Is(SEMANTIC(mins[BitsetBoundariesSize() - 1].bits), bits)) { |
| 356 return +V8_INFINITY; | 448 return +V8_INFINITY; |
| 357 } | 449 } |
| 358 for (size_t i = BitsetMinsSize()-1; i-- > 0; ) { | 450 for (size_t i = BitsetBoundariesSize() - 1; i-- > 0;) { |
| 359 if (Is(SEMANTIC(mins[i].bits), bits)) { | 451 if (Is(SEMANTIC(mins[i].bits), bits)) { |
| 360 return mz ? | 452 return mz ? |
| 361 std::max(0.0, mins[i+1].min - 1) : mins[i+1].min - 1; | 453 std::max(0.0, mins[i+1].min - 1) : mins[i+1].min - 1; |
| 362 } | 454 } |
| 363 } | 455 } |
| 364 if (mz) return 0; | 456 if (mz) return 0; |
| 365 return base::OS::nan_value(); | 457 return base::OS::nan_value(); |
| 366 } | 458 } |
| 367 | 459 |
| 368 | 460 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 // T <= (T1 \/ ... \/ Tn) if (T <= T1) \/ ... \/ (T <= Tn) | 523 // T <= (T1 \/ ... \/ Tn) if (T <= T1) \/ ... \/ (T <= Tn) |
| 432 if (that->IsUnion()) { | 524 if (that->IsUnion()) { |
| 433 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) { | 525 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) { |
| 434 if (this->Is(that->AsUnion()->Get(i))) return true; | 526 if (this->Is(that->AsUnion()->Get(i))) return true; |
| 435 if (i > 1 && this->IsRange()) return false; // Shortcut. | 527 if (i > 1 && this->IsRange()) return false; // Shortcut. |
| 436 } | 528 } |
| 437 return false; | 529 return false; |
| 438 } | 530 } |
| 439 | 531 |
| 440 if (that->IsRange()) { | 532 if (that->IsRange()) { |
| 441 return (this->IsRange() && Contains(that->AsRange(), this->AsRange())) | 533 return (this->IsRange() && Contains(that->AsRange(), this->AsRange())) || |
| 442 || (this->IsConstant() && | 534 (this->IsConstant() && |
| 443 Contains(that->AsRange(), *this->AsConstant()->Value())); | 535 Contains(that->AsRange(), this->AsConstant())); |
| 444 } | 536 } |
| 445 if (this->IsRange()) return false; | 537 if (this->IsRange()) return false; |
| 446 | 538 |
| 447 return this->SimplyEquals(that); | 539 return this->SimplyEquals(that); |
| 448 } | 540 } |
| 449 | 541 |
| 450 | 542 |
| 451 template<class Config> | 543 template<class Config> |
| 452 bool TypeImpl<Config>::NowIs(TypeImpl* that) { | 544 bool TypeImpl<Config>::NowIs(TypeImpl* that) { |
| 453 DisallowHeapAllocation no_allocation; | 545 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) | 587 // T overlaps (T1 \/ ... \/ Tn) if (T overlaps T1) \/ ... \/ (T overlaps Tn) |
| 496 if (that->IsUnion()) { | 588 if (that->IsUnion()) { |
| 497 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) { | 589 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) { |
| 498 if (this->Maybe(that->AsUnion()->Get(i))) return true; | 590 if (this->Maybe(that->AsUnion()->Get(i))) return true; |
| 499 } | 591 } |
| 500 return false; | 592 return false; |
| 501 } | 593 } |
| 502 | 594 |
| 503 if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub())) | 595 if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub())) |
| 504 return false; | 596 return false; |
| 505 if (this->IsBitset() || that->IsBitset()) return true; | 597 |
| 598 if (this->IsBitset() && that->IsBitset()) return true; | |
| 506 | 599 |
| 507 if (this->IsClass() != that->IsClass()) return true; | 600 if (this->IsClass() != that->IsClass()) return true; |
| 508 | 601 |
| 509 if (this->IsRange()) { | 602 if (this->IsRange()) { |
| 510 if (that->IsConstant()) { | 603 if (that->IsConstant()) { |
| 511 return Contains(this->AsRange(), *that->AsConstant()->Value()); | 604 return Contains(this->AsRange(), that->AsConstant()); |
| 512 } | 605 } |
| 513 return that->IsRange() && Overlap(this->AsRange(), that->AsRange()); | 606 if (that->IsRange()) { |
| 607 return Overlap(this->AsRange(), that->AsRange()); | |
| 608 } | |
| 609 if (that->IsBitset()) { | |
| 610 bitset number_bits = BitsetType::NumberBits(that->AsBitset()); | |
| 611 if (number_bits == BitsetType::kNone) { | |
| 612 return false; | |
| 613 } | |
| 614 if ((REPRESENTATION(that->AsBitset()) & | |
| 615 REPRESENTATION(this->BitsetLub())) == BitsetType::kNone) { | |
| 616 return false; | |
| 617 } | |
| 618 double min = std::max(BitsetType::Min(number_bits), this->Min()); | |
| 619 double max = std::min(BitsetType::Max(number_bits), this->Max()); | |
| 620 return min <= max; | |
| 621 } | |
| 514 } | 622 } |
| 515 if (that->IsRange()) { | 623 if (that->IsRange()) { |
| 516 if (this->IsConstant()) { | 624 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 } | 625 } |
| 521 | 626 |
| 627 if (this->IsBitset() || that->IsBitset()) return true; | |
| 628 | |
| 522 return this->SimplyEquals(that); | 629 return this->SimplyEquals(that); |
| 523 } | 630 } |
| 524 | 631 |
| 525 | 632 |
| 526 // Return the range in [this], or [NULL]. | 633 // Return the range in [this], or [NULL]. |
| 527 template<class Config> | 634 template<class Config> |
| 528 typename TypeImpl<Config>::RangeType* TypeImpl<Config>::GetRange() { | 635 typename TypeImpl<Config>::RangeType* TypeImpl<Config>::GetRange() { |
| 529 DisallowHeapAllocation no_allocation; | 636 DisallowHeapAllocation no_allocation; |
| 530 if (this->IsRange()) return this->AsRange(); | 637 if (this->IsRange()) return this->AsRange(); |
| 531 if (this->IsUnion() && this->AsUnion()->Get(1)->IsRange()) { | 638 if (this->IsUnion() && this->AsUnion()->Get(1)->IsRange()) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 552 template<class Config> | 659 template<class Config> |
| 553 bool TypeImpl<Config>::UnionType::Wellformed() { | 660 bool TypeImpl<Config>::UnionType::Wellformed() { |
| 554 DisallowHeapAllocation no_allocation; | 661 DisallowHeapAllocation no_allocation; |
| 555 // This checks the invariants of the union representation: | 662 // This checks the invariants of the union representation: |
| 556 // 1. There are at least two elements. | 663 // 1. There are at least two elements. |
| 557 // 2. At most one element is a bitset, and it must be the first one. | 664 // 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 | 665 // 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). | 666 // (even when the first element is not a bitset). |
| 560 // 4. No element is itself a union. | 667 // 4. No element is itself a union. |
| 561 // 5. No element is a subtype of any other. | 668 // 5. No element is a subtype of any other. |
| 669 // 6. If there is a range, then the bitset type does not contain | |
| 670 // plain number bits. | |
| 562 DCHECK(this->Length() >= 2); // (1) | 671 DCHECK(this->Length() >= 2); // (1) |
| 672 | |
| 673 bitset number_bits = this->Get(0)->IsBitset() | |
| 674 ? BitsetType::NumberBits(this->Get(0)->AsBitset()) | |
| 675 : 0; | |
| 676 | |
| 563 for (int i = 0; i < this->Length(); ++i) { | 677 for (int i = 0; i < this->Length(); ++i) { |
| 564 if (i != 0) DCHECK(!this->Get(i)->IsBitset()); // (2) | 678 if (i != 0) DCHECK(!this->Get(i)->IsBitset()); // (2) |
| 565 if (i != 1) DCHECK(!this->Get(i)->IsRange()); // (3) | 679 if (i != 1) DCHECK(!this->Get(i)->IsRange()); // (3) |
| 566 DCHECK(!this->Get(i)->IsUnion()); // (4) | 680 DCHECK(!this->Get(i)->IsUnion()); // (4) |
| 567 for (int j = 0; j < this->Length(); ++j) { | 681 for (int j = 0; j < this->Length(); ++j) { |
| 568 if (i != j) DCHECK(!this->Get(i)->Is(this->Get(j))); // (5) | 682 if (i != j) DCHECK(!this->Get(i)->Is(this->Get(j))); // (5) |
| 569 } | 683 } |
| 570 } | 684 } |
| 685 DCHECK(!this->Get(1)->IsRange() || (number_bits == 0)); // (6) | |
| 571 return true; | 686 return true; |
| 572 } | 687 } |
| 573 | 688 |
| 574 | 689 |
| 575 // ----------------------------------------------------------------------------- | 690 // ----------------------------------------------------------------------------- |
| 576 // Union and intersection | 691 // Union and intersection |
| 577 | 692 |
| 578 | 693 |
| 579 static bool AddIsSafe(int x, int y) { | 694 static bool AddIsSafe(int x, int y) { |
| 580 return x >= 0 ? | 695 return x >= 0 ? |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 607 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; | 722 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; |
| 608 if (!AddIsSafe(size1, size2)) return Any(region); | 723 if (!AddIsSafe(size1, size2)) return Any(region); |
| 609 int size = size1 + size2; | 724 int size = size1 + size2; |
| 610 if (!AddIsSafe(size, 2)) return Any(region); | 725 if (!AddIsSafe(size, 2)) return Any(region); |
| 611 size += 2; | 726 size += 2; |
| 612 UnionHandle result = UnionType::New(size, region); | 727 UnionHandle result = UnionType::New(size, region); |
| 613 size = 0; | 728 size = 0; |
| 614 | 729 |
| 615 // Deal with bitsets. | 730 // Deal with bitsets. |
| 616 result->Set(size++, BitsetType::New(bits, region)); | 731 result->Set(size++, BitsetType::New(bits, region)); |
| 732 // Insert a placeholder for the range. | |
| 733 result->Set(size++, None(region)); | |
| 617 | 734 |
| 618 // Deal with ranges. | 735 Limits lims = Limits::Empty(region); |
| 619 TypeHandle range = None(region); | 736 size = IntersectAux(type1, type2, result, size, &lims, region); |
| 620 RangeType* range1 = type1->GetRange(); | 737 |
| 621 RangeType* range2 = type2->GetRange(); | 738 // If the range is not empty, then insert it into the union and |
| 622 if (range1 != NULL && range2 != NULL) { | 739 // remove the number bits from the bitset. |
| 623 Limits lim = Intersect(Limits(range1), Limits(range2)); | 740 if (!IsEmpty(lims)) { |
| 624 if (lim.min->Number() <= lim.max->Number()) { | 741 UpdateRange(RangeType::New(lims, region), result, size, region); |
| 625 range = RangeType::New(lim, region); | 742 |
| 743 // Remove the number bits. | |
| 744 bitset number_bits = BitsetType::NumberBits(bits); | |
| 745 bits &= ~number_bits; | |
| 746 if (SEMANTIC(bits) == BitsetType::kNone) { | |
| 747 bits = BitsetType::kNone; | |
| 626 } | 748 } |
| 749 result->Set(0, BitsetType::New(bits, region)); | |
| 627 } | 750 } |
| 628 result->Set(size++, range); | |
| 629 | |
| 630 size = IntersectAux(type1, type2, result, size, region); | |
| 631 return NormalizeUnion(result, size); | 751 return NormalizeUnion(result, size); |
| 632 } | 752 } |
| 633 | 753 |
| 634 | 754 |
| 635 template<class Config> | 755 template<class Config> |
| 636 int TypeImpl<Config>::UpdateRange( | 756 int TypeImpl<Config>::UpdateRange( |
| 637 RangeHandle range, UnionHandle result, int size, Region* region) { | 757 RangeHandle range, UnionHandle result, int size, Region* region) { |
| 638 TypeHandle old_range = result->Get(1); | 758 TypeHandle old_range = result->Get(1); |
| 639 DCHECK(old_range->IsRange() || old_range->IsNone()); | 759 DCHECK(old_range->IsRange() || old_range->IsNone()); |
| 640 if (range->Is(old_range)) return size; | 760 if (range->Is(old_range)) return size; |
| 641 if (!old_range->Is(range->unhandle())) { | 761 if (!old_range->Is(range->unhandle())) { |
| 642 range = RangeType::New( | 762 range = RangeType::New( |
| 643 Union(Limits(range->AsRange()), Limits(old_range->AsRange())), region); | 763 Union(Limits(range->AsRange()), Limits(old_range->AsRange())), region); |
| 644 } | 764 } |
| 645 result->Set(1, range); | 765 result->Set(1, range); |
| 646 | 766 |
| 647 // Remove any components that just got subsumed. | 767 // Remove any components that just got subsumed. |
| 648 for (int i = 2; i < size; ) { | 768 for (int i = 2; i < size; ) { |
| 649 if (result->Get(i)->Is(range->unhandle())) { | 769 if (result->Get(i)->Is(range->unhandle())) { |
| 650 result->Set(i, result->Get(--size)); | 770 result->Set(i, result->Get(--size)); |
| 651 } else { | 771 } else { |
| 652 ++i; | 772 ++i; |
| 653 } | 773 } |
| 654 } | 774 } |
| 655 return size; | 775 return size; |
| 656 } | 776 } |
| 657 | 777 |
| 658 | 778 |
| 659 template<class Config> | 779 template <class Config> |
| 660 int TypeImpl<Config>::IntersectAux( | 780 typename TypeImpl<Config>::Limits TypeImpl<Config>::ToLimits(bitset bits, |
| 661 TypeHandle lhs, TypeHandle rhs, | 781 Region* region) { |
| 662 UnionHandle result, int size, Region* region) { | 782 bitset representation = REPRESENTATION(bits); |
| 783 bitset number_bits = BitsetType::NumberBits(bits); | |
| 784 | |
| 785 if (representation == BitsetType::kNone && number_bits == BitsetType::kNone) { | |
| 786 return Limits::Empty(region); | |
| 787 } | |
| 788 | |
| 789 double bitset_min = BitsetType::Min(number_bits); | |
| 790 double bitset_max = BitsetType::Max(number_bits); | |
| 791 | |
| 792 // TODO(jarin) Get rid of the heap numbers. | |
| 793 i::Factory* f = Config::isolate(region)->factory(); | |
| 794 | |
| 795 return Limits(f->NewNumber(bitset_min), f->NewNumber(bitset_max), | |
| 796 representation); | |
| 797 } | |
| 798 | |
| 799 | |
| 800 template <class Config> | |
| 801 typename TypeImpl<Config>::Limits TypeImpl<Config>::IntersectRangeAndBitset( | |
| 802 TypeHandle range, TypeHandle bitset, Region* region) { | |
| 803 Limits range_lims(range->AsRange()); | |
| 804 Limits bitset_lims = ToLimits(bitset->AsBitset(), region); | |
| 805 return Intersect(range_lims, bitset_lims); | |
| 806 } | |
| 807 | |
| 808 | |
| 809 template <class Config> | |
| 810 int TypeImpl<Config>::IntersectAux(TypeHandle lhs, TypeHandle rhs, | |
| 811 UnionHandle result, int size, Limits* lims, | |
| 812 Region* region) { | |
| 663 if (lhs->IsUnion()) { | 813 if (lhs->IsUnion()) { |
| 664 for (int i = 0, n = lhs->AsUnion()->Length(); i < n; ++i) { | 814 for (int i = 0, n = lhs->AsUnion()->Length(); i < n; ++i) { |
| 665 size = IntersectAux(lhs->AsUnion()->Get(i), rhs, result, size, region); | 815 size = |
| 816 IntersectAux(lhs->AsUnion()->Get(i), rhs, result, size, lims, region); | |
| 666 } | 817 } |
| 667 return size; | 818 return size; |
| 668 } | 819 } |
| 669 if (rhs->IsUnion()) { | 820 if (rhs->IsUnion()) { |
| 670 for (int i = 0, n = rhs->AsUnion()->Length(); i < n; ++i) { | 821 for (int i = 0, n = rhs->AsUnion()->Length(); i < n; ++i) { |
| 671 size = IntersectAux(lhs, rhs->AsUnion()->Get(i), result, size, region); | 822 size = |
| 823 IntersectAux(lhs, rhs->AsUnion()->Get(i), result, size, lims, region); | |
| 672 } | 824 } |
| 673 return size; | 825 return size; |
| 674 } | 826 } |
| 675 | 827 |
| 676 if (!BitsetType::IsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) { | 828 if (!BitsetType::IsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) { |
| 677 return size; | 829 return size; |
| 678 } | 830 } |
| 679 | 831 |
| 680 if (lhs->IsRange()) { | 832 if (lhs->IsRange()) { |
| 681 if (rhs->IsBitset() || rhs->IsClass()) { | 833 if (rhs->IsBitset()) { |
| 682 return UpdateRange( | 834 Limits lim = IntersectRangeAndBitset(lhs, rhs, region); |
| 683 Config::template cast<RangeType>(lhs), result, size, region); | 835 |
| 836 if (!IsEmpty(lim)) { | |
| 837 *lims = Union(lim, *lims); | |
| 838 } | |
| 839 return size; | |
| 684 } | 840 } |
| 685 if (rhs->IsConstant() && | 841 if (rhs->IsClass()) { |
| 686 Contains(lhs->AsRange(), *rhs->AsConstant()->Value())) { | 842 *lims = Union(Limits(lhs->AsRange()), *lims); |
| 843 } | |
| 844 if (rhs->IsConstant() && Contains(lhs->AsRange(), rhs->AsConstant())) { | |
| 687 return AddToUnion(rhs, result, size, region); | 845 return AddToUnion(rhs, result, size, region); |
| 688 } | 846 } |
| 847 if (rhs->IsRange()) { | |
| 848 Limits lim = Intersect(Limits(lhs->AsRange()), Limits(rhs->AsRange())); | |
| 849 if (!IsEmpty(lim)) { | |
| 850 *lims = Union(lim, *lims); | |
| 851 } | |
| 852 } | |
| 689 return size; | 853 return size; |
| 690 } | 854 } |
| 691 if (rhs->IsRange()) { | 855 if (rhs->IsRange()) { |
| 692 if (lhs->IsBitset() || lhs->IsClass()) { | 856 if (lhs->IsBitset()) { |
| 693 return UpdateRange( | 857 Limits lim = IntersectRangeAndBitset(rhs, lhs, region); |
| 694 Config::template cast<RangeType>(rhs), result, size, region); | 858 |
| 859 if (!IsEmpty(lim)) { | |
| 860 *lims = Union(lim, *lims); | |
| 861 } | |
| 862 return size; | |
| 695 } | 863 } |
| 696 if (lhs->IsConstant() && | 864 if (lhs->IsClass()) { |
| 697 Contains(rhs->AsRange(), *lhs->AsConstant()->Value())) { | 865 *lims = Union(Limits(rhs->AsRange()), *lims); |
| 866 } | |
| 867 if (lhs->IsConstant() && Contains(rhs->AsRange(), lhs->AsConstant())) { | |
| 698 return AddToUnion(lhs, result, size, region); | 868 return AddToUnion(lhs, result, size, region); |
| 699 } | 869 } |
| 700 return size; | 870 return size; |
| 701 } | 871 } |
| 702 | 872 |
| 703 if (lhs->IsBitset() || rhs->IsBitset()) { | 873 if (lhs->IsBitset() || rhs->IsBitset()) { |
| 704 return AddToUnion(lhs->IsBitset() ? rhs : lhs, result, size, region); | 874 return AddToUnion(lhs->IsBitset() ? rhs : lhs, result, size, region); |
| 705 } | 875 } |
| 706 if (lhs->IsClass() != rhs->IsClass()) { | 876 if (lhs->IsClass() != rhs->IsClass()) { |
| 707 return AddToUnion(lhs->IsClass() ? rhs : lhs, result, size, region); | 877 return AddToUnion(lhs->IsClass() ? rhs : lhs, result, size, region); |
| 708 } | 878 } |
| 709 if (lhs->SimplyEquals(rhs->unhandle())) { | 879 if (lhs->SimplyEquals(rhs->unhandle())) { |
| 710 return AddToUnion(lhs, result, size, region); | 880 return AddToUnion(lhs, result, size, region); |
| 711 } | 881 } |
| 712 return size; | 882 return size; |
| 713 } | 883 } |
| 714 | 884 |
| 715 | 885 |
| 886 // Make sure that we produce a well-formed range and bitset: | |
| 887 // If the range is non-empty, the number bits in the bitset should be | |
| 888 // clear. Moreover, if we have a canonical range (such as Signed32(), | |
| 889 // we want to produce a bitset rather than a range. | |
| 890 template <class Config> | |
| 891 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NormalizeRangeAndBitset( | |
| 892 RangeHandle range, bitset* bits, Region* region) { | |
| 893 // Fast path: If the bitset does not mention numbers, we can just keep the | |
| 894 // range. | |
| 895 bitset number_bits = BitsetType::NumberBits(*bits); | |
| 896 if (number_bits == 0) { | |
| 897 return range; | |
| 898 } | |
| 899 | |
| 900 // If the range is contained within the bitset, return an empty range | |
| 901 // (but make sure we take the representation). | |
| 902 bitset range_lub = range->BitsetLub(); | |
| 903 if (BitsetType::Is(BitsetType::NumberBits(range_lub), *bits)) { | |
| 904 *bits |= range_lub; | |
| 905 return None(region); | |
| 906 } | |
| 907 | |
| 908 // Slow path: reconcile the bitset range and the range. | |
| 909 double bitset_min = BitsetType::Min(number_bits); | |
| 910 double bitset_max = BitsetType::Max(number_bits); | |
| 911 | |
| 912 i::Handle<i::Object> range_min_obj = range->Min(); | |
| 913 i::Handle<i::Object> range_max_obj = range->Max(); | |
| 914 double range_min = range_min_obj->Number(); | |
| 915 double range_max = range_max_obj->Number(); | |
| 916 | |
| 917 bitset range_representation = REPRESENTATION(range->BitsetLub()); | |
| 918 bitset bits_representation = REPRESENTATION(*bits); | |
| 919 bitset representation = | |
| 920 (bits_representation | range_representation) & BitsetType::kNumber; | |
| 921 | |
| 922 // Remove the number bits from the bitset, they would just confuse us now. | |
| 923 *bits &= ~number_bits; | |
| 924 if (bits_representation == *bits) { | |
| 925 *bits = BitsetType::kNone; | |
| 926 } | |
| 927 | |
| 928 if (representation == range_representation && range_min <= bitset_min && | |
| 929 range_max >= bitset_max) { | |
| 930 // Bitset is contained within the range, just return the range. | |
| 931 return range; | |
| 932 } | |
| 933 | |
| 934 if (bitset_min < range_min) { | |
| 935 range_min_obj = Config::isolate(region)->factory()->NewNumber(bitset_min); | |
| 936 } | |
| 937 if (bitset_max > range_max) { | |
| 938 range_max_obj = Config::isolate(region)->factory()->NewNumber(bitset_max); | |
| 939 } | |
| 940 return RangeType::New(range_min_obj, range_max_obj, | |
| 941 BitsetType::New(representation, region), region); | |
| 942 } | |
| 943 | |
| 944 | |
| 716 template<class Config> | 945 template<class Config> |
| 717 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union( | 946 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union( |
| 718 TypeHandle type1, TypeHandle type2, Region* region) { | 947 TypeHandle type1, TypeHandle type2, Region* region) { |
| 719 | 948 |
| 720 // Fast case: bit sets. | 949 // Fast case: bit sets. |
| 721 if (type1->IsBitset() && type2->IsBitset()) { | 950 if (type1->IsBitset() && type2->IsBitset()) { |
| 722 return BitsetType::New(type1->AsBitset() | type2->AsBitset(), region); | 951 return BitsetType::New(type1->AsBitset() | type2->AsBitset(), region); |
| 723 } | 952 } |
| 724 | 953 |
| 725 // Fast case: top or bottom types. | 954 // Fast case: top or bottom types. |
| 726 if (type1->IsAny() || type2->IsNone()) return type1; | 955 if (type1->IsAny() || type2->IsNone()) return type1; |
| 727 if (type2->IsAny() || type1->IsNone()) return type2; | 956 if (type2->IsAny() || type1->IsNone()) return type2; |
| 728 | 957 |
| 729 // Semi-fast case. | 958 // Semi-fast case. |
| 730 if (type1->Is(type2)) return type2; | 959 if (type1->Is(type2)) return type2; |
| 731 if (type2->Is(type1)) return type1; | 960 if (type2->Is(type1)) return type1; |
| 732 | 961 |
| 733 // Slow case: create union. | 962 // Slow case: create union. |
| 734 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1; | 963 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1; |
| 735 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; | 964 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; |
| 736 if (!AddIsSafe(size1, size2)) return Any(region); | 965 if (!AddIsSafe(size1, size2)) return Any(region); |
| 737 int size = size1 + size2; | 966 int size = size1 + size2; |
| 738 if (!AddIsSafe(size, 2)) return Any(region); | 967 if (!AddIsSafe(size, 2)) return Any(region); |
| 739 size += 2; | 968 size += 2; |
| 740 UnionHandle result = UnionType::New(size, region); | 969 UnionHandle result = UnionType::New(size, region); |
| 741 size = 0; | 970 size = 0; |
| 742 | 971 |
| 743 // Deal with bitsets. | 972 // Compute the new bitset. |
| 744 TypeHandle bits = BitsetType::New( | 973 bitset new_bitset = type1->BitsetGlb() | type2->BitsetGlb(); |
| 745 type1->BitsetGlb() | type2->BitsetGlb(), region); | |
| 746 result->Set(size++, bits); | |
| 747 | 974 |
| 748 // Deal with ranges. | 975 // Deal with ranges. |
| 749 TypeHandle range = None(region); | 976 TypeHandle range = None(region); |
| 750 RangeType* range1 = type1->GetRange(); | 977 RangeType* range1 = type1->GetRange(); |
| 751 RangeType* range2 = type2->GetRange(); | 978 RangeType* range2 = type2->GetRange(); |
| 752 if (range1 != NULL && range2 != NULL) { | 979 if (range1 != NULL && range2 != NULL) { |
| 753 range = RangeType::New(Union(Limits(range1), Limits(range2)), region); | 980 Limits lims = Union(Limits(range1), Limits(range2)); |
| 981 RangeHandle union_range = RangeType::New(lims, region); | |
| 982 range = NormalizeRangeAndBitset(union_range, &new_bitset, region); | |
| 754 } else if (range1 != NULL) { | 983 } else if (range1 != NULL) { |
| 755 range = handle(range1); | 984 range = NormalizeRangeAndBitset(handle(range1), &new_bitset, region); |
| 756 } else if (range2 != NULL) { | 985 } else if (range2 != NULL) { |
| 757 range = handle(range2); | 986 range = NormalizeRangeAndBitset(handle(range2), &new_bitset, region); |
| 758 } | 987 } |
| 988 TypeHandle bits = BitsetType::New(new_bitset, region); | |
| 989 result->Set(size++, bits); | |
| 759 result->Set(size++, range); | 990 result->Set(size++, range); |
| 760 | 991 |
| 761 size = AddToUnion(type1, result, size, region); | 992 size = AddToUnion(type1, result, size, region); |
| 762 size = AddToUnion(type2, result, size, region); | 993 size = AddToUnion(type2, result, size, region); |
| 763 return NormalizeUnion(result, size); | 994 return NormalizeUnion(result, size); |
| 764 } | 995 } |
| 765 | 996 |
| 766 | 997 |
| 767 // Add [type] to [result] unless [type] is bitset, range, or already subsumed. | 998 // Add [type] to [result] unless [type] is bitset, range, or already subsumed. |
| 768 // Return new size of [result]. | 999 // 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( | 1142 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert( |
| 912 typename OtherType::TypeHandle type, Region* region) { | 1143 typename OtherType::TypeHandle type, Region* region) { |
| 913 if (type->IsBitset()) { | 1144 if (type->IsBitset()) { |
| 914 return BitsetType::New(type->AsBitset(), region); | 1145 return BitsetType::New(type->AsBitset(), region); |
| 915 } else if (type->IsClass()) { | 1146 } else if (type->IsClass()) { |
| 916 return ClassType::New(type->AsClass()->Map(), region); | 1147 return ClassType::New(type->AsClass()->Map(), region); |
| 917 } else if (type->IsConstant()) { | 1148 } else if (type->IsConstant()) { |
| 918 return ConstantType::New(type->AsConstant()->Value(), region); | 1149 return ConstantType::New(type->AsConstant()->Value(), region); |
| 919 } else if (type->IsRange()) { | 1150 } else if (type->IsRange()) { |
| 920 return RangeType::New( | 1151 return RangeType::New( |
| 921 type->AsRange()->Min(), type->AsRange()->Max(), region); | 1152 type->AsRange()->Min(), type->AsRange()->Max(), |
| 1153 BitsetType::New(REPRESENTATION(type->BitsetLub()), region), region); | |
| 922 } else if (type->IsContext()) { | 1154 } else if (type->IsContext()) { |
| 923 TypeHandle outer = Convert<OtherType>(type->AsContext()->Outer(), region); | 1155 TypeHandle outer = Convert<OtherType>(type->AsContext()->Outer(), region); |
| 924 return ContextType::New(outer, region); | 1156 return ContextType::New(outer, region); |
| 925 } else if (type->IsUnion()) { | 1157 } else if (type->IsUnion()) { |
| 926 int length = type->AsUnion()->Length(); | 1158 int length = type->AsUnion()->Length(); |
| 927 UnionHandle unioned = UnionType::New(length, region); | 1159 UnionHandle unioned = UnionType::New(length, region); |
| 928 for (int i = 0; i < length; ++i) { | 1160 for (int i = 0; i < length; ++i) { |
| 929 TypeHandle t = Convert<OtherType>(type->AsUnion()->Get(i), region); | 1161 TypeHandle t = Convert<OtherType>(type->AsUnion()->Get(i), region); |
| 930 unioned->Set(i, t); | 1162 unioned->Set(i, t); |
| 931 } | 1163 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 977 template <class Config> | 1209 template <class Config> |
| 978 void TypeImpl<Config>::BitsetType::Print(std::ostream& os, // NOLINT | 1210 void TypeImpl<Config>::BitsetType::Print(std::ostream& os, // NOLINT |
| 979 bitset bits) { | 1211 bitset bits) { |
| 980 DisallowHeapAllocation no_allocation; | 1212 DisallowHeapAllocation no_allocation; |
| 981 const char* name = Name(bits); | 1213 const char* name = Name(bits); |
| 982 if (name != NULL) { | 1214 if (name != NULL) { |
| 983 os << name; | 1215 os << name; |
| 984 return; | 1216 return; |
| 985 } | 1217 } |
| 986 | 1218 |
| 1219 // clang-format off | |
| 987 static const bitset named_bitsets[] = { | 1220 static const bitset named_bitsets[] = { |
| 988 #define BITSET_CONSTANT(type, value) REPRESENTATION(k##type), | 1221 #define BITSET_CONSTANT(type, value) REPRESENTATION(k##type), |
| 989 REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT) | 1222 REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT) |
| 990 #undef BITSET_CONSTANT | 1223 #undef BITSET_CONSTANT |
| 991 | 1224 |
| 992 #define BITSET_CONSTANT(type, value) SEMANTIC(k##type), | 1225 #define BITSET_CONSTANT(type, value) SEMANTIC(k##type), |
| 993 INTERNAL_BITSET_TYPE_LIST(BITSET_CONSTANT) | 1226 INTERNAL_BITSET_TYPE_LIST(BITSET_CONSTANT) |
|
rossberg
2015/01/19 11:43:56
Nit: one more indentation oddity
| |
| 994 SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT) | 1227 SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT) |
| 995 #undef BITSET_CONSTANT | 1228 #undef BITSET_CONSTANT |
| 996 }; | 1229 }; |
| 1230 // clang-format on | |
| 997 | 1231 |
| 998 bool is_first = true; | 1232 bool is_first = true; |
| 999 os << "("; | 1233 os << "("; |
| 1000 for (int i(arraysize(named_bitsets) - 1); bits != 0 && i >= 0; --i) { | 1234 for (int i(arraysize(named_bitsets) - 1); bits != 0 && i >= 0; --i) { |
| 1001 bitset subset = named_bitsets[i]; | 1235 bitset subset = named_bitsets[i]; |
| 1002 if ((bits & subset) == subset) { | 1236 if ((bits & subset) == subset) { |
| 1003 if (!is_first) os << " | "; | 1237 if (!is_first) os << " | "; |
| 1004 is_first = false; | 1238 is_first = false; |
| 1005 os << Name(subset); | 1239 os << Name(subset); |
| 1006 bits -= subset; | 1240 bits -= subset; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1097 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; | 1331 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; |
| 1098 | 1332 |
| 1099 template TypeImpl<ZoneTypeConfig>::TypeHandle | 1333 template TypeImpl<ZoneTypeConfig>::TypeHandle |
| 1100 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( | 1334 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( |
| 1101 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); | 1335 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); |
| 1102 template TypeImpl<HeapTypeConfig>::TypeHandle | 1336 template TypeImpl<HeapTypeConfig>::TypeHandle |
| 1103 TypeImpl<HeapTypeConfig>::Convert<Type>( | 1337 TypeImpl<HeapTypeConfig>::Convert<Type>( |
| 1104 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); | 1338 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); |
| 1105 | 1339 |
| 1106 } } // namespace v8::internal | 1340 } } // namespace v8::internal |
| OLD | NEW |