On Jun 18, 2020, Tobias Burnus <tob...@codesourcery.com> wrote: > On 6/18/20 8:10 AM, Alexandre Oliva wrote: >> Could you possibly give this *completely* untested patch a try and let >> me know whether it does any good?
> Otherwise, see attachment. I now added also the @/tmp file which is > passed to mkoffload. Thanks. I see the main problem besides the dumppfx constness is the double dot before target, fixed in the revised patch below. With this, I think the libgomp testsuite might work with offloading again. >> I actually thought it might be appropriate to use ".x<offload_target>" >> instead of ".target" in the dumpbase passed to mkoffload, so that we >> create different file names for different offload targets, > I wonder whether we need to do this – as one can create code for > multiple offload targets by the same compiler at the same time. Aah, I wasn't sure this was indeed the case. Well, then, I'll try to figure out how to get to the selected offloading target from the scandump machinery. > and intelmic. How does intelmic get into the picture? I looked for a mkoffload program for it in the GCC source tree and couldn't find one. This suggests that the addition of -dumpbase to the mkoffload interface might require changes elsewhere. handle dumpbase in offloading From: Alexandre Oliva <ol...@adacore.com> Pass dumpbase on to mkoffloads and their offload-target compiler runs. Obey -save-temps in naming temporary files while at that. for gcc/ChangeLog * colllect-utils.h (dumppfx): New. * colllect-utils.c (dumppfx): Likewise. * lto-wrapper.c (run_gcc): Set global dumppfx. (compile_offload_image): Pass a -dumpbase on to mkoffload. * config/nvptx/mkoffload.c (ptx_dumpbase): New. (main): Handle incoming -dumpbase. Set ptx_dumpbase. Obey save_temps. (compile_native): Pass -dumpbase et al to compiler. * config/gcn/mkoffload.c (gcn_dumpbase): New. (main): Handle incoming -dumpbase. Set gcn_dumpbase. Obey save_temps. Pass -dumpbase et al to offload target compiler. (compile_native): Pass -dumpbase et al to compiler. for gcc/testsuite/ChangeLog * lib/scanoffloadrtl.exp: Replace ".o" with ".target.mkoffload" globally as the dump base suffix. * lib/scanoffloadtree.exp: Likewise. --- gcc/collect-utils.c | 1 + gcc/collect-utils.h | 1 + gcc/config/gcn/mkoffload.c | 52 ++++++++++++++++++++++++++++++--- gcc/config/nvptx/mkoffload.c | 31 ++++++++++++++++++-- gcc/lto-wrapper.c | 16 +++++++++- gcc/testsuite/lib/scanoffloadrtl.exp | 28 +++++++++--------- gcc/testsuite/lib/scanoffloadtree.exp | 30 ++++++++++--------- 7 files changed, 121 insertions(+), 38 deletions(-) diff --git a/gcc/collect-utils.c b/gcc/collect-utils.c index e85843bc..d4fa2c3 100644 --- a/gcc/collect-utils.c +++ b/gcc/collect-utils.c @@ -34,6 +34,7 @@ static char *response_file; bool debug; bool verbose; bool save_temps; +const char *dumppfx; /* Notify user of a non-error. */ diff --git a/gcc/collect-utils.h b/gcc/collect-utils.h index e7c955f..6ff7d9d9 100644 --- a/gcc/collect-utils.h +++ b/gcc/collect-utils.h @@ -37,6 +37,7 @@ extern void utils_cleanup (bool); extern bool debug; extern bool verbose; extern bool save_temps; +extern const char *dumppfx; /* Provided by the tool itself. */ diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c index 4a99d70..9046451a 100644 --- a/gcc/config/gcn/mkoffload.c +++ b/gcc/config/gcn/mkoffload.c @@ -41,6 +41,7 @@ static const char *gcn_s1_name; static const char *gcn_s2_name; static const char *gcn_o_name; static const char *gcn_cfile_name; +static const char *gcn_dumpbase; enum offload_abi offload_abi = OFFLOAD_ABI_UNSET; @@ -496,6 +497,12 @@ compile_native (const char *infile, const char *outfile, const char *compiler) obstack_ptr_grow (&argv_obstack, "-save-temps"); if (verbose) obstack_ptr_grow (&argv_obstack, "-v"); + obstack_ptr_grow (&argv_obstack, "-dumpdir"); + obstack_ptr_grow (&argv_obstack, ""); + obstack_ptr_grow (&argv_obstack, "-dumpbase"); + obstack_ptr_grow (&argv_obstack, gcn_dumpbase); + obstack_ptr_grow (&argv_obstack, "-dumpbase-ext"); + obstack_ptr_grow (&argv_obstack, ".c"); switch (offload_abi) { case OFFLOAD_ABI_LP64: @@ -525,6 +532,7 @@ main (int argc, char **argv) FILE *out = stdout; FILE *cfile = stdout; const char *outname = 0; + char *dumpbase; progname = "mkoffload"; diagnostic_initialize (global_dc, 0); @@ -611,6 +619,9 @@ main (int argc, char **argv) save_temps = true; else if (strcmp (argv[i], "-v") == 0) verbose = true; + else if (strcmp (argv[i], "-dumpbase") == 0 + && i + 1 < argc) + dumppfx = argv[++i]; } if (!(fopenacc ^ fopenmp)) fatal_error (input_location, "either -fopenacc or -fopenmp must be set"); @@ -628,11 +639,6 @@ main (int argc, char **argv) gcc_unreachable (); } - gcn_s1_name = make_temp_file (".mkoffload.1.s"); - gcn_s2_name = make_temp_file (".mkoffload.2.s"); - gcn_o_name = make_temp_file (".mkoffload.hsaco"); - gcn_cfile_name = make_temp_file (".c"); - /* Build arguments for compiler pass. */ struct obstack cc_argv_obstack; obstack_init (&cc_argv_obstack); @@ -656,6 +662,35 @@ main (int argc, char **argv) obstack_ptr_grow (&cc_argv_obstack, argv[ix]); } + if (!dumppfx) + dumppfx = outname; + + const char *mko_dumpbase = concat (dumppfx, ".mkoffload", NULL); + const char *hsaco_dumpbase = concat (dumppfx, ".mkoffload.hsaco", NULL); + gcn_dumpbase = concat (dumppfx, ".c", NULL); + + if (save_temps) + { + gcn_s1_name = concat (mko_dumpbase, ".1.s", NULL); + gcn_s2_name = concat (mko_dumpbase, ".2.s", NULL); + gcn_o_name = hsaco_dumpbase; + gcn_cfile_name = gcn_dumpbase; + } + else + { + gcn_s1_name = make_temp_file (".mkoffload.1.s"); + gcn_s2_name = make_temp_file (".mkoffload.2.s"); + gcn_o_name = make_temp_file (".mkoffload.hsaco"); + gcn_cfile_name = make_temp_file (".c"); + } + + obstack_ptr_grow (&argv_obstack, "-dumpdir"); + obstack_ptr_grow (&argv_obstack, ""); + obstack_ptr_grow (&argv_obstack, "-dumpbase"); + obstack_ptr_grow (&argv_obstack, mko_dumpbase); + obstack_ptr_grow (&argv_obstack, "-dumpbase-ext"); + obstack_ptr_grow (&argv_obstack, ""); + obstack_ptr_grow (&cc_argv_obstack, "-o"); obstack_ptr_grow (&cc_argv_obstack, gcn_s1_name); obstack_ptr_grow (&cc_argv_obstack, NULL); @@ -674,6 +709,13 @@ main (int argc, char **argv) || strncmp (argv[i], "-march", 6) == 0) obstack_ptr_grow (&ld_argv_obstack, argv[i]); + obstack_ptr_grow (&argv_obstack, "-dumpdir"); + obstack_ptr_grow (&argv_obstack, ""); + obstack_ptr_grow (&argv_obstack, "-dumpbase"); + obstack_ptr_grow (&argv_obstack, hsaco_dumpbase); + obstack_ptr_grow (&argv_obstack, "-dumpbase-ext"); + obstack_ptr_grow (&argv_obstack, ""); + obstack_ptr_grow (&ld_argv_obstack, "-o"); obstack_ptr_grow (&ld_argv_obstack, gcn_o_name); obstack_ptr_grow (&ld_argv_obstack, NULL); diff --git a/gcc/config/nvptx/mkoffload.c b/gcc/config/nvptx/mkoffload.c index 803b585..efdf9b9 100644 --- a/gcc/config/nvptx/mkoffload.c +++ b/gcc/config/nvptx/mkoffload.c @@ -55,6 +55,7 @@ static id_map *var_ids, **vars_tail = &var_ids; /* Files to unlink. */ static const char *ptx_name; static const char *ptx_cfile_name; +static const char *ptx_dumpbase; enum offload_abi offload_abi = OFFLOAD_ABI_UNSET; @@ -369,6 +370,12 @@ compile_native (const char *infile, const char *outfile, const char *compiler) obstack_ptr_grow (&argv_obstack, "-save-temps"); if (verbose) obstack_ptr_grow (&argv_obstack, "-v"); + obstack_ptr_grow (&argv_obstack, "-dumpdir"); + obstack_ptr_grow (&argv_obstack, ""); + obstack_ptr_grow (&argv_obstack, "-dumpbase"); + obstack_ptr_grow (&argv_obstack, ptx_dumpbase); + obstack_ptr_grow (&argv_obstack, "-dumpbase-ext"); + obstack_ptr_grow (&argv_obstack, ".c"); switch (offload_abi) { case OFFLOAD_ABI_LP64: @@ -486,6 +493,9 @@ main (int argc, char **argv) save_temps = true; else if (strcmp (argv[i], "-v") == 0) verbose = true; + else if (strcmp (argv[i], "-dumpbase") == 0 + && i + 1 < argc) + dumppfx = argv[++i]; } if (!(fopenacc ^ fopenmp)) fatal_error (input_location, "either %<-fopenacc%> or %<-fopenmp%> " @@ -521,7 +531,14 @@ main (int argc, char **argv) obstack_ptr_grow (&argv_obstack, argv[ix]); } - ptx_cfile_name = make_temp_file (".c"); + if (!dumppfx) + dumppfx = outname; + + ptx_dumpbase = concat (dumppfx, ".c", NULL); + if (save_temps) + ptx_cfile_name = ptx_dumpbase; + else + ptx_cfile_name = make_temp_file (".c"); out = fopen (ptx_cfile_name, "w"); if (!out) @@ -531,7 +548,17 @@ main (int argc, char **argv) configurations. */ if (offload_abi == OFFLOAD_ABI_LP64) { - ptx_name = make_temp_file (".mkoffload"); + char *mko_dumpbase = concat (dumppfx, ".mkoffload", NULL); + if (save_temps) + ptx_name = mko_dumpbase; + else + ptx_name = make_temp_file (".mkoffload"); + obstack_ptr_grow (&argv_obstack, "-dumpdir"); + obstack_ptr_grow (&argv_obstack, ""); + obstack_ptr_grow (&argv_obstack, "-dumpbase"); + obstack_ptr_grow (&argv_obstack, mko_dumpbase); + obstack_ptr_grow (&argv_obstack, "-dumpbase-ext"); + obstack_ptr_grow (&argv_obstack, ""); obstack_ptr_grow (&argv_obstack, "-o"); obstack_ptr_grow (&argv_obstack, ptx_name); obstack_ptr_grow (&argv_obstack, NULL); diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c index 8fbca7c..e990961 100644 --- a/gcc/lto-wrapper.c +++ b/gcc/lto-wrapper.c @@ -830,6 +830,7 @@ compile_offload_image (const char *target, const char *compiler_path, unsigned int linker_opt_count) { char *filename = NULL; + char *dumpbase; char **argv; char *suffix = XALLOCAVEC (char, sizeof ("/accel//mkoffload") + strlen (target)); @@ -853,8 +854,16 @@ compile_offload_image (const char *target, const char *compiler_path, "could not find %s in %s (consider using %<-B%>)", suffix + 1, compiler_path); + /* ??? We should probably use the TARGET name instead of "target" + here, so as to create different file names for different offload + targets. */ + dumpbase = concat (dumppfx, "target", NULL); + /* Generate temporary output file name. */ - filename = make_temp_file (".target.o"); + if (save_temps) + filename = concat (dumpbase, ".o", NULL); + else + filename = make_temp_file (".target.o"); struct obstack argv_obstack; obstack_init (&argv_obstack); @@ -875,6 +884,9 @@ compile_offload_image (const char *target, const char *compiler_path, compiler_opt_count); append_diag_options (&argv_obstack, linker_opts, linker_opt_count); + obstack_ptr_grow (&argv_obstack, "-dumpbase"); + obstack_ptr_grow (&argv_obstack, dumpbase); + /* Append options specified by -foffload last. In case of conflicting options we expect offload compiler to choose the latest. */ append_offload_options (&argv_obstack, target, compiler_opts, @@ -1298,7 +1310,7 @@ run_gcc (unsigned argc, char *argv[]) bool linker_output_rel = false; bool skip_debug = false; unsigned n_debugobj; - const char *dumppfx = NULL, *incoming_dumppfx = NULL; + const char *incoming_dumppfx = dumppfx = NULL; static char current_dir[] = { '.', DIR_SEPARATOR, '\0' }; /* Get the driver and options. */ diff --git a/gcc/testsuite/lib/scanoffloadrtl.exp b/gcc/testsuite/lib/scanoffloadrtl.exp index 69e4e7c8..e792450 100644 --- a/gcc/testsuite/lib/scanoffloadrtl.exp +++ b/gcc/testsuite/lib/scanoffloadrtl.exp @@ -37,11 +37,11 @@ proc scan-offload-rtl-dump { args } { } if { [llength $args] >= 3 } { scan-dump "offload-rtl" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".o" \ - [lindex $args 2] + "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".target.mkoffload" \ + [lindex $args 2] } else { scan-dump "offload-rtl" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".o" + "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".target.mkoffload" } } @@ -62,11 +62,11 @@ proc scan-offload-rtl-dump-times { args } { } if { [llength $args] >= 4 } { scan-dump-times "offload-rtl" [lindex $args 0] [lindex $args 1] \ - "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 2]" ".o" \ + "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 2]" ".target.mkoffload" \ [lindex $args 3] } else { scan-dump-times "offload-rtl" [lindex $args 0] [lindex $args 1] \ - "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 2]" ".o" + "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 2]" ".target.mkoffload" } } @@ -87,11 +87,11 @@ proc scan-offload-rtl-dump-not { args } { } if { [llength $args] >= 3 } { scan-dump-not "offload-rtl" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".o" \ - [lindex $args 2] + "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".target.mkoffload" \ + [lindex $args 2] } else { scan-dump-not "offload-rtl" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".o" + "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".target.mkoffload" } } @@ -113,11 +113,11 @@ proc scan-offload-rtl-dump-dem { args } { } if { [llength $args] >= 3 } { scan-dump-dem "offload-rtl" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".o" \ - [lindex $args 2] + "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".target.mkoffload" \ + [lindex $args 2] } else { scan-dump-dem "offload-rtl" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".o" + "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".target.mkoffload" } } @@ -138,10 +138,10 @@ proc scan-offload-rtl-dump-dem-not { args } { } if { [llength $args] >= 3 } { scan-dump-dem-not "offload-rtl" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".o" \ - [lindex $args 2] + "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".target.mkoffload" \ + [lindex $args 2] } else { scan-dump-dem-not "offload-rtl" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".o" + "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".target.mkoffload" } } diff --git a/gcc/testsuite/lib/scanoffloadtree.exp b/gcc/testsuite/lib/scanoffloadtree.exp index 76a28d0..3a3b64d2 100644 --- a/gcc/testsuite/lib/scanoffloadtree.exp +++ b/gcc/testsuite/lib/scanoffloadtree.exp @@ -37,11 +37,11 @@ proc scan-offload-tree-dump { args } { } if { [llength $args] >= 3 } { scan-dump "offload-tree" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".o" \ - [lindex $args 2] + "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".target.mkoffload" \ + [lindex $args 2] } else { scan-dump "offload-tree" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".o" + "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".target.mkoffload" } } @@ -62,11 +62,11 @@ proc scan-offload-tree-dump-times { args } { } if { [llength $args] >= 4 } { scan-dump-times "offload-tree" [lindex $args 0] [lindex $args 1] \ - "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 2]" ".o" \ - [lindex $args 3] + "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 2]" ".target.mkoffload" \ + [lindex $args 3] } else { scan-dump-times "offload-tree" [lindex $args 0] [lindex $args 1] \ - "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 2]" ".o" + "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 2]" ".target.mkoffload" } } @@ -87,11 +87,11 @@ proc scan-offload-tree-dump-not { args } { } if { [llength $args] >= 3 } { scan-dump-not "offload-tree" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".o" \ - [lindex $args 2] + "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".target.mkoffload" \ + [lindex $args 2] } else { scan-dump-not "offload-tree" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".o" + "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".target.mkoffload" } } @@ -113,11 +113,11 @@ proc scan-offload-tree-dump-dem { args } { } if { [llength $args] >= 3 } { scan-dump-dem "offload-tree" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".o" \ - [lindex $args 2] + "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".target.mkoffload" \ + [lindex $args 2] } else { scan-dump-dem "offload-tree" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".o" + "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".target.mkoffload" } } @@ -138,10 +138,10 @@ proc scan-offload-tree-dump-dem-not { args } { } if { [llength $args] >= 3 } { scan-dump-dem-not "offload-tree" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".o" \ - [lindex $args 2] + "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".target.mkoffload" \ + [lindex $args 2] } else { scan-dump-dem-not "offload-tree" [lindex $args 0] \ - "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".o" + "\[0-9\]\[0-9\]\[0-9]t.[lindex $args 1]" ".target.mkoffload" } } -- Alexandre Oliva, freedom fighter he/him https://FSFLA.org/blogs/lxo/ Free Software Evangelist Stallman was right, but he's left :( GNU Toolchain Engineer Live long and free, and prosper ethically