Skip to content

[NewOffloadModel] Add additional options for clang-sycl-linker#21692

Open
YixingZhang007 wants to merge 17 commits intointel:syclfrom
YixingZhang007:add_new_option_clang_sycl_linker
Open

[NewOffloadModel] Add additional options for clang-sycl-linker#21692
YixingZhang007 wants to merge 17 commits intointel:syclfrom
YixingZhang007:add_new_option_clang_sycl_linker

Conversation

@YixingZhang007
Copy link
Copy Markdown
Contributor

@YixingZhang007 YixingZhang007 commented Apr 7, 2026

This patch is part of the ongoing effort to migrate to clang-sycl-linker. It adds the support for new options required for clang-sycl-linker, where they will be used during the linking and backend compilation stages.
Specifically, the following changes are made:

  1. New options supported by clang-sycl-linker are defined in SYCLLinkOpts.td.
  2. In ClangLinkerWrapper.cpp, appendClangSYCLLinkerArgsis introduced to forward the required flags toclang-sycl-linkervia-XlinkerwhenUseClangSYCLLinkeris enabled.UseClangSYCLLinkeris a temporary guard that will be removed onceclang-sycl-linker` is fully supported.
  3. Updated to process arguments passed to clang and forward any -Xlinker arguments to clang-sycl-linker in SPIRV.cpp.

@dm-vodopyanov dm-vodopyanov changed the title [NewOffloadModel] Add additional options for clang-sycl-sinker [NewOffloadModel] Add additional options for clang-sycl-linker Apr 7, 2026
@YixingZhang007 YixingZhang007 added the new-offload-model Enables testing with NewOffloadModel. label Apr 7, 2026
@YixingZhang007 YixingZhang007 force-pushed the add_new_option_clang_sycl_linker branch from 4915195 to 81ce781 Compare April 7, 2026 14:29
@YixingZhang007 YixingZhang007 marked this pull request as ready for review April 7, 2026 14:35
@YixingZhang007 YixingZhang007 requested review from a team as code owners April 7, 2026 14:35
Comment thread clang/lib/Driver/ToolChains/SPIRV.cpp Outdated
if (A->getOption().matches(options::OPT_Xlinker)) {
CmdArgs.push_back(A->getValue());
}
}
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.

Why is this needed? I'm seeing values of -Xlinker already being passed as expected.

clang++ --sycl-link --target=spirv64 -### a.o -Xlinker -blah
Intel SYCL compiler development build based on:
clang version 23.0.0git (https://github.com/mdtoguchi/llvm accf054)
Target: spirv64
Thread model: posix
InstalledDir: /localdisk2/mtoguchi/github/llvm/build/bin
Build config: +assertions
"clang-sycl-linker" "a.o" "-blah" "-o" "a.out"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for catching this! You're right, the -xlinker option is already handled within AddLinkerInputs function. I've reverted this change :)

};
for (auto [Opt, Flag] : SimpleFlags)
if (Args.hasArg(Opt))
XLinker(Flag);
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 looks like we have a bit of duplication of option names, etc, which would lead to a maintenance issue with any option name changes or even capturing new flags that need to be forwarded.

Leveraging the Args information would be beneficial here. A new 'Group' can be added for any of these options that need to be forwarded to the clang-sycl-linker. From there, check if an Arg is part of the group and then forward with render()

for (Arg *A : Args.filtered(options::OPT_sycl_Group))
  A->render(Args, CmdArgs);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm I am not quiet sure about this because the flags passed to clang-linker-wrapper need to be handled / processed differently when they get passed to clang-sycl-linker (for example option passed into --device-libs= need to be joined by comma). In this case, there might need to be several groups created.

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.

Sure - This was more of a comment for the general case where options can be directly mapped. Exceptions can be handled differently. Instead of creating a group, just a list of the OPT_ values that do map directly to do the checking, then passing the direct render. At least this way there are less strings to manage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see! I've created two lists, DirectOpts and ValueOpts, for options that are shared between clang-linker-wrapper and clang-sycl-linker. By calling A->getOption().getName().str(), we can generate the flag names dynamically instead of hardcoding strings, so we avoid maintaining a separate list of hardcoded strings. Please feel free to let me know if anything needed to be changed. Thank you! :)

@YixingZhang007 YixingZhang007 requested a review from maksimsab April 8, 2026 13:27
Copy link
Copy Markdown
Contributor

@elizabethandrews elizabethandrews left a comment

Choose a reason for hiding this comment

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

I am not familiar with this and defer to @mdtoguchi for review and approval.


def input_file_EQ : Joined<["--", "-"], "input-file=">,
Flags<[LinkerOnlyOption]>,
HelpText<"Input bitcode file for SYCL device linking">; No newline at end of file
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.

Given the text information here - how is this option different than using --bitcode-library? The name of -input-file makes it sound like you can pass any input file and clang-sycl-linker will just know what to do with the file and it not be of any type of file format, so the option name should be more descriptive.

Copy link
Copy Markdown
Contributor Author

@YixingZhang007 YixingZhang007 Apr 13, 2026

Choose a reason for hiding this comment

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

Thanks for the suggestion. I have changed the option name to be input-bitcode-file= and add a more descriptive comment for both this option as well as --bitcode-library.

HelpText<"Output in the SYCLBIN binary format in the state specified by <arg> (input, object or executable)">;

// Options to specify SYCL device kernel bitcode input files, extracted from offload binaries.
def input_bitcode_file_EQ : Joined<["--", "-"], "input-bitcode-file=">,
Copy link
Copy Markdown
Contributor

@mdtoguchi mdtoguchi Apr 15, 2026

Choose a reason for hiding this comment

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

How are --input-bitcode-file, --bitcode-library and --device-libs used? They all seem to imply the same things.

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.

--bitcode-library and --device-libs look similar.
--input-bitcode-file looks different.

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.

Copy link
Copy Markdown
Contributor Author

@YixingZhang007 YixingZhang007 Apr 16, 2026

Choose a reason for hiding this comment

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

The --bitcode-library is the same as the --bitcode-library option being passed from clang to clang-linker-wrapper, and the --device-libs are the same as the sycl-device-libraries being passed from clang to clang-linker-wrapper.

  • --bitcode-library directly injects a raw bitcode file into the SYCL device link stage, filtered by target triple.
    --device-libs injects SYCL runtime library files by filename, resolved from a search directory passed through --library-path=, extracting the correct target's binary from fat offload containers before linking.
  • Both feed the bitcode library to the same second llvm-link step, but --bitcode-library is a simple direct path while --device-libs adds a layer of directory resolution.
    I will add comment for these two options to explain the details.

For --input-bitcode-file, I'm thinking of creating it to pass the device input files that are extracted from host fat binaries and converted from SPIR-V to LLVM IR using spirv-to-ir-wrapper. Thanks for the suggestion from Maksim, I agree that we can use the existing OPT_INPUT option and I will remove this --input-bitcode-file

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.

The use of --sycl-device-libraries should go away. We have moved to linking in the device libraries at compile time and have stopped passing --sycl-device-libraries and --sycl-device-library-location to the clang-linker-wrapper.

Copy link
Copy Markdown
Contributor

@maksimsab maksimsab left a comment

Choose a reason for hiding this comment

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

Is it possible to add testing?

@YixingZhang007
Copy link
Copy Markdown
Contributor Author

Because I will be leaving this project soon and there is limited time I can work on this PR, I think it would be better to address some of the suggested changes in the comments in a future PR and keep the current PR with the feature we have right now. There are two changes that need to be made in future PRs:

  1. Add a test to verify that options passed into clang-linker-wrapper are passed to clang-sycl-linker.
  2. Remove --sycl-device-libraries and --sycl-device-library-location from clang-linker-wrapper, and also remove --device-libs and --library-path from clang-sycl-linker (we are currently still using these options in clang-sycl-linker).

@mdtoguchi @maksimsab Please feel free to let me know if this works, and I will note it in the Jira issue as well.

@mdtoguchi
Copy link
Copy Markdown
Contributor

Because I will be leaving this project soon and there is limited time I can work on this PR, I think it would be better to address some of the suggested changes in the comments in a future PR and keep the current PR with the feature we have right now. There are two changes that need to be made in future PRs:

  1. Add a test to verify that options passed into clang-linker-wrapper are passed to clang-sycl-linker.
  2. Remove --sycl-device-libraries and --sycl-device-library-location from clang-linker-wrapper, and also remove --device-libs and --library-path from clang-sycl-linker (we are currently still using these options in clang-sycl-linker).

@mdtoguchi @maksimsab Please feel free to let me know if this works, and I will note it in the Jira issue as well.

Okay by me. One thing to note, however, is that --sycl-device-library-location is still being used for resolving some bitcode files that are added in the clang-linker-wrapper itself. When we move those into the driver --sycl-device-library-location can be cleaned out. --sycl-device-libraries should be OK to clean out now.

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

Labels

new-offload-model Enables testing with NewOffloadModel.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants