Commit e7027442 authored by mbrandy's avatar mbrandy Committed by Commit bot

PPC: Crankshaft is now able to compile top level code even if there is a ScriptContext.

Port 29ebcc32

Original commit message:
    This CL introduces HPrologue instruction which does the context allocation work and supports deoptimization.

R=ishell@chromium.org, jyan@ca.ibm.com, dstence@us.ibm.com, joransiu@ca.ibm.com
BUG=

Review URL: https://codereview.chromium.org/1324023002

Cr-Commit-Position: refs/heads/master@{#30516}
parent 07bc0117
...@@ -186,7 +186,7 @@ void FullCodeGenerator::Generate() { ...@@ -186,7 +186,7 @@ void FullCodeGenerator::Generate() {
} }
} }
bool function_in_register = true; bool function_in_register_r4 = true;
// Possibly allocate a local context. // Possibly allocate a local context.
if (info->scope()->num_heap_slots() > 0) { if (info->scope()->num_heap_slots() > 0) {
...@@ -207,7 +207,7 @@ void FullCodeGenerator::Generate() { ...@@ -207,7 +207,7 @@ void FullCodeGenerator::Generate() {
__ push(r4); __ push(r4);
__ CallRuntime(Runtime::kNewFunctionContext, 1); __ CallRuntime(Runtime::kNewFunctionContext, 1);
} }
function_in_register = false; function_in_register_r4 = false;
// Context is returned in r3. It replaces the context passed to us. // Context is returned in r3. It replaces the context passed to us.
// It's saved in the stack and kept live in cp. // It's saved in the stack and kept live in cp.
__ mr(cp, r3); __ mr(cp, r3);
...@@ -240,14 +240,19 @@ void FullCodeGenerator::Generate() { ...@@ -240,14 +240,19 @@ void FullCodeGenerator::Generate() {
} }
} }
PrepareForBailoutForId(BailoutId::Prologue(), NO_REGISTERS);
// Function register is trashed in case we bailout here. But since that
// could happen only when we allocate a context the value of
// |function_in_register_r4| is correct.
// Possibly set up a local binding to the this function which is used in // Possibly set up a local binding to the this function which is used in
// derived constructors with super calls. // derived constructors with super calls.
Variable* this_function_var = scope()->this_function_var(); Variable* this_function_var = scope()->this_function_var();
if (this_function_var != nullptr) { if (this_function_var != nullptr) {
Comment cmnt(masm_, "[ This function"); Comment cmnt(masm_, "[ This function");
if (!function_in_register) { if (!function_in_register_r4) {
__ LoadP(r4, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); __ LoadP(r4, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
// The write barrier clobbers register again, keep is marked as such. // The write barrier clobbers register again, keep it marked as such.
} }
SetVar(this_function_var, r4, r3, r5); SetVar(this_function_var, r4, r3, r5);
} }
...@@ -271,6 +276,7 @@ void FullCodeGenerator::Generate() { ...@@ -271,6 +276,7 @@ void FullCodeGenerator::Generate() {
__ LoadP(r4, MemOperand(r5, StandardFrameConstants::kMarkerOffset)); __ LoadP(r4, MemOperand(r5, StandardFrameConstants::kMarkerOffset));
__ CmpSmiLiteral(r4, Smi::FromInt(StackFrame::CONSTRUCT), r0); __ CmpSmiLiteral(r4, Smi::FromInt(StackFrame::CONSTRUCT), r0);
Label non_construct_frame, done; Label non_construct_frame, done;
function_in_register_r4 = false;
__ bne(&non_construct_frame); __ bne(&non_construct_frame);
__ LoadP(r3, MemOperand( __ LoadP(r3, MemOperand(
...@@ -298,6 +304,7 @@ void FullCodeGenerator::Generate() { ...@@ -298,6 +304,7 @@ void FullCodeGenerator::Generate() {
__ LoadSmiLiteral(r4, Smi::FromInt(rest_index)); __ LoadSmiLiteral(r4, Smi::FromInt(rest_index));
__ LoadSmiLiteral(r3, Smi::FromInt(language_mode())); __ LoadSmiLiteral(r3, Smi::FromInt(language_mode()));
__ Push(r6, r5, r4, r3); __ Push(r6, r5, r4, r3);
function_in_register_r4 = false;
RestParamAccessStub stub(isolate()); RestParamAccessStub stub(isolate());
__ CallStub(&stub); __ CallStub(&stub);
...@@ -309,7 +316,7 @@ void FullCodeGenerator::Generate() { ...@@ -309,7 +316,7 @@ void FullCodeGenerator::Generate() {
if (arguments != NULL) { if (arguments != NULL) {
// Function uses arguments object. // Function uses arguments object.
Comment cmnt(masm_, "[ Allocate arguments object"); Comment cmnt(masm_, "[ Allocate arguments object");
if (!function_in_register) { if (!function_in_register_r4) {
// Load this again, if it's used by the local context below. // Load this again, if it's used by the local context below.
__ LoadP(r6, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); __ LoadP(r6, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
} else { } else {
......
...@@ -176,16 +176,27 @@ bool LCodeGen::GeneratePrologue() { ...@@ -176,16 +176,27 @@ bool LCodeGen::GeneratePrologue() {
if (info()->saves_caller_doubles()) { if (info()->saves_caller_doubles()) {
SaveCallerDoubles(); SaveCallerDoubles();
} }
return !is_aborted();
}
void LCodeGen::DoPrologue(LPrologue* instr) {
Comment(";;; Prologue begin");
// Possibly allocate a local context. // Possibly allocate a local context.
int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; if (info()->scope()->num_heap_slots() > 0) {
if (heap_slots > 0) {
Comment(";;; Allocate local context"); Comment(";;; Allocate local context");
bool need_write_barrier = true; bool need_write_barrier = true;
// Argument to NewContext is the function, which is in r4. // Argument to NewContext is the function, which is in r4.
DCHECK(!info()->scope()->is_script_scope()); int slots = info()->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
if (heap_slots <= FastNewContextStub::kMaximumSlots) { Safepoint::DeoptMode deopt_mode = Safepoint::kNoLazyDeopt;
FastNewContextStub stub(isolate(), heap_slots); if (info()->scope()->is_script_scope()) {
__ push(r4);
__ Push(info()->scope()->GetScopeInfo(info()->isolate()));
__ CallRuntime(Runtime::kNewScriptContext, 2);
deopt_mode = Safepoint::kLazyDeopt;
} else if (slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(isolate(), slots);
__ CallStub(&stub); __ CallStub(&stub);
// Result of FastNewContextStub is always in new space. // Result of FastNewContextStub is always in new space.
need_write_barrier = false; need_write_barrier = false;
...@@ -193,7 +204,8 @@ bool LCodeGen::GeneratePrologue() { ...@@ -193,7 +204,8 @@ bool LCodeGen::GeneratePrologue() {
__ push(r4); __ push(r4);
__ CallRuntime(Runtime::kNewFunctionContext, 1); __ CallRuntime(Runtime::kNewFunctionContext, 1);
} }
RecordSafepoint(Safepoint::kNoLazyDeopt); RecordSafepoint(deopt_mode);
// Context is returned in both r3 and cp. It replaces the context // Context is returned in both r3 and cp. It replaces the context
// passed to us. It's saved in the stack and kept live in cp. // passed to us. It's saved in the stack and kept live in cp.
__ mr(cp, r3); __ mr(cp, r3);
...@@ -226,13 +238,7 @@ bool LCodeGen::GeneratePrologue() { ...@@ -226,13 +238,7 @@ bool LCodeGen::GeneratePrologue() {
Comment(";;; End allocate local context"); Comment(";;; End allocate local context");
} }
// Trace the call. Comment(";;; Prologue end");
if (FLAG_trace && info()->IsOptimizing()) {
// We have not executed any compiled code yet, so cp still holds the
// incoming context.
__ CallRuntime(Runtime::kTraceEnter, 0);
}
return !is_aborted();
} }
......
...@@ -928,7 +928,7 @@ void LChunkBuilder::AddInstruction(LInstruction* instr, ...@@ -928,7 +928,7 @@ void LChunkBuilder::AddInstruction(LInstruction* instr,
} }
chunk_->AddInstruction(instr, current_block_); chunk_->AddInstruction(instr, current_block_);
if (instr->IsCall()) { if (instr->IsCall() || instr->IsPrologue()) {
HValue* hydrogen_value_for_lazy_bailout = hydrogen_val; HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
if (hydrogen_val->HasObservableSideEffects()) { if (hydrogen_val->HasObservableSideEffects()) {
HSimulate* sim = HSimulate::cast(hydrogen_val->next()); HSimulate* sim = HSimulate::cast(hydrogen_val->next());
...@@ -942,6 +942,11 @@ void LChunkBuilder::AddInstruction(LInstruction* instr, ...@@ -942,6 +942,11 @@ void LChunkBuilder::AddInstruction(LInstruction* instr,
} }
LInstruction* LChunkBuilder::DoPrologue(HPrologue* instr) {
return new (zone()) LPrologue();
}
LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
return new (zone()) LGoto(instr->FirstSuccessor()); return new (zone()) LGoto(instr->FirstSuccessor());
} }
......
...@@ -131,6 +131,7 @@ class LCodeGen; ...@@ -131,6 +131,7 @@ class LCodeGen;
V(OsrEntry) \ V(OsrEntry) \
V(Parameter) \ V(Parameter) \
V(Power) \ V(Power) \
V(Prologue) \
V(PushArgument) \ V(PushArgument) \
V(RegExpLiteral) \ V(RegExpLiteral) \
V(Return) \ V(Return) \
...@@ -384,6 +385,12 @@ class LGoto final : public LTemplateInstruction<0, 0, 0> { ...@@ -384,6 +385,12 @@ class LGoto final : public LTemplateInstruction<0, 0, 0> {
}; };
class LPrologue final : public LTemplateInstruction<0, 0, 0> {
public:
DECLARE_CONCRETE_INSTRUCTION(Prologue, "prologue")
};
class LLazyBailout final : public LTemplateInstruction<0, 0, 0> { class LLazyBailout final : public LTemplateInstruction<0, 0, 0> {
public: public:
LLazyBailout() : gap_instructions_size_(0) {} LLazyBailout() : gap_instructions_size_(0) {}
......
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