Message ID | 87y4fzztub.fsf@kepler.schwinge.homeip.net |
---|---|
State | New |
Headers | show |
2015-09-21 18:15 GMT+03:00 Thomas Schwinge <thomas@codesourcery.com>: > (<https://gcc.gnu.org/PR67300>, "--foffload* undocumented", has recently > been filed.) > > (In the following, "intelmic" is short for > "x86_64-intelmicemul-linux-gnu", and "nvptx" is short for "nvptx-none".) > > What is the syntax to use for building both intelmic and nvptx offloading > code? I understand we allow for separate -foffload=intelmic > -foffload=nvptx options. Do we also intend to allow > -foffload=intelmic,nvptx or -foffload=intelmic:nvptx? > > And then, we allow for specifying offloading compiler options with > -foffload=intelmic=[...] and -foffload=nvptx=[...]; do we also intend to > allow -foffload=intelmic,nvptx=[...] (do the options apply to nvptx only, > or to both intelmic and nvptx?), and/or > -foffload=intelmic=[...],nvptx=[...], and/or > -foffload=intelmic:nvptx=[...] (which "looks a bit like" the options > ought to apply to nvptx only -- or to both intelmic and nvptx?), and/or > -foffload=intelmic=[...]:nvptx=[...]? The plan was: 1. -foffload=intelmic,nvptx=[...] <- apply options to both intelmic,nvptx. Just like -foffload=[...] applies to both targets (if configured so). 2. -foffload=intelmic=[...],nvptx=[...] <- is not allowed. 3. To apply different options to different targets, one should pass: -foffload=intelmic=[...] -foffload=nvptx=[...]. > 3612 /* Check that GCC is configured to support the offload target. */ > 3613 c = OFFLOAD_TARGETS; > 3614 while (c) > 3615 { > 3616 n = strchr (c, ','); > 3617 if (n == NULL) > 3618 n = strchr (c, '\0'); > 3619 > 3620 if (next - cur == n - c && strncmp (target, c, n - c) == 0) > 3621 break; > 3622 > 3623 c = *n ? n + 1 : NULL; > 3624 } > 3625 > 3626 if (!c) > 3627 fatal_error (input_location, > 3628 "GCC is not configured to support %s as offload target", > 3629 target); > > So, this code will not do the right thing when configured with > --enable-offload-targets=intelmic,nvptx (thus, > OFFLOAD_TARGETS=intelmic:nvptx): using -foffload=nvptx will then result > in "xgcc: fatal error: GCC is not configured to support nvptx as offload > target". > > If I'm understanding the following code correctly, this supports the idea > that the intention has been for -foffload=[targets]=[options] to separate > the targets by commas, and separate the options by spaces -- is that > correct? Yes, targets are separated by commas, options are the whole string after the equal sign, spaces inside are allowed. -- Ilya
diff --git gcc/gcc.c gcc/gcc.c index 757bfc9..ad210c5a5 100644 --- gcc/gcc.c +++ gcc/gcc.c @@ -284,7 +284,8 @@ static const char *const spec_version = DEFAULT_TARGET_VERSION; static const char *spec_machine = DEFAULT_TARGET_MACHINE; static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE; -/* List of offload targets. */ +/* List of offload targets. Separated by colon. Empty string for + -foffload=disable. */ static char *offload_targets = NULL; @@ -4376,6 +4377,11 @@ process_command (unsigned int decoded_options_count, CL_DRIVER, &handlers, global_dc); } + /* If the user didn't specify any, default to all configured offload + targets. */ + if (offload_targets == NULL) + handle_foffload_option (OFFLOAD_TARGETS); + if (output_file && strcmp (output_file, "-") != 0 && strcmp (output_file, HOST_BIT_BUCKET) != 0) @@ -7572,22 +7578,17 @@ driver::maybe_putenv_COLLECT_LTO_WRAPPER () const void driver::maybe_putenv_OFFLOAD_TARGETS () const { - const char *targets = offload_targets; - - /* If no targets specified by -foffload, use all available targets. */ - if (!targets) - targets = OFFLOAD_TARGETS; - - if (strlen (targets) > 0) + if (offload_targets && offload_targets[0] != '\0') { obstack_grow (&collect_obstack, "OFFLOAD_TARGET_NAMES=", sizeof ("OFFLOAD_TARGET_NAMES=") - 1); - obstack_grow (&collect_obstack, targets, - strlen (targets) + 1); + obstack_grow (&collect_obstack, offload_targets, + strlen (offload_targets) + 1); xputenv (XOBFINISH (&collect_obstack, char *)); } free (offload_targets); + offload_targets = NULL; } /* Reject switches that no pass was interested in. */