]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
mode-switching: Allow targets to set the mode for EH handlers
authorRichard Sandiford <richard.sandiford@arm.com>
Sat, 11 Nov 2023 17:28:57 +0000 (17:28 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Sat, 11 Nov 2023 17:28:57 +0000 (17:28 +0000)
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
gcc/doc/tm.texi.in
gcc/mode-switching.cc
gcc/target.def

index 759331a2c963c89a3fa74127f97cbf0adbdd61b0..1a825c5004e8a1cfa748ad80705b7bcc3e4fdb97 100644 (file)
@@ -10455,6 +10455,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,
index a7b7aa289d88cf01ec51093d240e9b65621db569..5360c1bb2d8b7b8a7feeb42b95cb6bb8bcb9e76f 100644 (file)
@@ -6979,6 +6979,8 @@ mode or ``no mode'', depending on context.
 
 @hook TARGET_MODE_EXIT
 
+@hook TARGET_MODE_EH_HANDLER
+
 @hook TARGET_MODE_PRIORITY
 
 @node Target Attributes
index 1145350ca26f860dbc705453881d5d2c312cd17e..b8a887d81f71855ec3426d20ba8d78eed9f9352e 100644 (file)
@@ -597,7 +597,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);
              }
index 3dae33522f1895a39fbe70cf88dc5089feb981f7..a70275b8abddde883f4345c075195f7841e66e7e 100644 (file)
@@ -7070,6 +7070,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\