Commit cdc3b883 by Martin Liska Committed by Martin Liska

Support lower and upper limit for -fdbg-cnt flag.

2018-05-18  Martin Liska  <mliska@suse.cz>

	* dbgcnt.c (limit_low): Renamed from limit.
	(limit_high): New variable.
	(dbg_cnt_is_enabled): Check for upper limit.
	(dbg_cnt): Adjust dumping.
	(dbg_cnt_set_limit_by_index): Add new argument for high
	value.
	(dbg_cnt_set_limit_by_name): Likewise.
	(dbg_cnt_process_single_pair): Parse new format.
	(dbg_cnt_process_opt): Use strtok.
	(dbg_cnt_list_all_counters): Remove 'value' and add
	'limit_high'.
	* doc/invoke.texi: Document changes.
2018-05-18  Martin Liska  <mliska@suse.cz>

	* gcc.dg/ipa/ipa-icf-39.c: New test.
	* gcc.dg/pr68766.c: Adjust pruned output.

From-SVN: r260349
parent c566cc9f
2018-05-18 Martin Liska <mliska@suse.cz>
* dbgcnt.c (limit_low): Renamed from limit.
(limit_high): New variable.
(dbg_cnt_is_enabled): Check for upper limit.
(dbg_cnt): Adjust dumping.
(dbg_cnt_set_limit_by_index): Add new argument for high
value.
(dbg_cnt_set_limit_by_name): Likewise.
(dbg_cnt_process_single_pair): Parse new format.
(dbg_cnt_process_opt): Use strtok.
(dbg_cnt_list_all_counters): Remove 'value' and add
'limit_high'.
* doc/invoke.texi: Document changes.
2018-05-18 Richard Sandiford <richard.sandiford@linaro.org> 2018-05-18 Richard Sandiford <richard.sandiford@linaro.org>
* doc/sourcebuild.texi (scalar_all_fma): Document. * doc/sourcebuild.texi (scalar_all_fma): Document.
......
...@@ -1171,7 +1171,7 @@ List all available debugging counters with their limits and counts. ...@@ -1171,7 +1171,7 @@ List all available debugging counters with their limits and counts.
fdbg-cnt= fdbg-cnt=
Common RejectNegative Joined Var(common_deferred_options) Defer Common RejectNegative Joined Var(common_deferred_options) Defer
-fdbg-cnt=<counter>:<limit>[,<counter>:<limit>,...] Set the debug counter limit. -fdbg-cnt=<counter>[:<lower_limit>]:<upper_limit>[,<counter>:...] Set the debug counter limit.
fdebug-prefix-map= fdebug-prefix-map=
Common Joined RejectNegative Var(common_deferred_options) Defer Common Joined RejectNegative Var(common_deferred_options) Defer
......
...@@ -41,53 +41,84 @@ static struct string2counter_map map[debug_counter_number_of_counters] = ...@@ -41,53 +41,84 @@ static struct string2counter_map map[debug_counter_number_of_counters] =
#undef DEBUG_COUNTER #undef DEBUG_COUNTER
#define DEBUG_COUNTER(a) UINT_MAX, #define DEBUG_COUNTER(a) UINT_MAX,
static unsigned int limit[debug_counter_number_of_counters] = static unsigned int limit_high[debug_counter_number_of_counters] =
{ {
#include "dbgcnt.def" #include "dbgcnt.def"
}; };
#undef DEBUG_COUNTER #undef DEBUG_COUNTER
static unsigned int limit_low[debug_counter_number_of_counters];
static unsigned int count[debug_counter_number_of_counters]; static unsigned int count[debug_counter_number_of_counters];
bool bool
dbg_cnt_is_enabled (enum debug_counter index) dbg_cnt_is_enabled (enum debug_counter index)
{ {
return count[index] <= limit[index]; unsigned v = count[index];
return v > limit_low[index] && v <= limit_high[index];
} }
bool bool
dbg_cnt (enum debug_counter index) dbg_cnt (enum debug_counter index)
{ {
count[index]++; count[index]++;
if (dump_file && count[index] == limit[index])
fprintf (dump_file, "***dbgcnt: limit reached for %s.***\n", if (dump_file)
map[index].name); {
/* Do not print the info for default lower limit. */
if (count[index] == limit_low[index] && limit_low[index] > 0)
fprintf (dump_file, "***dbgcnt: lower limit %d reached for %s.***\n",
limit_low[index], map[index].name);
else if (count[index] == limit_high[index])
fprintf (dump_file, "***dbgcnt: upper limit %d reached for %s.***\n",
limit_high[index], map[index].name);
}
return dbg_cnt_is_enabled (index); return dbg_cnt_is_enabled (index);
} }
static void static void
dbg_cnt_set_limit_by_index (enum debug_counter index, int value) dbg_cnt_set_limit_by_index (enum debug_counter index, int low, int high)
{ {
limit[index] = value; limit_low[index] = low;
limit_high[index] = high;
fprintf (stderr, "dbg_cnt '%s' set to %d\n", map[index].name, value); fprintf (stderr, "dbg_cnt '%s' set to %d-%d\n", map[index].name, low, high);
} }
static bool static bool
dbg_cnt_set_limit_by_name (const char *name, int len, int value) dbg_cnt_set_limit_by_name (const char *name, int low, int high)
{ {
if (high < low)
{
error ("-fdbg-cnt=%s:%d:%d has smaller upper limit than the lower",
name, low, high);
return false;
}
if (low < 0)
{
error ("Lower limit %d of -fdbg-cnt=%s must be a non-negative number", low,
name);
return false;
}
if (high < 0)
{
error ("Upper limit %d of -fdbg-cnt=%s must be a non-negative number", high,
name);
return false;
}
int i; int i;
for (i = debug_counter_number_of_counters - 1; i >= 0; i--) for (i = debug_counter_number_of_counters - 1; i >= 0; i--)
if (strncmp (map[i].name, name, len) == 0 if (strcmp (map[i].name, name) == 0)
&& map[i].name[len] == '\0')
break; break;
if (i < 0) if (i < 0)
return false; return false;
dbg_cnt_set_limit_by_index ((enum debug_counter) i, value); dbg_cnt_set_limit_by_index ((enum debug_counter) i, low, high);
return true; return true;
} }
...@@ -96,42 +127,53 @@ dbg_cnt_set_limit_by_name (const char *name, int len, int value) ...@@ -96,42 +127,53 @@ dbg_cnt_set_limit_by_name (const char *name, int len, int value)
Returns NULL if there's no valid pair is found. Returns NULL if there's no valid pair is found.
Otherwise returns a pointer to the end of the pair. */ Otherwise returns a pointer to the end of the pair. */
static const char * static bool
dbg_cnt_process_single_pair (const char *arg) dbg_cnt_process_single_pair (const char *arg)
{ {
const char *colon = strchr (arg, ':'); char *str = xstrdup (arg);
char *endptr = NULL; char *name = strtok (str, ":");
int value; char *value1 = strtok (NULL, ":");
char *value2 = strtok (NULL, ":");
if (colon == NULL) int high, low;
return NULL;
value = strtol (colon + 1, &endptr, 10); if (value1 == NULL)
return NULL;
if (endptr != NULL && endptr != colon + 1 if (value2 == NULL)
&& dbg_cnt_set_limit_by_name (arg, colon - arg, value)) {
return endptr; low = 0;
high = strtol (value1, NULL, 10);
}
else
{
low = strtol (value1, NULL, 10);
high = strtol (value2, NULL, 10);
}
return NULL; return dbg_cnt_set_limit_by_name (name, low, high);
} }
void void
dbg_cnt_process_opt (const char *arg) dbg_cnt_process_opt (const char *arg)
{ {
const char *start = arg; char *str = xstrdup (arg);
const char *next; const char *next = strtok (str, ",");
unsigned int start = 0;
do { do {
next = dbg_cnt_process_single_pair (arg); if (!dbg_cnt_process_single_pair (arg))
if (next == NULL)
break; break;
} while (*next == ',' && (arg = next + 1)); start += strlen (arg) + 1;
next = strtok (NULL, ",");
} while (next != NULL);
if (next == NULL || *next != 0) if (next != NULL)
{ {
char *buffer = XALLOCAVEC (char, arg - start + 2); char *buffer = XALLOCAVEC (char, start + 2);
sprintf (buffer, "%*c", (int)(1 + (arg - start)), '^'); sprintf (buffer, "%*c", start + 1, '^');
error ("cannot find a valid counter:value pair:"); error ("cannot find a valid counter:value pair:");
error ("-fdbg-cnt=%s", start); error ("-fdbg-cnt=%s", next);
error (" %s", buffer); error (" %s", buffer);
} }
} }
...@@ -142,10 +184,11 @@ void ...@@ -142,10 +184,11 @@ void
dbg_cnt_list_all_counters (void) dbg_cnt_list_all_counters (void)
{ {
int i; int i;
printf (" %-30s %-5s %-5s\n", "counter name", "limit", "value"); printf (" %-32s %-11s %-12s\n", "counter name", "low limit",
printf ("----------------------------------------------\n"); "high limit");
printf ("-----------------------------------------------------------------\n");
for (i = 0; i < debug_counter_number_of_counters; i++) for (i = 0; i < debug_counter_number_of_counters; i++)
printf (" %-30s %5d %5u\n", printf (" %-30s %11u %12u\n",
map[i].name, limit[map[i].counter], count[map[i].counter]); map[i].name, limit_low[map[i].counter], limit_high[map[i].counter]);
printf ("\n"); printf ("\n");
} }
...@@ -14331,14 +14331,17 @@ Print the name and the counter upper bound for all debug counters. ...@@ -14331,14 +14331,17 @@ Print the name and the counter upper bound for all debug counters.
@item -fdbg-cnt=@var{counter-value-list} @item -fdbg-cnt=@var{counter-value-list}
@opindex fdbg-cnt @opindex fdbg-cnt
Set the internal debug counter upper bound. @var{counter-value-list} Set the internal debug counter lower and upper bound. @var{counter-value-list}
is a comma-separated list of @var{name}:@var{value} pairs is a comma-separated list of @var{name}:@var{lower_bound}:@var{upper_bound}
which sets the upper bound of each debug counter @var{name} to @var{value}. tuples which sets the lower and the upper bound of each debug
counter @var{name}. The @var{lower_bound} is optional and is zero
initialized if not set.
All debug counters have the initial upper bound of @code{UINT_MAX}; All debug counters have the initial upper bound of @code{UINT_MAX};
thus @code{dbg_cnt} returns true always unless the upper bound thus @code{dbg_cnt} returns true always unless the upper bound
is set by this option. is set by this option.
For example, with @option{-fdbg-cnt=dce:10,tail_call:0}, For example, with @option{-fdbg-cnt=dce:2:4,tail_call:10},
@code{dbg_cnt(dce)} returns true only for first 10 invocations. @code{dbg_cnt(dce)} returns true only for third and fourth invocation.
For @code{dbg_cnt(tail_call)} true is returned for first 10 invocations.
@item -print-file-name=@var{library} @item -print-file-name=@var{library}
@opindex print-file-name @opindex print-file-name
2018-05-18 Martin Liska <mliska@suse.cz>
* gcc.dg/ipa/ipa-icf-39.c: New test.
* gcc.dg/pr68766.c: Adjust pruned output.
2018-05-18 Richard Sandiford <richard.sandiford@linaro.org> 2018-05-18 Richard Sandiford <richard.sandiford@linaro.org>
* lib/target-supports.exp (check_effective_target_scalar_all_fma): * lib/target-supports.exp (check_effective_target_scalar_all_fma):
......
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-ipa-icf -fmerge-all-constants -fdbg-cnt=merged_ipa_icf:1:3" } */
/* { dg-prune-output "dbg_cnt 'merged_ipa_icf' set to 1-3" } */
static int a;
static int b;
static const int c = 2;
static const int d = 2;
static char * e = "test";
static char * f = "test";
static int g[3]={1,2,3};
static int h[3]={1,2,3};
static const int *i=&c;
static const int *j=&c;
static const int *k=&d;
int t(int tt)
{
switch (tt)
{
case 1: return a;
case 2: return b;
case 3: return c;
case 4: return d;
case 5: return e[1];
case 6: return f[1];
case 7: return g[1];
case 8: return h[1];
case 9: return i[0];
case 10: return j[0];
case 11: return k[0];
}
}
/* { dg-final { scan-ipa-dump-times "Unified;" 2 "icf" } } */
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-O2 -ftree-vectorize -fdbg-cnt=vect_loop:1" } */ /* { dg-options "-O2 -ftree-vectorize -fdbg-cnt=vect_loop:1" } */
/* { dg-additional-options "-mavx2" { target { i?86-*-* x86_64-*-* } } } */ /* { dg-additional-options "-mavx2" { target { i?86-*-* x86_64-*-* } } } */
/* { dg-prune-output "dbg_cnt 'vect_loop' set to 1" } */ /* { dg-prune-output "dbg_cnt 'vect_loop' set to 1-1" } */
int a, b, g, h; int a, b, g, h;
int c[58]; int c[58];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment