This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch committed] Add -mfixed-range option for SH


Hi,

The attached patch implements -mfixed-range on SH.  It's tested with
bootstrap and the top level "make -k check" on sh4-unknown-linux-gnu.
The document changes are tested with "make {dvi,pdf}".  Committed to
mainline.

Regards,
	kaz
--
2008-05-22  Kaz Kojima  <kkojima@gcc.gnu.org>

	* config/sh/sh.opt (mfixed-range): New option.
	* config/sh/sh-protos.h (sh_fix_range): Declare.
	* config/sh/sh.c (sh_fix_range): New function.
	* config/sh/sh.h (sh_fixed_range_str): Declare.
	(OVERRIDE_OPTIONS): Call sh_fix_range if sh_fixed_range_str
	is not empty.
	* doc/invoke.texi (SH Options): Document -mfixed-range.

diff -uprN ORIG/trunk/gcc/config/sh/sh-protos.h LOCAL/trunk/gcc/config/sh/sh-protos.h
--- ORIG/trunk/gcc/config/sh/sh-protos.h	2008-03-25 23:02:13.000000000 +0900
+++ LOCAL/trunk/gcc/config/sh/sh-protos.h	2008-05-19 23:25:21.000000000 +0900
@@ -173,6 +173,7 @@ extern enum reg_class sh_secondary_reloa
 					   struct secondary_reload_info *);
 extern int sh2a_get_function_vector_number (rtx);
 extern int sh2a_is_function_vector_call (rtx);
+extern void sh_fix_range (const char *);
 
 #endif /* ! GCC_SH_PROTOS_H */
 
diff -uprN ORIG/trunk/gcc/config/sh/sh.c LOCAL/trunk/gcc/config/sh/sh.c
--- ORIG/trunk/gcc/config/sh/sh.c	2008-05-19 09:16:59.000000000 +0900
+++ LOCAL/trunk/gcc/config/sh/sh.c	2008-05-19 23:25:20.000000000 +0900
@@ -7973,6 +7973,68 @@ initial_elimination_offset (int from, in
   else
     return total_auto_space;
 }
+
+/* Parse the -mfixed-range= option string.  */
+void
+sh_fix_range (const char *const_str)
+{
+  int i, first, last;
+  char *str, *dash, *comma;
+  
+  /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
+     REG2 are either register names or register numbers.  The effect
+     of this option is to mark the registers in the range from REG1 to
+     REG2 as ``fixed'' so they won't be used by the compiler.  */
+  
+  i = strlen (const_str);
+  str = (char *) alloca (i + 1);
+  memcpy (str, const_str, i + 1);
+  
+  while (1)
+    {
+      dash = strchr (str, '-');
+      if (!dash)
+	{
+	  warning (0, "value of -mfixed-range must have form REG1-REG2");
+	  return;
+	}
+      *dash = '\0';
+      comma = strchr (dash + 1, ',');
+      if (comma)
+	*comma = '\0';
+      
+      first = decode_reg_name (str);
+      if (first < 0)
+	{
+	  warning (0, "unknown register name: %s", str);
+	  return;
+	}
+      
+      last = decode_reg_name (dash + 1);
+      if (last < 0)
+	{
+	  warning (0, "unknown register name: %s", dash + 1);
+	  return;
+	}
+      
+      *dash = '-';
+      
+      if (first > last)
+	{
+	  warning (0, "%s-%s is an empty range", str, dash + 1);
+	  return;
+	}
+      
+      for (i = first; i <= last; ++i)
+	fixed_regs[i] = call_used_regs[i] = 1;
+
+      if (!comma)
+	break;
+
+      *comma = ',';
+      str = comma + 1;
+    }
+}
 
 /* Insert any deferred function attributes from earlier pragmas.  */
 static void
diff -uprN ORIG/trunk/gcc/config/sh/sh.h LOCAL/trunk/gcc/config/sh/sh.h
--- ORIG/trunk/gcc/config/sh/sh.h	2008-04-27 13:53:04.000000000 +0900
+++ LOCAL/trunk/gcc/config/sh/sh.h	2008-05-19 23:39:25.000000000 +0900
@@ -533,6 +533,8 @@ extern enum sh_divide_strategy_e sh_div_
 
 #define SUBTARGET_OVERRIDE_OPTIONS (void) 0
 
+extern const char *sh_fixed_range_str;
+
 #define OVERRIDE_OPTIONS 						\
 do {									\
   int regno;								\
@@ -754,6 +756,9 @@ do {									\
       if (align_functions < min_align)					\
 	align_functions = min_align;					\
     }									\
+									\
+  if (sh_fixed_range_str)						\
+    sh_fix_range (sh_fixed_range_str);					\
 } while (0)
 
 /* Target machine storage layout.  */
diff -uprN ORIG/trunk/gcc/config/sh/sh.opt LOCAL/trunk/gcc/config/sh/sh.opt
--- ORIG/trunk/gcc/config/sh/sh.opt	2008-04-05 09:19:14.000000000 +0900
+++ LOCAL/trunk/gcc/config/sh/sh.opt	2008-05-19 23:06:27.000000000 +0900
@@ -248,6 +248,10 @@ mdivsi3_libfunc=
 Target RejectNegative Joined Var(sh_divsi3_libfunc) Init("")
 Specify name for 32 bit signed division function
 
+mfixed-range=
+Target RejectNegative Joined Var(sh_fixed_range_str)
+Specify range of registers to make fixed
+
 mfmovd
 Target RejectNegative Mask(FMOVD) Undocumented
 
diff -uprN ORIG/trunk/gcc/doc/invoke.texi LOCAL/trunk/gcc/doc/invoke.texi
--- ORIG/trunk/gcc/doc/invoke.texi	2008-05-19 09:16:56.000000000 +0900
+++ LOCAL/trunk/gcc/doc/invoke.texi	2008-05-20 08:08:14.000000000 +0900
@@ -748,7 +748,7 @@ See RS/6000 and PowerPC Options.
 -mbigtable  -mfmovd  -mhitachi -mrenesas -mno-renesas -mnomacsave @gol
 -mieee  -mbitops  -misize  -minline-ic_invalidate -mpadstruct  -mspace @gol
 -mprefergot  -musermode -multcost=@var{number} -mdiv=@var{strategy} @gol
--mdivsi3_libfunc=@var{name}  @gol
+-mdivsi3_libfunc=@var{name} -mfixed-range=@var{register-range} @gol
 -madjust-unroll -mindexed-addressing -mgettrcost=@var{number} -mpt-fixed @gol
  -minvalid-symbols}
 
@@ -14102,6 +14102,14 @@ Set the name of the library function use
 division strategies, and the compiler will still expect the same
 sets of input/output/clobbered registers as if this option was not present.
 
+@item -mfixed-range=@var{register-range}
+@opindex mfixed-range
+Generate code treating the given register range as fixed registers.
+A fixed register is one that the register allocator can not use.  This is
+useful when compiling kernel code.  A register range is specified as
+two registers separated by a dash.  Multiple register ranges can be
+specified separated by a comma.
+
 @item -madjust-unroll
 @opindex madjust-unroll
 Throttle unrolling to avoid thrashing target registers.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]