Chromium Code Reviews| Index: src/x64/fast-codegen-x64.cc |
| =================================================================== |
| --- src/x64/fast-codegen-x64.cc (revision 3133) |
| +++ src/x64/fast-codegen-x64.cc (working copy) |
| @@ -144,18 +144,15 @@ |
| Comment cmnt(masm_, "[ ReturnStatement"); |
| SetStatementPosition(stmt); |
| Expression* expr = stmt->expression(); |
| - Visit(expr); |
| - |
| - // Complete the statement based on the location of the subexpression. |
| - Location source = expr->location(); |
| - ASSERT(!source.is_nowhere()); |
| - if (source.is_temporary()) { |
| - __ pop(rax); |
| - } else { |
| - ASSERT(source.is_constant()); |
| - ASSERT(expr->AsLiteral() != NULL); |
| + // Complete the statement based on the type of the subexpression. |
| + if (expr->AsLiteral() != NULL) { |
| __ Move(rax, expr->AsLiteral()->handle()); |
| + } else { |
| + Visit(expr); |
| + ASSERT(expr->location().is_temporary()); |
| + __ pop(rax); |
| } |
| + |
| if (FLAG_trace) { |
| __ push(rax); |
| __ CallRuntime(Runtime::kTraceExit, 1); |
| @@ -237,6 +234,15 @@ |
| } |
| +void FastCodeGenerator::VisitLiteral(Literal* expr) { |
| + if (expr->location().is_temporary()) { |
| + __ Push(expr->handle()); |
| + } else { |
| + ASSERT(expr->location().is_nowhere()); |
| + } |
| +} |
| + |
| + |
| void FastCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| Comment cmnt(masm_, "[ ObjectLiteral"); |
| Label boilerplate_exists; |
| @@ -301,9 +307,7 @@ |
| case ObjectLiteral::Property::PROTOTYPE: |
| __ push(rax); |
| Visit(key); |
| - if (key->location().is_constant()) { |
| - __ Push(key->handle()); |
| - } |
| + ASSERT(key->location().is_temporary()); |
| Visit(value); |
| ASSERT(value->location().is_temporary()); |
| __ CallRuntime(Runtime::kSetProperty, 3); |
| @@ -313,9 +317,7 @@ |
| case ObjectLiteral::Property::GETTER: |
| __ push(rax); |
| Visit(key); |
| - if (key->location().is_constant()) { |
| - __ Push(key->handle()); |
| - } |
| + ASSERT(key->location.is_temporary()); |
| __ Push(property->kind() == ObjectLiteral::Property::SETTER ? |
| Smi::FromInt(1) : |
| Smi::FromInt(0)); |
| @@ -439,31 +441,26 @@ |
| void FastCodeGenerator::VisitAssignment(Assignment* expr) { |
| Comment cmnt(masm_, "[ Assignment"); |
| ASSERT(expr->op() == Token::ASSIGN || expr->op() == Token::INIT_VAR); |
| - Expression* rhs = expr->value(); |
| - Visit(rhs); |
| // Left-hand side can only be a global or a (parameter or local) slot. |
| Variable* var = expr->target()->AsVariableProxy()->AsVariable(); |
| 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. |
| + Expression* rhs = expr->value(); |
| Location destination = expr->location(); |
| - Location source = rhs->location(); |
| - ASSERT(!destination.is_constant()); |
| - ASSERT(!source.is_nowhere()); |
| - |
| if (var->is_global()) { |
| // Assignment to a global variable, use inline caching. Right-hand-side |
| // value is passed in rax, variable name in rcx, and the global object |
| // on the stack. |
| - if (source.is_temporary()) { |
| - __ pop(rax); |
| - } else { |
| - ASSERT(source.is_constant()); |
| - ASSERT(rhs->AsLiteral() != NULL); |
| + |
| + // Code for the right-hand-side expression depends on its type. |
| + if (rhs->AsLiteral() != NULL) { |
| __ Move(rax, rhs->AsLiteral()->handle()); |
| + } else { |
| + ASSERT(rhs->location().is_temporary()); |
| + Visit(rhs); |
| + __ pop(rax); |
| } |
| __ Move(rcx, var->name()); |
| __ push(CodeGenerator::GlobalObject()); |
| @@ -476,8 +473,22 @@ |
| __ addq(rsp, Immediate(kPointerSize)); |
| } |
| } else { |
| - if (source.is_temporary()) { |
| + // Local or parameter assignment. |
| + |
| + // Code for the right-hand-side expression depends on its type. |
| + if (rhs->AsLiteral() != NULL) { |
| + // Two cases: 'temp <- (var = constant)', or 'var = constant' with a |
| + // discarded result. Always perform the assignment. |
| + __ Move(kScratchRegister, rhs->AsLiteral()->handle()); |
| + __ movq(Operand(rbp, SlotOffset(var->slot())), kScratchRegister); |
| if (destination.is_temporary()) { |
| + // Case 'temp <- (var = constant)'. Save result. |
| + __ push(kScratchRegister); |
| + } |
|
fschneider
2009/10/26 17:57:20
Add an assert here to be consistent with the rest
|
| + } else { |
| + ASSERT(rhs->location().is_temporary()); |
| + Visit(rhs); |
| + if (destination.is_temporary()) { |
| // Case 'temp1 <- (var = temp0)'. Preserve right-hand-side temporary |
| // on the stack. |
| __ movq(kScratchRegister, Operand(rsp, 0)); |
| @@ -487,17 +498,6 @@ |
| // Case 'var = temp'. Discard right-hand-side temporary. |
| __ pop(Operand(rbp, 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. |
| - __ Move(kScratchRegister, rhs->AsLiteral()->handle()); |
| - __ movq(Operand(rbp, SlotOffset(var->slot())), kScratchRegister); |
| - if (destination.is_temporary()) { |
| - // Case 'temp <- (var = constant)'. Save result. |
| - __ push(kScratchRegister); |
| - } |
| } |
| } |
| } |
| @@ -516,11 +516,7 @@ |
| int arg_count = args->length(); |
| for (int i = 0; i < arg_count; i++) { |
| Visit(args->at(i)); |
| - ASSERT(!args->at(i)->location().is_nowhere()); |
| - if (args->at(i)->location().is_constant()) { |
| - ASSERT(args->at(i)->AsLiteral() != NULL); |
| - __ Push(args->at(i)->AsLiteral()->handle()); |
| - } |
| + ASSERT(args->at(i)->location().is_temporary()); |
| } |
| // Record source position for debugger |
| SetSourcePosition(expr->position()); |
| @@ -551,15 +547,7 @@ |
| int arg_count = args->length(); |
| for (int i = 0; i < arg_count; i++) { |
| Visit(args->at(i)); |
| - ASSERT(!args->at(i)->location().is_nowhere()); |
| - if (args->at(i)->location().is_constant()) { |
| - ASSERT(args->at(i)->AsLiteral() != NULL); |
| - __ Push(args->at(i)->AsLiteral()->handle()); |
| - } else { |
| - ASSERT(args->at(i)->location().is_temporary()); |
| - // If location is temporary, it is already on the stack, |
| - // so nothing to do here. |
| - } |
| + ASSERT(args->at(i)->location().is_temporary()); |
| } |
| __ CallRuntime(function, arg_count); |
| @@ -580,21 +568,21 @@ |
| Label eval_right, done; |
| Location destination = expr->location(); |
| - ASSERT(!destination.is_constant()); |
| - |
| Expression* left = expr->left(); |
| - Location left_source = left->location(); |
| - ASSERT(!left_source.is_nowhere()); |
| - |
| Expression* right = expr->right(); |
| - Location right_source = right->location(); |
| - ASSERT(!right_source.is_nowhere()); |
| - Visit(left); |
| // Use the shared ToBoolean stub to find the boolean value of the |
| // left-hand subexpression. Load the value into rax to perform some |
| // inlined checks assumed by the stub. |
| - if (left_source.is_temporary()) { |
| + |
| + // Compile the left-hand value into rax. Put it on the stack if we may |
| + // need it as the value of the whole expression. |
| + if (left->AsLiteral() != NULL) { |
| + __ Move(rax, left->AsLiteral()->handle()); |
| + if (destination.is_temporary()) __ push(rax); |
|
fschneider
2009/10/26 17:57:20
May want to add an assert here to be consistent wi
|
| + } else { |
| + Visit(left); |
| + ASSERT(left->location().is_temporary()); |
| if (destination.is_temporary()) { |
| // Copy the left-hand value into rax because we may need it as the |
| // final result. |
| @@ -604,12 +592,6 @@ |
| // final result. |
| __ pop(rax); |
|
fschneider
2009/10/26 17:57:20
Adding an assert to be consistent on all platforms
|
| } |
| - } else { |
| - // Load the left-hand value into rax. Put it on the stack if we may |
| - // need it. |
| - ASSERT(left->AsLiteral() != NULL); |
| - __ Move(rax, left->AsLiteral()->handle()); |
| - if (destination.is_temporary()) __ push(rax); |
| } |
| // The left-hand value is in rax. It is also on the stack iff the |
| // destination location is temporary. |
| @@ -640,14 +622,21 @@ |
| if (destination.is_temporary()) { |
| __ addq(rsp, Immediate(kPointerSize)); |
| } |
| - Visit(right); |
| - |
| // Save or discard the right-hand value as needed. |
| - if (destination.is_temporary() && right_source.is_constant()) { |
| - ASSERT(right->AsLiteral() != NULL); |
| - __ Push(right->AsLiteral()->handle()); |
| - } else if (destination.is_nowhere() && right_source.is_temporary()) { |
| - __ addq(rsp, Immediate(kPointerSize)); |
| + if (right->AsLiteral() != NULL) { |
| + if (destination.is_temporary()) { |
| + __ Push(right->AsLiteral()->handle()); |
| + } else { |
| + ASSERT(destination.is_nowhere()); |
| + } |
| + } else { |
| + Visit(right); |
| + ASSERT(right->location().is_temporary()); |
| + if (destination.is_nowhere()) { |
| + __ addq(rsp, Immediate(kPointerSize)); |
| + } else { |
| + ASSERT(destination.is_temporary()); |
| + } |
| } |
| __ bind(&done); |