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

Side by Side Diff: src/hydrogen.cc

Issue 18503006: Move representation into HObjectAccess and remove from HLoadNamedField and HStoreNamedField. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 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-instructions.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 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 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 capacity_checker.Else(); 1085 capacity_checker.Else();
1086 1086
1087 environment()->Push(elements); 1087 environment()->Push(elements);
1088 capacity_checker.End(); 1088 capacity_checker.End();
1089 1089
1090 if (is_js_array) { 1090 if (is_js_array) {
1091 HValue* new_length = AddInstruction( 1091 HValue* new_length = AddInstruction(
1092 HAdd::New(zone, context, key, graph_->GetConstant1())); 1092 HAdd::New(zone, context, key, graph_->GetConstant1()));
1093 new_length->ClearFlag(HValue::kCanOverflow); 1093 new_length->ClearFlag(HValue::kCanOverflow);
1094 1094
1095 Representation representation = IsFastElementsKind(kind) 1095 AddStore(object, HObjectAccess::ForArrayLength(IsFastElementsKind(kind)),
danno 2013/07/23 16:15:43 Here just pass 'kind'
1096 ? Representation::Smi() : Representation::Tagged(); 1096 new_length);
1097 AddStore(object, HObjectAccess::ForArrayLength(), new_length,
1098 representation);
1099 } 1097 }
1100 1098
1101 length_checker.Else(); 1099 length_checker.Else();
1102 Add<HBoundsCheck>(key, length); 1100 Add<HBoundsCheck>(key, length);
1103 1101
1104 environment()->Push(elements); 1102 environment()->Push(elements);
1105 length_checker.End(); 1103 length_checker.End();
1106 1104
1107 return environment()->Pop(); 1105 return environment()->Pop();
1108 } 1106 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 1154
1157 IfBuilder if_builder(this); 1155 IfBuilder if_builder(this);
1158 1156
1159 if_builder.IfNot<HCompareObjectEqAndBranch>(elements, empty_fixed_array); 1157 if_builder.IfNot<HCompareObjectEqAndBranch>(elements, empty_fixed_array);
1160 1158
1161 if_builder.Then(); 1159 if_builder.Then();
1162 1160
1163 HInstruction* elements_length = AddLoadFixedArrayLength(elements); 1161 HInstruction* elements_length = AddLoadFixedArrayLength(elements);
1164 1162
1165 HInstruction* array_length = is_jsarray 1163 HInstruction* array_length = is_jsarray
1166 ? AddLoad(object, HObjectAccess::ForArrayLength(), 1164 ? AddLoad(object, HObjectAccess::ForArrayLength(true), NULL)
danno 2013/07/23 16:15:43 Here just pass from_kind
1167 NULL, Representation::Smi())
1168 : elements_length; 1165 : elements_length;
1169 array_length->set_type(HType::Smi());
1170 1166
1171 BuildGrowElementsCapacity(object, elements, from_kind, to_kind, 1167 BuildGrowElementsCapacity(object, elements, from_kind, to_kind,
1172 array_length, elements_length); 1168 array_length, elements_length);
1173 1169
1174 if_builder.End(); 1170 if_builder.End();
1175 } 1171 }
1176 1172
1177 AddStore(object, HObjectAccess::ForMap(), map); 1173 AddStore(object, HObjectAccess::ForMap(), map);
1178 } 1174 }
1179 1175
(...skipping 27 matching lines...) Expand all
1207 HValue* elements = AddLoadElements(object, mapcheck); 1203 HValue* elements = AddLoadElements(object, mapcheck);
1208 if (is_store && (fast_elements || fast_smi_only_elements) && 1204 if (is_store && (fast_elements || fast_smi_only_elements) &&
1209 store_mode != STORE_NO_TRANSITION_HANDLE_COW) { 1205 store_mode != STORE_NO_TRANSITION_HANDLE_COW) {
1210 HCheckMaps* check_cow_map = HCheckMaps::New( 1206 HCheckMaps* check_cow_map = HCheckMaps::New(
1211 elements, isolate()->factory()->fixed_array_map(), zone, top_info()); 1207 elements, isolate()->factory()->fixed_array_map(), zone, top_info());
1212 check_cow_map->ClearGVNFlag(kDependsOnElementsKind); 1208 check_cow_map->ClearGVNFlag(kDependsOnElementsKind);
1213 AddInstruction(check_cow_map); 1209 AddInstruction(check_cow_map);
1214 } 1210 }
1215 HInstruction* length = NULL; 1211 HInstruction* length = NULL;
1216 if (is_js_array) { 1212 if (is_js_array) {
1217 length = AddLoad(object, HObjectAccess::ForArrayLength(), mapcheck, 1213 length = AddLoad(object, HObjectAccess::ForArrayLength(true), mapcheck);
1218 Representation::Smi());
1219 } else { 1214 } else {
1220 length = AddLoadFixedArrayLength(elements); 1215 length = AddLoadFixedArrayLength(elements);
1221 } 1216 }
1222 length->set_type(HType::Smi()); 1217 length->set_type(HType::Smi());
1223 HValue* checked_key = NULL; 1218 HValue* checked_key = NULL;
1224 if (IsExternalArrayElementsKind(elements_kind)) { 1219 if (IsExternalArrayElementsKind(elements_kind)) {
1225 if (store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS) { 1220 if (store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS) {
1226 NoObservableSideEffectsScope no_effects(this); 1221 NoObservableSideEffectsScope no_effects(this);
1227 HLoadExternalArrayPointer* external_elements = 1222 HLoadExternalArrayPointer* external_elements =
1228 Add<HLoadExternalArrayPointer>(elements); 1223 Add<HLoadExternalArrayPointer>(elements);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 1319
1325 void HGraphBuilder::BuildInitializeElementsHeader(HValue* elements, 1320 void HGraphBuilder::BuildInitializeElementsHeader(HValue* elements,
1326 ElementsKind kind, 1321 ElementsKind kind,
1327 HValue* capacity) { 1322 HValue* capacity) {
1328 Factory* factory = isolate()->factory(); 1323 Factory* factory = isolate()->factory();
1329 Handle<Map> map = IsFastDoubleElementsKind(kind) 1324 Handle<Map> map = IsFastDoubleElementsKind(kind)
1330 ? factory->fixed_double_array_map() 1325 ? factory->fixed_double_array_map()
1331 : factory->fixed_array_map(); 1326 : factory->fixed_array_map();
1332 1327
1333 AddStoreMapConstant(elements, map); 1328 AddStoreMapConstant(elements, map);
1334 Representation representation = IsFastElementsKind(kind) 1329 AddStore(elements, HObjectAccess::ForFixedArrayLength(), capacity);
1335 ? Representation::Smi() : Representation::Tagged();
1336 AddStore(elements, HObjectAccess::ForFixedArrayLength(), capacity,
1337 representation);
1338 } 1330 }
1339 1331
1340 1332
1341 HValue* HGraphBuilder::BuildAllocateElementsAndInitializeElementsHeader( 1333 HValue* HGraphBuilder::BuildAllocateElementsAndInitializeElementsHeader(
1342 HValue* context, 1334 HValue* context,
1343 ElementsKind kind, 1335 ElementsKind kind,
1344 HValue* capacity) { 1336 HValue* capacity) {
1345 HValue* new_elements = BuildAllocateElements(context, kind, capacity); 1337 HValue* new_elements = BuildAllocateElements(context, kind, capacity);
1346 BuildInitializeElementsHeader(new_elements, kind, capacity); 1338 BuildInitializeElementsHeader(new_elements, kind, capacity);
1347 return new_elements; 1339 return new_elements;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 } 1453 }
1462 1454
1463 1455
1464 HLoadNamedField* HGraphBuilder::AddLoadElements(HValue* object, 1456 HLoadNamedField* HGraphBuilder::AddLoadElements(HValue* object,
1465 HValue* typecheck) { 1457 HValue* typecheck) {
1466 return AddLoad(object, HObjectAccess::ForElementsPointer(), typecheck); 1458 return AddLoad(object, HObjectAccess::ForElementsPointer(), typecheck);
1467 } 1459 }
1468 1460
1469 1461
1470 HLoadNamedField* HGraphBuilder::AddLoadFixedArrayLength(HValue* object) { 1462 HLoadNamedField* HGraphBuilder::AddLoadFixedArrayLength(HValue* object) {
1471 HLoadNamedField* instr = AddLoad(object, HObjectAccess::ForFixedArrayLength(), 1463 return AddLoad(object, HObjectAccess::ForFixedArrayLength());
1472 NULL, Representation::Smi());
1473 instr->set_type(HType::Smi());
1474 return instr;
1475 } 1464 }
1476 1465
1477 1466
1478 HValue* HGraphBuilder::BuildNewElementsCapacity(HValue* context, 1467 HValue* HGraphBuilder::BuildNewElementsCapacity(HValue* context,
1479 HValue* old_capacity) { 1468 HValue* old_capacity) {
1480 Zone* zone = this->zone(); 1469 Zone* zone = this->zone();
1481 HValue* half_old_capacity = 1470 HValue* half_old_capacity =
1482 AddInstruction(HShr::New(zone, context, old_capacity, 1471 AddInstruction(HShr::New(zone, context, old_capacity,
1483 graph_->GetConstant1())); 1472 graph_->GetConstant1()));
1484 half_old_capacity->ClearFlag(HValue::kCanOverflow); 1473 half_old_capacity->ClearFlag(HValue::kCanOverflow);
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1835 allocation_site_payload_(NULL), 1824 allocation_site_payload_(NULL),
1836 constructor_function_(constructor_function) { 1825 constructor_function_(constructor_function) {
1837 } 1826 }
1838 1827
1839 1828
1840 HValue* HGraphBuilder::JSArrayBuilder::EmitMapCode(HValue* context) { 1829 HValue* HGraphBuilder::JSArrayBuilder::EmitMapCode(HValue* context) {
1841 if (kind_ == GetInitialFastElementsKind()) { 1830 if (kind_ == GetInitialFastElementsKind()) {
1842 // No need for a context lookup if the kind_ matches the initial 1831 // No need for a context lookup if the kind_ matches the initial
1843 // map, because we can just load the map in that case. 1832 // map, because we can just load the map in that case.
1844 HObjectAccess access = HObjectAccess::ForPrototypeOrInitialMap(); 1833 HObjectAccess access = HObjectAccess::ForPrototypeOrInitialMap();
1845 HInstruction* load = 1834 return builder()->AddInstruction(
1846 builder()->BuildLoadNamedField(constructor_function_, 1835 builder()->BuildLoadNamedField(constructor_function_, access));
1847 access,
1848 Representation::Tagged());
1849 return builder()->AddInstruction(load);
1850 } 1836 }
1851 1837
1852 HInstruction* native_context = builder()->BuildGetNativeContext(context); 1838 HInstruction* native_context = builder()->BuildGetNativeContext(context);
1853 HInstruction* index = builder()->Add<HConstant>( 1839 HInstruction* index = builder()->Add<HConstant>(
1854 static_cast<int32_t>(Context::JS_ARRAY_MAPS_INDEX)); 1840 static_cast<int32_t>(Context::JS_ARRAY_MAPS_INDEX));
1855 1841
1856 HInstruction* map_array = builder()->Add<HLoadKeyed>( 1842 HInstruction* map_array = builder()->Add<HLoadKeyed>(
1857 native_context, index, static_cast<HValue*>(NULL), FAST_ELEMENTS); 1843 native_context, index, static_cast<HValue*>(NULL), FAST_ELEMENTS);
1858 1844
1859 HInstruction* kind_index = builder()->Add<HConstant>(kind_); 1845 HInstruction* kind_index = builder()->Add<HConstant>(kind_);
1860 1846
1861 return builder()->Add<HLoadKeyed>( 1847 return builder()->Add<HLoadKeyed>(
1862 map_array, kind_index, static_cast<HValue*>(NULL), FAST_ELEMENTS); 1848 map_array, kind_index, static_cast<HValue*>(NULL), FAST_ELEMENTS);
1863 } 1849 }
1864 1850
1865 1851
1866 HValue* HGraphBuilder::JSArrayBuilder::EmitInternalMapCode() { 1852 HValue* HGraphBuilder::JSArrayBuilder::EmitInternalMapCode() {
1867 // Find the map near the constructor function 1853 // Find the map near the constructor function
1868 HObjectAccess access = HObjectAccess::ForPrototypeOrInitialMap(); 1854 HObjectAccess access = HObjectAccess::ForPrototypeOrInitialMap();
1869 return builder()->AddInstruction( 1855 return builder()->AddInstruction(
1870 builder()->BuildLoadNamedField(constructor_function_, 1856 builder()->BuildLoadNamedField(constructor_function_, access));
1871 access,
1872 Representation::Tagged()));
1873 } 1857 }
1874 1858
1875 1859
1876 HValue* HGraphBuilder::JSArrayBuilder::EstablishAllocationSize( 1860 HValue* HGraphBuilder::JSArrayBuilder::EstablishAllocationSize(
1877 HValue* length_node) { 1861 HValue* length_node) {
1878 HValue* context = builder()->environment()->LookupContext(); 1862 HValue* context = builder()->environment()->LookupContext();
1879 ASSERT(length_node != NULL); 1863 ASSERT(length_node != NULL);
1880 1864
1881 int base_size = JSArray::kSize; 1865 int base_size = JSArray::kSize;
1882 if (mode_ == TRACK_ALLOCATION_SITE) { 1866 if (mode_ == TRACK_ALLOCATION_SITE) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 builder()->BuildFillElementsWithHole(context, elements_location_, kind_, 1951 builder()->BuildFillElementsWithHole(context, elements_location_, kind_,
1968 graph()->GetConstant0(), capacity); 1952 graph()->GetConstant0(), capacity);
1969 } 1953 }
1970 1954
1971 return new_object; 1955 return new_object;
1972 } 1956 }
1973 1957
1974 1958
1975 HStoreNamedField* HGraphBuilder::AddStore(HValue *object, 1959 HStoreNamedField* HGraphBuilder::AddStore(HValue *object,
1976 HObjectAccess access, 1960 HObjectAccess access,
1977 HValue *val, 1961 HValue *val) {
1978 Representation representation) { 1962 return Add<HStoreNamedField>(object, access, val);
1979 return Add<HStoreNamedField>(object, access, val, representation);
1980 } 1963 }
1981 1964
1982 1965
1983 HLoadNamedField* HGraphBuilder::AddLoad(HValue *object, 1966 HLoadNamedField* HGraphBuilder::AddLoad(HValue *object,
1984 HObjectAccess access, 1967 HObjectAccess access,
1985 HValue *typecheck, 1968 HValue *typecheck) {
1986 Representation representation) { 1969 return Add<HLoadNamedField>(object, access, typecheck);
1987 return Add<HLoadNamedField>(object, access, typecheck, representation);
1988 } 1970 }
1989 1971
1990 1972
1991 HStoreNamedField* HGraphBuilder::AddStoreMapConstant(HValue *object, 1973 HStoreNamedField* HGraphBuilder::AddStoreMapConstant(HValue *object,
1992 Handle<Map> map) { 1974 Handle<Map> map) {
1993 return Add<HStoreNamedField>(object, HObjectAccess::ForMap(), 1975 return Add<HStoreNamedField>(object, HObjectAccess::ForMap(),
1994 Add<HConstant>(map)); 1976 Add<HConstant>(map));
1995 } 1977 }
1996 1978
1997 1979
(...skipping 2521 matching lines...) Expand 10 before | Expand all | Expand 10 after
4519 if (!is_store) return false; 4501 if (!is_store) return false;
4520 4502
4521 // 2nd chance: A store into a non-existent field can still be inlined if we 4503 // 2nd chance: A store into a non-existent field can still be inlined if we
4522 // have a matching transition and some room left in the object. 4504 // have a matching transition and some room left in the object.
4523 type->LookupTransition(NULL, *name, lookup); 4505 type->LookupTransition(NULL, *name, lookup);
4524 return lookup->IsTransitionToField(*type) && 4506 return lookup->IsTransitionToField(*type) &&
4525 (type->unused_property_fields() > 0); 4507 (type->unused_property_fields() > 0);
4526 } 4508 }
4527 4509
4528 4510
4529 static Representation ComputeLoadStoreRepresentation(Handle<Map> type,
4530 LookupResult* lookup) {
4531 if (lookup->IsField()) {
4532 return lookup->representation();
4533 } else {
4534 Map* transition = lookup->GetTransitionMapFromMap(*type);
4535 int descriptor = transition->LastAdded();
4536 PropertyDetails details =
4537 transition->instance_descriptors()->GetDetails(descriptor);
4538 return details.representation();
4539 }
4540 }
4541
4542
4543 void HOptimizedGraphBuilder::AddCheckMap(HValue* object, Handle<Map> map) { 4511 void HOptimizedGraphBuilder::AddCheckMap(HValue* object, Handle<Map> map) {
4544 BuildCheckHeapObject(object); 4512 BuildCheckHeapObject(object);
4545 AddInstruction(HCheckMaps::New(object, map, zone(), top_info())); 4513 AddInstruction(HCheckMaps::New(object, map, zone(), top_info()));
4546 } 4514 }
4547 4515
4548 4516
4549 void HOptimizedGraphBuilder::AddCheckMapsWithTransitions(HValue* object, 4517 void HOptimizedGraphBuilder::AddCheckMapsWithTransitions(HValue* object,
4550 Handle<Map> map) { 4518 Handle<Map> map) {
4551 BuildCheckHeapObject(object); 4519 BuildCheckHeapObject(object);
4552 AddInstruction(HCheckMaps::NewWithTransitions( 4520 AddInstruction(HCheckMaps::NewWithTransitions(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4584 } 4552 }
4585 ASSERT(proto->GetPrototype(isolate())->IsNull()); 4553 ASSERT(proto->GetPrototype(isolate())->IsNull());
4586 } 4554 }
4587 ASSERT(proto->IsJSObject()); 4555 ASSERT(proto->IsJSObject());
4588 Add<HCheckPrototypeMaps>(Handle<JSObject>(JSObject::cast(map->prototype())), 4556 Add<HCheckPrototypeMaps>(Handle<JSObject>(JSObject::cast(map->prototype())),
4589 Handle<JSObject>(JSObject::cast(proto)), 4557 Handle<JSObject>(JSObject::cast(proto)),
4590 zone(), top_info()); 4558 zone(), top_info());
4591 } 4559 }
4592 4560
4593 HObjectAccess field_access = HObjectAccess::ForField(map, lookup, name); 4561 HObjectAccess field_access = HObjectAccess::ForField(map, lookup, name);
4594 Representation representation = ComputeLoadStoreRepresentation(map, lookup);
4595 bool transition_to_field = lookup->IsTransitionToField(*map); 4562 bool transition_to_field = lookup->IsTransitionToField(*map);
4596 4563
4597 HStoreNamedField *instr; 4564 HStoreNamedField *instr;
4598 if (FLAG_track_double_fields && representation.IsDouble()) { 4565 if (FLAG_track_double_fields && field_access.representation().IsDouble()) {
4566 HObjectAccess heap_number_access =
4567 field_access.WithRepresentation(Representation::Tagged());
4599 if (transition_to_field) { 4568 if (transition_to_field) {
4600 // The store requires a mutable HeapNumber to be allocated. 4569 // The store requires a mutable HeapNumber to be allocated.
4601 NoObservableSideEffectsScope no_side_effects(this); 4570 NoObservableSideEffectsScope no_side_effects(this);
4602 HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize); 4571 HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize);
4603 HInstruction* double_box = Add<HAllocate>( 4572 HInstruction* heap_number = Add<HAllocate>(
4604 environment()->LookupContext(), heap_number_size, 4573 environment()->LookupContext(), heap_number_size,
4605 HType::HeapNumber(), HAllocate::CAN_ALLOCATE_IN_NEW_SPACE); 4574 HType::HeapNumber(), HAllocate::CAN_ALLOCATE_IN_NEW_SPACE);
4606 AddStoreMapConstant(double_box, isolate()->factory()->heap_number_map()); 4575 AddStoreMapConstant(heap_number, isolate()->factory()->heap_number_map());
4607 AddStore(double_box, HObjectAccess::ForHeapNumberValue(), 4576 AddStore(heap_number, HObjectAccess::ForHeapNumberValue(), value);
4608 value, Representation::Double()); 4577 instr = new(zone()) HStoreNamedField(
4609 instr = new(zone()) HStoreNamedField(object, field_access, double_box); 4578 object, heap_number_access, heap_number);
4610 } else { 4579 } else {
4611 // Already holds a HeapNumber; load the box and write its value field. 4580 // Already holds a HeapNumber; load the box and write its value field.
4612 HInstruction* double_box = AddLoad(object, field_access); 4581 HInstruction* heap_number = AddLoad(object, heap_number_access);
4613 double_box->set_type(HType::HeapNumber()); 4582 heap_number->set_type(HType::HeapNumber());
4614 instr = new(zone()) HStoreNamedField(double_box, 4583 instr = new(zone()) HStoreNamedField(heap_number,
4615 HObjectAccess::ForHeapNumberValue(), value, Representation::Double()); 4584 HObjectAccess::ForHeapNumberValue(), value);
4616 } 4585 }
4617 } else { 4586 } else {
4618 // This is a non-double store. 4587 // This is a normal store.
4619 instr = new(zone()) HStoreNamedField( 4588 instr = new(zone()) HStoreNamedField(object, field_access, value);
4620 object, field_access, value, representation);
4621 } 4589 }
4622 4590
4623 if (transition_to_field) { 4591 if (transition_to_field) {
4624 Handle<Map> transition(lookup->GetTransitionMapFromMap(*map)); 4592 Handle<Map> transition(lookup->GetTransitionMapFromMap(*map));
4625 instr->SetTransition(transition, top_info()); 4593 instr->SetTransition(transition, top_info());
4626 // TODO(fschneider): Record the new map type of the object in the IR to 4594 // TODO(fschneider): Record the new map type of the object in the IR to
4627 // enable elimination of redundant checks after the transition store. 4595 // enable elimination of redundant checks after the transition store.
4628 instr->SetGVNFlag(kChangesMaps); 4596 instr->SetGVNFlag(kChangesMaps);
4629 } 4597 }
4630 return instr; 4598 return instr;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4677 Property* expr, 4645 Property* expr,
4678 HValue* object, 4646 HValue* object,
4679 SmallMapList* types, 4647 SmallMapList* types,
4680 Handle<String> name) { 4648 Handle<String> name) {
4681 // Use monomorphic load if property lookup results in the same field index 4649 // Use monomorphic load if property lookup results in the same field index
4682 // for all maps. Requires special map check on the set of all handled maps. 4650 // for all maps. Requires special map check on the set of all handled maps.
4683 if (types->length() > kMaxLoadPolymorphism) return NULL; 4651 if (types->length() > kMaxLoadPolymorphism) return NULL;
4684 4652
4685 LookupResult lookup(isolate()); 4653 LookupResult lookup(isolate());
4686 int count; 4654 int count;
4687 Representation representation = Representation::None();
4688 HObjectAccess access = HObjectAccess::ForMap(); // initial value unused. 4655 HObjectAccess access = HObjectAccess::ForMap(); // initial value unused.
4689 for (count = 0; count < types->length(); ++count) { 4656 for (count = 0; count < types->length(); ++count) {
4690 Handle<Map> map = types->at(count); 4657 Handle<Map> map = types->at(count);
4691 if (!ComputeLoadStoreField(map, name, &lookup, false)) break; 4658 if (!ComputeLoadStoreField(map, name, &lookup, false)) break;
4692 4659
4693 HObjectAccess new_access = HObjectAccess::ForField(map, &lookup, name); 4660 HObjectAccess new_access = HObjectAccess::ForField(map, &lookup, name);
4694 Representation new_representation =
4695 ComputeLoadStoreRepresentation(map, &lookup);
4696 4661
4697 if (count == 0) { 4662 if (count == 0) {
4698 // First time through the loop; set access and representation. 4663 // First time through the loop; set access and representation.
4699 access = new_access; 4664 access = new_access;
4700 } else if (!representation.IsCompatibleForLoad(new_representation)) { 4665 } else if (!access.representation().IsCompatibleForLoad(
4666 new_access.representation())) {
4701 // Representations did not match. 4667 // Representations did not match.
4702 break; 4668 break;
4703 } else if (access.offset() != new_access.offset()) { 4669 } else if (access.offset() != new_access.offset()) {
4704 // Offsets did not match. 4670 // Offsets did not match.
4705 break; 4671 break;
4706 } else if (access.IsInobject() != new_access.IsInobject()) { 4672 } else if (access.IsInobject() != new_access.IsInobject()) {
4707 // In-objectness did not match. 4673 // In-objectness did not match.
4708 break; 4674 break;
4709 } 4675 }
4710 representation = representation.generalize(new_representation); 4676 access = access.WithRepresentation(
4677 access.representation().generalize(new_access.representation()));
4711 } 4678 }
4712 4679
4713 if (count == types->length()) { 4680 if (count == types->length()) {
4714 // Everything matched; can use monomorphic load. 4681 // Everything matched; can use monomorphic load.
4715 BuildCheckHeapObject(object); 4682 BuildCheckHeapObject(object);
4716 AddInstruction(HCheckMaps::New(object, types, zone())); 4683 AddInstruction(HCheckMaps::New(object, types, zone()));
4717 return BuildLoadNamedField(object, access, representation); 4684 return BuildLoadNamedField(object, access);
4718 } 4685 }
4719 4686
4720 if (count != 0) return NULL; 4687 if (count != 0) return NULL;
4721 4688
4722 // Second chance: the property is on the prototype and all maps have the 4689 // Second chance: the property is on the prototype and all maps have the
4723 // same prototype. 4690 // same prototype.
4724 Handle<Map> map(types->at(0)); 4691 Handle<Map> map(types->at(0));
4725 if (!CanLoadPropertyFromPrototype(map, name, &lookup)) return NULL; 4692 if (!CanLoadPropertyFromPrototype(map, name, &lookup)) return NULL;
4726 4693
4727 Handle<Object> prototype(map->prototype(), isolate()); 4694 Handle<Object> prototype(map->prototype(), isolate());
4728 for (count = 1; count < types->length(); ++count) { 4695 for (count = 1; count < types->length(); ++count) {
4729 Handle<Map> test_map(types->at(count)); 4696 Handle<Map> test_map(types->at(count));
4730 if (!CanLoadPropertyFromPrototype(test_map, name, &lookup)) return NULL; 4697 if (!CanLoadPropertyFromPrototype(test_map, name, &lookup)) return NULL;
4731 if (test_map->prototype() != *prototype) return NULL; 4698 if (test_map->prototype() != *prototype) return NULL;
4732 } 4699 }
4733 4700
4734 LookupInPrototypes(map, name, &lookup); 4701 LookupInPrototypes(map, name, &lookup);
4735 if (!lookup.IsField()) return NULL; 4702 if (!lookup.IsField()) return NULL;
4736 4703
4737 BuildCheckHeapObject(object); 4704 BuildCheckHeapObject(object);
4738 AddInstruction(HCheckMaps::New(object, types, zone())); 4705 AddInstruction(HCheckMaps::New(object, types, zone()));
4706
4739 Handle<JSObject> holder(lookup.holder()); 4707 Handle<JSObject> holder(lookup.holder());
4740 Handle<Map> holder_map(holder->map()); 4708 Handle<Map> holder_map(holder->map());
4741 AddInstruction(new(zone()) HCheckPrototypeMaps( 4709 AddInstruction(new(zone()) HCheckPrototypeMaps(
4742 Handle<JSObject>::cast(prototype), holder, zone(), top_info())); 4710 Handle<JSObject>::cast(prototype), holder, zone(), top_info()));
4743 HValue* holder_value = AddInstruction(new(zone()) HConstant(holder)); 4711 HValue* holder_value = AddInstruction(new(zone()) HConstant(holder));
4744 return BuildLoadNamedField(holder_value, 4712 return BuildLoadNamedField(holder_value,
4745 HObjectAccess::ForField(holder_map, &lookup, name), 4713 HObjectAccess::ForField(holder_map, &lookup, name));
4746 ComputeLoadStoreRepresentation(map, &lookup));
4747 } 4714 }
4748 4715
4749 4716
4750 void HOptimizedGraphBuilder::HandlePolymorphicLoadNamedField( 4717 void HOptimizedGraphBuilder::HandlePolymorphicLoadNamedField(
4751 Property* expr, 4718 Property* expr,
4752 HValue* object, 4719 HValue* object,
4753 SmallMapList* types, 4720 SmallMapList* types,
4754 Handle<String> name) { 4721 Handle<String> name) {
4755 HInstruction* instr = TryLoadPolymorphicAsMonomorphic( 4722 HInstruction* instr = TryLoadPolymorphicAsMonomorphic(
4756 expr, object, types, name); 4723 expr, object, types, name);
(...skipping 28 matching lines...) Expand all
4785 int count; 4752 int count;
4786 Representation representation = Representation::None(); 4753 Representation representation = Representation::None();
4787 HObjectAccess access = HObjectAccess::ForMap(); // initial value unused. 4754 HObjectAccess access = HObjectAccess::ForMap(); // initial value unused.
4788 for (count = 0; count < types->length(); ++count) { 4755 for (count = 0; count < types->length(); ++count) {
4789 Handle<Map> map = types->at(count); 4756 Handle<Map> map = types->at(count);
4790 // Pass false to ignore transitions. 4757 // Pass false to ignore transitions.
4791 if (!ComputeLoadStoreField(map, name, &lookup, false)) break; 4758 if (!ComputeLoadStoreField(map, name, &lookup, false)) break;
4792 ASSERT(!map->is_observed()); 4759 ASSERT(!map->is_observed());
4793 4760
4794 HObjectAccess new_access = HObjectAccess::ForField(map, &lookup, name); 4761 HObjectAccess new_access = HObjectAccess::ForField(map, &lookup, name);
4795 Representation new_representation = 4762 Representation new_representation = new_access.representation();
4796 ComputeLoadStoreRepresentation(map, &lookup);
4797 4763
4798 if (count == 0) { 4764 if (count == 0) {
4799 // First time through the loop; set access and representation. 4765 // First time through the loop; set access and representation.
4800 access = new_access; 4766 access = new_access;
4801 representation = new_representation; 4767 representation = new_representation;
4802 } else if (!representation.IsCompatibleForStore(new_representation)) { 4768 } else if (!representation.IsCompatibleForStore(new_representation)) {
4803 // Representations did not match. 4769 // Representations did not match.
4804 break; 4770 break;
4805 } else if (access.offset() != new_access.offset()) { 4771 } else if (access.offset() != new_access.offset()) {
4806 // Offsets did not match. 4772 // Offsets did not match.
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
5379 HValue* context = environment()->LookupContext(); 5345 HValue* context = environment()->LookupContext();
5380 HValue* value = environment()->Pop(); 5346 HValue* value = environment()->Pop();
5381 HThrow* instr = Add<HThrow>(context, value); 5347 HThrow* instr = Add<HThrow>(context, value);
5382 instr->set_position(expr->position()); 5348 instr->set_position(expr->position());
5383 AddSimulate(expr->id()); 5349 AddSimulate(expr->id());
5384 current_block()->FinishExit(new(zone()) HAbnormalExit); 5350 current_block()->FinishExit(new(zone()) HAbnormalExit);
5385 set_current_block(NULL); 5351 set_current_block(NULL);
5386 } 5352 }
5387 5353
5388 5354
5389 HLoadNamedField* HGraphBuilder::BuildLoadNamedField( 5355 HLoadNamedField* HGraphBuilder::BuildLoadNamedField(HValue* object,
5390 HValue* object, 5356 HObjectAccess access) {
5391 HObjectAccess access, 5357 if (FLAG_track_double_fields && access.representation().IsDouble()) {
5392 Representation representation) { 5358 // load the heap number
5393 bool load_double = false; 5359 HLoadNamedField* heap_number =
5394 if (representation.IsDouble()) { 5360 AddLoad(object, access.WithRepresentation(Representation::Tagged()));
5395 representation = Representation::Tagged(); 5361 heap_number->set_type(HType::HeapNumber());
5396 load_double = FLAG_track_double_fields; 5362 // load the double value from it
5363 return new(zone()) HLoadNamedField(heap_number,
5364 HObjectAccess::ForHeapNumberValue(), NULL);
5397 } 5365 }
5398 HLoadNamedField* field = 5366 return new(zone()) HLoadNamedField(object, access, NULL);
5399 new(zone()) HLoadNamedField(object, access, NULL, representation);
5400 if (load_double) {
5401 AddInstruction(field);
5402 field->set_type(HType::HeapNumber());
5403 return new(zone()) HLoadNamedField(field,
5404 HObjectAccess::ForHeapNumberValue(), NULL, Representation::Double());
5405 }
5406 return field;
5407 } 5367 }
5408 5368
5409 5369
5410 HInstruction* HOptimizedGraphBuilder::BuildLoadNamedGeneric( 5370 HInstruction* HOptimizedGraphBuilder::BuildLoadNamedGeneric(
5411 HValue* object, 5371 HValue* object,
5412 Handle<String> name, 5372 Handle<String> name,
5413 Property* expr) { 5373 Property* expr) {
5414 if (expr->IsUninitialized()) { 5374 if (expr->IsUninitialized()) {
5415 AddSoftDeoptimize(); 5375 AddSoftDeoptimize();
5416 } 5376 }
(...skipping 19 matching lines...) Expand all
5436 Property* expr, 5396 Property* expr,
5437 Handle<Map> map) { 5397 Handle<Map> map) {
5438 // Handle a load from a known field. 5398 // Handle a load from a known field.
5439 ASSERT(!map->is_dictionary_map()); 5399 ASSERT(!map->is_dictionary_map());
5440 5400
5441 // Handle access to various length properties 5401 // Handle access to various length properties
5442 if (name->Equals(isolate()->heap()->length_string())) { 5402 if (name->Equals(isolate()->heap()->length_string())) {
5443 if (map->instance_type() == JS_ARRAY_TYPE) { 5403 if (map->instance_type() == JS_ARRAY_TYPE) {
5444 AddCheckMapsWithTransitions(object, map); 5404 AddCheckMapsWithTransitions(object, map);
5445 return new(zone()) HLoadNamedField(object, 5405 return new(zone()) HLoadNamedField(object,
5446 HObjectAccess::ForArrayLength()); 5406 HObjectAccess::ForArrayLength());
danno 2013/07/23 16:15:43 Here it's map->elements_kind()
5447 } 5407 }
5448 } 5408 }
5449 5409
5450 LookupResult lookup(isolate()); 5410 LookupResult lookup(isolate());
5451 map->LookupDescriptor(NULL, *name, &lookup); 5411 map->LookupDescriptor(NULL, *name, &lookup);
5452 if (lookup.IsField()) { 5412 if (lookup.IsField()) {
5453 AddCheckMap(object, map); 5413 AddCheckMap(object, map);
5454 return BuildLoadNamedField(object, 5414 return BuildLoadNamedField(object,
5455 HObjectAccess::ForField(map, &lookup, name), 5415 HObjectAccess::ForField(map, &lookup, name));
5456 ComputeLoadStoreRepresentation(map, &lookup));
5457 } 5416 }
5458 5417
5459 // Handle a load of a constant known function. 5418 // Handle a load of a constant known function.
5460 if (lookup.IsConstantFunction()) { 5419 if (lookup.IsConstantFunction()) {
5461 AddCheckMap(object, map); 5420 AddCheckMap(object, map);
5462 Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*map)); 5421 Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*map));
5463 return new(zone()) HConstant(function); 5422 return new(zone()) HConstant(function);
5464 } 5423 }
5465 5424
5466 // Handle a load from a known field somewhere in the prototype chain. 5425 // Handle a load from a known field somewhere in the prototype chain.
5467 LookupInPrototypes(map, name, &lookup); 5426 LookupInPrototypes(map, name, &lookup);
5468 if (lookup.IsField()) { 5427 if (lookup.IsField()) {
5469 Handle<JSObject> prototype(JSObject::cast(map->prototype())); 5428 Handle<JSObject> prototype(JSObject::cast(map->prototype()));
5470 Handle<JSObject> holder(lookup.holder()); 5429 Handle<JSObject> holder(lookup.holder());
5471 Handle<Map> holder_map(holder->map()); 5430 Handle<Map> holder_map(holder->map());
5472 AddCheckMap(object, map); 5431 AddCheckMap(object, map);
5473 Add<HCheckPrototypeMaps>(prototype, holder, zone(), top_info()); 5432 Add<HCheckPrototypeMaps>(prototype, holder, zone(), top_info());
5474 HValue* holder_value = Add<HConstant>(holder); 5433 HValue* holder_value = Add<HConstant>(holder);
5475 return BuildLoadNamedField(holder_value, 5434 return BuildLoadNamedField(holder_value,
5476 HObjectAccess::ForField(holder_map, &lookup, name), 5435 HObjectAccess::ForField(holder_map, &lookup, name));
5477 ComputeLoadStoreRepresentation(map, &lookup));
5478 } 5436 }
5479 5437
5480 // Handle a load of a constant function somewhere in the prototype chain. 5438 // Handle a load of a constant function somewhere in the prototype chain.
5481 if (lookup.IsConstantFunction()) { 5439 if (lookup.IsConstantFunction()) {
5482 Handle<JSObject> prototype(JSObject::cast(map->prototype())); 5440 Handle<JSObject> prototype(JSObject::cast(map->prototype()));
5483 Handle<JSObject> holder(lookup.holder()); 5441 Handle<JSObject> holder(lookup.holder());
5484 Handle<Map> holder_map(holder->map()); 5442 Handle<Map> holder_map(holder->map());
5485 AddCheckMap(object, map); 5443 AddCheckMap(object, map);
5486 Add<HCheckPrototypeMaps>(prototype, holder, zone(), top_info()); 5444 Add<HCheckPrototypeMaps>(prototype, holder, zone(), top_info());
5487 Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*holder_map)); 5445 Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*holder_map));
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
5689 set_current_block(this_map); 5647 set_current_block(this_map);
5690 HInstruction* checked_key = NULL; 5648 HInstruction* checked_key = NULL;
5691 HInstruction* access = NULL; 5649 HInstruction* access = NULL;
5692 if (IsFastElementsKind(elements_kind)) { 5650 if (IsFastElementsKind(elements_kind)) {
5693 if (is_store && !IsFastDoubleElementsKind(elements_kind)) { 5651 if (is_store && !IsFastDoubleElementsKind(elements_kind)) {
5694 AddInstruction(HCheckMaps::New( 5652 AddInstruction(HCheckMaps::New(
5695 elements, isolate()->factory()->fixed_array_map(), 5653 elements, isolate()->factory()->fixed_array_map(),
5696 zone(), top_info(), mapcompare)); 5654 zone(), top_info(), mapcompare));
5697 } 5655 }
5698 if (map->IsJSArray()) { 5656 if (map->IsJSArray()) {
5699 HInstruction* length = AddLoad(object, HObjectAccess::ForArrayLength(), 5657 HInstruction* length = AddLoad(
5700 mapcompare, Representation::Smi()); 5658 object, HObjectAccess::ForArrayLength(true), mapcompare);
danno 2013/07/23 16:15:43 And here it's also map->elements_kind()
5701 length->set_type(HType::Smi());
5702 checked_key = Add<HBoundsCheck>(key, length); 5659 checked_key = Add<HBoundsCheck>(key, length);
5703 } else { 5660 } else {
5704 HInstruction* length = AddLoadFixedArrayLength(elements); 5661 HInstruction* length = AddLoadFixedArrayLength(elements);
5705 checked_key = Add<HBoundsCheck>(key, length); 5662 checked_key = Add<HBoundsCheck>(key, length);
5706 } 5663 }
5707 access = AddFastElementAccess( 5664 access = AddFastElementAccess(
5708 elements, checked_key, val, mapcompare, 5665 elements, checked_key, val, mapcompare,
5709 elements_kind, is_store, NEVER_RETURN_HOLE, STANDARD_STORE); 5666 elements_kind, is_store, NEVER_RETURN_HOLE, STANDARD_STORE);
5710 } else if (IsDictionaryElementsKind(elements_kind)) { 5667 } else if (IsDictionaryElementsKind(elements_kind)) {
5711 if (is_store) { 5668 if (is_store) {
(...skipping 2771 matching lines...) Expand 10 before | Expand all | Expand 10 after
8483 AddStore(object_header, access, properties); 8440 AddStore(object_header, access, properties);
8484 8441
8485 if (boilerplate_object->IsJSArray()) { 8442 if (boilerplate_object->IsJSArray()) {
8486 Handle<JSArray> boilerplate_array = 8443 Handle<JSArray> boilerplate_array =
8487 Handle<JSArray>::cast(boilerplate_object); 8444 Handle<JSArray>::cast(boilerplate_object);
8488 Handle<Object> length_field = 8445 Handle<Object> length_field =
8489 Handle<Object>(boilerplate_array->length(), isolate()); 8446 Handle<Object>(boilerplate_array->length(), isolate());
8490 HInstruction* length = Add<HConstant>(length_field); 8447 HInstruction* length = Add<HConstant>(length_field);
8491 8448
8492 ASSERT(boilerplate_array->length()->IsSmi()); 8449 ASSERT(boilerplate_array->length()->IsSmi());
8493 Representation representation = 8450 AddStore(object_header, HObjectAccess::ForArrayLength(
8494 IsFastElementsKind(boilerplate_array->GetElementsKind()) 8451 IsFastElementsKind(boilerplate_array->GetElementsKind())),
8495 ? Representation::Smi() : Representation::Tagged(); 8452 length);
8496 AddStore(object_header, HObjectAccess::ForArrayLength(),
8497 length, representation);
8498 } 8453 }
8499 8454
8500 return result; 8455 return result;
8501 } 8456 }
8502 8457
8503 8458
8504 void HOptimizedGraphBuilder::BuildEmitInObjectProperties( 8459 void HOptimizedGraphBuilder::BuildEmitInObjectProperties(
8505 Handle<JSObject> boilerplate_object, 8460 Handle<JSObject> boilerplate_object,
8506 Handle<JSObject> original_boilerplate_object, 8461 Handle<JSObject> original_boilerplate_object,
8507 HValue* object_properties, 8462 HValue* object_properties,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
8553 if (data_target != NULL) { 8508 if (data_target != NULL) {
8554 double_box = Add<HInnerAllocatedObject>(data_target, *data_offset); 8509 double_box = Add<HInnerAllocatedObject>(data_target, *data_offset);
8555 *data_offset += HeapNumber::kSize; 8510 *data_offset += HeapNumber::kSize;
8556 } else { 8511 } else {
8557 double_box = Add<HInnerAllocatedObject>(target, *offset); 8512 double_box = Add<HInnerAllocatedObject>(target, *offset);
8558 *offset += HeapNumber::kSize; 8513 *offset += HeapNumber::kSize;
8559 } 8514 }
8560 AddStoreMapConstant(double_box, 8515 AddStoreMapConstant(double_box,
8561 isolate()->factory()->heap_number_map()); 8516 isolate()->factory()->heap_number_map());
8562 AddStore(double_box, HObjectAccess::ForHeapNumberValue(), 8517 AddStore(double_box, HObjectAccess::ForHeapNumberValue(),
8563 value_instruction, Representation::Double()); 8518 value_instruction);
8564 value_instruction = double_box; 8519 value_instruction = double_box;
8565 } 8520 }
8566 8521
8567 AddStore(object_properties, access, value_instruction); 8522 AddStore(object_properties, access, value_instruction);
8568 } 8523 }
8569 } 8524 }
8570 8525
8571 int inobject_properties = boilerplate_object->map()->inobject_properties(); 8526 int inobject_properties = boilerplate_object->map()->inobject_properties();
8572 HInstruction* value_instruction = 8527 HInstruction* value_instruction =
8573 Add<HConstant>(isolate()->factory()->one_pointer_filler_map()); 8528 Add<HConstant>(isolate()->factory()->one_pointer_filler_map());
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after
9949 if (ShouldProduceTraceOutput()) { 9904 if (ShouldProduceTraceOutput()) {
9950 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 9905 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
9951 } 9906 }
9952 9907
9953 #ifdef DEBUG 9908 #ifdef DEBUG
9954 graph_->Verify(false); // No full verify. 9909 graph_->Verify(false); // No full verify.
9955 #endif 9910 #endif
9956 } 9911 }
9957 9912
9958 } } // namespace v8::internal 9913 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698