From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 921C2383801C; Mon, 17 May 2021 09:46:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 921C2383801C MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-824] LTO: merge -flto=foo both from IL and linker cmdline X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/heads/master X-Git-Oldrev: b050cf6a4d9c305daff4a96e5a2489ece69dc287 X-Git-Newrev: 3cbcb5d0cfcd1713867ded483cb81148e2ccf0fc Message-Id: <20210517094616.921C2383801C@sourceware.org> Date: Mon, 17 May 2021 09:46:16 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2021 09:46:16 -0000 https://gcc.gnu.org/g:3cbcb5d0cfcd1713867ded483cb81148e2ccf0fc commit r12-824-g3cbcb5d0cfcd1713867ded483cb81148e2ccf0fc Author: Martin Liska Date: Thu May 13 13:41:17 2021 +0200 LTO: merge -flto=foo both from IL and linker cmdline 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. Diff: --- 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 &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 &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 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) {