From 2e7a553ae5a7b59ef53873c149a8bc7ee93e5365 Mon Sep 17 00:00:00 2001 From: rth Date: Mon, 9 Nov 2015 09:19:19 +0000 Subject: [PATCH] Add hook for modifying debug info for address spaces * dwarf2out.c (modified_type_die): Pass the address space number through TARGET_ADDR_SPACE_DEBUG to produce the dwarf address class. * target.def (TARGET_ADDR_SPACE_DEBUG): New. * targhooks.c (default_addr_space_debug): New. * targhooks.h (default_addr_space_debug): Declare. * doc/tm.texi.in (TARGET_ADDR_SPACE_DEBUG): Mark it. * doc/tm.texi: Rebuild. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@230000 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 8 ++++++++ gcc/doc/tm.texi | 5 +++++ gcc/doc/tm.texi.in | 2 ++ gcc/dwarf2out.c | 48 +++++++++++++++++++++++++++++------------------- gcc/target.def | 8 ++++++++ gcc/targhooks.c | 8 ++++++++ gcc/targhooks.h | 1 + 7 files changed, 61 insertions(+), 19 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 858f9b8..9a91cf8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,13 @@ 2015-11-09 Richard Henderson + * dwarf2out.c (modified_type_die): Pass the address space number + through TARGET_ADDR_SPACE_DEBUG to produce the dwarf address class. + * target.def (TARGET_ADDR_SPACE_DEBUG): New. + * targhooks.c (default_addr_space_debug): New. + * targhooks.h (default_addr_space_debug): Declare. + * doc/tm.texi.in (TARGET_ADDR_SPACE_DEBUG): Mark it. + * doc/tm.texi: Rebuild. + * gimple.c (check_loadstore): Return false when 0 is a valid address. * fold-const.c (const_unop) [ADDR_SPACE_CONVERT_EXPR]: Do not fold null when 0 is valid in the source address space. diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 56cf60d..5609a98 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -10379,6 +10379,11 @@ guaranteed that one of the two address spaces is a subset of the other, as determined by the @code{TARGET_ADDR_SPACE_SUBSET_P} target hook. @end deftypefn +@deftypefn {Target Hook} int TARGET_ADDR_SPACE_DEBUG (addr_space_t @var{as}) +Define this to define how the address space is encoded in dwarf. +The result is the value to be used with @code{DW_AT_address_class}. +@end deftypefn + @node Misc @section Miscellaneous Parameters @cindex parameters, miscellaneous diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 40abf76..96ca063a 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -7459,6 +7459,8 @@ c_register_addr_space ("__ea", ADDR_SPACE_EA); @hook TARGET_ADDR_SPACE_CONVERT +@hook TARGET_ADDR_SPACE_DEBUG + @node Misc @section Miscellaneous Parameters @cindex parameters, miscellaneous diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 6d02fe7..f184750 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -10899,29 +10899,39 @@ modified_type_die (tree type, int cv_quals, dw_die_ref context_die) mod_type_die = d; } } - else if (code == POINTER_TYPE) + else if (code == POINTER_TYPE || code == REFERENCE_TYPE) { - mod_type_die = new_die (DW_TAG_pointer_type, mod_scope, type); - add_AT_unsigned (mod_type_die, DW_AT_byte_size, - simple_type_size_in_bits (type) / BITS_PER_UNIT); - item_type = TREE_TYPE (type); - if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type))) - add_AT_unsigned (mod_type_die, DW_AT_address_class, - TYPE_ADDR_SPACE (item_type)); - } - else if (code == REFERENCE_TYPE) - { - if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4) - mod_type_die = new_die (DW_TAG_rvalue_reference_type, mod_scope, - type); - else - mod_type_die = new_die (DW_TAG_reference_type, mod_scope, type); + dwarf_tag tag = DW_TAG_pointer_type; + if (code == REFERENCE_TYPE) + { + if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4) + tag = DW_TAG_rvalue_reference_type; + else + tag = DW_TAG_reference_type; + } + mod_type_die = new_die (tag, mod_scope, type); + add_AT_unsigned (mod_type_die, DW_AT_byte_size, simple_type_size_in_bits (type) / BITS_PER_UNIT); item_type = TREE_TYPE (type); - if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type))) - add_AT_unsigned (mod_type_die, DW_AT_address_class, - TYPE_ADDR_SPACE (item_type)); + + addr_space_t as = TYPE_ADDR_SPACE (item_type); + if (!ADDR_SPACE_GENERIC_P (as)) + { + int action = targetm.addr_space.debug (as); + if (action >= 0) + { + /* Positive values indicate an address_class. */ + add_AT_unsigned (mod_type_die, DW_AT_address_class, action); + } + else + { + /* Negative values indicate an (inverted) segment base reg. */ + dw_loc_descr_ref d + = one_reg_loc_descriptor (~action, VAR_INIT_STATUS_INITIALIZED); + add_AT_loc (mod_type_die, DW_AT_segment, d); + } + } } else if (code == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE diff --git a/gcc/target.def b/gcc/target.def index fc52798..0f7d3e5 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -3244,6 +3244,14 @@ as determined by the @code{TARGET_ADDR_SPACE_SUBSET_P} target hook.", rtx, (rtx op, tree from_type, tree to_type), default_addr_space_convert) +/* Function to encode an address space into dwarf. */ +DEFHOOK +(debug, + "Define this to define how the address space is encoded in dwarf.\n\ +The result is the value to be used with @code{DW_AT_address_class}.", + int, (addr_space_t as), + default_addr_space_debug) + HOOK_VECTOR_END (addr_space) #undef HOOK_PREFIX diff --git a/gcc/targhooks.c b/gcc/targhooks.c index d9108a6..c810525 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -1277,6 +1277,14 @@ default_addr_space_zero_address_valid (addr_space_t as ATTRIBUTE_UNUSED) return false; } +/* The default hook for debugging the address space is to return the + address space number to indicate DW_AT_address_class. */ +int +default_addr_space_debug (addr_space_t as) +{ + return as; +} + /* The default hook for TARGET_ADDR_SPACE_CONVERT. This hook should never be called for targets with only a generic address space. */ diff --git a/gcc/targhooks.h b/gcc/targhooks.h index d93d4d7..8747f95 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -178,6 +178,7 @@ extern rtx default_addr_space_legitimize_address (rtx, rtx, machine_mode, addr_space_t); extern bool default_addr_space_subset_p (addr_space_t, addr_space_t); extern bool default_addr_space_zero_address_valid (addr_space_t); +extern int default_addr_space_debug (addr_space_t); extern rtx default_addr_space_convert (rtx, tree, tree); extern unsigned int default_case_values_threshold (void); extern bool default_have_conditional_execution (void); -- 2.7.4