* Add more restriction in 'peep2_find_free_register'
@ 2008-06-17 22:26 Anatoly Sokolov
2008-06-18 14:47 ` Ian Lance Taylor
0 siblings, 1 reply; 5+ messages in thread
From: Anatoly Sokolov @ 2008-06-17 22:26 UTC (permalink / raw)
To: gcc-patches; +Cc: rth, aesok, chertykov
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Add more restriction in 'peep2_find_free_register'
2008-06-17 22:26 Add more restriction in 'peep2_find_free_register' Anatoly Sokolov
@ 2008-06-18 14:47 ` Ian Lance Taylor
2008-06-19 15:36 ` Anatoly Sokolov
0 siblings, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2008-06-18 14:47 UTC (permalink / raw)
To: Anatoly Sokolov; +Cc: gcc-patches, rth, chertykov
Anatoly Sokolov <aesok@post.ru> writes:
> 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).
Please make a new target hook instead (I know that the existing
HARD_REGNO_RENAME_OK is still a macro). Thanks.
Ian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Add more restriction in 'peep2_find_free_register'
2008-06-18 14:47 ` Ian Lance Taylor
@ 2008-06-19 15:36 ` Anatoly Sokolov
2008-06-30 21:02 ` Ian Lance Taylor
0 siblings, 1 reply; 5+ messages in thread
From: Anatoly Sokolov @ 2008-06-19 15:36 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: gcc-patches, rth, chertykov, Anatoliy Sokolov, Andy H
[-- Attachment #1: Type: text/plain, Size: 1327 bytes --]
Hello.
Ian Lance Taylor writes:
> Anatoly Sokolov <aesok@post.ru> writes:
>>
>> * 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).
>
> Please make a new target hook instead (I know that the existing
> HARD_REGNO_RENAME_OK is still a macro). Thanks.
Andy H writes:
> Typo:
>
>default_hard_regno_scrath_ok
>
>default_hard_regno_scratch_ok
Thanks You, Andy.
2008-06-19 Anatoly Sokolov <aesok@post.ru>
* target.h (struct gcc_target): Add hard_regno_scratch_ok field.
* target-def.h (TARGET_HARD_REGNO_SCRATCH_OK): New.
(TARGET_INITIALIZER): Use TARGET_HARD_REGNO_SCRATCH_OK.
* targhooks.c (default_hard_regno_scratch_ok): New function.
* targhooks.h (default_hard_regno_scratch_ok): Declare function.
* doc/tm.texi: Document TARGET_HARD_REGNO_SCRATCH_OK hook.
* recog.c (peep2_find_free_register): Add check for global regs.
Add target specific check.
Anatoly.
[-- Attachment #2: hard_regno_scratch_ok.diff.txt --]
[-- Type: text/plain, Size: 3987 bytes --]
Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi (revision 136946)
+++ gcc/doc/tm.texi (working copy)
@@ -2242,6 +2242,16 @@
allocation.
@end defmac
+@deftypefn {Target Hook} bool TARGET_HARD_REGNO_SCRATCH_OK (unsigned int @var{regno})
+This target hook should return 'true' 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.
+
+TThe default version of this hook always returns 'true'.
+@end deftypefn
+
@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/targhooks.c
===================================================================
--- gcc/targhooks.c (revision 136946)
+++ gcc/targhooks.c (working copy)
@@ -703,4 +703,10 @@
return true;
}
+bool
+default_hard_regno_scratch_ok (unsigned int regno ATTRIBUTE_UNUSED)
+{
+ return true;
+}
+
#include "gt-targhooks.h"
Index: gcc/targhooks.h
===================================================================
--- gcc/targhooks.h (revision 136946)
+++ gcc/targhooks.h (working copy)
@@ -97,3 +97,5 @@
extern tree default_mangle_decl_assembler_name (tree, tree);
extern tree default_emutls_var_fields (tree, tree *);
extern tree default_emutls_var_init (tree, tree, tree);
+
+extern bool default_hard_regno_scratch_ok (unsigned int);
Index: gcc/target.h
===================================================================
--- gcc/target.h (revision 136946)
+++ gcc/target.h (working copy)
@@ -866,6 +866,10 @@
but will be later. */
void (* instantiate_decls) (void);
+ /* Return true if is OK to use a hard register REGNO as scratch register
+ in peephole2. */
+ bool (* hard_regno_scratch_ok) (unsigned int regno);
+
/* Functions specific to the C family of frontends. */
struct c {
/* Return machine mode for non-standard suffix
Index: gcc/recog.c
===================================================================
--- gcc/recog.c (revision 136946)
+++ gcc/recog.c (working copy)
@@ -40,6 +40,7 @@
#include "basic-block.h"
#include "output.h"
#include "reload.h"
+#include "target.h"
#include "timevar.h"
#include "tree-pass.h"
#include "df.h"
@@ -2898,6 +2899,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 +2911,9 @@
/* And that we don't create an extra save/restore. */
if (! call_used_regs[regno] && ! df_regs_ever_live_p (regno))
continue;
+ if (! targetm.hard_regno_scratch_ok (regno))
+ continue;
+
/* And we don't clobber traceback for noreturn functions. */
if ((regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM)
&& (! reload_completed || frame_pointer_needed))
Index: gcc/target-def.h
===================================================================
--- gcc/target-def.h (revision 136946)
+++ gcc/target-def.h (working copy)
@@ -617,6 +617,10 @@
#define TARGET_INSTANTIATE_DECLS hook_void_void
#endif
+#ifndef TARGET_HARD_REGNO_SCRATCH_OK
+#define TARGET_HARD_REGNO_SCRATCH_OK default_hard_regno_scratch_ok
+#endif
+
/* C specific. */
#ifndef TARGET_C_MODE_FOR_SUFFIX
#define TARGET_C_MODE_FOR_SUFFIX default_mode_for_suffix
@@ -842,6 +846,7 @@
TARGET_SECONDARY_RELOAD, \
TARGET_EXPAND_TO_RTL_HOOK, \
TARGET_INSTANTIATE_DECLS, \
+ TARGET_HARD_REGNO_SCRATCH_OK, \
TARGET_C, \
TARGET_CXX, \
TARGET_EMUTLS, \
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Add more restriction in 'peep2_find_free_register'
2008-06-19 15:36 ` Anatoly Sokolov
@ 2008-06-30 21:02 ` Ian Lance Taylor
0 siblings, 0 replies; 5+ messages in thread
From: Ian Lance Taylor @ 2008-06-30 21:02 UTC (permalink / raw)
To: Anatoly Sokolov; +Cc: gcc-patches, rth, chertykov, Andy H
"Anatoly Sokolov" <aesok@post.ru> writes:
> 2008-06-19 Anatoly Sokolov <aesok@post.ru>
>
> * target.h (struct gcc_target): Add hard_regno_scratch_ok field.
> * target-def.h (TARGET_HARD_REGNO_SCRATCH_OK): New.
> (TARGET_INITIALIZER): Use TARGET_HARD_REGNO_SCRATCH_OK.
> * targhooks.c (default_hard_regno_scratch_ok): New function.
> * targhooks.h (default_hard_regno_scratch_ok): Declare function.
> * doc/tm.texi: Document TARGET_HARD_REGNO_SCRATCH_OK hook.
> * recog.c (peep2_find_free_register): Add check for global regs.
> Add target specific check.
> +@deftypefn {Target Hook} bool TARGET_HARD_REGNO_SCRATCH_OK (unsigned int @var{regno})
> +This target hook should return 'true' 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.
> +
> +TThe default version of this hook always returns 'true'.
> +@end deftypefn
Change 'true' => @code{true}, in two places.
Typo: "TThe" => "The".
This patch is OK with those changes.
Thanks.
Ian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Add more restriction in 'peep2_find_free_register'
@ 2008-06-18 22:10 Anatoly Sokolov
0 siblings, 0 replies; 5+ messages in thread
From: Anatoly Sokolov @ 2008-06-18 22:10 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: gcc-patches
Hello.
Ian Lance Taylor writes:
> Anatoly Sokolov <aesok@post.ru> writes:
>
>> 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).
>
> Please make a new target hook instead (I know that the existing
> HARD_REGNO_RENAME_OK is still a macro). Thanks.
>
2008-06-18 Anatoly Sokolov <aesok@post.ru>
* target.h (struct gcc_target): Add hard_regno_scrath_ok field.
* target-def.h (TARGET_HARD_REGNO_SCRATCH_OK): New.
(TARGET_INITIALIZER): Use TARGET_HARD_REGNO_SCRATCH_OK.
* targhooks.c (default_hard_regno_scrath_ok): New function.
* targhooks.h (default_hard_regno_scrath_ok): Declare function.
* doc/tm.texi: Document TARGET_HARD_REGNO_SCRATCH_OK hook.
* recog.c: Include "target.h".
(peep2_find_free_register): Add check for global regs. Add target
specific check.
Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi (revision 136911)
+++ gcc/doc/tm.texi (working copy)
@@ -2242,6 +2242,16 @@
allocation.
@end defmac
+@deftypefn {Target Hook} bool TARGET_HARD_REGNO_SCRATCH_OK (unsigned int @var{regno})
+This target hook should return 'true' 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.
+
+TThe default version of this hook always returns 'true'.
+@end deftypefn
+
@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/targhooks.c
===================================================================
--- gcc/targhooks.c (revision 136911)
+++ gcc/targhooks.c (working copy)
@@ -697,4 +697,10 @@
return true;
}
+bool
+default_hard_regno_scrath_ok (unsigned int regno ATTRIBUTE_UNUSED)
+{
+ return true;
+}
+
#include "gt-targhooks.h"
Index: gcc/targhooks.h
===================================================================
--- gcc/targhooks.h (revision 136911)
+++ gcc/targhooks.h (working copy)
@@ -96,3 +96,5 @@
extern tree default_mangle_decl_assembler_name (tree, tree);
extern tree default_emutls_var_fields (tree, tree *);
extern tree default_emutls_var_init (tree, tree, tree);
+
+extern bool default_hard_regno_scrath_ok (unsigned int);
Index: gcc/target.h
===================================================================
--- gcc/target.h (revision 136911)
+++ gcc/target.h (working copy)
@@ -863,6 +863,10 @@
but will be later. */
void (* instantiate_decls) (void);
+ /* Return true if is OK to use a hard register REGNO as scratch register
+ in peephole2. */
+ bool (* hard_regno_scrath_ok) (unsigned int regno);
+
/* Functions specific to the C family of frontends. */
struct c {
/* Return machine mode for non-standard suffix
Index: gcc/recog.c
===================================================================
--- gcc/recog.c (revision 136911)
+++ gcc/recog.c (working copy)
@@ -40,6 +40,7 @@
#include "basic-block.h"
#include "output.h"
#include "reload.h"
+#include "target.h"
#include "timevar.h"
#include "tree-pass.h"
#include "df.h"
@@ -2898,6 +2899,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 +2911,9 @@
/* And that we don't create an extra save/restore. */
if (! call_used_regs[regno] && ! df_regs_ever_live_p (regno))
continue;
+ if (! targetm.hard_regno_scrath_ok (regno))
+ continue;
+
/* And we don't clobber traceback for noreturn functions. */
if ((regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM)
&& (! reload_completed || frame_pointer_needed))
Index: gcc/target-def.h
===================================================================
--- gcc/target-def.h (revision 136911)
+++ gcc/target-def.h (working copy)
@@ -614,6 +614,10 @@
#define TARGET_INSTANTIATE_DECLS hook_void_void
#endif
+#ifndef TARGET_HARD_REGNO_SCRATCH_OK
+#define TARGET_HARD_REGNO_SCRATCH_OK default_hard_regno_scrath_ok
+#endif
+
/* C specific. */
#ifndef TARGET_C_MODE_FOR_SUFFIX
#define TARGET_C_MODE_FOR_SUFFIX default_mode_for_suffix
@@ -838,6 +842,7 @@
TARGET_SECONDARY_RELOAD, \
TARGET_EXPAND_TO_RTL_HOOK, \
TARGET_INSTANTIATE_DECLS, \
+ TARGET_HARD_REGNO_SCRATCH_OK, \
TARGET_C, \
TARGET_CXX, \
TARGET_EMUTLS, \
Anatoly.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-06-30 21:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-17 22:26 Add more restriction in 'peep2_find_free_register' Anatoly Sokolov
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
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).