-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Introduce local variables with unknown size #122638
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
base: main
Are you sure you want to change the base?
Conversation
Adds lvaLclSymbolicSize for handling locals that may have an unknown size at compile time (SIZE_UNKNOWN). Adds various assertions to areas with assumptions based on concrete size values. Updates parts of value numbering and SSA building to use the symbolic size of the type.
|
@dotnet/arm64-contrib |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
|
@dotnet/arm64-contrib @dotnet/jit-contrib Please could I have a review for this patch? It's a precursor for supporting the rest of the local variable implementation for SVE |
| #define TYP_U_IMPL TYP_UINT | ||
| #endif | ||
|
|
||
| #define SIZE_UNKNOWN UINT8_MAX |
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.
What prevents a normal struct from having size UINT8_MAX?
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.
genTypeSizes for TYP_STRUCT returns 0 so it's fine?
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.
there is already TYP_UNKNOWN - can it be re-used here?
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.
genTypeSizes for TYP_STRUCT returns 0 so it's fine?
LclVarDsc::lvExactSize will assert for structs of size 255 in this PR if I am understanding correctly.
I think having a SIZE_UNKNOWN returned by lvSymbolicSize that you can forget to check is problematic and fragile. For example, it leaks into all users of VisitLocalDefs without good confidence that everyone remembers to check for it. I would much rather have this be some kind of optional value that makes it clear when it may not be present.
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.
I would much rather have this be some kind of optional value that makes it clear when it may not be present.
Say we have unsigned lvExactSize(bool *hasUnknownSize) instead? And I'll update all the call sites to decide whether hasUnknownSize is relevant or not to the situation.
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.
No, I would rather have a struct like
struct ValueSize
{
bool IsUnknown();
unsigned GetSize()
{
assert(!IsUnknown());
return ...;
}
};
to be used in the few places where we want to propagate a possibly unknown size, like VisitLocalDefs. Its internal representation can represent unknown as UINT_MAX (I don't think UINT8_MAX is reasonable).
But I would keep lvExactSize as asserting that it is not called on a value of unknown size. Hopefully there won't be many places where we need to even deal with something like ValueSize.
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.
Hopefully there won't be many places where we need to even deal with something like ValueSize.
It seems to be limited to value numbering, and after implementing your suggestion I can see which areas have the potential to fire assertions more clearly. I've updated the description to reflect this better.
Adds
ValueSizeclass for handling sizes that may be unknown at compile time during phases such as value numbering, that aren't concerned with the exact numeric value (only properties such as equivalence etc.). Adds various assertions to areas of value numbering and SSA building with assumptions based on exact size values. AddsLclVarDsc::lvValueSizeto produce aValueSizefor a local variable, which provides the criteria for which locals have unknown size at compile time.