Index: src/ia32/fast-codegen-ia32.cc |
=================================================================== |
--- src/ia32/fast-codegen-ia32.cc (revision 3195) |
+++ src/ia32/fast-codegen-ia32.cc (working copy) |
@@ -586,21 +586,24 @@ |
} |
-void FastCodeGenerator::EmitVariableAssignment(Expression::Context context, |
- Variable* var) { |
+void FastCodeGenerator::EmitVariableAssignment(Assignment* expr) { |
+ Variable* var = expr->target()->AsVariableProxy()->AsVariable(); |
+ ASSERT(var != NULL); |
+ |
if (var->is_global()) { |
- // Assignment to a global variable, use inline caching. Right-hand-side |
- // value is passed in eax, variable name in ecx, and the global object |
- // on the stack. |
+ // Assignment to a global variable. Use inline caching for the |
+ // assignment. Right-hand-side value is passed in eax, variable name in |
+ // ecx, and the global object on the stack. |
__ pop(eax); |
__ mov(ecx, var->name()); |
__ push(CodeGenerator::GlobalObject()); |
Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
__ call(ic, RelocInfo::CODE_TARGET); |
- // Overwrite the global object on the stack with the result if needed. |
- DropAndMove(context, eax); |
+ // Overwrite the receiver on the stack with the result if needed. |
+ DropAndMove(expr->context(), eax); |
+ |
} else { |
- switch (context) { |
+ switch (expr->context()) { |
case Expression::kUninitialized: |
UNREACHABLE(); |
case Expression::kEffect: |
@@ -643,28 +646,68 @@ |
} |
-void FastCodeGenerator::EmitNamedPropertyAssignment( |
- Expression::Context context, |
- Handle<Object> name) { |
+void FastCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
+ // Assignment to a property, using a named store IC. |
+ Property* prop = expr->target()->AsProperty(); |
+ ASSERT(prop != NULL); |
+ ASSERT(prop->key()->AsLiteral() != NULL); |
+ |
+ // If the assignment starts a block of assignments to the same object, |
+ // change to slow case to avoid the quadratic behavior of repeatedly |
+ // adding fast properties. |
+ if (expr->starts_initialization_block()) { |
+ __ push(Operand(esp, kPointerSize)); // Receiver is under value. |
+ __ CallRuntime(Runtime::kToSlowProperties, 1); |
+ } |
+ |
__ pop(eax); |
- __ mov(ecx, name); |
+ __ mov(ecx, prop->key()->AsLiteral()->handle()); |
Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
__ call(ic, RelocInfo::CODE_TARGET); |
- DropAndMove(context, eax); |
+ |
+ // If the assignment ends an initialization block, revert to fast case. |
+ if (expr->ends_initialization_block()) { |
+ __ push(eax); // Result of assignment, saved even if not needed. |
+ __ push(Operand(esp, kPointerSize)); // Receiver is under value. |
+ __ CallRuntime(Runtime::kToFastProperties, 1); |
+ __ pop(eax); |
+ } |
+ |
+ DropAndMove(expr->context(), eax); |
} |
-void FastCodeGenerator::EmitKeyedPropertyAssignment( |
- Expression::Context context) { |
+void FastCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
+ // Assignment to a property, using a keyed store IC. |
+ |
+ // If the assignment starts a block of assignments to the same object, |
+ // change to slow case to avoid the quadratic behavior of repeatedly |
+ // adding fast properties. |
+ if (expr->starts_initialization_block()) { |
+ // Reciever is under the key and value. |
+ __ push(Operand(esp, 2 * kPointerSize)); |
+ __ CallRuntime(Runtime::kToSlowProperties, 1); |
+ } |
+ |
__ pop(eax); |
Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
__ call(ic, RelocInfo::CODE_TARGET); |
// This nop signals to the IC that there is no inlined code at the call |
// site for it to patch. |
__ nop(); |
+ |
+ // If the assignment ends an initialization block, revert to fast case. |
+ if (expr->ends_initialization_block()) { |
+ __ push(eax); // Result of assignment, saved even if not needed. |
+ // Reciever is under the key and value. |
+ __ push(Operand(esp, 2 * kPointerSize)); |
+ __ CallRuntime(Runtime::kToFastProperties, 1); |
+ __ pop(eax); |
+ } |
+ |
// Receiver and key are still on stack. |
__ add(Operand(esp), Immediate(2 * kPointerSize)); |
- Move(context, eax); |
+ Move(expr->context(), eax); |
} |