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