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]

[profile patch] Make profile files directory proof


Hi,
I've installed this patch which makes the names of the
gcov data files (bb, bbg & da) preserve directory components
in a specified output file name% (and match the documentation).

Because there was some negative feedback on making -dumpbase
have this behaviour, Mark & I decided to implement this
functionality separately.

built & tested on i686-pc-linux-gnu.

nathan

% this is similar to the -M et al preprocess option changes.

-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2002-08-04  Nathan Sidwell  <nathan@codesourcery.com>

	* gcc.c (cc1_options): Pass output file as auxbase when
	appropriate.
	* profile.c (init_branch_prob): FILENAME has already had ending
	stripped.
	* final.c (end_final): Likewise.
	* toplev.c (aux_base_name): New global.
	(compile_file): Pass aux_base_name to init init_branch_prob and
	end_final.
	(independent_decode_option, case 'a'): New auxinfo options.
	(case 'd'): Protect against mising basename.
	(do_compile): Initialize aux_base_name.
	* toplev.h (aux_base_name): New global.
	* doc/invoke.texi: Adjust documentation.

Index: final.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/final.c,v
retrieving revision 1.264
diff -c -3 -p -r1.264 final.c
*** final.c	1 Aug 2002 18:37:38 -0000	1.264
--- final.c	4 Aug 2002 16:12:29 -0000
*************** end_final (filename)
*** 311,317 ****
  	strcpy (da_filename, cwd);
  	strcat (da_filename, "/");
  	strcat (da_filename, filename);
- 	strip_off_ending (da_filename, da_filename_len - 3);
  	strcat (da_filename, ".da");
  	da_filename_len = strlen (da_filename);
  	string_cst = build_string (da_filename_len + 1, da_filename);
--- 311,316 ----
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.333
diff -c -3 -p -r1.333 gcc.c
*** gcc.c	1 Aug 2002 06:24:59 -0000	1.333
--- gcc.c	4 Aug 2002 16:12:43 -0000
*************** static const char *cpp_debug_options = "
*** 697,702 ****
--- 697,703 ----
  static const char *cc1_options =
  "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
   %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
+  -auxbase%{c|S:%{o*:-strip%*}%{!o*: %b}}%{!c:%{!S: %b}}\
   %{g*} %{O*} %{W*&pedantic*} %{w} %{std*} %{ansi}\
   %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
   %{Qn:-fno-ident} %{--help:--help}\
Index: profile.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/profile.c,v
retrieving revision 1.95
diff -c -3 -p -r1.95 profile.c
*** profile.c	29 Jul 2002 18:40:45 -0000	1.95
--- profile.c	4 Aug 2002 16:12:45 -0000
*************** init_branch_prob (filename)
*** 1196,1202 ****
        /* Open an output file for the basic block/line number map.  */
        data_file = (char *) alloca (len + 4);
        strcpy (data_file, filename);
-       strip_off_ending (data_file, len);
        strcat (data_file, ".bb");
        if ((bb_file = fopen (data_file, "wb")) == 0)
  	fatal_io_error ("can't open %s", data_file);
--- 1196,1201 ----
*************** init_branch_prob (filename)
*** 1204,1210 ****
        /* Open an output file for the program flow graph.  */
        bbg_file_name = (char *) alloca (len + 5);
        strcpy (bbg_file_name, filename);
-       strip_off_ending (bbg_file_name, len);
        strcat (bbg_file_name, ".bbg");
        if ((bbg_file = fopen (bbg_file_name, "wb")) == 0)
  	fatal_io_error ("can't open %s", bbg_file_name);
--- 1203,1208 ----
*************** init_branch_prob (filename)
*** 1221,1227 ****
        len = strlen (filename);
        da_file_name = (char *) alloca (len + 4);
        strcpy (da_file_name, filename);
-       strip_off_ending (da_file_name, len);
        strcat (da_file_name, ".da");
        if ((da_file = fopen (da_file_name, "rb")) == 0)
  	warning ("file %s not found, execution counts assumed to be zero",
--- 1219,1224 ----
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.665
diff -c -3 -p -r1.665 toplev.c
*** toplev.c	1 Aug 2002 23:53:57 -0000	1.665
--- toplev.c	4 Aug 2002 16:12:57 -0000
*************** int input_file_stack_tick;
*** 168,173 ****
--- 168,177 ----
  
  const char *dump_base_name;
  
+ /* Name to use as a base for auxiliary output files.  */
+ 
+ const char *aux_base_name;
+ 
  /* Format to use to print dumpfile index value */
  #ifndef DUMPFILE_FORMAT
  #define DUMPFILE_FORMAT ".%02d."
*************** compile_file ()
*** 2117,2123 ****
    /* Initialize yet another pass.  */
  
    init_final (main_input_filename);
!   init_branch_prob (dump_base_name);
  
    timevar_push (TV_PARSE);
  
--- 2121,2127 ----
    /* Initialize yet another pass.  */
  
    init_final (main_input_filename);
!   init_branch_prob (aux_base_name);
  
    timevar_push (TV_PARSE);
  
*************** compile_file ()
*** 2190,2196 ****
  
    dw2_output_indirect_constants ();
  
!   end_final (dump_base_name);
  
    if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
      {
--- 2194,2200 ----
  
    dw2_output_indirect_constants ();
  
!   end_final (aux_base_name);
  
    if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
      {
*************** independent_decode_option (argc, argv)
*** 4297,4303 ****
  	  if (argc == 1)
  	    return 0;
  
! 	  dump_base_name = argv[1];
  	  return 2;
  	}
        else
--- 4301,4309 ----
  	  if (argc == 1)
  	    return 0;
  
! 	  if (argv[1][0])
! 	    dump_base_name = argv[1];
! 	  
  	  return 2;
  	}
        else
*************** independent_decode_option (argc, argv)
*** 4370,4375 ****
--- 4376,4405 ----
  	  else
  	    return 0;
  	}
+       else if (!strcmp (arg, "auxbase"))
+ 	{
+ 	  if (argc == 1)
+ 	    return 0;
+ 
+ 	  if (argv[1][0])
+ 	    aux_base_name = argv[1];
+ 	  
+ 	  return 2;
+ 	}
+       else if (!strcmp (arg, "auxbase-strip"))
+ 	{
+ 	  if (argc == 1)
+ 	    return 0;
+ 
+ 	  if (argv[1][0])
+ 	    {
+ 	      strip_off_ending (argv[1], strlen (argv[1]));
+ 	      if (argv[1][0])
+ 		aux_base_name = argv[1];
+ 	    }
+ 	  
+ 	  return 2;
+ 	}
        else
  	return 0;
        break;
*************** lang_dependent_init (name)
*** 5170,5176 ****
  {
    if (dump_base_name == 0)
      dump_base_name = name ? name : "gccdump";
! 
    /* Front-end initialization.  This hook can assume that GC,
       identifier hashes etc. are set up, but debug initialization is
       not done yet.  This routine must return the original filename
--- 5200,5206 ----
  {
    if (dump_base_name == 0)
      dump_base_name = name ? name : "gccdump";
!   
    /* Front-end initialization.  This hook can assume that GC,
       identifier hashes etc. are set up, but debug initialization is
       not done yet.  This routine must return the original filename
*************** do_compile (no_backend)
*** 5280,5285 ****
--- 5310,5328 ----
  {
    /* The bulk of command line switch processing.  */
    process_options ();
+ 
+   if (aux_base_name)
+     /*NOP*/;
+   else if (filename)
+     {
+       char *name = xstrdup (lbasename (filename));
+       
+       aux_base_name = name;
+       strip_off_ending (name, strlen (name));
+     }
+   
+   else
+     aux_base_name = "gccaux";
  
    /* We cannot start timing until after options are processed since that
       says if we run timers or not.  */
Index: toplev.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.h,v
retrieving revision 1.88
diff -c -3 -p -r1.88 toplev.h
*** toplev.h	25 Jul 2002 10:15:56 -0000	1.88
--- toplev.h	4 Aug 2002 16:12:57 -0000
*************** extern void check_global_declarations   
*** 108,113 ****
--- 108,115 ----
  
  extern const char *progname;
  extern const char *dump_base_name;
+ extern const char *aux_base_name;
+ 
  extern int target_flags_explicit;
  
  /* The hashtable, so that the C front ends can pass it to cpplib.  */
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.165
diff -c -3 -p -r1.165 invoke.texi
*** doc/invoke.texi	2 Aug 2002 01:16:09 -0000	1.165
--- doc/invoke.texi	4 Aug 2002 16:13:30 -0000
*************** allocation when it finishes.
*** 2818,2828 ****
  
  @item -fprofile-arcs
  @opindex fprofile-arcs
! Instrument @dfn{arcs} during compilation to generate coverage data
! or for profile-directed block ordering.  During execution the program
  records how many times each branch is executed and how many times it is
  taken.  When the compiled program exits it saves this data to a file
! called @file{@var{sourcename}.da} for each source file.
  
  For profile-directed block ordering, compile the program with
  @option{-fprofile-arcs} plus optimization and code generation options,
--- 2818,2833 ----
  
  @item -fprofile-arcs
  @opindex fprofile-arcs
! Instrument @dfn{arcs} during compilation to generate coverage data or
! for profile-directed block ordering.  During execution the program
  records how many times each branch is executed and how many times it is
  taken.  When the compiled program exits it saves this data to a file
! called @file{@var{auxname}.da} for each source file.  @var{auxname} is
! generated from the name of the output file, if explicitly specified and
! it is not the final executable, otherwise it is the basename of the
! source file. In both cases any suffix is removed (e.g.  @file{foo.da}
! for input file @file{dir/foo.c}, or @file{dir/foo.da} for output file
! specified as @option{-o dir/foo.o}).
  
  For profile-directed block ordering, compile the program with
  @option{-fprofile-arcs} plus optimization and code generation options,
*************** information to estimate all branch proba
*** 2863,2881 ****
  @item -ftest-coverage
  @opindex ftest-coverage
  Create data files for the @code{gcov} code-coverage utility
! (@pxref{Gcov,, @code{gcov}: a GCC Test Coverage Program}).
! The data file names begin with the name of your source file:
  
  @table @gcctabopt
! @item @var{sourcename}.bb
  A mapping from basic blocks to line numbers, which @code{gcov} uses to
  associate basic block execution counts with line numbers.
  
! @item @var{sourcename}.bbg
  A list of all arcs in the program flow graph.  This allows @code{gcov}
  to reconstruct the program flow graph, so that it can compute all basic
  block and arc execution counts from the information in the
! @code{@var{sourcename}.da} file.
  @end table
  
  Use @option{-ftest-coverage} with @option{-fprofile-arcs}; the latter
--- 2868,2886 ----
  @item -ftest-coverage
  @opindex ftest-coverage
  Create data files for the @code{gcov} code-coverage utility
! (@pxref{Gcov,, @code{gcov}: a GCC Test Coverage Program}).  See
! @option{-fprofile-arcs} option above for a description of @var{auxname}.
  
  @table @gcctabopt
! @item @var{auxname}.bb
  A mapping from basic blocks to line numbers, which @code{gcov} uses to
  associate basic block execution counts with line numbers.
  
! @item @var{auxname}.bbg
  A list of all arcs in the program flow graph.  This allows @code{gcov}
  to reconstruct the program flow graph, so that it can compute all basic
  block and arc execution counts from the information in the
! @file{@var{auxname}.da} file.
  @end table
  
  Use @option{-ftest-coverage} with @option{-fprofile-arcs}; the latter
*************** option adds instrumentation to the progr
*** 2883,2891 ****
  execution counts to another data file:
  
  @table @gcctabopt
! @item @var{sourcename}.da
  Runtime arc execution counts, used in conjunction with the arc
! information in the file @code{@var{sourcename}.bbg}.
  @end table
  
  Coverage data will map better to the source files if
--- 2888,2896 ----
  execution counts to another data file:
  
  @table @gcctabopt
! @item @var{auxname}.da
  Runtime arc execution counts, used in conjunction with the arc
! information in the file @file{@var{auxname}.bbg}.
  @end table
  
  Coverage data will map better to the source files if
*************** Coverage data will map better to the sou
*** 2896,2903 ****
  Says to make debugging dumps during compilation at times specified by
  @var{letters}.  This is used for debugging the compiler.  The file names
  for most of the dumps are made by appending a pass number and a word to
! the source file name (e.g.  @file{foo.c.00.rtl} or @file{foo.c.01.sibling}).
! Here are the possible letters for use in @var{letters}, and their meanings:
  
  @table @samp
  @item A
--- 2901,2912 ----
  Says to make debugging dumps during compilation at times specified by
  @var{letters}.  This is used for debugging the compiler.  The file names
  for most of the dumps are made by appending a pass number and a word to
! the @var{dumpname}. @var{dumpname} is generated from the name of the
! output file, if explicitly specified and it is not an executable,
! otherwise it is the basename of the source file. In both cases any
! suffix is removed (e.g.  @file{foo.00.rtl} or @file{foo.01.sibling}).
! Here are the possible letters for use in @var{letters}, and their
! meanings:
  
  @table @samp
  @item A

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