Skip to content

Commit efd2068

Browse files
author
kmillikin@chromium.org
committed
In the toplevel code generator, support local context allocation
provided that none of the parameters need to be copied into the context. Review URL: http://codereview.chromium.org/369003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3224 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
1 parent e8db709 commit efd2068

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

src/arm/fast-codegen-arm.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ void FastCodeGenerator::Generate(FunctionLiteral* fun) {
7171
}
7272
}
7373

74+
// Possibly allocate a local context.
75+
if (fun->scope()->num_heap_slots() > 0) {
76+
Comment cmnt(masm_, "[ Allocate local context");
77+
// Argument to NewContext is the function, still in r1.
78+
__ push(r1);
79+
__ CallRuntime(Runtime::kNewContext, 1);
80+
// Context is returned in both r0 and cp. It replaces the context
81+
// passed to us. It's saved in the stack and kept live in cp.
82+
__ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
83+
#ifdef DEBUG
84+
// Assert we do not have to copy any parameters into the context.
85+
for (int i = 0, len = fun->scope()->num_parameters(); i < len; i++) {
86+
Slot* slot = fun->scope()->parameter(i)->slot();
87+
ASSERT(slot != NULL && slot->type() != Slot::CONTEXT);
88+
}
89+
#endif
90+
}
91+
7492
// Check the stack for overflow or break request.
7593
// Put the lr setup instruction in the delay slot. The kInstrSize is
7694
// added to the implicit 8 byte offset that always applies to operations

src/compiler.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,21 @@ void Compiler::SetFunctionInfo(Handle<JSFunction> fun,
585585

586586
CodeGenSelector::CodeGenTag CodeGenSelector::Select(FunctionLiteral* fun) {
587587
Scope* scope = fun->scope();
588+
589+
if (scope->num_heap_slots() > 0) {
590+
// We support functions with a local context if they do not have
591+
// parameters that need to be copied into the context.
592+
for (int i = 0, len = scope->num_parameters(); i < len; i++) {
593+
Slot* slot = scope->parameter(i)->slot();
594+
if (slot != NULL && slot->type() == Slot::CONTEXT) {
595+
if (FLAG_trace_bailout) {
596+
PrintF("function has context-allocated parameters");
597+
}
598+
return NORMAL;
599+
}
600+
}
601+
}
602+
588603
if (scope->num_heap_slots() != 0) {
589604
if (FLAG_trace_bailout) PrintF("function has context slots\n");
590605
return NORMAL;

src/ia32/fast-codegen-ia32.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ void FastCodeGenerator::Generate(FunctionLiteral* fun) {
6767
}
6868
}
6969

70+
// Possibly allocate a local context.
71+
if (fun->scope()->num_heap_slots() > 0) {
72+
Comment cmnt(masm_, "[ Allocate local context");
73+
// Argument to NewContext is the function, still in edi.
74+
__ push(edi);
75+
__ CallRuntime(Runtime::kNewContext, 1);
76+
// Context is returned in both eax and esi. It replaces the context
77+
// passed to us. It's saved in the stack and kept live in esi.
78+
__ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi);
79+
#ifdef DEBUG
80+
// Assert we do not have to copy any parameters into the context.
81+
for (int i = 0, len = fun->scope()->num_parameters(); i < len; i++) {
82+
Slot* slot = fun->scope()->parameter(i)->slot();
83+
ASSERT(slot != NULL && slot->type() != Slot::CONTEXT);
84+
}
85+
#endif
86+
}
87+
7088
{ Comment cmnt(masm_, "[ Declarations");
7189
VisitDeclarations(fun->scope()->declarations());
7290
}

src/x64/fast-codegen-x64.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ void FastCodeGenerator::Generate(FunctionLiteral* fun) {
6767
}
6868
}
6969

70+
// Possibly allocate a local context.
71+
if (fun->scope()->num_heap_slots() > 0) {
72+
Comment cmnt(masm_, "[ Allocate local context");
73+
// Argument to NewContext is the function, still in rdi.
74+
__ push(rdi);
75+
__ CallRuntime(Runtime::kNewContext, 1);
76+
// Context is returned in both rax and rsi. It replaces the context
77+
// passed to us. It's saved in the stack and kept live in rsi.
78+
__ movq(Operand(rbp, StandardFrameConstants::kContextOffset), rsi);
79+
#ifdef DEBUG
80+
// Assert we do not have to copy any parameters into the context.
81+
for (int i = 0, len = fun->scope()->num_parameters(); i < len; i++) {
82+
Slot* slot = fun->scope()->parameter(i)->slot();
83+
ASSERT(slot != NULL && slot->type() != Slot::CONTEXT);
84+
}
85+
#endif
86+
}
87+
7088
{ Comment cmnt(masm_, "[ Stack check");
7189
Label ok;
7290
__ CompareRoot(rsp, Heap::kStackLimitRootIndex);

0 commit comments

Comments
 (0)