This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH PING 2/5] Named address spaces: support multiple pointer modes
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: richard dot guenther at gmail dot com (Richard Guenther)
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 21 Sep 2009 15:41:58 +0200 (CEST)
- Subject: Re: [PATCH PING 2/5] Named address spaces: support multiple pointer modes
Richard Guenther wrote:
> + /* As we do not know which address space the pointer is
> refering to, we can
> + handle this only if the target does not support different pointer =
> or
> + address modes depending on the address space. */
> + if (targetm.addr_space.address_mode !=3D default_addr_space_address_=
> mode
> + || targetm.addr_space.pointer_mode !=3D
> default_addr_space_pointer_mode)
>
> I think these changes are ugly. Please at least add a macro
> TARGET_SUPPORTS_ADDR_SPACE_P that expands to this test.
OK, I've checked the patch below into the named-addr-spaces-branch.
> It seems that really you should test if the current TU uses address
> space qualified types, no?
Well, that could be an optimization, I guess. (A more specific one
would be to actually encode the address space pointed to for registers
marked as REG_POINTER. Then we could just use the proper mode ...)
I'm not sure this is worth the effort at this point, as all these
checks make a difference only on targets that simultaneously support
named address spaces and pointer mode != address mode scenarios. We
currently do not have any such targets, the check is just a fail-safe ...
> Why do we need different modes for address spaces at all? As I don't
> really understand the issues here I don't feel qualified to review the
> patch. Sorry. Why would a single mode for all address spaces be enough?
> Isn't everything lowered during expansion, maybe simply using UNSPECs?
Well, we (may) need different modes for pointers to different address
spaces because those pointers may be differently sized. For example,
on the SPU (when using the -mea64 mode), generic pointers are 32-bit
values (or more precisely, 18-bit values stored in a 32-bit field)
refering to the SPU local store, while __ea pointers are 64-bit values
refering to the PowerPC process address space. So you have
sizeof (void *) == 4
sizeof (__ea void *) == 8
Other potential uses of the named address space infrastructure may
likewise require different pointer sizes, e.g. you could implement a
16-bit Intel mode with near / far pointers (2 vs. 4 bytes) and so on ...
I don't quite see where expansion comes in here; the different pointer
sizes are even visible on the language level. In any case, even while
the current SPU patch does indeed lower all non-generic address space
accesses during expansion (because we use a software-emulated cache),
other implementations may well have actual instructions to access
non-generic address spaces, so those will need to be represented
throughout the RTL stages.
(Actually, even on the SPU, operations on __ea pointers *except*
dereference -- copying a pointer value, pointer arithmetic etc. --
*is* expanded into RTL and has to use the proper mode throughout
the RTL stages ...)
Bye,
Ulrich
ChangeLog:
* target-def.h (TARGET_DEFAULT_ADDRESS_POINTER_MODES_P): New macro.
* alias.c: (find_base_value): Use TARGET_DEFAULT_ADDRESS_POINTER_MODES_P
to guard pointer size optimizations.
(find_base_term): Likewise.
* rtlanal.c: (nonzero_bits1): Likewise.
(num_sign_bit_copies1): Likewise.
* simplify-rtx.c: (simplify_unary_operation_1): Likewise.
* alias.c: Include "target-def.h" instead of "targhooks.h".
* rtlanal.c: Likewise.
* simplify-rtx.c: Likewise.
* Makefile.in (alias.o): Update dependencies.
(rtlanal.o): Likewise.
(simplify-rtx.o): Likewise.
Index: gcc/rtlanal.c
===================================================================
*** gcc/rtlanal.c (revision 151727)
--- gcc/rtlanal.c (working copy)
*************** along with GCC; see the file COPYING3.
*** 38,44 ****
#include "function.h"
#include "df.h"
#include "tree.h"
! #include "targhooks.h"
/* Forward declarations */
static void set_of_1 (rtx, const_rtx, void *);
--- 38,44 ----
#include "function.h"
#include "df.h"
#include "tree.h"
! #include "target-def.h"
/* Forward declarations */
static void set_of_1 (rtx, const_rtx, void *);
*************** nonzero_bits1 (const_rtx x, enum machine
*** 3752,3759 ****
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (targetm.addr_space.address_mode == default_addr_space_address_mode
! && targetm.addr_space.pointer_mode == default_addr_space_pointer_mode
&& POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode
&& REG_POINTER (x))
nonzero &= GET_MODE_MASK (ptr_mode);
--- 3752,3758 ----
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (TARGET_DEFAULT_ADDRESS_POINTER_MODES_P
&& POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode
&& REG_POINTER (x))
nonzero &= GET_MODE_MASK (ptr_mode);
*************** nonzero_bits1 (const_rtx x, enum machine
*** 3994,4002 ****
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (targetm.addr_space.address_mode == default_addr_space_address_mode
! && targetm.addr_space.pointer_mode
! == default_addr_space_pointer_mode
&& POINTERS_EXTEND_UNSIGNED > 0 && GET_MODE (x) == Pmode
&& (code == PLUS || code == MINUS)
&& REG_P (XEXP (x, 0)) && REG_POINTER (XEXP (x, 0)))
--- 3993,3999 ----
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (TARGET_DEFAULT_ADDRESS_POINTER_MODES_P
&& POINTERS_EXTEND_UNSIGNED > 0 && GET_MODE (x) == Pmode
&& (code == PLUS || code == MINUS)
&& REG_P (XEXP (x, 0)) && REG_POINTER (XEXP (x, 0)))
*************** num_sign_bit_copies1 (const_rtx x, enum
*** 4274,4281 ****
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (targetm.addr_space.address_mode == default_addr_space_address_mode
! && targetm.addr_space.pointer_mode == default_addr_space_pointer_mode
&& ! POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode
&& mode == Pmode && REG_POINTER (x))
return GET_MODE_BITSIZE (Pmode) - GET_MODE_BITSIZE (ptr_mode) + 1;
--- 4271,4277 ----
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (TARGET_DEFAULT_ADDRESS_POINTER_MODES_P
&& ! POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode
&& mode == Pmode && REG_POINTER (x))
return GET_MODE_BITSIZE (Pmode) - GET_MODE_BITSIZE (ptr_mode) + 1;
*************** num_sign_bit_copies1 (const_rtx x, enum
*** 4476,4483 ****
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (targetm.addr_space.address_mode == default_addr_space_address_mode
! && targetm.addr_space.pointer_mode == default_addr_space_pointer_mode
&& ! POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode
&& (code == PLUS || code == MINUS)
&& REG_P (XEXP (x, 0)) && REG_POINTER (XEXP (x, 0)))
--- 4472,4478 ----
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (TARGET_DEFAULT_ADDRESS_POINTER_MODES_P
&& ! POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode
&& (code == PLUS || code == MINUS)
&& REG_P (XEXP (x, 0)) && REG_POINTER (XEXP (x, 0)))
Index: gcc/alias.c
===================================================================
*** gcc/alias.c (revision 151726)
--- gcc/alias.c (working copy)
*************** along with GCC; see the file COPYING3.
*** 49,55 ****
#include "tree-ssa-alias.h"
#include "pointer-set.h"
#include "tree-flow.h"
! #include "targhooks.h"
/* The aliasing API provided here solves related but different problems:
--- 49,55 ----
#include "tree-ssa-alias.h"
#include "pointer-set.h"
#include "tree-flow.h"
! #include "target-def.h"
/* The aliasing API provided here solves related but different problems:
*************** find_base_value (rtx src)
*** 1053,1060 ****
/* As we do not know which address space the pointer is refering to, we can
handle this only if the target does not support different pointer or
address modes depending on the address space. */
! if (targetm.addr_space.address_mode != default_addr_space_address_mode
! || targetm.addr_space.pointer_mode != default_addr_space_pointer_mode)
break;
if (GET_MODE_SIZE (GET_MODE (src)) < GET_MODE_SIZE (Pmode))
break;
--- 1053,1059 ----
/* As we do not know which address space the pointer is refering to, we can
handle this only if the target does not support different pointer or
address modes depending on the address space. */
! if (!TARGET_DEFAULT_POINTER_ADDRESS_MODES_P)
break;
if (GET_MODE_SIZE (GET_MODE (src)) < GET_MODE_SIZE (Pmode))
break;
*************** find_base_value (rtx src)
*** 1073,1081 ****
/* As we do not know which address space the pointer is refering to, we can
handle this only if the target does not support different pointer or
address modes depending on the address space. */
! if (targetm.addr_space.address_mode != default_addr_space_address_mode
! || targetm.addr_space.pointer_mode != default_addr_space_pointer_mode)
break;
{
rtx temp = find_base_value (XEXP (src, 0));
--- 1072,1080 ----
/* As we do not know which address space the pointer is refering to, we can
handle this only if the target does not support different pointer or
address modes depending on the address space. */
! if (!TARGET_DEFAULT_POINTER_ADDRESS_MODES_P)
break;
+
{
rtx temp = find_base_value (XEXP (src, 0));
*************** find_base_term (rtx x)
*** 1471,1478 ****
/* As we do not know which address space the pointer is refering to, we can
handle this only if the target does not support different pointer or
address modes depending on the address space. */
! if (targetm.addr_space.address_mode != default_addr_space_address_mode
! || targetm.addr_space.pointer_mode != default_addr_space_pointer_mode)
return 0;
if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (Pmode))
return 0;
--- 1470,1476 ----
/* As we do not know which address space the pointer is refering to, we can
handle this only if the target does not support different pointer or
address modes depending on the address space. */
! if (!TARGET_DEFAULT_POINTER_ADDRESS_MODES_P)
return 0;
if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (Pmode))
return 0;
*************** find_base_term (rtx x)
*** 1491,1499 ****
/* As we do not know which address space the pointer is refering to, we can
handle this only if the target does not support different pointer or
address modes depending on the address space. */
! if (targetm.addr_space.address_mode != default_addr_space_address_mode
! || targetm.addr_space.pointer_mode != default_addr_space_pointer_mode)
return 0;
{
rtx temp = find_base_term (XEXP (x, 0));
--- 1489,1497 ----
/* As we do not know which address space the pointer is refering to, we can
handle this only if the target does not support different pointer or
address modes depending on the address space. */
! if (!TARGET_DEFAULT_POINTER_ADDRESS_MODES_P)
return 0;
+
{
rtx temp = find_base_term (XEXP (x, 0));
Index: gcc/simplify-rtx.c
===================================================================
*** gcc/simplify-rtx.c (revision 151727)
--- gcc/simplify-rtx.c (working copy)
*************** along with GCC; see the file COPYING3.
*** 39,45 ****
#include "output.h"
#include "ggc.h"
#include "target.h"
! #include "targhooks.h"
/* Simplification and canonicalization of RTL. */
--- 39,45 ----
#include "output.h"
#include "ggc.h"
#include "target.h"
! #include "target-def.h"
/* Simplification and canonicalization of RTL. */
*************** simplify_unary_operation_1 (enum rtx_cod
*** 967,974 ****
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (targetm.addr_space.address_mode == default_addr_space_address_mode
! && targetm.addr_space.pointer_mode == default_addr_space_pointer_mode
&& ! POINTERS_EXTEND_UNSIGNED
&& mode == Pmode && GET_MODE (op) == ptr_mode
&& (CONSTANT_P (op)
--- 967,973 ----
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (TARGET_DEFAULT_ADDRESS_POINTER_MODES_P
&& ! POINTERS_EXTEND_UNSIGNED
&& mode == Pmode && GET_MODE (op) == ptr_mode
&& (CONSTANT_P (op)
*************** simplify_unary_operation_1 (enum rtx_cod
*** 994,1001 ****
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (targetm.addr_space.address_mode == default_addr_space_address_mode
! && targetm.addr_space.pointer_mode == default_addr_space_pointer_mode
&& POINTERS_EXTEND_UNSIGNED > 0
&& mode == Pmode && GET_MODE (op) == ptr_mode
&& (CONSTANT_P (op)
--- 993,999 ----
/* As we do not know which address space the pointer is refering to,
we can do this only if the target does not support different pointer
or address modes depending on the address space. */
! if (TARGET_DEFAULT_ADDRESS_POINTER_MODES_P
&& POINTERS_EXTEND_UNSIGNED > 0
&& mode == Pmode && GET_MODE (op) == ptr_mode
&& (CONSTANT_P (op)
Index: gcc/target-def.h
===================================================================
*** gcc/target-def.h (revision 151727)
--- gcc/target-def.h (working copy)
***************
*** 505,510 ****
--- 505,518 ----
TARGET_ADDR_SPACE_CONVERT, \
}
+ /* Some places still assume that all pointer or address modes are the
+ standard Pmode and ptr_mode. These optimizations become invalid if
+ the target actually supports multiple different modes. For now,
+ we disable such optimizations on such targets, using this macro. */
+ #define TARGET_DEFAULT_POINTER_ADDRESS_MODES_P \
+ (targetm.addr_space.address_mode == default_addr_space_address_mode \
+ && targetm.addr_space.pointer_mode == default_addr_space_pointer_mode)
+
#ifndef TARGET_SCALAR_MODE_SUPPORTED_P
#define TARGET_SCALAR_MODE_SUPPORTED_P default_scalar_mode_supported_p
#endif
Index: gcc/Makefile.in
===================================================================
*** gcc/Makefile.in (revision 151727)
--- gcc/Makefile.in (working copy)
*************** print-rtl.o : print-rtl.c $(CONFIG_H) $(
*** 2659,2665 ****
rtlanal.o : rtlanal.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TOPLEV_H) \
$(RTL_H) hard-reg-set.h $(TM_P_H) insn-config.h $(RECOG_H) $(REAL_H) \
$(FLAGS_H) $(REGS_H) output.h $(TARGET_H) $(FUNCTION_H) $(TREE_H) \
! targhooks.h $(DF_H)
varasm.o : varasm.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
$(RTL_H) $(FLAGS_H) $(FUNCTION_H) $(EXPR_H) hard-reg-set.h $(REGS_H) \
--- 2659,2665 ----
rtlanal.o : rtlanal.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TOPLEV_H) \
$(RTL_H) hard-reg-set.h $(TM_P_H) insn-config.h $(RECOG_H) $(REAL_H) \
$(FLAGS_H) $(REGS_H) output.h $(TARGET_H) $(FUNCTION_H) $(TREE_H) \
! $(DF_H) $(TARGET_DEF_H)
varasm.o : varasm.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
$(RTL_H) $(FLAGS_H) $(FUNCTION_H) $(EXPR_H) hard-reg-set.h $(REGS_H) \
*************** jump.o : jump.c $(CONFIG_H) $(SYSTEM_H)
*** 2763,2769 ****
simplify-rtx.o : simplify-rtx.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(RTL_H) $(REGS_H) hard-reg-set.h $(FLAGS_H) $(REAL_H) insn-config.h \
$(RECOG_H) $(EXPR_H) $(TOPLEV_H) output.h $(FUNCTION_H) $(GGC_H) $(TM_P_H) \
! $(TREE_H) $(TARGET_H) targhooks.h
cgraph.o : cgraph.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
langhooks.h $(TOPLEV_H) $(FLAGS_H) $(GGC_H) $(TARGET_H) $(CGRAPH_H) \
gt-cgraph.h output.h intl.h $(BASIC_BLOCK_H) debug.h $(HASHTAB_H) \
--- 2763,2769 ----
simplify-rtx.o : simplify-rtx.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(RTL_H) $(REGS_H) hard-reg-set.h $(FLAGS_H) $(REAL_H) insn-config.h \
$(RECOG_H) $(EXPR_H) $(TOPLEV_H) output.h $(FUNCTION_H) $(GGC_H) $(TM_P_H) \
! $(TREE_H) $(TARGET_H) $(TARGET_DEF_H)
cgraph.o : cgraph.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
langhooks.h $(TOPLEV_H) $(FLAGS_H) $(GGC_H) $(TARGET_H) $(CGRAPH_H) \
gt-cgraph.h output.h intl.h $(BASIC_BLOCK_H) debug.h $(HASHTAB_H) \
*************** alias.o : alias.c $(CONFIG_H) $(SYSTEM_H
*** 3068,3074 ****
$(ALIAS_H) $(EMIT_RTL_H) $(GGC_H) $(FUNCTION_H) cselib.h $(TREE_H) $(TM_P_H) \
langhooks.h $(TARGET_H) gt-alias.h $(TIMEVAR_H) $(CGRAPH_H) \
$(SPLAY_TREE_H) $(VARRAY_H) $(IPA_TYPE_ESCAPE_H) $(DF_H) $(TREE_PASS_H) \
! tree-ssa-alias.h pointer-set.h $(TREE_FLOW_H) targhooks.h
stack-ptr-mod.o : stack-ptr-mod.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(TM_H) $(TREE_H) $(RTL_H) $(REGS_H) $(EXPR_H) $(TREE_PASS_H) \
$(BASIC_BLOCK_H) $(FLAGS_H) output.h $(DF_H)
--- 3068,3074 ----
$(ALIAS_H) $(EMIT_RTL_H) $(GGC_H) $(FUNCTION_H) cselib.h $(TREE_H) $(TM_P_H) \
langhooks.h $(TARGET_H) gt-alias.h $(TIMEVAR_H) $(CGRAPH_H) \
$(SPLAY_TREE_H) $(VARRAY_H) $(IPA_TYPE_ESCAPE_H) $(DF_H) $(TREE_PASS_H) \
! tree-ssa-alias.h pointer-set.h $(TREE_FLOW_H) $(TARGET_DEF_H)
stack-ptr-mod.o : stack-ptr-mod.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(TM_H) $(TREE_H) $(RTL_H) $(REGS_H) $(EXPR_H) $(TREE_PASS_H) \
$(BASIC_BLOCK_H) $(FLAGS_H) output.h $(DF_H)
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com