-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
egraph-based midend: draw the rest of the owl (productionized). #4953
Conversation
Subscribe to Label Action
This issue or pull request has been labeled: "cranelift", "cranelift:area:aarch64", "cranelift:area:x64", "cranelift:meta", "isle"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
Rather than recursively computing the lowest-cost node for a given eclass and memoizing the answer at each eclass node, we can do a single forward pass; because every eclass node refers only to earlier nodes, this is sufficient. The behavior may slightly differ from the earlier behavior because we cannot short-circuit costs to zero once a node is elaborated; but in practice this should not matter.
Use an explicit stack instead (with `ElabStackEntry` entries, alongside a result stack).
…ysis framework in cranelift-egraph.
@jameysharp I think this is more-or-less ready for review now! (In fact, I just spent a few hours doing the latest rebase/merge, and these are fairly painful because this PR does a lot of code-motion to factor out ISLE commonalities for mid-end and backends, so I'd really prefer to try to get this merged before much more changes to avoid another rebase hell :-) ) I've updated the implementations of the various rewriting and elaboration algorithms to avoid explicit recursion, and I've factored out a generic "analysis" mechanism for the egraph crate to own; these were the main cleanups I wanted/needd to do before the prototype would be considered production-ready, I think. Regarding the rule-rewriting reentrancy issue, I opted to simply cap the recursion with a static limit (max of 5 chained rewrites) for now, as (i) we'll need such a limit anyway to protect against accidentally infinitely-(co)recursive rules, and (ii) it is about an order of magnitude simpler than unwinding the nested-immediate-rewrites into some sort of "pending node queue" and splitting the id-space, and probably more efficient in the common case. In any case, let me know what you think -- I'm eager for feedback! |
@alexcrichton it looks like the verify-publish CI job is failing here because for some reason it's looking for the (not-yet-published) cranelift-egraph crate on crates.io rather than in the workspace. I copied the magic incantations for workspace-inheritance from the other intra-repo deps but I'm not sure if I'm missing something -- it's surprising that this fails if all the other builds work fine? |
tested using
when calling
the code compiles without error. when setting
backtrace
file reduced from |
You'll need to edit this list to include automatic publishing of a new crate. |
It’s actually already there, from the earlier PR that introduced the crate (line 28); this seems to be something new related to the workspaces change? |
Ah I only checked the diff of this PR, the list also needs to be topologically sorted so if |
Ah, that makes sense, thanks! |
…, like the comment instructs me to!
I've gone over the diff to the ISLE-side and Rust-side definitions of the prelude and ensured that the common bits, which are new files from git's point of view, now have contents that are strictly in the same order and exactly match the removed lines from the old (lowering-only) prelude. (Latest commit does some reordering to make this true.) (This involved a "diff-of-diffs" workflow and was a little ugly; and I wish git had better ways of showing code provenance for cross-file moves; but in the end at least I'm confident no definition was inadvertently missed or reverted to an older version.) |
Co-authored-by: Jamey Sharp <jamey@minilop.net>
Co-authored-by: Jamey Sharp <jamey@minilop.net>
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.
Here's review from FuncEGraph::build
...
Co-authored-by: Jamey Sharp <jamey@minilop.net>
Co-authored-by: Jamey Sharp <jamey@minilop.net>
…let's go with the simple thing for now.
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 think this is everything I have on elaboration. Gonna go back and recheck a couple other things but I'm almost done!
Co-authored-by: Jamey Sharp <jamey@minilop.net>
Co-authored-by: Jamey Sharp <jamey@minilop.net>
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.
Ship it! 🎉
Thanks so much for the detailed review -- it was really helpful! So ends one long saga, and begins another (actually using this thing) :-) |
I was curious about this so I've just compared the current merge-base from main (d68ca37) with this branch (ec8a1a9). I see a 1% improvement in compile time/CPU cycles/instructions retired on the bz2, pulldown-cmark, and spidermonkey benchmarks. Not 6% but definitely nice! |
The name "clif.isle" is stale (since bytecodealliance#4953), now two files "clif_lower.isle" and "clif_opt.isle" are generated. Not sure if that PR necessitates other changes this this doc.
* Small update for filename in `isle_integration.md` The name "clif.isle" is stale (since #4953), now two files "clif_lower.isle" and "clif_opt.isle" are generated. Not sure if that PR necessitates other changes this this doc. * Update cranelift/docs/isle-integration.md Co-authored-by: Jamey Sharp <jsharp@fastly.com>
This PR is a draft of an updated version of the egraph patch (and thus supersedes #4249) with the two parts already merged (multi-etors and the egraph crate proper) removed; it includes the Cranelift integration, the egraph build (CLIF to egraph) and elaboration (egraph to CLIF) algorithms, and rule application engine, as well as a set of rewrite rules that replaces the existing mid-end optimizations.
It still needs a bit more productionizing:
The purpose of this draft PR is to be a place to do this work on a rebased and up-to-date basis. (Lots happened since the original egraph work branched off in May, including incremental compilation and a good number of smaller changes.)
While patch-wrangling this week, I tried pulling this apart into smaller pieces, but the remaining bits are pretty cyclically entangled, and/or some of the intermediate points that might make sense (e.g. egraph build and elaboration without rule application) require re-synthesizing some scaffolding that would then disappear in the final state, so that seems a bit counterproductive. Once we have a polished state I can try pulling it apart into separate logical commits at least.