Add support to turn polymorphic loads from the same prototype into a monomorphic load.

R=yangguo@chromium.org

Review URL: https://chromiumcodereview.appspot.com/18887002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15569 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
verwaest@chromium.org 2013-07-09 09:59:23 +00:00
parent d32de2c957
commit 125b7d0848

View File

@ -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));
}