91384 Commits

Author SHA1 Message Date
Max Bernstein
9dab8cd633 Remove Option from get_class_name parameter 2025-04-18 21:53:01 +09:00
Max Bernstein
308cd59bf8 Rewrite SendWithoutBlock to SendWithoutBlockDirect when possible
In calls to top-level functions, we assume that call targets will not
get rewritten, so we can insert a PatchPoint and do the lookup at
compile-time.
2025-04-18 21:53:01 +09:00
Takashi Kokubun
cfc9234ccd Compile Param into VReg and ParallelMov (https://github.com/Shopify/zjit/pull/87) 2025-04-18 21:53:01 +09:00
Takashi Kokubun
dd44935e8b Update the VReg comment to imply spilling 2025-04-18 21:53:01 +09:00
Takashi Kokubun
0a1ef1696e Disassociate InsnOut from Insn index 2025-04-18 21:53:01 +09:00
Max Bernstein
8220b91c21 Fix s/Raw/Debug/g 2025-04-18 21:53:01 +09:00
Max Bernstein
49b8368aa6 Print iseq names in HIR dumps 2025-04-18 21:53:01 +09:00
Max Bernstein
a86d187cda Add option to dump optimized HIR 2025-04-18 21:53:01 +09:00
Max Bernstein
0a38850524 Only map pointers in tests
We want to otherwise see real pointers in print output.
2025-04-18 21:53:01 +09:00
Max Bernstein
52fe40f030 Default to BasicObject subclass if unknown 2025-04-18 21:53:01 +09:00
Alan Wu
2cf769376b Add profiling for opt_send_without_block
Split out from the CCall changes since we discussed during pairing that
this is useful to unblock some other changes. No tests since no one
consumes this profiling data yet.
2025-04-18 21:53:01 +09:00
Max Bernstein
36d328eb99 Make disassembly look nicer using InsnPrinter
This makes the disassembly comments much easier to read because they use
the more familiar `v2` rather than `InsnId(2)` and `Fixnum` rather than
`Type { bits: ...... }`.
2025-04-18 21:53:01 +09:00
Max Bernstein
556fda0864 Use expect-test for HIR tests
This makes it easier to update cascading test failures while still
making output reviewable in the PR.
2025-04-18 21:53:01 +09:00
Max Bernstein
d9720eaf10 Add constant folding pass (https://github.com/Shopify/zjit/pull/74)
Add a constant folding pass for HIR. This pass uses the types left by
`infer_types` to fold away:

* `GuardType(val, ty)` where `val` is already `ty`
* `FixnumAdd(l, r)` where `l` and `r` are constants
* `FixnumLt(l, r)` where `l` and `r` are constants
* `FixnumEq(l, r)` where `l` and `r` are constants
* `Test(v)`, where `v` is a constant
* `IfTrue(v)` and `IfFalse(v)` where `v` is a constant

It does this by using the union-find data structure in the IR to avoid a
complicated manual find-and-replace process for all the uses. Right now, for
branch instructions that it deletes, we remove from the block completely. This
is safe only because we have ensured that nothing refers to branch
instructions---they produce no values. However, if we want to instead replace
them with Nops that get ignored during codegen or removed by a later DCE pass,
that works for me as well.
2025-04-18 21:53:01 +09:00
Maxime Chevalier-Boisvert
97a478f95f Add recursive factorial and fibonacci functions to test_zjit.rb 2025-04-18 21:53:01 +09:00
Max Bernstein
102c48c85f Don't compute predecessors for infer_types (https://github.com/Shopify/zjit/pull/78)
We don't need this anymore thanks to the push-driven type union for
basic block arguments.
2025-04-18 21:53:01 +09:00
Alan Wu
e5647d8bd9 Assert that ids are initialized
I've been bit by this a couple times.
2025-04-18 21:53:00 +09:00
Alan Wu
6421e89962 DRY up IDs that have the same content as their name 2025-04-18 21:53:00 +09:00
Max Bernstein
f4283c68bc Fix VALUE/isize conversion
Coming out of VALUE did not work for negative numbers; they came out as
huge numbers instead.

Add more tests.
2025-04-18 21:53:00 +09:00
Takashi Kokubun
6ec411add7 Compile IfFalse, IfTrue, and Jump instructions (https://github.com/Shopify/zjit/pull/72)
* Compile IfFalse instruction

* Add a TODO comment

* Rename *s_len to num_*s

* Run only gen_param() against block.params

* Add a few more tests

* Wrap label indexes with Label

* Compile blocks in reverse post-order

* Simplify a nested test

* s/get_block/block/

* Return a number instead of an iterator

* Clarify the allocator uses disjoint sets of registers

* Use Display for Block and Insn

* Compile IfTrue and Jump

* Avoid resolving Param instructions

* Always compile Insn::Param as basic block arguments

* Remove an obsoleted variable

* Change it back to use find

* Use find for params too

* Use Display more

* Add more tests

* nested if
* if after if
* if elsif else
* loop after loop
* nested loops
* if in loop
* loop in if
2025-04-18 21:53:00 +09:00
Alan Wu
efb2ba3338 HIR printing: Assign stable address to pointers when first seen
This gives output stability while still showing address equality and
inequality.

This mapping mechanism is only turned on for FunctionPrinter, so
implementation of Display and Debug can share the same code but not go
through the mapping process. Outside of `cfg!(test)` we don't want
and need to stabilize the addresses.
2025-04-18 21:53:00 +09:00
Max Bernstein
a5330afed9 Fix another case of single-arm match 2025-04-18 21:53:00 +09:00
Max Bernstein
eb3045f23d Make reverse post-order traversal iterative 2025-04-18 21:53:00 +09:00
Takashi Kokubun
6a8150fc27 Refactor push_fixnum_insn! further (https://github.com/Shopify/zjit/pull/70)
* Refactor push_fixnum_insn! further

* Take one or zero extra argument
2025-04-18 21:53:00 +09:00
Max Bernstein
263a1f2bb3 Use a more noticeable invalid pointer 2025-04-18 21:53:00 +09:00
Max Bernstein
f525cff5c8 Test builtin type inference 2025-04-18 21:53:00 +09:00
Max Bernstein
4a4845cec8 Fix type checking for strings, arrays, and hashes in the constant pool
Prism hides the objects from the GC by setting the objects' class fields
to 0, so class_of returns 0 (unexpectedly, at least to me). Instead, use
builtin_type.
2025-04-18 21:53:00 +09:00
Max Bernstein
be874df1c4 Print fake/stable addresses in HIR printer in tests 2025-04-18 21:53:00 +09:00
Max Bernstein
92b87ec53f Convert send (with block) to HIR (https://github.com/Shopify/zjit/pull/67)
* Convert send (with block) to HIR

* Remove newline

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>

---------

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
2025-04-18 21:53:00 +09:00
Takashi Kokubun
d750e12fa6 Revert "Pass $state to fallbacks instead of exit_state"
This reverts commit e2eae71d44ced602946d54a083f600848eab79e9.

The $state exists for switching Fixnum insn, so guard_two_fixnums and
SendWithoutBlock shouldn't need to use $state. The other macro argument
pattern doesn't have $state, so it's now inconsistent.
2025-04-18 21:53:00 +09:00
Takashi Kokubun
c460b16272 Pass $state to fallbacks instead of exit_state 2025-04-18 21:53:00 +09:00
Takashi Kokubun
d488f74dee Resurrect icache invalidation for arm64 (https://github.com/Shopify/zjit/pull/68)
* Resurrect icache invalidation for arm64

* Get rid of cfg(not(test))
2025-04-18 21:53:00 +09:00
Takashi Kokubun
00cc26d04e Refactor Fixnum operations using macros 2025-04-18 21:53:00 +09:00
Takashi Kokubun
ae17323a65 Move a couple of bindgen targets to ZJIT bindgen
We filed https://github.com/Shopify/zjit/pull/65 and
https://github.com/Shopify/zjit/pull/64 concurrently.
2025-04-18 21:53:00 +09:00
Takashi Kokubun
f5c3fc877e Rename a reference to an obsoleted variable 2025-04-18 21:53:00 +09:00
Alan Wu
19e8e45f69 Rust tests: Load builtins (core library written in ruby)
Key here is calling rb_call_builtin_inits(), which sticking to public
API for robustness is done by calling ruby_options().

Fixes: https://github.com/Shopify/zjit/issues/61
2025-04-18 21:53:00 +09:00
Takashi Kokubun
fa7c3e6c9c Implement dynamic dispatch for opt_send_without_block (https://github.com/Shopify/zjit/pull/63)
* Implement dynamic dispatch for opt_send_without_block

* Rename stack methods

* Fix typos

* More clarification on gen_save_sp()

* Update a comment

* Update a comment about spills

* Rename name to method_name

* Test no-arg and 2-arg method calls
2025-04-18 21:53:00 +09:00
Takashi Kokubun
5a35c47c82 Stop sharing yjit/bindgen with ZJIT (https://github.com/Shopify/zjit/pull/64)
* cp -r yjit/bindgen zjit/

* Rename YJIT variables

* Stop mentioning YJIT in zjit.c
2025-04-18 21:53:00 +09:00
Takashi Kokubun
d492734d14 Fix a ubuntu job with --disable-zjit 2025-04-18 21:53:00 +09:00
Takashi Kokubun
bb46bb781c Stub Init_builtin_zjit for --disable-zjit 2025-04-18 21:53:00 +09:00
Takashi Kokubun
31121a9107 Avoid running the same test in multiple workflows
This workflow is supposed to test that we didn't mess up the
interpreter's implementation. We shouldn't need to run test_zjit.rb on
this workflow.
2025-04-18 21:53:00 +09:00
Max Bernstein
97f022b5e7 Print Ruby exception in test utils 2025-04-18 21:53:00 +09:00
Maxime Chevalier-Boisvert
c39a150787 Implement codegen for Test insn (https://github.com/Shopify/zjit/pull/57)
* Implement codegen for Test insn

* Update zjit/src/codegen.rs

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2025-04-18 21:53:00 +09:00
Maxime Chevalier-Boisvert
b345fa9006 Reorder two tests, update comment 2025-04-18 21:53:00 +09:00
Maxime Chevalier-Boisvert
b9424e5096 Remove redundant bits from zjit.md 2025-04-18 21:53:00 +09:00
Max Bernstein
9ca67c471d Explicitly give function parameters types (https://github.com/Shopify/zjit/pull/52)
* Explicitly give function parameters types

Entrypoint blocks have no predecessors, so they are not otherwise typed.
This means we have to explicitly mark them as being Object.

* Refactor some tests
2025-04-18 21:53:00 +09:00
Max Bernstein
4c694a4c15 Replace ...User with ...Subclass 2025-04-18 21:53:00 +09:00
Max Bernstein
ca4d09137b Add union and predicates for testing if immediate (https://github.com/Shopify/zjit/pull/54)
* Add union and predicates for testing if immediate

* Add tests

* Improve description for Primitive

* Add undef to immediates

Also partition Any into (Primitive | Value), where Value is
(Object | Undef)

* Add BasicObject to hierarchy

* Rename Value to RubyValue and Primitive to CValue
2025-04-18 21:52:59 +09:00
Takashi Kokubun
125d87b92b Prefix stack operation names with stack_ 2025-04-18 21:52:59 +09:00
Takashi Kokubun
6a4db3e1d7 Put hir_type sources in a sub-folder 2025-04-18 21:52:59 +09:00