public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Walter Lee <walt@tilera.com>
To: gcc-patches@gcc.gnu.org
Subject: [committed] TILE-Gx/TILEPro: unwind fix for dynamic frames
Date: Wed, 07 Mar 2012 18:01:00 -0000	[thread overview]
Message-ID: <201203071801.q27I1YWm017484@farm-0039.internal.tilera.com> (raw)


This patch fixes an unwinding bug for functions with dynamic stack
frames.  We stop generating REG_CFA_* notes for stack pointer, and at
the end of unwinding we restore the stack pointer by adjusting it by
EH_RETURN_STACKADJ_RTX.

Walter

diff --git a/gcc/config/tilegx/tilegx.c b/gcc/config/tilegx/tilegx.c
index fa739e3..217682e 100644
--- a/gcc/config/tilegx/tilegx.c
+++ b/gcc/config/tilegx/tilegx.c
@@ -3881,9 +3881,8 @@ tilegx_expand_prologue (void)
     {
       /* Copy the old stack pointer aside so we can save it later.  */
       sp_copy_regno = next_scratch_regno--;
-      insn = FRP (emit_move_insn (gen_rtx_REG (Pmode, sp_copy_regno),
-				  stack_pointer_rtx));
-      add_reg_note (insn, REG_CFA_REGISTER, NULL_RTX);
+      emit_move_insn (gen_rtx_REG (Pmode, sp_copy_regno),
+		      stack_pointer_rtx);
     }
 
   if (tilegx_current_function_is_leaf ())
@@ -3925,8 +3924,8 @@ tilegx_expand_prologue (void)
 	}
 
       /* Save our frame pointer for backtrace chaining.  */
-      FRP (frame_emit_store (sp_copy_regno, STACK_POINTER_REGNUM,
-			     chain_addr, cfa, cfa_offset));
+      emit_insn (gen_movdi (gen_frame_mem (DImode, chain_addr),
+			    gen_rtx_REG (DImode, sp_copy_regno)));
     }
 
   /* Compute where to start storing registers we need to save.  */
@@ -4067,16 +4066,7 @@ tilegx_expand_epilogue (bool sibcall_p)
 
   emit_insn (gen_blockage ());
 
-  if (crtl->calls_eh_return)
-    {
-      rtx r = compute_frame_addr (-total_size + UNITS_PER_WORD,
-				  &next_scratch_regno);
-      insn = emit_move_insn (gen_lowpart (DImode, stack_pointer_rtx),
-			     gen_frame_mem (DImode, r));
-      RTX_FRAME_RELATED_P (insn) = 1;
-      REG_NOTES (insn) = cfa_restores;
-    }
-  else if (frame_pointer_needed)
+  if (frame_pointer_needed)
     {
       /* Restore the old stack pointer by copying from the frame
          pointer.  */
@@ -4100,6 +4090,16 @@ tilegx_expand_epilogue (bool sibcall_p)
 			     cfa_restores);
     }
 
+  if (crtl->calls_eh_return)
+    {
+      if (TARGET_32BIT)
+	emit_insn (gen_sp_adjust_32bit (stack_pointer_rtx, stack_pointer_rtx,
+					EH_RETURN_STACKADJ_RTX));
+      else
+	emit_insn (gen_sp_adjust (stack_pointer_rtx, stack_pointer_rtx,
+				  EH_RETURN_STACKADJ_RTX));
+    }
+
   /* Restore the old frame pointer.  */
   if (frame_pointer_needed)
     {
diff --git a/gcc/config/tilepro/tilepro.c b/gcc/config/tilepro/tilepro.c
index 71b5807..011ac08 100644
--- a/gcc/config/tilepro/tilepro.c
+++ b/gcc/config/tilepro/tilepro.c
@@ -3556,9 +3556,8 @@ tilepro_expand_prologue (void)
     {
       /* Copy the old stack pointer aside so we can save it later.  */
       sp_copy_regno = next_scratch_regno--;
-      insn = FRP (emit_move_insn (gen_rtx_REG (Pmode, sp_copy_regno),
-				  stack_pointer_rtx));
-      add_reg_note (insn, REG_CFA_REGISTER, NULL_RTX);
+      emit_move_insn (gen_rtx_REG (Pmode, sp_copy_regno),
+		      stack_pointer_rtx);
     }
 
   if (tilepro_current_function_is_leaf ())
@@ -3600,8 +3599,8 @@ tilepro_expand_prologue (void)
 	}
 
       /* Save our frame pointer for backtrace chaining.  */
-      FRP (frame_emit_store (sp_copy_regno, STACK_POINTER_REGNUM,
-			     chain_addr, cfa, cfa_offset));
+      emit_insn (gen_movsi (gen_frame_mem (SImode, chain_addr),
+			    gen_rtx_REG (SImode, sp_copy_regno)));
     }
 
   /* Compute where to start storing registers we need to save.  */
@@ -3742,16 +3741,7 @@ tilepro_expand_epilogue (bool sibcall_p)
 
   emit_insn (gen_blockage ());
 
-  if (crtl->calls_eh_return)
-    {
-      rtx r = compute_frame_addr (-total_size + UNITS_PER_WORD,
-				  &next_scratch_regno);
-      insn = emit_move_insn (gen_rtx_REG (Pmode, STACK_POINTER_REGNUM),
-			     gen_frame_mem (Pmode, r));
-      RTX_FRAME_RELATED_P (insn) = 1;
-      REG_NOTES (insn) = cfa_restores;
-    }
-  else if (frame_pointer_needed)
+  if (frame_pointer_needed)
     {
       /* Restore the old stack pointer by copying from the frame
          pointer.  */
@@ -3767,6 +3757,10 @@ tilepro_expand_epilogue (bool sibcall_p)
 			     cfa_restores);
     }
 
+  if (crtl->calls_eh_return)
+    emit_insn (gen_sp_adjust (stack_pointer_rtx, stack_pointer_rtx,
+			      EH_RETURN_STACKADJ_RTX));
+
   /* Restore the old frame pointer.  */
   if (frame_pointer_needed)
     {

             reply	other threads:[~2012-03-07 18:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-07 18:01 Walter Lee [this message]
2012-03-07 20:11 ` Walter Lee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201203071801.q27I1YWm017484@farm-0039.internal.tilera.com \
    --to=walt@tilera.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).