Skip to content

Commit a041bda

Browse files
committed
[Driver][SYCL] Generalize huge device code linking support
Deprecate -fsycl-link-huge-device-code in favor of a new option, -flink-huge-device-code. The new option is identical in functionality but allowed with -fopenmp-targets. This also includes a minor improvement to deprecated handling in order to allow aliasing driver options to be deprecated independently.
1 parent b3e0428 commit a041bda

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,12 +3051,18 @@ defm sycl_instrument_device_code
30513051
BothFlags<[CC1Option, CoreOption], " Instrumentation and Tracing "
30523052
"Technology (ITT) instrumentation intrinsics calls "
30533053
"(experimental)">>;
3054-
def fsycl_link_huge_device_code : Flag<["-"], "fsycl-link-huge-device-code">,
3055-
Group<sycl_Group>, HelpText<"Generate and use a custom linker script for huge"
3054+
def flink_huge_device_code : Flag<["-"], "flink-huge-device-code">,
3055+
Group<Link_Group>, HelpText<"Generate and use a custom linker script for huge"
30563056
" device code sections">;
3057-
def fno_sycl_link_huge_device_code : Flag<["-"], "fno-sycl-link-huge-device-code">,
3058-
Group<sycl_Group>, HelpText<"Do not generate or use a custom linker script"
3057+
def fno_link_huge_device_code : Flag<["-"], "fno-link-huge-device-code">,
3058+
Group<Link_Group>, HelpText<"Do not generate or use a custom linker script"
30593059
" for huge device code sections (default)">;
3060+
def fsycl_link_huge_device_code : Flag<["-"], "fsycl-link-huge-device-code">,
3061+
Group<sycl_Group>, Alias<flink_huge_device_code>, HelpText<"Generate and use a custom linker script for huge"
3062+
" device code sections (deprecated)">, Flags<[Deprecated]>;
3063+
def fno_sycl_link_huge_device_code : Flag<["-"], "fno-sycl-link-huge-device-code">,
3064+
Group<sycl_Group>, Alias<fno_link_huge_device_code>, HelpText<"Do not generate or use a custom linker script"
3065+
" for huge device code sections (default) (deprecated)">, Flags<[Deprecated]>;
30603066
defm sycl_id_queries_fit_in_int: BoolFOption<"sycl-id-queries-fit-in-int",
30613067
LangOpts<"SYCLValueFitInMaxInt">, DefaultTrue,
30623068
PosFlag<SetTrue, [], "Assume">, NegFlag<SetFalse, [], "Do not assume">,

clang/lib/Driver/Driver.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,14 @@ InputArgList Driver::ParseArgStrings(ArrayRef<const char *> ArgStrings,
308308
}
309309

310310
// Deprecated options emit a diagnostic about deprecation, but are still
311-
// supported until removed.
312-
if (A->getOption().hasFlag(options::Deprecated)) {
313-
Diag(diag::warn_drv_deprecated_option_release) << A->getAsString(Args);
311+
// supported until removed. It's possible to have a deprecated option which
312+
// aliases with a non-deprecated option, so always compute the argument
313+
// actually used before checking for deprecation.
314+
const Arg *Used = A;
315+
while (Used->getAlias())
316+
Used = Used->getAlias();
317+
if (Used->getOption().hasFlag(options::Deprecated)) {
318+
Diag(diag::warn_drv_deprecated_option_release) << Used->getAsString(Args);
314319
ContainsError |= Diags.getDiagnosticLevel(
315320
diag::warn_drv_deprecated_option_release,
316321
SourceLocation()) > DiagnosticsEngine::Warning;

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,9 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
673673

674674
// If requested, use a custom linker script to handle very large device code
675675
// sections.
676-
if (Args.hasArg(options::OPT_fsycl) &&
677-
Args.hasFlag(options::OPT_fsycl_link_huge_device_code,
678-
options::OPT_fno_sycl_link_huge_device_code, false)) {
676+
if (Args.hasArg(options::OPT_fsycl, options::OPT_fopenmp_targets_EQ) &&
677+
Args.hasFlag(options::OPT_flink_huge_device_code,
678+
options::OPT_fno_link_huge_device_code, false)) {
679679
// Create temporary linker script. Keep it if save-temps is enabled.
680680
const char *LKS;
681681
SmallString<256> Name = llvm::sys::path::filename(Output.getFilename());
@@ -704,12 +704,12 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
704704
ScriptOS
705705
<< "/*\n"
706706
" * This linker script allows huge (>3GB) device code\n"
707-
" * sections. It has been auto-generated by the SYCL driver.\n"
707+
" * sections. It has been auto-generated by the driver.\n"
708708
" */\n"
709709
"SECTIONS\n"
710710
"{\n"
711-
" . = SEGMENT_START(\"sycl-device-code\", .);\n"
712-
" SYCL_DEVICE_CODE ALIGN(CONSTANT (MAXPAGESIZE)) + (. & "
711+
" . = SEGMENT_START(\"offload-device-code\", .);\n"
712+
" OFFLOAD_DEVICE_CODE ALIGN(CONSTANT (MAXPAGESIZE)) + (. & "
713713
"(CONSTANT (MAXPAGESIZE) - 1)) :\n"
714714
" {\n"
715715
" *(__CLANG_OFFLOAD_BUNDLE__*)\n"

clang/test/Driver/sycl-deprecated.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/// Test for any deprecated options
22
// RUN: %clangxx -fsycl-explicit-simd %s -### 2>&1 | FileCheck %s -DOPTION=-fsycl-explicit-simd
33
// RUN: %clangxx -fno-sycl-explicit-simd %s -### 2>&1 | FileCheck %s -DOPTION=-fno-sycl-explicit-simd
4+
// RUN: %clangxx -fsycl -fsycl-link-huge-device-code %s -### 2>&1 | FileCheck %s -DOPTION=-fsycl-link-huge-device-code
5+
// RUN: %clangxx -fsycl -fno-sycl-link-huge-device-code %s -### 2>&1 | FileCheck %s -DOPTION=-fno-sycl-link-huge-device-code
46
// CHECK: option '[[OPTION]]' is deprecated and will be removed in a future release
57

68
// RUN: %clangxx -fsycl -sycl-std=1.2.1 %s -### 2>&1 \

clang/test/Driver/sycl-huge-device-code-linker-script.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33

44
// RUN: %clangxx -### -fsycl -fsycl-link-huge-device-code %s 2>&1 | \
55
// RUN: FileCheck --check-prefix=CHECK-LINKER-SCRIPT %s
6+
// RUN: %clangxx -### -fopenmp -fopenmp-targets=x86_64 -flink-huge-device-code %s 2>&1 | \
7+
// RUN: FileCheck --check-prefix=CHECK-LINKER-SCRIPT %s
68
// CHECK-LINKER-SCRIPT: "-T" "{{.*}}.ld"
79

810
// Also check that a user-provided linker script may be used:
911
// RUN: %clangxx -### -fsycl -fsycl-link-huge-device-code %s \
1012
// RUN: -T custom-user-script.ld 2>&1 | \
1113
// RUN: FileCheck --check-prefixes=CHECK-USER-SCRIPT %s
14+
// RUN: %clangxx -### -fopenmp -fopenmp-targets=x86_64 %s \
15+
// RUN: -T custom-user-script.ld 2>&1 | \
16+
// RUN: FileCheck --check-prefixes=CHECK-USER-SCRIPT %s
1217
// CHECK-USER-SCRIPT: "-T" "custom-user-script.ld"

sycl/doc/UsersManual.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,14 @@ and not recommended to use in production environment.
285285
various events inside JIT generated kernels. These device libraries are
286286
linked in by default.
287287

288-
**`-f[no-]sycl-link-huge-device-code`**
288+
**`-f[no-]sycl-link-huge-device-code`** [DEPRECATED]
289289

290290
Place device code later in the linked binary in order to avoid precluding
291291
32-bit PC relative relocations between surrounding ELF sections when device
292292
code is larger than 2GiB. This is disabled by default.
293293

294+
Deprecated in favor of `-f[no-]link-huge-device-code`.
295+
294296
NOTE: This option is currently only supported on Linux.
295297

296298
**`-fsycl-force-target=<T>`**

0 commit comments

Comments
 (0)