[turbofan] Canonicalize return sequence for JSFunctions.
authorbmeurer <bmeurer@chromium.org>
Fri, 26 Jun 2015 09:34:32 +0000 (02:34 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 26 Jun 2015 09:34:45 +0000 (09:34 +0000)
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}

src/compiler/arm/code-generator-arm.cc
src/compiler/arm64/code-generator-arm64.cc
src/compiler/code-generator.h
src/compiler/ia32/code-generator-ia32.cc
src/compiler/mips/code-generator-mips.cc
src/compiler/mips64/code-generator-mips64.cc
src/compiler/x64/code-generator-x64.cc
src/compiler/x87/code-generator-x87.cc

index f147dd609b06aa1d1b3889170cdd8ed9e767fbeb..a73c895b286716ed24e5fb7564135456760273ae 100644 (file)
@@ -1024,12 +1024,18 @@ void CodeGenerator::AssembleReturn() {
     __ LeaveFrame(StackFrame::MANUAL);
     __ Ret();
   } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
-    __ LeaveFrame(StackFrame::MANUAL);
-    int pop_count = descriptor->IsJSFunctionCall()
-                        ? static_cast<int>(descriptor->JSParameterCount())
-                        : 0;
-    __ Drop(pop_count);
-    __ Ret();
+    // Canonicalize JSFunction return sites for now.
+    if (return_label_.is_bound()) {
+      __ b(&return_label_);
+    } else {
+      __ bind(&return_label_);
+      __ LeaveFrame(StackFrame::MANUAL);
+      int pop_count = descriptor->IsJSFunctionCall()
+                          ? static_cast<int>(descriptor->JSParameterCount())
+                          : 0;
+      __ Drop(pop_count);
+      __ Ret();
+    }
   } else {
     __ Ret();
   }
index 2307d034e60509ca8adef91c2908d4b6a7e60ff6..8692732112708148b11c9d2824ef67ddf58f7435 100644 (file)
@@ -1153,13 +1153,19 @@ void CodeGenerator::AssembleReturn() {
     __ Pop(fp, lr);
     __ Ret();
   } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
-    __ Mov(jssp, fp);
-    __ Pop(fp, lr);
-    int pop_count = descriptor->IsJSFunctionCall()
-                        ? static_cast<int>(descriptor->JSParameterCount())
-                        : 0;
-    __ Drop(pop_count);
-    __ Ret();
+    // Canonicalize JSFunction return sites for now.
+    if (return_label_.is_bound()) {
+      __ B(&return_label_);
+    } else {
+      __ Bind(&return_label_);
+      __ Mov(jssp, fp);
+      __ Pop(fp, lr);
+      int pop_count = descriptor->IsJSFunctionCall()
+                          ? static_cast<int>(descriptor->JSParameterCount())
+                          : 0;
+      __ Drop(pop_count);
+      __ Ret();
+    }
   } else {
     __ Ret();
   }
index ea53ba62c4625915f8ecc5b3d61a21da8fd8265b..d1545d10b9ce95652ca20c455a3ce077296b7d6f 100644 (file)
@@ -172,6 +172,7 @@ class CodeGenerator final : public GapResolver::Assembler {
   InstructionSequence* const code_;
   CompilationInfo* const info_;
   Label* const labels_;
+  Label return_label_;
   RpoNumber current_block_;
   SourcePosition current_source_position_;
   MacroAssembler masm_;
index cad28535ff0d4b660999db2623280b5e44e33966..7272fdee9a3776a9902ffd4f2a375514e8bfd61c 100644 (file)
@@ -1339,12 +1339,18 @@ void CodeGenerator::AssembleReturn() {
       __ ret(0);
     }
   } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
-    __ 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);
+    // Canonicalize JSFunction return sites for now.
+    if (return_label_.is_bound()) {
+      __ jmp(&return_label_);
+    } else {
+      __ bind(&return_label_);
+      __ 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 {
     __ ret(0);
   }
index f7c1e01f80153325ded7c75424b1ab1f737790b9..a49ec4e9f2f18352955d6d8ec12331049610be12 100644 (file)
@@ -1141,12 +1141,18 @@ void CodeGenerator::AssembleReturn() {
     __ Pop(ra, fp);
     __ Ret();
   } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
-    __ mov(sp, fp);
-    __ Pop(ra, fp);
-    int pop_count = descriptor->IsJSFunctionCall()
-                        ? static_cast<int>(descriptor->JSParameterCount())
-                        : 0;
-    __ DropAndRet(pop_count);
+    // Canonicalize JSFunction return sites for now.
+    if (return_label_.is_bound()) {
+      __ Branch(&return_label_);
+    } else {
+      __ bind(&return_label_);
+      __ mov(sp, fp);
+      __ Pop(ra, fp);
+      int pop_count = descriptor->IsJSFunctionCall()
+                          ? static_cast<int>(descriptor->JSParameterCount())
+                          : 0;
+      __ DropAndRet(pop_count);
+    }
   } else {
     __ Ret();
   }
index bd84c442b7fdacab4dfc20ee02bb72a80ab99a08..74adbf4d2eec1bc232a513adf014affc9c429219 100644 (file)
@@ -1214,12 +1214,18 @@ void CodeGenerator::AssembleReturn() {
     __ Pop(ra, fp);
     __ Ret();
   } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
-    __ mov(sp, fp);
-    __ Pop(ra, fp);
-    int pop_count = descriptor->IsJSFunctionCall()
-                        ? static_cast<int>(descriptor->JSParameterCount())
-                        : 0;
-    __ DropAndRet(pop_count);
+    // Canonicalize JSFunction return sites for now.
+    if (return_label_.is_bound()) {
+      __ Branch(&return_label_);
+    } else {
+      __ bind(&return_label_);
+      __ mov(sp, fp);
+      __ Pop(ra, fp);
+      int pop_count = descriptor->IsJSFunctionCall()
+                          ? static_cast<int>(descriptor->JSParameterCount())
+                          : 0;
+      __ DropAndRet(pop_count);
+    }
   } else {
     __ Ret();
   }
index 5de3ad1d38c20897c8547f2b4c485b7cdd124236..d86c50aa2f6a5c47d7b949fcdc6a7783892201fc 100644 (file)
@@ -1538,12 +1538,18 @@ void CodeGenerator::AssembleReturn() {
       __ ret(0);
     }
   } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
-    __ 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);
+    // Canonicalize JSFunction return sites for now.
+    if (return_label_.is_bound()) {
+      __ jmp(&return_label_);
+    } else {
+      __ bind(&return_label_);
+      __ 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 {
     __ ret(0);
   }
index 87d4e3ddfbac18150f5433e47be01b6b0a9ef18f..22de06f13b614a1b8be726b58196f6ae22c00d65 100644 (file)
@@ -1599,12 +1599,18 @@ void CodeGenerator::AssembleReturn() {
       __ ret(0);
     }
   } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
-    __ 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);
+    // Canonicalize JSFunction return sites for now.
+    if (return_label_.is_bound()) {
+      __ jmp(&return_label_);
+    } else {
+      __ bind(&return_label_);
+      __ 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 {
     __ ret(0);
   }