Fix a problem when compiling built-ins with the top-level compiler.
authorfschneider@chromium.org <fschneider@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 14 Jan 2010 17:22:59 +0000 (17:22 +0000)
committerfschneider@chromium.org <fschneider@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 14 Jan 2010 17:22:59 +0000 (17:22 +0000)
Replace runtime call to NumberAdd with call to binary op stub.

Until now the top-level compiler always called a runtime function
for count operations.

In some places we expected in the JS builtins smis as arguments.
If we perform a count operation before all smis would get converted into
heap numbers by the runtime number add function and result in a runtime
assert.

Also: Add missing debugger information in the top-level compiler for
do-while loops.

Review URL: http://codereview.chromium.org/548029

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

src/arm/fast-codegen-arm.cc
src/ast.h
src/fast-codegen.cc
src/fast-codegen.h
src/ia32/fast-codegen-ia32.cc
src/x64/fast-codegen-x64.cc

index 0d934b5..2444467 100644 (file)
@@ -1424,14 +1424,12 @@ void FastCodeGenerator::VisitCountOperation(CountOperation* expr) {
     }
   }
 
-  // Call runtime for +1/-1.
-  if (expr->op() == Token::INC) {
-    __ mov(ip, Operand(Smi::FromInt(1)));
-  } else {
-    __ mov(ip, Operand(Smi::FromInt(-1)));
-  }
-  __ stm(db_w, sp, ip.bit() | r0.bit());
-  __ CallRuntime(Runtime::kNumberAdd, 2);
+  // Call stub for +1/-1.
+  __ mov(r1, Operand(expr->op() == Token::INC
+                     ? Smi::FromInt(1)
+                     : Smi::FromInt(-1)));
+  GenericBinaryOpStub stub(Token::ADD, NO_OVERWRITE);
+  __ CallStub(&stub);
 
   // Store the value returned in r0.
   switch (assign_type) {
index 3961cb8..a714f9c 100644 (file)
--- a/src/ast.h
+++ b/src/ast.h
@@ -1184,6 +1184,9 @@ class CountOperation: public Expression {
   bool is_prefix() const { return is_prefix_; }
   bool is_postfix() const { return !is_prefix_; }
   Token::Value op() const { return op_; }
+  Token::Value binary_op() {
+    return op_ == Token::INC ? Token::ADD : Token::SUB;
+  }
   Expression* expression() const { return expression_; }
 
   virtual void MarkAsStatement() { is_prefix_ = true; }
index 455dd5f..2e3547a 100644 (file)
@@ -183,6 +183,13 @@ void FastCodeGenerator::SetStatementPosition(Statement* stmt) {
 }
 
 
+void FastCodeGenerator::SetStatementPosition(int pos) {
+  if (FLAG_debug_info) {
+    CodeGenerator::RecordPositions(masm_, pos);
+  }
+}
+
+
 void FastCodeGenerator::SetSourcePosition(int pos) {
   if (FLAG_debug_info && pos != RelocInfo::kNoPosition) {
     masm_->RecordPosition(pos);
@@ -360,8 +367,6 @@ void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
 }
 
 
-
-
 void FastCodeGenerator::VisitWithEnterStatement(WithEnterStatement* stmt) {
   Comment cmnt(masm_, "[ WithEnterStatement");
   SetStatementPosition(stmt);
@@ -412,6 +417,7 @@ void FastCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
   __ bind(&stack_check_success);
 
   __ bind(loop_statement.continue_target());
+  SetStatementPosition(stmt->condition_position());
   VisitForControl(stmt->cond(), &body, loop_statement.break_target());
 
   __ bind(&stack_limit_hit);
index ecac8e7..a1f493d 100644 (file)
@@ -296,6 +296,7 @@ class FastCodeGenerator: public AstVisitor {
   void SetFunctionPosition(FunctionLiteral* fun);
   void SetReturnPosition(FunctionLiteral* fun);
   void SetStatementPosition(Statement* stmt);
+  void SetStatementPosition(int pos);
   void SetSourcePosition(int pos);
 
   // Non-local control flow support.
index fdab585..cb28615 100644 (file)
@@ -1393,14 +1393,13 @@ void FastCodeGenerator::VisitCountOperation(CountOperation* expr) {
     }
   }
 
-  // Call runtime for +1/-1.
+  // Call stub for +1/-1.
   __ push(eax);
   __ push(Immediate(Smi::FromInt(1)));
-  if (expr->op() == Token::INC) {
-    __ CallRuntime(Runtime::kNumberAdd, 2);
-  } else {
-    __ CallRuntime(Runtime::kNumberSub, 2);
-  }
+  GenericBinaryOpStub stub(expr->binary_op(),
+                           NO_OVERWRITE,
+                           NO_GENERIC_BINARY_FLAGS);
+  __ CallStub(&stub);
 
   // Store the value returned in eax.
   switch (assign_type) {
index 3ef8678..81cc894 100644 (file)
@@ -1412,14 +1412,13 @@ void FastCodeGenerator::VisitCountOperation(CountOperation* expr) {
     }
   }
 
-  // Call runtime for +1/-1.
+  // Call stub for +1/-1.
   __ push(rax);
   __ Push(Smi::FromInt(1));
-  if (expr->op() == Token::INC) {
-    __ CallRuntime(Runtime::kNumberAdd, 2);
-  } else {
-    __ CallRuntime(Runtime::kNumberSub, 2);
-  }
+  GenericBinaryOpStub stub(expr->binary_op(),
+                           NO_OVERWRITE,
+                           NO_GENERIC_BINARY_FLAGS);
+  __ CallStub(&stub);
 
   // Store the value returned in rax.
   switch (assign_type) {