 Chromium Code Reviews
 Chromium Code Reviews Issue 305005:
  Added support for assignments to global variables in the toplevel code...  (Closed) 
  Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
    
  
    Issue 305005:
  Added support for assignments to global variables in the toplevel code...  (Closed) 
  Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/| Index: src/ia32/fast-codegen-ia32.cc | 
| =================================================================== | 
| --- src/ia32/fast-codegen-ia32.cc (revision 3091) | 
| +++ src/ia32/fast-codegen-ia32.cc (working copy) | 
| @@ -149,9 +149,10 @@ | 
| Expression* rhs = expr->value(); | 
| Visit(rhs); | 
| - // Left-hand side is always a (parameter or local) slot. | 
| + // Left-hand side can only be a global or a (parameter or local) slot. | 
| Variable* var = expr->target()->AsVariableProxy()->AsVariable(); | 
| - ASSERT(var != NULL && var->slot() != NULL); | 
| + ASSERT(var != NULL); | 
| + ASSERT(var->is_global() || var->slot() != NULL); | 
| // Complete the assignment based on the location of the right-hand-side | 
| // value and the desired location of the assignment value. | 
| @@ -160,27 +161,53 @@ | 
| ASSERT(!destination.is_constant()); | 
| ASSERT(!source.is_nowhere()); | 
| - if (source.is_temporary()) { | 
| + 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. | 
| + if (source.is_temporary()) { | 
| + __ pop(eax); | 
| + } else { | 
| + ASSERT(source.is_constant()); | 
| + ASSERT(rhs->AsLiteral() != NULL); | 
| + __ mov(eax, rhs->AsLiteral()->handle()); | 
| + } | 
| + __ 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. | 
| if (destination.is_temporary()) { | 
| - // Case 'temp1 <- (var = temp0)'. Preserve right-hand-side temporary | 
| - // on the stack. | 
| - __ mov(eax, Operand(esp, 0)); | 
| - __ mov(Operand(ebp, SlotOffset(var->slot())), eax); | 
| + __ mov(Operand(esp, 0), eax); | 
| } else { | 
| ASSERT(destination.is_nowhere()); | 
| - // Case 'var = temp'. Discard right-hand-side temporary. | 
| - __ pop(Operand(ebp, SlotOffset(var->slot()))); | 
| + __ pop(eax); | 
| 
fschneider
2009/10/20 13:58:40
We may avoid a memory access when discarding the r
 
Kevin Millikin (Chromium)
2009/10/20 14:08:48
Yes.  I didn't worry about it because:
Here we're
 | 
| } | 
| + | 
| } else { | 
| - ASSERT(source.is_constant()); | 
| - ASSERT(rhs->AsLiteral() != NULL); | 
| - // Two cases: 'temp <- (var = constant)', or 'var = constant' with a | 
| - // discarded result. Always perform the assignment. | 
| - __ mov(eax, rhs->AsLiteral()->handle()); | 
| - __ mov(Operand(ebp, SlotOffset(var->slot())), eax); | 
| - if (destination.is_temporary()) { | 
| - // Case 'temp <- (var = constant)'. Save result. | 
| - __ push(eax); | 
| + // Local or parameter assignment. | 
| + if (source.is_temporary()) { | 
| + if (destination.is_temporary()) { | 
| + // Case 'temp1 <- (var = temp0)'. Preserve right-hand-side | 
| + // temporary on the stack. | 
| + __ mov(eax, Operand(esp, 0)); | 
| + __ mov(Operand(ebp, SlotOffset(var->slot())), eax); | 
| + } else { | 
| + ASSERT(destination.is_nowhere()); | 
| + // Case 'var = temp'. Discard right-hand-side temporary. | 
| + __ pop(Operand(ebp, SlotOffset(var->slot()))); | 
| + } | 
| + } else { | 
| + ASSERT(source.is_constant()); | 
| + ASSERT(rhs->AsLiteral() != NULL); | 
| + // Two cases: 'temp <- (var = constant)', or 'var = constant' with a | 
| + // discarded result. Always perform the assignment. | 
| + __ mov(eax, rhs->AsLiteral()->handle()); | 
| + __ mov(Operand(ebp, SlotOffset(var->slot())), eax); | 
| + if (destination.is_temporary()) { | 
| + // Case 'temp <- (var = constant)'. Save result. | 
| + __ push(eax); | 
| + } | 
| } | 
| } | 
| } |