> 2013-11-19  Rong Xu  <x...@google.com>
> 
>       * gcc/gcov-io.h: Add atomic function macros for compiler use.
>       * gcc/common.opt (fprofile-generate-atomic): New option.
>       * gcc/tree-profile.c (gimple_init_edge_profiler): Support for
>         atomic counter update.
>       (gimple_gen_edge_profiler): Ditto.
>       * libgcc/libgcov-profiler.c 
>       (__gcov_interval_profiler_atomic): Ditto.
>       (__gcov_pow2_profiler_atomic): Ditto.
>       (__gcov_one_value_profiler_body_atomic): Ditto.
>       (__gcov_one_value_profiler_atomic): Ditto.
>       (__gcov_indirect_call_profiler_atomic): Ditto.
>       (__gcov_indirect_call_profiler_v2_atomic): Ditto.
>       (__gcov_time_profiler_atomic): Ditto.
>       (__gcov_average_profiler_atomic): Ditto.
>       * gcc/gcc.c: Link libatomic when -fprofile-generate-atomic used.
>       * libgcc/Makefile.in: Add atomic objects.
> 
> Index: gcc/common.opt
> ===================================================================
> --- gcc/common.opt    (revision 205053)
> +++ gcc/common.opt    (working copy)
> @@ -1684,6 +1684,15 @@ fprofile-correction
>  Common Report Var(flag_profile_correction)
>  Enable correction of flow inconsistent profile data input
>  
> +; fprofile-generate-atomic=0: default and disable atomical update.
> +; fprofile-generate-atomic=1: atomically update edge profile counters.
> +; fprofile-generate-atomic=2: atomically update value profile counters.
> +; fprofile-generate-atomic=3: atomically update edge and value profile 
> counters.
> +; other values will be ignored (fall back to the default of 0).
> +fprofile-generate-atomic=
> +Common Joined UInteger Report Var(flag_profile_generate_atomic) Init(3) 
> Optimization
> +fprofile-generate-atomic=[0..3] Atomical increments of profile counters.

Instead magic numbers I would preffer flags, like "edge" and "value"
and permiting combinations like -ffprofile-generate-atomic=edge,value

I wonder about the option name, I suppose this option also combine with 
-ftest-coverage
(and no longer too useful -fprofile-arcs), so the profile-generate prefix may 
be bit
misleading here (giving an impression that it is not useful in this case).
But I can't think of something really better.

Other thing I wonder about is that we may want to implement alternative 
solution with
TLS or smaller per-thread buffers and locked updates.  It would be bit 
difficult to 
extend -fprofile-generate-atomic to this...

> @@ -155,6 +155,9 @@ gimple_init_edge_profiler (void)
>    tree ic_profiler_fn_type;
>    tree average_profiler_fn_type;
>    tree time_profiler_fn_type;
> +  const char *fn_name;
> +  bool profile_gen_value_atomic = (flag_profile_generate_atomic == 2 ||
> +                                   flag_profile_generate_atomic == 3);
>  
>    if (!gcov_type_node)
>      {

Will this work with optimization attributes?

The rest of patch looks OK, lets settle option name and get it in.
Sorry for dropping the ball for 4.8.

Reply via email to