aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Bergner <bergner@gcc.gnu.org>2018-10-04 08:36:20 -0500
committerPeter Bergner <bergner@gcc.gnu.org>2018-10-04 08:36:20 -0500
commit82957a739c9ed37cc78d3cabfc61d04549e65867 (patch)
treec6391a013b017f1777208b69af63b59bb49804f7
parentac712e4eb43f3dd8d7f12624ea4014ecb2a9cf34 (diff)
downloadgcc-82957a739c9ed37cc78d3cabfc61d04549e65867.zip
gcc-82957a739c9ed37cc78d3cabfc61d04549e65867.tar.gz
gcc-82957a739c9ed37cc78d3cabfc61d04549e65867.tar.bz2
re PR rtl-optimization/87466 (IRA and LRA spill all pseudos that are live across setjmp calls)
gcc/ PR rtl-optimization/87466 * target.def (setjmp_preserves_nonvolatile_regs_p): New target hook. * doc/tm.texi.in (TARGET_SETJMP_PRESERVES_NONVOLATILE_REGS_P): New hook. * doc/tm.texi: Regenerate. * ira-lives.c (process_bb_node_lives): Use the new target hook. * lra-lives.c (process_bb_lives): Likewise. * config/rs6000/rs6000.c (TARGET_SETJMP_PRESERVES_NONVOLATILE_REGS_P): Define. gcc/testsuite/ PR rtl-optimization/87466 * gcc.target/powerpc/pr87466.c: New test. From-SVN: r264842
-rw-r--r--gcc/config/rs6000/rs6000.c3
-rw-r--r--gcc/doc/tm.texi13
-rw-r--r--gcc/doc/tm.texi.in2
-rw-r--r--gcc/ira-lives.c5
-rw-r--r--gcc/lra-lives.c5
-rw-r--r--gcc/target.def15
-rw-r--r--gcc/testsuite/gcc.target/powerpc/pr87466.c19
7 files changed, 58 insertions, 4 deletions
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index a2813c8..7036fd7 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -1978,6 +1978,9 @@ static const struct attribute_spec rs6000_attribute_table[] =
#undef TARGET_ASM_GLOBALIZE_DECL_NAME
#define TARGET_ASM_GLOBALIZE_DECL_NAME rs6000_globalize_decl_name
#endif
+
+#undef TARGET_SETJMP_PRESERVES_NONVOLATILE_REGS_P
+#define TARGET_SETJMP_PRESERVES_NONVOLATILE_REGS_P hook_bool_void_true
/* Processor table. */
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 83965b2..0fcf806 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -11008,6 +11008,19 @@ In order to enforce the representation of @code{mode},
@code{mode}.
@end deftypefn
+@deftypefn {Target Hook} bool TARGET_SETJMP_PRESERVES_NONVOLATILE_REGS_P (void)
+On some targets, it is assumed that the compiler will spill all pseudos
+ that are live across a call to @code{setjmp}, while other targets treat
+ @code{setjmp} calls as normal function calls.
+
+ This hook returns false if @code{setjmp} calls do not preserve all
+ non-volatile registers so that gcc that must spill all pseudos that are
+ live across @code{setjmp} calls. Define this to return true if the
+ target does not need to spill all pseudos live across @code{setjmp} calls.
+ The default implementation conservatively assumes all pseudos must be
+ spilled across @code{setjmp} calls.
+@end deftypefn
+
@defmac STORE_FLAG_VALUE
A C expression describing the value returned by a comparison operator
with an integral mode and stored by a store-flag instruction
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index e1966bd..63b0c0a 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -7509,6 +7509,8 @@ You need not define this macro if it would always have the value of zero.
@hook TARGET_MODE_REP_EXTENDED
+@hook TARGET_SETJMP_PRESERVES_NONVOLATILE_REGS_P
+
@defmac STORE_FLAG_VALUE
A C expression describing the value returned by a comparison operator
with an integral mode and stored by a store-flag instruction
diff --git a/gcc/ira-lives.c b/gcc/ira-lives.c
index ab8ad4a..f1a7d27 100644
--- a/gcc/ira-lives.c
+++ b/gcc/ira-lives.c
@@ -1207,8 +1207,9 @@ process_bb_node_lives (ira_loop_tree_node_t loop_tree_node)
call, if this function receives a nonlocal
goto. */
if (cfun->has_nonlocal_label
- || find_reg_note (insn, REG_SETJMP,
- NULL_RTX) != NULL_RTX)
+ || (!targetm.setjmp_preserves_nonvolatile_regs_p ()
+ && (find_reg_note (insn, REG_SETJMP, NULL_RTX)
+ != NULL_RTX)))
{
SET_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj));
SET_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj));
diff --git a/gcc/lra-lives.c b/gcc/lra-lives.c
index b41df60..a3bc29c 100644
--- a/gcc/lra-lives.c
+++ b/gcc/lra-lives.c
@@ -895,8 +895,9 @@ process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
sparseset_ior (pseudos_live_through_calls,
pseudos_live_through_calls, pseudos_live);
if (cfun->has_nonlocal_label
- || find_reg_note (curr_insn, REG_SETJMP,
- NULL_RTX) != NULL_RTX)
+ || (!targetm.setjmp_preserves_nonvolatile_regs_p ()
+ && (find_reg_note (curr_insn, REG_SETJMP, NULL_RTX)
+ != NULL_RTX)))
sparseset_ior (pseudos_live_through_setjumps,
pseudos_live_through_setjumps, pseudos_live);
}
diff --git a/gcc/target.def b/gcc/target.def
index 9733edf..ad27d35 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -3123,6 +3123,21 @@ In order to enforce the representation of @code{mode},\n\
int, (scalar_int_mode mode, scalar_int_mode rep_mode),
default_mode_rep_extended)
+ DEFHOOK
+(setjmp_preserves_nonvolatile_regs_p,
+ "On some targets, it is assumed that the compiler will spill all pseudos\n\
+ that are live across a call to @code{setjmp}, while other targets treat\n\
+ @code{setjmp} calls as normal function calls.\n\
+ \n\
+ This hook returns false if @code{setjmp} calls do not preserve all\n\
+ non-volatile registers so that gcc that must spill all pseudos that are\n\
+ live across @code{setjmp} calls. Define this to return true if the\n\
+ target does not need to spill all pseudos live across @code{setjmp} calls.\n\
+ The default implementation conservatively assumes all pseudos must be\n\
+ spilled across @code{setjmp} calls.",
+ bool, (void),
+ hook_bool_void_false)
+
/* True if MODE is valid for a pointer in __attribute__((mode("MODE"))). */
DEFHOOK
(valid_pointer_mode,
diff --git a/gcc/testsuite/gcc.target/powerpc/pr87466.c b/gcc/testsuite/gcc.target/powerpc/pr87466.c
new file mode 100644
index 0000000..2bb292c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr87466.c
@@ -0,0 +1,19 @@
+/* { dg-do compile { target powerpc*-*-* } } */
+/* { dg-options "-O2" } */
+
+#include <stdlib.h>
+#include <setjmp.h>
+
+extern void foo (jmp_buf);
+
+long
+c (long var)
+{
+ jmp_buf env;
+ if (setjmp(env) != 0)
+ abort();
+ foo (env);
+ return var;
+}
+
+/* { dg-final { scan-assembler {\mmr\M} } } */