Skip to content

Commit c33ba5d

Browse files
authored
[Driver][SYCL] Add support for exporting symbols for AOT (#9991)
Add support for -ftarget-export-symbols. This option when used with -fsycl -fsycl-targets=spir64_gen when creating shared libraries. This exposes the exported symbols in the library so they can be available for other modules.
1 parent a2aec49 commit c33ba5d

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,6 +3137,11 @@ def fsycl_max_parallel_jobs_EQ : Joined<["-"], "fsycl-max-parallel-link-jobs=">,
31373137
def ftarget_compile_fast : Flag<["-"], "ftarget-compile-fast">,
31383138
Flags<[CoreOption]>, HelpText<"Experimental feature: Reduce target "
31393139
"compilation time, with potential runtime performance trade-off.">;
3140+
def ftarget_export_symbols : Flag<["-"], "ftarget-export-symbols">,
3141+
Flags<[CoreOption]>, HelpText<"Expose exported symbols in a generated "
3142+
"target library to allow for visibilty to other modules.">;
3143+
def fno_target_export_symbols : Flag<["-"], "fno-target-export-symbols">,
3144+
Flags<[CoreOption]>;
31403145
def : Flag<["-"], "fsycl-rdc">, Flags<[CoreOption]>, Alias<fgpu_rdc>;
31413146
def : Flag<["-"], "fno-sycl-rdc">, Flags<[CoreOption]>, Alias<fno_gpu_rdc>;
31423147
def fsycl_optimize_non_user_code : Flag<["-"], "fsycl-optimize-non-user-code">,

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,12 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
991991
CmdArgs.push_back(Args.MakeArgString(DepInfo));
992992
}
993993
// -ftarget-compile-fast AOT
994-
if (Args.hasArg(options::OPT_ftarget_compile_fast)) {
994+
if (Args.hasArg(options::OPT_ftarget_compile_fast))
995995
BeArgs.push_back("-igc_opts 'PartitionUnit=1,SubroutineThreshold=50000'");
996-
}
996+
// -ftarget-export-symbols
997+
if (Args.hasFlag(options::OPT_ftarget_export_symbols,
998+
options::OPT_fno_target_export_symbols, false))
999+
BeArgs.push_back("-library-compilation");
9971000
} else if (Triple.getSubArch() == llvm::Triple::NoSubArch &&
9981001
Triple.isSPIR()) {
9991002
// -ftarget-compile-fast JIT
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Test -ftarget-export-symbols behavior
2+
3+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl \
4+
// RUN: -fsycl-targets=spir64_gen -ftarget-export-symbols %s 2>&1 \
5+
// RUN: | FileCheck -check-prefix=TARGET_EXPORT %s
6+
// RUN: %clang_cl -### --target=x86_64-pc-windows-msvc -fsycl \
7+
// RUN: -fsycl-targets=spir64_gen -ftarget-export-symbols %s 2>&1 \
8+
// RUN: | FileCheck -check-prefix=TARGET_EXPORT %s
9+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl \
10+
// RUN: -fsycl-targets=spir64_gen -ftarget-export-symbols \
11+
// RUN: -fno-target-export-symbols %s 2>&1 \
12+
// RUN: | FileCheck -check-prefix=NO_TARGET_EXPORT %s
13+
14+
// TARGET_EXPORT: ocloc{{.*}} "-output"
15+
// TARGET_EXPORT: "-options" "-library-compilation"
16+
// NO_TARGET_EXPORT-NOT: "-library-compilation"
17+
18+
// 'unused' for non-spir64_gen targets
19+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl \
20+
// RUN: -fsycl-targets=spir64 -ftarget-export-symbols %s 2>&1 \
21+
// RUN: | FileCheck -check-prefix=UNUSED %s
22+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl \
23+
// RUN: -fsycl-targets=spir64_x86_64 -ftarget-export-symbols %s 2>&1 \
24+
// RUN: | FileCheck -check-prefix=UNUSED %s
25+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl \
26+
// RUN: -fsycl-targets=spir64_fpga -ftarget-export-symbols %s 2>&1 \
27+
// RUN: | FileCheck -check-prefix=UNUSED %s
28+
29+
// UNUSED: argument unused during compilation: '-ftarget-export-symbols'

sycl/doc/UsersManual.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,13 @@ and not recommended to use in production environment.
416416
Instructs the target backend to reduce compilation time, potentially
417417
at the cost of runtime performance. Currently only supported on Intel GPUs.
418418

419+
**`-f[no-]target-export-symbols`**
420+
421+
Exposes exported symbols in a generated target library to allow for
422+
visibility to other modules.
423+
424+
NOTE: This flag is only supported for spir64_gen AOT targets.
425+
419426
# Example: SYCL device code compilation
420427

421428
To invoke SYCL device compiler set `-fsycl-device-only` flag.

0 commit comments

Comments
 (0)