OSDN Git Service

Pass -dumpbase and -dumpdir to gcc for LTO
authorhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 3 Jan 2010 17:03:38 +0000 (17:03 +0000)
committerhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 3 Jan 2010 17:03:38 +0000 (17:03 +0000)
gcc/

2010-01-03  H.J. Lu  <hongjiu.lu@intel.com>

PR lto/41564
* common.opt: Add dumpdir.

* gcc.c (cc1_options): Add "-dumpbase %B" only if -dumpbase
isn't specified.
(option_map): Add --dumpdir.

* gcc.h (DEFAULT_WORD_SWITCH_TAKES_ARG): Add dumpdir.

* lto-wrapper.c (run_gcc): Add -dumpbase and -dumpdir for -o.

* opts.c (decode_options): Try dump_dir_name first if
dump_base_name isn't an absolute path.
(common_handle_option): Handle OPT_dumpdir.

* toplev.c (dump_dir_name): New.
(print_switch_values): Also ignore -dumpdir.

* toplev.h (dump_dir_name): New.

gcc/lto/

2010-01-03  H.J. Lu  <hongjiu.lu@intel.com>

PR lto/41564
* lto.c (DUMPBASE_SUFFIX): New.
(lto_execute_ltrans): Append a sequence number to -dumpbase
for LTRANS.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@155591 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/common.opt
gcc/gcc.c
gcc/gcc.h
gcc/lto-wrapper.c
gcc/lto/ChangeLog
gcc/lto/lto.c
gcc/opts.c
gcc/toplev.c
gcc/toplev.h

index cb0ecfa..414dc2c 100644 (file)
@@ -1,3 +1,25 @@
+2010-01-03  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR lto/41564
+       * common.opt: Add dumpdir.
+
+       * gcc.c (cc1_options): Add "-dumpbase %B" only if -dumpbase
+       isn't specified.
+       (option_map): Add --dumpdir.
+
+       * gcc.h (DEFAULT_WORD_SWITCH_TAKES_ARG): Add dumpdir.
+
+       * lto-wrapper.c (run_gcc): Add -dumpbase and -dumpdir for -o.
+
+       * opts.c (decode_options): Try dump_dir_name first if
+       dump_base_name isn't an absolute path.
+       (common_handle_option): Handle OPT_dumpdir.
+
+       * toplev.c (dump_dir_name): New.
+       (print_switch_values): Also ignore -dumpdir.
+
+       * toplev.h (dump_dir_name): New.
+
 2010-01-03  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/42589
 2010-01-03  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/42589
index 77967f8..ac942ee 100644 (file)
@@ -1,6 +1,6 @@
 ; Options for the language- and target-independent parts of the compiler.
 
 ; Options for the language- and target-independent parts of the compiler.
 
-; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
 ; Free Software Foundation, Inc.
 ;
 ; This file is part of GCC.
 ; Free Software Foundation, Inc.
 ;
 ; This file is part of GCC.
@@ -253,6 +253,10 @@ dumpbase
 Common Separate
 -dumpbase <file>       Set the file basename to be used for dumps
 
 Common Separate
 -dumpbase <file>       Set the file basename to be used for dumps
 
+dumpdir
+Common Separate
+-dumpdir <dir>         Set the directory name to be used for dumps
+
 ; The version of the C++ ABI in use.  The following values are allowed:
 ;
 ; 0: The version of the ABI believed most conformant with the C++ ABI
 ; The version of the C++ ABI in use.  The following values are allowed:
 ;
 ; 0: The version of the ABI believed most conformant with the C++ ABI
index ad69de7..068671d 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1,6 +1,7 @@
 /* Compiler driver program that can handle many languages.
    Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
 /* Compiler driver program that can handle many languages.
    Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
+   2010
    Free Software Foundation, Inc.
 
 This file is part of GCC.
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -891,7 +892,7 @@ static const char *cpp_debug_options = "%{d*}";
 /* NB: This is shared amongst all front-ends, except for Ada.  */
 static const char *cc1_options =
 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
 /* NB: This is shared amongst all front-ends, except for Ada.  */
 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*}\
+ %1 %{!Q:-quiet} %{!dumpbase:-dumpbase %B} %{d*} %{m*} %{a*}\
  %{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} \
  %{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %b}} \
  %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\
  %{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} \
  %{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %b}} \
  %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\
@@ -1188,6 +1189,7 @@ static const struct option_map option_map[] =
    {"--dependencies", "-M", 0},
    {"--dump", "-d", "a"},
    {"--dumpbase", "-dumpbase", "a"},
    {"--dependencies", "-M", 0},
    {"--dump", "-d", "a"},
    {"--dumpbase", "-dumpbase", "a"},
+   {"--dumpdir", "-dumpdir", "a"},
    {"--encoding", "-fencoding=", "aj"},
    {"--entry", "-e", 0},
    {"--extra-warnings", "-W", 0},
    {"--encoding", "-fencoding=", "aj"},
    {"--entry", "-e", 0},
    {"--extra-warnings", "-W", 0},
index 560c7f9..e62b11e 100644 (file)
--- a/gcc/gcc.h
+++ b/gcc/gcc.h
@@ -1,5 +1,5 @@
 /* Header file for modules that link with gcc.c
 /* Header file for modules that link with gcc.c
-   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2007, 2008
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2007, 2008, 2010
    Free Software Foundation, Inc.
 
 This file is part of GCC.
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -52,7 +52,8 @@ struct spec_function
   || !strcmp (STR, "isysroot") \
   || !strcmp (STR, "-param") || !strcmp (STR, "specs") \
   || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ") \
   || !strcmp (STR, "isysroot") \
   || !strcmp (STR, "-param") || !strcmp (STR, "specs") \
   || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ") \
-  || !strcmp (STR, "fintrinsic-modules-path") || !strcmp (STR, "dumpbase"))
+  || !strcmp (STR, "fintrinsic-modules-path") \
+  || !strcmp (STR, "dumpbase") || !strcmp (STR, "dumpdir"))
 
 
 /* These are exported by gcc.c.  */
 
 
 /* These are exported by gcc.c.  */
index 5f24f59..ec0a96e 100644 (file)
@@ -1,5 +1,5 @@
 /* Wrapper to call lto.  Used by collect2 and the linker plugin.
 /* Wrapper to call lto.  Used by collect2 and the linker plugin.
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    Factored out of collect2 by Rafael Espindola <espindola@google.com>
 
 
    Factored out of collect2 by Rafael Espindola <espindola@google.com>
 
@@ -258,7 +258,7 @@ run_gcc (unsigned argc, char *argv[])
   const char **argv_ptr;
   char *list_option_full = NULL;
 
   const char **argv_ptr;
   char *list_option_full = NULL;
 
-  new_argc += 8;
+  new_argc += 12;
   new_argv = (const char **) xcalloc (sizeof (char *), new_argc);
 
   argv_ptr = new_argv;
   new_argv = (const char **) xcalloc (sizeof (char *), new_argc);
 
   argv_ptr = new_argv;
@@ -316,7 +316,31 @@ run_gcc (unsigned argc, char *argv[])
             temporary file for the LTO output.  The `-o' option
             will be interpreted by the linker.  */
          if (s[2] == '\0')
             temporary file for the LTO output.  The `-o' option
             will be interpreted by the linker.  */
          if (s[2] == '\0')
-           i++;
+           {
+             char *output_dir, *base, *name;
+
+             i++;
+             output_dir = xstrdup (argv[i]);
+             base = output_dir;
+             for (name = base; *name; name++)
+               if (IS_DIR_SEPARATOR (*name))
+                 base = name + 1;
+             *base = '\0';
+
+             *argv_ptr++ = "-dumpbase";
+             if (*output_dir == '\0')
+               {
+                 static char current_dir[] =
+                   { '.', DIR_SEPARATOR, '\0' };
+                 output_dir = current_dir;
+                 *argv_ptr++ = argv[i];
+               }
+             else
+               *argv_ptr++ = &argv[i][base - output_dir];
+
+             *argv_ptr++ = "-dumpdir";
+             *argv_ptr++ = output_dir;
+           }
        }
       else
        /* Pass the option or argument to LTO.  */
        }
       else
        /* Pass the option or argument to LTO.  */
index 2aa86db..92e595f 100644 (file)
@@ -1,3 +1,10 @@
+2010-01-03  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR lto/41564
+       * lto.c (DUMPBASE_SUFFIX): New.
+       (lto_execute_ltrans): Append a sequence number to -dumpbase
+       for LTRANS.
+
 2010-01-02  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR lto/42580
 2010-01-02  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR lto/42580
index e62bc02..1608e56 100644 (file)
@@ -1,5 +1,5 @@
 /* Top-level LTO routines.
 /* Top-level LTO routines.
-   Copyright 2009 Free Software Foundation, Inc.
+   Copyright 2009, 2010 Free Software Foundation, Inc.
    Contributed by CodeSourcery, Inc.
 
 This file is part of GCC.
    Contributed by CodeSourcery, Inc.
 
 This file is part of GCC.
@@ -1069,6 +1069,8 @@ lto_wpa_write_files (void)
   return output_files;
 }
 
   return output_files;
 }
 
+/* Template of LTRANS dumpbase suffix.  */
+#define DUMPBASE_SUFFIX        ".ltrans18446744073709551615"
 
 /* Perform local transformations (LTRANS) on the files in the NULL-terminated
    FILES array.  These should have been written previously by
 
 /* Perform local transformations (LTRANS) on the files in the NULL-terminated
    FILES array.  These should have been written previously by
@@ -1088,6 +1090,8 @@ lto_execute_ltrans (char *const *files)
   int err;
   int status;
   FILE *ltrans_output_list_stream = NULL;
   int err;
   int status;
   FILE *ltrans_output_list_stream = NULL;
+  bool seen_dumpbase = false;
+  char *dumpbase_suffix = NULL;
 
   timevar_push (TV_WHOPR_WPA_LTRANS_EXEC);
 
 
   timevar_push (TV_WHOPR_WPA_LTRANS_EXEC);
 
@@ -1126,13 +1130,26 @@ lto_execute_ltrans (char *const *files)
          ++j;
        obstack_init (&env_obstack);
        obstack_grow (&env_obstack, &collect_gcc_options[i], j - i);
          ++j;
        obstack_init (&env_obstack);
        obstack_grow (&env_obstack, &collect_gcc_options[i], j - i);
-       obstack_1grow (&env_obstack, 0);
+       if (seen_dumpbase)
+         obstack_grow (&env_obstack, DUMPBASE_SUFFIX,
+                       sizeof (DUMPBASE_SUFFIX));
+       else
+         obstack_1grow (&env_obstack, 0);
        option = XOBFINISH (&env_obstack, char *);
        option = XOBFINISH (&env_obstack, char *);
+       if (seen_dumpbase)
+         {
+           dumpbase_suffix = option + 7 + j - i;
+           seen_dumpbase = false;
+         }
 
        /* LTRANS does not need -fwpa nor -fltrans-*.  */
        if (strncmp (option, "-fwpa", 5) != 0
            && strncmp (option, "-fltrans-", 9) != 0)
 
        /* LTRANS does not need -fwpa nor -fltrans-*.  */
        if (strncmp (option, "-fwpa", 5) != 0
            && strncmp (option, "-fltrans-", 9) != 0)
-         *argv_ptr++ = option;
+         {
+           if (strncmp (option, "-dumpbase", 9) == 0)
+             seen_dumpbase = true;
+           *argv_ptr++ = option;
+         }
       }
   *argv_ptr++ = "-fltrans";
 
       }
   *argv_ptr++ = "-fltrans";
 
@@ -1190,6 +1207,11 @@ lto_execute_ltrans (char *const *files)
          argv_ptr[2] = files[i];
          argv_ptr[3] = NULL;
 
          argv_ptr[2] = files[i];
          argv_ptr[3] = NULL;
 
+         /* Append a sequence number to -dumpbase for LTRANS.  */
+         if (dumpbase_suffix)
+           snprintf (dumpbase_suffix, sizeof (DUMPBASE_SUFFIX) - 7,
+                     "%lu", (unsigned long) i);
+
          /* Execute the driver.  */
          pex = pex_init (0, "lto1", NULL);
          if (pex == NULL)
          /* Execute the driver.  */
          pex = pex_init (0, "lto1", NULL);
          if (pex == NULL)
index 5407527..4ba0d7f 100644 (file)
@@ -1,5 +1,5 @@
 /* Command line option handling.
 /* Command line option handling.
-   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
    Contributed by Neil Booth.
 
    Free Software Foundation, Inc.
    Contributed by Neil Booth.
 
@@ -971,24 +971,31 @@ decode_options (unsigned int argc, const char **argv)
 
   handle_options (argc, argv, lang_mask);
 
 
   handle_options (argc, argv, lang_mask);
 
-  /* Make DUMP_BASE_NAME relative to the AUX_BASE_NAME directory,
-     typically the directory to contain the object file.  */
-  if (aux_base_name && ! IS_ABSOLUTE_PATH (dump_base_name))
+  if (dump_base_name && ! IS_ABSOLUTE_PATH (dump_base_name))
     {
     {
-      const char *aux_base;
-
-      base_of_path (aux_base_name, &aux_base);
-      if (aux_base_name != aux_base)
+      /* First try to make DUMP_BASE_NAME relative to the DUMP_DIR_NAME
+        directory.  Then try to make DUMP_BASE_NAME relative to the
+        AUX_BASE_NAME directory, typically the directory to contain
+        the object file.  */
+      if (dump_dir_name)
+       dump_base_name = concat (dump_dir_name, dump_base_name, NULL);
+      else if (aux_base_name)
        {
        {
-         int dir_len = aux_base - aux_base_name;
-         char *new_dump_base_name =
-           XNEWVEC (char, strlen(dump_base_name) + dir_len + 1);
-
-         /* Copy directory component from AUX_BASE_NAME.  */
-         memcpy (new_dump_base_name, aux_base_name, dir_len);
-         /* Append existing DUMP_BASE_NAME.  */
-         strcpy (new_dump_base_name + dir_len, dump_base_name);
-         dump_base_name = new_dump_base_name;
+         const char *aux_base;
+
+         base_of_path (aux_base_name, &aux_base);
+         if (aux_base_name != aux_base)
+           {
+             int dir_len = aux_base - aux_base_name;
+             char *new_dump_base_name =
+               XNEWVEC (char, strlen(dump_base_name) + dir_len + 1);
+
+             /* Copy directory component from AUX_BASE_NAME.  */
+             memcpy (new_dump_base_name, aux_base_name, dir_len);
+             /* Append existing DUMP_BASE_NAME.  */
+             strcpy (new_dump_base_name + dir_len, dump_base_name);
+             dump_base_name = new_dump_base_name;
+           }
        }
     }
 
        }
     }
 
@@ -1701,6 +1708,10 @@ common_handle_option (size_t scode, const char *arg, int value,
       dump_base_name = arg;
       break;
 
       dump_base_name = arg;
       break;
 
+    case OPT_dumpdir:
+      dump_dir_name = arg;
+      break;
+
     case OPT_falign_functions_:
       align_functions = value;
       break;
     case OPT_falign_functions_:
       align_functions = value;
       break;
index e916c8d..224b288 100644 (file)
@@ -152,6 +152,10 @@ struct line_maps *line_table;
 
 const char *dump_base_name;
 
 
 const char *dump_base_name;
 
+/* Directory used for dump output files.  */
+
+const char *dump_dir_name;
+
 /* Name to use as a base for auxiliary output files.  */
 
 const char *aux_base_name;
 /* Name to use as a base for auxiliary output files.  */
 
 const char *aux_base_name;
@@ -1388,6 +1392,7 @@ print_switch_values (print_switch_fn_type print_fn)
          /* Ignore these.  */
          if (strcmp (*p, "-o") == 0
              || strcmp (*p, "-dumpbase") == 0
          /* Ignore these.  */
          if (strcmp (*p, "-o") == 0
              || strcmp (*p, "-dumpbase") == 0
+             || strcmp (*p, "-dumpdir") == 0
              || strcmp (*p, "-auxbase") == 0)
            {
              if (p[1] != NULL)
              || strcmp (*p, "-auxbase") == 0)
            {
              if (p[1] != NULL)
index 53f981c..983022e 100644 (file)
@@ -1,6 +1,7 @@
 /* toplev.h - Various declarations for functions found in toplev.c
 /* toplev.h - Various declarations for functions found in toplev.c
-   Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008,
-   2009 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007,
+   2008, 2009, 2010
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
 
 This file is part of GCC.
 
@@ -116,6 +117,7 @@ extern unsigned local_tick;
 
 extern const char *progname;
 extern const char *dump_base_name;
 
 extern const char *progname;
 extern const char *dump_base_name;
+extern const char *dump_dir_name;
 extern const char *aux_base_name;
 extern const char *aux_info_file_name;
 extern const char *profile_data_prefix;
 extern const char *aux_base_name;
 extern const char *aux_info_file_name;
 extern const char *profile_data_prefix;