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