Skip to content

[SYCL] Call clang instead of llc. #15259

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 5 commits into from
Sep 18, 2024
Merged

Conversation

hvdijk
Copy link
Contributor

@hvdijk hvdijk commented Sep 2, 2024

Previously, OffloadWrapper::ConstructJob would call llc to convert LLVM IR into machine code. With this change, it calls clang instead.

This should be mostly NFC for x86, there may be some small changes in exactly which passes run, but they are intended to be roughly the same, and enables future changes passing along more clang options.

For other targets, this is a bugfix. Specifically, for RISC-V, llc and clang disagree on which subtarget features to enable by default, resulting in linker errors due to subtarget feature mismatches between the llc-compiled wrapper and other clang-compiled object files.

Previously, OffloadWrapper::ConstructJob would call llc to convert LLVM
IR into machine code. With this change, it calls clang instead.

This should be mostly NFC for x86, there may be some small changes in
exactly which passes run, but they are intended to be roughly the same,
and enables future changes passing along more clang options.

For other targets, this is a bugfix. Specifically, for RISC-V, llc and
clang disagree on which subtarget features to enable by default,
resulting in linker errors due to subtarget feature mismatches between
the llc-compiled wrapper and other clang-compiled object files.
@hvdijk hvdijk requested a review from a team as a code owner September 2, 2024 22:53
* Windows does not support, and does not need, -fPIC.
* Update lit tests.
const char *Clang = C.getArgs().MakeArgString(ClangPath);
C.addCommand(std::make_unique<Command>(JA, *this,
ResponseFileSupport::None(), Clang,
ClangArgs, std::nullopt));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think ideally, this should be handled outside of the wrapper call, where we call the wrapper, then create a new job that calls the compiler backend to create the object. But as we are moving away from the old offload model in the near future that work may be wasted effort.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it should not be in this function directly, though I had a slightly different idea there, that is what the // TODO Use TC.SelectTool(). comment is about. I was concerned it would be too big a change to go that route right away, and I would have that same concern with your idea. But if you say this whole approach is going away anyway, then definitely it sounds like it is not worth the extra work.

llvm::Reloc::Model RelocationModel;
unsigned PICLevel;
bool IsPIE;
std::tie(RelocationModel, PICLevel, IsPIE) =
ParsePICArgs(getToolChain(), TCArgs);
if (PICLevel > 0 || TCArgs.hasArg(options::OPT_shared)) {
LlcArgs.push_back("-relocation-model=pic");
if (!TC.getAuxTriple()->isOSWindows())
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why we need this restriction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Windows does not support (or need) -fPIC, it results in "clang: error: unsupported option '-fPIC' for target 'x86_64-pc-windows-msvc'".

@hvdijk
Copy link
Contributor Author

hvdijk commented Sep 16, 2024

ping

Copy link
Contributor

@mdtoguchi mdtoguchi left a comment

Choose a reason for hiding this comment

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

Thanks - LGTM.

@bader
Copy link
Contributor

bader commented Sep 16, 2024

@hvdijk, @mdtoguchi, is llc used for anything else in the SYCL compilation flow?
If no, please, remove it from the deploy-sycl-toolchain target.
https://github.com/intel/llvm/blob/sycl/sycl/CMakeLists.txt#L443

@maksimsab
Copy link
Contributor

@bader Yes, it is being used in the clang-linker-wrapper at the moment.

// CHK-SPLIT-CMDS-NEXT: "{{.*}}llc" -filetype=obj -o [[LLCOUT:.*]] [[WRAPPEROUT]].bc

@hvdijk
Copy link
Contributor Author

hvdijk commented Sep 16, 2024

@bader Yes, it is being used in the clang-linker-wrapper at the moment.

Looking at that, probably that would benefit from the same change; if so, would you prefer that I update this PR to do so or would you prefer that as a later followup PR?

@bader
Copy link
Contributor

bader commented Sep 16, 2024

@bader Yes, it is being used in the clang-linker-wrapper at the moment.

Looking at that, probably that would benefit from the same change; if so, would you prefer that I update this PR to do so or would you prefer that as a later followup PR?

Eventually, we will switch to the new offloading model, so I would do the change sooner rather than later, but I don't have a strong opinion about the form. I leave this decision to you.
If you split the change into PRs, I suggest updating PR title or description to say that we update only "old" offload model.

- Update clang-offload-wrapper too.
- Remove unused SYCL::Linker::constructLlcCommand.
@hvdijk hvdijk requested a review from a team as a code owner September 17, 2024 16:09
@hvdijk
Copy link
Contributor Author

hvdijk commented Sep 17, 2024

Updated to modify clang-linker-wrapper too (with an incorrect name in the commit message, but that is going to be squashed anyway) and to remove SYCL::Linker::constructLlcCommand.

I did not modify deploy-sycl-toolchain yet because I noticed that llc is still called when compiling SPIR-V files (see clang/lib/Driver/ToolChains/Clang.cpp) and I was not sure whether this is a scenario that is important to Intel.

@asudarsa
Copy link
Contributor

Updated to modify clang-linker-wrapper too (with an incorrect name in the commit message, but that is going to be squashed anyway) and to remove SYCL::Linker::constructLlcCommand.

I did not modify deploy-sycl-toolchain yet because I noticed that llc is still called when compiling SPIR-V files (see clang/lib/Driver/ToolChains/Clang.cpp) and I was not sure whether this is a scenario that is important to Intel.

Hi @hvdijk

Thanks so much for updating the clang-linker-wrapper. w.r.t the use of llc for SPIR-V code generation, it is a temporary workaround I added to test the SPIR-V backend. I will be removing that work-around soon and will remove the llc dependency for sycl toolchain at that point.
Hope that's agreeable.

Thanks

Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks

@PietroGhg
Copy link
Contributor

@intel/llvm-gatekeepers this looks ready to merge, thank you

@martygrant martygrant merged commit 464b077 into intel:sycl Sep 18, 2024
11 checks passed
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.

7 participants