Commit 4314a3ef by Thomas Schwinge Committed by Thomas Schwinge

[PR other/65021] mkoffloads -save-temps handling, and cleanup cleanup

	gcc/
	PR other/65021
	* config/i386/intelmic-mkoffload.c (mkoffload_atexit): Rename
	function to...
	(mkoffload_cleanup): ... this.  Adjust all users.
	(maybe_unlink): Look at save_temps and verbose flags instead of
	debug flag.
	(main): Parse "-save-temps" flag.
	(generate_target_descr_file, generate_target_offloadend_file)
	(generate_host_descr_file, prepare_target_image): Pass it on.
	* config/nvptx/mkoffload.c (tool_cleanup): Implement.
	(mkoffload_cleanup): New function.
	(maybe_unlink): Look at save_temps and verbose flags instead of
	debug flag.
	(main): Instead of calling utils_cleanup, register atexit handler
	for mkoffload_cleanup.
	(main): Parse "-save-temps" flag.
	(compile_native, main): Pass it on.
	* lto-wrapper.c (compile_offload_image): Likewise.

From-SVN: r228488
parent 1d10676d
2015-10-05 Thomas Schwinge <thomas@codesourcery.com>
PR other/65021
* config/i386/intelmic-mkoffload.c (mkoffload_atexit): Rename
function to...
(mkoffload_cleanup): ... this. Adjust all users.
(maybe_unlink): Look at save_temps and verbose flags instead of
debug flag.
(main): Parse "-save-temps" flag.
(generate_target_descr_file, generate_target_offloadend_file)
(generate_host_descr_file, prepare_target_image): Pass it on.
* config/nvptx/mkoffload.c (tool_cleanup): Implement.
(mkoffload_cleanup): New function.
(maybe_unlink): Look at save_temps and verbose flags instead of
debug flag.
(main): Instead of calling utils_cleanup, register atexit handler
for mkoffload_cleanup.
(main): Parse "-save-temps" flag.
(compile_native, main): Pass it on.
* lto-wrapper.c (compile_offload_image): Likewise.
2015-10-05 Trevor Saunders <tbsaunde+gcc@tbsaunde.org> 2015-10-05 Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
* gimple.h (gimple_op_ptr): Require a non const gimple *. * gimple.h (gimple_op_ptr): Require a non const gimple *.
...@@ -763,7 +784,7 @@ ...@@ -763,7 +784,7 @@
* config/i386/intelmic-mkoffload.c (main): Parse "-v" flag. * config/i386/intelmic-mkoffload.c (main): Parse "-v" flag.
(generate_target_descr_file, generate_target_offloadend_file) (generate_target_descr_file, generate_target_offloadend_file)
(generate_host_descr_file, prepare_target_image, main): Pass it on. (generate_host_descr_file, prepare_target_image): Pass it on.
* config/nvptx/mkoffload.c (main): Parse "-v" flag. * config/nvptx/mkoffload.c (main): Parse "-v" flag.
(compile_native, main): Pass it on. (compile_native, main): Pass it on.
* lto-wrapper.c (compile_offload_image): Likewise. * lto-wrapper.c (compile_offload_image): Likewise.
...@@ -45,6 +45,7 @@ const char *temp_files[MAX_NUM_TEMPS]; ...@@ -45,6 +45,7 @@ const char *temp_files[MAX_NUM_TEMPS];
enum offload_abi offload_abi = OFFLOAD_ABI_UNSET; enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
/* Delete tempfiles and exit function. */ /* Delete tempfiles and exit function. */
void void
tool_cleanup (bool from_signal ATTRIBUTE_UNUSED) tool_cleanup (bool from_signal ATTRIBUTE_UNUSED)
{ {
...@@ -53,19 +54,24 @@ tool_cleanup (bool from_signal ATTRIBUTE_UNUSED) ...@@ -53,19 +54,24 @@ tool_cleanup (bool from_signal ATTRIBUTE_UNUSED)
} }
static void static void
mkoffload_atexit (void) mkoffload_cleanup (void)
{ {
tool_cleanup (false); tool_cleanup (false);
} }
/* Unlink FILE unless we are debugging. */ /* Unlink FILE unless requested otherwise. */
void void
maybe_unlink (const char *file) maybe_unlink (const char *file)
{ {
if (debug) if (!save_temps)
notice ("[Leaving %s]\n", file); {
else if (unlink_if_ordinary (file)
unlink_if_ordinary (file); && errno != ENOENT)
fatal_error (input_location, "deleting file %s: %m", file);
}
else if (verbose)
fprintf (stderr, "[Leaving %s]\n", file);
} }
/* Add or change the value of an environment variable, outputting the /* Add or change the value of an environment variable, outputting the
...@@ -281,6 +287,8 @@ generate_target_descr_file (const char *target_compiler) ...@@ -281,6 +287,8 @@ generate_target_descr_file (const char *target_compiler)
struct obstack argv_obstack; struct obstack argv_obstack;
obstack_init (&argv_obstack); obstack_init (&argv_obstack);
obstack_ptr_grow (&argv_obstack, target_compiler); obstack_ptr_grow (&argv_obstack, target_compiler);
if (save_temps)
obstack_ptr_grow (&argv_obstack, "-save-temps");
if (verbose) if (verbose)
obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-v");
obstack_ptr_grow (&argv_obstack, "-c"); obstack_ptr_grow (&argv_obstack, "-c");
...@@ -321,6 +329,8 @@ generate_target_offloadend_file (const char *target_compiler) ...@@ -321,6 +329,8 @@ generate_target_offloadend_file (const char *target_compiler)
struct obstack argv_obstack; struct obstack argv_obstack;
obstack_init (&argv_obstack); obstack_init (&argv_obstack);
obstack_ptr_grow (&argv_obstack, target_compiler); obstack_ptr_grow (&argv_obstack, target_compiler);
if (save_temps)
obstack_ptr_grow (&argv_obstack, "-save-temps");
if (verbose) if (verbose)
obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-v");
obstack_ptr_grow (&argv_obstack, "-c"); obstack_ptr_grow (&argv_obstack, "-c");
...@@ -386,6 +396,8 @@ generate_host_descr_file (const char *host_compiler) ...@@ -386,6 +396,8 @@ generate_host_descr_file (const char *host_compiler)
struct obstack argv_obstack; struct obstack argv_obstack;
obstack_init (&argv_obstack); obstack_init (&argv_obstack);
obstack_ptr_grow (&argv_obstack, host_compiler); obstack_ptr_grow (&argv_obstack, host_compiler);
if (save_temps)
obstack_ptr_grow (&argv_obstack, "-save-temps");
if (verbose) if (verbose)
obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-v");
obstack_ptr_grow (&argv_obstack, "-c"); obstack_ptr_grow (&argv_obstack, "-c");
...@@ -434,6 +446,8 @@ prepare_target_image (const char *target_compiler, int argc, char **argv) ...@@ -434,6 +446,8 @@ prepare_target_image (const char *target_compiler, int argc, char **argv)
struct obstack argv_obstack; struct obstack argv_obstack;
obstack_init (&argv_obstack); obstack_init (&argv_obstack);
obstack_ptr_grow (&argv_obstack, target_compiler); obstack_ptr_grow (&argv_obstack, target_compiler);
if (save_temps)
obstack_ptr_grow (&argv_obstack, "-save-temps");
if (verbose) if (verbose)
obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-v");
obstack_ptr_grow (&argv_obstack, "-xlto"); obstack_ptr_grow (&argv_obstack, "-xlto");
...@@ -536,7 +550,7 @@ main (int argc, char **argv) ...@@ -536,7 +550,7 @@ main (int argc, char **argv)
gcc_init_libintl (); gcc_init_libintl ();
diagnostic_initialize (global_dc, 0); diagnostic_initialize (global_dc, 0);
if (atexit (mkoffload_atexit) != 0) if (atexit (mkoffload_cleanup) != 0)
fatal_error (input_location, "atexit failed"); fatal_error (input_location, "atexit failed");
const char *host_compiler = getenv ("COLLECT_GCC"); const char *host_compiler = getenv ("COLLECT_GCC");
...@@ -568,6 +582,8 @@ main (int argc, char **argv) ...@@ -568,6 +582,8 @@ main (int argc, char **argv)
"unrecognizable argument of option " STR); "unrecognizable argument of option " STR);
} }
#undef STR #undef STR
else if (strcmp (argv[i], "-save-temps") == 0)
save_temps = true;
else if (strcmp (argv[i], "-v") == 0) else if (strcmp (argv[i], "-v") == 0)
verbose = true; verbose = true;
} }
......
...@@ -58,26 +58,36 @@ enum offload_abi offload_abi = OFFLOAD_ABI_UNSET; ...@@ -58,26 +58,36 @@ enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
/* Delete tempfiles. */ /* Delete tempfiles. */
/* Unlink a temporary file unless requested otherwise. */ void
tool_cleanup (bool from_signal ATTRIBUTE_UNUSED)
{
if (ptx_cfile_name)
maybe_unlink (ptx_cfile_name);
if (ptx_name)
maybe_unlink (ptx_name);
}
static void
mkoffload_cleanup (void)
{
tool_cleanup (false);
}
/* Unlink FILE unless requested otherwise. */
void void
maybe_unlink (const char *file) maybe_unlink (const char *file)
{ {
if (! debug) if (!save_temps)
{ {
if (unlink_if_ordinary (file) if (unlink_if_ordinary (file)
&& errno != ENOENT) && errno != ENOENT)
fatal_error (input_location, "deleting file %s: %m", file); fatal_error (input_location, "deleting file %s: %m", file);
} }
else else if (verbose)
fprintf (stderr, "[Leaving %s]\n", file); fprintf (stderr, "[Leaving %s]\n", file);
} }
void
tool_cleanup (bool)
{
}
/* Add or change the value of an environment variable, outputting the /* Add or change the value of an environment variable, outputting the
change to standard error if in verbose mode. */ change to standard error if in verbose mode. */
static void static void
...@@ -353,6 +363,8 @@ compile_native (const char *infile, const char *outfile, const char *compiler) ...@@ -353,6 +363,8 @@ compile_native (const char *infile, const char *outfile, const char *compiler)
struct obstack argv_obstack; struct obstack argv_obstack;
obstack_init (&argv_obstack); obstack_init (&argv_obstack);
obstack_ptr_grow (&argv_obstack, compiler); obstack_ptr_grow (&argv_obstack, compiler);
if (save_temps)
obstack_ptr_grow (&argv_obstack, "-save-temps");
if (verbose) if (verbose)
obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-v");
switch (offload_abi) switch (offload_abi)
...@@ -387,6 +399,9 @@ main (int argc, char **argv) ...@@ -387,6 +399,9 @@ main (int argc, char **argv)
progname = "mkoffload"; progname = "mkoffload";
diagnostic_initialize (global_dc, 0); diagnostic_initialize (global_dc, 0);
if (atexit (mkoffload_cleanup) != 0)
fatal_error (input_location, "atexit failed");
char *collect_gcc = getenv ("COLLECT_GCC"); char *collect_gcc = getenv ("COLLECT_GCC");
if (collect_gcc == NULL) if (collect_gcc == NULL)
fatal_error (input_location, "COLLECT_GCC must be set."); fatal_error (input_location, "COLLECT_GCC must be set.");
...@@ -461,6 +476,8 @@ main (int argc, char **argv) ...@@ -461,6 +476,8 @@ main (int argc, char **argv)
#undef STR #undef STR
else if (strcmp (argv[i], "-fopenmp") == 0) else if (strcmp (argv[i], "-fopenmp") == 0)
fopenmp = true; fopenmp = true;
else if (strcmp (argv[i], "-save-temps") == 0)
save_temps = true;
else if (strcmp (argv[i], "-v") == 0) else if (strcmp (argv[i], "-v") == 0)
verbose = true; verbose = true;
} }
...@@ -468,6 +485,8 @@ main (int argc, char **argv) ...@@ -468,6 +485,8 @@ main (int argc, char **argv)
struct obstack argv_obstack; struct obstack argv_obstack;
obstack_init (&argv_obstack); obstack_init (&argv_obstack);
obstack_ptr_grow (&argv_obstack, driver); obstack_ptr_grow (&argv_obstack, driver);
if (save_temps)
obstack_ptr_grow (&argv_obstack, "-save-temps");
if (verbose) if (verbose)
obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-v");
obstack_ptr_grow (&argv_obstack, "-xlto"); obstack_ptr_grow (&argv_obstack, "-xlto");
...@@ -532,7 +551,5 @@ main (int argc, char **argv) ...@@ -532,7 +551,5 @@ main (int argc, char **argv)
compile_native (ptx_cfile_name, outname, collect_gcc); compile_native (ptx_cfile_name, outname, collect_gcc);
utils_cleanup (false);
return 0; return 0;
} }
...@@ -685,6 +685,8 @@ compile_offload_image (const char *target, const char *compiler_path, ...@@ -685,6 +685,8 @@ compile_offload_image (const char *target, const char *compiler_path,
struct obstack argv_obstack; struct obstack argv_obstack;
obstack_init (&argv_obstack); obstack_init (&argv_obstack);
obstack_ptr_grow (&argv_obstack, compiler); obstack_ptr_grow (&argv_obstack, compiler);
if (save_temps)
obstack_ptr_grow (&argv_obstack, "-save-temps");
if (verbose) if (verbose)
obstack_ptr_grow (&argv_obstack, "-v"); obstack_ptr_grow (&argv_obstack, "-v");
obstack_ptr_grow (&argv_obstack, "-o"); obstack_ptr_grow (&argv_obstack, "-o");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment