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

Side by Side Diff: src/hydrogen.cc

Issue 14966005: Fix polymorphic to monomorphic load to take representation into account. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 7 years, 7 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/property-details.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 7113 matching lines...) Expand 10 before | Expand all | Expand 10 after
7124 instr->set_position(expr->position()); 7124 instr->set_position(expr->position());
7125 ast_context()->ReturnInstruction(instr, expr->id()); 7125 ast_context()->ReturnInstruction(instr, expr->id());
7126 return true; 7126 return true;
7127 } 7127 }
7128 7128
7129 7129
7130 void HOptimizedGraphBuilder::HandlePolymorphicLoadNamedField(Property* expr, 7130 void HOptimizedGraphBuilder::HandlePolymorphicLoadNamedField(Property* expr,
7131 HValue* object, 7131 HValue* object,
7132 SmallMapList* types, 7132 SmallMapList* types,
7133 Handle<String> name) { 7133 Handle<String> name) {
7134 int count = 0;
7135 int previous_field_offset = 0;
7136 bool previous_field_is_in_object = false;
7137 bool is_monomorphic_field = true;
7138 7134
7139 if (HandlePolymorphicArrayLengthLoad(expr, object, types, name)) 7135 if (HandlePolymorphicArrayLengthLoad(expr, object, types, name))
7140 return; 7136 return;
7141 7137
7142 Handle<Map> map; 7138 AddInstruction(new(zone()) HCheckNonSmi(object));
7143 LookupResult lookup(isolate()); 7139
7144 for (int i = 0; i < types->length() && count < kMaxLoadPolymorphism; ++i) { 7140 // Use monomorphic load if property lookup results in the same field index
7145 map = types->at(i); 7141 // for all maps. Requires special map check on the set of all handled maps.
7146 if (ComputeLoadStoreField(map, name, &lookup, false)) { 7142 HInstruction* instr = NULL;
7143 if (types->length() > 0 && types->length() <= kMaxLoadPolymorphism) {
7144 LookupResult lookup(isolate());
7145 int previous_field_offset = 0;
7146 bool previous_field_is_in_object = false;
7147 Representation representation = Representation::None();
7148 int count;
7149 for (count = 0; count < types->length(); ++count) {
7150 Handle<Map> map = types->at(count);
7151 if (!ComputeLoadStoreField(map, name, &lookup, false)) break;
7152
7147 int index = ComputeLoadStoreFieldIndex(map, &lookup); 7153 int index = ComputeLoadStoreFieldIndex(map, &lookup);
7154 Representation new_representation =
7155 ComputeLoadStoreRepresentation(map, &lookup);
7148 bool is_in_object = index < 0; 7156 bool is_in_object = index < 0;
7149 int offset = index * kPointerSize; 7157 int offset = index * kPointerSize;
7158
7150 if (index < 0) { 7159 if (index < 0) {
7151 // Negative property indices are in-object properties, indexed 7160 // Negative property indices are in-object properties, indexed
7152 // from the end of the fixed part of the object. 7161 // from the end of the fixed part of the object.
7153 offset += map->instance_size(); 7162 offset += map->instance_size();
7154 } else { 7163 } else {
7155 offset += FixedArray::kHeaderSize; 7164 offset += FixedArray::kHeaderSize;
7156 } 7165 }
7166
7157 if (count == 0) { 7167 if (count == 0) {
7158 previous_field_offset = offset; 7168 previous_field_offset = offset;
7159 previous_field_is_in_object = is_in_object; 7169 previous_field_is_in_object = is_in_object;
7160 } else if (is_monomorphic_field) { 7170 representation = new_representation;
7161 is_monomorphic_field = (offset == previous_field_offset) && 7171 } else if (offset != previous_field_offset ||
7162 (is_in_object == previous_field_is_in_object); 7172 is_in_object != previous_field_is_in_object ||
7173 (FLAG_track_fields &&
7174 !representation.IsCompatibleForLoad(new_representation))) {
7175 break;
7163 } 7176 }
7164 ++count; 7177
7178 representation = representation.generalize(new_representation);
7179 }
7180
7181 if (count == types->length()) {
7182 AddInstruction(HCheckMaps::New(object, types, zone()));
7183 instr = DoBuildLoadNamedField(
7184 object, previous_field_is_in_object,
7185 representation, previous_field_offset);
7165 } 7186 }
7166 } 7187 }
7167 7188
7168 // Use monomorphic load if property lookup results in the same field index 7189 if (instr == NULL) {
7169 // for all maps. Requires special map check on the set of all handled maps.
7170 AddInstruction(new(zone()) HCheckNonSmi(object));
7171 HInstruction* instr;
7172 if (count == types->length() && is_monomorphic_field) {
7173 AddInstruction(HCheckMaps::New(object, types, zone()));
7174 instr = BuildLoadNamedField(object, map, &lookup);
7175 } else {
7176 HValue* context = environment()->LookupContext(); 7190 HValue* context = environment()->LookupContext();
7177 instr = new(zone()) HLoadNamedFieldPolymorphic(context, 7191 instr = new(zone()) HLoadNamedFieldPolymorphic(
7178 object, 7192 context, object, types, name, zone());
7179 types,
7180 name,
7181 zone());
7182 } 7193 }
7183 7194
7184 instr->set_position(expr->position()); 7195 instr->set_position(expr->position());
7185 return ast_context()->ReturnInstruction(instr, expr->id()); 7196 return ast_context()->ReturnInstruction(instr, expr->id());
7186 } 7197 }
7187 7198
7188 7199
7189 void HOptimizedGraphBuilder::HandlePolymorphicStoreNamedField( 7200 void HOptimizedGraphBuilder::HandlePolymorphicStoreNamedField(
7190 Assignment* expr, 7201 Assignment* expr,
7191 HValue* object, 7202 HValue* object,
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
7728 AddSimulate(expr->id()); 7739 AddSimulate(expr->id());
7729 current_block()->FinishExit(new(zone()) HAbnormalExit); 7740 current_block()->FinishExit(new(zone()) HAbnormalExit);
7730 set_current_block(NULL); 7741 set_current_block(NULL);
7731 } 7742 }
7732 7743
7733 7744
7734 HLoadNamedField* HOptimizedGraphBuilder::BuildLoadNamedField( 7745 HLoadNamedField* HOptimizedGraphBuilder::BuildLoadNamedField(
7735 HValue* object, 7746 HValue* object,
7736 Handle<Map> map, 7747 Handle<Map> map,
7737 LookupResult* lookup) { 7748 LookupResult* lookup) {
7749 int index = lookup->GetLocalFieldIndexFromMap(*map);
7750 // Negative property indices are in-object properties, indexed from the end of
7751 // the fixed part of the object. Non-negative property indices are in the
7752 // properties array.
7753 int inobject = index < 0;
7738 Representation representation = lookup->representation(); 7754 Representation representation = lookup->representation();
7739 int index = lookup->GetLocalFieldIndexFromMap(*map); 7755 int offset = inobject
7740 if (index < 0) { 7756 ? index * kPointerSize + map->instance_size()
7741 // Negative property indices are in-object properties, indexed 7757 : index * kPointerSize + FixedArray::kHeaderSize;
7742 // from the end of the fixed part of the object. 7758 return DoBuildLoadNamedField(object, inobject, representation, offset);
7743 int offset = (index * kPointerSize) + map->instance_size();
7744 return new(zone()) HLoadNamedField(object, true, representation, offset);
7745 } else {
7746 // Non-negative property indices are in the properties array.
7747 int offset = (index * kPointerSize) + FixedArray::kHeaderSize;
7748 return new(zone()) HLoadNamedField(object, false, representation, offset);
7749 }
7750 } 7759 }
7751 7760
7752 7761
7762 HLoadNamedField* HGraphBuilder::DoBuildLoadNamedField(
7763 HValue* object,
7764 bool inobject,
7765 Representation representation,
7766 int offset) {
7767 return new(zone()) HLoadNamedField(object, inobject, representation, offset);
7768 }
7769
7770
7753 HInstruction* HOptimizedGraphBuilder::BuildLoadNamedGeneric( 7771 HInstruction* HOptimizedGraphBuilder::BuildLoadNamedGeneric(
7754 HValue* object, 7772 HValue* object,
7755 Handle<String> name, 7773 Handle<String> name,
7756 Property* expr) { 7774 Property* expr) {
7757 if (expr->IsUninitialized()) { 7775 if (expr->IsUninitialized()) {
7758 AddSoftDeoptimize(); 7776 AddSoftDeoptimize();
7759 } 7777 }
7760 HValue* context = environment()->LookupContext(); 7778 HValue* context = environment()->LookupContext();
7761 return new(zone()) HLoadNamedGeneric(context, object, name); 7779 return new(zone()) HLoadNamedGeneric(context, object, name);
7762 } 7780 }
(...skipping 4510 matching lines...) Expand 10 before | Expand all | Expand 10 after
12273 } 12291 }
12274 } 12292 }
12275 12293
12276 #ifdef DEBUG 12294 #ifdef DEBUG
12277 if (graph_ != NULL) graph_->Verify(false); // No full verify. 12295 if (graph_ != NULL) graph_->Verify(false); // No full verify.
12278 if (allocator_ != NULL) allocator_->Verify(); 12296 if (allocator_ != NULL) allocator_->Verify();
12279 #endif 12297 #endif
12280 } 12298 }
12281 12299
12282 } } // namespace v8::internal 12300 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/property-details.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698