Skip to content

Commit 4b62aea

Browse files
[SYCL][Driver] Update -fsycl-dump-device-code option name. (#18908)
This PR deprecates the usage of `-fsycl-dump-device-code` option, making this option backend-agnostic, extending its functionality beyond just SYCL to include OpenMP and other offloading models in the future, with the new option name: `-save-offload-code=/path/to/offload/code/`(Linux) and `-(or)/Qsave-offload-code=/path/to/offload/code/` (Windows) A diagnostic warning is emitted when `-fsycl-dump-device-code` option is passed to the Clang driver. Example: ``` clang++ -fsycl -fsycl-dump-device-code= syclfile.cpp clang++: warning: option '-fsycl-dump-device-code=' is deprecated and will be removed in a future release, use '-save-offload-code=' instead [-Wdeprecated] ``` --------- Co-authored-by: Alexey Bader <[email protected]>
1 parent fdaac35 commit 4b62aea

File tree

15 files changed

+131
-106
lines changed

15 files changed

+131
-106
lines changed

clang/include/clang/Driver/Driver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class Driver {
101101

102102
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
103103

104-
bool DumpDeviceCode;
104+
bool SaveOffloadCode;
105105

106106
enum DriverMode {
107107
GCCMode,
@@ -453,7 +453,7 @@ class Driver {
453453
return ClangExecutable.c_str();
454454
}
455455

456-
bool isDumpDeviceCodeEnabled() const { return DumpDeviceCode; }
456+
bool isSaveOffloadCodeEnabled() const { return SaveOffloadCode; }
457457

458458
bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; }
459459
bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; }

clang/include/clang/Driver/Options.td

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7348,9 +7348,14 @@ defm sycl_allow_device_image_dependencies: BoolOptionWithoutMarshalling<"f", "sy
73487348
PosFlag<SetTrue, [], [ClangOption], "Allow dependencies between device code images">,
73497349
NegFlag<SetFalse, [], [ClangOption], "Do not allow dependencies between device code images (default)">>;
73507350

7351-
def fsycl_dump_device_code_EQ : Joined<["-"], "fsycl-dump-device-code=">,
7351+
def save_offload_code_EQ : Joined<["-"], "save-offload-code=">,
73527352
Flags<[NoXarchOption]>,
7353-
HelpText<"Dump device code into the user provided directory.">;
7353+
Visibility<[ClangOption]>,
7354+
HelpText<"Save offload code generated during compilation into the user provided directory.">;
7355+
def fsycl_dump_device_code_EQ : Joined<["-"], "fsycl-dump-device-code=">,
7356+
Alias<save_offload_code_EQ>,
7357+
Flags<[NoXarchOption, Deprecated]>,
7358+
HelpText<"Dump device code into the user provided directory. (deprecated)">;
73547359
def fsyclbin_EQ : Joined<["-"], "fsyclbin=">, Values<"executable,object,input">,
73557360
HelpText<"Output in the SYCLBIN binary format in the state specified by <arg> (input, object or executable (default))">;
73567361
def fsyclbin : Flag<["-"], "fsyclbin">, Alias<fsyclbin_EQ>,
@@ -9586,6 +9591,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
95869591
Alias<_SLASH_winsdkversion>;
95879592
def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
95889593
Alias<_SLASH_winsysroot>;
9594+
def _SLASH_Qsave_offload_code : CLJoined<"Qsave-offload-code=">, Alias<save_offload_code_EQ>,
9595+
HelpText<"Save offload code generated during compilation into the user provided directory.">;
95899596

95909597
// Ignored:
95919598

clang/lib/Driver/Compilation.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ bool Compilation::CleanupFile(const char *File, bool IssueErrors) const {
182182
// able to remove), or non-regular files. Underlying tools may have
183183
// intentionally not overwritten them.
184184

185-
// Save the device code files if -fsycl-dump-device-code option is enabled.
186-
if (TheDriver.isDumpDeviceCodeEnabled()) {
187-
Arg *DumpDeviceCodeArg =
188-
getArgs().getLastArg(options::OPT_fsycl_dump_device_code_EQ);
185+
// Save the device code files if -save-offload-code option is enabled.
186+
if (TheDriver.isSaveOffloadCodeEnabled()) {
187+
Arg *SaveOffloadCodeArg =
188+
getArgs().getLastArg(options::OPT_save_offload_code_EQ);
189189
std::string ExpectedDir =
190-
DumpDeviceCodeArg ? DumpDeviceCodeArg->getValue() : "";
190+
SaveOffloadCodeArg ? SaveOffloadCodeArg->getValue() : "";
191191
std::string ActualFile(File);
192192

193193
if (ActualFile.find(ExpectedDir) != std::string::npos) {

clang/lib/Driver/Driver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ std::string CUIDOptions::getCUID(StringRef InputFile,
245245
Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
246246
DiagnosticsEngine &Diags, std::string Title,
247247
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
248-
: Diags(Diags), VFS(std::move(VFS)), DumpDeviceCode(false), Mode(GCCMode),
248+
: Diags(Diags), VFS(std::move(VFS)), SaveOffloadCode(false), Mode(GCCMode),
249249
SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone),
250250
Offload(OffloadHostDevice), CXX20HeaderType(HeaderMode_None),
251251
ModulesModeCXX20(false), LTOMode(LTOK_None), OffloadLTOMode(LTOK_None),
@@ -2099,8 +2099,8 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
20992099
.Default(SaveTempsCwd);
21002100
}
21012101

2102-
if (Args.getLastArg(options::OPT_fsycl_dump_device_code_EQ))
2103-
DumpDeviceCode = true;
2102+
if (Args.getLastArg(options::OPT_save_offload_code_EQ))
2103+
SaveOffloadCode = true;
21042104

21052105
if (const Arg *A = Args.getLastArg(
21062106
options::OPT_offload_host_only, options::OPT_offload_device_only,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10755,15 +10755,15 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
1075510755
TCArgs.MakeArgString("--out-file-list=" + OutputFileName));
1075610756
ForeachArgs.push_back(
1075710757
TCArgs.MakeArgString("--out-replace=" + OutputFileName));
10758-
// If fsycl-dump-device-code is passed, put the output files from llvm-spirv
10759-
// into the path provided in fsycl-dump-device-code.
10760-
if (C.getDriver().isDumpDeviceCodeEnabled()) {
10758+
// If save-offload-code is passed, put the output files from llvm-spirv
10759+
// into the path provided in save-offload-code.
10760+
if (C.getDriver().isSaveOffloadCodeEnabled()) {
1076110761
SmallString<128> OutputDir;
1076210762

10763-
Arg *DumpDeviceCodeArg =
10764-
C.getArgs().getLastArg(options::OPT_fsycl_dump_device_code_EQ);
10763+
Arg *SaveOffloadCodeArg =
10764+
C.getArgs().getLastArg(options::OPT_save_offload_code_EQ);
1076510765

10766-
OutputDir = (DumpDeviceCodeArg ? DumpDeviceCodeArg->getValue() : "");
10766+
OutputDir = (SaveOffloadCodeArg ? SaveOffloadCodeArg->getValue() : "");
1076710767

1076810768
// If the output directory path is empty, put the llvm-spirv output in the
1076910769
// current directory.
@@ -11417,9 +11417,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1141711417
CmdArgs.push_back(Args.MakeArgString(
1141811418
Twine("-sycl-device-library-location=") + DeviceLibDir));
1141911419

11420-
if (C.getDriver().isDumpDeviceCodeEnabled()) {
11420+
if (C.getDriver().isSaveOffloadCodeEnabled()) {
1142111421
SmallString<128> DumpDir;
11422-
Arg *A = C.getArgs().getLastArg(options::OPT_fsycl_dump_device_code_EQ);
11422+
Arg *A = C.getArgs().getLastArg(options::OPT_save_offload_code_EQ);
1142311423
DumpDir = A ? A->getValue() : "";
1142411424
CmdArgs.push_back(
1142511425
Args.MakeArgString(Twine("-sycl-dump-device-code=") + DumpDir));

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,16 @@ void SYCL::constructLLVMForeachCommand(Compilation &C, const JobAction &JA,
248248
C.getArgs().MakeArgString("--out-dir=" + OutputDirName));
249249
}
250250

251-
// If fsycl-dump-device-code is passed, put the PTX files
252-
// into the path provided in fsycl-dump-device-code.
251+
// If save-offload-code is passed, put the PTX files
252+
// into the path provided in save-offload-code.
253253
if (T->getToolChain().getTriple().isNVPTX() &&
254-
C.getDriver().isDumpDeviceCodeEnabled() && Ext == "s") {
254+
C.getDriver().isSaveOffloadCodeEnabled() && Ext == "s") {
255255
SmallString<128> OutputDir;
256256

257-
Arg *DumpDeviceCodeArg =
258-
C.getArgs().getLastArg(options::OPT_fsycl_dump_device_code_EQ);
257+
Arg *SaveOffloadCodeArg =
258+
C.getArgs().getLastArg(options::OPT_save_offload_code_EQ);
259259

260-
OutputDir = (DumpDeviceCodeArg ? DumpDeviceCodeArg->getValue() : "");
260+
OutputDir = (SaveOffloadCodeArg ? SaveOffloadCodeArg->getValue() : "");
261261

262262
// If the output directory path is empty, put the PTX files in the
263263
// current directory.

clang/test/Driver/save-ptx-files.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
// Save PTX files during PTX target processing using -fsycl-dump-device-code option.
1+
// Save PTX files during PTX target processing using -save-offload-code option.
22

3-
// Verify that -fsycl-dump-device-code saves PTX files in the user provided directory
3+
// Verify that -save-offload-code saves PTX files in the user provided directory
44
// while targeting CUDA enabled GPUs.
55

66
// Linux
7-
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda,spir64-unknown-unknown -target x86_64-unknown-linux-gnu --cuda-path=%S/Inputs/CUDA/usr/local/cuda -fsycl-dump-device-code=/user/input/path %s 2>&1 \
7+
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda,spir64-unknown-unknown -target x86_64-unknown-linux-gnu --cuda-path=%S/Inputs/CUDA/usr/local/cuda -save-offload-code=/user/input/path %s 2>&1 \
88
// RUN: | FileCheck %s --check-prefixes=CHECK-PTX-FILES,CHECK-SPIRV-FILES
99

1010
// clang --driver-mode=g++
11-
// RUN: %clangxx -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda -target x86_64-unknown-linux-gnu --cuda-path=%S/Inputs/CUDA/usr/local/cuda -fsycl-dump-device-code=/user/input/path %s 2>&1 \
11+
// RUN: %clangxx -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda -target x86_64-unknown-linux-gnu --cuda-path=%S/Inputs/CUDA/usr/local/cuda -save-offload-code=/user/input/path %s 2>&1 \
1212
// RUN: | FileCheck %s --check-prefixes=CHECK-PTX-FILES
1313

14-
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda,spir64-unknown-unknown -target x86_64-unknown-linux-gnu --cuda-path=%S/Inputs/CUDA/usr/local/cuda -fsycl-dump-device-code= %s 2>&1 \
14+
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda,spir64-unknown-unknown -target x86_64-unknown-linux-gnu --cuda-path=%S/Inputs/CUDA/usr/local/cuda -save-offload-code= %s 2>&1 \
1515
// RUN: | FileCheck %s --check-prefixes=CHECK-PTX-FILES-CWD,CHECK-SPIRV-FILES-CWD
1616

1717
// CHECK-PTX-FILES: llvm-foreach{{.*}} "--out-ext=s"{{.*}} "--out-dir=/user/input/path{{(/|\\\\)}}" "--" "{{.*}}clang{{.*}}" {{.*}} "-fsycl-is-device" {{.*}}.s{{.*}}
@@ -22,20 +22,20 @@
2222
// Windows - Check if PTX files are saved in the user provided path.
2323
// RUN: %clang_cl -### -fsycl \
2424
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
25-
// RUN: -fsycl-dump-device-code=/user/input/path %s 2>&1 \
25+
// RUN: -Qsave-offload-code=/user/input/path %s 2>&1 \
2626
// RUN: | FileCheck -check-prefix=CHECK-PTX-WIN %s
2727

2828
// Windows - Check if PTX and SPV files are saved in user provided path.
2929
// RUN: %clang_cl -### -fsycl \
3030
// RUN: -fsycl-targets=nvptx64-nvidia-cuda,spir64-unknown-unknown --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
31-
// RUN: -fsycl-dump-device-code=/user/input/path %s 2>&1 \
31+
// RUN: -Qsave-offload-code=/user/input/path %s 2>&1 \
3232
// RUN: | FileCheck -check-prefixes=CHECK-PTX-WIN,CHECK-SPV-WIN %s
3333

34-
// Windows - Check PTX files saved in current working directory when -fsycl-dump-device-code
34+
// Windows - Check PTX files saved in current working directory when -save-offload-code
3535
// is empty.
3636
// RUN: %clang_cl -### -fsycl \
3737
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
38-
// RUN: -fsycl-dump-device-code= %s 2>&1 \
38+
// RUN: -Qsave-offload-code= %s 2>&1 \
3939
// RUN: | FileCheck -check-prefix=CHECK-PTX-WIN-CWD %s
4040

4141
// CHECK-PTX-WIN: llvm-foreach{{.*}} "--out-ext=s"{{.*}} "--out-dir=/user/input/path{{(/|\\\\)}}" "--" "{{.*}}clang{{.*}}" {{.*}} "-fsycl-is-device" {{.*}}.asm{{.*}}

clang/test/Driver/sycl-deprecated.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
// RUN: %clangxx -fsycl -fno-sycl-use-bitcode %s -### 2>&1 \
1111
// RUN: | FileCheck %s --check-prefix=CHECK_REPLACE -DOPTION=-fno-sycl-use-bitcode -DOPTION_REPLACE=-fsycl-device-obj=spirv
1212
// RUN: %clangxx -fsycl -fsycl-fp32-prec-sqrt %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_REPLACE -DOPTION=-fsycl-fp32-prec-sqrt -DOPTION_REPLACE=-foffload-fp32-prec-sqrt
13+
// RUN: %clangxx -fsycl -fsycl-dump-device-code=/path/to/spv/ %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_REPLACE -DOPTION=-fsycl-dump-device-code=/path/to/spv/ -DOPTION_REPLACE=-save-offload-code=/path/to/spv/
1314
// CHECK_REPLACE: option '[[OPTION]]' is deprecated and will be removed in a future release, use '[[OPTION_REPLACE]]' instead

clang/test/Driver/sycl-dump-device-code-old-model.cpp

Lines changed: 0 additions & 35 deletions
This file was deleted.

clang/test/Driver/sycl-dump-device-code.cpp

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SYCL offloading tests using -save-offload-code
2+
3+
// Verify that -save-offload-code puts the device code (.spv files)
4+
// in the user provided directory.
5+
6+
// Linux
7+
// clang -fsycl --no-offload-new-driver -target x86_64-unknown-linux-gnu
8+
// RUN: %clang -fsycl --no-offload-new-driver -fno-sycl-instrument-device-code -fno-sycl-device-lib=all -target x86_64-unknown-linux-gnu -save-offload-code=/user/input/path %s -### 2>&1 \
9+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code
10+
11+
// clang -fsycl --no-offload-new-driver -fsycl-targets=spir64-unknown-unknown
12+
// RUN: %clang -fsycl --no-offload-new-driver -fsycl-targets=spir64-unknown-unknown -target x86_64-unknown-linux-gnu -save-offload-code=/user/input/path %s -### 2>&1 \
13+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code
14+
15+
// clang --driver-mode=g++
16+
// RUN: %clangxx -fsycl --no-offload-new-driver -fsycl-targets=spir64-unknown-unknown -target x86_64-unknown-linux-gnu -save-offload-code=/user/input/path %s -### 2>&1 \
17+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code
18+
19+
// Windows
20+
// RUN: %clang_cl -fsycl --no-offload-new-driver -Qsave-offload-code=/user/input/path %s -### 2>&1 \
21+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code-WIN
22+
23+
// CHK-save-offload-code: llvm-foreach{{.*}} "--out-dir=/user/input/path{{(/|\\\\)}}" "--" "{{.*}}llvm-spirv"
24+
// CHK-save-offload-code-WIN: llvm-foreach{{.*}} "--out-dir=/user/input/path{{(/|\\\\)}}" "--" "{{.*}}llvm-spirv"
25+
26+
// Linux
27+
// RUN: %clang -fsycl --no-offload-new-driver -fsycl-targets=spir64-unknown-unknown -target x86_64-unknown-linux-gnu -save-offload-code= %s -### 2>&1 \
28+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code-CWD
29+
30+
// Windows
31+
// RUN: %clang_cl -fsycl --no-offload-new-driver -Qsave-offload-code= %s -### 2>&1 \
32+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code-WIN-CWD
33+
34+
// CHK-save-offload-code-CWD: llvm-foreach{{.*}} "--out-dir=.{{(/|\\\\)}}" "--" "{{.*}}llvm-spirv"
35+
// CHK-save-offload-code-WIN-CWD: llvm-foreach{{.*}} "--out-dir=.{{(/|\\\\)}}" "--" "{{.*}}llvm-spirv"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SYCL offloading tests using -save-offload-code
2+
3+
// Verify that -save-offload-code passes the option to
4+
// clang-linker-wrapper in the new offload model.
5+
6+
// clang -fsycl --offload-new-driver -target x86_64-unknown-linux-gnu
7+
// RUN: %clang -fsycl --offload-new-driver -fno-sycl-instrument-device-code -fno-sycl-device-lib=all -target x86_64-unknown-linux-gnu -save-offload-code=/user/input/path %s -### 2>&1 \
8+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code-NEW-OFFLOAD
9+
10+
// clang -fsycl --offload-new-driver -fsycl-targets=spir64-unknown-unknown
11+
// RUN: %clang -fsycl --offload-new-driver -fsycl-targets=spir64-unknown-unknown -target x86_64-unknown-linux-gnu -save-offload-code=/user/input/path %s -### 2>&1 \
12+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code-NEW-OFFLOAD
13+
14+
// clang --driver-mode=g++
15+
// RUN: %clangxx -fsycl --offload-new-driver -fsycl-targets=spir64-unknown-unknown -target x86_64-unknown-linux-gnu -save-offload-code=/user/input/path %s -### 2>&1 \
16+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code-NEW-OFFLOAD
17+
18+
// Windows
19+
// RUN: %clang_cl -fsycl --offload-new-driver -Qsave-offload-code=/user/input/path %s -### 2>&1 \
20+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code-WIN-NEW-OFFLOAD
21+
22+
// CHK-save-offload-code-NEW-OFFLOAD: clang-linker-wrapper{{.*}} "-sycl-dump-device-code=/user/input/path"
23+
// CHK-save-offload-code-WIN-NEW-OFFLOAD: clang-linker-wrapper{{.*}} "-sycl-dump-device-code=/user/input/path"
24+
25+
// Linux
26+
// RUN: %clang -fsycl --offload-new-driver -fsycl-targets=spir64-unknown-unknown -target x86_64-unknown-linux-gnu -save-offload-code= %s -### 2>&1 \
27+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code-CWD-NEW-OFFLOAD
28+
29+
// Windows
30+
// RUN: %clang_cl -fsycl --offload-new-driver -Qsave-offload-code= %s -### 2>&1 \
31+
// RUN: | FileCheck %s --check-prefixes=CHK-save-offload-code-WIN-CWD-NEW-OFFLOAD
32+
33+
// CHK-save-offload-code-CWD-NEW-OFFLOAD: clang-linker-wrapper{{.*}} "-sycl-dump-device-code="
34+
// CHK-save-offload-code-WIN-CWD-NEW-OFFLOAD: clang-linker-wrapper{{.*}} "-sycl-dump-device-code="

0 commit comments

Comments
 (0)