public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6131] driver: Improve option diagnostics [PR103465]
@ 2021-12-28 10:05 Martin Liska
  0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2021-12-28 10:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a187edd2b437fc9571d57f771a624963fcce08f8

commit r12-6131-ga187edd2b437fc9571d57f771a624963fcce08f8
Author: Martin Liska <mliska@suse.cz>
Date:   Fri Dec 10 09:58:52 2021 +0100

    driver: Improve option diagnostics [PR103465]
    
    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);
    ...
    
            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.

Diff:
---
 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 cdd6463e49b..e4e47ff77b3 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1014,8 +1014,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)
     {
@@ -1116,61 +1114,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)
@@ -1406,6 +1349,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.  */
 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-28 10:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-28 10:05 [gcc r12-6131] driver: Improve option diagnostics [PR103465] Martin Liska

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).