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 "src/types.h" | 5 #include "src/types.h" |
6 | 6 |
7 #include "src/string-stream.h" | 7 #include "src/string-stream.h" |
8 #include "src/types-inl.h" | 8 #include "src/types-inl.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 DisallowHeapAllocation no_allocation; | 255 DisallowHeapAllocation no_allocation; |
256 | 256 |
257 // Fast path for bitsets. | 257 // Fast path for bitsets. |
258 if (this->IsNone()) return true; | 258 if (this->IsNone()) return true; |
259 if (that->IsBitset()) { | 259 if (that->IsBitset()) { |
260 return (BitsetType::Lub(this) | that->AsBitset()) == that->AsBitset(); | 260 return (BitsetType::Lub(this) | that->AsBitset()) == that->AsBitset(); |
261 } | 261 } |
262 if (this->IsBitset() && SEMANTIC(this->AsBitset()) == BitsetType::kNone) { | 262 if (this->IsBitset() && SEMANTIC(this->AsBitset()) == BitsetType::kNone) { |
263 // Bitsets only have non-bitset supertypes along the representation axis. | 263 // Bitsets only have non-bitset supertypes along the representation axis. |
264 int that_bitset = that->BitsetGlb(); | 264 int that_bitset = that->BitsetGlb(); |
265 return (this->AsBitset() | that_bitset) == that_bitset; | 265 return (BitsetType::Is(this->AsBitset(), that_bitset)); |
266 } | 266 } |
267 | 267 |
268 if (that->IsClass()) { | 268 if (that->IsClass()) { |
269 return this->IsClass() | 269 return this->IsClass() |
270 && *this->AsClass()->Map() == *that->AsClass()->Map() | 270 && *this->AsClass()->Map() == *that->AsClass()->Map() |
271 && ((Config::is_class(that) && Config::is_class(this)) || | 271 && ((Config::is_class(that) && Config::is_class(this)) || |
272 BitsetType::New(this->BitsetLub())->Is( | 272 BitsetType::New(this->BitsetLub())->Is( |
273 BitsetType::New(that->BitsetLub()))); | 273 BitsetType::New(that->BitsetLub()))); |
274 } | 274 } |
275 if (that->IsConstant()) { | 275 if (that->IsConstant()) { |
(...skipping 30 matching lines...) Expand all Loading... |
306 if (this->IsUnion()) { | 306 if (this->IsUnion()) { |
307 UnionHandle unioned = handle(this->AsUnion()); | 307 UnionHandle unioned = handle(this->AsUnion()); |
308 for (int i = 0; i < unioned->Length(); ++i) { | 308 for (int i = 0; i < unioned->Length(); ++i) { |
309 if (!unioned->Get(i)->Is(that)) return false; | 309 if (!unioned->Get(i)->Is(that)) return false; |
310 } | 310 } |
311 return true; | 311 return true; |
312 } | 312 } |
313 | 313 |
314 // T <= (T1 \/ ... \/ Tn) <=> (T <= T1) \/ ... \/ (T <= Tn) | 314 // T <= (T1 \/ ... \/ Tn) <=> (T <= T1) \/ ... \/ (T <= Tn) |
315 // (iff T is not a union) | 315 // (iff T is not a union) |
316 ASSERT(!this->IsUnion()); | 316 ASSERT(!this->IsUnion() && that->IsUnion()); |
317 if (that->IsUnion()) { | 317 UnionHandle unioned = handle(that->AsUnion()); |
318 UnionHandle unioned = handle(that->AsUnion()); | 318 for (int i = 0; i < unioned->Length(); ++i) { |
319 for (int i = 0; i < unioned->Length(); ++i) { | 319 if (this->Is(unioned->Get(i))) return true; |
320 if (this->Is(unioned->Get(i))) return true; | 320 if (this->IsBitset()) break; // Fast fail, only first field is a bitset. |
321 if (this->IsBitset()) break; // Fast fail, only first field is a bitset. | |
322 } | |
323 return false; | |
324 } | 321 } |
325 | |
326 return false; | 322 return false; |
327 } | 323 } |
328 | 324 |
329 | 325 |
330 template<class Config> | 326 template<class Config> |
331 bool TypeImpl<Config>::NowIs(TypeImpl* that) { | 327 bool TypeImpl<Config>::NowIs(TypeImpl* that) { |
332 DisallowHeapAllocation no_allocation; | 328 DisallowHeapAllocation no_allocation; |
333 | 329 |
334 // TODO(rossberg): this is incorrect for | 330 // TODO(rossberg): this is incorrect for |
335 // Union(Constant(V), T)->NowIs(Class(M)) | 331 // Union(Constant(V), T)->NowIs(Class(M)) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 // T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn) | 371 // T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn) |
376 if (that->IsUnion()) { | 372 if (that->IsUnion()) { |
377 UnionHandle unioned = handle(that->AsUnion()); | 373 UnionHandle unioned = handle(that->AsUnion()); |
378 for (int i = 0; i < unioned->Length(); ++i) { | 374 for (int i = 0; i < unioned->Length(); ++i) { |
379 if (this->Maybe(unioned->Get(i))) return true; | 375 if (this->Maybe(unioned->Get(i))) return true; |
380 } | 376 } |
381 return false; | 377 return false; |
382 } | 378 } |
383 | 379 |
384 ASSERT(!this->IsUnion() && !that->IsUnion()); | 380 ASSERT(!this->IsUnion() && !that->IsUnion()); |
385 if (this->IsBitset()) { | 381 if (this->IsBitset() || that->IsBitset()) { |
386 return BitsetType::IsInhabited(this->AsBitset() & that->BitsetLub()); | 382 return BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub()); |
387 } | |
388 if (that->IsBitset()) { | |
389 return BitsetType::IsInhabited(this->BitsetLub() & that->AsBitset()); | |
390 } | 383 } |
391 if (this->IsClass()) { | 384 if (this->IsClass()) { |
392 return that->IsClass() | 385 return that->IsClass() |
393 && *this->AsClass()->Map() == *that->AsClass()->Map(); | 386 && *this->AsClass()->Map() == *that->AsClass()->Map(); |
394 } | 387 } |
395 if (this->IsConstant()) { | 388 if (this->IsConstant()) { |
396 return that->IsConstant() | 389 return that->IsConstant() |
397 && *this->AsConstant()->Value() == *that->AsConstant()->Value(); | 390 && *this->AsConstant()->Value() == *that->AsConstant()->Value(); |
398 } | 391 } |
399 if (this->IsContext()) { | 392 if (this->IsContext()) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 430 } |
438 | 431 |
439 | 432 |
440 // ----------------------------------------------------------------------------- | 433 // ----------------------------------------------------------------------------- |
441 // Union and intersection | 434 // Union and intersection |
442 | 435 |
443 template<class Config> | 436 template<class Config> |
444 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Narrow( | 437 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Narrow( |
445 int bitset, Region* region) { | 438 int bitset, Region* region) { |
446 TypeHandle bound = BitsetType::New(bitset, region); | 439 TypeHandle bound = BitsetType::New(bitset, region); |
| 440 ASSERT(!this->IsBitset() && this->Is(bound)); |
447 if (this->IsClass()) { | 441 if (this->IsClass()) { |
448 return ClassType::New(this->AsClass()->Map(), bound, region); | 442 return ClassType::New(this->AsClass()->Map(), bound, region); |
449 } else if (this->IsConstant()) { | 443 } else if (this->IsConstant()) { |
450 return ConstantType::New(this->AsConstant()->Value(), bound, region); | 444 return ConstantType::New(this->AsConstant()->Value(), bound, region); |
451 } else if (this->IsContext()) { | 445 } else if (this->IsContext()) { |
452 return ContextType::New(this->AsContext()->Outer(), bound, region); | 446 return ContextType::New(this->AsContext()->Outer(), bound, region); |
453 } else if (this->IsArray()) { | 447 } else if (this->IsArray()) { |
454 return ArrayType::New(this->AsArray()->Element(), bound, region); | 448 return ArrayType::New(this->AsArray()->Element(), bound, region); |
455 } else if (this->IsFunction()) { | 449 } else if (this->IsFunction()) { |
456 FunctionType* function = this->AsFunction(); | 450 FunctionType* function = this->AsFunction(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 } | 557 } |
564 | 558 |
565 | 559 |
566 // If bitset is subsumed by another entry in the result, remove it. | 560 // If bitset is subsumed by another entry in the result, remove it. |
567 // (Only bitsets with empty semantic axis can be subtypes of non-bitsets.) | 561 // (Only bitsets with empty semantic axis can be subtypes of non-bitsets.) |
568 template<class Config> | 562 template<class Config> |
569 int TypeImpl<Config>::NormalizeUnion(UnionHandle result, int size, int bitset) { | 563 int TypeImpl<Config>::NormalizeUnion(UnionHandle result, int size, int bitset) { |
570 if (bitset != BitsetType::kNone && SEMANTIC(bitset) == BitsetType::kNone) { | 564 if (bitset != BitsetType::kNone && SEMANTIC(bitset) == BitsetType::kNone) { |
571 for (int i = 1; i < size; ++i) { | 565 for (int i = 1; i < size; ++i) { |
572 int glb = result->Get(i)->BitsetGlb(); | 566 int glb = result->Get(i)->BitsetGlb(); |
573 if ((bitset | glb) == glb) { | 567 if (BitsetType::Is(bitset, glb)) { |
574 for (int j = 1; j < size; ++j) { | 568 for (int j = 1; j < size; ++j) { |
575 result->Set(j - 1, result->Get(j)); | 569 result->Set(j - 1, result->Get(j)); |
576 } | 570 } |
577 --size; | 571 --size; |
578 break; | 572 break; |
579 } | 573 } |
580 } | 574 } |
581 } | 575 } |
582 return size; | 576 return size; |
583 } | 577 } |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; | 962 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; |
969 | 963 |
970 template TypeImpl<ZoneTypeConfig>::TypeHandle | 964 template TypeImpl<ZoneTypeConfig>::TypeHandle |
971 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( | 965 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( |
972 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); | 966 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); |
973 template TypeImpl<HeapTypeConfig>::TypeHandle | 967 template TypeImpl<HeapTypeConfig>::TypeHandle |
974 TypeImpl<HeapTypeConfig>::Convert<Type>( | 968 TypeImpl<HeapTypeConfig>::Convert<Type>( |
975 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); | 969 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); |
976 | 970 |
977 } } // namespace v8::internal | 971 } } // namespace v8::internal |
OLD | NEW |