Reviewers: Jarin,

Message:
Hey Jaro,

Here's the proof-of-concept implementation of for-of in Crankshaft.
This is not intended for landing now. We'll first have to have some
strategic discussion about this.
Please take a look.

Thanks,
Benedikt

Description:
[crankshaft] Add baseline implementation of for-of.

This adds a baseline implementation of for-of without any specific
optimizations to Crankshaft, and enables compilation of methods
containing for-of with Crankshaft.

[email protected]

Please review this at https://codereview.chromium.org/1327753002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+38, -2 lines):
  M src/ast-numbering.cc
  M src/hydrogen.cc
  M src/typing.cc


Index: src/ast-numbering.cc
diff --git a/src/ast-numbering.cc b/src/ast-numbering.cc
index 7338cc6724219678852d5a90c40155b5a62e53ad..b3945c3ac38575301831063c0ee436a298e38ffd 100644
--- a/src/ast-numbering.cc
+++ b/src/ast-numbering.cc
@@ -389,7 +389,6 @@ void AstNumberingVisitor::VisitForInStatement(ForInStatement* node) {

 void AstNumberingVisitor::VisitForOfStatement(ForOfStatement* node) {
   IncrementNodeCount();
-  DisableCrankshaft(kForOfStatement);
   node->set_base_id(ReserveIdRange(ForOfStatement::num_ids()));
   Visit(node->assign_iterator());
   Visit(node->next_result());
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 4a3dd2710b1514dcf0c179575a2e5420c132cfde..fd1b72264118df535763e8ae440d326ccda432c8 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -5406,7 +5406,37 @@ void HOptimizedGraphBuilder::VisitForOfStatement(ForOfStatement* stmt) {
   DCHECK(!HasStackOverflow());
   DCHECK(current_block() != NULL);
   DCHECK(current_block()->HasPredecessor());
-  return Bailout(kForOfStatement);
+  CHECK_ALIVE(VisitForEffect(stmt->assign_iterator()));
+  DCHECK(current_block() != NULL);
+  HBasicBlock* loop_entry = BuildLoopEntry(stmt);
+
+  HBasicBlock* body_entry = graph()->CreateBasicBlock();
+  HBasicBlock* loop_successor = graph()->CreateBasicBlock();
+  CHECK_BAILOUT(VisitForEffect(stmt->next_result()));
+  CHECK_BAILOUT(
+      VisitForControl(stmt->result_done(), loop_successor, body_entry));
+  if (body_entry->HasPredecessor()) {
+    body_entry->SetJoinId(stmt->BackEdgeId());
+    set_current_block(body_entry);
+  }
+  if (loop_successor->HasPredecessor()) {
+    loop_successor->SetJoinId(stmt->ExitId());
+  } else {
+    loop_successor = NULL;
+  }
+
+  BreakAndContinueInfo break_info(stmt, scope());
+  if (current_block() != NULL) {
+    BreakAndContinueScope push(&break_info, this);
+    CHECK_BAILOUT(VisitForEffect(stmt->assign_each()));
+    CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry));
+  }
+  HBasicBlock* body_exit =
+      JoinContinue(stmt, current_block(), break_info.continue_block());
+
+  HBasicBlock* loop_exit = CreateLoop(stmt, loop_entry, body_exit,
+ loop_successor, break_info.break_block());
+  set_current_block(loop_exit);
 }


Index: src/typing.cc
diff --git a/src/typing.cc b/src/typing.cc
index fb758828b076524a47c6be702050437507d4be95..07e8416e7d232cae12c74332f0d969d0f13f02f0 100644
--- a/src/typing.cc
+++ b/src/typing.cc
@@ -299,7 +299,14 @@ void AstTyper::VisitForInStatement(ForInStatement* stmt) {

 void AstTyper::VisitForOfStatement(ForOfStatement* stmt) {
   RECURSE(Visit(stmt->iterable()));
+  RECURSE(Visit(stmt->assign_iterator()));
   store_.Forget();  // Control may transfer here via looping or 'continue'.
+  RECURSE(Visit(stmt->next_result()));
+  // Collect type feedback.
+  stmt->result_done()->RecordToBooleanTypeFeedback(oracle());
+  ObserveTypesAtOsrEntry(stmt);
+  RECURSE(Visit(stmt->result_done()));
+  RECURSE(Visit(stmt->assign_each()));
   RECURSE(Visit(stmt->body()));
   store_.Forget();  // Control may transfer here via 'break'.
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to