-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
llvm: Add support for vectorcall (X86_VectorCall) convention #30567
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nrc (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This is probably most important for MSVC interfacing. |
Are there specific APIs that need this? I do not like adding features just because they exist in LLVM. Let's not add calling conventions lightly. cc @rust-lang/lang |
There doesn’t seem to be many uses of this calling conventions in public APIs, but there’s some (e.g. skia) that use this CC for optimisation purposes. |
I only know of PHP 7 (which is with what I'm fiddling around currently). The general problem is that rust first doesn't support all of LLVMs I do not quite understand why @brson doesn't want (more) parity with LLVM here, |
I think that Rust should support any calling convention that can be reasonably used from C code. Things like vectorcall can be used by C code quite easily (at least on Windows with msvc), and are likely to be part of the public interface of libraries. As such, Rust should be proactive in supporting these calling conventions when it knows they exist, rather than waiting for people to get fed up with maintaining custom builds of Rust. There are weird custom calling conventions for things like Haskell and stuff which can't really be used from C code and are unlikely to be in the public interface of a library. I recommend not supporting these, as there's very little reason to support them. |
The reason (aiui) for not exposing everything llvm exposes is that we don't want to be tied to the llvm backend any more than we already are. We might want to support a C or gcc or custom backend in the future and every extra implementation detail we expose which ties us to llvm makes that harder. It seems reasonable to expose calling conventions which are supported by all major C compilers if there is a demand. I don't know if that is the case here. |
I indeed agree that exposing everything llvm exposes is a bad idea However I can't quite agree with
|
cc @rust-lang/tools @steffengy these are good points. I'm not sure where we stand on platform-specific stuff. This probably needs some discussion some where (tools/lang/core teams). |
Reading the MSDN page linked and this one makes it fairly clear to me that this isn't an LLVM-ism at all, and should be safe/desirable to provide. |
Rust is its own language, not a high-level interface to LLVM. We've had many cases in the past where patches exposed LLVM functionality just because it was neat and we could. LLVM is a big backend. It does lots of stuff. The more we expose the harder it is to maintain, spec, and port to non-LLVM backends. |
@brson
https://software.intel.com/sites/default/files/Vectorcall_regcall_Demystified.pdf And since, as I already mentioned,
I really do not see any reason not to add support in this case. |
Ok so y'all are kinda talking past each other on the issue of specific vs general. Hashing it out on IRC, the ultimate issue here is: Who's going to use this? We don't like adding features that literally no one is going to use "because we can", because that leads to rot. @steffengy you seem to imply that you're interested in using this for some problem, but you haven't explicitly stated that. Are you? @retep998 are there any systems you maintain that will benefit from this? Are there public interfaces that require this (@nagisa couldn't find any)? The fact that "this exists and isn't tied to LLVM specifically" is an ok start, but if there isn't any strong motivating usecases today, it might make sense to hold off on this. |
|
Yes I currently am (else this PR wouldn't exist)
Additionally I also found https://github.com/google/skia that seems to use it
That does apply generally, but I do not really think that applies here, |
Regarding maintenance, I was surprised to see no test case in this PR, but according to |
I personally very much agree with @brson's sentiments about not exposing everything LLVM does "just because", however I also agree with @gankro's assessment that this may not apply to this PR (e.g. it seems that vectorcall is both a prior name and has usage in other compilers). In terms of of a public API exposed by the compiler itself, there's a few facets:
@ranma42 no we don't auto-generate tests for things like this, but I would personally like to see at least one usage of this in a test regardless. Overall I would like to explore putting this ABI behind a feature gate, and then I would be quite comfortable landing it. |
@alexcrichton The |
Perhaps you can say more about what you want to do with this calling convention. It still seems to me that there are not public APIs that require Rust to implement vectorcall for compatibility. So the only reason I see to implement it is that it offers a compelling performance improvement in some case. Even if that is true, it does not necessarily suggest to me that 'vectorcall' is the way for Rust to achieve the same thing. A performance win really needs to be big for us to add an entirely new calling convention. |
There probably some private API methods I'm using, but most actually are public, Source-Reference (limited to 2 results per file) Whether there's a huge performance win, I cannot say, but since the Intel performance |
@brson how do you feel about adding this behind a feature gate? @steffengy could you also add a positive test which uses the ABI? |
@steffengy reading the PR, I had one question: from what I can tell, this ABI is specific to Windows? Do you know what LLVM will do on other platforms? I would think that we probably want to just error out on non-Windows targets. |
@nikomatsakis LLVM seems to work fine using vectorcall on other platforms, else the tests wouldnt pass. You're right though that vectorcall is used only by msvc at the moment. |
What concerned me is more that LLVM may be doing some random thing that is neither well specified nor particularly portable. |
@nikomatsakis It's basically the same with Win64 at the moment (which rust supports), |
To be clear, this is mostly a theoretical concern and I'm not overly worried. But just to spell it out. What I was worried about is that people call into some C library that is declared with this calling convention. Then we switch from LLVM to some other backend. And we find out that it's a pain to reproduce the precise behavior that LLVM had in this new backend, because it is linux specific and doesn't support this windows-specific calling convention. Basically, part of the argument for supporting a calling convention is that it is widespread on Win64, and hence whatever backend we choose will support it, which I think makes sense. But it's not true on linux, and hence by permitting it we are committing ourselves more to LLVM than we otherwise would. No? |
If somebody would use a linux library which would indeed use this calling convention, This problem exists for every windows-specific calling convention though So you are not really bound to LLVM, but to a backend which supports windows-specific calling conventions, if someone would for whatever reason would want to use this convention on a non windows target (atleast today thats highly unlikely) I also think it's more like a theoretical concern, which should not have any larger impact in the future. |
Thanks for the examples @steffengy. I reluctantly concede that it looks inevitable that we'll have to implement this. Go for it. |
⌛ Testing commit 4396a2d with merge 400bacf... |
💔 Test failed - auto-linux-64-nopt-t |
@bors retry |
Add support to use functions exported using vectorcall. This essentially only allows to pass a new LLVM calling convention from rust to LLVM. ```rust extern "vectorcall" fn abc(param: c_void); ``` references ---- http://llvm.org/docs/doxygen/html/CallingConv_8h_source.html https://msdn.microsoft.com/en-us/library/dn375768.aspx
💔 Test failed - auto-linux-64-nopt-t |
@bors retry |
Wow, the linux version of rust is quite flaky with those spurious failures. |
⚡ Previous build results for auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-debug-opt, auto-linux-64-opt, auto-linux-cross-opt, auto-linux-musl-64-opt, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-msvc-32-opt are reusable. Rebuilding only auto-linux-64-nopt-t, auto-linux-64-x-android-t, auto-win-gnu-32-nopt-t, auto-win-gnu-32-opt, auto-win-gnu-64-nopt-t, auto-win-gnu-64-opt, auto-win-msvc-64-opt... |
Yes. I think we should consider generating an error (or at least a warning) for all such ABIs when they are used outside the target platform. I agree this is not specific to vectorcall (nor to Windows; I'm sure there are linux-specific conventions out there) and didn't mean to imply otherwise. But, as you say, I'm not too worried about this being a big problem in practice. I'll just let it go. :) |
…, r=ehuss Add tracking issue and unstable book page for `"vectorcall"` ABI Originally added in 2015 by rust-lang#30567, the Windows `"vectorcall"` ABI didn't have a tracking issue until now. Tracking issue: rust-lang#124485
…, r=ehuss Add tracking issue and unstable book page for `"vectorcall"` ABI Originally added in 2015 by rust-lang#30567, the Windows `"vectorcall"` ABI didn't have a tracking issue until now. Tracking issue: rust-lang#124485
…, r=ehuss Add tracking issue and unstable book page for `"vectorcall"` ABI Originally added in 2015 by rust-lang#30567, the Windows `"vectorcall"` ABI didn't have a tracking issue until now. Tracking issue: rust-lang#124485
…, r=ehuss Add tracking issue and unstable book page for `"vectorcall"` ABI Originally added in 2015 by rust-lang#30567, the Windows `"vectorcall"` ABI didn't have a tracking issue until now. Tracking issue: rust-lang#124485
…, r=ehuss Add tracking issue and unstable book page for `"vectorcall"` ABI Originally added in 2015 by rust-lang#30567, the Windows `"vectorcall"` ABI didn't have a tracking issue until now. Tracking issue: rust-lang#124485
Rollup merge of rust-lang#124486 - beetrees:vectorcall-tracking-issue, r=ehuss Add tracking issue and unstable book page for `"vectorcall"` ABI Originally added in 2015 by rust-lang#30567, the Windows `"vectorcall"` ABI didn't have a tracking issue until now. Tracking issue: rust-lang#124485
Add support to use functions exported using vectorcall.
This essentially only allows to pass a new LLVM calling convention
from rust to LLVM.
references
http://llvm.org/docs/doxygen/html/CallingConv_8h_source.html
https://msdn.microsoft.com/en-us/library/dn375768.aspx