https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116087

--- Comment #4 from Andi Kleen <andi-gcc at firstfloor dot org> ---
After some digging into the code: libcpp already keeps track of how many tokens
get expanded in a global. This is even accessible for through linemap's
statistics dumped on -fmem-report, but only as a averaged statistic:

 if (s.num_expanded_macros != 0)
    fprintf (stderr, "Average number of tokens per macro expansion:  %5ld\n",
             s.num_macro_tokens / s.num_expanded_macros);

I guess a first step would be to make those accessible directly.

diff --git a/gcc/input.cc b/gcc/input.cc
index fabfbfb6eaa..d3b12037ba8 100644
--- a/gcc/input.cc
+++ b/gcc/input.cc
@@ -1325,6 +1325,8 @@ dump_line_table_statistics (void)
   if (s.num_expanded_macros != 0)
     fprintf (stderr, "Average number of tokens per macro expansion:  %5ld\n",
              s.num_macro_tokens / s.num_expanded_macros);
+  fprintf (stderr, "Number of expanded tokens:           " PRsa (5) "\n",
+          SIZE_AMOUNT (s.num_macro_tokens));
   fprintf (stderr,
            "\nLine Table allocations during the "
           "compilation process\n");

Reply via email to