Skip to content

transformations: (convert-pdl-to-pdl-interp) Add eqsat instrumentation#5585

Open
jumerckx wants to merge 32 commits intomainfrom
jumerckx/pdl-to-pdl-interp-eqsat
Open

transformations: (convert-pdl-to-pdl-interp) Add eqsat instrumentation#5585
jumerckx wants to merge 32 commits intomainfrom
jumerckx/pdl-to-pdl-interp-eqsat

Conversation

@jumerckx
Copy link
Collaborator

  • Adds extra calls to native rewrites, guarded by if self.optimize_for_eqsat
  • Add option to print the constraint tree for debugging
  • If optimize_for_eqsat, order constraints such that get_defining_ops are spread apart.

@jumerckx jumerckx self-assigned this Jan 26, 2026
@jumerckx jumerckx added the transformations Passes, rewrites label Jan 26, 2026
With the foreach approach, I believe part of this logic can be
simplified/omitted, but this is a good first step.
We need to be more careful with the bindings selected by matchers.
Right now, values are sometimes passed as their class result to a
rewriter:
```
x = …
y = …

c = class x, y

rewrite “myrewrite”(c)
```

This is problematic in MLIR as other rewrites can invalidate c. While we
are guaranteed to not erase any operation in the “program domain”, this
is not true for the operations of the “e-graph domain”.
The solution is to ensure in the pdl lowering that only values from the
program domain are passed to rewriters and the conversion to e-graph
domain happens at the latest possible point, in the rewriter itself.
(This is not an issue in xDSL because erasing an e-class does not
discard of the object)
non-eqsat lowering should stay the same
@jumerckx jumerckx force-pushed the jumerckx/pdl-to-pdl-interp-eqsat branch from 84a0313 to c8f2a47 Compare January 26, 2026 10:24
@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 78.46154% with 70 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.22%. Comparing base (a259e76) to head (6295563).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
...transforms/convert_pdl_to_pdl_interp/conversion.py 78.46% 45 Missing and 25 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5585      +/-   ##
==========================================
- Coverage   86.25%   86.22%   -0.03%     
==========================================
  Files         403      403              
  Lines       56660    57186     +526     
  Branches     6512     6641     +129     
==========================================
+ Hits        48871    49310     +439     
- Misses       6268     6321      +53     
- Partials     1521     1555      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jumerckx jumerckx marked this pull request as ready for review January 27, 2026 13:09
@superlopuh
Copy link
Member

Hi @jumerckx, can you please take a look at the CI failures? seems like it should be good to merge with those resolved

@jumerckx jumerckx force-pushed the jumerckx/pdl-to-pdl-interp-eqsat branch from 795a3ab to 2b9401f Compare February 11, 2026 12:02
often it doesn't seem to do anything on top of the sorted list, but
better safe than sorry?
@jumerckx
Copy link
Collaborator Author

Done

@superlopuh
Copy link
Member

Actually I just noticed the 200 missing lines in coverage, it seems that there are no tests for the actual conversion? Could you please add some? I'm not sure how best to test this since it's quite large, but it would be good to have at least some way of catching changes in behaviour, even if they're not the platonic ideal of a unit test...

@superlopuh
Copy link
Member

How do ChooseNodes get generated? Should we add a second smoke test with optimize for eqsat being true to show the difference in output?

@jumerckx
Copy link
Collaborator Author

I added a small smoketest, you want me to cover things better?

@jumerckx
Copy link
Collaborator Author

How do ChooseNodes get generated? Should we add a second smoke test with optimize for eqsat being true to show the difference in output?

ChooseNodes are not directly visible in the generated output. The are created The smoketest is with optimize_for_eqsat=true, I've now added the output for false.

@superlopuh
Copy link
Member

I have a feeling something went wrong with editing the last message, you didn't finish explaining how they are created :) Codecov seems to not pick up them being created with optimizations on or off?

@jumerckx
Copy link
Collaborator Author

I have a feeling something went wrong with editing the last message
Yeah, though I'd also misunderstood your question.

Choosenodes are inserted at every branch point where a defining operation from a different location is required.
So if you have two patterns

f(g(a), b)
f(a, g(b))

First the outer operation (f) will be checked (operation name, n_operands, types, ...). Then there are two branches:
The first branch will get_defining_op of the first operand, and continue trying to match the first pattern.
The second branch will do the same for the second operand and pattern.

In the current implementation, having different patterns that require separate defining operations but share the exact same matching until that point is exceedingly rare so ChooseNodes typically have one choice. There is definitely some low-hanging fruit should we want to optimize this lowering further.

The test does actually create and generate code from a (single-choice) ChooseNode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

transformations Passes, rewrites

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants