Skip to content

ZJIT #13131

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

Merged
merged 323 commits into from
Apr 18, 2025
Merged

ZJIT #13131

merged 323 commits into from
Apr 18, 2025

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Apr 18, 2025

This PR upstreams ZJIT to CRuby. [Feature #21221]

As the ticket clarifies, ZJIT is not yet ready for evaluation; it doesn't implement side exits or invalidations, so most benchmarks crash.

For now, YJIT and ZJIT cannot be enabled together. When rustc is available, YJIT is enabled by default, and ZJIT is disabled. If you configure with --enable-zjit, you can build ZJIT. We have a branch that allows to support YJIT and ZJIT in the same build, but that's going to be merged separately from this PR.

Some commit messages refer to PRs in Shopify/zjit to link past discussions. The repository is currently private, but we're going to publish it shortly.

This comment was marked as spam.

@k0kubun k0kubun force-pushed the zjit branch 4 times, most recently from 74a8e4c to 6b4db2d Compare April 18, 2025 11:13
@k0kubun k0kubun marked this pull request as ready for review April 18, 2025 12:51
@matzbot matzbot requested a review from a team April 18, 2025 12:51
aidenfoxivey and others added 25 commits April 18, 2025 21:53
* Remove redundant  statements

* Remove .clone() since A64 implements Copy

* Remove .clone() since InsnId implements Copy

.

* Dereference since *const rb_call_data implements Copy

* Remove unnecessary return statement

* Remove unnecessary braces

* Use .is_empty() over length checks

* Remove unnecessary conversion handling

Since i32 can always fit into i64 (the inner type in Opnd::Imm), the conversion is infallibile.

* Use slice notation in lieu of Vec

https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

* Simplify match statement
We want to return representatives for the stack and locals.
* Remove immediately deferenced borrow operators

source: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

* Remove unnecessary cast as i64

Since Const::CInt64 wraps i64, it is unnecessary to cast to i64.

* Remove unnecessary borrow operators

* Beautify assign operation syntax

* Use .is_null() convenience method

* Omit .into() call from u32 to u32

* Use more descriptive std::ptr::null<VALUE>()

In lieu of casting a literal as a type, opt to use the convenience type.

* Use sized integer literal

* Simplify pattern matching to explicit check
* Add --zjit-profile-interval option

* Fix min to max

* Avoid rewriting instructions for --zjit-call-threshold=1

* Rename the option to --zjit-num-profiles
* Disable ZJIT profiling at call-threshold

* Stop referencing ZJIT instructions in codegen
In case the callee writes to the caller's locals, we need to be able to
immediately side-exit because our frame's invariants might have been
invalidated.

If in the course of optimization we rewrite the Send, we can choose to
remove the PatchPoint too---but it's not an error to keep it around.
A new optimization pass. Also:
- Printing for `Insn::CCall`
- Wrap `ID` and add convenience method for printing, replacing calls to rb_id2name()
We don't want to only guard on the class
We need to keep the Snapshot instruction alive.
Helps with readability and threads type info that's there around for
longer. Amend test so `GuardType` doesn't DCE'ed.
* Implement JIT-to-JIT calls

* Use a closer dummy address for Arm64

* Revert an obsoleted change

* Revert a few more obsoleted changes

* Fix outdated comments

* Explain PosMarkers for CCall

* s/JIT code/machine code/

* Get rid of ParallelMov
* Show failing test

* Add second test case

* Add empty NewArray setup

* Update opt_tests and fix NewArray instantiation

* Add code generation for NewArray

* Add NewArray ordering test
This makes the output a little nicer when doing --zjit-dump-hir=all
@k0kubun k0kubun merged commit 0232c31 into ruby:master Apr 18, 2025
83 checks passed
@k0kubun k0kubun deleted the zjit branch April 18, 2025 13:47
@taketo1113 taketo1113 mentioned this pull request Apr 19, 2025
3 tasks
@maximecb
Copy link
Contributor

👏 👏 👏 👏 👏

🎉 🎉 🎉 🎉 🎉

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

Successfully merging this pull request may close these issues.

5 participants