-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement portable tailcall helpers (#341)
* Implement portable tailcall helpers This implements tailcall-via-help support for all platforms supported by the runtime. In this new mechanism the JIT asks the runtime for help whenever it realizes it will need a helper to perform a tailcall, i.e. when it sees an explicit tail. prefixed call that it cannot make into a fast jump-based tailcall. The runtime created two important IL stubs to help the JIT in performing the necessary tailcalls. One IL stub is used to store the args for the tailcall, while the other is used to dispatch the actual tailcall itself. The JIT will then transform the call from return tail. F(a1, ..., an); to IL_STUB_StoreTailCallArgs(a1, ..., an); T result; IL_STUB_DispatchTailCalls(..., &result); return result; The dispatcher is written in such a way that it is able to dispatch multiple tailcalls in a row when tailcalled functions also perform tailcalls. To do this, the JIT helps the dispatcher detect if the caller's caller is also a dispatcher. When this is the case the dispatcher returns to let the previous dispatcher perform the tailcall with the currently stored args. This allows the frame to unwind and ensures that sequences of tailcalls do not grow the stack more than by a constant factor. Due to this unwinding the args cannot be stored on the stack and are instead stored in TLS. The GC is made specially of this buffer as the args can be anything, including interior pointers. The control-flow when performing the new tailcalls is nonstandard, so this also changes the debugger to support proper stepping into/over/out of tailcalled functions when they go through the new dispatcher. x86's tailcalling mechanism does not change. This commit also includes the following changes: * Update design doc for helper-based tailcalls * Change lowering of GT_LABEL on arm. Generate movw/movt instead of adr on arm. adr on arm allows offsets up to 4k, which may not be enough. In particular, IL_STUB_CallTailCallTarget uses GT_LABEL before argument setup code and it can be more than 4k. * Add COMPlus_FastTailCalls environment variable. COMPlus_FastTailCalls controls whether fast tail calls are allowed. If COMPlus_FastTailCalls is 0, fast tail calls are not allowed even for tail-prefixed calls. Only helper-based calls are allowed. This is useful for testing helper-based calls. Co-authored-by: Eugene Rozenfeld <erozen@microsoft.com>
- Loading branch information
1 parent
d68342c
commit e1ffadd
Showing
72 changed files
with
4,801 additions
and
3,430 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.