Use 'location_hash' for 'seen_locations' in 'gcc/profile.c:branch_prob' (was: [PATCH] Fix GCOV CFG related issues)

Thomas Schwinge thomas@codesourcery.com
Tue Nov 9 14:29:27 GMT 2021


Hi!

On 2018-07-25T15:40:24+0200, Martin Liška <mliska@suse.cz> wrote:
> --- a/gcc/profile.c
> +++ b/gcc/profile.c
> @@ -1256,6 +1256,8 @@ branch_prob (void)
>        /* Initialize the output.  */
>        output_location (NULL, 0, NULL, NULL);
>
> +      hash_set<int_hash <location_t, 0, 2> > seen_locations;
> +
>        FOR_EACH_BB_FN (bb, cfun)
>       {
>         gimple_stmt_iterator gsi;

Given my recent commit 088199e5d0fc0d54f48af0783a2630a773bbb387
"Generalize 'gcc/input.h:struct location_hash'", OK to push the attached
"Use 'location_hash' for 'seen_locations' in 'gcc/profile.c:branch_prob'"?


Grüße
 Thomas


> @@ -1263,8 +1265,9 @@ branch_prob (void)
>
>         if (bb == ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb)
>           {
> -           expanded_location curr_location =
> -             expand_location (DECL_SOURCE_LOCATION (current_function_decl));
> +           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);
>           }
> @@ -1272,17 +1275,25 @@ branch_prob (void)
>         for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
>           {
>             gimple *stmt = gsi_stmt (gsi);
> -           if (!RESERVED_LOCATION_P (gimple_location (stmt)))
> -             output_location (gimple_filename (stmt), gimple_lineno (stmt),
> -                              &offset, bb);
> +           location_t loc = gimple_location (stmt);
> +           if (!RESERVED_LOCATION_P (loc))
> +             {
> +               seen_locations.add (loc);
> +               output_location (gimple_filename (stmt), gimple_lineno (stmt),
> +                                &offset, bb);
> +             }
>           }
>
> -       /* Notice GOTO expressions eliminated while constructing the CFG.  */
> +       /* Notice GOTO expressions eliminated while constructing the CFG.
> +          It's hard to distinguish such expression, but goto_locus should
> +          not be any of already seen location.  */
> +       location_t loc;
>         if (single_succ_p (bb)
> -           && !RESERVED_LOCATION_P (single_succ_edge (bb)->goto_locus))
> +           && (loc = single_succ_edge (bb)->goto_locus)
> +           && !RESERVED_LOCATION_P (loc)
> +           && !seen_locations.contains (loc))
>           {
> -           expanded_location curr_location
> -             = expand_location (single_succ_edge (bb)->goto_locus);
> +           expanded_location curr_location = expand_location (loc);
>             output_location (curr_location.file, curr_location.line,
>                              &offset, bb);
>           }


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Use-location_hash-for-seen_locations-in-gcc-profile..patch
Type: text/x-diff
Size: 2567 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20211109/bc826fbf/attachment.bin>


More information about the Gcc-patches mailing list