Commit graph

547 commits

Author SHA1 Message Date
ywenc
4a7d1a7062 ZJIT: Add IsNil optimization and tests for optimized hir 2025-06-30 17:04:15 -07:00
Max Bernstein
8f758de4c8 ZJIT: Rename Ruby<->Rust functions for clarity
No need to be so terse.
2025-06-30 19:21:42 -04:00
Max Bernstein
665da05141 ZJIT: Pretty-print symbols in HIR dump
This lets us better see what is going on, for example in pattern
matching code, which has a bunch of dynamic method lookups and
`respond_to?` sends.
2025-06-30 19:21:42 -04:00
Max Bernstein
e54a242bdf
ZJIT: Mark GetLocal as having no effects (#13750)
This removes the GetLocal of l3 from:

    def test
      l3 = 3
      1.times do |l2|
        _ = l3
        1
      end
    end
2025-06-30 15:15:43 -07:00
Max Bernstein
90247fb77d
ZJIT: Don't compile functions with unhandled parameter types (#13749) 2025-06-30 14:43:50 -07:00
Stan Lo
dc1b55a387
ZJIT: Add new ZJIT types for Set (#13743) 2025-06-30 09:58:32 -07:00
Takashi Kokubun
44e4b02754
ZJIT: setglobal should not return output (#13744)
* ZJIT: setglobal should not return output

* Let the caller wrap Some
2025-06-30 09:27:31 -07:00
Alan Wu
0828dff3f8 ZJIT: Codegen for defined?(yield)
Lots of stdlib methods such as Integer#times and Kernel#then use this,
so at least this will make writing tests slightly easier.
2025-06-28 00:03:42 +09:00
Alan Wu
32def14980 ZJIT: Use std::fmt::Display when codegen for instruction fails
It's nicer since e.g. you get text representation of enums like
`defined_type` instead of just a number.
2025-06-28 00:03:42 +09:00
Alan Wu
8e75a36129 ZJIT: Add TODOs and omitted test for nested scope local access 2025-06-27 20:42:38 +09:00
Alan Wu
b125fb56c9 ZJIT: Function::find(): Use find_vec!() more 2025-06-27 20:42:38 +09:00
Alan Wu
ed4b8d35a2 ZJIT: Function::find(): Use clone() instead of doing it manually 2025-06-27 20:42:38 +09:00
Alan Wu
7874321e82 ZJIT: Add codegen for GetLocal and SetLocal
They're only used when level≠0. Same EP hopping logic as interpreter and
YJIT. Change assert_compiles() to get ISeq by method name since the old
code didn't support methods defined using define_method() which I need
for the new test.
2025-06-27 20:42:38 +09:00
Alan Wu
ff09cf199d ZJIT: getlocal and setlocal to HIR 2025-06-27 20:42:38 +09:00
Takashi Kokubun
f8cd26736f
ZJIT: Stop loading an extra parameter (#13719) 2025-06-26 14:06:49 -07:00
Max Bernstein
aca692cd41
ZJIT: Disable profiling instructions before asserting opcodes in tests (#13720) 2025-06-26 16:24:22 -04:00
Nobuyoshi Nakada
152cf102b7
Remove trailing spaces 2025-06-24 18:30:54 +09:00
Max Bernstein
74e6bddf15
ZJIT: Parse putspecialobject(VMCore) into Const (#13683)
This way we get more information in HIR for the optimizer.

Fix https://github.com/Shopify/ruby/issues/587
2025-06-23 23:55:37 +00:00
Max Bernstein
3a9bf4a2ae
ZJIT: Optimize frozen array aref (#13666)
If we have a frozen array `[..., a, ...]` and a compile-time fixnum index `i`,
we can do the array load at compile-time.
2025-06-23 17:41:49 -05:00
ywenc
b1ce569ffc
ZJIT: anytostring to HIR (GH-13658)
Pop two values from the stack, return the first if it is a string,
otherwise return string coercion of the second

Also piggybacks a fix for string subclasses skipping `to_s` for
`objtostring`.

Co-authored-by: composerinteralia <composerinteralia@github.com>
2025-06-24 00:20:28 +09:00
Max Bernstein
6602a08aa5
ZJIT: Move ccall comments near ccall instructions (#13662)
Don't confuse them with other nearby instructions.
2025-06-21 09:15:05 +09:00
Hiroshi SHIBATA
b6babd9a07
ZJIT: Typofix (#13665) 2025-06-20 09:52:45 -07:00
Max Bernstein
9e33e043e5
ZJIT: Add pass to clean CFG (#13655)
We can fuse linked lists of blocks. This can be run any time, improves
future analyses, improves codegen, and also makes the HIR output look
nicer.

Inspired by my implementation of CleanCFG for Cinder, which was itself
inspired by Brett Simmers' implementation in HHVM.
2025-06-20 00:51:02 +00:00
ywenc
38d38bd5ce ZJIT: objtostring to HIR
Add a fast path for known strings at compile time, otherwise calls method id to_s using Insn::SendWithoutBlock

Co-authored-by: composerinteralia <composerinteralia@github.com>

More specific test name in zjit/src/hir.rs

Co-authored-by: Max Bernstein <tekknolagi@gmail.com>
2025-06-20 01:19:38 +09:00
Alan Wu
34eaa6418e ZJIT: Add dupn support 2025-06-19 23:29:37 +09:00
Alan Wu
963fc0abbc ZJIT: Implement opt_reverse 2025-06-19 20:38:13 +09:00
Daniel Colson
3290d3d7f0
ZJIT: Support invokebuiltin opcodes (#13632)
* `invokebuiltin`
* `invokebuiltin_delegate`
* `invokebuiltin_delegate_leave`

These instructions all call out to a C function, passing EC, self, and
some number of arguments. `invokebuiltin` gets the arguments from the
stack, whereas the `_delegate` instructions use a subset of the locals.

`opt_invokebuiltin_delegate_leave` has a fast path for `leave`, but I'm
not sure we need to do anything special for that here (FWIW YJIT appears
to treat the two delegate instructions the same).
2025-06-18 15:58:34 -07:00
Jean Boussier
fb68721f63 Rename imemo_class_fields -> imemo_fields 2025-06-17 15:28:05 +02:00
Alan Wu
0933400f45 ZJIT: Add codegen (and FrameState) for GetConstPath
Issue a call to rb_vm_opt_getconstant_path() like the interpreter, but
since that allocates the IC, we need to save the PC before calling. Add
FrameState to GetConstPath to get access to the PC.
2025-06-17 20:51:58 +09:00
Daniel Colson
01ff17fa40 ZJIT: Parse opt freeze insns to HIR
* `opt_hash_freeze`
* `opt_ary_freeze`
* `opt_str_freeze`
* `opt_str_uminus`

Similar to `opt_neq`, but there are no args for `freeze`

Co-authored-by: ywenc <ywenc@github.com>
Co-authored-by: Max Bernstein <max@bernsteinbear.com>
2025-06-17 20:35:47 +09:00
Daniel Colson
b1410c1c75 ZJIT: Add codegen for StringCopy
Prior to this commit we compiled `putstring` and `putchilledstring` to
`StringCopy`, but then failed to compile past HIR.

This commit adds codegen for `StringCopy` to call `rb_ec_str_ressurrect`
as the VM does for these instructions.
2025-06-17 08:20:07 +09:00
Stan Lo
cce4bfdca9
ZJIT: Add support for putspecialobject (#13565)
* ZJIT: Add support for putspecialobject

* Address feedback

* Update tests

* Adjust the indentation of a Ruby test

---------

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2025-06-16 12:24:33 -07:00
Jean Boussier
15084fbc3c Get rid of FL_EXIVAR
Now that the shape_id gives us all the same information, it's no
longer needed.
2025-06-13 23:50:30 +02:00
Max Bernstein
0674f7dfb5 ZJIT: Only write LIR output of HIR instructions with output 2025-06-13 08:54:35 -07:00
Max Bernstein
f208e017f2 ZJIT: Add codegen for SideExit 2025-06-13 08:54:35 -07:00
Takashi Kokubun
7fa3e1a1db
ZJIT: Write a callee frame on JIT-to-JIT calls (#13579)
Co-authored-by: Max Bernstein <tekknolagi@gmail.com>
2025-06-12 17:18:50 -07:00
Jean Boussier
e070d93573 Get rid of rb_shape_lookup 2025-06-12 17:08:22 +02:00
Jean Boussier
3abdd4241f Turn rb_classext_t.fields into a T_IMEMO/class_fields
This behave almost exactly as a T_OBJECT, the layout is entirely
compatible.

This aims to solve two problems.

First, it solves the problem of namspaced classes having
a single `shape_id`. Now each namespaced classext
has an object that can hold the namespace specific
shape.

Second, it open the door to later make class instance variable
writes atomics, hence be able to read class variables
without locking the VM.
In the future, in multi-ractor mode, we can do the write
on a copy of the `fields_obj` and then atomically swap it.

Considerations:

  - Right now the `RClass` shape_id is always synchronized,
    but with namespace we should likely mark classes that have
    multiple namespace with a specific shape flag.
2025-06-12 07:58:16 +02:00
Alan Wu
59fad961b8 ZJIT: x86: Fix panic writing 32-bit number with top bit set
Previously, `asm.mov(m32, imm32)` panicked when `imm32 > 0x80000000`. It
attempted to split imm32 into a register before doing the store, but
then the register size didn't match the destination size.

Instead of splitting, use the `MOV r/m32, imm32` form which works for
all 32-bit values. Adjust asserts that assumed that all forms undergo
sign extension, which is not true for this case.

See: 54edc930f9
2025-06-11 19:49:49 +09:00
Alan Wu
4ebe0a1ba5 ZJIT: Restore x86 assembler tests 2025-06-11 19:49:49 +09:00
Alan Wu
c489020cab ZJIT: Restore some A64 backend tests to fix unused warning 2025-06-11 19:49:49 +09:00
Alan Wu
0bc24353d3 ZJIT: Restore most x64 backend tests 2025-06-11 19:49:49 +09:00
Aaron Patterson
0f922edca0 ZJIT: Support get/set on global variables
Adds support for code like:

```ruby
$foo
$foo = x
```
2025-06-10 10:42:01 -07:00
Alan Wu
b8922a8d45 ZJIT: Parse opt_regexpmatch2 into HIR 2025-06-09 22:36:53 +09:00
Alan Wu
ec1244cfd2 ZJIT: Parse opt_not into HIR 2025-06-09 22:36:53 +09:00
Alan Wu
038087adf7 ZJIT: Parse opt_or into HIR 2025-06-09 22:36:53 +09:00
Alan Wu
1c43f7e966 ZJIT: Parse opt_and into HIR 2025-06-09 22:36:53 +09:00
Alan Wu
4a2480e79a ZJIT: Parse opt_succ into HIR 2025-06-09 22:36:53 +09:00
Alan Wu
9865aa94f7 ZJIT: Parse opt_empty_p into HIR 2025-06-09 22:36:53 +09:00
Jean Boussier
191f6e3b87 Get rid of rb_shape_t.heap_id 2025-06-07 18:30:44 +02:00