Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 5352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5363 if (access.representation().IsDouble()) { | 5363 if (access.representation().IsDouble()) { |
| 5364 // Load the heap number. | 5364 // Load the heap number. |
| 5365 checked_object = Add<HLoadNamedField>( | 5365 checked_object = Add<HLoadNamedField>( |
| 5366 checked_object, static_cast<HValue*>(NULL), | 5366 checked_object, static_cast<HValue*>(NULL), |
| 5367 access.WithRepresentation(Representation::Tagged())); | 5367 access.WithRepresentation(Representation::Tagged())); |
| 5368 checked_object->set_type(HType::HeapNumber()); | 5368 checked_object->set_type(HType::HeapNumber()); |
| 5369 // Load the double value from it. | 5369 // Load the double value from it. |
| 5370 access = HObjectAccess::ForHeapNumberValue(); | 5370 access = HObjectAccess::ForHeapNumberValue(); |
| 5371 } | 5371 } |
| 5372 return New<HLoadNamedField>( | 5372 return New<HLoadNamedField>( |
| 5373 checked_object, static_cast<HValue*>(NULL), access, info->field_map()); | 5373 checked_object, checked_object, access, info->field_maps(), top_info()); |
| 5374 } | 5374 } |
| 5375 | 5375 |
| 5376 | 5376 |
| 5377 HInstruction* HOptimizedGraphBuilder::BuildStoreNamedField( | 5377 HInstruction* HOptimizedGraphBuilder::BuildStoreNamedField( |
| 5378 PropertyAccessInfo* info, | 5378 PropertyAccessInfo* info, |
| 5379 HValue* checked_object, | 5379 HValue* checked_object, |
| 5380 HValue* value) { | 5380 HValue* value) { |
| 5381 bool transition_to_field = info->lookup()->IsTransition(); | 5381 bool transition_to_field = info->lookup()->IsTransition(); |
| 5382 // TODO(verwaest): Move this logic into PropertyAccessInfo. | 5382 // TODO(verwaest): Move this logic into PropertyAccessInfo. |
| 5383 HObjectAccess field_access = info->access(); | 5383 HObjectAccess field_access = info->access(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 5407 } else { | 5407 } else { |
| 5408 // Already holds a HeapNumber; load the box and write its value field. | 5408 // Already holds a HeapNumber; load the box and write its value field. |
| 5409 HInstruction* heap_number = Add<HLoadNamedField>( | 5409 HInstruction* heap_number = Add<HLoadNamedField>( |
| 5410 checked_object, static_cast<HValue*>(NULL), heap_number_access); | 5410 checked_object, static_cast<HValue*>(NULL), heap_number_access); |
| 5411 heap_number->set_type(HType::HeapNumber()); | 5411 heap_number->set_type(HType::HeapNumber()); |
| 5412 instr = New<HStoreNamedField>(heap_number, | 5412 instr = New<HStoreNamedField>(heap_number, |
| 5413 HObjectAccess::ForHeapNumberValue(), | 5413 HObjectAccess::ForHeapNumberValue(), |
| 5414 value, STORE_TO_INITIALIZED_ENTRY); | 5414 value, STORE_TO_INITIALIZED_ENTRY); |
| 5415 } | 5415 } |
| 5416 } else { | 5416 } else { |
| 5417 if (!info->field_map().is_null()) { | 5417 if (!info->field_maps()->is_empty()) { |
| 5418 ASSERT(field_access.representation().IsHeapObject()); | 5418 ASSERT(field_access.representation().IsHeapObject()); |
| 5419 BuildCheckHeapObject(value); | 5419 BuildCheckHeapObject(value); |
| 5420 value = BuildCheckMap(value, info->field_map()); | 5420 if (info->field_maps()->length() == 1) { |
| 5421 // TODO(bmeurer): Also apply stable maps optimization to the else case! | |
|
Benedikt Meurer
2014/04/16 07:35:24
Note that this requires changes to the HCheckMaps,
| |
| 5422 value = BuildCheckMap(value, info->field_maps()->first()); | |
| 5423 } else { | |
| 5424 value = Add<HCheckMaps>(value, info->field_maps()); | |
| 5425 } | |
| 5421 | 5426 |
| 5422 // TODO(bmeurer): This is a dirty hack to avoid repeating the smi check | 5427 // TODO(bmeurer): This is a dirty hack to avoid repeating the smi check |
| 5423 // that was already performed by the HCheckHeapObject above in the | 5428 // that was already performed by the HCheckHeapObject above in the |
| 5424 // HStoreNamedField below. We should really do this right instead and | 5429 // HStoreNamedField below. We should really do this right instead and |
| 5425 // make Crankshaft aware of Representation::HeapObject(). | 5430 // make Crankshaft aware of Representation::HeapObject(). |
| 5426 field_access = field_access.WithRepresentation(Representation::Tagged()); | 5431 field_access = field_access.WithRepresentation(Representation::Tagged()); |
| 5427 } | 5432 } |
| 5428 | 5433 |
| 5429 // This is a normal store. | 5434 // This is a normal store. |
| 5430 instr = New<HStoreNamedField>( | 5435 instr = New<HStoreNamedField>( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5482 if (!info->lookup_.IsField()) return false; | 5487 if (!info->lookup_.IsField()) return false; |
| 5483 | 5488 |
| 5484 Representation r = access_.representation(); | 5489 Representation r = access_.representation(); |
| 5485 if (IsLoad()) { | 5490 if (IsLoad()) { |
| 5486 if (!info->access_.representation().IsCompatibleForLoad(r)) return false; | 5491 if (!info->access_.representation().IsCompatibleForLoad(r)) return false; |
| 5487 } else { | 5492 } else { |
| 5488 if (!info->access_.representation().IsCompatibleForStore(r)) return false; | 5493 if (!info->access_.representation().IsCompatibleForStore(r)) return false; |
| 5489 } | 5494 } |
| 5490 if (info->access_.offset() != access_.offset()) return false; | 5495 if (info->access_.offset() != access_.offset()) return false; |
| 5491 if (info->access_.IsInobject() != access_.IsInobject()) return false; | 5496 if (info->access_.IsInobject() != access_.IsInobject()) return false; |
| 5492 if (!field_map_.is_identical_to(info->field_map_)) { | 5497 if (IsLoad()) { |
| 5493 if (!IsLoad()) return false; | 5498 if (field_maps_.is_empty() || info->field_maps_.is_empty()) { |
| 5494 | 5499 info->field_maps_.Clear(); |
| 5495 // Throw away type information for merging polymorphic loads. | 5500 } else { |
| 5496 field_map_ = info->field_map_ = Handle<Map>(); | 5501 for (int i = 0; i < field_maps_.length(); ++i) { |
| 5502 info->field_maps_.AddMapIfMissing(field_maps_.at(i), info->zone()); | |
| 5503 } | |
| 5504 info->field_maps_.Sort(); | |
| 5505 } | |
| 5506 } else { | |
| 5507 if (field_maps_.length() != info->field_maps_.length()) return false; | |
| 5508 for (int i = 0; i < field_maps_.length(); ++i) { | |
| 5509 if (!field_maps_.at(i).is_identical_to(info->field_maps_.at(i))) { | |
| 5510 return false; | |
| 5511 } | |
| 5512 } | |
| 5497 } | 5513 } |
| 5498 info->GeneralizeRepresentation(r); | 5514 info->GeneralizeRepresentation(r); |
| 5499 return true; | 5515 return true; |
| 5500 } | 5516 } |
| 5501 | 5517 |
| 5502 | 5518 |
| 5503 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupDescriptor() { | 5519 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupDescriptor() { |
| 5504 if (!type_->IsClass()) return true; | 5520 if (!type_->IsClass()) return true; |
| 5505 map()->LookupDescriptor(NULL, *name_, &lookup_); | 5521 map()->LookupDescriptor(NULL, *name_, &lookup_); |
| 5506 return LoadResult(map()); | 5522 return LoadResult(map()); |
| 5507 } | 5523 } |
| 5508 | 5524 |
| 5509 | 5525 |
| 5510 bool HOptimizedGraphBuilder::PropertyAccessInfo::LoadResult(Handle<Map> map) { | 5526 bool HOptimizedGraphBuilder::PropertyAccessInfo::LoadResult(Handle<Map> map) { |
| 5511 if (!IsLoad() && lookup_.IsProperty() && | 5527 if (!IsLoad() && lookup_.IsProperty() && |
| 5512 (lookup_.IsReadOnly() || !lookup_.IsCacheable())) { | 5528 (lookup_.IsReadOnly() || !lookup_.IsCacheable())) { |
| 5513 return false; | 5529 return false; |
| 5514 } | 5530 } |
| 5515 | 5531 |
| 5516 if (lookup_.IsField()) { | 5532 if (lookup_.IsField()) { |
| 5517 // Construct the object field access. | 5533 // Construct the object field access. |
| 5518 access_ = HObjectAccess::ForField(map, &lookup_, name_); | 5534 access_ = HObjectAccess::ForField(map, &lookup_, name_); |
| 5519 | 5535 |
| 5520 // Load field map for heap objects. | 5536 // Load field map for heap objects. |
| 5521 if (access_.representation().IsHeapObject()) LoadFieldMap(map); | 5537 if (access_.representation().IsHeapObject()) LoadFieldMaps(map); |
| 5522 } else if (lookup_.IsPropertyCallbacks()) { | 5538 } else if (lookup_.IsPropertyCallbacks()) { |
| 5523 Handle<Object> callback(lookup_.GetValueFromMap(*map), isolate()); | 5539 Handle<Object> callback(lookup_.GetValueFromMap(*map), isolate()); |
| 5524 if (!callback->IsAccessorPair()) return false; | 5540 if (!callback->IsAccessorPair()) return false; |
| 5525 Object* raw_accessor = IsLoad() | 5541 Object* raw_accessor = IsLoad() |
| 5526 ? Handle<AccessorPair>::cast(callback)->getter() | 5542 ? Handle<AccessorPair>::cast(callback)->getter() |
| 5527 : Handle<AccessorPair>::cast(callback)->setter(); | 5543 : Handle<AccessorPair>::cast(callback)->setter(); |
| 5528 if (!raw_accessor->IsJSFunction()) return false; | 5544 if (!raw_accessor->IsJSFunction()) return false; |
| 5529 Handle<JSFunction> accessor = handle(JSFunction::cast(raw_accessor)); | 5545 Handle<JSFunction> accessor = handle(JSFunction::cast(raw_accessor)); |
| 5530 if (accessor->shared()->IsApiFunction()) { | 5546 if (accessor->shared()->IsApiFunction()) { |
| 5531 CallOptimization call_optimization(accessor); | 5547 CallOptimization call_optimization(accessor); |
| 5532 if (call_optimization.is_simple_api_call()) { | 5548 if (call_optimization.is_simple_api_call()) { |
| 5533 CallOptimization::HolderLookup holder_lookup; | 5549 CallOptimization::HolderLookup holder_lookup; |
| 5534 Handle<Map> receiver_map = this->map(); | 5550 Handle<Map> receiver_map = this->map(); |
| 5535 api_holder_ = call_optimization.LookupHolderOfExpectedType( | 5551 api_holder_ = call_optimization.LookupHolderOfExpectedType( |
| 5536 receiver_map, &holder_lookup); | 5552 receiver_map, &holder_lookup); |
| 5537 } | 5553 } |
| 5538 } | 5554 } |
| 5539 accessor_ = accessor; | 5555 accessor_ = accessor; |
| 5540 } else if (lookup_.IsConstant()) { | 5556 } else if (lookup_.IsConstant()) { |
| 5541 constant_ = handle(lookup_.GetConstantFromMap(*map), isolate()); | 5557 constant_ = handle(lookup_.GetConstantFromMap(*map), isolate()); |
| 5542 } | 5558 } |
| 5543 | 5559 |
| 5544 return true; | 5560 return true; |
| 5545 } | 5561 } |
| 5546 | 5562 |
| 5547 | 5563 |
| 5548 void HOptimizedGraphBuilder::PropertyAccessInfo::LoadFieldMap(Handle<Map> map) { | 5564 void HOptimizedGraphBuilder::PropertyAccessInfo::LoadFieldMaps( |
| 5565 Handle<Map> map) { | |
| 5566 ASSERT(field_maps_.is_empty()); | |
| 5567 | |
| 5549 // Figure out the field type from the accessor map. | 5568 // Figure out the field type from the accessor map. |
| 5550 HeapType* field_type = lookup_.GetFieldTypeFromMap(*map); | 5569 Handle<HeapType> field_type(lookup_.GetFieldTypeFromMap(*map), isolate()); |
| 5551 if (field_type->IsClass()) { | |
| 5552 Handle<Map> field_map = field_type->AsClass(); | |
| 5553 if (field_map->is_stable()) { | |
| 5554 field_map_ = field_map; | |
| 5555 Map::AddDependentCompilationInfo( | |
| 5556 field_map_, DependentCode::kPrototypeCheckGroup, top_info()); | |
| 5557 | 5570 |
| 5558 // Add dependency on the map that introduced the field. | 5571 // Collect the (stable) maps from the field type. |
| 5559 Map::AddDependentCompilationInfo( | 5572 int num_field_maps = field_type->NumClasses(); |
| 5560 handle(lookup_.GetFieldOwnerFromMap(*map), isolate()), | 5573 if (num_field_maps == 0) return; |
| 5561 DependentCode::kFieldTypeGroup, top_info()); | 5574 field_maps_.Reserve(num_field_maps, zone()); |
| 5575 HeapType::Iterator<Map> it = field_type->Classes(); | |
| 5576 while (!it.Done()) { | |
| 5577 Handle<Map> field_map = it.Current(); | |
| 5578 if (!field_map->is_stable()) { | |
| 5579 field_maps_.Clear(); | |
| 5580 return; | |
| 5562 } | 5581 } |
| 5582 field_maps_.Add(field_map, zone()); | |
| 5583 it.Advance(); | |
| 5563 } | 5584 } |
| 5585 field_maps_.Sort(); | |
| 5586 ASSERT_EQ(num_field_maps, field_maps_.length()); | |
| 5587 | |
| 5588 // Add dependency on the map that introduced the field. | |
| 5589 Map::AddDependentCompilationInfo( | |
| 5590 handle(lookup_.GetFieldOwnerFromMap(*map), isolate()), | |
| 5591 DependentCode::kFieldTypeGroup, top_info()); | |
| 5564 } | 5592 } |
| 5565 | 5593 |
| 5566 | 5594 |
| 5567 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupInPrototypes() { | 5595 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupInPrototypes() { |
| 5568 Handle<Map> map = this->map(); | 5596 Handle<Map> map = this->map(); |
| 5569 | 5597 |
| 5570 while (map->prototype()->IsJSObject()) { | 5598 while (map->prototype()->IsJSObject()) { |
| 5571 holder_ = handle(JSObject::cast(map->prototype())); | 5599 holder_ = handle(JSObject::cast(map->prototype())); |
| 5572 if (holder_->map()->is_deprecated()) { | 5600 if (holder_->map()->is_deprecated()) { |
| 5573 JSObject::TryMigrateInstance(holder_); | 5601 JSObject::TryMigrateInstance(holder_); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 5597 if (IsLoad()) return true; | 5625 if (IsLoad()) return true; |
| 5598 | 5626 |
| 5599 if (lookup_.IsPropertyCallbacks()) return true; | 5627 if (lookup_.IsPropertyCallbacks()) return true; |
| 5600 Handle<Map> map = this->map(); | 5628 Handle<Map> map = this->map(); |
| 5601 map->LookupTransition(NULL, *name_, &lookup_); | 5629 map->LookupTransition(NULL, *name_, &lookup_); |
| 5602 if (lookup_.IsTransitionToField() && map->unused_property_fields() > 0) { | 5630 if (lookup_.IsTransitionToField() && map->unused_property_fields() > 0) { |
| 5603 // Construct the object field access. | 5631 // Construct the object field access. |
| 5604 access_ = HObjectAccess::ForField(map, &lookup_, name_); | 5632 access_ = HObjectAccess::ForField(map, &lookup_, name_); |
| 5605 | 5633 |
| 5606 // Load field map for heap objects. | 5634 // Load field map for heap objects. |
| 5607 if (access_.representation().IsHeapObject()) LoadFieldMap(transition()); | 5635 if (access_.representation().IsHeapObject()) LoadFieldMaps(transition()); |
| 5608 return true; | 5636 return true; |
| 5609 } | 5637 } |
| 5610 return false; | 5638 return false; |
| 5611 } | 5639 } |
| 5612 | 5640 |
| 5613 | 5641 |
| 5614 bool HOptimizedGraphBuilder::PropertyAccessInfo::CanAccessAsMonomorphic( | 5642 bool HOptimizedGraphBuilder::PropertyAccessInfo::CanAccessAsMonomorphic( |
| 5615 SmallMapList* types) { | 5643 SmallMapList* types) { |
| 5616 ASSERT(type_->Is(ToType(types->first()))); | 5644 ASSERT(type_->Is(ToType(types->first()))); |
| 5617 if (!CanAccessMonomorphic()) return false; | 5645 if (!CanAccessMonomorphic()) return false; |
| (...skipping 5983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11601 if (ShouldProduceTraceOutput()) { | 11629 if (ShouldProduceTraceOutput()) { |
| 11602 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 11630 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
| 11603 } | 11631 } |
| 11604 | 11632 |
| 11605 #ifdef DEBUG | 11633 #ifdef DEBUG |
| 11606 graph_->Verify(false); // No full verify. | 11634 graph_->Verify(false); // No full verify. |
| 11607 #endif | 11635 #endif |
| 11608 } | 11636 } |
| 11609 | 11637 |
| 11610 } } // namespace v8::internal | 11638 } } // namespace v8::internal |
| OLD | NEW |