This is a small extension to -mlog * Print double_int with %D or %X * Print supported sub-options with ? * Fix thinko in avr_log_set_avr_log that ignored -mdeb.
Ok for trunk? Johann PR target/50566 * config/avr/avr-protos.h (avr_log_t): Add field .builtin. * config/avr/avr-log.c (avr_log_set_avr_log): Initialize it. Don't ignore TARGET_ALL_DEBUG. Print self-info with ?. (avr_log_vadump): Support %D and %X to print double_int. (avr_double_int_pop_digit): New static function. (avr_dump_double_int_hex): New static function.
Index: config/avr/avr-log.c =================================================================== --- config/avr/avr-log.c (revision 181554) +++ config/avr/avr-log.c (working copy) @@ -47,6 +47,8 @@ t: tree T: tree (brief) C: enum rtx_code + D: double_int (signed decimal) + X: double_int (unsigned hex) m: enum machine_mode R: enum reg_class L: insn list @@ -82,7 +84,7 @@ static void avr_log_vadump (FILE*, const /* As we have no variadic macros, avr_edump maps to a call to avr_log_set_caller_e which saves __FUNCTION__ to avr_log_caller and - returns a function pointer to avr_log_fdump_e. avr_fdump_e + returns a function pointer to avr_log_fdump_e. avr_log_fdump_e gets the printf-like arguments and calls avr_log_vadump, the worker function. avr_fdump works the same way. */ @@ -135,6 +137,49 @@ avr_log_set_caller_f (const char *caller return avr_log_fdump_f; } + +/* Copy-paste from double-int.c:double_int_split_digit (it's static there). + Splits last digit of *CST (taken as unsigned) in BASE and returns it. */ + +static unsigned +avr_double_int_pop_digit (double_int *cst, unsigned base) +{ + unsigned HOST_WIDE_INT resl, reml; + HOST_WIDE_INT resh, remh; + + div_and_round_double (FLOOR_DIV_EXPR, true, cst->low, cst->high, base, 0, + &resl, &resh, &reml, &remh); + cst->high = resh; + cst->low = resl; + + return reml; +} + + +/* Dump VAL as hex value to FILE. */ + +static void +avr_dump_double_int_hex (FILE *file, double_int val) +{ + unsigned digit[4]; + + digit[0] = avr_double_int_pop_digit (&val, 1 << 16); + digit[1] = avr_double_int_pop_digit (&val, 1 << 16); + digit[2] = avr_double_int_pop_digit (&val, 1 << 16); + digit[3] = avr_double_int_pop_digit (&val, 1 << 16); + + fprintf (file, "0x"); + + if (digit[3] | digit[2]) + fprintf (file, "%04x%04x", digit[3], digit[2]); + + if (digit[3] | digit[2] | digit[1] | digit[0]) + fprintf (file, "%04x%04x", digit[1], digit[0]); + else + fprintf (file, "0"); +} + + /* Worker function implementing the %-codes and forwarding to respective print/dump function. */ @@ -189,6 +234,14 @@ avr_log_vadump (FILE *file, const char * fprintf (file, "%d", va_arg (ap, int)); break; + case 'D': + dump_double_int (file, va_arg (ap, double_int), false); + break; + + case 'X': + avr_dump_double_int_hex (file, va_arg (ap, double_int)); + break; + case 'x': fprintf (file, "%x", va_arg (ap, int)); break; @@ -251,7 +304,7 @@ avr_log_vadump (FILE *file, const char * location_t loc = va_arg (ap, location_t); if (BUILTINS_LOCATION == loc) - fprintf (file, "<BUILTIN-LOCATION"); + fprintf (file, "<BUILTIN-LOCATION>"); else if (UNKNOWN_LOCATION == loc) fprintf (file, "<UNKNOWN-LOCATION>"); else @@ -306,21 +359,33 @@ avr_log_vadump (FILE *file, const char * void avr_log_set_avr_log (void) { - if (avr_log_details) + bool all = TARGET_ALL_DEBUG != 0; + + if (all || avr_log_details) { /* Adding , at beginning and end of string makes searching easier. */ char *str = (char*) alloca (3 + strlen (avr_log_details)); + bool info; str[0] = ','; strcat (stpcpy (str+1, avr_log_details), ","); - -#define SET_DUMP_DETAIL(S) \ - avr_log.S = (TARGET_ALL_DEBUG \ - || NULL != strstr (str, "," #S ",") \ - || NULL != strstr (str, ",all,")) + + all |= NULL != strstr (str, ",all,"); + info = NULL != strstr (str, ",?,"); + + if (info) + fprintf (stderr, "\n-mlog="); + +#define SET_DUMP_DETAIL(S) \ + do { \ + avr_log.S = (all || NULL != strstr (str, "," #S ",")); \ + if (info) \ + fprintf (stderr, #S ","); \ + } while (0) SET_DUMP_DETAIL (address_cost); + SET_DUMP_DETAIL (builtin); SET_DUMP_DETAIL (constraints); SET_DUMP_DETAIL (legitimate_address_p); SET_DUMP_DETAIL (legitimize_address); @@ -329,5 +394,8 @@ avr_log_set_avr_log (void) SET_DUMP_DETAIL (rtx_costs); #undef SET_DUMP_DETAIL + + if (info) + fprintf (stderr, "?\n\n"); } } Index: config/avr/avr-protos.h =================================================================== --- config/avr/avr-protos.h (revision 181554) +++ config/avr/avr-protos.h (working copy) @@ -142,6 +142,7 @@ extern void avr_log_set_avr_log (void); typedef struct { unsigned address_cost :1; + unsigned builtin :1; unsigned constraints :1; unsigned legitimate_address_p :1; unsigned legitimize_address :1;