aboutsummaryrefslogtreecommitdiff
path: root/gcc/profile.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2018-07-31 12:34:36 +0200
committerMartin Liska <marxin@gcc.gnu.org>2018-07-31 10:34:36 +0000
commite2844b1358f12ae25fd4b7bb95ffcb38c5b2c257 (patch)
treeb7900aba2f8e4ac6802ec6086fcef6f783b59a18 /gcc/profile.c
parent80dde427a00b3121ec7b1b3664208149feaa23a8 (diff)
downloadgcc-e2844b1358f12ae25fd4b7bb95ffcb38c5b2c257.zip
gcc-e2844b1358f12ae25fd4b7bb95ffcb38c5b2c257.tar.gz
gcc-e2844b1358f12ae25fd4b7bb95ffcb38c5b2c257.tar.bz2
GCOV: add cache for streamed locations.
2018-07-31 Martin Liska <mliska@suse.cz> PR gcov-profile/85338 PR gcov-profile/85350 PR gcov-profile/85372 * profile.c (struct location_triplet): New. (struct location_triplet_hash): Likewise. (output_location): Do not output a BB that is already recorded for a line. (branch_prob): Use streamed_locations. 2018-07-31 Martin Liska <mliska@suse.cz> PR gcov-profile/85338 PR gcov-profile/85350 PR gcov-profile/85372 * gcc.misc-tests/gcov-pr85338.c: New test. * gcc.misc-tests/gcov-pr85350.c: New test. * gcc.misc-tests/gcov-pr85372.c: New test. From-SVN: r263113
Diffstat (limited to 'gcc/profile.c')
-rw-r--r--gcc/profile.c91
1 files changed, 83 insertions, 8 deletions
diff --git a/gcc/profile.c b/gcc/profile.c
index 00f37b6..cb51e0d 100644
--- a/gcc/profile.c
+++ b/gcc/profile.c
@@ -919,17 +919,90 @@ compute_value_histograms (histogram_values values, unsigned cfg_checksum,
free (histogram_counts[t]);
}
+/* Location triplet which records a location. */
+struct location_triplet
+{
+ const char *filename;
+ int lineno;
+ int bb_index;
+};
+
+/* Traits class for streamed_locations hash set below. */
+
+struct location_triplet_hash : typed_noop_remove <location_triplet>
+{
+ typedef location_triplet value_type;
+ typedef location_triplet compare_type;
+
+ static hashval_t
+ hash (const location_triplet &ref)
+ {
+ inchash::hash hstate (0);
+ if (ref.filename)
+ hstate.add_int (strlen (ref.filename));
+ hstate.add_int (ref.lineno);
+ hstate.add_int (ref.bb_index);
+ return hstate.end ();
+ }
+
+ static bool
+ equal (const location_triplet &ref1, const location_triplet &ref2)
+ {
+ return ref1.lineno == ref2.lineno
+ && ref1.bb_index == ref2.bb_index
+ && ref1.filename != NULL
+ && ref2.filename != NULL
+ && strcmp (ref1.filename, ref2.filename) == 0;
+ }
+
+ static void
+ mark_deleted (location_triplet &ref)
+ {
+ ref.lineno = -1;
+ }
+
+ static void
+ mark_empty (location_triplet &ref)
+ {
+ ref.lineno = -2;
+ }
+
+ static bool
+ is_deleted (const location_triplet &ref)
+ {
+ return ref.lineno == -1;
+ }
+
+ static bool
+ is_empty (const location_triplet &ref)
+ {
+ return ref.lineno == -2;
+ }
+};
+
+
+
+
/* When passed NULL as file_name, initialize.
When passed something else, output the necessary commands to change
line to LINE and offset to FILE_NAME. */
static void
-output_location (char const *file_name, int line,
+output_location (hash_set<location_triplet_hash> *streamed_locations,
+ char const *file_name, int line,
gcov_position_t *offset, basic_block bb)
{
static char const *prev_file_name;
static int prev_line;
bool name_differs, line_differs;
+ location_triplet triplet;
+ triplet.filename = file_name;
+ triplet.lineno = line;
+ triplet.bb_index = bb ? bb->index : 0;
+
+ if (streamed_locations->add (triplet))
+ return;
+
if (!file_name)
{
prev_file_name = NULL;
@@ -1018,6 +1091,8 @@ branch_prob (void)
flow_call_edges_add (NULL);
add_noreturn_fake_exit_edges ();
+ hash_set <location_triplet_hash> streamed_locations;
+
/* We can't handle cyclic regions constructed using abnormal edges.
To avoid these we replace every source of abnormal edge by a fake
edge from entry node and every destination by fake edge to exit.
@@ -1254,7 +1329,7 @@ branch_prob (void)
/* Line numbers. */
/* Initialize the output. */
- output_location (NULL, 0, NULL, NULL);
+ output_location (&streamed_locations, NULL, 0, NULL, NULL);
hash_set<int_hash <location_t, 0, 2> > seen_locations;
@@ -1268,8 +1343,8 @@ branch_prob (void)
location_t loc = DECL_SOURCE_LOCATION (current_function_decl);
seen_locations.add (loc);
expanded_location curr_location = expand_location (loc);
- output_location (curr_location.file, curr_location.line,
- &offset, bb);
+ output_location (&streamed_locations, curr_location.file,
+ curr_location.line, &offset, bb);
}
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
@@ -1279,8 +1354,8 @@ branch_prob (void)
if (!RESERVED_LOCATION_P (loc))
{
seen_locations.add (loc);
- output_location (gimple_filename (stmt), gimple_lineno (stmt),
- &offset, bb);
+ output_location (&streamed_locations, gimple_filename (stmt),
+ gimple_lineno (stmt), &offset, bb);
}
}
@@ -1294,8 +1369,8 @@ branch_prob (void)
&& !seen_locations.contains (loc))
{
expanded_location curr_location = expand_location (loc);
- output_location (curr_location.file, curr_location.line,
- &offset, bb);
+ output_location (&streamed_locations, curr_location.file,
+ curr_location.line, &offset, bb);
}
if (offset)