This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch RFA: Let languages control -ffast-math


"Joseph S. Myers" <joseph@codesourcery.com> writes:

> On Sat, 5 Feb 2011, Ian Lance Taylor wrote:
>
>> This patch adds a new language hook apply_combined_option which lets the
>> frontend control whether a meta-option like -ffast-math should affect
>> another more specific option.  This is a general mechanism and is named
>> accordingly, but in fact at present it seems only appropriate for
>> -ffast-math and -funsafe-math-optimizations, so I would be willing to
>> give it a more specific name if that seems appropriate.
>
> opts.c is not meant to use langhooks; I moved anything that would be 
> problematic to share with the driver into opts-global.c so that opts.c can 
> in future be shared with the driver.  So it would be better in that 
> regard, though less general, for the init_options langhook to set 
> something in the gcc_options struct indicating that a particular option 
> should not be controlled by -ffast-math.
>
> (Various targets have linker specs 
> %{ffast-math|funsafe-math-optimizations:crtfastmath.o%s} and it would be 
> good if in future they could be based on logical state of 
> flag_unsafe_math_optimizations in the driver, so knowing these 
> implications in the driver is potentially useful.  But certainly such 
> driver processing can only operate with language-independent defaults 
> since it may be linking a multi-language program.)

OK, here is an approach more along those lines.

I am currently bootstrapping and testing this with all default languages
(except Java) on x86_64-unknown-linux-gnu, but I expect no problems as a
bootstrap with Go has succeeded.  Is this patch OK if bootstrap and
testing succeeds?

Ian


2011-02-07  Ian Lance Taylor  <iant@google.com>

	* common.opt (fcx-limited-range): Add SetByCombined flag.
	(ffinite-math-only, fmath-errno, frounding-math): Likewise.
	(fsignaling-nans, fsigned-zeros, ftrapping-math): Likewise.
	(fassociative-math, freciprocal-math): Likewise.
	(funsafe-math-optimizations): Likewise.
	* opth-gen.awk: Handle SetByCombined.
	* optc-gen.awk: Likewise.
	* opts.c (set_fast_math_flags): Don't override flag if set by
	frontend.
	(set_unsafe_math_optimizations_flags): Likewise.
	* doc/options.texi (Option properties): Document SetByCombined.


Index: common.opt
===================================================================
--- common.opt	(revision 169848)
+++ common.opt	(working copy)
@@ -1,6 +1,6 @@
 ; Options for the language- and target-independent parts of the compiler.
 
-; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
 ; Free Software Foundation, Inc.
 ;
 ; This file is part of GCC.
@@ -878,7 +878,7 @@ Common Ignore
 Does nothing.  Preserved for backward compatibility.
 
 fcx-limited-range
-Common Report Var(flag_cx_limited_range) Optimization
+Common Report Var(flag_cx_limited_range) Optimization SetByCombined
 Omit range reduction step when performing complex division
 
 fcx-fortran-rules
@@ -1024,7 +1024,7 @@ ffast-math
 Common
 
 ffinite-math-only
-Common Report Var(flag_finite_math_only) Optimization
+Common Report Var(flag_finite_math_only) Optimization SetByCombined
 Assume no NaNs or infinities are generated
 
 ffixed-
@@ -1340,7 +1340,7 @@ Common Report Var(flag_lto_report) Init(
 Report various link-time optimization statistics
 
 fmath-errno
-Common Report Var(flag_errno_math) Init(1) Optimization
+Common Report Var(flag_errno_math) Init(1) Optimization SetByCombined
 Set errno after built-in math functions
 
 fmax-errors=
@@ -1577,7 +1577,7 @@ Common Ignore
 Does nothing.  Preserved for backward compatibility.
 
 frounding-math
-Common Report Var(flag_rounding_math) Optimization
+Common Report Var(flag_rounding_math) Optimization SetByCombined
 Disable optimizations that assume default FP rounding behavior
 
 fsched-interblock
@@ -1706,11 +1706,11 @@ Common Report Var(flag_show_column) Init
 Show column numbers in diagnostics, when available.  Default on
 
 fsignaling-nans
-Common Report Var(flag_signaling_nans) Optimization
+Common Report Var(flag_signaling_nans) Optimization SetByCombined
 Disable optimizations observable by IEEE signaling NaNs
 
 fsigned-zeros
-Common Report Var(flag_signed_zeros) Init(1) Optimization
+Common Report Var(flag_signed_zeros) Init(1) Optimization SetByCombined
 Disable floating point optimizations that ignore the IEEE signedness of zero
 
 fsingle-precision-constant
@@ -1827,7 +1827,7 @@ Perform superblock formation via tail du
 ; (user-visible) trap.  This is the case, for example, in nonstop
 ; IEEE 754 arithmetic.
 ftrapping-math
-Common Report Var(flag_trapping_math) Init(1) Optimization
+Common Report Var(flag_trapping_math) Init(1) Optimization SetByCombined
 Assume floating-point operations can trap
 
 ftrapv
@@ -1978,12 +1978,12 @@ Common Report Var(flag_unsafe_loop_optim
 Allow loop optimizations to assume that the loops behave in normal way
 
 fassociative-math
-Common Report Var(flag_associative_math)
+Common Report Var(flag_associative_math) SetByCombined
 Allow optimization for floating-point arithmetic which may change the
 result of the operation due to rounding.
 
 freciprocal-math
-Common Report Var(flag_reciprocal_math)
+Common Report Var(flag_reciprocal_math) SetByCombined
 Same as -fassociative-math for expressions which include division.
 
 ; Nonzero means that unsafe floating-point math optimizations are allowed
@@ -1991,7 +1991,7 @@ Same as -fassociative-math for expressio
 ; are allowed to assume that their arguments and results are "normal"
 ; (e.g., nonnegative for SQRT).
 funsafe-math-optimizations
-Common Report Var(flag_unsafe_math_optimizations) Optimization
+Common Report Var(flag_unsafe_math_optimizations) Optimization SetByCombined
 Allow math optimizations that may violate IEEE or ISO standards
 
 funswitch-loops
Index: opth-gen.awk
===================================================================
--- opth-gen.awk	(revision 169848)
+++ opth-gen.awk	(working copy)
@@ -1,4 +1,4 @@
-#  Copyright (C) 2003,2004,2005,2006,2007,2008, 2010
+#  Copyright (C) 2003,2004,2005,2006,2007,2008, 2010, 2011
 #  Free Software Foundation, Inc.
 #  Contributed by Kelley Cook, June 2004.
 #  Original code from Neil Booth, May 2003.
@@ -193,6 +193,13 @@ for (i = 0; i < n_opts; i++) {
 		print "#endif"
 	}
 }
+for (i = 0; i < n_opts; i++) {
+	if (flag_set_p("SetByCombined", flags[i])) {
+		print "#ifndef GENERATOR_FILE"
+		print "  bool frontend_set_" var_name(flags[i]) ";"
+		print "#endif"
+	}
+}
 print "#ifndef GENERATOR_FILE"
 print "};"
 print "extern struct gcc_options global_options;"
Index: optc-gen.awk
===================================================================
--- optc-gen.awk	(revision 169848)
+++ optc-gen.awk	(working copy)
@@ -1,4 +1,4 @@
-#  Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010
+#  Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011
 #  Free Software Foundation, Inc.
 #  Contributed by Kelley Cook, June 2004.
 #  Original code from Neil Booth, May 2003.
@@ -250,6 +250,10 @@ for (i = 0; i < n_opts; i++) {
 		print "#undef x_" name
 	}
 }
+for (i = 0; i < n_opts; i++) {
+	if (flag_set_p("SetByCombined", flags[i]))
+		print "  false, /* frontend_set_" var_name(flags[i]) " */"
+}
 print "};"
 print ""
 print "struct gcc_options global_options;"
Index: opts.c
===================================================================
--- opts.c	(revision 169848)
+++ opts.c	(working copy)
@@ -1,5 +1,5 @@
 /* Command line option handling.
-   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
    Contributed by Neil Booth.
 
@@ -1757,15 +1757,23 @@ set_Wstrict_aliasing (struct gcc_options
 static void
 set_fast_math_flags (struct gcc_options *opts, int set)
 {
-  opts->x_flag_unsafe_math_optimizations = set;
-  set_unsafe_math_optimizations_flags (opts, set);
-  opts->x_flag_finite_math_only = set;
-  opts->x_flag_errno_math = !set;
+  if (!opts->frontend_set_flag_unsafe_math_optimizations)
+    {
+      opts->x_flag_unsafe_math_optimizations = set;
+      set_unsafe_math_optimizations_flags (opts, set);
+    }
+  if (!opts->frontend_set_flag_finite_math_only)
+    opts->x_flag_finite_math_only = set;
+  if (!opts->frontend_set_flag_errno_math)
+    opts->x_flag_errno_math = !set;
   if (set)
     {
-      opts->x_flag_signaling_nans = 0;
-      opts->x_flag_rounding_math = 0;
-      opts->x_flag_cx_limited_range = 1;
+      if (!opts->frontend_set_flag_signaling_nans)
+	opts->x_flag_signaling_nans = 0;
+      if (!opts->frontend_set_flag_rounding_math)
+	opts->x_flag_rounding_math = 0;
+      if (!opts->frontend_set_flag_cx_limited_range)
+	opts->x_flag_cx_limited_range = 1;
     }
 }
 
@@ -1774,10 +1782,14 @@ set_fast_math_flags (struct gcc_options 
 static void
 set_unsafe_math_optimizations_flags (struct gcc_options *opts, int set)
 {
-  opts->x_flag_trapping_math = !set;
-  opts->x_flag_signed_zeros = !set;
-  opts->x_flag_associative_math = set;
-  opts->x_flag_reciprocal_math = set;
+  if (!opts->frontend_set_flag_trapping_math)
+    opts->x_flag_trapping_math = !set;
+  if (!opts->frontend_set_flag_signed_zeros)
+    opts->x_flag_signed_zeros = !set;
+  if (!opts->frontend_set_flag_associative_math)
+    opts->x_flag_associative_math = set;
+  if (!opts->frontend_set_flag_reciprocal_math)
+    opts->x_flag_reciprocal_math = set;
 }
 
 /* Return true iff flags in OPTS are set as if -ffast-math.  */
Index: doc/options.texi
===================================================================
--- doc/options.texi	(revision 169848)
+++ doc/options.texi	(working copy)
@@ -1,4 +1,4 @@
-@c Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+@c Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
 @c Free Software Foundation, Inc.
 @c This is part of the GCC manual.
 @c For copying conditions, see the file gcc.texi.
@@ -436,4 +436,17 @@ the @option{--help} output.
 Build the @code{cl_target_option} structure to hold a copy of the
 option, add the functions @code{cl_target_option_save} and
 @code{cl_target_option_restore} to save and restore the options.
+
+@item SetByCombined
+The option may also be set by a combined option such as
+@option{-ffast-math}.  This causes the @code{gcc_options} struct to
+have a field @code{frontend_set_@var{name}}, where @code{@var{name}}
+is the name of the field holding the value of this option (without the
+leading @code{x_}).  This gives the frontend a way to indicate that
+the value has been set explicitly and should not be changed by the
+combined option.  For example, some frontends use this to prevent
+@option{-ffast-math} and @option{-fno-fast-math} from changing the
+value of @option{-fmath-errno} for languages that do not use
+@code{errno}.
+
 @end table

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]