OLD | NEW |
---|---|
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 Loading... | |
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 if (types->length() > 0 && types->length() <= kMaxLoadPolymorphism) { |
mvstanton
2013/05/07 10:17:17
I like this if check against kMaxLoadPolymorphism,
Toon Verwaest
2013/05/07 10:30:24
Done.
| |
7143 LookupResult lookup(isolate()); | |
7144 int previous_field_offset = 0; | |
7145 bool previous_field_is_in_object = false; | |
7146 Representation representation = Representation::None(); | |
7147 int count; | |
7148 for (count = 0; count < types->length(); ++count) { | |
7149 Handle<Map> map = types->at(count); | |
7150 if (!ComputeLoadStoreField(map, name, &lookup, false)) break; | |
7151 | |
7147 int index = ComputeLoadStoreFieldIndex(map, &lookup); | 7152 int index = ComputeLoadStoreFieldIndex(map, &lookup); |
7153 Representation new_representation = | |
7154 ComputeLoadStoreRepresentation(map, &lookup); | |
7148 bool is_in_object = index < 0; | 7155 bool is_in_object = index < 0; |
7149 int offset = index * kPointerSize; | 7156 int offset = index * kPointerSize; |
7157 | |
7150 if (index < 0) { | 7158 if (index < 0) { |
7151 // Negative property indices are in-object properties, indexed | 7159 // Negative property indices are in-object properties, indexed |
7152 // from the end of the fixed part of the object. | 7160 // from the end of the fixed part of the object. |
7153 offset += map->instance_size(); | 7161 offset += map->instance_size(); |
7154 } else { | 7162 } else { |
7155 offset += FixedArray::kHeaderSize; | 7163 offset += FixedArray::kHeaderSize; |
7156 } | 7164 } |
7165 | |
7157 if (count == 0) { | 7166 if (count == 0) { |
7158 previous_field_offset = offset; | 7167 previous_field_offset = offset; |
7159 previous_field_is_in_object = is_in_object; | 7168 previous_field_is_in_object = is_in_object; |
7160 } else if (is_monomorphic_field) { | 7169 representation = new_representation; |
7161 is_monomorphic_field = (offset == previous_field_offset) && | 7170 } else if (offset != previous_field_offset || |
7162 (is_in_object == previous_field_is_in_object); | 7171 is_in_object != previous_field_is_in_object || |
7172 (FLAG_track_fields && | |
7173 !representation.IsCompatibleForLoad(new_representation))) { | |
7174 break; | |
7163 } | 7175 } |
7164 ++count; | 7176 |
7177 representation = representation.generalize(new_representation); | |
7178 } | |
7179 | |
7180 if (count == types->length()) { | |
7181 AddInstruction(HCheckMaps::New(object, types, zone())); | |
7182 HInstruction* instr = DoBuildLoadNamedField( | |
7183 object, previous_field_is_in_object, | |
7184 representation, previous_field_offset); | |
7185 instr->set_position(expr->position()); | |
mvstanton
2013/05/07 10:17:17
the instr->set_position() line and ast_context() l
Toon Verwaest
2013/05/07 10:30:24
Done.
| |
7186 return ast_context()->ReturnInstruction(instr, expr->id()); | |
7165 } | 7187 } |
7166 } | 7188 } |
7167 | 7189 |
7168 // Use monomorphic load if property lookup results in the same field index | 7190 HValue* context = environment()->LookupContext(); |
7169 // for all maps. Requires special map check on the set of all handled maps. | 7191 HInstruction* instr = new(zone()) HLoadNamedFieldPolymorphic( |
7170 AddInstruction(new(zone()) HCheckNonSmi(object)); | 7192 context, object, types, name, zone()); |
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(); | |
7177 instr = new(zone()) HLoadNamedFieldPolymorphic(context, | |
7178 object, | |
7179 types, | |
7180 name, | |
7181 zone()); | |
7182 } | |
7183 | |
7184 instr->set_position(expr->position()); | 7193 instr->set_position(expr->position()); |
7185 return ast_context()->ReturnInstruction(instr, expr->id()); | 7194 return ast_context()->ReturnInstruction(instr, expr->id()); |
7186 } | 7195 } |
7187 | 7196 |
7188 | 7197 |
7189 void HOptimizedGraphBuilder::HandlePolymorphicStoreNamedField( | 7198 void HOptimizedGraphBuilder::HandlePolymorphicStoreNamedField( |
7190 Assignment* expr, | 7199 Assignment* expr, |
7191 HValue* object, | 7200 HValue* object, |
7192 HValue* value, | 7201 HValue* value, |
7193 SmallMapList* types, | 7202 SmallMapList* types, |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7728 AddSimulate(expr->id()); | 7737 AddSimulate(expr->id()); |
7729 current_block()->FinishExit(new(zone()) HAbnormalExit); | 7738 current_block()->FinishExit(new(zone()) HAbnormalExit); |
7730 set_current_block(NULL); | 7739 set_current_block(NULL); |
7731 } | 7740 } |
7732 | 7741 |
7733 | 7742 |
7734 HLoadNamedField* HOptimizedGraphBuilder::BuildLoadNamedField( | 7743 HLoadNamedField* HOptimizedGraphBuilder::BuildLoadNamedField( |
7735 HValue* object, | 7744 HValue* object, |
7736 Handle<Map> map, | 7745 Handle<Map> map, |
7737 LookupResult* lookup) { | 7746 LookupResult* lookup) { |
7747 int index = lookup->GetLocalFieldIndexFromMap(*map); | |
7748 // Negative property indices are in-object properties, indexed from the end of | |
7749 // the fixed part of the object. Non-negative property indices are in the | |
7750 // properties array. | |
7751 int inobject = index < 0; | |
7738 Representation representation = lookup->representation(); | 7752 Representation representation = lookup->representation(); |
7739 int index = lookup->GetLocalFieldIndexFromMap(*map); | 7753 int offset = inobject |
7740 if (index < 0) { | 7754 ? index * kPointerSize + map->instance_size() |
7741 // Negative property indices are in-object properties, indexed | 7755 : index * kPointerSize + FixedArray::kHeaderSize; |
7742 // from the end of the fixed part of the object. | 7756 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 } | 7757 } |
7751 | 7758 |
7752 | 7759 |
7760 HLoadNamedField* HGraphBuilder::DoBuildLoadNamedField( | |
7761 HValue* object, | |
7762 bool inobject, | |
7763 Representation representation, | |
7764 int offset) { | |
7765 return new(zone()) HLoadNamedField(object, inobject, representation, offset); | |
7766 } | |
7767 | |
7768 | |
7753 HInstruction* HOptimizedGraphBuilder::BuildLoadNamedGeneric( | 7769 HInstruction* HOptimizedGraphBuilder::BuildLoadNamedGeneric( |
7754 HValue* object, | 7770 HValue* object, |
7755 Handle<String> name, | 7771 Handle<String> name, |
7756 Property* expr) { | 7772 Property* expr) { |
7757 if (expr->IsUninitialized()) { | 7773 if (expr->IsUninitialized()) { |
7758 AddSoftDeoptimize(); | 7774 AddSoftDeoptimize(); |
7759 } | 7775 } |
7760 HValue* context = environment()->LookupContext(); | 7776 HValue* context = environment()->LookupContext(); |
7761 return new(zone()) HLoadNamedGeneric(context, object, name); | 7777 return new(zone()) HLoadNamedGeneric(context, object, name); |
7762 } | 7778 } |
(...skipping 4510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12273 } | 12289 } |
12274 } | 12290 } |
12275 | 12291 |
12276 #ifdef DEBUG | 12292 #ifdef DEBUG |
12277 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 12293 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
12278 if (allocator_ != NULL) allocator_->Verify(); | 12294 if (allocator_ != NULL) allocator_->Verify(); |
12279 #endif | 12295 #endif |
12280 } | 12296 } |
12281 | 12297 |
12282 } } // namespace v8::internal | 12298 } } // namespace v8::internal |
OLD | NEW |