Enable inlining functions with contexts different than their caller.

BUG=
TEST=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9421 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 1046b1a4
...@@ -4527,14 +4527,17 @@ bool HGraphBuilder::TryInline(Call* expr) { ...@@ -4527,14 +4527,17 @@ bool HGraphBuilder::TryInline(Call* expr) {
return false; return false;
} }
// No context change required.
CompilationInfo* outer_info = info(); CompilationInfo* outer_info = info();
#if !defined(V8_TARGET_ARCH_IA32)
// Target must be able to use caller's context.
if (target->context() != outer_info->closure()->context() || if (target->context() != outer_info->closure()->context() ||
outer_info->scope()->contains_with() || outer_info->scope()->contains_with() ||
outer_info->scope()->num_heap_slots() > 0) { outer_info->scope()->num_heap_slots() > 0) {
TraceInline(target, caller, "target requires context change"); TraceInline(target, caller, "target requires context change");
return false; return false;
} }
#endif
// Don't inline deeper than kMaxInliningLevels calls. // Don't inline deeper than kMaxInliningLevels calls.
HEnvironment* env = environment(); HEnvironment* env = environment();
...@@ -4655,6 +4658,10 @@ bool HGraphBuilder::TryInline(Call* expr) { ...@@ -4655,6 +4658,10 @@ bool HGraphBuilder::TryInline(Call* expr) {
function, function,
undefined, undefined,
call_kind); call_kind);
HConstant* context = new HConstant(Handle<Context>(target->context()),
Representation::Tagged());
AddInstruction(context);
inner_env->BindContext(context);
HBasicBlock* body_entry = CreateBasicBlock(inner_env); HBasicBlock* body_entry = CreateBasicBlock(inner_env);
current_block()->Goto(body_entry); current_block()->Goto(body_entry);
body_entry->SetJoinId(expr->ReturnId()); body_entry->SetJoinId(expr->ReturnId());
......
...@@ -516,14 +516,18 @@ void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, ...@@ -516,14 +516,18 @@ void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id,
int argc, int argc,
LInstruction* instr, LInstruction* instr,
LOperand* context) { LOperand* context) {
ASSERT(context->IsRegister() || context->IsStackSlot());
if (context->IsRegister()) { if (context->IsRegister()) {
if (!ToRegister(context).is(esi)) { if (!ToRegister(context).is(esi)) {
__ mov(esi, ToRegister(context)); __ mov(esi, ToRegister(context));
} }
} else { } else if (context->IsStackSlot()) {
// Context is stack slot.
__ mov(esi, ToOperand(context)); __ mov(esi, ToOperand(context));
} else if (context->IsConstantOperand()) {
Handle<Object> literal =
chunk_->LookupLiteral(LConstantOperand::cast(context));
LoadHeapObject(esi, Handle<Context>::cast(literal));
} else {
UNREACHABLE();
} }
__ CallRuntimeSaveDoubles(id); __ CallRuntimeSaveDoubles(id);
...@@ -1235,8 +1239,13 @@ void LCodeGen::DoConstantD(LConstantD* instr) { ...@@ -1235,8 +1239,13 @@ void LCodeGen::DoConstantD(LConstantD* instr) {
void LCodeGen::DoConstantT(LConstantT* instr) { void LCodeGen::DoConstantT(LConstantT* instr) {
ASSERT(instr->result()->IsRegister()); Register reg = ToRegister(instr->result());
__ Set(ToRegister(instr->result()), Immediate(instr->value())); Handle<Object> handle = instr->value();
if (handle->IsHeapObject()) {
LoadHeapObject(reg, Handle<HeapObject>::cast(handle));
} else {
__ Set(reg, Immediate(handle));
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment