Move more type collection logic from AST to oracle.
authorrossberg@chromium.org <rossberg@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 28 Nov 2013 13:16:51 +0000 (13:16 +0000)
committerrossberg@chromium.org <rossberg@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 28 Nov 2013 13:16:51 +0000 (13:16 +0000)
(More to come in follow-up CL.)

R=jkummerow@chromium.org
BUG=

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

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

src/ast.cc
src/ast.h
src/type-info.cc
src/type-info.h
src/typing.cc

index 3ca1449409466af29bca87c184efa14b6c381a4b..20881bd5a23db8239fbebf16e84d5ff05c3a0ae0 100644 (file)
@@ -575,11 +575,6 @@ bool FunctionDeclaration::IsInlineable() const {
 // once we use the common type field in the AST consistently.
 
 
-void ForInStatement::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
-  for_in_type_ = static_cast<ForInType>(oracle->ForInType(this));
-}
-
-
 void Expression::RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) {
   to_boolean_types_ = oracle->ToBooleanTypes(test_id());
 }
@@ -645,31 +640,6 @@ void Assignment::RecordTypeFeedback(TypeFeedbackOracle* oracle,
 }
 
 
-void CountOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle,
-                                        Zone* zone) {
-  TypeFeedbackId id = CountStoreFeedbackId();
-  is_monomorphic_ = oracle->StoreIsMonomorphicNormal(id);
-  receiver_types_.Clear();
-  if (is_monomorphic_) {
-    // Record receiver type for monomorphic keyed stores.
-    receiver_types_.Add(
-        oracle->StoreMonomorphicReceiverType(id), zone);
-  } else if (oracle->StoreIsKeyedPolymorphic(id)) {
-    receiver_types_.Reserve(kMaxKeyedPolymorphism, zone);
-    oracle->CollectKeyedReceiverTypes(id, &receiver_types_);
-  } else {
-    oracle->CollectPolymorphicStoreReceiverTypes(id, &receiver_types_);
-  }
-  store_mode_ = oracle->GetStoreMode(id);
-  type_ = oracle->IncrementType(this);
-}
-
-
-void CaseClause::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
-  compare_type_ = oracle->ClauseType(CompareId());
-}
-
-
 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) {
   // If there is an interceptor, we can't compute the target for a direct call.
   if (type->has_named_interceptor()) return false;
index 4158907d993ecdb4a30c64bed47e40d41fdc5d0e..33ede1658bda3af696a9b3c32f58908d9e656b25 100644 (file)
--- a/src/ast.h
+++ b/src/ast.h
@@ -924,9 +924,9 @@ class ForInStatement V8_FINAL : public ForEachStatement {
   }
 
   TypeFeedbackId ForInFeedbackId() const { return reuse(PrepareId()); }
-  void RecordTypeFeedback(TypeFeedbackOracle* oracle);
   enum ForInType { FAST_FOR_IN, SLOW_FOR_IN };
   ForInType for_in_type() const { return for_in_type_; }
+  void set_for_in_type(ForInType type) { for_in_type_ = type; }
 
   BailoutId BodyId() const { return body_id_; }
   BailoutId PrepareId() const { return prepare_id_; }
@@ -1122,8 +1122,8 @@ class CaseClause V8_FINAL : public AstNode {
 
   // Type feedback information.
   TypeFeedbackId CompareId() { return compare_id_; }
-  void RecordTypeFeedback(TypeFeedbackOracle* oracle);
   Handle<Type> compare_type() { return compare_type_; }
+  void set_compare_type(Handle<Type> type) { compare_type_ = type; }
 
  private:
   CaseClause(Isolate* isolate,
@@ -1996,7 +1996,6 @@ class CountOperation V8_FINAL : public Expression {
 
   Expression* expression() const { return expression_; }
 
-  void RecordTypeFeedback(TypeFeedbackOracle* oracle, Zone* zone);
   virtual bool IsMonomorphic() V8_OVERRIDE { return is_monomorphic_; }
   virtual SmallMapList* GetReceiverTypes() V8_OVERRIDE {
     return &receiver_types_;
@@ -2005,6 +2004,9 @@ class CountOperation V8_FINAL : public Expression {
     return store_mode_;
   }
   Handle<Type> type() const { return type_; }
+  void set_is_monomorphic(bool b) { is_monomorphic_ = b; }
+  void set_store_mode(KeyedAccessStoreMode mode) { store_mode_ = mode; }
+  void set_type(Handle<Type> type) { type_ = type; }
 
   BailoutId AssignmentId() const { return assignment_id_; }
 
index 36a2dd124073a5d863bb9660103cf7dca817905b..59850c7fc53ca751f755c6524b0ffe496f7bc417 100644 (file)
@@ -225,8 +225,8 @@ bool TypeFeedbackOracle::ObjectLiteralStoreIsMonomorphic(
 }
 
 
-byte TypeFeedbackOracle::ForInType(ForInStatement* stmt) {
-  Handle<Object> value = GetInfo(stmt->ForInFeedbackId());
+byte TypeFeedbackOracle::ForInType(TypeFeedbackId id) {
+  Handle<Object> value = GetInfo(id);
   return value->IsSmi() &&
       Smi::cast(*value)->value() == TypeFeedbackCells::kForInFastCaseMarker
           ? ForInStatement::FAST_FOR_IN : ForInStatement::SLOW_FOR_IN;
@@ -444,8 +444,8 @@ Handle<Type> TypeFeedbackOracle::ClauseType(TypeFeedbackId id) {
 }
 
 
-Handle<Type> TypeFeedbackOracle::IncrementType(CountOperation* expr) {
-  Handle<Object> object = GetInfo(expr->CountBinOpFeedbackId());
+Handle<Type> TypeFeedbackOracle::CountType(TypeFeedbackId id) {
+  Handle<Object> object = GetInfo(id);
   Handle<Type> unknown(Type::None(), isolate_);
   if (!object->IsCode()) return unknown;
   Handle<Code> code = Handle<Code>::cast(object);
@@ -456,6 +456,21 @@ Handle<Type> TypeFeedbackOracle::IncrementType(CountOperation* expr) {
 }
 
 
+void TypeFeedbackOracle::CountReceiverTypes(
+    TypeFeedbackId id, SmallMapList* receiver_types) {
+  receiver_types->Clear();
+  if (StoreIsMonomorphicNormal(id)) {
+    // Record receiver type for monomorphic keyed stores.
+    receiver_types->Add(StoreMonomorphicReceiverType(id), zone());
+  } else if (StoreIsKeyedPolymorphic(id)) {
+    receiver_types->Reserve(kMaxKeyedPolymorphism, zone());
+    CollectKeyedReceiverTypes(id, receiver_types);
+  } else {
+    CollectPolymorphicStoreReceiverTypes(id, receiver_types);
+  }
+}
+
+
 void TypeFeedbackOracle::CollectPolymorphicMaps(Handle<Code> code,
                                                 SmallMapList* types) {
   MapHandleList maps;
index a116971051eba074c2fe4b0f656bf74169140d4c..d6b920750ebc17f869fa7051fbc5376226d7570a 100644 (file)
@@ -256,7 +256,9 @@ class TypeFeedbackOracle: public ZoneObject {
 
   // TODO(1571) We can't use ForInStatement::ForInType as the return value due
   // to various cycles in our headers.
-  byte ForInType(ForInStatement* expr);
+  // TODO(rossberg): once all oracle access is removed from ast.cc, it should
+  // be possible.
+  byte ForInType(TypeFeedbackId id);
 
   Handle<Map> LoadMonomorphicReceiverType(Property* expr);
   Handle<Map> StoreMonomorphicReceiverType(TypeFeedbackId id);
@@ -312,9 +314,10 @@ class TypeFeedbackOracle: public ZoneObject {
                    Handle<Type>* right,
                    Handle<Type>* combined);
 
-  Handle<Type> ClauseType(TypeFeedbackId id);
+  Handle<Type> CountType(TypeFeedbackId id);
+  void CountReceiverTypes(TypeFeedbackId id, SmallMapList* receiver_types);
 
-  Handle<Type> IncrementType(CountOperation* expr);
+  Handle<Type> ClauseType(TypeFeedbackId id);
 
   Zone* zone() const { return zone_; }
   Isolate* isolate() const { return isolate_; }
index 84f596859d76d48892d9cc4a976e8e6165439316..e5f4ce584318632e33aa924bd1e6276a8bea52c4 100644 (file)
@@ -200,7 +200,7 @@ void AstTyper::VisitSwitchStatement(SwitchStatement* stmt) {
     for (int i = 0; i < clauses->length(); ++i) {
       CaseClause* clause = clauses->at(i);
       if (!clause->is_default())
-        clause->RecordTypeFeedback(oracle());
+        clause->set_compare_type(oracle()->ClauseType(clause->CompareId()));
     }
   }
 }
@@ -262,7 +262,8 @@ void AstTyper::VisitForStatement(ForStatement* stmt) {
 
 void AstTyper::VisitForInStatement(ForInStatement* stmt) {
   // Collect type feedback.
-  stmt->RecordTypeFeedback(oracle());
+  stmt->set_for_in_type(static_cast<ForInStatement::ForInType>(
+      oracle()->ForInType(stmt->ForInFeedbackId())));
 
   RECURSE(Visit(stmt->enumerable()));
   store_.Forget();  // Control may transfer here via looping or 'continue'.
@@ -525,11 +526,12 @@ void AstTyper::VisitUnaryOperation(UnaryOperation* expr) {
 
 void AstTyper::VisitCountOperation(CountOperation* expr) {
   // Collect type feedback.
-  expr->RecordTypeFeedback(oracle(), zone());
-  Property* prop = expr->expression()->AsProperty();
-  if (prop != NULL) {
-    prop->RecordTypeFeedback(oracle(), zone());
-  }
+  TypeFeedbackId store_id = expr->CountStoreFeedbackId();
+  expr->set_is_monomorphic(oracle()->StoreIsMonomorphicNormal(store_id));
+  expr->set_store_mode(oracle()->GetStoreMode(store_id));
+  oracle()->CountReceiverTypes(store_id, expr->GetReceiverTypes());
+  expr->set_type(oracle()->CountType(expr->CountBinOpFeedbackId()));
+  // TODO(rossberg): merge the count type with the generic expression type.
 
   RECURSE(Visit(expr->expression()));