Commit 5532af44 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Move more type collection logic from AST to oracle.

(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
parent 843fca16
......@@ -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;
......
......@@ -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_; }
......
......@@ -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;
......
......@@ -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_; }
......
......@@ -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()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment