Repository navigation
JIT: Use sentinel arg to clear error register pre-Swift call - #99428
Conversation
|
@jakobbotsch PTAL, thanks! |
|
/azp run runtime-coreclr jitstressregs |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| // GTF_CALL_M_SWIFT_ERROR_HANDLING indicates the call has a SwiftError* argument, | ||
| // so the error register value will eventually be consumed post-call. | ||
| if ((call->gtCallMoreFlags & GTF_CALL_M_SWIFT_ERROR_HANDLING) != 0) | ||
| if (call->HasSwiftErrorHandling()) |
There was a problem hiding this comment.
If this ends up being expensive TP wise you can add some handling in AddedWellKnownArg to make it cheaper.
There was a problem hiding this comment.
I guess it'll be cheap with the check for the calling convention in HasSwiftErrorHandling
There was a problem hiding this comment.
Yeah, I don't think this will be too expensive in the general case, though if we want to speed up the Swift error handling case, I can add some new state to CallArgs to avoid the lookup.
There was a problem hiding this comment.
Actually, updating this state in AddedWellKnownArg would probably affect TP in the general case. I'll probably have to separate this logic out.
| bool HasSwiftErrorHandling() | ||
| { | ||
| // Most calls aren't Swift calls, so short-circuit this check by checking the calling convention first. | ||
| return (unmgdCallConv == CorInfoCallConvExtension::Swift) && |
There was a problem hiding this comment.
Accessing unmgdCallConv here is UB when that's not the active union member, so this probably needs a few other checks.
|
jitstressregs passed. Gonna push a trivial revision. |
| #endif | ||
| #ifdef SWIFT_SUPPORT | ||
| // True if we are calling a Swift method that may throw. | ||
| bool m_hasSwiftErrorHandling : 1; |
There was a problem hiding this comment.
Was the other approach costing TP, or why are we going with this?
I would follow the pattern in AddedWellKnownArg instead, unless it really turns out to be costly. I think the consistency and correct-by-construction handling is preferable.
There was a problem hiding this comment.
(But I liked your initial approach. I don't think the iteration of the args for swift calls is a problem.)
There was a problem hiding this comment.
Was the other approach costing TP, or why are we going with this?
The cost of that approach was trivial, though I realized we check if a call uses Swift error handling in a few places where the call may be managed, so we'd have to call GetUnmanagedCallConv instead of checking unmgdCallConv directly to avoid UB. Considering we already use this AddedWellKnownArg state handling in a few places, it seemed cleaner to just copy that approach.
I would follow the pattern in AddedWellKnownArg instead, unless it really turns out to be costly. I think the consistency and correct-by-construction handling is preferable.
Got it, fixed.
There was a problem hiding this comment.
AddedWellKnownArg is used just to improve performance. If we can avoid introducing extra state to maintain and there is no discernable TP cost of it, then I think we should do that.
There was a problem hiding this comment.
I checked the TP impact locally, and the AddedWellKnownArg actually seems to be a bit more costly in the general case (~0.01-0.02% impact versus 0.07%). Even with the additional branch in HasSwiftErrorHandling from the call to GetUnmanagedCallConv, that seems like the way to go. I'll revert to it.
| case WellKnownArg::SwiftError: | ||
| m_hasSwiftErrorHandling = true; | ||
| break; | ||
| #endif // SWIFT_SUPPORT |
There was a problem hiding this comment.
RemovedWellKnownArg should also be updated.
This reverts commit 2052e84.
Fixes #99414. By adding a well-known zero argument to Swift calls with error handling that is always passed via the error register, we can get the JIT to clear the error register before the call, and also prevent the function address from being passed in the error register.