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); | 5373 checked_object, static_cast<HValue*>(NULL), access, info->field_map()); |
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 = HObjectAccess::ForField( | 5383 HObjectAccess field_access = info->access(); |
5384 info->map(), info->lookup(), info->name()); | |
5385 | 5384 |
5386 HStoreNamedField *instr; | 5385 HStoreNamedField *instr; |
5387 if (field_access.representation().IsDouble()) { | 5386 if (field_access.representation().IsDouble()) { |
5388 HObjectAccess heap_number_access = | 5387 HObjectAccess heap_number_access = |
5389 field_access.WithRepresentation(Representation::Tagged()); | 5388 field_access.WithRepresentation(Representation::Tagged()); |
5390 if (transition_to_field) { | 5389 if (transition_to_field) { |
5391 // The store requires a mutable HeapNumber to be allocated. | 5390 // The store requires a mutable HeapNumber to be allocated. |
5392 NoObservableSideEffectsScope no_side_effects(this); | 5391 NoObservableSideEffectsScope no_side_effects(this); |
5393 HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize); | 5392 HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize); |
5394 | 5393 |
(...skipping 13 matching lines...) Expand all Loading... |
5408 } else { | 5407 } else { |
5409 // 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. |
5410 HInstruction* heap_number = Add<HLoadNamedField>( | 5409 HInstruction* heap_number = Add<HLoadNamedField>( |
5411 checked_object, static_cast<HValue*>(NULL), heap_number_access); | 5410 checked_object, static_cast<HValue*>(NULL), heap_number_access); |
5412 heap_number->set_type(HType::HeapNumber()); | 5411 heap_number->set_type(HType::HeapNumber()); |
5413 instr = New<HStoreNamedField>(heap_number, | 5412 instr = New<HStoreNamedField>(heap_number, |
5414 HObjectAccess::ForHeapNumberValue(), | 5413 HObjectAccess::ForHeapNumberValue(), |
5415 value, STORE_TO_INITIALIZED_ENTRY); | 5414 value, STORE_TO_INITIALIZED_ENTRY); |
5416 } | 5415 } |
5417 } else { | 5416 } else { |
| 5417 if (!info->field_map().is_null()) { |
| 5418 ASSERT(field_access.representation().IsHeapObject()); |
| 5419 BuildCheckHeapObject(value); |
| 5420 value = BuildCheckMap(value, info->field_map()); |
| 5421 |
| 5422 // TODO(bmeurer): This is a dirty hack to avoid repeating the smi check |
| 5423 // that was already performed by the HCheckHeapObject above in the |
| 5424 // HStoreNamedField below. We should really do this right instead and |
| 5425 // make Crankshaft aware of Representation::HeapObject(). |
| 5426 field_access = field_access.WithRepresentation(Representation::Tagged()); |
| 5427 } |
| 5428 |
5418 // This is a normal store. | 5429 // This is a normal store. |
5419 instr = New<HStoreNamedField>( | 5430 instr = New<HStoreNamedField>( |
5420 checked_object->ActualValue(), field_access, value, | 5431 checked_object->ActualValue(), field_access, value, |
5421 transition_to_field ? INITIALIZING_STORE : STORE_TO_INITIALIZED_ENTRY); | 5432 transition_to_field ? INITIALIZING_STORE : STORE_TO_INITIALIZED_ENTRY); |
5422 } | 5433 } |
5423 | 5434 |
5424 if (transition_to_field) { | 5435 if (transition_to_field) { |
5425 HConstant* transition_constant = Add<HConstant>(info->transition()); | 5436 HConstant* transition_constant = Add<HConstant>(info->transition()); |
5426 instr->SetTransition(transition_constant, top_info()); | 5437 instr->SetTransition(transition_constant, top_info()); |
5427 instr->SetChangesFlag(kMaps); | 5438 instr->SetChangesFlag(kMaps); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5471 if (!info->lookup_.IsField()) return false; | 5482 if (!info->lookup_.IsField()) return false; |
5472 | 5483 |
5473 Representation r = access_.representation(); | 5484 Representation r = access_.representation(); |
5474 if (IsLoad()) { | 5485 if (IsLoad()) { |
5475 if (!info->access_.representation().IsCompatibleForLoad(r)) return false; | 5486 if (!info->access_.representation().IsCompatibleForLoad(r)) return false; |
5476 } else { | 5487 } else { |
5477 if (!info->access_.representation().IsCompatibleForStore(r)) return false; | 5488 if (!info->access_.representation().IsCompatibleForStore(r)) return false; |
5478 } | 5489 } |
5479 if (info->access_.offset() != access_.offset()) return false; | 5490 if (info->access_.offset() != access_.offset()) return false; |
5480 if (info->access_.IsInobject() != access_.IsInobject()) return false; | 5491 if (info->access_.IsInobject() != access_.IsInobject()) return false; |
| 5492 if (!field_map_.is_identical_to(info->field_map_)) { |
| 5493 if (!IsLoad()) return false; |
| 5494 |
| 5495 // Throw away type information for merging polymorphic loads. |
| 5496 field_map_ = info->field_map_ = Handle<Map>(); |
| 5497 } |
5481 info->GeneralizeRepresentation(r); | 5498 info->GeneralizeRepresentation(r); |
5482 return true; | 5499 return true; |
5483 } | 5500 } |
5484 | 5501 |
5485 | 5502 |
5486 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupDescriptor() { | 5503 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupDescriptor() { |
5487 if (!type_->IsClass()) return true; | 5504 if (!type_->IsClass()) return true; |
5488 map()->LookupDescriptor(NULL, *name_, &lookup_); | 5505 map()->LookupDescriptor(NULL, *name_, &lookup_); |
5489 return LoadResult(map()); | 5506 return LoadResult(map()); |
5490 } | 5507 } |
5491 | 5508 |
5492 | 5509 |
5493 bool HOptimizedGraphBuilder::PropertyAccessInfo::LoadResult(Handle<Map> map) { | 5510 bool HOptimizedGraphBuilder::PropertyAccessInfo::LoadResult(Handle<Map> map) { |
5494 if (!IsLoad() && lookup_.IsProperty() && | 5511 if (!IsLoad() && lookup_.IsProperty() && |
5495 (lookup_.IsReadOnly() || !lookup_.IsCacheable())) { | 5512 (lookup_.IsReadOnly() || !lookup_.IsCacheable())) { |
5496 return false; | 5513 return false; |
5497 } | 5514 } |
5498 | 5515 |
5499 if (lookup_.IsField()) { | 5516 if (lookup_.IsField()) { |
| 5517 // Construct the object field access. |
5500 access_ = HObjectAccess::ForField(map, &lookup_, name_); | 5518 access_ = HObjectAccess::ForField(map, &lookup_, name_); |
| 5519 |
| 5520 // Load field map for heap objects. |
| 5521 if (access_.representation().IsHeapObject()) LoadFieldMap(map); |
5501 } else if (lookup_.IsPropertyCallbacks()) { | 5522 } else if (lookup_.IsPropertyCallbacks()) { |
5502 Handle<Object> callback(lookup_.GetValueFromMap(*map), isolate()); | 5523 Handle<Object> callback(lookup_.GetValueFromMap(*map), isolate()); |
5503 if (!callback->IsAccessorPair()) return false; | 5524 if (!callback->IsAccessorPair()) return false; |
5504 Object* raw_accessor = IsLoad() | 5525 Object* raw_accessor = IsLoad() |
5505 ? Handle<AccessorPair>::cast(callback)->getter() | 5526 ? Handle<AccessorPair>::cast(callback)->getter() |
5506 : Handle<AccessorPair>::cast(callback)->setter(); | 5527 : Handle<AccessorPair>::cast(callback)->setter(); |
5507 if (!raw_accessor->IsJSFunction()) return false; | 5528 if (!raw_accessor->IsJSFunction()) return false; |
5508 Handle<JSFunction> accessor = handle(JSFunction::cast(raw_accessor)); | 5529 Handle<JSFunction> accessor = handle(JSFunction::cast(raw_accessor)); |
5509 if (accessor->shared()->IsApiFunction()) { | 5530 if (accessor->shared()->IsApiFunction()) { |
5510 CallOptimization call_optimization(accessor); | 5531 CallOptimization call_optimization(accessor); |
5511 if (call_optimization.is_simple_api_call()) { | 5532 if (call_optimization.is_simple_api_call()) { |
5512 CallOptimization::HolderLookup holder_lookup; | 5533 CallOptimization::HolderLookup holder_lookup; |
5513 Handle<Map> receiver_map = this->map(); | 5534 Handle<Map> receiver_map = this->map(); |
5514 api_holder_ = call_optimization.LookupHolderOfExpectedType( | 5535 api_holder_ = call_optimization.LookupHolderOfExpectedType( |
5515 receiver_map, &holder_lookup); | 5536 receiver_map, &holder_lookup); |
5516 } | 5537 } |
5517 } | 5538 } |
5518 accessor_ = accessor; | 5539 accessor_ = accessor; |
5519 } else if (lookup_.IsConstant()) { | 5540 } else if (lookup_.IsConstant()) { |
5520 constant_ = handle(lookup_.GetConstantFromMap(*map), isolate()); | 5541 constant_ = handle(lookup_.GetConstantFromMap(*map), isolate()); |
5521 } | 5542 } |
5522 | 5543 |
5523 return true; | 5544 return true; |
5524 } | 5545 } |
5525 | 5546 |
5526 | 5547 |
| 5548 void HOptimizedGraphBuilder::PropertyAccessInfo::LoadFieldMap(Handle<Map> map) { |
| 5549 // Figure out the field type from the accessor map. |
| 5550 HeapType* field_type = lookup_.GetFieldTypeFromMap(*map); |
| 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 field_map_->AddDependentCompilationInfo( |
| 5556 DependentCode::kPrototypeCheckGroup, top_info()); |
| 5557 |
| 5558 // Add dependency on the map that introduced the field. |
| 5559 lookup_.GetFieldOwnerFromMap(*map)->AddDependentCompilationInfo( |
| 5560 DependentCode::kFieldTypeGroup, top_info()); |
| 5561 } |
| 5562 } |
| 5563 } |
| 5564 |
| 5565 |
5527 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupInPrototypes() { | 5566 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupInPrototypes() { |
5528 Handle<Map> map = this->map(); | 5567 Handle<Map> map = this->map(); |
5529 | 5568 |
5530 while (map->prototype()->IsJSObject()) { | 5569 while (map->prototype()->IsJSObject()) { |
5531 holder_ = handle(JSObject::cast(map->prototype())); | 5570 holder_ = handle(JSObject::cast(map->prototype())); |
5532 if (holder_->map()->is_deprecated()) { | 5571 if (holder_->map()->is_deprecated()) { |
5533 JSObject::TryMigrateInstance(holder_); | 5572 JSObject::TryMigrateInstance(holder_); |
5534 } | 5573 } |
5535 map = Handle<Map>(holder_->map()); | 5574 map = Handle<Map>(holder_->map()); |
5536 if (!CanInlinePropertyAccess(ToType(map))) { | 5575 if (!CanInlinePropertyAccess(ToType(map))) { |
(...skipping 16 matching lines...) Expand all Loading... |
5553 if (IsLoad()) return true; | 5592 if (IsLoad()) return true; |
5554 return !lookup_.IsReadOnly() && lookup_.IsCacheable(); | 5593 return !lookup_.IsReadOnly() && lookup_.IsCacheable(); |
5555 } | 5594 } |
5556 if (!LookupInPrototypes()) return false; | 5595 if (!LookupInPrototypes()) return false; |
5557 if (IsLoad()) return true; | 5596 if (IsLoad()) return true; |
5558 | 5597 |
5559 if (lookup_.IsPropertyCallbacks()) return true; | 5598 if (lookup_.IsPropertyCallbacks()) return true; |
5560 Handle<Map> map = this->map(); | 5599 Handle<Map> map = this->map(); |
5561 map->LookupTransition(NULL, *name_, &lookup_); | 5600 map->LookupTransition(NULL, *name_, &lookup_); |
5562 if (lookup_.IsTransitionToField() && map->unused_property_fields() > 0) { | 5601 if (lookup_.IsTransitionToField() && map->unused_property_fields() > 0) { |
| 5602 // Construct the object field access. |
| 5603 access_ = HObjectAccess::ForField(map, &lookup_, name_); |
| 5604 |
| 5605 // Load field map for heap objects. |
| 5606 if (access_.representation().IsHeapObject()) LoadFieldMap(transition()); |
5563 return true; | 5607 return true; |
5564 } | 5608 } |
5565 return false; | 5609 return false; |
5566 } | 5610 } |
5567 | 5611 |
5568 | 5612 |
5569 bool HOptimizedGraphBuilder::PropertyAccessInfo::CanAccessAsMonomorphic( | 5613 bool HOptimizedGraphBuilder::PropertyAccessInfo::CanAccessAsMonomorphic( |
5570 SmallMapList* types) { | 5614 SmallMapList* types) { |
5571 ASSERT(type_->Is(ToType(types->first()))); | 5615 ASSERT(type_->Is(ToType(types->first()))); |
5572 if (!CanAccessMonomorphic()) return false; | 5616 if (!CanAccessMonomorphic()) return false; |
(...skipping 5983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11556 if (ShouldProduceTraceOutput()) { | 11600 if (ShouldProduceTraceOutput()) { |
11557 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 11601 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
11558 } | 11602 } |
11559 | 11603 |
11560 #ifdef DEBUG | 11604 #ifdef DEBUG |
11561 graph_->Verify(false); // No full verify. | 11605 graph_->Verify(false); // No full verify. |
11562 #endif | 11606 #endif |
11563 } | 11607 } |
11564 | 11608 |
11565 } } // namespace v8::internal | 11609 } } // namespace v8::internal |
OLD | NEW |