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 IQ2000 port


This patch makes the IQ2000 port define its options using a .opt file.

ISTR this port started out as a copy of the MIPS port and was then
adapted.  It still has the following MIPS-derived options:

    -mgpopt
    -membedded-data
    -muninit-const-in-rodaata

-mgpopt and -muninit-const-in-rodaata are ignored.  -membedded-data is
checked in one "if" statement, but due to the lack of -mgpopt support,
the two arms are identical (well, except for a misleading comment ;):

    if (TARGET_EMBEDDED_DATA)
      {
        /* For embedded applications, always put an object in read-only data
           if possible, in order to reduce RAM usage.  */
        if ((TREE_CODE (decl) == VAR_DECL
             && TREE_READONLY (decl) && !TREE_SIDE_EFFECTS (decl)
             && DECL_INITIAL (decl)
             && (DECL_INITIAL (decl) == error_mark_node
                 || TREE_CONSTANT (DECL_INITIAL (decl))))
            /* Deal with calls from output_constant_def_contents.  */
            || TREE_CODE (decl) != VAR_DECL)
          readonly_data_section ();
        else
          data_section ();
      }
    else
      {
        /* For hosted applications, always put an object in small data if
           possible, as this gives the best performance.  */
        if ((TREE_CODE (decl) == VAR_DECL
             && TREE_READONLY (decl) && !TREE_SIDE_EFFECTS (decl)
             && DECL_INITIAL (decl)
             && (DECL_INITIAL (decl) == error_mark_node
                 || TREE_CONSTANT (DECL_INITIAL (decl))))
            /* Deal with calls from output_constant_def_contents.  */
            || TREE_CODE (decl) != VAR_DECL)
          readonly_data_section ();
        else
          data_section ();
      }

I've kept these three options in-tact anyway.

-mcpu is supported and has a purpose: it selects between two different
schedulers.  The patch handles this in the new handle_option hook.

-march is supported but it only accepts one value (iq2000), albeit it
with three spellings: "iq2000", "default" and "DEFAULT".  The option
controls a variable called "iq2000_arch" but this variable is never
checked.

I dealt with this by removing iq2000_arch and making handle_option
reject anything except the three valid arguments.  There's no
user-visible difference between this and the old behaviour and it
would be easy enough to add back the iq2000_arch variable if it ever
becomes necessary.

There were some TARGET_DEBUG* macros that were defined as "target_flags
& 0".  Since hand-coded checks of target_flags should be rare after the
.opt transition, I redefined them as "0" instead.

Tested by successfully building a combined binutils/gcc/newlib tree
for iq2000-elf (C and C++ only).  Also tested by trying each option
by hand and checking that it worked (subject to observations above).
OK to install?

Richard


	* config/iq2000/iq2000.h (target_flags, MASK_GPOPT, MASK_EMBEDDED_DATA)
	(MASK_UNINIT_CONST_IN_RODATA, TARGET_EMBEDDED_DATA, TARGET_SWITCHES)
	(TARGET_DEFAULT, TARGET_CPU_DEFAULT, SUBTARGET_TARGET_OPTIONS)
	(TARGET_OPTIONS, iq2000_cpu_string, iq2000_arch_string): Delete.
	(TARGET_DEBUG_MODE, TARGET_DEBUG_A_MODE, TARGET_DEBUG_B_MODE)
	(TARGET_DEBUG_C_MODE, TARGET_DEBUG_D_MODE): Define to 0 rather
	than target_flags & 0.
	* config/iq2000/iq2000.c (iq2000_cpu_string, iq2000_arch_string)
	(iq2000_arch, iq2000_parse_cpu): Delete.
	(TARGET_HANDLE_OPTION): Override default.
	(iq2000_handle_option): New function.
	(override_options): Remove -march= and -mcpu= handling.
	* config/iq2000/iq2000.opt: New file.

Index: config/iq2000/iq2000.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/iq2000/iq2000.h,v
retrieving revision 1.22
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.22 iq2000.h
*** config/iq2000/iq2000.h	21 Feb 2005 20:32:05 -0000	1.22
--- config/iq2000/iq2000.h	22 Mar 2005 21:26:11 -0000
*************** #define TARGET_CPU_CPP_BUILTINS()       
*** 44,116 ****
      }                                           \
    while (0)
  
- extern int	target_flags;
- 
- #define MASK_GPOPT         0x00000008   /* Optimize for global pointer.  */
- #define MASK_EMBEDDED_DATA 0x00008000   /* Reduce RAM usage, not fast code.  */
- #define MASK_UNINIT_CONST_IN_RODATA \
-                            0x00800000   /* Store uninitialized
-                                            consts in rodata.  */
- 
  /* Macros used in the machine description to test the flags.  */
  
  #define TARGET_STATS		0
  
! /* For embedded systems, optimize for reduced RAM space instead of for
!    fastest code.  */
! #define TARGET_EMBEDDED_DATA	(target_flags & MASK_EMBEDDED_DATA)
! 
! #define TARGET_DEBUG_MODE	(target_flags & 0)
! #define TARGET_DEBUG_A_MODE	(target_flags & 0)
! #define TARGET_DEBUG_B_MODE	(target_flags & 0)
! #define TARGET_DEBUG_C_MODE	(target_flags & 0)
! #define TARGET_DEBUG_D_MODE	(target_flags & 0)
! 
! #define TARGET_SWITCHES							\
! {									\
!   {"no-crt0",          0,                                               \
!      N_("No default crt0.o") },					 	\
!   {"gpopt",		  MASK_GPOPT,					\
!      N_("Use GP relative sdata/sbss sections")},			\
!   {"no-gpopt",		 -MASK_GPOPT,					\
!      N_("Don't use GP relative sdata/sbss sections")},			\
!   {"embedded-data",	  MASK_EMBEDDED_DATA,				\
!      N_("Use ROM instead of RAM")},					\
!   {"no-embedded-data",	 -MASK_EMBEDDED_DATA,				\
!      N_("Don't use ROM instead of RAM")},				\
!   {"uninit-const-in-rodata", MASK_UNINIT_CONST_IN_RODATA,		\
!      N_("Put uninitialized constants in ROM (needs -membedded-data)")},	\
!   {"no-uninit-const-in-rodata", -MASK_UNINIT_CONST_IN_RODATA,		\
!      N_("Don't put uninitialized constants in ROM")},			\
!   {"",			  (TARGET_DEFAULT				\
! 			   | TARGET_CPU_DEFAULT),			\
!      NULL},								\
! }
! 
! /* Default target_flags if no switches are specified.  */
! 
! #define TARGET_DEFAULT 0
! 
! #ifndef TARGET_CPU_DEFAULT
! #define TARGET_CPU_DEFAULT 0
! #endif
  
  #ifndef IQ2000_ISA_DEFAULT
  #define IQ2000_ISA_DEFAULT 1
  #endif
  
- #define TARGET_OPTIONS							\
- {									\
-   SUBTARGET_TARGET_OPTIONS						\
-   { "cpu=",	& iq2000_cpu_string,					\
-       N_("Specify CPU for scheduling purposes")},			\
-   { "arch=",    & iq2000_arch_string,                                   \
-       N_("Specify CPU for code generation purposes")},                  \
- }
- 
- /* This is meant to be redefined in the host dependent files.  */
- #define SUBTARGET_TARGET_OPTIONS
- 
  #define IQ2000_VERSION "[1.0]"
  
  #ifndef MACHINE_TYPE
--- 44,63 ----
      }                                           \
    while (0)
  
  /* Macros used in the machine description to test the flags.  */
  
  #define TARGET_STATS		0
  
! #define TARGET_DEBUG_MODE	0
! #define TARGET_DEBUG_A_MODE	0
! #define TARGET_DEBUG_B_MODE	0
! #define TARGET_DEBUG_C_MODE	0
! #define TARGET_DEBUG_D_MODE	0
  
  #ifndef IQ2000_ISA_DEFAULT
  #define IQ2000_ISA_DEFAULT 1
  #endif
  
  #define IQ2000_VERSION "[1.0]"
  
  #ifndef MACHINE_TYPE
*************** extern rtx branch_cmp[2];
*** 1167,1178 ****
  /* What type of branch to use.  */
  extern enum cmp_type branch_type;
  
- /* Strings to hold which cpu and instruction set architecture to use.  */
- extern const char * iq2000_cpu_string;	  /* For -mcpu=<xxx>.  */
- extern const char * iq2000_arch_string;   /* For -march=<xxx>.  */
- 
- 
- 
  enum iq2000_builtins
  {
    IQ2000_BUILTIN_ADO16,
--- 1114,1119 ----
Index: config/iq2000/iq2000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/iq2000/iq2000.c,v
retrieving revision 1.31
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.31 iq2000.c
*** config/iq2000/iq2000.c	30 Dec 2004 03:07:50 -0000	1.31
--- config/iq2000/iq2000.c	22 Mar 2005 21:26:11 -0000
*************** rtx branch_cmp[2];
*** 125,135 ****
  /* What type of branch to use.  */
  enum cmp_type branch_type;
  
- /* Strings to hold which cpu and instruction set architecture to use.  */
- const char * iq2000_cpu_string;	  /* For -mcpu=<xxx>.  */
- const char * iq2000_arch_string;  /* For -march=<xxx>.  */
- 
- 
  /* Local variables.  */
  
  /* The next branch instruction is a branch likely, not branch normal.  */
--- 125,130 ----
*************** static rtx iq2000_load_reg2;
*** 152,166 ****
  static rtx iq2000_load_reg3;
  static rtx iq2000_load_reg4;
  
- /* The target cpu for code generation.  */
- static enum processor_type iq2000_arch;
- 
  /* Mode used for saving/restoring general purpose registers.  */
  static enum machine_mode gpr_mode;
  
  
  /* Initialize the GCC target structure.  */
  static struct machine_function* iq2000_init_machine_status (void);
  static void iq2000_select_rtx_section (enum machine_mode, rtx, unsigned HOST_WIDE_INT);
  static void iq2000_init_builtins      (void);
  static rtx  iq2000_expand_builtin     (tree, rtx, rtx, enum machine_mode, int);
--- 147,159 ----
  static rtx iq2000_load_reg3;
  static rtx iq2000_load_reg4;
  
  /* Mode used for saving/restoring general purpose registers.  */
  static enum machine_mode gpr_mode;
  
  
  /* Initialize the GCC target structure.  */
  static struct machine_function* iq2000_init_machine_status (void);
+ static bool iq2000_handle_option      (size_t, const char *, int);
  static void iq2000_select_rtx_section (enum machine_mode, rtx, unsigned HOST_WIDE_INT);
  static void iq2000_init_builtins      (void);
  static rtx  iq2000_expand_builtin     (tree, rtx, rtx, enum machine_mode, int);
*************** #define TARGET_INIT_BUILTINS 		iq2000_in
*** 183,188 ****
--- 176,183 ----
  #define TARGET_EXPAND_BUILTIN 		iq2000_expand_builtin
  #undef  TARGET_ASM_SELECT_RTX_SECTION
  #define TARGET_ASM_SELECT_RTX_SECTION	iq2000_select_rtx_section
+ #undef  TARGET_HANDLE_OPTION
+ #define TARGET_HANDLE_OPTION		iq2000_handle_option
  #undef  TARGET_RTX_COSTS
  #define TARGET_RTX_COSTS		iq2000_rtx_costs
  #undef  TARGET_ADDRESS_COST
*************** iq2000_init_machine_status (void)
*** 1606,1631 ****
    return f;
  }
  
! static enum processor_type
! iq2000_parse_cpu (const char * cpu_string)
! {
!   const char *p = cpu_string;
!   enum processor_type cpu;
  
!   cpu = PROCESSOR_DEFAULT;
!   switch (p[2])
      {
!     case '1':
!       if (!strcmp (p, "iq10"))
! 	cpu = PROCESSOR_IQ10;
!       break;
!     case '2':
!       if (!strcmp (p, "iq2000"))
! 	cpu = PROCESSOR_IQ2000;
!       break;
!     }
  
!   return cpu;
  }
  
  /* Detect any conflicts in the switches.  */
--- 1601,1631 ----
    return f;
  }
  
! /* Implement TARGET_HANDLE_OPTION.  */
  
! static bool
! iq2000_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
! {
!   switch (code)
      {
!     case OPT_mcpu_:
!       if (strcmp (arg, "iq10") == 0)
! 	iq2000_tune = PROCESSOR_IQ10;
!       else if (strcmp (arg, "iq2000") == 0)
! 	iq2000_tune = PROCESSOR_IQ2000;
!       else
! 	return false;
!       return true;
  
!     case OPT_march_:
!       /* This option has no effect at the moment.  */
!       return (strcmp (arg, "default") == 0
! 	      || strcmp (arg, "DEFAULT") == 0
! 	      || strcmp (arg, "iq2000") == 0);
! 
!     default:
!       return true;
!     }
  }
  
  /* Detect any conflicts in the switches.  */
*************** iq2000_parse_cpu (const char * cpu_strin
*** 1633,1685 ****
  void
  override_options (void)
  {
-   enum processor_type iq2000_cpu;
- 
    target_flags &= ~MASK_GPOPT;
  
    iq2000_isa = IQ2000_ISA_DEFAULT;
  
    /* Identify the processor type.  */
  
-   if (iq2000_cpu_string != 0)
-     {
-       iq2000_cpu = iq2000_parse_cpu (iq2000_cpu_string);
-       if (iq2000_cpu == PROCESSOR_DEFAULT)
- 	{
- 	  error ("bad value (%s) for -mcpu= switch", iq2000_arch_string);
- 	  iq2000_cpu_string = "default";
- 	}
-       iq2000_arch = iq2000_cpu;
-       iq2000_tune = iq2000_cpu;
-     }
- 
-   if (iq2000_arch_string == 0
-       || ! strcmp (iq2000_arch_string, "default")
-       || ! strcmp (iq2000_arch_string, "DEFAULT"))
-     {
-       switch (iq2000_isa)
- 	{
- 	default:
- 	  iq2000_arch_string = "iq2000";
- 	  iq2000_arch = PROCESSOR_IQ2000;
- 	  break;
- 	}
-     }
-   else
-     {
-       iq2000_arch = iq2000_parse_cpu (iq2000_arch_string);
-       if (iq2000_arch == PROCESSOR_DEFAULT)
- 	{
- 	  error ("bad value (%s) for -march= switch", iq2000_arch_string);
- 	  iq2000_arch_string = "default";
- 	}
-       if (iq2000_arch == PROCESSOR_IQ10)
- 	{
- 	  error ("The compiler does not support -march=%s.", iq2000_arch_string);
- 	  iq2000_arch_string = "default";
- 	}
-     }
- 
    iq2000_print_operand_punct['?'] = 1;
    iq2000_print_operand_punct['#'] = 1;
    iq2000_print_operand_punct['&'] = 1;
--- 1633,1644 ----
diff -c /dev/null config/iq2000/iq2000.opt
*** /dev/null	2005-01-29 16:17:39.000000000 +0000
--- config/iq2000/iq2000.opt	2005-03-22 19:54:31.000000000 +0000
***************
*** 0 ****
--- 1,45 ----
+ ; Options for the Vitesse IQ2000 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.
+ 
+ march=
+ Target RejectNegative Joined
+ Specify CPU for code generation purposes
+ 
+ mcpu=
+ Target RejectNegative Joined
+ Specify CPU for scheduling purposes
+ 
+ membedded-data
+ Target Mask(EMBEDDED_DATA)
+ Use ROM instead of RAM
+ 
+ mgpopt
+ Target Mask(GPOPT)
+ Use GP relative sdata/sbss sections
+ 
+ ; Not used by the compiler proper.
+ mno-crt0
+ Target RejectNegative
+ No default crt0.o
+ 
+ muninit-const-in-rodata
+ Target Mask(UNINIT_CONST_IN_RODATA)
+ Put uninitialized constants in ROM (needs -membedded-data)


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