]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
lto-wrapper.c (run_gcc): With -save-temps generate a user-visible ltrans filename.
authorRichard Guenther <rguenther@suse.de>
Fri, 28 May 2010 12:48:54 +0000 (12:48 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 28 May 2010 12:48:54 +0000 (12:48 +0000)
2010-05-28  Richard Guenther  <rguenther@suse.de>

* lto-wrapper.c (run_gcc): With -save-temps generate a
user-visible ltrans filename.  Fixup ltrans unit numbering.

lto/
* lto.c (prefix_name_with_star): Removed.
(strip_extension): Likewise.
(get_filename_for_set): Likewise.
(lto_write_ltrans_list): Fold into ...
(lto_wpa_write_files): ... this.  Name LTRANS units
by suffixing the ltrans output list filename.
(do_whole_program_analysis): Adjust.

From-SVN: r159967

gcc/ChangeLog
gcc/lto-wrapper.c
gcc/lto/ChangeLog
gcc/lto/lto.c

index 92dc7f7b099ea308fb1f66dc08fbaf4bf7c10c91..8925b5a666934d2a7b9b7c1aee5378b79542866d 100644 (file)
@@ -1,3 +1,8 @@
+2010-05-28  Richard Guenther  <rguenther@suse.de>
+
+       * lto-wrapper.c (run_gcc): With -save-temps generate a
+       user-visible ltrans filename.  Fixup ltrans unit numbering.
+
 2010-05-28  Kai Tietz  <kai.tietz@onevision.com>
 
        * c-common.c (c_common_nodes_and_builtins): Replace use
index 7454b54af79b61a6187db0eda1b5c5b45a010fd0..dda272bd1d9faaf24986a604bdb5fb080567b92b 100644 (file)
@@ -407,13 +407,21 @@ run_gcc (unsigned argc, char *argv[])
       if (linker_output)
        {
          char *dumpbase = (char *) xmalloc (strlen (linker_output)
-                                            + sizeof(".wpa") + 1);
+                                            + sizeof (".wpa") + 1);
          strcpy (dumpbase, linker_output);
          strcat (dumpbase, ".wpa");
          argv_ptr[0] = dumpbase;
        }
 
-      ltrans_output_file = make_temp_file (".ltrans.out");
+      if (linker_output && debug)
+       {
+         ltrans_output_file = (char *) xmalloc (strlen (linker_output)
+                                                + sizeof (".ltrans.out") + 1);
+         strcpy (ltrans_output_file, linker_output);
+         strcat (ltrans_output_file, ".ltrans.out");
+       }
+      else
+       ltrans_output_file = make_temp_file (".ltrans.out");
       list_option_full = (char *) xmalloc (sizeof (char) *
                         (strlen (ltrans_output_file) + list_option_len + 1));
       tmp = list_option_full;
@@ -516,7 +524,7 @@ cont:
                                      + sizeof(DUMPBASE_SUFFIX) + 1);
              snprintf (dumpbase,
                        strlen (linker_output) + sizeof(DUMPBASE_SUFFIX),
-                       "%s.ltrans%u", linker_output, nr);
+                       "%s.ltrans%u", linker_output, i);
              argv_ptr[0] = dumpbase;
            }
 
index b11097f9c822bfb5658a9c4589e7fb42a6f3880a..fb71dc30c73d2ec799bc1799469f31651a18108b 100644 (file)
@@ -1,3 +1,13 @@
+2010-05-28  Richard Guenther  <rguenther@suse.de>
+
+       * lto.c (prefix_name_with_star): Removed.
+       (strip_extension): Likewise.
+       (get_filename_for_set): Likewise.
+       (lto_write_ltrans_list): Fold into ...
+       (lto_wpa_write_files): ... this.  Name LTRANS units
+       by suffixing the ltrans output list filename.
+       (do_whole_program_analysis): Adjust.
+
 2010-05-27  Joseph Myers  <joseph@codesourcery.com>
 
        * lto.c: Include diagnostic-core.h instead of diagnostic.h.
index d69fba3f00082daf5836331a3ba1e4dc5020efdb..37d57bbc58ff18d61065249b1cec4850a4ea76ff 100644 (file)
@@ -848,123 +848,29 @@ lto_promote_cross_file_statics (void)
 }
 
 
-/* Given a file name FNAME, return a string with FNAME prefixed with '*'.  */
-
-static char *
-prefix_name_with_star (const char *fname)
-{
-  char *star_fname;
-  size_t len;
-  
-  len = strlen (fname) + 1 + 1;
-  star_fname = XNEWVEC (char, len);
-  snprintf (star_fname, len, "*%s", fname);
-
-  return star_fname;
-}
-
-
-/* Return a copy of FNAME without the .o extension.  */
-
-static char *
-strip_extension (const char *fname)
-{
-  char *s = XNEWVEC (char, strlen (fname) - 2 + 1);
-  gcc_assert (strstr (fname, ".o"));
-  snprintf (s, strlen (fname) - 2 + 1, "%s", fname);
-
-  return s;
-}
-
-
-/* Return a file name associated with cgraph node set SET.  This may
-   be a new temporary file name if SET needs to be processed by
-   LTRANS, or the original file name if all the nodes in SET belong to
-   the same input file.  */
-
-static char *
-get_filename_for_set (cgraph_node_set set)
-{
-  char *fname = NULL;
-  static const size_t max_fname_len = 100;
-
-  /* Create a new temporary file to store SET.  To facilitate
-     debugging, use file names from SET as part of the new
-     temporary file name.  */
-  cgraph_node_set_iterator si;
-  struct pointer_set_t *pset = pointer_set_create ();
-  for (si = csi_start (set); !csi_end_p (si); csi_next (&si))
-    {
-      struct cgraph_node *n = csi_node (si);
-      const char *node_fname;
-      char *f;
-
-      /* Don't use the same file name more than once.  */
-      if (pointer_set_insert (pset, n->local.lto_file_data))
-       continue;
-
-      /* The first file name found in SET determines the output
-        directory.  For the remaining files, we use their
-        base names.  */
-      node_fname = n->local.lto_file_data->file_name;
-      if (fname == NULL)
-       {
-         fname = strip_extension (node_fname);
-         continue;
-       }
-
-      f = strip_extension (lbasename (node_fname));
-
-      /* If the new name causes an excessively long file name,
-        make the last component "___" to indicate overflow.  */
-      if (strlen (fname) + strlen (f) > max_fname_len - 3)
-       {
-         fname = reconcat (fname, fname, "___", NULL);
-         break;
-       }
-      else
-       {
-         fname = reconcat (fname, fname, "_", f, NULL);
-         free (f);
-       }
-    }
-
-  pointer_set_destroy (pset);
-
-  if (!fname)
-    {
-      /* Since SET does not need to be processed by LTRANS, use
-        the original file name and mark it with a '*' prefix so that
-        lto_execute_ltrans knows not to process it.  */
-      cgraph_node_set_iterator si = csi_start (set);
-      struct cgraph_node *first = csi_node (si);
-      fname = prefix_name_with_star (first->local.lto_file_data->file_name);
-    }
-  else
-    {
-      /* Add the extension .wpa.o to indicate that this file has been
-        produced by WPA.  */
-      fname = reconcat (fname, fname, ".wpa.o", NULL);
-      gcc_assert (fname);
-    }
-
-  return fname;
-}
-
 static lto_file *current_lto_file;
 
 
-/* Write all output files in WPA mode.  Returns a NULL-terminated array of
-   output file names.  */
+/* Write all output files in WPA mode and the file with the list of
+   LTRANS units.  */
 
-static char **
+static void
 lto_wpa_write_files (void)
 {
-  char **output_files;
-  unsigned i, n_sets, last_out_file_ix, num_out_files;
+  unsigned i, n_sets;
   lto_file *file;
   cgraph_node_set set;
   varpool_node_set vset;
+  FILE *ltrans_output_list_stream;
+  char *temp_filename;
+  size_t blen;
+
+  /* Open the LTRANS output list.  */
+  if (!ltrans_output_list)
+    fatal_error ("no LTRANS output list filename provided");
+  ltrans_output_list_stream = fopen (ltrans_output_list, "w");
+  if (ltrans_output_list_stream == NULL)
+    fatal_error ("opening LTRANS output list %s: %m", ltrans_output_list);
 
   timevar_push (TV_WHOPR_WPA);
 
@@ -987,86 +893,57 @@ lto_wpa_write_files (void)
 
   timevar_push (TV_WHOPR_WPA_IO);
 
-  /* The number of output files depends on the number of input files
-     and how many callgraph node sets we create.  Reserve enough space
-     for the maximum of these two.  */
-  num_out_files = MAX (VEC_length (cgraph_node_set, lto_cgraph_node_sets),
-                       num_in_fnames);
-  output_files = XNEWVEC (char *, num_out_files + 1);
+  /* Generate a prefix for the LTRANS unit files.  */
+  blen = strlen (ltrans_output_list);
+  temp_filename = (char *) xmalloc (blen + sizeof ("2147483648.o"));
+  strcpy (temp_filename, ltrans_output_list);
+  if (blen > sizeof (".out")
+      && strcmp (temp_filename + blen - sizeof (".out") + 1,
+                ".out") == 0)
+    temp_filename[blen - sizeof (".out") + 1] = '\0';
+  blen = strlen (temp_filename);
 
   n_sets = VEC_length (cgraph_node_set, lto_cgraph_node_sets);
   for (i = 0; i < n_sets; i++)
     {
-      char *temp_filename;
+      size_t len;
 
       set = VEC_index (cgraph_node_set, lto_cgraph_node_sets, i);
       vset = VEC_index (varpool_node_set, lto_varpool_node_sets, i);
-      temp_filename = get_filename_for_set (set);
-      output_files[i] = temp_filename;
-
-      if (cgraph_node_set_nonempty_p (set) || varpool_node_set_nonempty_p (vset))
-       {
-         /* Write all the nodes in SET to TEMP_FILENAME.  */
-         file = lto_obj_file_open (temp_filename, true);
-         if (!file)
-           fatal_error ("lto_obj_file_open() failed");
-
-         if (!quiet_flag)
-           fprintf (stderr, " %s", temp_filename);
-
-         lto_set_current_out_file (file);
-
-         ipa_write_optimization_summaries (set, vset);
-
-         lto_set_current_out_file (NULL);
-         lto_obj_file_close (file);
-       }
-    }
-
-  last_out_file_ix = n_sets;
-
-  lto_stats.num_output_files += n_sets;
-
-  output_files[last_out_file_ix] = NULL;
-
-  timevar_pop (TV_WHOPR_WPA_IO);
-
-  return output_files;
-}
+      if (!cgraph_node_set_nonempty_p (set)
+         && !varpool_node_set_nonempty_p (vset))
+       continue;
 
-/* Perform local transformations (LTRANS) on the files in the NULL-terminated
-   FILES array.  These should have been written previously by
-   lto_wpa_write_files ().  Transformations are performed via executing
-   COLLECT_GCC for reach file.  */
+      /* Write all the nodes in SET.  */
+      sprintf (temp_filename + blen, "%u.o", i);
+      file = lto_obj_file_open (temp_filename, true);
+      if (!file)
+       fatal_error ("lto_obj_file_open() failed");
 
-static void
-lto_write_ltrans_list (char *const *files)
-{
-  FILE *ltrans_output_list_stream = NULL;
-  unsigned i;
+      if (!quiet_flag)
+       fprintf (stderr, " %s", temp_filename);
 
-  /* Open the LTRANS output list.  */
-  if (!ltrans_output_list)
-    error ("no LTRANS output filename provided");
+      lto_set_current_out_file (file);
 
-  ltrans_output_list_stream = fopen (ltrans_output_list, "w");
-  if (ltrans_output_list_stream == NULL)
-    error ("opening LTRANS output list %s: %m", ltrans_output_list);
+      ipa_write_optimization_summaries (set, vset);
 
-  for (i = 0; files[i]; ++i)
-    {
-      size_t len;
+      lto_set_current_out_file (NULL);
+      lto_obj_file_close (file);
 
-      len = strlen (files[i]);
-      if (fwrite (files[i], 1, len, ltrans_output_list_stream) < len
+      len = strlen (temp_filename);
+      if (fwrite (temp_filename, 1, len, ltrans_output_list_stream) < len
          || fwrite ("\n", 1, 1, ltrans_output_list_stream) < 1)
-       error ("writing to LTRANS output list %s: %m",
-              ltrans_output_list);
+       fatal_error ("writing to LTRANS output list %s: %m",
+                    ltrans_output_list);
     }
 
+  lto_stats.num_output_files += n_sets;
+
   /* Close the LTRANS output list.  */
   if (fclose (ltrans_output_list_stream))
-    error ("closing LTRANS output list %s: %m", ltrans_output_list);
+    fatal_error ("closing LTRANS output list %s: %m", ltrans_output_list);
+
+  timevar_pop (TV_WHOPR_WPA_IO);
 }
 
 
@@ -1793,8 +1670,6 @@ materialize_cgraph (void)
 static void
 do_whole_program_analysis (void)
 {
-  char **output_files;
-
   /* Note that since we are in WPA mode, materialize_cgraph will not
      actually read in all the function bodies.  It only materializes
      the decls and cgraph nodes so that analysis can be performed.  */
@@ -1829,7 +1704,7 @@ do_whole_program_analysis (void)
       fprintf (stderr, "\nStreaming out");
       fflush (stderr);
     }
-  output_files = lto_wpa_write_files ();
+  lto_wpa_write_files ();
   ggc_collect ();
   if (!quiet_flag)
     fprintf (stderr, "\n");
@@ -1843,10 +1718,6 @@ do_whole_program_analysis (void)
   /* Show the LTO report before launching LTRANS.  */
   if (flag_lto_report)
     print_lto_report ();
-
-  lto_write_ltrans_list (output_files);
-
-  XDELETEVEC (output_files);
 }