This is the mail archive of the gcc@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] Remove TARGET_ADDR_SPACE_KEYWORDS target macro


Mike Meissner wrote:
> On Wed, May 26, 2010 at 10:16:22AM -0700, Mark Mitchell wrote:
> > Ulrich Weigand wrote:
> > 
> > >> So the question is: The goal is to have hooks, not macros, right? If
> > >> so, can reviewers please take care to reject patches that introduce
> > >> new macros?
> > > 
> > > I don't know to which extent this is a formal goal these days, but I
> > > personally agree that it would be nice to eliminate macros.
> > 
> > Yes, the (informally agreed) policy is to have hooks, not macros.  There
> > may be situations where that is technically impossible, but I'd expect
> > those to be very rare.
> 
> For the target address space stuff, it is to the __ea keyword.  You don't want
> a target hook that is called on every identifier, but instead you want a target
> hook that is called in c_parse_init (in c-parser.c) and init_reswords (in
> cp/lex.c) to set up the keywords.  The target hook would have to duplicate the
> functionality of all of the setup that c_parse_init and init_reswords do,
> particularly if they have different semantics.

It looks like this may be simpler than I thought.  The following patch
introduces a "c_register_addr_space" routine that the back-end may call
to register a named address space qualifier keyword.  (This could be done
either statically at start-up, or even dynamically e.g. in respose to a
target-specific #pragma.)

In the current patch, the SPU back-end uses somewhat of a hack to actually
perform that call: it is included in the REGISTER_TARGET_PRAGMAS macro.
Note that this macro is already being used by the SPU and several other
back-end for similar hacks.  It seems that it might be a good idea to
replace this by something like a "register_target_extensions" callback
in targetcm, but that can probably be done in a separate patch.

The patch below passes all the "__ea" related tests on SPU; a full test
suite run is ongoing.  OK if it passes?

Bye,
Ulrich

ChangeLog:

	* c-common.h (c_register_addr_space): Add prototype.
	(ADDR_SPACE_KEYWORD): Remove.
	* c-common.c (c_register_addr_space): New function.
	(c_addr_space_name): Reimplement.
	(c_common_reswords): Do not include TARGET_ADDR_SPACE_KEYWORDS.

	* config/spu/spu.h (TARGET_ADDR_SPACE_KEYWORDS): Remove.
	(REGISTER_TARGET_PRAGMAS): Call c_register_addr_space.

	* doc/tm.texi (Named Address Spaces): Mention c_register_addr_space.
	Remove TARGET_ADDR_SPACE_KEYWORDS.

Index: gcc/doc/tm.texi
===================================================================
*** gcc/doc/tm.texi	(revision 159889)
--- gcc/doc/tm.texi	(working copy)
*************** Internally, address spaces are represent
*** 9966,9982 ****
  range 0 to 15 with address space 0 being reserved for the generic
  address space.
  
! @defmac TARGET_ADDR_SPACE_KEYWORDS
! A list of @code{ADDR_SPACE_KEYWORD} macros to define each named
! address keyword.  The @code{ADDR_SPACE_KEYWORD} macro takes two
! arguments, the keyword string and the number of the named address
! space.  For example, the SPU port uses the following to declare
! @code{__ea} as the keyword for named address space #1:
  @smallexample
  #define ADDR_SPACE_EA 1
! #define TARGET_ADDR_SPACE_KEYWORDS ADDR_SPACE_KEYWORD ("__ea", ADDR_SPACE_EA)
  @end smallexample
- @end defmac
  
  @deftypefn {Target Hook} {enum machine_mode} TARGET_ADDR_SPACE_POINTER_MODE (addr_space_t @var{address_space})
  Define this to return the machine mode to use for pointers to
--- 9966,9979 ----
  range 0 to 15 with address space 0 being reserved for the generic
  address space.
  
! To register a named address space qualifier keyword with the C front end,
! the target may call the @code{c_register_addr_space} routine.  For example,
! the SPU port uses the following to declare @code{__ea} as the keyword for
! named address space #1:
  @smallexample
  #define ADDR_SPACE_EA 1
! c_register_addr_space ("__ea", ADDR_SPACE_EA);
  @end smallexample
  
  @deftypefn {Target Hook} {enum machine_mode} TARGET_ADDR_SPACE_POINTER_MODE (addr_space_t @var{address_space})
  Define this to return the machine mode to use for pointers to
Index: gcc/c-common.c
===================================================================
*** gcc/c-common.c	(revision 159889)
--- gcc/c-common.c	(working copy)
*************** const struct c_common_resword c_common_r
*** 718,728 ****
    { "inout",		RID_INOUT,		D_OBJC },
    { "oneway",		RID_ONEWAY,		D_OBJC },
    { "out",		RID_OUT,		D_OBJC },
- 
- #ifdef TARGET_ADDR_SPACE_KEYWORDS
-   /* Any address space keywords recognized by the target.  */
-   TARGET_ADDR_SPACE_KEYWORDS,
- #endif
  };
  
  const unsigned int num_c_common_reswords =
--- 718,723 ----
*************** const struct attribute_spec c_common_for
*** 857,873 ****
    { NULL,                     0, 0, false, false, false, NULL }
  };
  
  /* Return identifier for address space AS.  */
  const char *
  c_addr_space_name (addr_space_t as)
  {
!   unsigned int i;
! 
!   for (i = 0; i < num_c_common_reswords; i++)
!     if (c_common_reswords[i].rid == RID_FIRST_ADDR_SPACE + as)
!       return c_common_reswords[i].word;
! 
!   gcc_unreachable ();
  }
  
  /* Push current bindings for the function name VAR_DECLS.  */
--- 852,885 ----
    { NULL,                     0, 0, false, false, false, NULL }
  };
  
+ 
+ /* Register reserved keyword WORD as qualifier for address space AS.  */
+ 
+ void
+ c_register_addr_space (const char *word, addr_space_t as)
+ {
+   int rid = RID_FIRST_ADDR_SPACE + as;
+   tree id;
+ 
+   /* Address space qualifiers are only supported
+      in C with GNU extensions enabled.  */
+   if (c_dialect_cxx () || c_dialect_objc () || flag_no_asm)
+     return;
+ 
+   id = get_identifier (word);
+   C_SET_RID_CODE (id, rid);
+   C_IS_RESERVED_WORD (id) = 1;
+   ridpointers [rid] = id;
+ }
+ 
  /* Return identifier for address space AS.  */
+ 
  const char *
  c_addr_space_name (addr_space_t as)
  {
!   int rid = RID_FIRST_ADDR_SPACE + as;
!   gcc_assert (ridpointers [rid]);
!   return IDENTIFIER_POINTER (ridpointers [rid]);
  }
  
  /* Push current bindings for the function name VAR_DECLS.  */
Index: gcc/c-common.h
===================================================================
*** gcc/c-common.h	(revision 159889)
--- gcc/c-common.h	(working copy)
*************** struct c_common_resword
*** 288,297 ****
  #define D_CXX_OBJC	0x100	/* In Objective C, and C++, but not C.  */
  #define D_CXXWARN	0x200	/* In C warn with -Wcxx-compat.  */
  
- /* Macro for backends to define named address keywords.  */
- #define ADDR_SPACE_KEYWORD(STRING, VALUE) \
-   { STRING, RID_FIRST_ADDR_SPACE + (VALUE), D_CONLY | D_EXT }
- 
  /* The reserved keyword table.  */
  extern const struct c_common_resword c_common_reswords[];
  
--- 288,293 ----
*************** extern const struct attribute_spec c_com
*** 803,808 ****
--- 799,805 ----
  
  extern tree (*make_fname_decl) (location_t, tree, int);
  
+ extern void c_register_addr_space (const char *str, addr_space_t as);
  extern const char *c_addr_space_name (addr_space_t as);
  extern tree identifier_global_value (tree);
  extern void record_builtin_type (enum rid, const char *, tree);
Index: gcc/config/spu/spu.h
===================================================================
*** gcc/config/spu/spu.h	(revision 159889)
--- gcc/config/spu/spu.h	(working copy)
*************** enum reg_class { 
*** 245,250 ****
--- 245,251 ----
  	 && GET_MODE_SIZE (FROM) != GET_MODE_SIZE (TO))
  
  #define REGISTER_TARGET_PRAGMAS() do {					\
+ c_register_addr_space ("__ea", ADDR_SPACE_EA);				\
  targetm.resolve_overloaded_builtin = spu_resolve_overloaded_builtin;	\
  }while (0);
  
*************** targetm.resolve_overloaded_builtin = spu
*** 608,616 ****
  /* Address spaces.  */
  #define ADDR_SPACE_EA	1
  
- /* Named address space keywords.  */
- #define TARGET_ADDR_SPACE_KEYWORDS ADDR_SPACE_KEYWORD ("__ea", ADDR_SPACE_EA)
- 
  
  /* Builtins.  */
  
--- 609,614 ----

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


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