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

Unified Diff: src/hydrogen.cc

Issue 18887002: Add support to turn polymorphic loads from the same prototype into a monomorphic load. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 591b870a44292e3cc0bf947248d370f23a01a836..fa6dd72ec06261889731cdee8619e0847fed7133 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -4978,12 +4978,45 @@ HInstruction* HOptimizedGraphBuilder::TryLoadPolymorphicAsMonomorphic(
representation = representation.generalize(new_representation);
}
- if (count != types->length()) return NULL;
+ if (count == types->length()) {
+ // Everything matched; can use monomorphic load.
+ BuildCheckHeapObject(object);
+ AddInstruction(HCheckMaps::New(object, types, zone()));
+ return BuildLoadNamedField(object, access, representation);
+ }
+
+ if (count != 0) return NULL;
+
+ // Second chance: the property is on the prototype and all maps have the
+ // same prototype.
+ Handle<Map> map(types->at(0));
+ if (map->has_named_interceptor()) return NULL;
+ if (map->is_dictionary_map()) return NULL;
+
+ Handle<Object> prototype(map->prototype(), isolate());
+ for (count = 1; count < types->length(); ++count) {
+ Handle<Map> test_map(types->at(count));
+ // Ensure the property is on the prototype, not the object itself.
+ if (map->has_named_interceptor()) return NULL;
+ if (test_map->is_dictionary_map()) return NULL;
+ test_map->LookupDescriptor(NULL, *name, &lookup);
+ if (lookup.IsFound()) return NULL;
+ if (test_map->prototype() != *prototype) return NULL;
+ }
+
+ LookupInPrototypes(map, name, &lookup);
+ if (!lookup.IsField()) return NULL;
- // Everything matched; can use monomorphic load.
BuildCheckHeapObject(object);
AddInstruction(HCheckMaps::New(object, types, zone()));
- return BuildLoadNamedField(object, access, representation);
+ Handle<JSObject> holder(lookup.holder());
+ Handle<Map> holder_map(holder->map());
+ AddInstruction(new(zone()) HCheckPrototypeMaps(
+ Handle<JSObject>::cast(prototype), holder, zone(), top_info()));
+ HValue* holder_value = AddInstruction(new(zone()) HConstant(holder));
+ return BuildLoadNamedField(holder_value,
+ HObjectAccess::ForField(holder_map, &lookup, name),
+ ComputeLoadStoreRepresentation(map, &lookup));
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698