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

Unified Diff: src/hydrogen.cc

Issue 14284010: Introduce HObjectAccess, which is used by LoadNamedField and StoreNamedField to denote what parts (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 9ca78ccc84454c2f20140f22614b5951b79911e9..21ce1897ea8a38b21a4b0b72b789b207b2d04c1d 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -1189,13 +1189,7 @@ HValue* HGraphBuilder::BuildCheckForCapacityGrow(HValue* object,
new_length->ChangeRepresentation(Representation::Integer32());
new_length->ClearFlag(HValue::kCanOverflow);
- Factory* factory = isolate()->factory();
- HInstruction* length_store = AddInstruction(new(zone) HStoreNamedField(
- object,
- factory->length_field_string(),
- new_length, true,
- JSArray::kLengthOffset));
- length_store->SetGVNFlag(kChangesArrayLengths);
+ AddStore(object, AccessArrayLength(), new_length);
}
length_checker.Else();
@@ -1278,7 +1272,8 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
HInstruction* length = NULL;
if (is_js_array) {
length = AddInstruction(
danno 2013/04/26 09:39:38 while your here, and you add a AddLoad (like your
- HLoadNamedField::NewArrayLength(zone, object, mapcheck, HType::Smi()));
+ new(zone) HLoadNamedField(object, AccessArrayLength(), mapcheck));
+ length->set_type(HType::Smi());
} else {
length = AddInstruction(new(zone) HFixedArrayBaseLength(elements));
}
@@ -1411,13 +1406,11 @@ void HGraphBuilder::BuildInitializeElements(HValue* elements,
Handle<Map> map = IsFastDoubleElementsKind(kind)
? factory->fixed_double_array_map()
: factory->fixed_array_map();
- BuildStoreMap(elements, map);
- Handle<String> fixed_array_length_field_name = factory->length_field_string();
- HInstruction* store_length =
- new(zone) HStoreNamedField(elements, fixed_array_length_field_name,
- capacity, true, FixedArray::kLengthOffset);
- AddInstruction(store_length);
+ HValue* map_constant =
+ AddInstruction(new(zone) HConstant(map, Representation::Tagged()));
+ AddStore(elements, AccessMap(), map_constant);
+ AddStore(elements, AccessFixedArrayLength(), capacity);
}
@@ -1430,29 +1423,6 @@ HValue* HGraphBuilder::BuildAllocateAndInitializeElements(HValue* context,
}
-HInstruction* HGraphBuilder::BuildStoreMap(HValue* object,
- HValue* map) {
- Zone* zone = this->zone();
- Factory* factory = isolate()->factory();
- Handle<String> map_field_name = factory->map_field_string();
- HInstruction* store_map =
- new(zone) HStoreNamedField(object, map_field_name, map,
- true, JSObject::kMapOffset);
- store_map->SetGVNFlag(kChangesMaps);
- AddInstruction(store_map);
- return store_map;
-}
-
-
-HInstruction* HGraphBuilder::BuildStoreMap(HValue* object,
- Handle<Map> map) {
- Zone* zone = this->zone();
- HValue* map_constant =
- AddInstruction(new(zone) HConstant(map, Representation::Tagged()));
- return BuildStoreMap(object, map_constant);
-}
-
-
HValue* HGraphBuilder::BuildNewElementsCapacity(HValue* context,
HValue* old_capacity) {
Zone* zone = this->zone();
@@ -1502,7 +1472,6 @@ HValue* HGraphBuilder::BuildGrowElementsCapacity(HValue* object,
ElementsKind kind,
HValue* length,
HValue* new_capacity) {
- Zone* zone = this->zone();
HValue* context = environment()->LookupContext();
BuildNewSpaceArrayCheck(new_capacity, kind);
@@ -1514,13 +1483,7 @@ HValue* HGraphBuilder::BuildGrowElementsCapacity(HValue* object,
new_elements, kind,
length, new_capacity);
- Factory* factory = isolate()->factory();
- HInstruction* elements_store = AddInstruction(new(zone) HStoreNamedField(
- object,
- factory->elements_field_string(),
- new_elements, true,
- JSArray::kElementsOffset));
- elements_store->SetGVNFlag(kChangesElementsPointer);
+ AddStore(object, AccessElements(), new_elements);
return new_elements;
}
@@ -1635,16 +1598,10 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context,
// Copy the JS array part.
for (int i = 0; i < JSArray::kSize; i += kPointerSize) {
if ((i != JSArray::kElementsOffset) || (length == 0)) {
+ ObjectAccess access = AccessArray(i);
danno 2013/04/26 09:39:38 Careful, this isn't what you think. This loop does
HInstruction* value =
- AddInstruction(new(zone) HLoadNamedField(boilerplate, true, i));
- if (i != JSArray::kMapOffset) {
- AddInstruction(new(zone) HStoreNamedField(object,
- factory->empty_string(),
- value,
- true, i));
- } else {
- BuildStoreMap(object, value);
- }
+ AddInstruction(new(zone) HLoadNamedField(boilerplate, access));
+ AddStore(object, access, value);
}
}
@@ -1653,12 +1610,12 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context,
HValue* alloc_site =
AddInstruction(new(zone) HInnerAllocatedObject(object, JSArray::kSize));
Handle<Map> alloc_site_map(isolate()->heap()->allocation_site_info_map());
- BuildStoreMap(alloc_site, alloc_site_map);
- int alloc_payload_offset = AllocationSiteInfo::kPayloadOffset;
- AddInstruction(new(zone) HStoreNamedField(alloc_site,
- factory->empty_string(),
- boilerplate,
- true, alloc_payload_offset));
+ HValue* alloc_site_map_constant = AddInstruction(new(zone)
+ HConstant(alloc_site_map, Representation::Tagged()));
+ AddStore(alloc_site, AccessMap(), alloc_site_map_constant);
danno 2013/04/26 09:39:38 I still think a wrapper utility BuildStoreMap woul
+ ObjectAccess access = AccessInobject(
+ factory->payload_string(), AllocationSiteInfo::kPayloadOffset);
+ AddStore(alloc_site, access, boilerplate);
}
if (length > 0) {
@@ -1668,20 +1625,15 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context,
AddInstruction(new(zone) HLoadElements(boilerplate, NULL));
HValue* object_elements =
AddInstruction(new(zone) HInnerAllocatedObject(object, elems_offset));
- AddInstruction(new(zone) HStoreNamedField(object,
- factory->elements_field_string(),
- object_elements,
- true, JSObject::kElementsOffset));
+ AddStore(object, AccessElements(), object_elements);
// Copy the elements array header.
for (int i = 0; i < FixedArrayBase::kHeaderSize; i += kPointerSize) {
- HInstruction* value =
- AddInstruction(new(zone) HLoadNamedField(boilerplate_elements,
- true, i));
- AddInstruction(new(zone) HStoreNamedField(object_elements,
- factory->empty_string(),
- value,
- true, i));
+ // TODO(titzer): AccessFixedArray?
+ ObjectAccess access = AccessInobject(factory->empty_string(), i);
+ HInstruction* value = AddInstruction(new(zone)
+ HLoadNamedField(boilerplate_elements, access));
+ AddStore(object_elements, access, value);
}
// Copy the elements array contents.
@@ -1754,6 +1706,83 @@ void HGraphBuilder::BuildCompareNil(
}
+HStoreNamedField* HGraphBuilder::AddStore(HValue *object, ObjectAccess access,
+ HValue *val) {
+ HStoreNamedField *instr = new(zone()) HStoreNamedField(object, access, val);
+ AddInstruction(instr);
+ return instr;
+}
+
+
+ObjectAccess HGraphBuilder::AccessArray(int offset) {
+ Factory *factory = isolate()->factory();
+ ObjectAccess::Portion portion = ObjectAccess::kInobject;
+ Handle<String> name = factory->empty_string();
+ if (offset == JSObject::kElementsOffset) {
+ portion = ObjectAccess::kElementsPointer;
+ name = factory->elements_field_string();
+ } else if (offset == JSArray::kLengthOffset) {
+ portion = ObjectAccess::kArrayLengths;
+ name = factory->length_field_string();
+ } else if (offset == JSArray::kMapOffset) {
+ portion = ObjectAccess::kMaps;
+ name = factory->map_field_string();
danno 2013/04/26 09:39:38 See my other comments about consolidating this log
+ }
+ return ObjectAccess(portion, offset, false, name);
+}
+
+
+ObjectAccess HGraphBuilder::AccessArrayLength() {
+ return ObjectAccess(ObjectAccess::kArrayLengths, JSArray::kLengthOffset,
+ false, isolate()->factory()->length_field_string());
+}
+
+
+ObjectAccess HGraphBuilder::AccessFixedArrayLength() {
+ return ObjectAccess(ObjectAccess::kInobject, FixedArray::kLengthOffset,
+ false, isolate()->factory()->length_field_string());
+}
+
+
+ObjectAccess HGraphBuilder::AccessElements() {
+ return ObjectAccess(ObjectAccess::kElementsPointer, JSObject::kElementsOffset,
+ false, isolate()->factory()->elements_field_string());
+}
+
+
+ObjectAccess HGraphBuilder::AccessMap() {
+ return ObjectAccess(ObjectAccess::kMaps, JSObject::kMapOffset,
+ false, isolate()->factory()->map_field_string());
+}
+
+
+ObjectAccess HGraphBuilder::AccessField(Handle<Map> map, Handle<String> name,
+ LookupResult* lookup) {
+ ASSERT(lookup->IsField() || lookup->IsTransitionToField(*map));
+ int index;
+ if (lookup->IsField()) {
+ index = lookup->GetLocalFieldIndexFromMap(*map);
+ } else {
+ Map* transition = lookup->GetTransitionMapFromMap(*map);
+ index = transition->PropertyIndexFor(*name) - map->inobject_properties();
+ }
+ if (index < 0) {
+ // Negative property indices are in-object properties, indexed
+ // from the end of the fixed part of the object.
+ int offset = (index * kPointerSize) + map->instance_size();
+ return ObjectAccess(ObjectAccess::kInobject, offset, false);
+ } else {
+ // Non-negative property indices are in the properties array.
+ int offset = (index * kPointerSize) + FixedArray::kHeaderSize;
+ return ObjectAccess(ObjectAccess::kBackingStore, offset, false, name);
+ }
+}
+
+ObjectAccess HGraphBuilder::AccessInobject(Handle<String> name, int offset) {
+ return ObjectAccess(ObjectAccess::kInobject, offset, false, name);
+}
+
+
HOptimizedGraphBuilder::HOptimizedGraphBuilder(CompilationInfo* info,
TypeFeedbackOracle* oracle)
: HGraphBuilder(info),
@@ -6661,19 +6690,6 @@ static bool ComputeLoadStoreField(Handle<Map> type,
}
-static int ComputeLoadStoreFieldIndex(Handle<Map> type,
- Handle<String> name,
- LookupResult* lookup) {
- ASSERT(lookup->IsField() || lookup->IsTransitionToField(*type));
- if (lookup->IsField()) {
- return lookup->GetLocalFieldIndexFromMap(*type);
- } else {
- Map* transition = lookup->GetTransitionMapFromMap(*type);
- return transition->PropertyIndexFor(*name) - type->inobject_properties();
- }
-}
-
-
void HOptimizedGraphBuilder::AddCheckMap(HValue* object, Handle<Map> map) {
AddInstruction(new(zone()) HCheckNonSmi(object));
AddInstruction(HCheckMaps::New(object, map, zone()));
@@ -6724,18 +6740,8 @@ HInstruction* HOptimizedGraphBuilder::BuildStoreNamedField(
zone()));
}
- int index = ComputeLoadStoreFieldIndex(map, name, lookup);
- bool is_in_object = index < 0;
- int offset = index * kPointerSize;
- if (index < 0) {
- // Negative property indices are in-object properties, indexed
- // from the end of the fixed part of the object.
- offset += map->instance_size();
- } else {
- offset += FixedArray::kHeaderSize;
- }
- HStoreNamedField* instr =
- new(zone()) HStoreNamedField(object, name, value, is_in_object, offset);
+ ObjectAccess access = AccessField(map, name, lookup);
+ HStoreNamedField* instr = new(zone()) HStoreNamedField(object, access, value);
if (lookup->IsTransitionToField(*map)) {
Handle<Map> transition(lookup->GetTransitionMapFromMap(*map));
instr->set_transition(transition);
@@ -6807,7 +6813,8 @@ bool HOptimizedGraphBuilder::HandlePolymorphicArrayLengthLoad(
HInstruction* typecheck =
AddInstruction(HCheckMaps::New(object, types, zone()));
HInstruction* instr =
- HLoadNamedField::NewArrayLength(zone(), object, typecheck);
+ new(zone()) HLoadNamedField(object, AccessArrayLength(), typecheck);
+
instr->set_position(expr->position());
ast_context()->ReturnInstruction(instr, expr->id());
return true;
@@ -6831,22 +6838,15 @@ void HOptimizedGraphBuilder::HandlePolymorphicLoadNamedField(Property* expr,
for (int i = 0; i < types->length() && count < kMaxLoadPolymorphism; ++i) {
map = types->at(i);
if (ComputeLoadStoreField(map, name, &lookup, false)) {
- int index = ComputeLoadStoreFieldIndex(map, name, &lookup);
- bool is_in_object = index < 0;
- int offset = index * kPointerSize;
- if (index < 0) {
- // Negative property indices are in-object properties, indexed
- // from the end of the fixed part of the object.
- offset += map->instance_size();
- } else {
- offset += FixedArray::kHeaderSize;
- }
+ ObjectAccess access = AccessField(map, name, &lookup);
if (count == 0) {
- previous_field_offset = offset;
- previous_field_is_in_object = is_in_object;
+ previous_field_offset = access.offset();
+ previous_field_is_in_object = access.IsInobject();
} else if (is_monomorphic_field) {
- is_monomorphic_field = (offset == previous_field_offset) &&
- (is_in_object == previous_field_is_in_object);
+ // TODO(titzer): just break out of this loop if not the same
+ is_monomorphic_field =
+ (access.offset() == previous_field_offset) &&
+ (access.IsInobject() == previous_field_is_in_object);
}
++count;
}
@@ -6858,14 +6858,12 @@ void HOptimizedGraphBuilder::HandlePolymorphicLoadNamedField(Property* expr,
HInstruction* instr;
if (count == types->length() && is_monomorphic_field) {
AddInstruction(HCheckMaps::New(object, types, zone()));
- instr = BuildLoadNamedField(object, map, &lookup);
+ instr = new(zone())
+ HLoadNamedField(object, AccessField(map, name, &lookup));
} else {
HValue* context = environment()->LookupContext();
- instr = new(zone()) HLoadNamedFieldPolymorphic(context,
- object,
- types,
- name,
- zone());
+ instr = new(zone())
+ HLoadNamedFieldPolymorphic(context, object, types, name, zone());
}
instr->set_position(expr->position());
@@ -7418,24 +7416,6 @@ void HOptimizedGraphBuilder::VisitThrow(Throw* expr) {
}
-HLoadNamedField* HOptimizedGraphBuilder::BuildLoadNamedField(
- HValue* object,
- Handle<Map> map,
- LookupResult* lookup) {
- int index = lookup->GetLocalFieldIndexFromMap(*map);
- if (index < 0) {
- // Negative property indices are in-object properties, indexed
- // from the end of the fixed part of the object.
- int offset = (index * kPointerSize) + map->instance_size();
- return new(zone()) HLoadNamedField(object, true, offset);
- } else {
- // Non-negative property indices are in the properties array.
- int offset = (index * kPointerSize) + FixedArray::kHeaderSize;
- return new(zone()) HLoadNamedField(object, false, offset);
- }
-}
-
-
HInstruction* HOptimizedGraphBuilder::BuildLoadNamedGeneric(
HValue* object,
Handle<String> name,
@@ -7471,7 +7451,7 @@ HInstruction* HOptimizedGraphBuilder::BuildLoadNamedMonomorphic(
if (name->Equals(isolate()->heap()->length_string())) {
if (map->instance_type() == JS_ARRAY_TYPE) {
AddCheckMapsWithTransitions(object, map);
- return HLoadNamedField::NewArrayLength(zone(), object, object);
+ return new(zone()) HLoadNamedField(object, AccessArrayLength());
}
}
@@ -7479,7 +7459,7 @@ HInstruction* HOptimizedGraphBuilder::BuildLoadNamedMonomorphic(
map->LookupDescriptor(NULL, *name, &lookup);
if (lookup.IsField()) {
AddCheckMap(object, map);
- return BuildLoadNamedField(object, map, &lookup);
+ return new(zone()) HLoadNamedField(object, AccessField(map, name, &lookup));
}
// Handle a load of a constant known function.
@@ -7496,11 +7476,12 @@ HInstruction* HOptimizedGraphBuilder::BuildLoadNamedMonomorphic(
Handle<JSObject> holder(lookup.holder());
Handle<Map> holder_map(holder->map());
AddCheckMap(object, map);
- AddInstruction(
- new(zone()) HCheckPrototypeMaps(prototype, holder, zone()));
- HValue* holder_value = AddInstruction(
- new(zone()) HConstant(holder, Representation::Tagged()));
- return BuildLoadNamedField(holder_value, holder_map, &lookup);
+ AddInstruction(new(zone())
+ HCheckPrototypeMaps(prototype, holder, zone()));
+ HValue* holder_value = AddInstruction(new(zone())
+ HConstant(holder, Representation::Tagged()));
+ return new(zone())
+ HLoadNamedField(holder_value, AccessField(holder_map, name, &lookup));
}
// Handle a load of a constant function somewhere in the prototype chain.
@@ -7764,10 +7745,10 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
current_block()->Finish(typecheck);
set_current_block(if_jsarray);
- HInstruction* length;
- length = AddInstruction(
- HLoadNamedField::NewArrayLength(zone(), object, typecheck,
- HType::Smi()));
+ HInstruction* length = AddInstruction(new(zone())
+ HLoadNamedField(object, AccessArrayLength(), typecheck));
+ length->set_type(HType::Smi());
+
checked_key = AddBoundsCheck(key, length, ALLOW_SMI_KEY);
access = AddInstruction(BuildFastElementAccess(
elements, checked_key, val, elements_kind_branch,
@@ -10421,17 +10402,20 @@ void HOptimizedGraphBuilder::BuildEmitDeepCopy(
isolate()));
HInstruction* value_instruction =
AddInstruction(new(zone) HInnerAllocatedObject(target, *offset));
- AddInstruction(new(zone) HStoreNamedField(
- object_properties, factory->unknown_field_string(), value_instruction,
- true, boilerplate_object->GetInObjectPropertyOffset(i)));
+
+ ObjectAccess access = AccessInobject(factory->unknown_field_string(),
+ boilerplate_object->GetInObjectPropertyOffset(i));
+ AddStore(object_properties, access, value_instruction);
+
BuildEmitDeepCopy(value_object, original_value_object, target,
offset, DONT_TRACK_ALLOCATION_SITE);
} else {
HInstruction* value_instruction = AddInstruction(new(zone) HConstant(
value, Representation::Tagged()));
- AddInstruction(new(zone) HStoreNamedField(
- object_properties, factory->unknown_field_string(), value_instruction,
- true, boilerplate_object->GetInObjectPropertyOffset(i)));
+
+ ObjectAccess access = AccessInobject(factory->unknown_field_string(),
+ boilerplate_object->GetInObjectPropertyOffset(i));
+ AddStore(object_properties, access, value_instruction);
}
}
@@ -10440,12 +10424,12 @@ void HOptimizedGraphBuilder::BuildEmitDeepCopy(
HValue* alloc_site =
AddInstruction(new(zone) HInnerAllocatedObject(target, JSArray::kSize));
Handle<Map> alloc_site_map(isolate()->heap()->allocation_site_info_map());
- BuildStoreMap(alloc_site, alloc_site_map);
- int alloc_payload_offset = AllocationSiteInfo::kPayloadOffset;
- AddInstruction(new(zone) HStoreNamedField(alloc_site,
- factory->payload_string(),
- original_boilerplate,
- true, alloc_payload_offset));
+ HValue* alloc_site_map_constant = AddInstruction(new(zone)
+ HConstant(alloc_site_map, Representation::Tagged()));
+ AddStore(alloc_site, AccessMap(), alloc_site_map_constant);
+ ObjectAccess access = AccessInobject(
+ factory->payload_string(), AllocationSiteInfo::kPayloadOffset);
+ AddStore(alloc_site, access, original_boilerplate);
}
if (object_elements != NULL) {
@@ -10517,7 +10501,9 @@ HValue* HOptimizedGraphBuilder::BuildCopyObjectHeader(
HValue* object_header =
AddInstruction(new(zone) HInnerAllocatedObject(target, object_offset));
Handle<Map> boilerplate_object_map(boilerplate_object->map());
- BuildStoreMap(object_header, boilerplate_object_map);
+ HValue* boilerplate_object_map_constant = AddInstruction(new(zone)
+ HConstant(boilerplate_object_map, Representation::Tagged()));
+ AddStore(object_header, AccessMap(), boilerplate_object_map_constant);
HInstruction* elements;
if (elements_size == 0) {
@@ -10530,22 +10516,16 @@ HValue* HOptimizedGraphBuilder::BuildCopyObjectHeader(
target, elements_offset));
result = elements;
}
- HInstruction* elements_store = AddInstruction(new(zone) HStoreNamedField(
- object_header,
- factory->elements_field_string(),
- elements,
- true, JSObject::kElementsOffset));
- elements_store->SetGVNFlag(kChangesElementsPointer);
+ AddStore(object_header, AccessElements(), elements);
Handle<Object> properties_field =
Handle<Object>(boilerplate_object->properties(), isolate());
ASSERT(*properties_field == isolate()->heap()->empty_fixed_array());
HInstruction* properties = AddInstruction(new(zone) HConstant(
properties_field, Representation::None()));
- AddInstruction(new(zone) HStoreNamedField(object_header,
- factory->empty_string(),
- properties,
- true, JSObject::kPropertiesOffset));
+ ObjectAccess access = AccessInobject(
+ factory->empty_string(), JSObject::kPropertiesOffset);
+ AddStore(object_header, access, properties);
if (boilerplate_object->IsJSArray()) {
Handle<JSArray> boilerplate_array =
@@ -10554,12 +10534,7 @@ HValue* HOptimizedGraphBuilder::BuildCopyObjectHeader(
Handle<Object>(boilerplate_array->length(), isolate());
HInstruction* length = AddInstruction(new(zone) HConstant(
length_field, Representation::None()));
- HInstruction* length_store = AddInstruction(new(zone) HStoreNamedField(
- object_header,
- factory->length_field_string(),
- length,
- true, JSArray::kLengthOffset));
- length_store->SetGVNFlag(kChangesArrayLengths);
+ AddStore(object_header, AccessArrayLength(), length);
}
return result;
@@ -10947,11 +10922,7 @@ void HOptimizedGraphBuilder::GenerateSetValueOf(CallRuntime* call) {
// Create in-object property store to kValueOffset.
set_current_block(if_js_value);
Handle<String> name = isolate()->factory()->undefined_string();
- AddInstruction(new(zone()) HStoreNamedField(object,
- name,
- value,
- true, // in-object store.
- JSValue::kValueOffset));
+ AddStore(object, AccessInobject(name, JSValue::kValueOffset), value);
if_js_value->Goto(join);
join->SetJoinId(call->id());
set_current_block(join);

Powered by Google App Engine
This is Rietveld 408576698