diff options
author | xur <xur@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-11-13 00:24:49 +0000 |
---|---|---|
committer | xur <xur@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-11-13 00:24:49 +0000 |
commit | ded3d3f8abc23c9641c8a975da35e16b26ce432a (patch) | |
tree | 37fb2ef6bc9b218262b6180c7c04cd43556c7d23 /libgcc/libgcov-merge.c | |
parent | dda576baf394f4e3ec9a75b72101f918b54f8b86 (diff) | |
download | gcc-ded3d3f8abc23c9641c8a975da35e16b26ce432a.tar.gz |
2013-11-12 Rong Xu <xur@google.com>
The patch re-factors libgcov.c to make it better modulelized.
It contains two pieces of work:
1. break gcov_exit() into the following structure:
gcov_exit()
--> gcov_exit_compute_summary()
--> allocate_filename_struct()
for gi_ptr in gcov_list
--> gcov_exit_dump_gcov()
--> gcov_exit_open_gcda_file()
--> gcov_exit_merge_gcda ()
--> gcov_exit_merge_summary ()
--> gcov_exit_write_gcda ()
2. split libgcov.c into the following files:
libgcov-profiler.c
libgcov-merge.c
libgcov-interface.c
libgcov-driver.c
libgcov-driver-system.c (source included into libgcov-driver.c)
* libgcc/libgcov.c: Delete as part of re-factoring.
* gcc/gcov-io.h (__gcov_indirect_call_profiler): Add the decl to
avoid warning.
* libgcc/libgcov-interface.c (init_mx): Moved from libgcov.c.
(init_mx_once): Ditto.
(__gcov_flush): Ditto.
(__gcov_reset): Ditto.
(__gcov_dump): Ditto.
(__gcov_fork): Ditto.
(__gcov_execl): Ditto.
(__gcov_execlp): Ditto.
(__gcov_execle): Ditto.
(__gcov_execv): Ditto.
(__gcov_execvp): Ditto.
(__gcov_execve): Ditto.
* libgcc/libgcov-merge.c (__gcov_merge_time_profile): Moved from
libgcov.c.
(__gcov_merge_add): Ditto.
(__gcov_merge_ior): Ditto.
(__gcov_merge_single): Ditto.
(__gcov_merge_delta): Ditto.
* libgcc/libgcov-profiler.c
(__gcov_interval_profiler): Ditto.
(__gcov_pow2_profiler): Ditto.
(__gcov_one_value_profiler_body): Ditto.
(__gcov_one_value_profiler): Ditto.
(__gcov_indirect_call_profiler): Ditto.
(__gcov_indirect_call_profiler_v2): Ditto.
(__gcov_time_profiler): Ditto.
(__gcov_average_profiler): Ditto.
(__gcov_ior_profiler): Ditto.
* libgcc/libgcov-driver.c (set_gcov_list): New.
(get_gcov_dump_complete): Ditto.
(set_gcov_dump_complete):Ditto.
(reset_gcov_dump_complete):Ditto.
(gcov_exit_compute_summary): New function split from gcov_exit().
(gcov_exit_merge_gcda): Ditto.
(gcov_exit_write_gcda): Ditto.
(gcov_exit_merge_summary): Ditto.
(gcov_exit_dump_gcov): Ditto.
(struct gcov_fn_buffer): Moved from libgcov.c
(struct gcov_summary_buffer): Ditto.
(free_fn_data): Ditto.
(buffer_fn_data): Ditto.
(crc32_unsigned): Ditto.
(gcov_version): Ditto.
(gcov_histogram_insert): Ditto.
(gcov_compute_histogram): Ditto.
(gcov_exit): Ditto.
(gcov_clear): Ditto.
(__gcov_init): Ditto.
(this_prg): Make it file scope static variable.
(all_prg): Ditto.
(crc32): Ditto.
(gi_filename): Ditto.
(fn_buffer): Ditto.
(sum_buffer): Ditto.
(struct gcov_filename_aux): New types to store auxiliary information
for gi_filename.
* libgcc/libgcov-driver-system.c (gcov_error): New utility function.
(allocate_filename_struct): New function split from gcov_exit().
(gcov_exit_open_gcda_file): Ditto.
(create_file_directory): Moved from libgcov.c
* libgcc/Makefile.in: Change to build newly added files.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@204730 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgcc/libgcov-merge.c')
-rw-r--r-- | libgcc/libgcov-merge.c | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/libgcc/libgcov-merge.c b/libgcc/libgcov-merge.c new file mode 100644 index 00000000000..45cd48cc4c4 --- /dev/null +++ b/libgcc/libgcov-merge.c @@ -0,0 +1,181 @@ +/* Routines required for instrumenting a program. */ +/* Compile this one with gcc. */ +/* Copyright (C) 1989-2013 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#include "tconfig.h" +#include "tsystem.h" +#include "coretypes.h" +#include "tm.h" +#include "libgcc_tm.h" + +#if defined(inhibit_libc) +#define IN_LIBGCOV (-1) +#else +#define IN_LIBGCOV 1 +#endif + +#include "gcov-io.h" + +#if defined(inhibit_libc) +/* If libc and its header files are not available, provide dummy functions. */ + +#ifdef L_gcov_merge_add +void __gcov_merge_add (gcov_type *counters __attribute__ ((unused)), + unsigned n_counters __attribute__ ((unused))) {} +#endif + +#ifdef L_gcov_merge_single +void __gcov_merge_single (gcov_type *counters __attribute__ ((unused)), + unsigned n_counters __attribute__ ((unused))) {} +#endif + +#ifdef L_gcov_merge_delta +void __gcov_merge_delta (gcov_type *counters __attribute__ ((unused)), + unsigned n_counters __attribute__ ((unused))) {} +#endif + +#else + +#ifdef L_gcov_merge_add +/* The profile merging function that just adds the counters. It is given + an array COUNTERS of N_COUNTERS old counters and it reads the same number + of counters from the gcov file. */ +void +__gcov_merge_add (gcov_type *counters, unsigned n_counters) +{ + for (; n_counters; counters++, n_counters--) + *counters += gcov_read_counter (); +} +#endif /* L_gcov_merge_add */ + +#ifdef L_gcov_merge_ior +/* The profile merging function that just adds the counters. It is given + an array COUNTERS of N_COUNTERS old counters and it reads the same number + of counters from the gcov file. */ +void +__gcov_merge_ior (gcov_type *counters, unsigned n_counters) +{ + for (; n_counters; counters++, n_counters--) + *counters |= gcov_read_counter (); +} +#endif + +#ifdef L_gcov_merge_time_profile +/* Time profiles are merged so that minimum from all valid (greater than zero) + is stored. There could be a fork that creates new counters. To have + the profile stable, we chosen to pick the smallest function visit time. */ +void +__gcov_merge_time_profile (gcov_type *counters, unsigned n_counters) +{ + unsigned int i; + gcov_type value; + + for (i = 0; i < n_counters; i++) + { + value = gcov_read_counter (); + + if (value && (!counters[i] || value < counters[i])) + counters[i] = value; + } +} +#endif /* L_gcov_merge_time_profile */ + +#ifdef L_gcov_merge_single +/* The profile merging function for choosing the most common value. + It is given an array COUNTERS of N_COUNTERS old counters and it + reads the same number of counters from the gcov file. The counters + are split into 3-tuples where the members of the tuple have + meanings: + + -- the stored candidate on the most common value of the measured entity + -- counter + -- total number of evaluations of the value */ +void +__gcov_merge_single (gcov_type *counters, unsigned n_counters) +{ + unsigned i, n_measures; + gcov_type value, counter, all; + + gcc_assert (!(n_counters % 3)); + n_measures = n_counters / 3; + for (i = 0; i < n_measures; i++, counters += 3) + { + value = gcov_read_counter (); + counter = gcov_read_counter (); + all = gcov_read_counter (); + + if (counters[0] == value) + counters[1] += counter; + else if (counter > counters[1]) + { + counters[0] = value; + counters[1] = counter - counters[1]; + } + else + counters[1] -= counter; + counters[2] += all; + } +} +#endif /* L_gcov_merge_single */ + +#ifdef L_gcov_merge_delta +/* The profile merging function for choosing the most common + difference between two consecutive evaluations of the value. It is + given an array COUNTERS of N_COUNTERS old counters and it reads the + same number of counters from the gcov file. The counters are split + into 4-tuples where the members of the tuple have meanings: + + -- the last value of the measured entity + -- the stored candidate on the most common difference + -- counter + -- total number of evaluations of the value */ +void +__gcov_merge_delta (gcov_type *counters, unsigned n_counters) +{ + unsigned i, n_measures; + gcov_type value, counter, all; + + gcc_assert (!(n_counters % 4)); + n_measures = n_counters / 4; + for (i = 0; i < n_measures; i++, counters += 4) + { + /* last = */ gcov_read_counter (); + value = gcov_read_counter (); + counter = gcov_read_counter (); + all = gcov_read_counter (); + + if (counters[1] == value) + counters[2] += counter; + else if (counter > counters[2]) + { + counters[1] = value; + counters[2] = counter - counters[2]; + } + else + counters[2] -= counter; + counters[3] += all; + } +} +#endif /* L_gcov_merge_delta */ +#endif /* inhibit_libc */ |