Revision: 3667
Author: [email protected]
Date: Thu Jan 21 00:31:16 2010
Log: Add the for statement back into the set of things the
non-optimizing compiler can cope with.  By default it bails out
to the old compiler on encountering a for loop (for performance)
but with this change the --always-fast-compiler flag will enable
functions with for loops to be compiled in the non-optimizing
compiler.  Also enables the non-optimizing compiler on functions
that can be lazily compiled (again only with the flag).
Review URL: http://codereview.chromium.org/552065
http://code.google.com/p/v8/source/detail?r=3667

Added:
 /branches/bleeding_edge/test/mjsunit/for.js
Modified:
 /branches/bleeding_edge/src/compiler.cc
 /branches/bleeding_edge/src/full-codegen.cc
 /branches/bleeding_edge/test/mjsunit/debug-step.js

=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/for.js Thu Jan 21 00:31:16 2010
@@ -0,0 +1,32 @@
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Test missing condition in for loop.
+for (var i = 0; ; i++) {
+  if (i > 100) break;
+}
+assertEquals(101, i);
=======================================
--- /branches/bleeding_edge/src/compiler.cc     Wed Jan 20 08:28:21 2010
+++ /branches/bleeding_edge/src/compiler.cc     Thu Jan 21 00:31:16 2010
@@ -469,7 +469,8 @@

     // Generate code and return it.
     bool is_compiled = false;
-    if (FLAG_fast_compiler && literal->try_fast_codegen()) {
+    if (FLAG_always_fast_compiler ||
+        (FLAG_fast_compiler && literal->try_fast_codegen())) {
       FullCodeGenSyntaxChecker checker;
       checker.Check(literal);
       if (checker.has_supported_syntax()) {
=======================================
--- /branches/bleeding_edge/src/full-codegen.cc Wed Jan 20 08:28:21 2010
+++ /branches/bleeding_edge/src/full-codegen.cc Thu Jan 21 00:31:16 2010
@@ -172,7 +172,20 @@


 void FullCodeGenSyntaxChecker::VisitForStatement(ForStatement* stmt) {
-  BAILOUT("ForStatement");
+  if (!FLAG_always_fast_compiler) BAILOUT("ForStatement");
+  if (stmt->init() != NULL) {
+    Visit(stmt->init());
+    CHECK_BAILOUT;
+  }
+  if (stmt->cond() != NULL) {
+    Visit(stmt->cond());
+    CHECK_BAILOUT;
+  }
+  Visit(stmt->body());
+  if (stmt->next() != NULL) {
+    CHECK_BAILOUT;
+    Visit(stmt->next());
+  }
 }


@@ -855,7 +868,48 @@


 void FullCodeGenerator::VisitForStatement(ForStatement* stmt) {
-  UNREACHABLE();
+  Comment cmnt(masm_, "[ ForStatement");
+  SetStatementPosition(stmt);
+  Label test, body, stack_limit_hit, stack_check_success;
+
+  Iteration loop_statement(this, stmt);
+  if (stmt->init() != NULL) {
+    Visit(stmt->init());
+  }
+
+  increment_loop_depth();
+  // Emit the test at the bottom of the loop (even if empty).
+  __ jmp(&test);
+
+  __ bind(&body);
+  Visit(stmt->body());
+
+  __ bind(loop_statement.continue_target());
+
+  SetStatementPosition(stmt);
+  if (stmt->next() != NULL) {
+    Visit(stmt->next());
+  }
+
+  __ bind(&test);
+
+  // Check stack before looping.
+  __ StackLimitCheck(&stack_limit_hit);
+  __ bind(&stack_check_success);
+
+  if (stmt->cond() != NULL) {
+    VisitForControl(stmt->cond(), &body, loop_statement.break_target());
+  } else {
+    __ jmp(&body);
+  }
+
+  __ bind(&stack_limit_hit);
+  StackCheckStub stack_stub;
+  __ CallStub(&stack_stub);
+  __ jmp(&stack_check_success);
+
+  __ bind(loop_statement.break_target());
+  decrement_loop_depth();
 }


-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to