From patchwork Thu May 13 11:49:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1478041 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fgqhf7536z9sW1 for ; Thu, 13 May 2021 21:49:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F8FD383D026; Thu, 13 May 2021 11:49:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 71CF3385781A for ; Thu, 13 May 2021 11:49:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 71CF3385781A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mliska@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 78A73B021; Thu, 13 May 2021 11:49:47 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] LTO: merge -flto=foo both from IL and linker cmdline To: gcc-patches@gcc.gnu.org Message-ID: <999a6bfa-7b11-4565-1437-97d66de977c6@suse.cz> Date: Thu, 13 May 2021 13:49:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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? 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 &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) {