[tree-profiling] Debug profile inconsistencies
Jan Hubicka
jh@suse.cz
Sat Apr 17 23:22:00 GMT 2004
Hi,
This patch dumps profile inconsistencies into the debug files.
bootstrapped/regtested i686-pc-gnu-linux, will install it to
tree-profiling branch until I work out to make it less anoying than it
is right now.
Honza
2004-04-17 Jan Hubicka <jh@suse.cz>
* basic-block.h (check_bb_profile): Declare.
* cfg.c (check_bb_function): Break out from...
(dump_flow_info): This one.
* tree-cfg.c (dump_function_to_file): Use it.
* tree-pretty-print.c (dump_bb_header): Likewise.
Index: basic-block.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/basic-block.h,v
retrieving revision 1.153.2.46.2.2
diff -c -3 -p -r1.153.2.46.2.2 basic-block.h
*** basic-block.h 3 Mar 2004 14:17:20 -0000 1.153.2.46.2.2
--- basic-block.h 17 Apr 2004 19:19:47 -0000
*************** extern basic_block first_dom_son (enum c
*** 709,714 ****
--- 709,715 ----
extern basic_block next_dom_son (enum cdi_direction, basic_block);
extern edge try_redirect_by_replacing_jump (edge, basic_block, bool);
extern void break_superblocks (void);
+ extern void check_bb_profile (basic_block, FILE *);
#include "cfghooks.h"
Index: cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfg.c,v
retrieving revision 1.34.2.23.2.7
diff -c -3 -p -r1.34.2.23.2.7 cfg.c
*** cfg.c 30 Mar 2004 23:18:41 -0000 1.34.2.23.2.7
--- cfg.c 17 Apr 2004 19:19:48 -0000
*************** clear_bb_flags (void)
*** 468,473 ****
--- 468,517 ----
bb->flags = 0;
}
+ /* Check the consistency of profile information. We can't do that
+ in verify_flow_info, as the counts may get invalid for incompletely
+ solved graphs, later eliminating of conditionals or roundoff errors.
+ It is still practical to have them reported for debugging of simple
+ testcases. */
+ void
+ check_bb_profile (basic_block bb, FILE * file)
+ {
+ edge e;
+ int sum = 0;
+ gcov_type lsum;
+
+ if (bb != EXIT_BLOCK_PTR)
+ {
+ for (e = bb->succ; e; e = e->succ_next)
+ sum += e->probability;
+ if (bb->succ && abs (sum - REG_BR_PROB_BASE) > 100)
+ fprintf (file, "Invalid sum of outgoing probabilities %.1f%%\n",
+ sum * 100.0 / REG_BR_PROB_BASE);
+ lsum = 0;
+ for (e = bb->succ; e; e = e->succ_next)
+ lsum += e->count;
+ if (bb->succ && (lsum - bb->count > 100 || lsum - bb->count < -100))
+ fprintf (file, "Invalid sum of outgoing counts %i, should be %i\n",
+ (int) lsum, (int) bb->count);
+ }
+ if (bb != ENTRY_BLOCK_PTR)
+ {
+ sum = 0;
+ for (e = bb->pred; e; e = e->pred_next)
+ sum += EDGE_FREQUENCY (e);
+ if (abs (sum - bb->frequency) > 100)
+ fprintf (file,
+ "Invalid sum of incomming frequencies %i, should be %i\n",
+ sum, bb->frequency);
+ lsum = 0;
+ for (e = bb->pred; e; e = e->pred_next)
+ lsum += e->count;
+ if (lsum - bb->count > 100 || lsum - bb->count < -100)
+ fprintf (file, "Invalid sum of incomming counts %i, should be %i\n",
+ (int) lsum, (int) bb->count);
+ }
+ }
+
void
dump_flow_info (FILE *file)
{
*************** dump_flow_info (FILE *file)
*** 526,533 ****
FOR_EACH_BB (bb)
{
edge e;
- int sum;
- gcov_type lsum;
fprintf (file, "\nBasic block %d ", bb->index);
fprintf (file, "prev %d, next %d, ",
--- 570,575 ----
*************** dump_flow_info (FILE *file)
*** 562,598 ****
}
putc ('\n', file);
!
! /* Check the consistency of profile information. We can't do that
! in verify_flow_info, as the counts may get invalid for incompletely
! solved graphs, later eliminating of conditionals or roundoff errors.
! It is still practical to have them reported for debugging of simple
! testcases. */
! sum = 0;
! for (e = bb->succ; e; e = e->succ_next)
! sum += e->probability;
! if (bb->succ && abs (sum - REG_BR_PROB_BASE) > 100)
! fprintf (file, "Invalid sum of outgoing probabilities %.1f%%\n",
! sum * 100.0 / REG_BR_PROB_BASE);
! sum = 0;
! for (e = bb->pred; e; e = e->pred_next)
! sum += EDGE_FREQUENCY (e);
! if (abs (sum - bb->frequency) > 100)
! fprintf (file,
! "Invalid sum of incomming frequencies %i, should be %i\n",
! sum, bb->frequency);
! lsum = 0;
! for (e = bb->pred; e; e = e->pred_next)
! lsum += e->count;
! if (lsum - bb->count > 100 || lsum - bb->count < -100)
! fprintf (file, "Invalid sum of incomming counts %i, should be %i\n",
! (int)lsum, (int)bb->count);
! lsum = 0;
! for (e = bb->succ; e; e = e->succ_next)
! lsum += e->count;
! if (bb->succ && (lsum - bb->count > 100 || lsum - bb->count < -100))
! fprintf (file, "Invalid sum of incomming counts %i, should be %i\n",
! (int)lsum, (int)bb->count);
}
putc ('\n', file);
--- 604,610 ----
}
putc ('\n', file);
! check_bb_profile (bb, file);
}
putc ('\n', file);
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.267.2.10
diff -c -3 -p -r1.1.4.267.2.10 tree-cfg.c
*** tree-cfg.c 3 Apr 2004 16:33:35 -0000 1.1.4.267.2.10
--- tree-cfg.c 17 Apr 2004 19:19:48 -0000
*************** dump_function_to_file (tree fn, FILE *fi
*** 4131,4136 ****
--- 4131,4137 ----
if (basic_block_info)
{
/* Make a CFG based dump. */
+ check_bb_profile (ENTRY_BLOCK_PTR, file);
if (!ignore_topmost_bind)
fprintf (file, "{\n");
*************** dump_function_to_file (tree fn, FILE *fi
*** 4141,4146 ****
--- 4142,4148 ----
dump_generic_bb (file, bb, 2, flags);
fprintf (file, "}\n");
+ check_bb_profile (EXIT_BLOCK_PTR, file);
}
else
{
Index: tree-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-pretty-print.c,v
retrieving revision 1.1.2.73.2.5
diff -c -3 -p -r1.1.2.73.2.5 tree-pretty-print.c
*** tree-pretty-print.c 30 Mar 2004 23:19:30 -0000 1.1.2.73.2.5
--- tree-pretty-print.c 17 Apr 2004 19:19:48 -0000
*************** dump_bb_header (pretty_printer *buffer,
*** 2094,2099 ****
--- 2094,2104 ----
INDENT (indent);
pp_string (buffer, "# BLOCK ");
pp_decimal_int (buffer, bb->index);
+ if (bb->frequency)
+ {
+ pp_string (buffer, " freq ");
+ pp_decimal_int (buffer, bb->frequency);
+ }
if (flags & TDF_LINENO)
{
*************** dump_bb_header (pretty_printer *buffer,
*** 2136,2141 ****
--- 2141,2148 ----
pp_newline (buffer);
}
}
+ pp_write_text_to_stream (buffer);
+ check_bb_profile (bb, buffer->buffer->stream);
}
/* Dumps end of basic block BB to buffer BUFFER indented by INDENT
More information about the Gcc-patches
mailing list