-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
GH-135379: Support limited scalar replacement for replicated uops in the JIT code generator. #135563
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
GH-135379: Support limited scalar replacement for replicated uops in the JIT code generator. #135563
Conversation
…nerator. Use it to support efficient specializations of COPY and SWAP in the JIT.
Can you call the PR something else instead of "scalar replacement"? Scalar replacement is the other term for escape analysis in the JVM https://devblogs.microsoft.com/java/improving-openjdk-scalar-replacement-part-1-3/ I know CS has a lot of overlapping terms, but I think it would be clearer to call it "change replicates to ranges" or something. |
scalarize works too. |
Tools/cases_generator/analyzer.py
Outdated
] + items[index+1:] | ||
|
||
def scalarize_stack(stack: StackEffect, oparg: int) -> StackEffect: | ||
# Only scalarize if no more than one input or output is array |
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.
This comment doesn't seem to belong to this code segment?
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.
Yes, I refactored the code but didn't move the comment.
This is scalar replacement. We are replacing a composite object (an array in this case) with a set of scalar values. In the JVM, that means breaking down an object into its parts. The JVM version is a lot more complex and powerful, but it is doing the same thing, and the motivation is the same: register allocation. |
It's somewhat confusing because it's scalar replacement in the JIT, but not in the default interpreter. Though you subtly implied it with the "uops". |
Co-authored-by: Ken Jin <[email protected]>
index = -1 | ||
for i, item in enumerate(items): | ||
if "oparg" in item.size: | ||
if index >= 0: | ||
return items | ||
index = i | ||
if index < 0: | ||
return items |
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.
This entire part is somewhat confusing, but I'll let it slide since there's a comment up top :).
…ps in the JIT code generator. (pythonGH-135563) * Use it to support efficient specializations of COPY and SWAP in the JIT.
This PR does three things:
replicate
to support ranges starting from values other than zeroCOPY
andSWAP
to take advantage of that.With TOS caching this should allow
COPY
andSWAP
to be implemented as register-to-register moves.