aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatoly Sokolov <aesok@post.ru>2008-07-09 17:43:11 +0400
committerAnatoly Sokolov <aesok@gcc.gnu.org>2008-07-09 17:43:11 +0400
commitdbc42c44d87ef1031c3f649436df02fbcdbcc3c6 (patch)
tree1e2b360a3708a9b833a49b11cda5009cb7f10ed9
parent28f16d05a00d360b76f3c48ac739bcab22fb1418 (diff)
downloadgcc-dbc42c44d87ef1031c3f649436df02fbcdbcc3c6.zip
gcc-dbc42c44d87ef1031c3f649436df02fbcdbcc3c6.tar.gz
gcc-dbc42c44d87ef1031c3f649436df02fbcdbcc3c6.tar.bz2
target.h (struct gcc_target): Add hard_regno_scratch_ok field.
* 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: Include "target.h". (peep2_find_free_register): Add check for global regs. Add target specific check. * Makefile.in (recog.o): Depend on target.h. From-SVN: r137657
-rw-r--r--gcc/ChangeLog13
-rw-r--r--gcc/Makefile.in2
-rw-r--r--gcc/doc/tm.texi10
-rw-r--r--gcc/recog.c7
-rw-r--r--gcc/target-def.h5
-rw-r--r--gcc/target.h4
-rw-r--r--gcc/targhooks.c6
-rw-r--r--gcc/targhooks.h2
8 files changed, 48 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c579c50..8fabd6d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,16 @@
+2008-07-09 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: Include "target.h".
+ (peep2_find_free_register): Add check for global regs. Add target
+ specific check.
+ * Makefile.in (recog.o): Depend on target.h.
+
2008-07-09 Kaz Kojima <kkojima@gcc.gnu.org>
* config/sh/sh.c (sh_canonical_va_list_type): New.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 1bd7ed4..93acc46 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2868,7 +2868,7 @@ recog.o : recog.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
$(FUNCTION_H) $(BASIC_BLOCK_H) $(REGS_H) $(RECOG_H) $(EXPR_H) \
$(FLAGS_H) insn-config.h $(INSN_ATTR_H) toplev.h output.h reload.h \
addresses.h $(TM_P_H) $(TIMEVAR_H) tree-pass.h hard-reg-set.h $(REAL_H) \
- $(DF_H) $(DBGCNT_H)
+ $(DF_H) $(DBGCNT_H) $(TARGET_H)
reg-stack.o : reg-stack.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(RTL_H) $(TREE_H) $(RECOG_H) $(REGS_H) hard-reg-set.h $(FLAGS_H) \
insn-config.h toplev.h reload.h $(FUNCTION_H) $(TM_P_H) $(GGC_H) \
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index b5418a3..5860018 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -2242,6 +2242,16 @@ possible since doing so will allow GCC to perform better register
allocation.
@end defmac
+@deftypefn {Target Hook} bool TARGET_HARD_REGNO_SCRATCH_OK (unsigned int @var{regno})
+This target hook should return @code{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.
+
+The default version of this hook always returns @code{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
diff --git a/gcc/recog.c b/gcc/recog.c
index 3ddfd86..73d5764 100644
--- a/gcc/recog.c
+++ b/gcc/recog.c
@@ -40,6 +40,7 @@ along with GCC; see the file COPYING3. If not see
#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 @@ peep2_find_free_register (int from, int to, const char *class_str,
/* 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 @@ peep2_find_free_register (int from, int to, const char *class_str,
/* 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))
diff --git a/gcc/target-def.h b/gcc/target-def.h
index 7ffb134..29ed888 100644
--- a/gcc/target-def.h
+++ b/gcc/target-def.h
@@ -619,6 +619,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
@@ -846,6 +850,7 @@
TARGET_SECONDARY_RELOAD, \
TARGET_EXPAND_TO_RTL_HOOK, \
TARGET_INSTANTIATE_DECLS, \
+ TARGET_HARD_REGNO_SCRATCH_OK, \
TARGET_C, \
TARGET_CXX, \
TARGET_EMUTLS, \
diff --git a/gcc/target.h b/gcc/target.h
index 1185243..d1642ef 100644
--- a/gcc/target.h
+++ b/gcc/target.h
@@ -872,6 +872,10 @@ struct gcc_target
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
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index 7e931c5..1cb5614 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -703,4 +703,10 @@ default_builtin_vector_alignment_reachable (const_tree type, bool is_packed)
return true;
}
+bool
+default_hard_regno_scratch_ok (unsigned int regno ATTRIBUTE_UNUSED)
+{
+ return true;
+}
+
#include "gt-targhooks.h"
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 5aebc7e..4ad0fc8 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -97,3 +97,5 @@ extern int default_reloc_rw_mask (void);
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);