[SYCL] Add option forwarding from clang-linker-wrapper tool to clang-sycl-linker #21958
[SYCL] Add option forwarding from clang-linker-wrapper tool to clang-sycl-linker #21958srividya-sundaram wants to merge 4 commits into
Conversation
|
More general comment.
In cases like that the suggested approach is: https://llvm.org/docs/Contributing.html#how-to-submit-a-patch Please, use this approach in your patches. |
8d6725d to
20f67e1
Compare
YuriPlyakhin
left a comment
There was a problem hiding this comment.
could you please update title?
| @@ -0,0 +1,42 @@ | |||
| // Test that clang-linker-wrapper correctly invokes clang-sycl-linker when --use-clang-sycl-linker is enabled | |||
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
I think this should be a new test, similar to
And if anything from this test can be submitted upstream, that should be done first (but looking at what is being checked here, it seems this test indeed belongs to downstream for now).
| // CHECK-DEFAULT: clang-linker-wrapper | ||
| // CHECK-DEFAULT-NOT: "--use-clang-sycl-linker" | ||
| // | ||
| // Test that --use-clang-sycl-linker flag is passed through |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
| bool UseClangSYCLLinker = false; | |
| static bool UseClangSYCLLinker = false; |
| OPT_bitcode_library_EQ, | ||
| }; | ||
| for (OptSpecifier Opt : ValueOpts) { | ||
| if (const opt::Arg *A = Args.getLastArg(Opt)) { |
There was a problem hiding this comment.
OPT_bitcode_library_EQ can be provided multiple times, right? getLastArg will use only last value, so previous libraries would be dropped.
| OPT_sycl_remove_unused_external_funcs, | ||
| OPT_no_sycl_remove_unused_external_funcs, |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
This is sycl-specific function, should it be placed to sycl namespace?
| } | ||
| } | ||
|
|
||
| static const OptSpecifier ValueOpts[] = { |
There was a problem hiding this comment.
are all options which we are forwarding to clang-sycl-linker supported by it?
YuriPlyakhin
left a comment
There was a problem hiding this comment.
this pr needs some more work.
This is the first patch in a series that moves SYCL device code linking logic from
clang-linker-wrapperinto theclang-sycl-linkertool.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-linkerinvocations will be added in subsequent PRs.Added infrastructure from PR 21692 + tests for option forwarding.