And here are the backend parts for supporting epilogue unwind for SH, ccing Kaz. Note that this needs the prior dwarf2 pass changes in too, or else occasional ICEs ensue.
About the issue on unneeded post-return CFI, mentioned before on libc-alpha, this patch currently does produce such directives. The generated unwind info should still be correct, though will need other changes to be optimal. Thanks, Chung-Lin 2012-05-18 Chung-Lin Tang <clt...@codesourcery.com> * config/sh/sh.c (output_stack_adjust): Remove !epilogue_p condition for generating REG_FRAME_RELATED_EXPR note. (pop): Add code for generating REG_CFA_RESTORE, REG_CFA_ADJUST_CFA notes. Set RTX_FRAME_RELATED_P to 1. (sh_expand_epilogue): Use frame_insn() for FP to SP move. Set 'frame_p' of calls to output_stack_adjust() to 'true'.
Index: config/sh/sh.c =================================================================== --- config/sh/sh.c (revision 187548) +++ config/sh/sh.c (working copy) @@ -6460,11 +6460,10 @@ output_stack_adjust (int size, rtx reg, int epilog emit_insn (GEN_MOV (const_reg, GEN_INT (size))); insn = emit_fn (GEN_ADD3 (reg, reg, const_reg)); } - if (! epilogue_p) - add_reg_note (insn, REG_FRAME_RELATED_EXPR, - gen_rtx_SET (VOIDmode, reg, - gen_rtx_PLUS (SImode, reg, - GEN_INT (size)))); + add_reg_note (insn, REG_FRAME_RELATED_EXPR, + gen_rtx_SET (VOIDmode, reg, + gen_rtx_PLUS (SImode, reg, + GEN_INT (size)))); } } } @@ -6509,7 +6508,7 @@ push (int rn) static void pop (int rn) { - rtx x; + rtx x, sp_reg, reg; if (rn == FPUL_REG) x = gen_pop_fpul (); else if (rn == FPSCR_REG) @@ -6527,7 +6526,18 @@ pop (int rn) x = gen_pop (gen_rtx_REG (SImode, rn)); x = emit_insn (x); + + sp_reg = gen_rtx_REG (SImode, STACK_POINTER_REGNUM); + reg = copy_rtx (GET_CODE (PATTERN (x)) == PARALLEL + ? SET_DEST (XVECEXP (PATTERN (x), 0, 0)) + : SET_DEST (PATTERN (x))); + add_reg_note (x, REG_CFA_RESTORE, reg); + add_reg_note (x, REG_CFA_ADJUST_CFA, + gen_rtx_SET (SImode, sp_reg, + plus_constant (SImode, sp_reg, + GET_MODE_SIZE (GET_MODE (reg))))); add_reg_note (x, REG_INC, gen_rtx_REG (SImode, STACK_POINTER_REGNUM)); + RTX_FRAME_RELATED_P (x) = 1; } /* Generate code to push the regs specified in the mask. */ @@ -7410,14 +7420,14 @@ sh_expand_epilogue (bool sibcall_p) See PR/18032 and PR/40313. */ emit_insn (gen_blockage ()); output_stack_adjust (frame_size, hard_frame_pointer_rtx, e, - &live_regs_mask, false); + &live_regs_mask, true); /* We must avoid moving the stack pointer adjustment past code which reads from the local frame, else an interrupt could occur after the SP adjustment and clobber data in the local frame. */ emit_insn (gen_blockage ()); - emit_insn (GEN_MOV (stack_pointer_rtx, hard_frame_pointer_rtx)); + frame_insn (GEN_MOV (stack_pointer_rtx, hard_frame_pointer_rtx)); } else if (frame_size) { @@ -7427,7 +7437,7 @@ sh_expand_epilogue (bool sibcall_p) frame. */ emit_insn (gen_blockage ()); output_stack_adjust (frame_size, stack_pointer_rtx, e, - &live_regs_mask, false); + &live_regs_mask, true); } if (SHMEDIA_REGS_STACK_ADJUST ()) @@ -7644,7 +7654,7 @@ sh_expand_epilogue (bool sibcall_p) output_stack_adjust (crtl->args.pretend_args_size + save_size + d_rounding + crtl->args.info.stack_regs * 8, - stack_pointer_rtx, e, NULL, false); + stack_pointer_rtx, e, NULL, true); if (crtl->calls_eh_return) emit_insn (GEN_ADD3 (stack_pointer_rtx, stack_pointer_rtx,