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 "types.h" | 5 #include "types.h" |
6 | 6 |
7 #include "string-stream.h" | 7 #include "string-stream.h" |
8 #include "types-inl.h" | 8 #include "types-inl.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } | 299 } |
300 return false; | 300 return false; |
301 } | 301 } |
302 | 302 |
303 return false; | 303 return false; |
304 } | 304 } |
305 | 305 |
306 | 306 |
307 template<class Config> | 307 template<class Config> |
308 bool TypeImpl<Config>::NowIs(TypeImpl* that) { | 308 bool TypeImpl<Config>::NowIs(TypeImpl* that) { |
309 if (this->Is(that)) return true; | 309 if (this->IsConstant()) { |
310 if (this->IsConstant() && this->AsConstant()->IsHeapObject()) { | 310 DisallowHeapAllocation no_allocation; |
311 i::Handle<i::Map> map(i::HeapObject::cast(*this->AsConstant())->map()); | 311 i::Object* object = *this->AsConstant(); |
312 for (Iterator<i::Map> it = that->Classes(); !it.Done(); it.Advance()) { | 312 if (object->IsHeapObject()) { |
313 if (*it.Current() == *map) return true; | 313 i::Map* map = i::HeapObject::cast(object)->map(); |
| 314 for (Iterator<i::Map> it = that->Classes(); !it.Done(); it.Advance()) { |
| 315 if (*it.Current() == map) return true; |
| 316 } |
314 } | 317 } |
315 } | 318 } |
316 return false; | 319 return this->Is(that); |
317 } | 320 } |
318 | 321 |
319 | 322 |
320 // Check this overlaps that. | 323 // Check this overlaps that. |
321 template<class Config> | 324 template<class Config> |
322 bool TypeImpl<Config>::Maybe(TypeImpl* that) { | 325 bool TypeImpl<Config>::Maybe(TypeImpl* that) { |
323 // Fast path for bitsets. | |
324 if (this->IsBitset()) { | |
325 return IsInhabited(this->AsBitset() & that->LubBitset()); | |
326 } | |
327 if (that->IsBitset()) { | |
328 return IsInhabited(this->LubBitset() & that->AsBitset()); | |
329 } | |
330 | |
331 // (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T) | 326 // (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T) |
332 if (this->IsUnion()) { | 327 if (this->IsUnion()) { |
333 StructHandle unioned = this->AsUnion(); | 328 StructHandle unioned = this->AsUnion(); |
334 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 329 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
335 TypeHandle this_i = Config::struct_get(unioned, i); | 330 TypeHandle this_i = Config::struct_get(unioned, i); |
336 if (this_i->Maybe(that)) return true; | 331 if (this_i->Maybe(that)) return true; |
337 } | 332 } |
338 return false; | 333 return false; |
339 } | 334 } |
340 | 335 |
341 // T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn) | 336 // T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn) |
342 if (that->IsUnion()) { | 337 if (that->IsUnion()) { |
343 StructHandle unioned = that->AsUnion(); | 338 StructHandle unioned = that->AsUnion(); |
344 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 339 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
345 TypeHandle that_i = Config::struct_get(unioned, i); | 340 TypeHandle that_i = Config::struct_get(unioned, i); |
346 if (this->Maybe(that_i)) return true; | 341 if (this->Maybe(that_i)) return true; |
347 } | 342 } |
348 return false; | 343 return false; |
349 } | 344 } |
350 | 345 |
351 ASSERT(!this->IsUnion() && !that->IsUnion()); | 346 ASSERT(!this->IsUnion() && !that->IsUnion()); |
| 347 if (this->IsBitset()) { |
| 348 return IsInhabited(this->AsBitset() & that->LubBitset()); |
| 349 } |
| 350 if (that->IsBitset()) { |
| 351 return IsInhabited(this->LubBitset() & that->AsBitset()); |
| 352 } |
| 353 |
352 if (this->IsClass()) { | 354 if (this->IsClass()) { |
353 return that->IsClass() && *this->AsClass() == *that->AsClass(); | 355 return that->IsClass() && *this->AsClass() == *that->AsClass(); |
354 } | 356 } |
355 if (this->IsConstant()) { | 357 if (this->IsConstant()) { |
356 return that->IsConstant() && *this->AsConstant() == *that->AsConstant(); | 358 return that->IsConstant() && *this->AsConstant() == *that->AsConstant(); |
357 } | 359 } |
358 | 360 |
359 return false; | 361 return false; |
360 } | 362 } |
361 | 363 |
362 | 364 |
363 template<class Config> | 365 template<class Config> |
364 bool TypeImpl<Config>::Contains(i::Object* value) { | 366 bool TypeImpl<Config>::Contains(i::Object* value) { |
365 for (Iterator<i::Object> it = this->Constants(); !it.Done(); it.Advance()) { | 367 for (Iterator<i::Object> it = this->Constants(); !it.Done(); it.Advance()) { |
366 if (*it.Current() == value) return true; | 368 if (*it.Current() == value) return true; |
367 } | 369 } |
368 return Config::from_bitset(LubBitset(value))->Is(this); | 370 return Config::from_bitset(LubBitset(value))->Is(this); |
369 } | 371 } |
370 | 372 |
371 | 373 |
372 template<class Config> | 374 template<class Config> |
373 bool TypeImpl<Config>::NowContains(i::Object* value) { | 375 bool TypeImpl<Config>::NowContains(i::Object* value) { |
374 return this->Contains(value) || | 376 if (value->IsHeapObject()) { |
375 (this->IsClass() && value->IsHeapObject() && | 377 DisallowHeapAllocation no_allocation; |
376 *this->AsClass() == i::HeapObject::cast(value)->map()); | 378 i::Map* map = i::HeapObject::cast(value)->map(); |
| 379 for (Iterator<i::Map> it = this->Classes(); !it.Done(); it.Advance()) { |
| 380 if (*it.Current() == map) return true; |
| 381 } |
| 382 } |
| 383 return this->Contains(value); |
377 } | 384 } |
378 | 385 |
379 | 386 |
380 template<class Config> | 387 template<class Config> |
381 bool TypeImpl<Config>::InUnion(StructHandle unioned, int current_size) { | 388 bool TypeImpl<Config>::InUnion(StructHandle unioned, int current_size) { |
382 ASSERT(!this->IsUnion()); | 389 ASSERT(!this->IsUnion()); |
383 for (int i = 0; i < current_size; ++i) { | 390 for (int i = 0; i < current_size; ++i) { |
384 TypeHandle type = Config::struct_get(unioned, i); | 391 TypeHandle type = Config::struct_get(unioned, i); |
385 if (this->Is(type)) return true; | 392 if (this->Is(type)) return true; |
386 } | 393 } |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; | 688 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; |
682 | 689 |
683 template TypeImpl<ZoneTypeConfig>::TypeHandle | 690 template TypeImpl<ZoneTypeConfig>::TypeHandle |
684 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( | 691 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( |
685 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); | 692 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); |
686 template TypeImpl<HeapTypeConfig>::TypeHandle | 693 template TypeImpl<HeapTypeConfig>::TypeHandle |
687 TypeImpl<HeapTypeConfig>::Convert<Type>( | 694 TypeImpl<HeapTypeConfig>::Convert<Type>( |
688 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); | 695 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); |
689 | 696 |
690 } } // namespace v8::internal | 697 } } // namespace v8::internal |
OLD | NEW |