Commit 2b9112a5 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Canonicalize return sequence for JSFunctions.

This optimization is already implemented in fullcodegen, and
basically makes sure that we do not unecessarily blow up the
code with duplicated return sequences everywhere.

R=danno@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#29315}
parent 17486957
...@@ -1024,12 +1024,18 @@ void CodeGenerator::AssembleReturn() { ...@@ -1024,12 +1024,18 @@ void CodeGenerator::AssembleReturn() {
__ LeaveFrame(StackFrame::MANUAL); __ LeaveFrame(StackFrame::MANUAL);
__ Ret(); __ Ret();
} else if (descriptor->IsJSFunctionCall() || needs_frame_) { } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
__ LeaveFrame(StackFrame::MANUAL); // Canonicalize JSFunction return sites for now.
int pop_count = descriptor->IsJSFunctionCall() if (return_label_.is_bound()) {
? static_cast<int>(descriptor->JSParameterCount()) __ b(&return_label_);
: 0; } else {
__ Drop(pop_count); __ bind(&return_label_);
__ Ret(); __ LeaveFrame(StackFrame::MANUAL);
int pop_count = descriptor->IsJSFunctionCall()
? static_cast<int>(descriptor->JSParameterCount())
: 0;
__ Drop(pop_count);
__ Ret();
}
} else { } else {
__ Ret(); __ Ret();
} }
......
...@@ -1153,13 +1153,19 @@ void CodeGenerator::AssembleReturn() { ...@@ -1153,13 +1153,19 @@ void CodeGenerator::AssembleReturn() {
__ Pop(fp, lr); __ Pop(fp, lr);
__ Ret(); __ Ret();
} else if (descriptor->IsJSFunctionCall() || needs_frame_) { } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
__ Mov(jssp, fp); // Canonicalize JSFunction return sites for now.
__ Pop(fp, lr); if (return_label_.is_bound()) {
int pop_count = descriptor->IsJSFunctionCall() __ B(&return_label_);
? static_cast<int>(descriptor->JSParameterCount()) } else {
: 0; __ Bind(&return_label_);
__ Drop(pop_count); __ Mov(jssp, fp);
__ Ret(); __ Pop(fp, lr);
int pop_count = descriptor->IsJSFunctionCall()
? static_cast<int>(descriptor->JSParameterCount())
: 0;
__ Drop(pop_count);
__ Ret();
}
} else { } else {
__ Ret(); __ Ret();
} }
......
...@@ -172,6 +172,7 @@ class CodeGenerator final : public GapResolver::Assembler { ...@@ -172,6 +172,7 @@ class CodeGenerator final : public GapResolver::Assembler {
InstructionSequence* const code_; InstructionSequence* const code_;
CompilationInfo* const info_; CompilationInfo* const info_;
Label* const labels_; Label* const labels_;
Label return_label_;
RpoNumber current_block_; RpoNumber current_block_;
SourcePosition current_source_position_; SourcePosition current_source_position_;
MacroAssembler masm_; MacroAssembler masm_;
......
...@@ -1339,12 +1339,18 @@ void CodeGenerator::AssembleReturn() { ...@@ -1339,12 +1339,18 @@ void CodeGenerator::AssembleReturn() {
__ ret(0); __ ret(0);
} }
} else if (descriptor->IsJSFunctionCall() || needs_frame_) { } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
__ mov(esp, ebp); // Move stack pointer back to frame pointer. // Canonicalize JSFunction return sites for now.
__ pop(ebp); // Pop caller's frame pointer. if (return_label_.is_bound()) {
int pop_count = descriptor->IsJSFunctionCall() __ jmp(&return_label_);
? static_cast<int>(descriptor->JSParameterCount()) } else {
: 0; __ bind(&return_label_);
__ Ret(pop_count * kPointerSize, ebx); __ mov(esp, ebp); // Move stack pointer back to frame pointer.
__ pop(ebp); // Pop caller's frame pointer.
int pop_count = descriptor->IsJSFunctionCall()
? static_cast<int>(descriptor->JSParameterCount())
: 0;
__ Ret(pop_count * kPointerSize, ebx);
}
} else { } else {
__ ret(0); __ ret(0);
} }
......
...@@ -1141,12 +1141,18 @@ void CodeGenerator::AssembleReturn() { ...@@ -1141,12 +1141,18 @@ void CodeGenerator::AssembleReturn() {
__ Pop(ra, fp); __ Pop(ra, fp);
__ Ret(); __ Ret();
} else if (descriptor->IsJSFunctionCall() || needs_frame_) { } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
__ mov(sp, fp); // Canonicalize JSFunction return sites for now.
__ Pop(ra, fp); if (return_label_.is_bound()) {
int pop_count = descriptor->IsJSFunctionCall() __ Branch(&return_label_);
? static_cast<int>(descriptor->JSParameterCount()) } else {
: 0; __ bind(&return_label_);
__ DropAndRet(pop_count); __ mov(sp, fp);
__ Pop(ra, fp);
int pop_count = descriptor->IsJSFunctionCall()
? static_cast<int>(descriptor->JSParameterCount())
: 0;
__ DropAndRet(pop_count);
}
} else { } else {
__ Ret(); __ Ret();
} }
......
...@@ -1214,12 +1214,18 @@ void CodeGenerator::AssembleReturn() { ...@@ -1214,12 +1214,18 @@ void CodeGenerator::AssembleReturn() {
__ Pop(ra, fp); __ Pop(ra, fp);
__ Ret(); __ Ret();
} else if (descriptor->IsJSFunctionCall() || needs_frame_) { } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
__ mov(sp, fp); // Canonicalize JSFunction return sites for now.
__ Pop(ra, fp); if (return_label_.is_bound()) {
int pop_count = descriptor->IsJSFunctionCall() __ Branch(&return_label_);
? static_cast<int>(descriptor->JSParameterCount()) } else {
: 0; __ bind(&return_label_);
__ DropAndRet(pop_count); __ mov(sp, fp);
__ Pop(ra, fp);
int pop_count = descriptor->IsJSFunctionCall()
? static_cast<int>(descriptor->JSParameterCount())
: 0;
__ DropAndRet(pop_count);
}
} else { } else {
__ Ret(); __ Ret();
} }
......
...@@ -1538,12 +1538,18 @@ void CodeGenerator::AssembleReturn() { ...@@ -1538,12 +1538,18 @@ void CodeGenerator::AssembleReturn() {
__ ret(0); __ ret(0);
} }
} else if (descriptor->IsJSFunctionCall() || needs_frame_) { } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
__ movq(rsp, rbp); // Move stack pointer back to frame pointer. // Canonicalize JSFunction return sites for now.
__ popq(rbp); // Pop caller's frame pointer. if (return_label_.is_bound()) {
int pop_count = descriptor->IsJSFunctionCall() __ jmp(&return_label_);
? static_cast<int>(descriptor->JSParameterCount()) } else {
: 0; __ bind(&return_label_);
__ Ret(pop_count * kPointerSize, rbx); __ movq(rsp, rbp); // Move stack pointer back to frame pointer.
__ popq(rbp); // Pop caller's frame pointer.
int pop_count = descriptor->IsJSFunctionCall()
? static_cast<int>(descriptor->JSParameterCount())
: 0;
__ Ret(pop_count * kPointerSize, rbx);
}
} else { } else {
__ ret(0); __ ret(0);
} }
......
...@@ -1599,12 +1599,18 @@ void CodeGenerator::AssembleReturn() { ...@@ -1599,12 +1599,18 @@ void CodeGenerator::AssembleReturn() {
__ ret(0); __ ret(0);
} }
} else if (descriptor->IsJSFunctionCall() || needs_frame_) { } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
__ mov(esp, ebp); // Move stack pointer back to frame pointer. // Canonicalize JSFunction return sites for now.
__ pop(ebp); // Pop caller's frame pointer. if (return_label_.is_bound()) {
int pop_count = descriptor->IsJSFunctionCall() __ jmp(&return_label_);
? static_cast<int>(descriptor->JSParameterCount()) } else {
: 0; __ bind(&return_label_);
__ Ret(pop_count * kPointerSize, ebx); __ mov(esp, ebp); // Move stack pointer back to frame pointer.
__ pop(ebp); // Pop caller's frame pointer.
int pop_count = descriptor->IsJSFunctionCall()
? static_cast<int>(descriptor->JSParameterCount())
: 0;
__ Ret(pop_count * kPointerSize, ebx);
}
} else { } else {
__ ret(0); __ ret(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