This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[named-addr-space] Cleanup target hooks
- From: Paolo Bonzini <bonzini at gnu dot org>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 16 Jun 2009 07:50:50 -0400
- Subject: [named-addr-space] Cleanup target hooks
This patch completes the transition to TARGET_LEGITIMATE_ADDRESS_P
and TARGET_LEGITIMIZE_ADDRESS, which made the presence of separate
hooks for non-generic address spaces superfluous.
If this is accepted, I'll convert the other targets to add the
new argument, which is a trivial patch.
I also have a followup that eliminates memory_address_addr_space_p
since it can be changed to a direct invocation of the target hook.
Built cc1 for spu-elf. Ok for named-addr-spaces branch?
Thanks,
Paolo
2009-06-14 Paolo Bonzini <bonzini@gnu.org>
* target-def.h (TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P,
TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS): Delete.
* reload.c (strict_memory_address_p): Adjust call to hook.
* explow.c (memory_address_addr_space): Unify hooks.
* recog.c (memory_address_p): Adjust call to hook.
(memory_address_addr_space_p): Unify hooks.
* targhooks.c (default_legitimate_address_p,
default_legitimize_address): Add address space argument.
(default_addr_space_legitimate_address_p,
default_addr_space_legitimize_address): Delete.
* targhooks.h (default_legitimate_address_p,
default_legitimize_address): Add address space argument.
(default_addr_space_legitimate_address_p,
default_addr_space_legitimize_address): Delete.
* target.h (struct gcc_target): Adjust for above changes.
* doc/tm.texi (TARGET_LEGITIMATE_ADDRESS_P,
TARGET_LEGITIMIZE_ADDRESS): Mention address space extensions.
(TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P
TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS): Delete.
* config/spu/spu.c (TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P
TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS,
spu_addr_space_legitimate_address_p,
spu_addr_space_legitimize_address): Delete.
(spu_legitimate_address_p, spu_legitimize_address): Merge
ADDR_SPACE_EA cases here.
Index: gcc/target-def.h
===================================================================
--- gcc/target-def.h (branch nas-cleanup)
+++ gcc/target-def.h (working copy)
@@ -474,16 +474,6 @@
#define TARGET_ADDR_SPACE_NAME default_addr_space_name
#endif
-#ifndef TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P
-#define TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P \
- default_addr_space_legitimate_address_p
-#endif
-
-#ifndef TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS
-#define TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS \
- default_addr_space_legitimize_address
-#endif
-
#ifndef TARGET_ADDR_SPACE_CAN_CONVERT_P
#define TARGET_ADDR_SPACE_CAN_CONVERT_P default_addr_space_can_convert_p
#endif
@@ -509,8 +499,6 @@
TARGET_ADDR_SPACE_POINTER_MODE, \
TARGET_ADDR_SPACE_MINUS_TYPE, \
TARGET_ADDR_SPACE_NAME, \
- TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P, \
- TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS, \
TARGET_ADDR_SPACE_SUBSET_P, \
TARGET_ADDR_SPACE_CAN_CONVERT_P, \
TARGET_ADDR_SPACE_CONVERT, \
Index: gcc/reload.c
===================================================================
--- gcc/reload.c (branch nas-cleanup)
+++ gcc/reload.c (working copy)
@@ -2142,7 +2142,7 @@ strict_memory_address_p (enum machine_mo
win:
return 1;
#else
- return targetm.legitimate_address_p (mode, addr, 1);
+ return targetm.legitimate_address_p (mode, addr, 1, 0);
#endif
}
Index: gcc/explow.c
===================================================================
--- gcc/explow.c (branch nas-cleanup)
+++ gcc/explow.c (working copy)
@@ -450,10 +450,7 @@ memory_address_addr_space (enum machine_
in certain cases. This is not necessary since the code
below can handle all possible cases, but machine-dependent
transformations can make better code. */
- if (!as)
- x = targetm.legitimize_address (x, oldx, mode);
- else
- x = targetm.addr_space.legitimize_address (x, oldx, mode, as);
+ x = targetm.legitimize_address (x, oldx, mode, as);
if (oldx != x && memory_address_addr_space_p (mode, x, as))
goto done;
Index: gcc/recog.c
===================================================================
--- gcc/recog.c (branch nas-cleanup)
+++ gcc/recog.c (working copy)
@@ -1260,7 +1260,7 @@ memory_address_p (enum machine_mode mode
win:
return 1;
#else
- return targetm.legitimate_address_p (mode, addr, 0);
+ return targetm.legitimate_address_p (mode, addr, 0, 0);
#endif
}
@@ -1269,10 +1269,7 @@ memory_address_p (enum machine_mode mode
int
memory_address_addr_space_p (enum machine_mode mode, rtx addr, addr_space_t as)
{
- if (!as)
- return memory_address_p (mode, addr);
- else
- return targetm.addr_space.legitimate_address_p (mode, addr, 0, as);
+ return targetm.legitimate_address_p (mode, addr, 0, as);
}
/* Return 1 if OP is a valid memory reference with mode MODE,
Index: gcc/targhooks.c
===================================================================
--- gcc/targhooks.c (branch nas-cleanup)
+++ gcc/targhooks.c (working copy)
@@ -71,10 +71,12 @@ along with GCC; see the file COPYING3.
bool
default_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
rtx addr ATTRIBUTE_UNUSED,
- bool strict ATTRIBUTE_UNUSED)
+ bool strict ATTRIBUTE_UNUSED,
+ addr_space_t as ATTRIBUTE_UNUSED)
{
#ifdef GO_IF_LEGITIMATE_ADDRESS
/* Defer to the old implementation using a goto. */
+ gcc_assert (!as);
if (strict)
return strict_memory_address_p (mode, addr);
else
@@ -129,7 +131,8 @@ default_return_in_memory (const_tree typ
rtx
default_legitimize_address (rtx x, rtx orig_x ATTRIBUTE_UNUSED,
- enum machine_mode mode ATTRIBUTE_UNUSED)
+ enum machine_mode mode ATTRIBUTE_UNUSED,
+ addr_space_t as ATTRIBUTE_UNUSED)
{
return x;
}
@@ -780,29 +783,6 @@ default_addr_space_name (addr_space_t ad
gcc_unreachable ();
}
-/* Named address space version of legitimate_address_p. */
-
-bool
-default_addr_space_legitimate_address_p (enum machine_mode mode, rtx mem,
- bool strict, addr_space_t as)
-{
- if (as)
- gcc_unreachable ();
-
- return targetm.legitimate_address_p (mode, mem, strict);
-}
-
-/* Named address space version of LEGITIMIZE_ADDRESS. */
-
-rtx
-default_addr_space_legitimize_address (rtx x ATTRIBUTE_UNUSED,
- rtx oldx ATTRIBUTE_UNUSED,
- enum machine_mode mode ATTRIBUTE_UNUSED,
- addr_space_t as ATTRIBUTE_UNUSED)
-{
- return x;
-}
-
/* The default hook for determining if one named address space is a subset of
another and to return which address space to use as the common address
space. */
Index: gcc/targhooks.h
===================================================================
--- gcc/targhooks.h (branch nas-cleanup)
+++ gcc/targhooks.h (working copy)
@@ -18,10 +18,12 @@ You should have received a copy of the G
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
-extern bool default_legitimate_address_p (enum machine_mode, rtx, bool);
+extern bool default_legitimate_address_p (enum machine_mode, rtx, bool,
+ addr_space_t);
extern void default_external_libcall (rtx);
-extern rtx default_legitimize_address (rtx, rtx, enum machine_mode);
+extern rtx default_legitimize_address (rtx, rtx, enum machine_mode,
+ addr_space_t);
extern int default_unspec_may_trap_p (const_rtx, unsigned);
@@ -113,10 +115,6 @@ extern bool default_valid_pointer_mode (
extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
extern tree default_addr_space_minus_type (addr_space_t, addr_space_t);
extern const char *default_addr_space_name (addr_space_t);
-extern bool default_addr_space_legitimate_address_p (enum machine_mode, rtx,
- bool, addr_space_t);
-extern rtx default_addr_space_legitimize_address (rtx, rtx, enum machine_mode,
- addr_space_t);
extern bool default_addr_space_subset_p (addr_space_t, addr_space_t);
extern bool default_addr_space_can_convert_p (tree, tree);
extern rtx default_addr_space_convert (rtx, tree, tree);
Index: gcc/target.h
===================================================================
--- gcc/target.h (branch nas-cleanup)
+++ gcc/target.h (working copy)
@@ -611,13 +611,13 @@ struct gcc_target
/* Given an invalid address X for a given machine mode, try machine-specific
ways to make it legitimate. Return X or an invalid address on failure. */
- rtx (* legitimize_address) (rtx, rtx, enum machine_mode);
+ rtx (* legitimize_address) (rtx, rtx, enum machine_mode, addr_space_t);
/* Given an address RTX, undo the effects of LEGITIMIZE_ADDRESS. */
rtx (* delegitimize_address) (rtx);
- /* Given an address RTX, say whether it is valid. */
- bool (* legitimate_address_p) (enum machine_mode, rtx, bool);
+ /* Given an address RTX, say whether it is valid in the given address space. */
+ bool (* legitimate_address_p) (enum machine_mode, rtx, bool, addr_space_t);
/* True if the given constant can be put into an object_block. */
bool (* use_blocks_for_constant_p) (enum machine_mode, const_rtx);
@@ -690,15 +690,6 @@ struct gcc_target
/* Function to map an address space to a descriptive string. */
const char * (* name) (addr_space_t);
- /* True if an addrress is a valid memory address to a given named address
- space for a given mode. */
- bool (* legitimate_address_p) (enum machine_mode, rtx, bool, addr_space_t);
-
- /* Return an updated address to convert an invalid pointer to a named
- address space to a valid one. If NULL_RTX is returned use machine
- independent methods to make the address valid. */
- rtx (* legitimize_address) (rtx, rtx, enum machine_mode, addr_space_t);
-
/* True if one named address space is a subset of another named address. */
bool (* subset_p) (addr_space_t, addr_space_t);
Index: gcc/config/spu/spu.c
===================================================================
--- gcc/config/spu/spu.c (branch nas-cleanup)
+++ gcc/config/spu/spu.c (working copy)
@@ -152,9 +152,8 @@ char regs_ever_allocated[FIRST_PSEUDO_RE
static void spu_init_builtins (void);
static unsigned char spu_scalar_mode_supported_p (enum machine_mode mode);
static unsigned char spu_vector_mode_supported_p (enum machine_mode mode);
-static bool spu_legitimate_address_p (enum machine_mode, rtx, bool);
-static bool spu_addr_space_legitimate_address_p (enum machine_mode, rtx,
- bool, addr_space_t);
+static bool spu_legitimate_address_p (enum machine_mode, rtx, bool,
+ addr_space_t);
static rtx adjust_operand (rtx op, HOST_WIDE_INT * start);
static rtx get_pic_reg (void);
static int need_to_save_reg (int regno, int saving);
@@ -203,9 +202,7 @@ static void spu_init_libfuncs (void);
static bool spu_return_in_memory (const_tree type, const_tree fntype);
static void fix_range (const char *);
static void spu_encode_section_info (tree, rtx, int);
-static rtx spu_legitimize_address (rtx, rtx, enum machine_mode);
-static rtx spu_addr_space_legitimize_address (rtx, rtx, enum machine_mode,
- addr_space_t);
+static rtx spu_legitimize_address (rtx, rtx, enum machine_mode, addr_space_t);
static tree spu_builtin_mul_widen_even (tree);
static tree spu_builtin_mul_widen_odd (tree);
static tree spu_builtin_mask_for_load (void);
@@ -299,13 +296,6 @@ spu_libgcc_shift_count_mode (void);
#undef TARGET_ADDR_SPACE_NAME
#define TARGET_ADDR_SPACE_NAME spu_addr_space_name
-#undef TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P
-#define TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P \
- spu_addr_space_legitimate_address_p
-
-#undef TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS
-#define TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS spu_addr_space_legitimize_address
-
#undef TARGET_ADDR_SPACE_CAN_CONVERT_P
#define TARGET_ADDR_SPACE_CAN_CONVERT_P spu_addr_space_can_convert_p
@@ -3705,8 +3695,21 @@ spu_legitimate_constant_p (rtx x)
preferable to allow any alignment and fix it up when splitting.) */
static bool
spu_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
- rtx x, bool reg_ok_strict)
+ rtx x, bool reg_ok_strict, addr_space_t as)
{
+ switch (as)
+ {
+ case ADDR_SPACE_EA:
+ return (REG_P (x) && (GET_MODE (x) == EAmode));
+
+ case ADDR_SPACE_GENERIC:
+ /* Handled below. */
+ break;
+
+ default:
+ gcc_unreachable ();
+ }
+
if (mode == TImode && GET_CODE (x) == AND
&& GET_CODE (XEXP (x, 1)) == CONST_INT
&& INTVAL (XEXP (x, 1)) == (HOST_WIDE_INT) -16)
@@ -3784,31 +3787,18 @@ spu_legitimate_address_p (enum machine_m
return 0;
}
-/* Like spu_legitimate_address_p, except with named addresses. */
-static bool
-spu_addr_space_legitimate_address_p (enum machine_mode mode, rtx x,
- bool reg_ok_strict, addr_space_t as)
-{
- if (as == ADDR_SPACE_EA)
- return (REG_P (x) && (GET_MODE (x) == EAmode));
-
- else if (as != ADDR_SPACE_GENERIC)
- gcc_unreachable ();
-
- return spu_legitimate_address_p (mode, x, reg_ok_strict);
-}
-
/* When the address is reg + const_int, force the const_int into a
register. */
static rtx
spu_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
- enum machine_mode mode ATTRIBUTE_UNUSED)
+ enum machine_mode mode ATTRIBUTE_UNUSED,
+ addr_space_t as)
{
rtx op0, op1;
rtx y;
/* Make sure both operands are registers. */
- if (GET_CODE (x) == PLUS)
+ if (as == ADDR_SPACE_GENERIC && GET_CODE (x) == PLUS)
{
op0 = XEXP (x, 0);
op1 = XEXP (x, 1);
@@ -3827,23 +3817,12 @@ spu_legitimize_address (rtx x, rtx oldx
else if (GET_CODE (op1) != REG)
op1 = force_reg (Pmode, op1);
y = gen_rtx_PLUS (Pmode, op0, op1);
- if (spu_legitimate_address_p (mode, y, 0))
+ if (spu_legitimate_address_p (mode, y, 0, as))
return y;
}
return x;
}
-/* Like spu_legitimate_address, except with named address support. */
-static rtx
-spu_addr_space_legitimize_address (rtx x, rtx oldx, enum machine_mode mode,
- addr_space_t as)
-{
- if (as != ADDR_SPACE_GENERIC)
- return x;
-
- return spu_legitimize_address (x, oldx, mode);
-}
-
/* Handle an attribute requiring a FUNCTION_DECL; arguments as in
struct attribute_spec.handler. */
static tree
Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi (branch nas-cleanup)
+++ gcc/doc/tm.texi (working copy)
@@ -5366,9 +5366,12 @@ the maximum number that @code{TARGET_LEG
accept.
@end defmac
-@deftypefn {Target Hook} TARGET_LEGITIMATE_ADDRESS_P (enum machine_mode @var{mode}, rtx @var{x}, bool @var{strict})
+@deftypefn {Target Hook} TARGET_LEGITIMATE_ADDRESS_P (enum machine_mode @var{mode}, rtx @var{x}, bool @var{strict}, addr_space_t @var{as})
A function that returns whether @var{x} (an RTX) is a legitimate memory
address on the target machine for a memory operand of mode @var{mode}.
+Unless the target supports multiple address spaces, @var{as} will always
+be zero and can be ignored (@pxref{Named Address Spaces, , Adding support
+for named address spaces}).
Legitimate addresses are defined in two variants: a strict variant and a
non-strict one. The @code{strict} parameter chooses which variant is
@@ -5450,10 +5453,12 @@ The typical use of this macro is to hand
a label_ref or symbol_ref within an UNSPEC@.
@end defmac
-@deftypefn {Target Hook} rtx TARGET_LEGITIMIZE_ADDRESS (rtx @var{x}, rtx @var{oldx}, enum machine_mode @var{mode})
+@deftypefn {Target Hook} rtx TARGET_LEGITIMIZE_ADDRESS (rtx @var{x}, rtx @var{oldx}, enum machine_mode @var{mode}, addr_space_t @var{as})
This hook is given an invalid memory address @var{x} for an
operand of mode @var{mode} and should try to return a valid memory
-address.
+address. Unless the target supports multiple address spaces,
+@var{as} will always be zero and can be ignored (@pxref{Named
+Address Spaces, , Adding support for named address spaces}).
@findex break_out_memory_refs
@var{x} will always be the result of a call to @code{break_out_memory_refs},
@@ -9798,6 +9803,10 @@ Internally, address spaces are represent
range 0 to 15 with address space 0 being reserved for the generic
address space.
+Implementing address spaces requires implementation of several hooks.
+Besides the ones listed here, @code{TARGET_LEGITIMATE_ADDRESS_P} and
+@code{TARGET_LEGITIMATE_ADDRESS_P} are also affected.
+
@deftypefn {Target Hook} {enum machine_mode} TARGET_ADDR_SPACE_POINTER_MODE (addr_space_t @var{address_space})
Define this to return a pointer mode for a given @var{address_space} if
the target supports named address spaces. The default version of this
@@ -9830,22 +9839,6 @@ named address spaces, the default versio
compiler to abort.
@end deftypefn
-@deftypefn {Target Hook} {bool} TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P (enum machine_mode @var{mode}, rtx @var{exp}, bool @var{strict}, addr_space_t @var{as})
-Define this to return true if @var{exp} is a valid address for mode
-@var{mode} in the named address space @var{as}. The @var{strict}
-parameter says whether strict addressing is in effect after reload has
-finished. This target hook is the same as the
-@code{TARGET_LEGITIMATE_ADDRESS_P} target hook, except that includes
-explicit named address space support.
-@end deftypefn
-
-@deftypefn {Target Hook} {rtx} TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS (rtx @var{x}, rtx @var{oldx}, enum machine_mode @var{mode}, addr_space_t @var{as})
-Define this to modify an invalid address @var{x} to be a valid address
-with mode @var{mode} in the named address space @var{as}. This target
-hook is the same as the @code{LEGITIMIZE_ADDRESS} target hook, except
-that it includes explicit named address space support.
-@end deftypefn
-
@deftypefn {Target Hook} {bool} TARGET_ADDR_SPACE_SUBSET_P (addr_space_t @var{superset}, addr_space_t @var{subset})
Define this to return the @var{subset} named address space is
contained within the @var{superset} named address space. Pointers to