From patchwork Fri Dec 10 10:04:50 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: 48764 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5BD1A3857C78 for ; Fri, 10 Dec 2021 10:05:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 4849F3858037 for ; Fri, 10 Dec 2021 10:04:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4849F3858037 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id EC32B210EA; Fri, 10 Dec 2021 10:04:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1639130690; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hdsqS0P37W5WbUIOMrUrGRmLjn3AeJmvu5abYba6ZR4=; b=MRgVz/js/5I7ngNngJC546zEjCCiNiwX1mfmSrharmojkD02r2UtohcroTNA6NJKJITS0y FWXOSLlTnnTrhWpuOFGmcQ7RTyTrHEkiy6S2iN1ftzMY030PriFKzF4lILtDtmrNBQNZT4 /iKrkM92tFjTHaCiJNABtK4JUufAFOg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1639130690; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hdsqS0P37W5WbUIOMrUrGRmLjn3AeJmvu5abYba6ZR4=; b=AxyqvU0vLccvRC+91VJ5elwn9Qw8u4Zix0KOwVaZf0nnI/L46S084Z8YIK61UgHL9pUG2t FDumaatOWNDoAZBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D2DE113C1D; Fri, 10 Dec 2021 10:04:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aMeoMUIms2F6RQAAMHmgww (envelope-from ); Fri, 10 Dec 2021 10:04:50 +0000 Message-ID: Date: Fri, 10 Dec 2021 11:04:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] driver: Improve option diagnostics [PR103465] To: gcc-patches@gcc.gnu.org Content-Language: en-US X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" It happens that options are parsed and various diagnostics happen in finish_options. That's a proper place as the function is also called for optimize/target attributes (pragmas). However, it is possible that target overwrites an option from command line and so the diagnostics does not happen. That's fixed in the patch. - options are parsed and finish_options is called: if (opts->x_flag_unwind_tables && !targetm_common.unwind_tables_default && opts->x_flag_reorder_blocks_and_partition && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)) { if (opts_set->x_flag_reorder_blocks_and_partition) inform (loc, "%<-freorder-blocks-and-partition%> does not support " "unwind info on this architecture"); opts->x_flag_reorder_blocks_and_partition = 0; opts->x_flag_reorder_blocks = 1; } It's not triggered because of opts->x_flag_unwind_tables is false by default, but the option is overwritten in target: ... if (TARGET_64BIT_P (opts->x_ix86_isa_flags)) { if (opts->x_optimize >= 1) SET_OPTION_IF_UNSET (opts, opts_set, flag_omit_frame_pointer, !USE_IX86_FRAME_POINTER); if (opts->x_flag_asynchronous_unwind_tables && TARGET_64BIT_MS_ABI) SET_OPTION_IF_UNSET (opts, opts_set, flag_unwind_tables, 1); ... Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin PR driver/103465 gcc/ChangeLog: * opts.c (finish_options): More part of diagnostics to ... (diagnose_options): ... here. Call the function from both finish_options and process_options. * opts.h (diagnose_options): Declare. * toplev.c (process_options): Call diagnose_options. --- gcc/opts.c | 125 ++++++++++++++++++++++++++++----------------------- gcc/opts.h | 2 + gcc/toplev.c | 2 + 3 files changed, 72 insertions(+), 57 deletions(-) diff --git a/gcc/opts.c b/gcc/opts.c index 870cceca85a..525640b2968 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -1005,8 +1005,6 @@ void finish_options (struct gcc_options *opts, struct gcc_options *opts_set, location_t loc) { - enum unwind_info_type ui_except; - if (opts->x_dump_base_name && ! opts->x_dump_base_name_prefixed) { @@ -1107,61 +1105,6 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, opts->x_flag_no_inline = 1; } - /* The optimization to partition hot and cold basic blocks into separate - sections of the .o and executable files does not work (currently) - with exception handling. This is because there is no support for - generating unwind info. If opts->x_flag_exceptions is turned on - we need to turn off the partitioning optimization. */ - - ui_except = targetm_common.except_unwind_info (opts); - - if (opts->x_flag_exceptions - && opts->x_flag_reorder_blocks_and_partition - && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)) - { - if (opts_set->x_flag_reorder_blocks_and_partition) - inform (loc, - "%<-freorder-blocks-and-partition%> does not work " - "with exceptions on this architecture"); - opts->x_flag_reorder_blocks_and_partition = 0; - opts->x_flag_reorder_blocks = 1; - } - - /* If user requested unwind info, then turn off the partitioning - optimization. */ - - if (opts->x_flag_unwind_tables - && !targetm_common.unwind_tables_default - && opts->x_flag_reorder_blocks_and_partition - && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)) - { - if (opts_set->x_flag_reorder_blocks_and_partition) - inform (loc, - "%<-freorder-blocks-and-partition%> does not support " - "unwind info on this architecture"); - opts->x_flag_reorder_blocks_and_partition = 0; - opts->x_flag_reorder_blocks = 1; - } - - /* If the target requested unwind info, then turn off the partitioning - optimization with a different message. Likewise, if the target does not - support named sections. */ - - if (opts->x_flag_reorder_blocks_and_partition - && (!targetm_common.have_named_sections - || (opts->x_flag_unwind_tables - && targetm_common.unwind_tables_default - && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)))) - { - if (opts_set->x_flag_reorder_blocks_and_partition) - inform (loc, - "%<-freorder-blocks-and-partition%> does not work " - "on this architecture"); - opts->x_flag_reorder_blocks_and_partition = 0; - opts->x_flag_reorder_blocks = 1; - } - - /* Pipelining of outer loops is only possible when general pipelining capabilities are requested. */ if (!opts->x_flag_sel_sched_pipelining) @@ -1397,6 +1340,74 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, && debug_info_level >= DINFO_LEVEL_NORMAL && dwarf_debuginfo_p () && !(flag_selective_scheduling || flag_selective_scheduling2)); + + diagnose_options (opts, opts_set, loc); +} + +/* The function diagnoses incompatible combinations for provided options + (OPTS and OPTS_SET) at a given LOCation. The function is called both + when command line is parsed (after the target optimization hook) and + when an optimize/target attribute (or pragma) is used. */ + +void diagnose_options (gcc_options *opts, gcc_options *opts_set, + location_t loc) +{ + /* The optimization to partition hot and cold basic blocks into separate + sections of the .o and executable files does not work (currently) + with exception handling. This is because there is no support for + generating unwind info. If opts->x_flag_exceptions is turned on + we need to turn off the partitioning optimization. */ + + enum unwind_info_type ui_except + = targetm_common.except_unwind_info (opts); + + if (opts->x_flag_exceptions + && opts->x_flag_reorder_blocks_and_partition + && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)) + { + if (opts_set->x_flag_reorder_blocks_and_partition) + inform (loc, + "%<-freorder-blocks-and-partition%> does not work " + "with exceptions on this architecture"); + opts->x_flag_reorder_blocks_and_partition = 0; + opts->x_flag_reorder_blocks = 1; + } + + /* If user requested unwind info, then turn off the partitioning + optimization. */ + + if (opts->x_flag_unwind_tables + && !targetm_common.unwind_tables_default + && opts->x_flag_reorder_blocks_and_partition + && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)) + { + if (opts_set->x_flag_reorder_blocks_and_partition) + inform (loc, + "%<-freorder-blocks-and-partition%> does not support " + "unwind info on this architecture"); + opts->x_flag_reorder_blocks_and_partition = 0; + opts->x_flag_reorder_blocks = 1; + } + + /* If the target requested unwind info, then turn off the partitioning + optimization with a different message. Likewise, if the target does not + support named sections. */ + + if (opts->x_flag_reorder_blocks_and_partition + && (!targetm_common.have_named_sections + || (opts->x_flag_unwind_tables + && targetm_common.unwind_tables_default + && (ui_except == UI_SJLJ || ui_except >= UI_TARGET)))) + { + if (opts_set->x_flag_reorder_blocks_and_partition) + inform (loc, + "%<-freorder-blocks-and-partition%> does not work " + "on this architecture"); + opts->x_flag_reorder_blocks_and_partition = 0; + opts->x_flag_reorder_blocks = 1; + } + + } #define LEFT_COLUMN 27 diff --git a/gcc/opts.h b/gcc/opts.h index 4c2b77ec0f0..8003d26bda6 100644 --- a/gcc/opts.h +++ b/gcc/opts.h @@ -428,6 +428,8 @@ extern bool target_handle_option (struct gcc_options *opts, extern void finish_options (struct gcc_options *opts, struct gcc_options *opts_set, location_t loc); +extern void diagnose_options (gcc_options *opts, gcc_options *opts_set, + location_t loc); extern void print_help (struct gcc_options *opts, unsigned int lang_mask, const char *help_option_argument); extern void default_options_optimization (struct gcc_options *opts, diff --git a/gcc/toplev.c b/gcc/toplev.c index 99276bde87d..6727c9f314f 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -1718,6 +1718,8 @@ process_options (bool no_backend) if (flag_large_source_files) line_table->default_range_bits = 0; + diagnose_options (&global_options, &global_options_set, UNKNOWN_LOCATION); + /* Please don't change global_options after this point, those changes won't be reflected in optimization_{default,current}_node. */ }