This allows to emit decls in 'shared' memory from the middle-end. * config/nvptx/nvptx.c (nvptx_legitimate_address_p): Adjust prototype. (nvptx_section_for_decl): If type of decl has a specific address space, return it. (nvptx_addr_space_from_address): Ditto. (TARGET_ADDR_SPACE_POINTER_MODE): Define. (TARGET_ADDR_SPACE_ADDRESS_MODE): Ditto. (TARGET_ADDR_SPACE_SUBSET_P): Ditto. (TARGET_ADDR_SPACE_CONVERT): Ditto. (TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P): Ditto. --- gcc/config/nvptx/nvptx.c | 49 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-)
diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index a619e4c..779b018 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -1571,7 +1571,7 @@ nvptx_maybe_convert_symbolic_operand (rtx orig_op) /* Returns true if X is a valid address for use in a memory reference. */ static bool -nvptx_legitimate_address_p (machine_mode, rtx x, bool) +nvptx_legitimate_address_p (machine_mode, rtx x, bool, addr_space_t) { enum rtx_code code = GET_CODE (x); @@ -1642,7 +1642,10 @@ nvptx_section_for_decl (const_tree decl) if (is_const) return ".const"; - return ".global"; + addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl)); + if (as == ADDR_SPACE_GENERIC) + as = ADDR_SPACE_GLOBAL; + return nvptx_section_from_addr_space (as); } /* Look for a SYMBOL_REF in ADDR and return the address space to be used @@ -1666,6 +1669,9 @@ nvptx_addr_space_from_address (rtx addr) if (is_const) return ADDR_SPACE_CONST; + if (TYPE_ADDR_SPACE (TREE_TYPE (decl)) != ADDR_SPACE_GENERIC) + return TYPE_ADDR_SPACE (TREE_TYPE (decl)); + return ADDR_SPACE_GLOBAL; } @@ -4916,14 +4922,49 @@ nvptx_use_anchors_for_symbol (const_rtx ARG_UNUSED (symbol)) return false; } +#undef TARGET_ADDR_SPACE_POINTER_MODE +#define TARGET_ADDR_SPACE_POINTER_MODE nvptx_addr_space_pointer_mode +static enum machine_mode +nvptx_addr_space_pointer_mode (addr_space_t) +{ + return Pmode; +} + +#undef TARGET_ADDR_SPACE_ADDRESS_MODE +#define TARGET_ADDR_SPACE_ADDRESS_MODE nvptx_addr_space_address_mode +static enum machine_mode +nvptx_addr_space_address_mode (addr_space_t) +{ + return Pmode; +} + +#undef TARGET_ADDR_SPACE_SUBSET_P +#define TARGET_ADDR_SPACE_SUBSET_P nvptx_addr_space_subset_p +static bool +nvptx_addr_space_subset_p (addr_space_t /*subset*/, + addr_space_t superset) +{ + return superset == ADDR_SPACE_GENERIC; +} + +#undef TARGET_ADDR_SPACE_CONVERT +#define TARGET_ADDR_SPACE_CONVERT nvptx_addr_space_convert + +static rtx +nvptx_addr_space_convert (rtx op, tree /*from_type*/, tree to_type) +{ + gcc_checking_assert (TYPE_ADDR_SPACE (to_type) == ADDR_SPACE_GENERIC); + return nvptx_maybe_convert_symbolic_operand (op); +} + #undef TARGET_OPTION_OVERRIDE #define TARGET_OPTION_OVERRIDE nvptx_option_override #undef TARGET_ATTRIBUTE_TABLE #define TARGET_ATTRIBUTE_TABLE nvptx_attribute_table -#undef TARGET_LEGITIMATE_ADDRESS_P -#define TARGET_LEGITIMATE_ADDRESS_P nvptx_legitimate_address_p +#undef TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P +#define TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P nvptx_legitimate_address_p #undef TARGET_PROMOTE_FUNCTION_MODE #define TARGET_PROMOTE_FUNCTION_MODE nvptx_promote_function_mode