Hello,
I apologize for late reply here. I went thru the paper in gereater
detail. While I originally though the usual path-profiling can be
reasonably merged with the prime math profiling, so it is useful both
for optimizaiton and coverage testing, I think it is better to not do
that - the requirements of prime path profiling are rather specific and
expensive to get right.
>
> gcc/ChangeLog:
>
> * Makefile.in (OBJS): Add prime-paths.o, path-coverage.o.
> (GTFILES): Add prime-paths.cc, path-coverage.cc
> (GCOV_OBJS): Add graphds.o, prime-paths.o, bitmap.o
> * builtins.cc (expand_builtin_fork_or_exec): Check
> path_coverage_flag.
> * collect2.cc (main): Add -fno-path-coverage to OBSTACK.
> * common.opt: Add new options -fpath-coverage,
> -fpath-coverage-limit, -Wcoverage-too-many-paths
> * doc/gcov.texi: Add --prime-paths, --prime-paths-lines,
> --prime-paths-source documentation.
> * doc/invoke.texi: Add -fpath-coverage, -fpath-coverage-limit,
> -Wcoverage-too-many-paths documentation.
> * gcc.cc: Link gcov on -fpath-coverage.
> * gcov-counter.def (GCOV_COUNTER_PATHS): New.
> * gcov-io.h (GCOV_TAG_PATHS): New.
> (GCOV_TAG_PATHS_LENGTH): New.
> (GCOV_TAG_PATHS_NUM): New.
> * gcov.cc (class path_info): New.
> (struct coverage_info): Add paths, paths_covered.
> (find_prime_paths): New.
> (add_path_counts): New.
> (find_arc): New.
> (print_usage): Add -e, --prime-paths, --prime-paths-lines,
> --prime-paths-source.
> (process_args): Likewise.
> (json_set_prime_path_coverage): New.
> (output_json_intermediate_file): Call
> json_set_prime_path_coverage.
> (process_all_functions): Call find_prime_paths.
> (generate_results): Call add_path_counts.
> (read_graph_file): Read path counters.
> (read_count_file): Likewise.
> (function_summary): Print path counts.
> (file_summary): Likewise.
> (print_source_line): New.
> (print_prime_path_lines): New.
> (print_inlined_separator): New.
> (print_prime_path_source): New.
> (output_path_coverage): New.
> (output_lines): Print path coverage.
> * ipa-inline.cc (can_early_inline_edge_p): Check
> path_coverage_flag.
> * passes.cc (finish_optimization_passes): Likewise.
> * profile.cc (branch_prob): Likewise.
> * selftest-run-tests.cc (selftest::run_tests): Run path coverage
> tests.
> * selftest.h (path_coverage_cc_tests): New declaration.
> * tree-profile.cc (tree_profiling): Check path_coverage_flag.
> (pass_ipa_tree_profile::gate): Likewise.
> * path-coverage.cc: New file.
> * prime-paths.cc: New file.
>
> gcc/testsuite/ChangeLog:
>
> * lib/gcov.exp: Add prime paths test function.
> * g++.dg/gcov/gcov-22.C: New test.
> * g++.dg/gcov/gcov-23-1.h: New test.
> * g++.dg/gcov/gcov-23-2.h: New test.
> * g++.dg/gcov/gcov-23.C: New test.
> * gcc.misc-tests/gcov-29.c: New test.
> * gcc.misc-tests/gcov-30.c: New test.
> * gcc.misc-tests/gcov-31.c: New test.
> * gcc.misc-tests/gcov-32.c: New test.
> * gcc.misc-tests/gcov-33.c: New test.
> * gcc.misc-tests/gcov-34.c: New test.
> ---
> gcc/Makefile.in | 6 +-
> gcc/builtins.cc | 2 +-
> gcc/collect2.cc | 6 +-
> gcc/common.opt | 16 +
> gcc/doc/gcov.texi | 187 +++
> gcc/doc/invoke.texi | 36 +
> gcc/gcc.cc | 4 +-
> gcc/gcov-counter.def | 3 +
> gcc/gcov-io.h | 3 +
> gcc/gcov.cc | 487 +++++-
> gcc/ipa-inline.cc | 2 +-
> gcc/passes.cc | 4 +-
> gcc/path-coverage.cc | 776 +++++++++
> gcc/prime-paths.cc | 2052 ++++++++++++++++++++++++
> gcc/profile.cc | 6 +-
> gcc/selftest-run-tests.cc | 1 +
> gcc/selftest.h | 1 +
> gcc/testsuite/g++.dg/gcov/gcov-22.C | 170 ++
> gcc/testsuite/g++.dg/gcov/gcov-23-1.h | 9 +
> gcc/testsuite/g++.dg/gcov/gcov-23-2.h | 9 +
> gcc/testsuite/g++.dg/gcov/gcov-23.C | 30 +
> gcc/testsuite/gcc.misc-tests/gcov-29.c | 869 ++++++++++
> gcc/testsuite/gcc.misc-tests/gcov-30.c | 869 ++++++++++
> gcc/testsuite/gcc.misc-tests/gcov-31.c | 35 +
> gcc/testsuite/gcc.misc-tests/gcov-32.c | 24 +
> gcc/testsuite/gcc.misc-tests/gcov-33.c | 27 +
> gcc/testsuite/gcc.misc-tests/gcov-34.c | 29 +
> gcc/testsuite/lib/gcov.exp | 118 +-
> gcc/tree-profile.cc | 11 +-
> 29 files changed, 5775 insertions(+), 17 deletions(-)
> create mode 100644 gcc/path-coverage.cc
> create mode 100644 gcc/prime-paths.cc
> create mode 100644 gcc/testsuite/g++.dg/gcov/gcov-22.C
> create mode 100644 gcc/testsuite/g++.dg/gcov/gcov-23-1.h
> create mode 100644 gcc/testsuite/g++.dg/gcov/gcov-23-2.h
> create mode 100644 gcc/testsuite/g++.dg/gcov/gcov-23.C
> create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-29.c
> create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-30.c
> create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-31.c
> create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-32.c
> create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-33.c
> create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-34.c
>
> diff --git a/gcc/builtins.cc b/gcc/builtins.cc
> index 9d106405f79..e70a8132337 100644
> --- a/gcc/builtins.cc
> +++ b/gcc/builtins.cc
> @@ -6362,7 +6362,7 @@ expand_builtin_fork_or_exec (tree fn, tree exp, rtx
> target, int ignore)
> tree call;
>
> /* If we are not profiling, just call the function. */
> - if (!profile_arc_flag && !condition_coverage_flag)
> + if (!profile_arc_flag && !condition_coverage_flag && !path_coverage_flag)
It is somewhat ugly to keep adding new flags in many places. Can you
please add predicate profile_instrumentation_p () (better neame welcome)
and use it on all places?
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 18322247fb4..a754405ada6 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -659,6 +659,7 @@ Objective-C and Objective-C++ Dialects}.
> @xref{Instrumentation Options,,Program Instrumentation Options}.
> @gccoptlist{-p -pg -fprofile-arcs --coverage -ftest-coverage
> -fcondition-coverage
> +-fpath-coverage
> -fprofile-abs-path
> -fprofile-dir=@var{path} -fprofile-generate -fprofile-generate=@var{path}
> -fprofile-info-section -fprofile-info-section=@var{name}
> @@ -6689,6 +6690,13 @@ terms and GCC gives up coverage. Coverage is given up
> when there are more
> terms in the conditional than there are bits in a @code{gcov_type_unsigned}.
> This warning is enabled by default.
>
> +@opindex Wno-coverage-too-many-paths
> +@opindex Wcoverage-too-many-paths
> +@item -Wno-coverage-too-many-paths
> +Warn if @option{-fpath-coverage} is used and a function has too many
> +paths and GCC gives up coverage. Giving up is controlled by
> +@option{-fpath-coverage-limit}. This warning is enabled by default.
> +
> @opindex Wno-coverage-invalid-line-number
> @opindex Wcoverage-invalid-line-number
> @item -Wno-coverage-invalid-line-number
> @@ -17464,6 +17472,26 @@ can be used to verify that all terms in a Boolean
> function are tested and have
> an independent effect on the outcome of a decision. The result can be read
> with @code{gcov --conditions}.
>
> +@item -fpath-coverage
> +@opindex fpath-coverage
> +Add code so that the paths taken are tracked. During execution the
> +program records the prime paths taken. The number of paths grows very
> +fast with complexity, and to avoid exploding compile times GCC will give
> +up instrumentation if the approximate number of paths exceeds the limit
> +controlled by @option{-fpath-coverage-limit}. The result can be read
> +with @code{gcov --prime-paths --prime-paths-lines --prime-paths-source}.
Do we have a way to link the section of gcov manual? (I am not quite
sure - my texinfo skills are rather pedestrian).
Patch is OK with this change. Do you plan more profiling work next
stage1? I realize that this is second time I left long patch from you
to slip for many months, which is not good. Contributions are welcome
and I will try to do better.
Honza