libdw rejects line tables with discriminators wider than 24 bits.
Keep the discriminator field widths, but temporarily clamp copy IDs to
the 24 bit range. Warn when copy IDs or multiplicity are clamped.
Bootstrapped and regression tested on aarch64-linux-gnu.
gcc/ChangeLog:
* hierarchical_discriminator.cc (update_location_discriminator):
Warn when clamping multiplicity.
(allocate_copyid_base): Temporarily clamp copy IDs for libdw and warn.
Signed-off-by: Kugan Vivekanandarajah <[email protected]>
---
gcc/hierarchical_discriminator.cc | 53 +++++++++++++++++++++++++++----
1 file changed, 47 insertions(+), 6 deletions(-)
diff --git a/gcc/hierarchical_discriminator.cc
b/gcc/hierarchical_discriminator.cc
index 65e1184cae3..aa8ca8bc4ef 100644
--- a/gcc/hierarchical_discriminator.cc
+++ b/gcc/hierarchical_discriminator.cc
@@ -55,7 +55,19 @@ update_location_discriminator (location_t loc,
? multiplicity_factor
: comp.multiplicity * multiplicity_factor;
if (new_mult > DISCR_MULTIPLICITY_MAX)
- new_mult = DISCR_MULTIPLICITY_MAX;
+ {
+ static int warned_uid = -1;
+ if (current_function_decl
+ && warned_uid != (int) DECL_UID (current_function_decl))
+ {
+ warned_uid = DECL_UID (current_function_decl);
+ warning_at (loc, OPT_Wauto_profile,
+ "discriminator multiplicity %u exceeds "
+ "the maximum %u",
+ new_mult, DISCR_MULTIPLICITY_MAX);
+ }
+ new_mult = DISCR_MULTIPLICITY_MAX;
+ }
comp.multiplicity = new_mult;
}
@@ -312,6 +324,12 @@ allocate_copyid_base (location_t loc, unsigned int stride)
if (loc == UNKNOWN_LOCATION)
return 1; /* Return default base copyid. */
+ /* libdw rejects a compilation unit's line table if a discriminator needs
+ more than 24 bits. This is a temporary workaround which does not change
+ the discriminator field widths. */
+ const unsigned int max_copyid = (1U << (24 - DISCR_COPYID_SHIFT)) - 1;
+ static int warned_uid = -1;
+
/* Check if this location has been seen before. */
unsigned int *existing = cfun->copyid_alloc->location_map->get (loc);
if (existing)
@@ -320,9 +338,21 @@ allocate_copyid_base (location_t loc, unsigned int stride)
unsigned int base = *existing;
*existing += stride; /* Update for next duplication. */
- /* Clamp to maximum. */
- if (*existing > DISCR_COPYID_MAX)
- *existing = DISCR_COPYID_MAX;
+ if (*existing > max_copyid)
+ {
+ if (current_function_decl
+ && warned_uid != (int) DECL_UID (current_function_decl))
+ {
+ warned_uid = DECL_UID (current_function_decl);
+ warning_at (loc, OPT_Wauto_profile,
+ "too many copies for distinct discriminator "
+ "copy ids, "
+ "reusing copy id %u", max_copyid);
+ }
+ *existing = max_copyid;
+ if (base > max_copyid)
+ base = max_copyid;
+ }
return base;
}
else
@@ -331,8 +361,19 @@ allocate_copyid_base (location_t loc, unsigned int stride)
Start at 1 (not 0, which means "no copyid"). */
unsigned int base = 1;
unsigned int next = base + stride;
- if (next > DISCR_COPYID_MAX)
- next = DISCR_COPYID_MAX;
+ if (next > max_copyid)
+ {
+ if (current_function_decl
+ && warned_uid != (int) DECL_UID (current_function_decl))
+ {
+ warned_uid = DECL_UID (current_function_decl);
+ warning_at (loc, OPT_Wauto_profile,
+ "too many copies for distinct discriminator "
+ "copy ids, "
+ "reusing copy id %u", max_copyid);
+ }
+ next = max_copyid;
+ }
/* Record this location for future duplications. */
cfun->copyid_alloc->location_map->put (loc, next);
--
2.34.1