From 39b06d8850d18460284f0c4ce4a72a91fafb88eb Mon Sep 17 00:00:00 2001 From: "jkummerow@chromium.org" Date: Thu, 30 Jun 2011 08:40:31 +0000 Subject: [PATCH] Add support for dictionary elements to polymorphic crankshaft code. Review URL: http://codereview.chromium.org/7285001 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8479 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/hydrogen.cc | 17 ++++++++++++----- src/ic.cc | 3 ++- src/objects.h | 4 ++++ src/stub-cache.cc | 4 ++++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/hydrogen.cc b/src/hydrogen.cc index d700fd2e34..602344ec4d 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -3917,8 +3917,6 @@ HValue* HGraphBuilder::HandlePolymorphicElementAccess(HValue* object, todo_external_array = true; } } - // We can't treat dictionary elements here (need to deopt instead). - type_todo[JSObject::DICTIONARY_ELEMENTS] = false; // Support for FAST_DOUBLE_ELEMENTS isn't implemented yet, so we deopt. type_todo[JSObject::FAST_DOUBLE_ELEMENTS] = false; @@ -3936,9 +3934,12 @@ HValue* HGraphBuilder::HandlePolymorphicElementAccess(HValue* object, for (JSObject::ElementsKind elements_kind = JSObject::FAST_ELEMENTS; elements_kind <= JSObject::LAST_ELEMENTS_KIND; elements_kind = JSObject::ElementsKind(elements_kind + 1)) { - // After having handled FAST_ELEMENTS in the first run of the loop, we - // need to add some code that's executed for all other cases. - if (elements_kind == 1 && todo_external_array) { + // After having handled FAST_ELEMENTS and DICTIONARY_ELEMENTS, we + // need to add some code that's executed for all external array cases. + STATIC_ASSERT(JSObject::LAST_EXTERNAL_ARRAY_ELEMENTS_KIND == + JSObject::LAST_ELEMENTS_KIND); + if (elements_kind == JSObject::FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND + && todo_external_array) { elements = AddInstruction(new(zone()) HLoadElements(object)); // We need to forcibly prevent some ElementsKind-dependent instructions // from being hoisted out of any loops they might occur in, because @@ -4007,6 +4008,12 @@ HValue* HGraphBuilder::HandlePolymorphicElementAccess(HValue* object, access = AddInstruction( new(zone()) HLoadKeyedFastElement(elements, checked_key)); } + } else if (elements_kind == JSObject::DICTIONARY_ELEMENTS) { + if (is_store) { + access = AddInstruction(BuildStoreKeyedGeneric(object, key, val)); + } else { + access = AddInstruction(BuildLoadKeyedGeneric(object, key)); + } } else { // External array elements. access = AddInstruction(BuildExternalArrayElementAccess( external_elements, checked_key, val, elements_kind, is_store)); diff --git a/src/ic.cc b/src/ic.cc index efa8f2db95..fd8c27045d 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -1745,7 +1745,8 @@ MaybeObject* KeyedIC::ComputeMonomorphicStub(JSObject* receiver, Code* generic_stub) { Code* result = NULL; if (receiver->HasFastElements() || - receiver->HasExternalArrayElements()) { + receiver->HasExternalArrayElements() || + receiver->HasDictionaryElements()) { MaybeObject* maybe_stub = isolate()->stub_cache()->ComputeKeyedLoadOrStoreElement( receiver, is_store, strict_mode); diff --git a/src/objects.h b/src/objects.h index e49bbefa30..b2b1a77c6b 100644 --- a/src/objects.h +++ b/src/objects.h @@ -3946,6 +3946,10 @@ class Map: public HeapObject { kind <= JSObject::LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; } + inline bool has_dictionary_elements() { + return elements_kind() == JSObject::DICTIONARY_ELEMENTS; + } + // Tells whether the map is attached to SharedFunctionInfo // (for inobject slack tracking). inline void set_attached_to_shared_function_info(bool value); diff --git a/src/stub-cache.cc b/src/stub-cache.cc index d5392d95bf..eb813814d4 100644 --- a/src/stub-cache.cc +++ b/src/stub-cache.cc @@ -1694,6 +1694,8 @@ MaybeObject* KeyedLoadStubCompiler::ComputeSharedKeyedLoadElementStub( } else if (receiver_map->has_external_array_elements()) { JSObject::ElementsKind elements_kind = receiver_map->elements_kind(); maybe_stub = KeyedLoadExternalArrayStub(elements_kind).TryGetCode(); + } else if (receiver_map->has_dictionary_elements()) { + maybe_stub = isolate()->builtins()->builtin(Builtins::kKeyedLoadIC_Slow); } else { UNREACHABLE(); } @@ -1746,6 +1748,8 @@ MaybeObject* KeyedStoreStubCompiler::ComputeSharedKeyedStoreElementStub( } else if (receiver_map->has_external_array_elements()) { JSObject::ElementsKind elements_kind = receiver_map->elements_kind(); maybe_stub = KeyedStoreExternalArrayStub(elements_kind).TryGetCode(); + } else if (receiver_map->has_dictionary_elements()) { + maybe_stub = isolate()->builtins()->builtin(Builtins::kKeyedStoreIC_Slow); } else { UNREACHABLE(); }