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: [-fcompare-debug] var tracking options are not optimization options


On Jan  4, 2017, Alexandre Oliva <aoliva@redhat.com> wrote:

> So I guess we need some alternate PerFunction option flag that makes
> it per-function, but not part of the ICF hash?

Like this...

If we include them in the ICF hash, they may cause congruence_groups to
be processed in a different order due to different hashes, which in turn
causes different funcdef_nos to be assigned to functions.  Since these
numbers are included in -fcompare-debug dumps, they cause failures.

Since these options are not optimization options, in that they do not
(or should not, save for bugs like this) affect the executable code
output by the compiler, they should not be marked as such.

This patch replaces the Optimization flag in the var-tracking options
with the newly-introduced PerFunction flag, so that it can still be
controlled on a per-function basis, but that disregards it in the hash
computation used by ICF.

This fixes -fcompare-debug failures in numerous LTO testcases.

Regstrapped on x86_64-linux-gnu and i686-linux-gnu.  Ok to install?

for  gcc/ChangeLog

	* doc/options.texi (PerFunction): New.
	* opt-functions.awk (switch_flags): Map both Optimization and
	PerFunction to CL_OPTIMIZATION.
	* opth-gen.awk: Test for PerFunction flag along with
	Optimization.
	* optc-save-gen.awk: Likewise.  Introduce var_opt_hash and set
	it only when the latter is present.  Skip those that don't in
	the hash function generator.
	* common.opt (fvar-tracking): Mark as PerFunction instead of
	Optimization.
	(fvar-tracking-assignments): Likewise.
	(fvar-tracking-assignments-toggle): Likewise.
	(fvar-tracking-uninit): Likewise.
---
 gcc/common.opt        |    8 ++++----
 gcc/doc/options.texi  |    7 +++++++
 gcc/opt-functions.awk |    2 +-
 gcc/optc-save-gen.awk |    7 +++++--
 gcc/opth-gen.awk      |    2 +-
 5 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 1872d51..44f7557 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2601,7 +2601,7 @@ Common Undocumented Var(flag_use_linker_plugin)
 ; will be set according to optimize, debug_info_level and debug_hooks
 ; in process_options ().
 fvar-tracking
-Common Report Var(flag_var_tracking) Init(2) Optimization
+Common Report Var(flag_var_tracking) Init(2) PerFunction
 Perform variable tracking.
 
 ; Positive if we should track variables at assignments, negative if
@@ -2609,13 +2609,13 @@ Perform variable tracking.
 ; annotations.  When flag_var_tracking_assignments ==
 ; AUTODETECT_VALUE it will be set according to flag_var_tracking.
 fvar-tracking-assignments
-Common Report Var(flag_var_tracking_assignments) Init(2) Optimization
+Common Report Var(flag_var_tracking_assignments) Init(2) PerFunction
 Perform variable tracking by annotating assignments.
 
 ; Nonzero if we should toggle flag_var_tracking_assignments after
 ; processing options and computing its default.  */
 fvar-tracking-assignments-toggle
-Common Report Var(flag_var_tracking_assignments_toggle) Optimization
+Common Report Var(flag_var_tracking_assignments_toggle) PerFunction
 Toggle -fvar-tracking-assignments.
 
 ; Positive if we should track uninitialized variables, negative if
@@ -2623,7 +2623,7 @@ Toggle -fvar-tracking-assignments.
 ; annotations.  When flag_var_tracking_uninit == AUTODETECT_VALUE it
 ; will be set according to flag_var_tracking.
 fvar-tracking-uninit
-Common Report Var(flag_var_tracking_uninit) Optimization
+Common Report Var(flag_var_tracking_uninit) PerFunction
 Perform variable tracking and also tag variables that are uninitialized.
 
 ftree-vectorize
diff --git a/gcc/doc/options.texi b/gcc/doc/options.texi
index 87cf688..14c149e 100644
--- a/gcc/doc/options.texi
+++ b/gcc/doc/options.texi
@@ -430,6 +430,13 @@ This is an optimization option.  It should be shown as such in
 @code{Var} should be saved and restored when the optimization level is
 changed with @code{optimize} attributes.
 
+@item PerFunction
+This is an option that can be overridden on a per-function basis.
+@code{Optimization} implies @code{PerFunction}, but options that do not
+affect executable code generation may use this flag instead, so that the
+option is not taken into account in ways that might affect executable
+code generation.
+
 @item Undocumented
 The option is deliberately missing documentation and should not
 be included in the @option{--help} output.
diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk
index 7cf5025..a4aeeda 100644
--- a/gcc/opt-functions.awk
+++ b/gcc/opt-functions.awk
@@ -105,7 +105,7 @@ function switch_flags (flags)
 	  test_flag("Undocumented", flags,  " | CL_UNDOCUMENTED") \
 	  test_flag("NoDWARFRecord", flags,  " | CL_NO_DWARF_RECORD") \
 	  test_flag("Warning", flags,  " | CL_WARNING") \
-	  test_flag("Optimization", flags,  " | CL_OPTIMIZATION")
+	  test_flag("(Optimization|PerFunction)", flags,  " | CL_OPTIMIZATION")
 	sub( "^0 \\| ", "", result )
 	return result
 }
diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk
index 8ce4248..0928d5d 100644
--- a/gcc/optc-save-gen.awk
+++ b/gcc/optc-save-gen.awk
@@ -100,7 +100,7 @@ var_opt_range["optimize_debug"] = "0, 1";
 # cache.
 
 for (i = 0; i < n_opts; i++) {
-	if (flag_set_p("Optimization", flags[i])) {
+	if (flag_set_p("(Optimization|PerFunction)", flags[i])) {
 		name = var_name(flags[i])
 		if(name == "")
 			continue;
@@ -743,7 +743,7 @@ var_opt_val[2] = "x_optimize_debug"
 var_opt_val_type[1] = "char "
 var_opt_val_type[2] = "char "
 for (i = 0; i < n_opts; i++) {
-	if (flag_set_p("Optimization", flags[i])) {
+	if (flag_set_p("(Optimization|PerFunction)", flags[i])) {
 		name = var_name(flags[i])
 		if(name == "")
 			continue;
@@ -756,6 +756,7 @@ for (i = 0; i < n_opts; i++) {
 		otype = var_type_struct(flags[i])
 		var_opt_val_type[n_opt_val] = otype;
 		var_opt_val[n_opt_val++] = "x_" name;
+		var_opt_hash[n_opt_val] = flag_set_p("Optimization", flags[i]);
 	}
 }
 print "";
@@ -765,6 +766,8 @@ print "cl_optimization_hash (struct cl_optimization const *ptr ATTRIBUTE_UNUSED)
 print "{";
 print "  inchash::hash hstate;";
 for (i = 0; i < n_opt_val; i++) {
+	if (!var_opt_hash[i])
+		continue;
 	name = var_opt_val[i]
 	print "  hstate.add_wide_int (ptr->" name");";
 }
diff --git a/gcc/opth-gen.awk b/gcc/opth-gen.awk
index c728a42..69a7003 100644
--- a/gcc/opth-gen.awk
+++ b/gcc/opth-gen.awk
@@ -142,7 +142,7 @@ var_opt_char[1] = "unsigned char x_optimize_size";
 var_opt_char[2] = "unsigned char x_optimize_debug";
 
 for (i = 0; i < n_opts; i++) {
-	if (flag_set_p("Optimization", flags[i])) {
+	if (flag_set_p("(Optimization|PerFunction)", flags[i])) {
 		name = var_name(flags[i])
 		if(name == "")
 			continue;


-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer


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