Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: src/hydrogen.cc

Issue 239923004: Allow merging of monomorphic accesses to tracked fields. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-check-elimination.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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!
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
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()) {
5494 5499 info->field_maps_.Clear();
5495 // Throw away type information for merging polymorphic loads. 5500 } else if (!info->field_maps_.is_empty()) {
5496 info->field_map_ = Handle<Map>::null(); 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 // We can only merge stores that agree on their field maps. The comparison
5508 // below is safe, since we keep the field maps sorted.
5509 if (field_maps_.length() != info->field_maps_.length()) return false;
5510 for (int i = 0; i < field_maps_.length(); ++i) {
5511 if (!field_maps_.at(i).is_identical_to(info->field_maps_.at(i))) {
5512 return false;
5513 }
5514 }
5497 } 5515 }
5498 info->GeneralizeRepresentation(r); 5516 info->GeneralizeRepresentation(r);
5499 return true; 5517 return true;
5500 } 5518 }
5501 5519
5502 5520
5503 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupDescriptor() { 5521 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupDescriptor() {
5504 if (!type_->IsClass()) return true; 5522 if (!type_->IsClass()) return true;
5505 map()->LookupDescriptor(NULL, *name_, &lookup_); 5523 map()->LookupDescriptor(NULL, *name_, &lookup_);
5506 return LoadResult(map()); 5524 return LoadResult(map());
5507 } 5525 }
5508 5526
5509 5527
5510 bool HOptimizedGraphBuilder::PropertyAccessInfo::LoadResult(Handle<Map> map) { 5528 bool HOptimizedGraphBuilder::PropertyAccessInfo::LoadResult(Handle<Map> map) {
5511 if (!IsLoad() && lookup_.IsProperty() && 5529 if (!IsLoad() && lookup_.IsProperty() &&
5512 (lookup_.IsReadOnly() || !lookup_.IsCacheable())) { 5530 (lookup_.IsReadOnly() || !lookup_.IsCacheable())) {
5513 return false; 5531 return false;
5514 } 5532 }
5515 5533
5516 if (lookup_.IsField()) { 5534 if (lookup_.IsField()) {
5517 // Construct the object field access. 5535 // Construct the object field access.
5518 access_ = HObjectAccess::ForField(map, &lookup_, name_); 5536 access_ = HObjectAccess::ForField(map, &lookup_, name_);
5519 5537
5520 // Load field map for heap objects. 5538 // Load field map for heap objects.
5521 LoadFieldMap(map); 5539 LoadFieldMaps(map);
5522 } else if (lookup_.IsPropertyCallbacks()) { 5540 } else if (lookup_.IsPropertyCallbacks()) {
5523 Handle<Object> callback(lookup_.GetValueFromMap(*map), isolate()); 5541 Handle<Object> callback(lookup_.GetValueFromMap(*map), isolate());
5524 if (!callback->IsAccessorPair()) return false; 5542 if (!callback->IsAccessorPair()) return false;
5525 Object* raw_accessor = IsLoad() 5543 Object* raw_accessor = IsLoad()
5526 ? Handle<AccessorPair>::cast(callback)->getter() 5544 ? Handle<AccessorPair>::cast(callback)->getter()
5527 : Handle<AccessorPair>::cast(callback)->setter(); 5545 : Handle<AccessorPair>::cast(callback)->setter();
5528 if (!raw_accessor->IsJSFunction()) return false; 5546 if (!raw_accessor->IsJSFunction()) return false;
5529 Handle<JSFunction> accessor = handle(JSFunction::cast(raw_accessor)); 5547 Handle<JSFunction> accessor = handle(JSFunction::cast(raw_accessor));
5530 if (accessor->shared()->IsApiFunction()) { 5548 if (accessor->shared()->IsApiFunction()) {
5531 CallOptimization call_optimization(accessor); 5549 CallOptimization call_optimization(accessor);
5532 if (call_optimization.is_simple_api_call()) { 5550 if (call_optimization.is_simple_api_call()) {
5533 CallOptimization::HolderLookup holder_lookup; 5551 CallOptimization::HolderLookup holder_lookup;
5534 Handle<Map> receiver_map = this->map(); 5552 Handle<Map> receiver_map = this->map();
5535 api_holder_ = call_optimization.LookupHolderOfExpectedType( 5553 api_holder_ = call_optimization.LookupHolderOfExpectedType(
5536 receiver_map, &holder_lookup); 5554 receiver_map, &holder_lookup);
5537 } 5555 }
5538 } 5556 }
5539 accessor_ = accessor; 5557 accessor_ = accessor;
5540 } else if (lookup_.IsConstant()) { 5558 } else if (lookup_.IsConstant()) {
5541 constant_ = handle(lookup_.GetConstantFromMap(*map), isolate()); 5559 constant_ = handle(lookup_.GetConstantFromMap(*map), isolate());
5542 } 5560 }
5543 5561
5544 return true; 5562 return true;
5545 } 5563 }
5546 5564
5547 5565
5548 void HOptimizedGraphBuilder::PropertyAccessInfo::LoadFieldMap(Handle<Map> map) { 5566 void HOptimizedGraphBuilder::PropertyAccessInfo::LoadFieldMaps(
5549 // Clear any previous field map. 5567 Handle<Map> map) {
5550 field_map_ = Handle<Map>::null(); 5568 // Figure out the field type from the accessor map.
5569 Handle<HeapType> field_type(lookup_.GetFieldTypeFromMap(*map), isolate());
5551 5570
5552 // Figure out the field type from the accessor map. 5571 // Collect the (stable) maps from the field type.
5553 HeapType* field_type = lookup_.GetFieldTypeFromMap(*map); 5572 int num_field_maps = field_type->NumClasses();
5554 if (field_type->IsClass()) { 5573 if (num_field_maps == 0) {
5555 ASSERT(access_.representation().IsHeapObject()); 5574 field_maps_.Clear();
5556 Handle<Map> field_map = field_type->AsClass(); 5575 return;
5557 if (field_map->is_stable()) { 5576 }
5558 field_map_ = field_map; 5577 ASSERT(access_.representation().IsHeapObject());
5559 Map::AddDependentCompilationInfo( 5578 field_maps_.Reserve(num_field_maps, zone());
5560 field_map_, DependentCode::kPrototypeCheckGroup, top_info()); 5579 HeapType::Iterator<Map> it = field_type->Classes();
5580 while (!it.Done()) {
5581 Handle<Map> field_map = it.Current();
5582 if (!field_map->is_stable()) {
5583 field_maps_.Clear();
5584 return;
5585 }
5586 field_maps_.Add(field_map, zone());
5587 it.Advance();
5588 }
5589 field_maps_.Sort();
5590 ASSERT_EQ(num_field_maps, field_maps_.length());
5561 5591
5562 // Add dependency on the map that introduced the field. 5592 // Add dependency on the map that introduced the field.
5563 Map::AddDependentCompilationInfo( 5593 Map::AddDependentCompilationInfo(
5564 handle(lookup_.GetFieldOwnerFromMap(*map), isolate()), 5594 handle(lookup_.GetFieldOwnerFromMap(*map), isolate()),
5565 DependentCode::kFieldTypeGroup, top_info()); 5595 DependentCode::kFieldTypeGroup, top_info());
5566 }
5567 }
5568 } 5596 }
5569 5597
5570 5598
5571 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupInPrototypes() { 5599 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupInPrototypes() {
5572 Handle<Map> map = this->map(); 5600 Handle<Map> map = this->map();
5573 5601
5574 while (map->prototype()->IsJSObject()) { 5602 while (map->prototype()->IsJSObject()) {
5575 holder_ = handle(JSObject::cast(map->prototype())); 5603 holder_ = handle(JSObject::cast(map->prototype()));
5576 if (holder_->map()->is_deprecated()) { 5604 if (holder_->map()->is_deprecated()) {
5577 JSObject::TryMigrateInstance(holder_); 5605 JSObject::TryMigrateInstance(holder_);
(...skipping 23 matching lines...) Expand all
5601 if (IsLoad()) return true; 5629 if (IsLoad()) return true;
5602 5630
5603 if (lookup_.IsPropertyCallbacks()) return true; 5631 if (lookup_.IsPropertyCallbacks()) return true;
5604 Handle<Map> map = this->map(); 5632 Handle<Map> map = this->map();
5605 map->LookupTransition(NULL, *name_, &lookup_); 5633 map->LookupTransition(NULL, *name_, &lookup_);
5606 if (lookup_.IsTransitionToField() && map->unused_property_fields() > 0) { 5634 if (lookup_.IsTransitionToField() && map->unused_property_fields() > 0) {
5607 // Construct the object field access. 5635 // Construct the object field access.
5608 access_ = HObjectAccess::ForField(map, &lookup_, name_); 5636 access_ = HObjectAccess::ForField(map, &lookup_, name_);
5609 5637
5610 // Load field map for heap objects. 5638 // Load field map for heap objects.
5611 LoadFieldMap(transition()); 5639 LoadFieldMaps(transition());
5612 return true; 5640 return true;
5613 } 5641 }
5614 return false; 5642 return false;
5615 } 5643 }
5616 5644
5617 5645
5618 bool HOptimizedGraphBuilder::PropertyAccessInfo::CanAccessAsMonomorphic( 5646 bool HOptimizedGraphBuilder::PropertyAccessInfo::CanAccessAsMonomorphic(
5619 SmallMapList* types) { 5647 SmallMapList* types) {
5620 ASSERT(type_->Is(ToType(types->first()))); 5648 ASSERT(type_->Is(ToType(types->first())));
5621 if (!CanAccessMonomorphic()) return false; 5649 if (!CanAccessMonomorphic()) return false;
(...skipping 5983 matching lines...) Expand 10 before | Expand all | Expand 10 after
11605 if (ShouldProduceTraceOutput()) { 11633 if (ShouldProduceTraceOutput()) {
11606 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 11634 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
11607 } 11635 }
11608 11636
11609 #ifdef DEBUG 11637 #ifdef DEBUG
11610 graph_->Verify(false); // No full verify. 11638 graph_->Verify(false); // No full verify.
11611 #endif 11639 #endif
11612 } 11640 }
11613 11641
11614 } } // namespace v8::internal 11642 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-check-elimination.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698