public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: "Martin Liška" <mliska@suse.cz>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] LTO: merge -flto=foo both from IL and linker cmdline
Date: Mon, 17 May 2021 11:05:01 +0200	[thread overview]
Message-ID: <CAFiYyc16O8E5Q7HZGZieyo+puKnNWQzUvDk0M3takbmW0Vyamw@mail.gmail.com> (raw)
In-Reply-To: <999a6bfa-7b11-4565-1437-97d66de977c6@suse.cz>

On Thu, May 13, 2021 at 1:49 PM Martin Liška <mliska@suse.cz> wrote:
>
> Hello.
>
> In g:3835aa0eb90292d652dd6b200f302f3cac7e643f, I changed logic that the output
> -flto=foo argument is taken from IL file command lines. However, it should be also
> merged with linker command line. One can use -flto for compilation and -flto=16 for linking.
>
> Ready after it finishes tests?

OK.

Richard.

> Thanks,
> Martin
>
> gcc/ChangeLog:
>
>         * lto-wrapper.c (merge_flto_options): Factor out a new function.
>         (merge_and_complain): Use it.
>         (run_gcc): Merge also linker command line -flto=foo argument
>         with IL files.
> ---
>   gcc/lto-wrapper.c | 118 +++++++++++++++++++++++++---------------------
>   1 file changed, 65 insertions(+), 53 deletions(-)
>
> diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
> index a71d6147152..1c2643984f9 100644
> --- a/gcc/lto-wrapper.c
> +++ b/gcc/lto-wrapper.c
> @@ -189,6 +189,37 @@ find_option (vec<cl_decoded_option> &options, cl_decoded_option *option)
>     return find_option (options, option->opt_index);
>   }
>
> +/* Merge -flto FOPTION into vector of DECODED_OPTIONS.  */
> +
> +static void
> +merge_flto_options (vec<cl_decoded_option> &decoded_options,
> +                   cl_decoded_option *foption)
> +{
> +  int existing_opt = find_option (decoded_options, foption);
> +  if (existing_opt == -1)
> +    decoded_options.safe_push (*foption);
> +  else
> +    {
> +      if (strcmp (foption->arg, decoded_options[existing_opt].arg) != 0)
> +       {
> +         /* -flto=auto is preferred.  */
> +         if (strcmp (decoded_options[existing_opt].arg, "auto") == 0)
> +           ;
> +         else if (strcmp (foption->arg, "auto") == 0
> +                  || strcmp (foption->arg, "jobserver") == 0)
> +           decoded_options[existing_opt].arg = foption->arg;
> +         else if (strcmp (decoded_options[existing_opt].arg,
> +                          "jobserver") != 0)
> +           {
> +             int n = atoi (foption->arg);
> +             int original_n = atoi (decoded_options[existing_opt].arg);
> +             if (n > original_n)
> +               decoded_options[existing_opt].arg = foption->arg;
> +           }
> +       }
> +    }
> +}
> +
>   /* Try to merge and complain about options FDECODED_OPTIONS when applied
>      ontop of DECODED_OPTIONS.  */
>
> @@ -427,28 +458,7 @@ merge_and_complain (vec<cl_decoded_option> decoded_options,
>           break;
>
>         case OPT_flto_:
> -         if (existing_opt == -1)
> -           decoded_options.safe_push (*foption);
> -         else
> -           {
> -             if (strcmp (foption->arg, decoded_options[existing_opt].arg) != 0)
> -               {
> -                 /* -flto=auto is preferred.  */
> -                 if (strcmp (decoded_options[existing_opt].arg, "auto") == 0)
> -                   ;
> -                 else if (strcmp (foption->arg, "auto") == 0
> -                          || strcmp (foption->arg, "jobserver") == 0)
> -                   decoded_options[existing_opt].arg = foption->arg;
> -                 else if (strcmp (decoded_options[existing_opt].arg,
> -                                  "jobserver") != 0)
> -                   {
> -                     int n = atoi (foption->arg);
> -                     int original_n = atoi (decoded_options[existing_opt].arg);
> -                     if (n > original_n)
> -                       decoded_options[existing_opt].arg = foption->arg;
> -                   }
> -               }
> -           }
> +         merge_flto_options (decoded_options, foption);
>           break;
>         }
>       }
> @@ -1515,37 +1525,6 @@ run_gcc (unsigned argc, char *argv[])
>     append_compiler_options (&argv_obstack, fdecoded_options);
>     append_linker_options (&argv_obstack, decoded_options);
>
> -  /* Process LTO-related options on merged options.  */
> -  for (j = 1; j < fdecoded_options.length (); ++j)
> -    {
> -      cl_decoded_option *option = &fdecoded_options[j];
> -      switch (option->opt_index)
> -       {
> -       case OPT_flto_:
> -         if (strcmp (option->arg, "jobserver") == 0)
> -           {
> -             parallel = 1;
> -             jobserver = 1;
> -           }
> -         else if (strcmp (option->arg, "auto") == 0)
> -           {
> -             parallel = 1;
> -             auto_parallel = 1;
> -           }
> -         else
> -           {
> -             parallel = atoi (option->arg);
> -             if (parallel <= 1)
> -               parallel = 0;
> -           }
> -         /* Fallthru.  */
> -
> -       case OPT_flto:
> -         lto_mode = LTO_MODE_WHOPR;
> -         break;
> -       }
> -    }
> -
>     /* Scan linker driver arguments for things that are of relevance to us.  */
>     for (j = 1; j < decoded_options.length (); ++j)
>       {
> @@ -1574,6 +1553,8 @@ run_gcc (unsigned argc, char *argv[])
>           break;
>
>         case OPT_flto_:
> +         /* Merge linker -flto= option with what we have in IL files.  */
> +         merge_flto_options (fdecoded_options, option);
>           if (strcmp (option->arg, "jobserver") == 0)
>             jobserver_requested = true;
>           break;
> @@ -1596,6 +1577,37 @@ run_gcc (unsigned argc, char *argv[])
>         }
>       }
>
> +  /* Process LTO-related options on merged options.  */
> +  for (j = 1; j < fdecoded_options.length (); ++j)
> +    {
> +      cl_decoded_option *option = &fdecoded_options[j];
> +      switch (option->opt_index)
> +       {
> +       case OPT_flto_:
> +         if (strcmp (option->arg, "jobserver") == 0)
> +           {
> +             parallel = 1;
> +             jobserver = 1;
> +           }
> +         else if (strcmp (option->arg, "auto") == 0)
> +           {
> +             parallel = 1;
> +             auto_parallel = 1;
> +           }
> +         else
> +           {
> +             parallel = atoi (option->arg);
> +             if (parallel <= 1)
> +               parallel = 0;
> +           }
> +         /* Fallthru.  */
> +
> +       case OPT_flto:
> +         lto_mode = LTO_MODE_WHOPR;
> +         break;
> +       }
> +    }
> +
>     /* Output lto-wrapper invocation command.  */
>     if (verbose)
>       {
> --
> 2.31.1
>

      reply	other threads:[~2021-05-17  9:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-13 11:49 Martin Liška
2021-05-17  9:05 ` Richard Biener [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFiYyc16O8E5Q7HZGZieyo+puKnNWQzUvDk0M3takbmW0Vyamw@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mliska@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).