Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Unified Diff: src/interpreter/bytecode-generator.cc

Issue 1531693002: [Interpreter] Implement ForIn in bytecode graph builder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@oth-0009-phi
Patch Set: Fix missing comment. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/interpreter/bytecode-generator.cc
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc
index 22972537abcbccb0e72a702ba07e9e4eb12a011a..af5111e4fcc8e5fc35bbb9ddf6ef762e6b6f31d7 100644
--- a/src/interpreter/bytecode-generator.cc
+++ b/src/interpreter/bytecode-generator.cc
@@ -851,7 +851,6 @@ void BytecodeGenerator::VisitForInAssignment(Expression* expr,
void BytecodeGenerator::VisitForInStatement(ForInStatement* stmt) {
EffectResultScope statement_result_scope(this);
-
if (stmt->subject()->IsNullLiteral() ||
stmt->subject()->IsUndefinedLiteral(isolate())) {
// ForIn generates lots of code, skip if it wouldn't produce any effects.
@@ -865,34 +864,33 @@ void BytecodeGenerator::VisitForInStatement(ForInStatement* stmt) {
VisitForAccumulatorValue(stmt->subject());
loop_builder.BreakIfUndefined();
loop_builder.BreakIfNull();
-
Register receiver = execution_result()->NewRegister();
+ // BytecodeGenerator emits a cast here as the BytecodeGraphBuilder
+ // only supports a single de-opt point per bytecode. So whilst the
+ // ast-graph-builder does the cast (semantically) inside
+ // ForInPrepare we need to cast first in case it de-opts.
Benedikt Meurer 2015/12/18 07:55:50 Same here. I'm not sure what that comment is suppo
builder()->CastAccumulatorToJSObject();
+ loop_builder.BreakIfNull();
builder()->StoreAccumulatorInRegister(receiver);
- builder()->CallRuntime(Runtime::kGetPropertyNamesFast, receiver, 1);
- builder()->ForInPrepare(receiver);
- loop_builder.BreakIfUndefined();
-
- Register for_in_state = execution_result()->NewRegister();
- builder()->StoreAccumulatorInRegister(for_in_state);
+ Register cache_type = execution_result()->NewRegister();
+ Register cache_array = execution_result()->NewRegister();
+ Register cache_length = execution_result()->NewRegister();
+ builder()->ForInPrepare(receiver, cache_type, cache_array, cache_length);
// Check loop termination (accumulator holds index).
- Register index = receiver; // Re-using register as receiver no longer used.
+ Register index = execution_result()->NewRegister();
builder()->LoadLiteral(Smi::FromInt(0));
+ builder()->StoreAccumulatorInRegister(index);
loop_builder.LoopHeader();
loop_builder.Condition();
- builder()->StoreAccumulatorInRegister(index).ForInDone(for_in_state);
+ builder()->ForInDone(index, cache_length);
loop_builder.BreakIfTrue();
- builder()->ForInNext(for_in_state, index);
+ builder()->ForInNext(receiver, cache_type, cache_array, index);
loop_builder.ContinueIfUndefined();
-
VisitForInAssignment(stmt->each(), stmt->EachFeedbackSlot());
Visit(stmt->body());
-
- // TODO(oth): replace CountOperation here with ForInStep.
loop_builder.Next();
- builder()->LoadAccumulatorWithRegister(index).CountOperation(
- Token::Value::ADD, language_mode_strength());
+ builder()->ForInStep(index);
loop_builder.JumpToHeader();
loop_builder.LoopEnd();
}

Powered by Google App Engine
This is Rietveld 408576698