Skip to content

[SYCL] Add option forwarding from clang-linker-wrapper tool to clang-sycl-linker #21958

Open
srividya-sundaram wants to merge 4 commits into
intel:syclfrom
srividya-sundaram:clw-to-csl
Open

[SYCL] Add option forwarding from clang-linker-wrapper tool to clang-sycl-linker #21958
srividya-sundaram wants to merge 4 commits into
intel:syclfrom
srividya-sundaram:clw-to-csl

Conversation

@srividya-sundaram
Copy link
Copy Markdown
Contributor

@srividya-sundaram srividya-sundaram commented May 7, 2026

This is the first patch in a series that moves SYCL device code linking logic from clang-linker-wrapper into the clang-sycl-linker tool.
I’m continuing the work from where Yixing left off.

At the moment, the tests only verify that the options are forwarded to clang-linker-wrapper.
Tests validating clang-sycl-linker invocations will be added in subsequent PRs.

Added infrastructure from PR 21692 + tests for option forwarding.

@srividya-sundaram srividya-sundaram marked this pull request as ready for review May 8, 2026 00:27
@srividya-sundaram srividya-sundaram requested review from a team as code owners May 8, 2026 00:27
Comment thread clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
@maksimsab
Copy link
Copy Markdown
Contributor

More general comment.
I see that your PR targets 2 independent goals:

  • Add option forwarding
  • Remove deprecated device library options

In cases like that the suggested approach is:

The patch should:
* be an isolated change. Independent changes should be submitted as separate patches as this makes reviewing easier.

https://llvm.org/docs/Contributing.html#how-to-submit-a-patch

Please, use this approach in your patches.

Copy link
Copy Markdown
Contributor

@YuriPlyakhin YuriPlyakhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please update title?

@srividya-sundaram srividya-sundaram changed the title [SYCL] Add option forwarding and remove deprecated device library options [SYCL] Add option forwarding from clang linker wrapper to clang sycl linker May 8, 2026
@srividya-sundaram srividya-sundaram changed the title [SYCL] Add option forwarding from clang linker wrapper to clang sycl linker [SYCL] Add option forwarding from clang-linker-wrapper tool to clang-sycl-linker May 8, 2026
Comment thread clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Comment thread clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Comment thread clang/test/Driver/clang-sycl-linker-test.cpp Outdated
Comment thread clang/test/Driver/clang-sycl-linker-test.cpp Outdated
Comment thread clang/test/Driver/clang-sycl-linker-test.cpp Outdated
Comment thread clang/test/Driver/clang-sycl-linker-test.cpp Outdated
@@ -0,0 +1,42 @@
// Test that clang-linker-wrapper correctly invokes clang-sycl-linker when --use-clang-sycl-linker is enabled
Copy link
Copy Markdown
Contributor

@YuriPlyakhin YuriPlyakhin May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test looks similiar to the one I see in community: https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/linker-wrapper.c

Other similar tests that are programming-model or target specific:

https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/linker-wrapper-hip-amdgcnspirv.c

https://github.com/llvm/llvm-project/blob/e721580311e3988e767ec3aaa06bce025f72ff7e/clang/test/Driver/hipspv-toolchain.hip#L55

Do you think it would be possible to add test like you wrote here to community first aligned with naming and style? (like linker-wrapper-sycl.cpp), and then add modifications in downstream on top of what is in upstream?

I want to minimize our back-and-forth between downstream and community and submit to community first if that makes sense.

// REQUIRES: spirv-registered-target
//
// Test the dry run of a simple case to link two input files.
// Create bitcode files for clang-sycl-linker direct tests
Copy link
Copy Markdown
Contributor

@YuriPlyakhin YuriPlyakhin May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm moving this test to Tooling in community, pls, see here: llvm/llvm-project#197566
I think it might make sense to wait while this patch lands, before modifying it in downstream.

Also, I'd prefer to minimize updating comments like this. Original comment explains the test case, not sure why it was removed.

Upd: after I reviewed modifications to entire file, I think this current file should not be modified at all, and instead all additional tests should be added as a new driver test file. Current test is testing clang-sycl-linker, you want to add clang driver test.

// Create bitcode files for clang-sycl-linker direct tests
// RUN: %clangxx -emit-llvm -c -target spirv64 %s -o %t_1.bc
// RUN: %clangxx -emit-llvm -c -target spirv64 %s -o %t_2.bc
// Create SYCL offload object files for driver tests
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep this test as clang-sycl-linker test and driver tests should be added separately.

// RUN: | FileCheck %s --check-prefix=NOTARGET
// NOTARGET: Target triple must be specified
//
// Test that driver options are correctly passed through clang-linker-wrapper.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// CHECK-DEFAULT: clang-linker-wrapper
// CHECK-DEFAULT-NOT: "--use-clang-sycl-linker"
//
// Test that --use-clang-sycl-linker flag is passed through
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems some tests in this file duplicate tests in previous file. For example what this test is testing differently comparing to the one in clang/test/Driver/clang-sycl-linker-test.cpp line 123

I think there are some other duplications as well


Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
bool IsSYCLKind = false) {
uint16_t ActiveOffloadKindMask = 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to avoid divergence like this with the community code? In upstream, ActiveOffloadKindMask is not a default parameter. Is there a strong reason to make it a default parameter in this code base?
I checked in all calls to clang in this file, we anyway pass this param explicitly.

// Set via --use-clang-sycl-linker flag.
// TODO: Remove this flag once the linking and backend compilation have been
// fully migrated to clang-sycl-linker and make it the default behavior.
bool UseClangSYCLLinker = false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool UseClangSYCLLinker = false;
static bool UseClangSYCLLinker = false;

OPT_bitcode_library_EQ,
};
for (OptSpecifier Opt : ValueOpts) {
if (const opt::Arg *A = Args.getLastArg(Opt)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPT_bitcode_library_EQ can be provided multiple times, right? getLastArg will use only last value, so previous libraries would be dropped.

Comment on lines +1716 to +1717
OPT_sycl_remove_unused_external_funcs,
OPT_no_sycl_remove_unused_external_funcs,
Copy link
Copy Markdown
Contributor

@YuriPlyakhin YuriPlyakhin May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are using getLastArg on this array, initializing DirectOpts with both yes/no variants of the option may cause forwarding the wrong option (like yes-variant is provided last in the command line, but we are checking for no-variant in the loop last).
Should we use something like this instead?
Args.hasFlag(OPT_pos, OPT_neg, default)
or
getLastArg(OPT_pos, OPT_neg)

CmdArgs.push_back("-c");
}

if (UseClangSYCLLinker && (ActiveOffloadKindMask & OFK_SYCL)) {
Copy link
Copy Markdown
Contributor

@YuriPlyakhin YuriPlyakhin May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ordering of the code is causing nativecpu to use clang-sycl-linker. Does this pass work? Are there any tests for this?
same question for nvptx pass.

/// invocation).
/// \param Triple The target triple for the device.
/// \param Arch The target architecture (e.g., "pvc", "graniterapids").
static void appendClangSYCLLinkerArgs(const ArgList &Args,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sycl-specific function, should it be placed to sycl namespace?

}
}

static const OptSpecifier ValueOpts[] = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are all options which we are forwarding to clang-sycl-linker supported by it?

Copy link
Copy Markdown
Contributor

@YuriPlyakhin YuriPlyakhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pr needs some more work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants