From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6545 invoked by alias); 18 Jun 2008 21:46:48 -0000 Received: (qmail 6531 invoked by uid 22791); 18 Jun 2008 21:46:46 -0000 X-Spam-Check-By: sourceware.org Received: from contrabass.post.ru (HELO contrabass.post.ru) (85.21.78.5) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 18 Jun 2008 21:46:27 +0000 Received: from corbina.ru (mail.post.ru [195.14.50.16]) by contrabass.post.ru (Postfix) with ESMTP id 8C6918A508; Thu, 19 Jun 2008 01:46:23 +0400 (MSD) Received: from [10.193.100.241] (account aesok@post.ru HELO Vista.corbina.ru) by corbina.ru (CommuniGate Pro SMTP 5.1.14) with ESMTPA id 720713189; Thu, 19 Jun 2008 01:46:23 +0400 Date: Wed, 18 Jun 2008 22:10:00 -0000 From: Anatoly Sokolov X-Mailer: The Bat! (v4.0.14) Professional Message-ID: <474011943.20080619014643@post.ru> To: Ian Lance Taylor CC: gcc-patches@gcc.gnu.org , rth@redhat.com , chertykov@gmail.com , Subject: Re: Add more restriction in 'peep2_find_free_register' MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1251 Content-Transfer-Encoding: quoted-printable Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2008-06/txt/msg01213.txt.bz2 Hello. Ian Lance Taylor writes: > Anatoly Sokolov writes: >=20 >> This patch add two more check in 'peep2_find_free_register' function, wh= ich >> 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 registe= rs >> which are saved in prologue. In 'rename_registers' optimization pass t= his >> 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 inte= rrupt >> and 'match_scratch' in peephole2 (avr, m68k). >=20 > Please make a new target hook instead (I know that the existing > HARD_REGNO_RENAME_OK is still a macro). Thanks. >=20 2008-06-18 Anatoly Sokolov * 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/doc/tm.texi (revision 136911) +++ gcc/doc/tm.texi (working copy) @@ -2242,6 +2242,16 @@ allocation. @end defmac =20 +@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=20 +@var{regno} as scratch reg in peephole2. + +One common use of this macro is to prevent using of a register that=20 +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/fr= om Index: gcc/targhooks.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/targhooks.c (revision 136911) +++ gcc/targhooks.c (working copy) @@ -697,4 +697,10 @@ return true; } =20 +bool=20 +default_hard_regno_scrath_ok (unsigned int regno ATTRIBUTE_UNUSED) +{ + return true; +} + #include "gt-targhooks.h" Index: gcc/targhooks.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/target.h (revision 136911) +++ gcc/target.h (working copy) @@ -863,6 +863,10 @@ but will be later. */ void (* instantiate_decls) (void); =20 + /* Return true if is OK to use a hard register REGNO as scratch register= =20 + 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 =3D=3D FRAME_POINTER_REGNUM || regno =3D=3D HARD_FRAME_PO= INTER_REGNUM) && (! reload_completed || frame_pointer_needed)) Index: gcc/target-def.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/target-def.h (revision 136911) +++ gcc/target-def.h (working copy) @@ -614,6 +614,10 @@ #define TARGET_INSTANTIATE_DECLS hook_void_void #endif =20 +#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.