Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,9 @@ def fsycl_host_compiler_options_EQ : Joined<["-"], "fsycl-host-compiler-options=
def fno_sycl_use_footer : Flag<["-"], "fno-sycl-use-footer">, Flags<[CoreOption]>,
HelpText<"Disable usage of the integration footer during SYCL enabled "
"compilations.">;
def fsycl_footer_path_EQ : Joined<["-"], "fsycl-footer-path=">,
Flags<[CoreOption]>, HelpText<"Specify the location of the temporary "
"source file with the included integration footer.">;
def fsyntax_only : Flag<["-"], "fsyntax-only">,
Flags<[NoXarchOption,CoreOption,CC1Option,FC1Option]>, Group<Action_Group>;
def ftabstop_EQ : Joined<["-"], "ftabstop=">, Group<f_Group>;
Expand Down
26 changes: 26 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6753,6 +6753,32 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
&JA);
}

// Redirect output for the generated source + integration footer.
if (isa<AppendFooterJobAction>(JA)) {
if (Arg *A = C.getArgs().getLastArg(options::OPT_fsycl_footer_path_EQ)) {
SmallString<128> OutName(A->getValue());
StringRef BaseName = llvm::sys::path::filename(BaseInput);
if (isSaveTempsEnabled()) {
// Retain the location specified by the user with -save-temps.
const char *Suffix = types::getTypeTempSuffix(JA.getType());
std::string::size_type End = std::string::npos;
if (!types::appendSuffixForType(JA.getType()))
End = BaseName.rfind('.');
SmallString<128> Suffixed(BaseName.substr(0, End));
Suffixed += OffloadingPrefix;
Suffixed += '.';
Suffixed += Suffix;
llvm::sys::path::append(OutName, Suffixed.c_str());
} else {
std::string TmpName =
GetTemporaryPath(llvm::sys::path::stem(BaseName),
types::getTypeTempSuffix(JA.getType()));
llvm::sys::path::append(OutName, llvm::sys::path::filename(TmpName));
}
return C.addTempFile(C.getArgs().MakeArgString(OutName));
}
}

// Default to writing to stdout?
if (AtTopLevel && !CCGenDiagnostics && HasPreprocessOutput(JA)) {
return "-";
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Driver/sycl-int-footer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@
// COMMON-PHASES: [[#OFFLOAD+9]]: file-table-tform, {[[#OFFLOAD+6]], [[#OFFLOAD+8]]}, tempfiletable, (device-sycl)
// COMMON-PHASES: [[#OFFLOAD+10]]: clang-offload-wrapper, {[[#OFFLOAD+9]]}, object, (device-sycl)
// COMMON-PHASES: [[#OFFLOAD+11]]: offload, "host-sycl (x86_64-{{.*}})" {[[#OFFLOAD+4]]}, "device-sycl (spir64-unknown-unknown-sycldevice)" {[[#OFFLOAD+10]]}, image

/// Test for -fsycl-footer-path=<dir>
// RUN: %clangxx -fsycl -fsycl-footer-path=dummy_dir %s -### 2>&1 \
// RUN: | FileCheck -check-prefix FOOTER_PATH %s
// FOOTER_PATH: append-file{{.*}} "--output=dummy_dir{{(/|\\\\)}}[[APPENDEDSRC:.+\.cpp]]"
// FOOTER_PATH: clang{{.*}} "-x" "c++" "dummy_dir{{(/|\\\\)}}[[APPENDEDSRC]]"