Introduce Type::IsCurrently
authorrossberg@chromium.org <rossberg@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 22 Nov 2013 13:16:40 +0000 (13:16 +0000)
committerrossberg@chromium.org <rossberg@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 22 Nov 2013 13:16:40 +0000 (13:16 +0000)
R=verwaest@chromium.org
BUG=

Review URL: https://codereview.chromium.org/83003003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18015 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/ic.cc
src/types.cc
src/types.h

index 53c103a..96f1804 100644 (file)
--- a/src/ic.cc
+++ b/src/ic.cc
@@ -783,7 +783,7 @@ void CallICBase::UpdateCaches(LookupResult* lookup,
       : Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate())),
                          isolate());
 
-  PatchCache(handle(Type::CurrentOf(cache_object), isolate()), name, code);
+  PatchCache(handle(Type::OfCurrently(cache_object), isolate()), name, code);
   TRACE_IC("CallIC", name);
 }
 
@@ -1148,7 +1148,7 @@ void LoadIC::UpdateCaches(LookupResult* lookup,
     code = ComputeHandler(lookup, object, name);
   }
 
-  PatchCache(handle(Type::CurrentOf(object), isolate()), name, code);
+  PatchCache(handle(Type::OfCurrently(object), isolate()), name, code);
   TRACE_IC("LoadIC", name);
 }
 
@@ -1609,7 +1609,7 @@ void StoreIC::UpdateCaches(LookupResult* lookup,
 
   Handle<Code> code = ComputeHandler(lookup, receiver, name, value);
 
-  PatchCache(handle(Type::CurrentOf(receiver), isolate()), name, code);
+  PatchCache(handle(Type::OfCurrently(receiver), isolate()), name, code);
   TRACE_IC("StoreIC", name);
 }
 
index 7c54d4f..485ba88 100644 (file)
@@ -244,7 +244,7 @@ int Type::GlbBitset() {
 
 
 // Most precise _current_ type of a value (usually its class).
-Type* Type::CurrentOf(Handle<i::Object> value) {
+Type* Type::OfCurrently(Handle<i::Object> value) {
   if (value->IsSmi()) return Smi();
   i::Map* map = i::HeapObject::cast(*value)->map();
   if (map->instance_type() == HEAP_NUMBER_TYPE ||
@@ -297,6 +297,14 @@ bool Type::SlowIs(Type* that) {
 }
 
 
+bool Type::IsCurrently(Type* that) {
+  return this->Is(that) ||
+      (this->is_constant() && that->is_class() &&
+       this->as_constant()->IsHeapObject() &&
+       i::HeapObject::cast(*this->as_constant())->map() == *that->as_class());
+}
+
+
 // Check this overlaps that.
 bool Type::Maybe(Type* that) {
   // Fast path for bitsets.
index eab78c2..1dc79dd 100644 (file)
@@ -153,13 +153,18 @@ class Type : public Object {
   static Type* Of(Handle<i::Object> value) {
     return from_bitset(LubBitset(*value));
   }
-  static Type* CurrentOf(Handle<i::Object> value);
 
-  bool Is(Type* that) { return (this == that) ? true : SlowIs(that); }
+  bool Is(Type* that) { return this == that || SlowIs(that); }
   bool Is(Handle<Type> that) { return this->Is(*that); }
   bool Maybe(Type* that);
   bool Maybe(Handle<Type> that) { return this->Maybe(*that); }
 
+  // State-dependent versions of Of and Is that consider subtyping between
+  // a constant and its map class.
+  static Type* OfCurrently(Handle<i::Object> value);
+  bool IsCurrently(Type* that);
+  bool IsCurrently(Handle<Type> that)  { return this->IsCurrently(*that); }
+
   bool IsClass() { return is_class(); }
   bool IsConstant() { return is_constant(); }
   Handle<i::Map> AsClass() { return as_class(); }