diff options
author | Richard Guenther <rguenther@suse.de> | 2010-05-19 15:43:22 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2010-05-19 15:43:22 +0000 |
commit | c04b6b3823c92bd06e1a6b33d1a05003f1760df7 (patch) | |
tree | 689a3a31c6e8de88d9e21e313b23a02153e122b9 /gcc/lto-wrapper.c | |
parent | d416abb494df912d22716d8882b7aceaab487fdf (diff) | |
download | gcc-c04b6b3823c92bd06e1a6b33d1a05003f1760df7.zip gcc-c04b6b3823c92bd06e1a6b33d1a05003f1760df7.tar.gz gcc-c04b6b3823c92bd06e1a6b33d1a05003f1760df7.tar.bz2 |
invoke.texi (-fwhopr): Document new optional jobs argument.
2010-05-19 Richard Guenther <rguenther@suse.de>
* doc/invoke.texi (-fwhopr): Document new optional jobs argument.
* common.opt (fwhopr=): New.
* opts.c (common_handle_option): Handle OPT_fwhopr.
* gcc.c (LINK_COMMAND_SPEC): Pass fwhopr*.
* collect2.c (main): Match -fwhopr*.
* lto-wrapper.c (run_gcc): Handle jobs argument of -fwhopr.
Execute ltrans stage in parallel when jobs is bigger than 1.
From-SVN: r159573
Diffstat (limited to 'gcc/lto-wrapper.c')
-rw-r--r-- | gcc/lto-wrapper.c | 83 |
1 files changed, 70 insertions, 13 deletions
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c index 5c9650e..3dbd96b 100644 --- a/gcc/lto-wrapper.c +++ b/gcc/lto-wrapper.c @@ -148,7 +148,10 @@ collect_execute (char **argv) if (pex == NULL) fatal_perror ("pex_init failed"); - errmsg = pex_run (pex, PEX_LAST | PEX_SEARCH, argv[0], argv, NULL, + /* Do not use PEX_LAST here, we use our stdout for communicating with + collect2 or the linker-plugin. Any output from the sub-process + will confuse that. */ + errmsg = pex_run (pex, PEX_SEARCH, argv[0], argv, NULL, NULL, &err); if (errmsg != NULL) { @@ -264,6 +267,7 @@ run_gcc (unsigned argc, char *argv[]) const char *collect_gcc_options, *collect_gcc; struct obstack env_obstack; bool seen_o = false; + int parallel = 0; /* Get the driver and options. */ collect_gcc = getenv ("COLLECT_GCC"); @@ -329,8 +333,16 @@ run_gcc (unsigned argc, char *argv[]) /* We've handled these LTO options, do not pass them on. */ if (strcmp (option, "-flto") == 0) lto_mode = LTO_MODE_LTO; - else if (strcmp (option, "-fwhopr") == 0) - lto_mode = LTO_MODE_WHOPR; + else if (strncmp (option, "-fwhopr", 7) == 0) + { + lto_mode = LTO_MODE_WHOPR; + if (option[7] == '=') + { + parallel = atoi (option+8); + if (parallel <= 1) + parallel = 0; + } + } else *argv_ptr++ = option; } @@ -416,13 +428,23 @@ run_gcc (unsigned argc, char *argv[]) else if (lto_mode == LTO_MODE_WHOPR) { FILE *stream = fopen (ltrans_output_file, "r"); - int nr = 0; + unsigned int nr = 0; + char **input_names = NULL; + char **output_names = NULL; + char *makefile = NULL; + FILE *mstream = NULL; if (!stream) fatal_perror ("fopen: %s", ltrans_output_file); argv_ptr[1] = "-fltrans"; + if (parallel) + { + makefile = make_temp_file (".mk"); + mstream = fopen (makefile, "w"); + } + for (;;) { const unsigned piece = 32; @@ -444,10 +466,7 @@ cont: input_name[len - 1] = '\0'; if (input_name[0] == '*') - { - continue; - output_name = &input_name[1]; - } + output_name = &input_name[1]; else { /* Otherwise, add FILES[I] to lto_execute_ltrans command line @@ -467,7 +486,7 @@ cont: + sizeof(DUMPBASE_SUFFIX) + 1); snprintf (dumpbase, strlen (linker_output) + sizeof(DUMPBASE_SUFFIX), - "%s.ltrans%d", linker_output, nr++); + "%s.ltrans%u", linker_output, nr); argv_ptr[0] = dumpbase; } @@ -476,14 +495,52 @@ cont: argv_ptr[4] = input_name; argv_ptr[5] = NULL; - fork_execute (CONST_CAST (char **, new_argv)); - - maybe_unlink_file (input_name); + if (parallel) + { + fprintf (mstream, "%s:\n\t@%s ", output_name, new_argv[0]); + for (i = 1; new_argv[i] != NULL; ++i) + fprintf (mstream, " '%s'", new_argv[i]); + fprintf (mstream, "\n"); + } + else + fork_execute (CONST_CAST (char **, new_argv)); } - fputs (output_name, stdout); + nr++; + input_names = (char **)xrealloc (input_names, nr * sizeof (char *)); + output_names = (char **)xrealloc (output_names, nr * sizeof (char *)); + input_names[nr-1] = input_name; + output_names[nr-1] = output_name; + } + if (parallel) + { + struct pex_obj *pex; + char jobs[32]; + fprintf (mstream, "all:"); + for (i = 0; i < nr; ++i) + fprintf (mstream, " \\\n\t%s", output_names[i]); + fprintf (mstream, "\n"); + fclose (mstream); + new_argv[0] = "make"; + new_argv[1] = "-f"; + new_argv[2] = makefile; + snprintf (jobs, 31, "-j%d", parallel); + new_argv[3] = jobs; + new_argv[4] = "all"; + new_argv[5] = NULL; + pex = collect_execute (CONST_CAST (char **, new_argv)); + collect_wait (new_argv[0], pex); + maybe_unlink_file (makefile); + } + for (i = 0; i < nr; ++i) + { + fputs (output_names[i], stdout); putc ('\n', stdout); + maybe_unlink_file (input_names[i]); + free (input_names[i]); } + free (output_names); + free (input_names); fclose (stream); maybe_unlink_file (ltrans_output_file); free (list_option_full); |