-
Notifications
You must be signed in to change notification settings - Fork 5k
JIT: Avoid implicit byref retbufs in async calls #115888
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
Open
jakobbotsch
wants to merge
3
commits into
dotnet:main
Choose a base branch
from
jakobbotsch:fix-115884
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+43
−8
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -844,10 +844,7 @@ GenTree* Compiler::impStoreStruct(GenTree* store, | |||||
GenTreeFlags indirFlags = GTF_EMPTY; | ||||||
GenTree* destAddr = impGetNodeAddr(store, CHECK_SPILL_ALL, &indirFlags); | ||||||
|
||||||
// Make sure we don't pass something other than a local address to the return buffer arg. | ||||||
// It is allowed to pass current's method return buffer as it is a local too. | ||||||
if ((fgAddrCouldBeHeap(destAddr) && !eeIsByrefLike(srcCall->gtRetClsHnd)) || | ||||||
(compIsAsync() && !destAddr->OperIs(GT_LCL_ADDR))) | ||||||
if (!impIsLegalRetBuf(destAddr, srcCall)) | ||||||
{ | ||||||
unsigned tmp = lvaGrabTemp(false DEBUGARG("stack copy for value returned via return buffer")); | ||||||
lvaSetStruct(tmp, srcCall->gtRetClsHnd, false); | ||||||
|
@@ -971,10 +968,7 @@ GenTree* Compiler::impStoreStruct(GenTree* store, | |||||
GenTreeFlags indirFlags = GTF_EMPTY; | ||||||
GenTree* destAddr = impGetNodeAddr(store, CHECK_SPILL_ALL, &indirFlags); | ||||||
|
||||||
// Make sure we don't pass something other than a local address to the return buffer arg. | ||||||
// It is allowed to pass current's method return buffer as it is a local too. | ||||||
if ((fgAddrCouldBeHeap(destAddr) && !eeIsByrefLike(call->gtRetClsHnd)) || | ||||||
(compIsAsync() && !destAddr->OperIs(GT_LCL_ADDR))) | ||||||
if (!impIsLegalRetBuf(destAddr, call)) | ||||||
{ | ||||||
unsigned tmp = lvaGrabTemp(false DEBUGARG("stack copy for value returned via return buffer")); | ||||||
lvaSetStruct(tmp, call->gtRetClsHnd, false); | ||||||
|
@@ -1068,6 +1062,46 @@ GenTree* Compiler::impStoreStruct(GenTree* store, | |||||
return store; | ||||||
} | ||||||
|
||||||
//------------------------------------------------------------------------ | ||||||
// impIsLegalRetbuf: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment header uses
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
// Check if a return buffer is of a legal shape. | ||||||
// | ||||||
// Arguments: | ||||||
// retBuf - The return buffer | ||||||
// call - The call that is passed the return buffer | ||||||
// | ||||||
// Return Value: | ||||||
// True if it is legal according to ABI and IR invariants. | ||||||
// | ||||||
// Notes: | ||||||
// ABI requires all return buffers to point to stack. Also, we have an IR | ||||||
// invariant for async calls that return buffers must be the address of a | ||||||
// local. | ||||||
// | ||||||
bool Compiler::impIsLegalRetBuf(GenTree* retBuf, GenTreeCall* call) | ||||||
{ | ||||||
if (call->IsAsync()) | ||||||
{ | ||||||
// Async calls require LCL_ADDR shape for the retbuf to know where to | ||||||
// save the value on resumption. | ||||||
if (!retBuf->OperIs(GT_LCL_ADDR)) | ||||||
{ | ||||||
return false; | ||||||
} | ||||||
|
||||||
// LCL_ADDR on an implicit byref will turn into LCL_VAR in morph. | ||||||
if (lvaIsImplicitByRefLocal(retBuf->AsLclVarCommon()->GetLclNum())) | ||||||
{ | ||||||
return false; | ||||||
} | ||||||
|
||||||
return true; | ||||||
} | ||||||
|
||||||
// The ABI requires the retbuffer to point to stack. | ||||||
return !fgAddrCouldBeHeap(retBuf) || eeIsByrefLike(call->gtRetClsHnd); | ||||||
} | ||||||
|
||||||
//------------------------------------------------------------------------ | ||||||
// impStoreStructPtr: Store (copy) the structure from 'src' to 'destAddr'. | ||||||
// | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Add a brief Doxygen-style comment above this declaration to explain when
impIsLegalRetBuf
should be used and its ABI/async guarantees.Copilot uses AI. Check for mistakes.