diff options
author | Martin Liska <mliska@suse.cz> | 2016-06-24 18:22:44 +0200 |
---|---|---|
committer | Martin Liska <marxin@gcc.gnu.org> | 2016-06-24 16:22:44 +0000 |
commit | 199b1891cb3855b293e0abf18a894645738e3132 (patch) | |
tree | 58def27bed7c883fb39401708de460fccdea696c /gcc | |
parent | 04619cb86e06ee543dd4ab2b3b8e7fad772883bd (diff) | |
download | gcc-199b1891cb3855b293e0abf18a894645738e3132.zip gcc-199b1891cb3855b293e0abf18a894645738e3132.tar.gz gcc-199b1891cb3855b293e0abf18a894645738e3132.tar.bz2 |
Dump profile-based number of iterations
* analyze_brprob.py: Parse and display average number
of loop iterations.
* cfgloop.c (flow_loop_dump): Dump average number of loop iterations.
* cfgloop.h: Change 'struct loop' to 'const struct loop' for a
few functions.
* cfgloopanal.c (expected_loop_iterations_unbounded): Set a new
argument to true if the expected number of iterations is
loop-based.
From-SVN: r237762
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/cfgloop.c | 12 | ||||
-rw-r--r-- | gcc/cfgloop.h | 7 | ||||
-rw-r--r-- | gcc/cfgloopanal.c | 11 |
4 files changed, 32 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 01c7807..80048f1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2016-06-24 Martin Liska <mliska@suse.cz> + + * cfgloop.c (flow_loop_dump): Dump average number of loop iterations. + * cfgloop.h: Change 'struct loop' to 'const struct loop' for a + few functions. + * cfgloopanal.c (expected_loop_iterations_unbounded): Set a new + argument to true if the expected number of iterations is + loop-based. + 2016-06-24 Uros Bizjak <ubizjak@gmail.com> * configure.ac (HAVE_AS_GOTOF_IN_DATA): Use $as_ix86_gas_32_opt to diff --git a/gcc/cfgloop.c b/gcc/cfgloop.c index 5650f0d..e6174bd 100644 --- a/gcc/cfgloop.c +++ b/gcc/cfgloop.c @@ -136,6 +136,14 @@ flow_loop_dump (const struct loop *loop, FILE *file, loop_depth (loop), (long) (loop_outer (loop) ? loop_outer (loop)->num : -1)); + if (loop->latch) + { + bool read_profile_p; + gcov_type nit = expected_loop_iterations_unbounded (loop, &read_profile_p); + if (read_profile_p && !loop->any_estimate) + fprintf (file, ";; profile-based iteration count: %lu\n", nit); + } + fprintf (file, ";; nodes:"); bbs = get_loop_body (loop); for (i = 0; i < loop->num_nodes; i++) @@ -1913,7 +1921,7 @@ get_estimated_loop_iterations (struct loop *loop, widest_int *nit) false, otherwise returns true. */ bool -get_max_loop_iterations (struct loop *loop, widest_int *nit) +get_max_loop_iterations (const struct loop *loop, widest_int *nit) { if (!loop->any_upper_bound) return false; @@ -1927,7 +1935,7 @@ get_max_loop_iterations (struct loop *loop, widest_int *nit) on the number of iterations of LOOP could not be derived, returns -1. */ HOST_WIDE_INT -get_max_loop_iterations_int (struct loop *loop) +get_max_loop_iterations_int (const struct loop *loop) { widest_int nit; HOST_WIDE_INT hwi_nit; diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h index aba2988..dfc7525 100644 --- a/gcc/cfgloop.h +++ b/gcc/cfgloop.h @@ -319,7 +319,8 @@ extern void verify_loop_structure (void); /* Loop analysis. */ extern bool just_once_each_iteration_p (const struct loop *, const_basic_block); -gcov_type expected_loop_iterations_unbounded (struct loop *); +gcov_type expected_loop_iterations_unbounded (const struct loop *, + bool *read_profile_p = NULL); extern unsigned expected_loop_iterations (struct loop *); extern rtx doloop_condition_get (rtx); @@ -778,10 +779,10 @@ loop_outermost (struct loop *loop) extern void record_niter_bound (struct loop *, const widest_int &, bool, bool); extern HOST_WIDE_INT get_estimated_loop_iterations_int (struct loop *); -extern HOST_WIDE_INT get_max_loop_iterations_int (struct loop *); +extern HOST_WIDE_INT get_max_loop_iterations_int (const struct loop *); extern HOST_WIDE_INT get_likely_max_loop_iterations_int (struct loop *); extern bool get_estimated_loop_iterations (struct loop *loop, widest_int *nit); -extern bool get_max_loop_iterations (struct loop *loop, widest_int *nit); +extern bool get_max_loop_iterations (const struct loop *loop, widest_int *nit); extern bool get_likely_max_loop_iterations (struct loop *loop, widest_int *nit); extern int bb_loop_depth (const_basic_block); diff --git a/gcc/cfgloopanal.c b/gcc/cfgloopanal.c index 938ac43..c163986 100644 --- a/gcc/cfgloopanal.c +++ b/gcc/cfgloopanal.c @@ -231,12 +231,15 @@ average_num_loop_insns (const struct loop *loop) value. */ gcov_type -expected_loop_iterations_unbounded (struct loop *loop) +expected_loop_iterations_unbounded (const struct loop *loop, + bool *read_profile_p) { edge e; edge_iterator ei; gcov_type expected; + if (read_profile_p) + *read_profile_p = false; /* Average loop rolls about 3 times. If we have no profile at all, it is best we can do. */ @@ -258,7 +261,11 @@ expected_loop_iterations_unbounded (struct loop *loop) if (count_in == 0) expected = count_latch * 2; else - expected = (count_latch + count_in - 1) / count_in; + { + expected = (count_latch + count_in - 1) / count_in; + if (read_profile_p) + *read_profile_p = true; + } } else { |