Repository navigation
Open
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIarea-Diagnostics-coreclrdocumentationDocumentation bug or enhancement, does not impact product or test code
Milestone
Description
@dotnet/jit-contrib @sywhang
While investigating #10706 I'm seeing a number of things that look inconsistent and probably need to be fixed or better documented. Jit folks, can you let me know what you think?
- The FunctionEnter3/FunctionLeave3/FunctionTailcall3 methods are a publicly exposed and have a documented ABI. On Linux x64 we pass FunctionIDOrClientID in R14, MSDN documentation doesn't mention a custom calling convention so developers would expect RDI. I believe we picked R14 for good reason so I propose we change MSDN to match.
- The runtime sometimes provides the implementation of the ProfileEnter call as an intermediary between the jitted code and other forms of the profiler callback. On Linux x64 that gives us 4 non-agreeing definitions of the register preservation requirements:
- The MSDN docs claim the caller must preserve all registers
- The code comments above the runtime ProfileEnterNaked implementation suggest a number of registers are not preserved:
https://github.com/dotnet/coreclr/blob/master/src/vm/amd64/asmhelpers.S#L59
(Incidentally the comments aren't self-consistent either, xmm1 and rdx are both preserved and not preserved ; ) - The implementation of the JIT has different expectations about what would be preserved (for example is it really safe to trash the argument registers in the prologue of the caller?)
- The implementation of the assembly routine preserves all the integer argument registers
https://github.com/dotnet/coreclr/blob/master/src/vm/amd64/asmhelpers.S#L135
I don't have a good sense of exactly what the JIT expects to be preserved across this call for the code to run correctly, but whatever it is I'd like to bring our own comments, implementation, and MSDN docs into alignment with it. I suspect there may be discrepancies for the register preservation requirements on other architectures, but I'm happy to start with Linux x64.
Thanks!
-Noah
category:documentation
theme:prolog-epilog
skill-level:intermediate
cost:medium
impact:small
Reacted by Matt Warren, Aaron R Robinson, Bertrand Bonnefoy-Claudet and Ilia
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIarea-Diagnostics-coreclrdocumentationDocumentation bug or enhancement, does not impact product or test code
Activity
BruceForstall commentedon Aug 8, 2018
Note that the document that JIT depends most on for ABI related questions is the "CLR ABI". It has a section on the profiler hooks: https://github.com/dotnet/coreclr/blob/master/Documentation/botr/clr-abi.md#profiler-hooks. It could certainly be expanded to be more clear, and answer more questions like you have here.
In the JIT, the most interesting parts of the implementation are
genProfilingEnterCallbackandgenProfilingLeaveCallback.Generally, documentation probably was originally written for x86 -- the first architecture -- and not updated very much to handle the other architectures (x64, Linux x64, arm32, arm64, Linux x86).
It looks to me that for Linux x64:
FunctionEnter3WithInfo(and friends) are, and the JIT just always generates the same code.There is no documentation in the code or "CLR ABI" to explain why R14/R15 were picked. Presumably it is because there is no caller-provided "home" space for the argument registers, as on Windows x64. So we don't want to trash the incoming registers. On Windows, we first home all the register argument, and then we can trash them.
Regarding register preservation:
The asmhelper.S comment that says rax/rdx/xmm0/xmm1 need to be preserved should, I believe, only apply to the "leave" helper, which needs to preserve the function return value.
These statements should really be backed up by testing! And extended to other platforms.
noahfalk commentedon Aug 9, 2018
Thanks for looking into this Bruce! I agree on the testing. My thinking here is we could write a trivial profiler that registers ELT callbacks in order to deliberately trash every register we believe we can. If we can have this profiler loaded and pass all the CoreCLR tests then it would be good evidence the analysis was accurate.
That is intentional. The public contract is only on the 1st argument. The second argument is private contract between JIT and runtime so that the runtime can implement FunctionEnter3WithInfo.
noahfalk commentedon Aug 20, 2018
@BruceForstall - I've been looking at this a bit more and it raised a few (hopefully quick) additional questions:
Clean up register preservation requirements for Enter callback
BruceForstall commentedon Aug 20, 2018
The questions are specific to x64, I believe.
We don't support
__vectorcallconvention, so:Maybe @CarolEidt can comment to verify.
CarolEidt commentedon Aug 21, 2018
@BruceForstall is right about the handling of the upper bits of XMM arguments, though for anything that's not classified as a call, we expect them to be preserved.
On Linux/x64, I believe it's the case that a struct of 2 floats would be returned in XMM0, but a struct of 2 doubles or 3 or 4 floats would be returned in XMM0 and XMM1.
There's no support for using more than 2 registers for returns.
BruceForstall commentedon Mar 13, 2019
@noahfalk It doesn't seem like this is a 3.0 issue, so I'm moving it to Future.