Skip to content

Commit 155acd1

Browse files
authored
[Driver][SYCL] Enable way to emit int-footer source to a specific dir (#4167)
During an -fsycl enabled build, we use an integration footer during the host portion of the compilation. This requires to create a temporary file that is based on the original source file and contains the generated footer. Some build systems recognize this additional file that is being generated and is not part of any expected generated dependency. Introduce an option that allows the user to specify the location in which this new source file is created so the build system can properly track and recognize its creation. The new option is -fsycl-footer-path=<path>
1 parent dc0f7ec commit 155acd1

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,9 @@ def fsycl_host_compiler_options_EQ : Joined<["-"], "fsycl-host-compiler-options=
26412641
def fno_sycl_use_footer : Flag<["-"], "fno-sycl-use-footer">, Flags<[CoreOption]>,
26422642
HelpText<"Disable usage of the integration footer during SYCL enabled "
26432643
"compilations.">;
2644+
def fsycl_footer_path_EQ : Joined<["-"], "fsycl-footer-path=">,
2645+
Flags<[CoreOption]>, HelpText<"Specify the location of the temporary "
2646+
"source file with the included integration footer.">;
26442647
def fsyntax_only : Flag<["-"], "fsyntax-only">,
26452648
Flags<[NoXarchOption,CoreOption,CC1Option,FC1Option]>, Group<Action_Group>;
26462649
def ftabstop_EQ : Joined<["-"], "ftabstop=">, Group<f_Group>;

clang/lib/Driver/Driver.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6752,6 +6752,32 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
67526752
&JA);
67536753
}
67546754

6755+
// Redirect output for the generated source + integration footer.
6756+
if (isa<AppendFooterJobAction>(JA)) {
6757+
if (Arg *A = C.getArgs().getLastArg(options::OPT_fsycl_footer_path_EQ)) {
6758+
SmallString<128> OutName(A->getValue());
6759+
StringRef BaseName = llvm::sys::path::filename(BaseInput);
6760+
if (isSaveTempsEnabled()) {
6761+
// Retain the location specified by the user with -save-temps.
6762+
const char *Suffix = types::getTypeTempSuffix(JA.getType());
6763+
std::string::size_type End = std::string::npos;
6764+
if (!types::appendSuffixForType(JA.getType()))
6765+
End = BaseName.rfind('.');
6766+
SmallString<128> Suffixed(BaseName.substr(0, End));
6767+
Suffixed += OffloadingPrefix;
6768+
Suffixed += '.';
6769+
Suffixed += Suffix;
6770+
llvm::sys::path::append(OutName, Suffixed.c_str());
6771+
} else {
6772+
std::string TmpName =
6773+
GetTemporaryPath(llvm::sys::path::stem(BaseName),
6774+
types::getTypeTempSuffix(JA.getType()));
6775+
llvm::sys::path::append(OutName, llvm::sys::path::filename(TmpName));
6776+
}
6777+
return C.addTempFile(C.getArgs().MakeArgString(OutName));
6778+
}
6779+
}
6780+
67556781
// Default to writing to stdout?
67566782
if (AtTopLevel && !CCGenDiagnostics && HasPreprocessOutput(JA)) {
67576783
return "-";

clang/test/Driver/sycl-int-footer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,9 @@
6060
// COMMON-PHASES: [[#OFFLOAD+9]]: file-table-tform, {[[#OFFLOAD+6]], [[#OFFLOAD+8]]}, tempfiletable, (device-sycl)
6161
// COMMON-PHASES: [[#OFFLOAD+10]]: clang-offload-wrapper, {[[#OFFLOAD+9]]}, object, (device-sycl)
6262
// COMMON-PHASES: [[#OFFLOAD+11]]: offload, "host-sycl (x86_64-{{.*}})" {[[#OFFLOAD+4]]}, "device-sycl (spir64-unknown-unknown-sycldevice)" {[[#OFFLOAD+10]]}, image
63+
64+
/// Test for -fsycl-footer-path=<dir>
65+
// RUN: %clangxx -fsycl -fsycl-footer-path=dummy_dir %s -### 2>&1 \
66+
// RUN: | FileCheck -check-prefix FOOTER_PATH %s
67+
// FOOTER_PATH: append-file{{.*}} "--output=dummy_dir{{(/|\\\\)}}[[APPENDEDSRC:.+\.cpp]]"
68+
// FOOTER_PATH: clang{{.*}} "-x" "c++" "dummy_dir{{(/|\\\\)}}[[APPENDEDSRC]]"

0 commit comments

Comments
 (0)