diff mbox

[GOOGLE] Add flag to enalbe AutoFDO accurate mode

Message ID CAO2gOZVs-YERrXhJYgWUe-2+xDZeCH56kAH8yak_SMJfJbb=TQ@mail.gmail.com
State New
Headers show

Commit Message

Dehao Chen Oct. 15, 2013, 5:58 p.m. UTC
This patch add a new flag to let user to tell compiler that the
AutoFDO profile is accurate. So the compiler will assume function
without any sample is UNLIKELY_EXECUTED. This could save 10%~20% text
section size.

Bootstrapped and passed regression test.

OK for google-4_8 branch?

Thanks,
Dehao

       else if (lookup_attribute ("hot", DECL_ATTRIBUTES
(current_function_decl))

Comments

Xinliang David Li Oct. 18, 2013, 3:41 p.m. UTC | #1
ok.

David

On Tue, Oct 15, 2013 at 10:58 AM, Dehao Chen <dehao@google.com> wrote:
> This patch add a new flag to let user to tell compiler that the
> AutoFDO profile is accurate. So the compiler will assume function
> without any sample is UNLIKELY_EXECUTED. This could save 10%~20% text
> section size.
>
> Bootstrapped and passed regression test.
>
> OK for google-4_8 branch?
>
> Thanks,
> Dehao
>
> Index: gcc/common.opt
> ===================================================================
> --- gcc/common.opt (revision 203546)
> +++ gcc/common.opt (working copy)
> @@ -942,6 +942,10 @@ Common Joined RejectNegative Var(auto_profile_file
>  Use sample profile information for call graph node weights. The profile
>  file is specified in the argument.
>
> +fauto-profile-accurate
> +Common Report Var(flag_auto_profile_accurate) Optimization
> +Whether to assume the sample profile is accurate.
> +
>  ; -fcheck-bounds causes gcc to generate array bounds checks.
>  ; For C, C++ and ObjC: defaults off.
>  ; For Java: defaults to on.
> Index: gcc/predict.c
> ===================================================================
> --- gcc/predict.c (revision 203546)
> +++ gcc/predict.c (working copy)
> @@ -2866,7 +2866,9 @@ compute_function_frequency (void)
>        || (flag_auto_profile && profile_status == PROFILE_GUESSED))
>      {
>        int flags = flags_from_decl_or_type (current_function_decl);
> -      if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl))
> +      if (profile_info && flag_auto_profile_accurate)
> + node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
> +      else if (lookup_attribute ("cold", DECL_ATTRIBUTES
> (current_function_decl))
>    != NULL)
>          node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
>        else if (lookup_attribute ("hot", DECL_ATTRIBUTES
> (current_function_decl))
diff mbox

Patch

Index: gcc/common.opt
===================================================================
--- gcc/common.opt (revision 203546)
+++ gcc/common.opt (working copy)
@@ -942,6 +942,10 @@  Common Joined RejectNegative Var(auto_profile_file
 Use sample profile information for call graph node weights. The profile
 file is specified in the argument.

+fauto-profile-accurate
+Common Report Var(flag_auto_profile_accurate) Optimization
+Whether to assume the sample profile is accurate.
+
 ; -fcheck-bounds causes gcc to generate array bounds checks.
 ; For C, C++ and ObjC: defaults off.
 ; For Java: defaults to on.
Index: gcc/predict.c
===================================================================
--- gcc/predict.c (revision 203546)
+++ gcc/predict.c (working copy)
@@ -2866,7 +2866,9 @@  compute_function_frequency (void)
       || (flag_auto_profile && profile_status == PROFILE_GUESSED))
     {
       int flags = flags_from_decl_or_type (current_function_decl);
-      if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl))
+      if (profile_info && flag_auto_profile_accurate)
+ node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
+      else if (lookup_attribute ("cold", DECL_ATTRIBUTES
(current_function_decl))
   != NULL)
         node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;