Skip to content

[Driver][SYCL] Add support for exporting symbols for AOT #9991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 28, 2023
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
5 changes: 5 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -3131,6 +3131,11 @@ def fsycl_max_parallel_jobs_EQ : Joined<["-"], "fsycl-max-parallel-link-jobs=">,
def ftarget_compile_fast : Flag<["-"], "ftarget-compile-fast">,
Flags<[CoreOption]>, HelpText<"Experimental feature: Reduce target "
"compilation time, with potential runtime performance trade-off.">;
def ftarget_export_symbols : Flag<["-"], "ftarget-export-symbols">,
Flags<[CoreOption]>, HelpText<"Expose exported symbols in a generated "
"target library to allow for visibilty to other modules.">;
def fno_target_export_symbols : Flag<["-"], "fno-target-export-symbols">,
Flags<[CoreOption]>;
def : Flag<["-"], "fsycl-rdc">, Flags<[CoreOption]>, Alias<fgpu_rdc>;
def : Flag<["-"], "fno-sycl-rdc">, Flags<[CoreOption]>, Alias<fno_gpu_rdc>;
def fsycl_optimize_non_user_code : Flag<["-"], "fsycl-optimize-non-user-code">,
Expand Down
7 changes: 5 additions & 2 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,9 +991,12 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
CmdArgs.push_back(Args.MakeArgString(DepInfo));
}
// -ftarget-compile-fast AOT
if (Args.hasArg(options::OPT_ftarget_compile_fast)) {
if (Args.hasArg(options::OPT_ftarget_compile_fast))
BeArgs.push_back("-igc_opts 'PartitionUnit=1,SubroutineThreshold=50000'");
}
// -ftarget-export-symbols
if (Args.hasFlag(options::OPT_ftarget_export_symbols,
options::OPT_fno_target_export_symbols, false))
BeArgs.push_back("-library-compilation");
} else if (Triple.getSubArch() == llvm::Triple::NoSubArch &&
Triple.isSPIR()) {
// -ftarget-compile-fast JIT
Expand Down
29 changes: 29 additions & 0 deletions clang/test/Driver/ftarget-export-symbols.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Test -ftarget-export-symbols behavior

// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl \
// RUN: -fsycl-targets=spir64_gen -ftarget-export-symbols %s 2>&1 \
// RUN: | FileCheck -check-prefix=TARGET_EXPORT %s
// RUN: %clang_cl -### --target=x86_64-pc-windows-msvc -fsycl \
// RUN: -fsycl-targets=spir64_gen -ftarget-export-symbols %s 2>&1 \
// RUN: | FileCheck -check-prefix=TARGET_EXPORT %s
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl \
// RUN: -fsycl-targets=spir64_gen -ftarget-export-symbols \
// RUN: -fno-target-export-symbols %s 2>&1 \
// RUN: | FileCheck -check-prefix=NO_TARGET_EXPORT %s

// TARGET_EXPORT: ocloc{{.*}} "-output"
// TARGET_EXPORT: "-options" "-library-compilation"
// NO_TARGET_EXPORT-NOT: "-library-compilation"

// 'unused' for non-spir64_gen targets
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl \
// RUN: -fsycl-targets=spir64 -ftarget-export-symbols %s 2>&1 \
// RUN: | FileCheck -check-prefix=UNUSED %s
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl \
// RUN: -fsycl-targets=spir64_x86_64 -ftarget-export-symbols %s 2>&1 \
// RUN: | FileCheck -check-prefix=UNUSED %s
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl \
// RUN: -fsycl-targets=spir64_fpga -ftarget-export-symbols %s 2>&1 \
// RUN: | FileCheck -check-prefix=UNUSED %s

// UNUSED: argument unused during compilation: '-ftarget-export-symbols'
7 changes: 7 additions & 0 deletions sycl/doc/UsersManual.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ and not recommended to use in production environment.
Instructs the target backend to reduce compilation time, potentially
at the cost of runtime performance. Currently only supported on Intel GPUs.

**`-f[no-]target-export-symbols`**

Exposes exported symbols in a generated target library to allow for
visibility to other modules.

NOTE: This flag is only supported for spir64_gen AOT targets.

# Example: SYCL device code compilation

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