Revision: 3612
Author: [email protected]
Date: Fri Jan 15 04:00:59 2010
Log: Fix issue 541 and some refactoring of the top-level compiler.

* Refactor VisitProperty to use the platform-specific methods for emitting the IC calls.
* Refactor recording of source positions in the top-level compiler.
* Correct the recorded source positions for assignments and property loads.
* Fix bug on x64 where source positions were not recorded before a calling a call-IC. * Correct some inconsistencies between IA-32 and X64 top-level code generator.

We now pass all regression tests with
--always-fast-compiler.

Review URL: http://codereview.chromium.org/550043
http://code.google.com/p/v8/source/detail?r=3612

Modified:
 /branches/bleeding_edge/src/arm/fast-codegen-arm.cc
 /branches/bleeding_edge/src/fast-codegen.cc
 /branches/bleeding_edge/src/fast-codegen.h
 /branches/bleeding_edge/src/ia32/fast-codegen-ia32.cc
 /branches/bleeding_edge/src/x64/fast-codegen-x64.cc

=======================================
--- /branches/bleeding_edge/src/arm/fast-codegen-arm.cc Thu Jan 14 09:22:59 2010 +++ /branches/bleeding_edge/src/arm/fast-codegen-arm.cc Fri Jan 15 04:00:59 2010
@@ -817,23 +817,19 @@
 }


-void FastCodeGenerator::EmitNamedPropertyLoad(Property* prop,
- Expression::Context context) {
+void FastCodeGenerator::EmitNamedPropertyLoad(Property* prop) {
   SetSourcePosition(prop->position());
   Literal* key = prop->key()->AsLiteral();
   __ mov(r2, Operand(key->handle()));
   Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
   __ Call(ic, RelocInfo::CODE_TARGET);
-  Apply(context, r0);
 }


-void FastCodeGenerator::EmitKeyedPropertyLoad(Property* prop,
- Expression::Context context) {
+void FastCodeGenerator::EmitKeyedPropertyLoad(Property* prop) {
   SetSourcePosition(prop->position());
   Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize));
   __ Call(ic, RelocInfo::CODE_TARGET);
-  Apply(context, r0);
 }


@@ -969,6 +965,9 @@
     __ push(ip);
     __ CallRuntime(Runtime::kToSlowProperties, 1);
   }
+
+  // Record source code position before IC call.
+  SetSourcePosition(expr->position());

   __ pop(r0);
   __ mov(r2, Operand(prop->key()->AsLiteral()->handle()));
@@ -1000,6 +999,9 @@
     __ push(ip);
     __ CallRuntime(Runtime::kToSlowProperties, 1);
   }
+
+  // Record source code position before IC call.
+  SetSourcePosition(expr->position());

   __ pop(r0);
   Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize));
@@ -1024,24 +1026,16 @@
   Comment cmnt(masm_, "[ Property");
   Expression* key = expr->key();

-  // Record the source position for the property load.
-  SetSourcePosition(expr->position());
-
   // Evaluate receiver.
   Visit(expr->obj());

   if (key->IsPropertyName()) {
- // Do a named property load. The IC expects the property name in r2 and
-    // the receiver on the stack.
-    __ mov(r2, Operand(key->AsLiteral()->handle()));
-    Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
-    __ Call(ic, RelocInfo::CODE_TARGET);
+    EmitNamedPropertyLoad(expr);
+    // Drop receiver left on the stack by IC.
     DropAndApply(1, expr->context(), r0);
   } else {
-    // Do a keyed property load.
     Visit(expr->key());
-    Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize));
-    __ Call(ic, RelocInfo::CODE_TARGET);
+    EmitKeyedPropertyLoad(expr);
     // Drop key and receiver left on the stack by IC.
     DropAndApply(2, expr->context(), r0);
   }
@@ -1383,12 +1377,13 @@
     Visit(prop->obj());
     ASSERT_EQ(Expression::kValue, prop->obj()->context());
     if (assign_type == NAMED_PROPERTY) {
-      EmitNamedPropertyLoad(prop, Expression::kValue);
+      EmitNamedPropertyLoad(prop);
     } else {
       Visit(prop->key());
       ASSERT_EQ(Expression::kValue, prop->key()->context());
-      EmitKeyedPropertyLoad(prop, Expression::kValue);
-    }
+      EmitKeyedPropertyLoad(prop);
+    }
+    __ push(r0);
   }

   // Convert to number.
=======================================
--- /branches/bleeding_edge/src/fast-codegen.cc Thu Jan 14 09:22:59 2010
+++ /branches/bleeding_edge/src/fast-codegen.cc Fri Jan 15 04:00:59 2010
@@ -639,9 +639,6 @@
 void FastCodeGenerator::VisitAssignment(Assignment* expr) {
   Comment cmnt(masm_, "[ Assignment");

-  // Record source code position of the (possible) IC call.
-  SetSourcePosition(expr->position());
-
// Left-hand side can only be a property, a global or a (parameter or local) // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY.
   enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
@@ -682,10 +679,12 @@
                          Expression::kValue);
         break;
       case NAMED_PROPERTY:
-        EmitNamedPropertyLoad(prop, Expression::kValue);
+        EmitNamedPropertyLoad(prop);
+        __ push(result_register());
         break;
       case KEYED_PROPERTY:
-        EmitKeyedPropertyLoad(prop, Expression::kValue);
+        EmitKeyedPropertyLoad(prop);
+        __ push(result_register());
         break;
     }
   }
@@ -699,6 +698,9 @@
   if (expr->is_compound()) {
     EmitCompoundAssignmentOp(expr->binary_op(), Expression::kValue);
   }
+
+  // Record source position before possible IC call.
+  SetSourcePosition(expr->position());

   // Store the value.
   switch (assign_type) {
=======================================
--- /branches/bleeding_edge/src/fast-codegen.h  Thu Jan 14 09:22:59 2010
+++ /branches/bleeding_edge/src/fast-codegen.h  Fri Jan 15 04:00:59 2010
@@ -271,11 +271,11 @@

   // Load a value from a named property.
   // The receiver is left on the stack by the IC.
-  void EmitNamedPropertyLoad(Property* expr, Expression::Context context);
+  void EmitNamedPropertyLoad(Property* expr);

   // Load a value from a keyed property.
   // The receiver and the key is left on the stack by the IC.
-  void EmitKeyedPropertyLoad(Property* expr, Expression::Context context);
+  void EmitKeyedPropertyLoad(Property* expr);

   // Apply the compound assignment operator. Expects both operands on top
   // of the stack.
=======================================
--- /branches/bleeding_edge/src/ia32/fast-codegen-ia32.cc Thu Jan 14 09:22:59 2010 +++ /branches/bleeding_edge/src/ia32/fast-codegen-ia32.cc Fri Jan 15 04:00:59 2010
@@ -126,7 +126,6 @@
         fun->scope()->arguments_shadow()->AsVariable()->slot();
     Move(dot_arguments_slot, ecx, ebx, edx);
   }
-

   { Comment cmnt(masm_, "[ Declarations");
     VisitDeclarations(fun->scope()->declarations());
@@ -805,23 +804,21 @@
 }


-void FastCodeGenerator::EmitNamedPropertyLoad(Property* prop,
- Expression::Context context) {
+void FastCodeGenerator::EmitNamedPropertyLoad(Property* prop) {
   SetSourcePosition(prop->position());
   Literal* key = prop->key()->AsLiteral();
   __ mov(ecx, Immediate(key->handle()));
   Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
   __ call(ic, RelocInfo::CODE_TARGET);
-  Apply(context, eax);
+  __ nop();
 }


-void FastCodeGenerator::EmitKeyedPropertyLoad(Property* prop,
- Expression::Context context) {
+void FastCodeGenerator::EmitKeyedPropertyLoad(Property* prop) {
   SetSourcePosition(prop->position());
   Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize));
   __ call(ic, RelocInfo::CODE_TARGET);
-  Apply(context, eax);
+  __ nop();
 }


@@ -848,6 +845,7 @@
     __ push(CodeGenerator::GlobalObject());
     Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize));
     __ call(ic, RelocInfo::CODE_TARGET);
+    __ nop();
     // Overwrite the receiver on the stack with the result if needed.
     DropAndApply(1, context, eax);

@@ -943,6 +941,9 @@
     __ push(Operand(esp, kPointerSize));  // Receiver is under value.
     __ CallRuntime(Runtime::kToSlowProperties, 1);
   }
+
+  // Record source code position before IC call.
+  SetSourcePosition(expr->position());

   __ pop(eax);
   __ mov(ecx, prop->key()->AsLiteral()->handle());
@@ -972,6 +973,9 @@
     __ push(Operand(esp, 2 * kPointerSize));
     __ CallRuntime(Runtime::kToSlowProperties, 1);
   }
+
+  // Record source code position before IC call.
+  SetSourcePosition(expr->position());

   __ pop(eax);
   Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize));
@@ -998,31 +1002,17 @@
   Comment cmnt(masm_, "[ Property");
   Expression* key = expr->key();

-  // Record the source position for the property load.
-  SetSourcePosition(expr->position());
-
   // Evaluate the receiver.
   Visit(expr->obj());

   if (key->IsPropertyName()) {
-    // Do a named property load.  The IC expects the property name in ecx
-    // and the receiver on the stack.
-    __ mov(ecx, Immediate(key->AsLiteral()->handle()));
-    Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
-    __ call(ic, RelocInfo::CODE_TARGET);
-    // By emitting a nop we make sure that we do not have a test eax
- // instruction after the call it is treated specially by the LoadIC code.
-    __ nop();
+    EmitNamedPropertyLoad(expr);
+    // Drop receiver left on the stack by IC.
     DropAndApply(1, expr->context(), eax);
   } else {
-    // Do a keyed property load.
     Visit(expr->key());
-    Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize));
-    __ call(ic, RelocInfo::CODE_TARGET);
-    // By emitting a nop we make sure that we do not have a "test eax,..."
- // instruction after the call it is treated specially by the LoadIC code.
-    __ nop();
-    // Drop key left on the stack by IC.
+    EmitKeyedPropertyLoad(expr);
+    // Drop key and receiver left on the stack by IC.
     DropAndApply(2, expr->context(), eax);
   }
 }
@@ -1352,12 +1342,13 @@
     Visit(prop->obj());
     ASSERT_EQ(Expression::kValue, prop->obj()->context());
     if (assign_type == NAMED_PROPERTY) {
-      EmitNamedPropertyLoad(prop, Expression::kValue);
+      EmitNamedPropertyLoad(prop);
     } else {
       Visit(prop->key());
       ASSERT_EQ(Expression::kValue, prop->key()->context());
-      EmitKeyedPropertyLoad(prop, Expression::kValue);
-    }
+      EmitKeyedPropertyLoad(prop);
+    }
+    __ push(eax);
   }

   // Convert to number.
=======================================
--- /branches/bleeding_edge/src/x64/fast-codegen-x64.cc Thu Jan 14 09:22:59 2010 +++ /branches/bleeding_edge/src/x64/fast-codegen-x64.cc Fri Jan 15 04:00:59 2010
@@ -131,6 +131,10 @@
         fun->scope()->arguments_shadow()->AsVariable()->slot();
     Move(dot_arguments_slot, rcx, rbx, rdx);
   }
+
+  { Comment cmnt(masm_, "[ Declarations");
+    VisitDeclarations(fun->scope()->declarations());
+  }

   { Comment cmnt(masm_, "[ Stack check");
     Label ok;
@@ -140,10 +144,6 @@
     __ CallStub(&stub);
     __ bind(&ok);
   }
-
-  { Comment cmnt(masm_, "[ Declarations");
-    VisitDeclarations(fun->scope()->declarations());
-  }

   if (FLAG_trace) {
     __ CallRuntime(Runtime::kTraceEnter, 0);
@@ -817,23 +817,21 @@
 }


-void FastCodeGenerator::EmitNamedPropertyLoad(Property* prop,
- Expression::Context context) {
+void FastCodeGenerator::EmitNamedPropertyLoad(Property* prop) {
   SetSourcePosition(prop->position());
   Literal* key = prop->key()->AsLiteral();
   __ Move(rcx, key->handle());
   Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
   __ Call(ic, RelocInfo::CODE_TARGET);
-  Apply(context, rax);
+  __ nop();
 }


-void FastCodeGenerator::EmitKeyedPropertyLoad(Property* prop,
- Expression::Context context) {
+void FastCodeGenerator::EmitKeyedPropertyLoad(Property* prop) {
   SetSourcePosition(prop->position());
   Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize));
   __ Call(ic, RelocInfo::CODE_TARGET);
-  Apply(context, rax);
+  __ nop();
 }


@@ -955,6 +953,9 @@
     __ push(Operand(rsp, kPointerSize));  // Receiver is under value.
     __ CallRuntime(Runtime::kToSlowProperties, 1);
   }
+
+  // Record source code position before IC call.
+  SetSourcePosition(expr->position());

   __ pop(rax);
   __ Move(rcx, prop->key()->AsLiteral()->handle());
@@ -984,6 +985,9 @@
     __ push(Operand(rsp, 2 * kPointerSize));
     __ CallRuntime(Runtime::kToSlowProperties, 1);
   }
+
+  // Record source code position before IC call.
+  SetSourcePosition(expr->position());

   __ pop(rax);
   Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize));
@@ -1010,30 +1014,16 @@
   Comment cmnt(masm_, "[ Property");
   Expression* key = expr->key();

-  // Record the source position for the property load.
-  SetSourcePosition(expr->position());
-
   // Evaluate receiver.
   Visit(expr->obj());

   if (key->IsPropertyName()) {
-    // Do a named property load.  The IC expects the property name in rcx
-    // and the receiver on the stack.
-    __ Move(rcx, key->AsLiteral()->handle());
-    Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
-    __ call(ic, RelocInfo::CODE_TARGET);
-    // By emitting a nop we make sure that we do not have a "test rax,..."
- // instruction after the call it is treated specially by the LoadIC code.
-    __ nop();
+    EmitNamedPropertyLoad(expr);
+    // Drop receiver left on the stack by IC.
     DropAndApply(1, expr->context(), rax);
   } else {
-    // Do a keyed property load.
     Visit(expr->key());
-    Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize));
-    __ call(ic, RelocInfo::CODE_TARGET);
-    // Notice: We must not have a "test rax, ..." instruction after the
-    // call. It is treated specially by the LoadIC code.
-    __ nop();
+    EmitKeyedPropertyLoad(expr);
     // Drop key and receiver left on the stack by IC.
     DropAndApply(2, expr->context(), rax);
   }
@@ -1053,9 +1043,10 @@
   // Record source position for debugger.
   SetSourcePosition(expr->position());
   // Call the IC initialization code.
+  InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
   Handle<Code> ic = CodeGenerator::ComputeCallInitialize(arg_count,
-                                                         NOT_IN_LOOP);
-  __ call(ic, mode);
+                                                         in_loop);
+  __ Call(ic, mode);
   // Restore context register.
   __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
   // Discard the function left on TOS.
@@ -1371,12 +1362,13 @@
     Visit(prop->obj());
     ASSERT_EQ(Expression::kValue, prop->obj()->context());
     if (assign_type == NAMED_PROPERTY) {
-      EmitNamedPropertyLoad(prop, Expression::kValue);
+      EmitNamedPropertyLoad(prop);
     } else {
       Visit(prop->key());
       ASSERT_EQ(Expression::kValue, prop->key()->context());
-      EmitKeyedPropertyLoad(prop, Expression::kValue);
-    }
+      EmitKeyedPropertyLoad(prop);
+    }
+    __ push(rax);
   }

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

Reply via email to