Index: src/ia32/fast-codegen-ia32.cc |
=================================================================== |
--- src/ia32/fast-codegen-ia32.cc (revision 3181) |
+++ src/ia32/fast-codegen-ia32.cc (working copy) |
@@ -65,6 +65,10 @@ |
} |
} |
+ { Comment cmnt(masm_, "[ Declarations"); |
+ VisitDeclarations(fun->scope()->declarations()); |
+ } |
+ |
{ Comment cmnt(masm_, "[ Stack check"); |
Label ok; |
ExternalReference stack_guard_limit = |
@@ -76,10 +80,6 @@ |
__ bind(&ok); |
} |
- { Comment cmnt(masm_, "[ Declarations"); |
- VisitDeclarations(fun->scope()->declarations()); |
- } |
- |
if (FLAG_trace) { |
__ CallRuntime(Runtime::kTraceEnter, 0); |
} |
@@ -92,18 +92,27 @@ |
// Emit a 'return undefined' in case control fell off the end of the |
// body. |
__ mov(eax, Factory::undefined_value()); |
+ } |
+ { Comment cmnt(masm_, "[ Return sequence"); |
SetReturnPosition(fun); |
- if (FLAG_trace) { |
- __ push(eax); |
- __ CallRuntime(Runtime::kTraceExit, 1); |
+ if (return_label_.is_bound()) { |
+ __ jmp(&return_label_); |
+ } else { |
+ // Common return label |
+ __ bind(&return_label_); |
+ |
+ if (FLAG_trace) { |
+ __ push(eax); |
+ __ CallRuntime(Runtime::kTraceExit, 1); |
+ } |
+ __ RecordJSReturn(); |
+ // Do not use the leave instruction here because it is too short to |
+ // patch with the code required by the debugger. |
+ __ mov(esp, ebp); |
+ __ pop(ebp); |
+ __ ret((fun->scope()->num_parameters() + 1) * kPointerSize); |
} |
- __ RecordJSReturn(); |
- // Do not use the leave instruction here because it is too short to |
- // patch with the code required by the debugger. |
- __ mov(esp, ebp); |
- __ pop(ebp); |
- __ ret((fun->scope()->num_parameters() + 1) * kPointerSize); |
} |
} |
@@ -171,17 +180,24 @@ |
__ pop(eax); |
} |
- if (FLAG_trace) { |
- __ push(eax); |
- __ CallRuntime(Runtime::kTraceExit, 1); |
+ if (return_label_.is_bound()) { |
+ __ jmp(&return_label_); |
+ } else { |
+ __ bind(&return_label_); |
+ |
+ if (FLAG_trace) { |
+ __ push(eax); |
+ __ CallRuntime(Runtime::kTraceExit, 1); |
+ } |
+ |
+ __ RecordJSReturn(); |
+ |
+ // Do not use the leave instruction here because it is too short to |
+ // patch with the code required by the debugger. |
+ __ mov(esp, ebp); |
+ __ pop(ebp); |
+ __ ret((function_->scope()->num_parameters() + 1) * kPointerSize); |
} |
- __ RecordJSReturn(); |
- |
- // Do not use the leave instruction here because it is too short to |
- // patch with the code required by the debugger. |
- __ mov(esp, ebp); |
- __ pop(ebp); |
- __ ret((function_->scope()->num_parameters() + 1) * kPointerSize); |
} |
@@ -484,6 +500,8 @@ |
Visit(rhs); |
__ pop(eax); |
} |
+ // Record position for debugger. |
+ SetSourcePosition(expr->position()); |
__ mov(ecx, var->name()); |
__ push(CodeGenerator::GlobalObject()); |
Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
@@ -533,6 +551,7 @@ |
// Evaluate receiver. |
Visit(expr->obj()); |
+ |
if (key->AsLiteral() != NULL && key->AsLiteral()->handle()->IsSymbol() && |
!String::cast(*(key->AsLiteral()->handle()))->AsArrayIndex(&dummy)) { |
// Do a NAMED property load. |
@@ -558,27 +577,20 @@ |
} |
-void FastCodeGenerator::VisitCall(Call* expr) { |
- Expression* fun = expr->expression(); |
+void FastCodeGenerator::EmitCallWithIC(Call* expr, RelocInfo::Mode reloc_info) { |
+ // Code common for calls using the IC. |
ZoneList<Expression*>* args = expr->arguments(); |
- Variable* var = fun->AsVariableProxy()->AsVariable(); |
- ASSERT(var != NULL && !var->is_this() && var->is_global()); |
- ASSERT(!var->is_possibly_eval()); |
- |
- __ push(Immediate(var->name())); |
- // Push global object (receiver). |
- __ push(CodeGenerator::GlobalObject()); |
int arg_count = args->length(); |
for (int i = 0; i < arg_count; i++) { |
Visit(args->at(i)); |
ASSERT_EQ(Expression::kValue, args->at(i)->context()); |
} |
- // Record source position for debugger |
+ // Record source position for debugger. |
SetSourcePosition(expr->position()); |
// Call the IC initialization code. |
Handle<Code> ic = CodeGenerator::ComputeCallInitialize(arg_count, |
NOT_IN_LOOP); |
- __ call(ic, RelocInfo::CODE_TARGET_CONTEXT); |
+ __ call(ic, reloc_info); |
// Restore context register. |
__ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
// Discard the function left on TOS. |
@@ -586,6 +598,79 @@ |
} |
+void FastCodeGenerator::EmitCallWithStub(Call* expr) { |
+ // Code common for calls using the call stub. |
+ ZoneList<Expression*>* args = expr->arguments(); |
+ int arg_count = args->length(); |
+ for (int i = 0; i < arg_count; i++) { |
+ Visit(args->at(i)); |
+ } |
+ // Record source position for debugger. |
+ SetSourcePosition(expr->position()); |
+ CallFunctionStub stub(arg_count, NOT_IN_LOOP); |
+ __ CallStub(&stub); |
+ // Restore context register. |
+ __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
+ // Discard the function left on TOS. |
+ DropAndMove(expr->context(), eax); |
+} |
+ |
+ |
+void FastCodeGenerator::VisitCall(Call* expr) { |
+ Expression* fun = expr->expression(); |
+ |
+ if (fun->AsProperty() != NULL) { |
+ // Call on a property. |
+ Property* prop = fun->AsProperty(); |
+ Literal* key = prop->key()->AsLiteral(); |
+ if (key != NULL && key->handle()->IsSymbol()) { |
+ // Call on a named property: foo.x(1,2,3) |
+ __ push(Immediate(key->handle())); |
+ Visit(prop->obj()); |
+ // Use call IC. |
+ EmitCallWithIC(expr, RelocInfo::CODE_TARGET); |
+ } else { |
+ // Call on a keyed property: foo[key](1,2,3) |
+ // Use a keyed load IC followed by a call IC. |
+ Visit(prop->obj()); |
+ Visit(prop->key()); |
+ // Record source position of property. |
+ SetSourcePosition(prop->position()); |
+ 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. |
+ __ add(Operand(esp), Immediate(kPointerSize)); |
+ // Pop receiver. |
+ __ pop(ebx); |
+ // Push result (function). |
+ __ push(eax); |
+ // Push receiver object on stack. |
+ if (prop->is_synthetic()) { |
+ __ push(CodeGenerator::GlobalObject()); |
+ } else { |
+ __ push(ebx); |
+ } |
+ EmitCallWithStub(expr); |
+ } |
+ } else if (fun->AsVariableProxy()->AsVariable() != NULL) { |
+ // Call on a global variable |
+ Variable* var = fun->AsVariableProxy()->AsVariable(); |
+ ASSERT(var != NULL && !var->is_this() && var->is_global()); |
+ ASSERT(!var->is_possibly_eval()); |
+ __ push(Immediate(var->name())); |
+ // Push global object (receiver). |
+ __ push(CodeGenerator::GlobalObject()); |
+ EmitCallWithIC(expr, RelocInfo::CODE_TARGET_CONTEXT); |
+ } else { |
+ // Calls we cannot handle right now. |
+ // Should bailout in the CodeGenSelector. |
+ UNREACHABLE(); |
+ } |
+} |
+ |
void FastCodeGenerator::VisitCallNew(CallNew* expr) { |
Comment cmnt(masm_, "[ CallNew"); |
// According to ECMA-262, section 11.2.2, page 44, the function |