gcc-12/SME-0035-mode-switching-Allow-targets-to-set-the-mode-for-EH-.patch
eastb233 dbbaf1198d AArch64: Support SME intrinsics
(cherry picked from commit 5a8b1f3fd450f440943ca1eabccdfe6e9abdf668)
2024-03-20 09:15:24 +08:00

94 lines
3.3 KiB
Diff

From 15e311c4ba2a7052f1e4bbd548b8c95c4cdea0cb Mon Sep 17 00:00:00 2001
From: Richard Sandiford <richard.sandiford@arm.com>
Date: Sat, 11 Nov 2023 17:28:57 +0000
Subject: [PATCH 035/144] mode-switching: Allow targets to set the mode for EH
handlers
Reference: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=4b803fbf839439b1deca660e32d5ced211111dfa
The mode-switching pass already had hooks to say what mode
an entity is in on entry to a function and what mode it must
be in on return. For SME, we also want to say what mode an
entity is guaranteed to be in on entry to an exception handler.
gcc/
* target.def (mode_switching.eh_handler): New hook.
* doc/tm.texi.in (TARGET_MODE_EH_HANDLER): New @hook.
* doc/tm.texi: Regenerate.
* mode-switching.cc (optimize_mode_switching): Use eh_handler
to get the mode on entry to an exception handler.
---
gcc/doc/tm.texi | 6 ++++++
gcc/doc/tm.texi.in | 2 ++
gcc/mode-switching.cc | 5 ++++-
gcc/target.def | 7 +++++++
4 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 53a40e467..381fa2c95 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -10531,6 +10531,12 @@ If @code{TARGET_MODE_EXIT} is defined then @code{TARGET_MODE_ENTRY}
must be defined.
@end deftypefn
+@deftypefn {Target Hook} int TARGET_MODE_EH_HANDLER (int @var{entity})
+If this hook is defined, it should return the mode that @var{entity} is
+guaranteed to be in on entry to an exception handler, or the number of modes
+if there is no such guarantee.
+@end deftypefn
+
@deftypefn {Target Hook} int TARGET_MODE_PRIORITY (int @var{entity}, int @var{n})
This hook specifies the order in which modes for @var{entity}
are processed. 0 is the highest priority,
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index cdfa36564..282cb9926 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -7136,6 +7136,8 @@ mode or ``no mode'', depending on context.
@hook TARGET_MODE_EXIT
+@hook TARGET_MODE_EH_HANDLER
+
@hook TARGET_MODE_PRIORITY
@node Target Attributes
diff --git a/gcc/mode-switching.cc b/gcc/mode-switching.cc
index 4761c2ff0..9a6ba6cca 100644
--- a/gcc/mode-switching.cc
+++ b/gcc/mode-switching.cc
@@ -596,7 +596,10 @@ optimize_mode_switching (void)
gcc_assert (NOTE_INSN_BASIC_BLOCK_P (ins_pos));
if (ins_pos != BB_END (bb))
ins_pos = NEXT_INSN (ins_pos);
- ptr = new_seginfo (no_mode, no_mode, ins_pos, live_now);
+ if (bb_has_eh_pred (bb)
+ && targetm.mode_switching.eh_handler)
+ last_mode = targetm.mode_switching.eh_handler (e);
+ ptr = new_seginfo (no_mode, last_mode, ins_pos, live_now);
add_seginfo (&tail_ptr, ptr);
bitmap_clear_bit (transp_all, bb->index);
}
diff --git a/gcc/target.def b/gcc/target.def
index be8a99172..0a9bcefba 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -6985,6 +6985,13 @@ If @code{TARGET_MODE_EXIT} is defined then @code{TARGET_MODE_ENTRY}\n\
must be defined.",
int, (int entity), NULL)
+DEFHOOK
+(eh_handler,
+ "If this hook is defined, it should return the mode that @var{entity} is\n\
+guaranteed to be in on entry to an exception handler, or the number of modes\n\
+if there is no such guarantee.",
+ int, (int entity), NULL)
+
DEFHOOK
(priority,
"This hook specifies the order in which modes for @var{entity}\n\
--
2.19.1