[vta,vta4.3,trunk?] introduce -fcompare-debug

Richard Henderson rth@redhat.com
Wed Jun 3 18:06:00 GMT 2009


> With this option, the compiler will compile the same program twice,
> dumping the final RTL and comparing the dumps.  This will enable us to
> verify that -g and/or -fvar-tracking-assignments have no codegen
> effects on our entire testsuite, and any other codebase you might want
> to compile with -fcompare-debug.

Letting other folks argue over what to call the option, I think the
basic idea is definitely sound.

> +	      INSN_UID (insn) = 0;
> +
> +	}

Watch the spurious newlines.  There are quite a few.

> +int compare_debug;
> +int compare_debug_second;

There's very little commentary added anywhere in gcc.c.
What do the different values {-1,0,1,2,3} mean for compare_debug?

> +      const char *gcd = getenv ("GCC_COMPARE_DEBUG");

I'm not thrilled with the use of environment variables here, but
the description of its use with -fcompare-debug-not-overridden makes
some sense.

> @@ -6774,10 +6948,109 @@ main (int argc, char **argv)
>  	    }
>  	  else
>  	    {
> +	      if (compare_debug)
> +		{
> +		  if (debug_check_temp_file[0])
> +		    free (debug_check_temp_file[0]);
> +		  debug_check_temp_file[0] = NULL;
> +
> +		  if (debug_check_temp_file[1])
> +		    free (debug_check_temp_file[1]);
> +		  debug_check_temp_file[1] = NULL;
> +		}
> +
>  	      value = do_spec (input_file_compiler->spec);
>  	      infiles[i].compiled = true;
>  	      if (value < 0)
> -		this_file_error = 1;
> +		{
> +		  this_file_error = 1;
> +		}
> +	      else if (compare_debug && debug_check_temp_file[0])
> +		{
> +		  FILE *temp[2];
> +
> +		  if (verbose_flag)
> +		    error ("Recompiling with -fcompare-debug");
> +
> +		  compare_debug = -compare_debug;
> +		  n_switches = n_switches_debug_check[1];
> +		  switches = switches_debug_check[1];
> +
> +		  debug_check_temp_file[1] = NULL;
> +		  value = do_spec (input_file_compiler->spec);
> +
> +		  compare_debug = -compare_debug;
> +		  n_switches = n_switches_debug_check[0];
> +		  switches = switches_debug_check[0];
> +
> +		  if (value < 0)
> +		    {
> +		      error ("during -fcompare-debug recompilation");
> +		      this_file_error = 1;
> +		    }
> +
> +		  gcc_assert (debug_check_temp_file[1]
> +			      && strcmp (debug_check_temp_file[0],
> +					 debug_check_temp_file[1]));
> +
> +		  temp[0] = fopen (debug_check_temp_file[0], "r");
> +		  if (!temp[0])
> +		    {
> +		      error ("%s: could not open compare-debug file %s",
> +			     input_filename, debug_check_temp_file[0]);
> +		      this_file_error = 1;
> +		    }
> +		  temp[1] = fopen (debug_check_temp_file[1], "r");
> +		  if (!temp[1])
> +		    {
> +		      error ("%s: could not open compare-debug file %s",
> +			     input_filename, debug_check_temp_file[1]);
> +		      this_file_error = 1;
> +		    }
> +
> +		  free (debug_check_temp_file[1]);
> +		  debug_check_temp_file[1] = NULL;
> +		  free (debug_check_temp_file[0]);
> +		  debug_check_temp_file[0] = NULL;
> +
> +		  if (verbose_flag)
> +		    error ("Comparing final insns dumps");
> +
> +		  if (!this_file_error && temp[0] && temp[1])
> +		    for (;;)
> +		      {
> +			int c0, c1;
> +			c0 = fgetc (temp[0]);
> +			c1 = fgetc (temp[1]);
> +
> +			if (c0 != c1)
> +			  {
> +			    error ("%s: -fcompare-debug failure",
> +				   input_filename);
> +			    this_file_error = 1;
> +			    break;
> +			  }
> +
> +			if (c0 == EOF)
> +			  break;
> +		      }
> +
> +		  if (temp[1])
> +		    fclose (temp[1]);
> +		  if (temp[0])
> +		    fclose (temp[0]);
> +		}
> +
> +	      if (compare_debug)
> +		{
> +		  if (debug_check_temp_file[0])
> +		    free (debug_check_temp_file[0]);
> +		  debug_check_temp_file[0] = NULL;
> +
> +		  if (debug_check_temp_file[1])
> +		    free (debug_check_temp_file[1]);
> +		  debug_check_temp_file[1] = NULL;
> +		}

Surely some subroutines are warrented here.

With the file comparison, surely we can speed this up a bit
by examining file sizes first, mmaping the files and using
memcmp, or even by execing cmp.

Is there a way to have the compiler dump the final_insns file
without actually doing the comparison within the driver?  I'm
thinking of the usage case where we compile stage2 without
debug info, and stage3 with debug info, and compare the two
stages via their dump files without implicitly running the
compilation step a third time and adding that much more time
to the build process.


r~



More information about the Gcc-patches mailing list