ARM side of load optimization in the presence of eval.

Review URL: http://codereview.chromium.org/20453

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1301 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
ager@chromium.org 2009-02-18 13:54:13 +00:00
parent ddd2ac4015
commit cafe25f258
3 changed files with 117 additions and 8 deletions

View File

@ -369,7 +369,7 @@ MemOperand CodeGenerator::SlotOperand(Slot* slot, Register tmp) {
ASSERT(!tmp.is(cp)); // do not overwrite context register ASSERT(!tmp.is(cp)); // do not overwrite context register
Register context = cp; Register context = cp;
int chain_length = scope()->ContextChainLength(slot->var()->scope()); int chain_length = scope()->ContextChainLength(slot->var()->scope());
for (int i = chain_length; i-- > 0;) { for (int i = 0; i < chain_length; i++) {
// Load the closure. // Load the closure.
// (All contexts, even 'with' contexts, have a closure, // (All contexts, even 'with' contexts, have a closure,
// and it is the same for all contexts inside a function. // and it is the same for all contexts inside a function.
@ -397,6 +397,35 @@ MemOperand CodeGenerator::SlotOperand(Slot* slot, Register tmp) {
} }
MemOperand CodeGenerator::ContextSlotOperandCheckExtensions(Slot* slot,
Register tmp,
Register tmp2,
Label* slow) {
ASSERT(slot->type() == Slot::CONTEXT);
int index = slot->index();
Register context = cp;
for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) {
if (s->num_heap_slots() > 0) {
if (s->calls_eval()) {
// Check that extension is NULL.
__ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX));
__ tst(tmp2, tmp2);
__ b(ne, slow);
}
__ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX));
__ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset));
context = tmp;
}
}
// Check that last extension is NULL.
__ ldr(tmp2, ContextOperand(tmp, Context::EXTENSION_INDEX));
__ tst(tmp2, tmp2);
__ b(ne, slow);
__ ldr(tmp, ContextOperand(tmp, Context::FCONTEXT_INDEX));
return ContextOperand(tmp, index);
}
// Loads a value on TOS. If it is a boolean value, the result may have been // Loads a value on TOS. If it is a boolean value, the result may have been
// (partially) translated into branches, or it may have set the condition // (partially) translated into branches, or it may have set the condition
// code register. If force_cc is set, the value is forced to set the // code register. If force_cc is set, the value is forced to set the
@ -1985,7 +2014,28 @@ void CodeGenerator::LoadFromSlot(Slot* slot, TypeofState typeof_state) {
if (slot->type() == Slot::LOOKUP) { if (slot->type() == Slot::LOOKUP) {
ASSERT(slot->var()->is_dynamic()); ASSERT(slot->var()->is_dynamic());
// For now, just do a runtime call. Label slow, done;
// Generate fast-case code for variables that might be shadowed by
// eval-introduced variables. Eval is used a lot without
// introducing variables. In those cases, we do not want to
// perform a runtime call for all variables in the scope
// containing the eval.
if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) {
LoadFromGlobalSlotCheckExtensions(slot, typeof_state, r1, r2, &slow);
__ b(&done);
} else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) {
Slot* potential_slot = slot->var()->local_if_not_shadowed()->slot();
__ ldr(r0,
ContextSlotOperandCheckExtensions(potential_slot,
r1,
r2,
&slow));
__ b(&done);
}
__ bind(&slow);
frame_->Push(cp); frame_->Push(cp);
__ mov(r0, Operand(slot->var()->name())); __ mov(r0, Operand(slot->var()->name()));
frame_->Push(r0); frame_->Push(r0);
@ -1995,6 +2045,8 @@ void CodeGenerator::LoadFromSlot(Slot* slot, TypeofState typeof_state) {
} else { } else {
__ CallRuntime(Runtime::kLoadContextSlot, 2); __ CallRuntime(Runtime::kLoadContextSlot, 2);
} }
__ bind(&done);
frame_->Push(r0); frame_->Push(r0);
} else { } else {
@ -2019,6 +2071,51 @@ void CodeGenerator::LoadFromSlot(Slot* slot, TypeofState typeof_state) {
} }
void CodeGenerator::LoadFromGlobalSlotCheckExtensions(Slot* slot,
TypeofState typeof_state,
Register tmp,
Register tmp2,
Label* slow) {
// Check that no extension objects have been created by calls to
// eval from the current scope to the global scope.
Register context = cp;
for (Scope* s = scope(); s != NULL; s = s->outer_scope()) {
if (s->num_heap_slots() > 0) {
if (s->calls_eval()) {
// Check that extension is NULL.
__ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX));
__ tst(tmp2, tmp2);
__ b(ne, slow);
}
// Load next context in chain.
__ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX));
__ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset));
context = tmp;
}
// If no outer scope calls eval, we do not need to check more
// context extensions.
if (!s->outer_scope_calls_eval()) break;
}
// All extension objects were empty and it is safe to use a global
// load IC call.
Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
// Load the global object.
LoadGlobal();
// Setup the name register.
__ mov(r2, Operand(slot->var()->name()));
// Call IC stub.
if (typeof_state == INSIDE_TYPEOF) {
__ Call(ic, RelocInfo::CODE_TARGET);
} else {
__ Call(ic, RelocInfo::CODE_TARGET_CONTEXT);
}
// Pop the global object. The result is in r0.
frame_->Pop();
}
void CodeGenerator::VisitSlot(Slot* node) { void CodeGenerator::VisitSlot(Slot* node) {
Comment cmnt(masm_, "[ Slot"); Comment cmnt(masm_, "[ Slot");
LoadFromSlot(node, typeof_state()); LoadFromSlot(node, typeof_state());

View File

@ -256,6 +256,11 @@ class CodeGenerator: public AstVisitor {
MemOperand SlotOperand(Slot* slot, Register tmp); MemOperand SlotOperand(Slot* slot, Register tmp);
MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
Register tmp,
Register tmp2,
Label* slow);
// Expressions // Expressions
MemOperand GlobalObject() const { MemOperand GlobalObject() const {
return ContextOperand(cp, Context::GLOBAL_INDEX); return ContextOperand(cp, Context::GLOBAL_INDEX);
@ -272,6 +277,11 @@ class CodeGenerator: public AstVisitor {
// Read a value from a slot and leave it on top of the expression stack. // Read a value from a slot and leave it on top of the expression stack.
void LoadFromSlot(Slot* slot, TypeofState typeof_state); void LoadFromSlot(Slot* slot, TypeofState typeof_state);
void LoadFromGlobalSlotCheckExtensions(Slot* slot,
TypeofState typeof_state,
Register tmp,
Register tmp2,
Label* slow);
// Special code for typeof expressions: Unfortunately, we must // Special code for typeof expressions: Unfortunately, we must
// be careful when loading the expression in 'typeof' // be careful when loading the expression in 'typeof'

View File

@ -455,16 +455,17 @@ Operand CodeGenerator::ContextSlotOperandCheckExtensions(Slot* slot,
Label* slow) { Label* slow) {
ASSERT(slot->type() == Slot::CONTEXT); ASSERT(slot->type() == Slot::CONTEXT);
int index = slot->index(); int index = slot->index();
__ mov(tmp, Operand(esi)); Register context = esi;
for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) { for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) {
if (s->num_heap_slots() > 0) { if (s->num_heap_slots() > 0) {
if (s->calls_eval()) { if (s->calls_eval()) {
// Check that extension is NULL. // Check that extension is NULL.
__ cmp(ContextOperand(tmp, Context::EXTENSION_INDEX), Immediate(0)); __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0));
__ j(not_equal, slow, not_taken); __ j(not_equal, slow, not_taken);
} }
__ mov(tmp, ContextOperand(tmp, Context::CLOSURE_INDEX)); __ mov(tmp, ContextOperand(context, Context::CLOSURE_INDEX));
__ mov(tmp, FieldOperand(tmp, JSFunction::kContextOffset)); __ mov(tmp, FieldOperand(tmp, JSFunction::kContextOffset));
context = tmp;
} }
} }
// Check that last extension is NULL. // Check that last extension is NULL.
@ -2412,17 +2413,18 @@ void CodeGenerator::LoadFromGlobalSlotCheckExtensions(Slot* slot,
Label* slow) { Label* slow) {
// Check that no extension objects have been created by calls to // Check that no extension objects have been created by calls to
// eval from the current scope to the global scope. // eval from the current scope to the global scope.
__ mov(tmp, Operand(esi)); Register context = esi;
for (Scope* s = scope(); s != NULL; s = s->outer_scope()) { for (Scope* s = scope(); s != NULL; s = s->outer_scope()) {
if (s->num_heap_slots() > 0) { if (s->num_heap_slots() > 0) {
if (s->calls_eval()) { if (s->calls_eval()) {
// Check that extension is NULL. // Check that extension is NULL.
__ cmp(ContextOperand(tmp, Context::EXTENSION_INDEX), Immediate(0)); __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0));
__ j(not_equal, slow, not_taken); __ j(not_equal, slow, not_taken);
} }
// Load next context in chain. // Load next context in chain.
__ mov(tmp, ContextOperand(tmp, Context::CLOSURE_INDEX)); __ mov(tmp, ContextOperand(context, Context::CLOSURE_INDEX));
__ mov(tmp, FieldOperand(tmp, JSFunction::kContextOffset)); __ mov(tmp, FieldOperand(tmp, JSFunction::kContextOffset));
context = tmp;
} }
// If no outer scope calls eval, we do not need to check more // If no outer scope calls eval, we do not need to check more
// context extensions. // context extensions.