diff mbox

[committed] TILE-Gx/TILEPro: unwind fix for dynamic frames

Message ID 201203071801.q27I1YWm017484@farm-0039.internal.tilera.com
State New
Headers show

Commit Message

Walter Lee March 7, 2012, 6:01 p.m. UTC
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

Comments

Walter Lee March 7, 2012, 8:11 p.m. UTC | #1
On 3/7/2012 1:01 PM, Walter Lee wrote:
>
> 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.

I forgot to attach the ChangeLog:

	* config/tilegx/tilegx.c (tilegx_expand_prologue): Don't generate
	REG_CFA_* notes for the stack pointer.
	(tilegx_expand_epilogue): Restore stack pointer by adjusting it by
	EH_RETURN_STACKADJ_RTX.
	* config/tilepro/tilepro.c (tilepro_expand_prologue): Don't
	generate REG_CFA_* notes for the stack pointer.
	(tilepro_expand_epilogue): Restore stack pointer by adjusting it
	by EH_RETURN_STACKADJ_RTX.

Walter
diff mbox

Patch

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)
     {