Skip to content
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

[mypyc] Implement lowering pass and add primitives for int (in)equality #17027

Merged
merged 15 commits into from Mar 16, 2024

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Mar 14, 2024

Add a new PrimitiveOp op which can be transformed into lower-level ops in a lowering pass after reference counting op insertion pass.

Higher-level ops in IR make it easier to implement various optimizations, and the output of irbuild test cases will be more compact and readable.

Implement the lowering pass. Currently it's pretty minimal, and I will add additional primitives and the direct transformation of various primitives to CallC ops in follow-up PRs. Currently primitives that map to C calls generate CallC ops in the main irbuild pass, but the long-term goal is to only/mostly generate PrimitiveOps instead of CallC ops during the main irbuild pass.

Also implement primitives for tagged integer equality and inequality as examples.

Lowering of primitives is implemented using decorated handler functions in mypyc.lower that are found based on the name of the primitive. The name has no other significance, though it's also used in pretty-printed IR output.

Work on mypyc/mypyc#854. The issue describes the motivation in more detail.

@JukkaL JukkaL changed the title [mypyc] Implement lowering pass and add high-level primitives for int (in)equality [mypyc] Implement lowering pass and add primitives for int (in)equality Mar 14, 2024
It's pointless, plus the IR is incomplete and so code gen will likely fail.
@JukkaL
Copy link
Collaborator Author

JukkaL commented Mar 15, 2024

This seems to expose a pre-existing bug in reference counting transform.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Mar 16, 2024

This seems to expose a pre-existing bug in reference counting transform.

This was actually a regression in this PR. We hit a limitation of the reference counting transform (not a bug as such).

@JukkaL JukkaL merged commit c591c89 into master Mar 16, 2024
13 checks passed
@JukkaL JukkaL deleted the mypyc-lowering branch March 16, 2024 12:54
JukkaL added a commit that referenced this pull request Mar 19, 2024
…17040)

Support lowering of tagged integer `<`, `<=`, `>` and `>=` operations.

Previously we had separate code paths for integer comparisons in values
vs conditions. Unify these and remove the duplicate code path. The
different code paths produced subtly different code, but now they are
identical.

The generated code is now sometimes slightly more verbose in the slow
path (big integer). I may look into simplifying it in a follow-up PR.

This also makes the output of many irbuild test cases significantly more
compact.

Follow-up to #17027. Work on mypyc/mypyc#854.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants