From: Anatoly Sokolov <aesok@post.ru>
To: gcc-patches@gcc.gnu.org
Cc: rth@redhat.com, aesok@post.ru, chertykov@gmail.com
Subject: Add more restriction in 'peep2_find_free_register'
Date: Tue, 17 Jun 2008 22:26:00 -0000 [thread overview]
Message-ID: <113229086.20080618021412@post.ru> (raw)
Hello.
This patch add two more check in 'peep2_find_free_register' function, which
find free hard registers for use as scratch registers in peephole2.
* It is not allowed to use register that are being declared as global, as
scratch register.
* For an interrupt function it is safety to use only call-used registers
which are saved in prologue. In 'rename_registers' optimization pass this
check is done in HARD_REGNO_RENAME_OK macro. This patch add
HARD_REGNO_SCRATCH_OK macro for 'peephole2' pass. The
HARD_REGNO_SCRATCH_OK macro sould be difined for target which use interrupt
and 'match_scratch' in peephole2 (avr, m68k).
For example for avr target:
avr.h:
#define HARD_REGNO_SCRATCH_OK(REGNO) avr_hard_regno_scrath_ok (REGNO)
avr.c:
int
avr_hard_regno_scrath_ok (unsigned int regno)
{
/* Interrupt functions can only use registers that have already been
saved by the prologue, even if they would normally be
call-clobbered. */
if ((cfun->machine->is_interrupt || cfun->machine->is_signal)
&& !df_regs_ever_live_p (regno))
return 0;
return 1;
}
2008-06-17 Anatoly Sokolov <aesok@post.ru>
* recog.c (peep2_find_free_register): Add check for global regs.
Add target specific check.
Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi (revision 136872)
+++ gcc/doc/tm.texi (working copy)
@@ -2242,6 +2242,16 @@
allocation.
@end defmac
+@defmac HARD_REGNO_SCRATCH_OK (@var{regno})
+A C expression that is nonzero if it is OK to use a hard register
+@var{regno} as scratch reg in peephole2.
+
+One common use of this macro is to prevent using of a register that
+is not saved by a prologue in an interrupt handler.
+
+The default is always nonzero.
+@end defmac
+
@defmac AVOID_CCMODE_COPIES
Define this macro if the compiler should avoid copies to/from @code{CCmode}
registers. You should only define this macro if support for copying to/from
Index: gcc/recog.c
===================================================================
--- gcc/recog.c (revision 136872)
+++ gcc/recog.c (working copy)
@@ -2898,6 +2898,9 @@
/* Don't allocate fixed registers. */
if (fixed_regs[regno])
continue;
+ /* Don't allocate global registers. */
+ if (global_regs[regno])
+ continue;
/* Make sure the register is of the right class. */
if (! TEST_HARD_REG_BIT (reg_class_contents[cl], regno))
continue;
@@ -2907,6 +2910,10 @@
/* And that we don't create an extra save/restore. */
if (! call_used_regs[regno] && ! df_regs_ever_live_p (regno))
continue;
+#ifdef HARD_REGNO_SCRATCH_OK
+ if (! HARD_REGNO_SCRATCH_OK(regno))
+ continue;
+#endif
/* And we don't clobber traceback for noreturn functions. */
if ((regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM)
&& (! reload_completed || frame_pointer_needed))
Anatoly.
next reply other threads:[~2008-06-17 22:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-17 22:26 Anatoly Sokolov [this message]
2008-06-18 14:47 ` Ian Lance Taylor
2008-06-19 15:36 ` Anatoly Sokolov
2008-06-30 21:02 ` Ian Lance Taylor
2008-06-18 22:10 Anatoly Sokolov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=113229086.20080618021412@post.ru \
--to=aesok@post.ru \
--cc=chertykov@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=rth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).