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]

RFA: Use .opt files for the mn10300 port


This patch makes the mn10300 port define its options using .opt files.
For a target with only four switches (one of which is just for the linker),
it ended up being a bit complicated ;)

The main problem is the way the -mam33 and -mam33-2 options are handled.
The relevant target_flags are actually hard-coded constants, but for the
sake of explanation, I'll give them some names:

    #define MASK_MULT_BUG 1
    #define MASK_AM33     2
    #define MASK_AM33_2   4

So:

  - mn10300.h defaults to the base mn10300 processor, meaning that
    MASK_AM33 and MASK_AM33_2 are clear by default.  MASK_MULT_BUG
    is set by default.  The options then behave as follows:

    -mam33:       set MASK_AM33, clear MASK_MULT_BUG
    -mno-am33:    clear MASK_AM33
    -mam33-2:     set MASK_AM33 and MASK_AM33_2, clear MASK_MULT_BUG
    -mno-am33-2:  clear MASK_AM33_2

    The idea seems to be that TARGET_AM33_2 should imply TARGET_AM33,
    but it's obvious from the above that "-mam33-2 -mno-am33" could lead
    to TARGET_AM33_2 && !TARGET_AM33.  Also, combinations like
    "-mam33 -mno-am33" will (surprisingly) have the same effect
    as "-mno-mult-bug".

  - linux.h defaults to am33-2 (MASK_AM33 | MASK_AM33_2).  It also
    provides its own TARGET_SWITCHES, these switches being a subset
    of the ones in mn10300.h:

    -mam33-2:     set MASK_AM33 and MASK_AM33_2
    -mam33:       clear MASK_AM33_2

    No consistency problems here ;)

I thought about three possible ways of handling this:

  1. Stick rigidly to the current setup.  Have two different .opt files,
     one for mn10300-elf and one for am33_2.0-linux-gnu.

  2. Define a single .opt file and disable -mmult-bug, -mno-mult-bug,
     -mno-am33 and -mno-am33-2 for linux configurations.

  3. Try to generalise the code so that it will work for both
     configurations.

I went for (3) here.  The advantages are (a) that it will avoid the
!TARGET_AM33 && TARGET_AM33_2 inconsistency and (b) that it will allow
configurations to have a default of am33 without the need for another
.opt file or more conditional code.

Specifically, the patch:

  - replaces the two target masks with an enumeration: mn10300_processor.

  - replaces TARGET_DEFAULT with PROCESSOR_DEFAULT, the initial value
    of mn10300_processor.

  - makes -mam33 and -mam33-2 set mn10300_processor to their respective
    values.

The main question is how -mno-am33* should be handled.  To me, the most
logical thing seemed to be that "-mno-FOO" should mean:

   mn10300_processor = MIN (FOO - 1, PROCESSOR_DEFAULT)

Thus -mno-am33 would always select the basic mn10300 processor.
-mno-am33-2 would do the same on targets the default to the mn10300
processor and would be equivalent to -mam33 on a target that defaults
to -mam33 or -mam33-2.

The patch avoids the -mno-mult-bug problems by enforcing
TARGET_AM33 => !TARGET_MULT_BUG in OVERRIDE_OPTIONS.

Tested by building mn10300-elf for a combined binutils, gcc and newlib
tree, and by building cc1 for am33_2.0-linux-gnu.  I also tried each
option by hand (on both configurations) to check that it was having
the desired effect.  OK to install?

Richard


	* config/mn10300/mn10300-protos.h (mn10300_override_options): Declare.
	* config/mn10300/mn10300.h (target_flags, TARGET_MULT_BUG)
	(TARGET_SWITCHES, TARGET_DEFAULT): Delete.
	(processor_type): New enum.
	(mn10300_processor): New variable.
	(TARGET_AM33, TARGET_AM33_2): Redefine in terms of mn10300_processor.
	(PROCESSOR_DEFAULT, OVERRIDE_OPTIONS): New macros.
	* config/mn10300/linux.h (TARGET_SWITCHES, TARGET_DEFAULT): Delete.
	(PROCESSOR_DEFAULT): New macro.
	* config/mn10300/mn10300.c (mn10300_processor): New variable.
	(TARGET_DEFAULT_TARGET_FLAGS, TARGET_HANDLE_OPTION): Override defaults.
	(mn10300_handle_option, mn10300_override_options): New functions.
	* config/mn10300/mn10300.opt: New file.

Index: config/mn10300/mn10300-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mn10300/mn10300-protos.h,v
retrieving revision 1.16
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.16 mn10300-protos.h
*** config/mn10300/mn10300-protos.h	19 Mar 2005 00:21:22 -0000	1.16
--- config/mn10300/mn10300-protos.h	2 Apr 2005 21:06:16 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 25,30 ****
--- 25,31 ----
  extern void mn10300_va_start (tree, rtx);
  #endif /* TREE_CODE */
  
+ extern void mn10300_override_options (void);
  extern struct rtx_def *legitimize_address (rtx, rtx, enum machine_mode);
  extern rtx legitimize_pic_address (rtx, rtx);
  extern int legitimate_pic_operand_p (rtx);
Index: config/mn10300/mn10300.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mn10300/mn10300.h,v
retrieving revision 1.86
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.86 mn10300.h
*** config/mn10300/mn10300.h	19 Mar 2005 00:21:22 -0000	1.86
--- config/mn10300/mn10300.h	2 Apr 2005 21:06:17 -0000
*************** #define TARGET_CPU_CPP_BUILTINS()		\
*** 42,87 ****
  
  #define CPP_SPEC "%{mam33:-D__AM33__} %{mam33-2:-D__AM33__=2 -D__AM33_2__}"
  
- /* Run-time compilation parameters selecting different hardware subsets.  */
- 
- extern int target_flags;
- 
  extern GTY(()) int mn10300_unspec_int_label_counter;
  
! /* Macros used in the machine description to test the flags.  */
  
! /* Macro to define tables used to set the flags.
!    This is a list in braces of pairs in braces,
!    each pair being { "NAME", VALUE }
!    where VALUE is the bits to set or minus the bits to clear.
!    An empty string NAME is used to identify the default VALUE.  */
! 
! /* Generate code to work around mul/mulq bugs on the mn10300.  */
! #define TARGET_MULT_BUG			(target_flags & 0x1)
! 
! /* Generate code for the AM33 processor.  */
! #define TARGET_AM33			(target_flags & 0x2)
! 
! /* Generate code for the AM33/2.0 processor.  */
! #define TARGET_AM33_2			(target_flags & 0x4)
! 
! #define TARGET_SWITCHES  \
!   {{ "mult-bug",	0x1,  N_("Work around hardware multiply bug")},	\
!    { "no-mult-bug", 	-0x1, N_("Do not work around hardware multiply bug")},\
!    { "am33", 		0x2,  N_("Target the AM33 processor")},	\
!    { "am33", 		-(0x1), ""},\
!    { "no-am33", 	-0x2, ""},	\
!    { "no-crt0",		0,    N_("No default crt0.o") }, \
!    { "am33-2",		0x6,  N_("Target the AM33/2.0 processor")},   \
!    { "am33-2",		-(0x1), ""},\
!    { "no-am33-2",	-0x4,   ""},  \
!    { "relax",		0,    N_("Enable linker relaxations") }, \
!    { "", TARGET_DEFAULT, NULL}}
  
! #ifndef TARGET_DEFAULT
! #define TARGET_DEFAULT 0x1
  #endif
  
  /* Print subsidiary information on the compiler version in use.  */
  
  #define TARGET_VERSION fprintf (stderr, " (MN10300)");
--- 42,66 ----
  
  #define CPP_SPEC "%{mam33:-D__AM33__} %{mam33-2:-D__AM33__=2 -D__AM33_2__}"
  
  extern GTY(()) int mn10300_unspec_int_label_counter;
  
! enum processor_type {
!   PROCESSOR_MN10300,
!   PROCESSOR_AM33,
!   PROCESSOR_AM33_2
! };
  
! extern enum processor_type mn10300_processor;
  
! #define TARGET_AM33	(mn10300_processor >= PROCESSOR_AM33)
! #define TARGET_AM33_2	(mn10300_processor == PROCESSOR_AM33_2)
! 
! #ifndef PROCESSOR_DEFAULT
! #define PROCESSOR_DEFAULT PROCESSOR_MN10300
  #endif
  
+ #define OVERRIDE_OPTIONS mn10300_override_options ()
+ 
  /* Print subsidiary information on the compiler version in use.  */
  
  #define TARGET_VERSION fprintf (stderr, " (MN10300)");
Index: config/mn10300/linux.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mn10300/linux.h,v
retrieving revision 1.5
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.5 linux.h
*** config/mn10300/linux.h	7 Feb 2005 08:11:10 -0000	1.5
--- config/mn10300/linux.h	2 Apr 2005 21:06:17 -0000
*************** #define LINK_SPEC "%{mrelax:--relax} %{s
*** 40,54 ****
       %{!dynamic-linker:-dynamic-linker /lib/ld.so.1}} \
     %{static:-static}"
  
! #undef  TARGET_SWITCHES
! #define TARGET_SWITCHES	\
!   {{ "am33",		-0x4,	N_("Target the AM33 processor") }, \
!    { "am33-2",		6,	N_("Target the AM33/2.0 processor") }, \
!    { "relax",		0,	N_("Enable linker relaxations") }, \
!    { "", TARGET_DEFAULT, NULL }}
! 
! #undef  TARGET_DEFAULT
! #define TARGET_DEFAULT 6
  
  #undef  TARGET_VERSION
  #define TARGET_VERSION fprintf (stderr, " (AM33/2.0 GNU/Linux)");
--- 40,47 ----
       %{!dynamic-linker:-dynamic-linker /lib/ld.so.1}} \
     %{static:-static}"
  
! #undef  PROCESSOR_DEFAULT
! #define PROCESSOR_DEFAULT PROCESSOR_AM33_2
  
  #undef  TARGET_VERSION
  #define TARGET_VERSION fprintf (stderr, " (AM33/2.0 GNU/Linux)");
Index: config/mn10300/mn10300.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mn10300/mn10300.c,v
retrieving revision 1.77
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.77 mn10300.c
*** config/mn10300/mn10300.c	19 Mar 2005 00:21:22 -0000	1.77
--- config/mn10300/mn10300.c	2 Apr 2005 21:06:17 -0000
*************** int mn10300_unspec_int_label_counter;
*** 54,59 ****
--- 54,62 ----
     symbol names from register names.  */
  int mn10300_protect_label;
  
+ /* The selected processor.  */
+ enum processor_type mn10300_processor = PROCESSOR_DEFAULT;
+ 
  /* The size of the callee register save area.  Right now we save everything
     on entry since it costs us nothing in code size.  It does cost us from a
     speed standpoint, so we want to optimize this sooner or later.  */
*************** #define REG_SAVE_BYTES (4 * regs_ever_li
*** 65,70 ****
--- 68,74 ----
  				|| regs_ever_live[16] || regs_ever_live[17]))
  
  
+ static bool mn10300_handle_option (size_t, const char *, int);
  static int mn10300_address_cost_1 (rtx, int *);
  static int mn10300_address_cost (rtx);
  static bool mn10300_rtx_costs (rtx, int, int, int *);
*************** #define TARGET_ASM_FILE_START mn10300_fi
*** 90,95 ****
--- 94,104 ----
  #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
  #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
  
+ #undef TARGET_DEFAULT_TARGET_FLAGS
+ #define TARGET_DEFAULT_TARGET_FLAGS MASK_MULT_BUG
+ #undef TARGET_HANDLE_OPTION
+ #define TARGET_HANDLE_OPTION mn10300_handle_option
+ 
  #undef  TARGET_ENCODE_SECTION_INFO
  #define TARGET_ENCODE_SECTION_INFO mn10300_encode_section_info
  
*************** #define TARGET_EXPAND_BUILTIN_SAVEREGS m
*** 110,115 ****
--- 119,155 ----
  static void mn10300_encode_section_info (tree, rtx, int);
  struct gcc_target targetm = TARGET_INITIALIZER;
  
+ /* Implement TARGET_HANDLE_OPTION.  */
+ 
+ static bool
+ mn10300_handle_option (size_t code,
+ 		       const char *arg ATTRIBUTE_UNUSED,
+ 		       int value)
+ {
+   switch (code)
+     {
+     case OPT_mam33:
+       mn10300_processor = value ? PROCESSOR_AM33 : PROCESSOR_MN10300;
+       return true;
+     case OPT_mam33_2:
+       mn10300_processor = (value
+ 			   ? PROCESSOR_AM33_2
+ 			   : MIN (PROCESSOR_AM33, PROCESSOR_DEFAULT));
+       return true;
+     default:
+       return true;
+     }
+ }
+ 
+ /* Implement OVERRIDE_OPTIONS.  */
+ 
+ void
+ mn10300_override_options (void)
+ {
+   if (TARGET_AM33)
+     target_flags &= ~MASK_MULT_BUG;
+ }
+ 
  static void
  mn10300_file_start (void)
  {
diff -c /dev/null config/mn10300/mn10300.opt
*** /dev/null	2005-03-29 10:04:47.000000000 +0100
--- config/mn10300/mn10300.opt	2005-04-02 22:03:23.631142389 +0100
***************
*** 0 ****
--- 1,37 ----
+ ; Options for the Matsushita MN10300 port of the compiler.
+ 
+ ; Copyright (C) 2005 Free Software Foundation, Inc.
+ ;
+ ; This file is part of GCC.
+ ;
+ ; GCC is free software; you can redistribute it and/or modify it under
+ ; the terms of the GNU General Public License as published by the Free
+ ; Software Foundation; either version 2, or (at your option) any later
+ ; version.
+ ;
+ ; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+ ; WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ ; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ ; for more details.
+ ;
+ ; You should have received a copy of the GNU General Public License
+ ; along with GCC; see the file COPYING.  If not, write to the Free
+ ; Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ ; 02111-1307, USA.
+ 
+ mam33
+ Target
+ Target the AM33 processor
+ 
+ mam33-2
+ Target
+ Target the AM33/2.0 processor
+ 
+ mmult-bug
+ Target Report Mask(MULT_BUG)
+ Work around hardware multiply bug
+ 
+ ; Ignored by the compiler
+ mrelax
+ Target RejectNegative
+ Enable linker relaxations


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