Граф коммитов

73390 Коммитов

Автор SHA1 Сообщение Дата
Kevin Newton f883aabc13 Instruction enum (https://github.com/Shopify/ruby/pull/423)
* Remove references to explicit instruction parts

Previously we would reference individual instruction fields
manually. We can't do that with instructions that are enums, so
this commit removes those references. As a side effect, we can
remove the push_insn_parts() function from the assembler because we
now explicitly push instruction structs every time.

* Switch instructions to enum

Instructions are now no longer a large struct with a bunch of
optional fields. Instead they are an enum with individual shapes
for the variants.

In terms of size, the instruction struct was 120 bytes while the
new instruction enum is 106 bytes. The bigger win however is that
we're not allocating any vectors for instruction operands (except
for CCall), which should help cut down on memory usage.

Adding new instructions will be a little more complicated going
forward, but every mission-critical function that needs to be
touched will have an exhaustive match, so the compiler should guide
any additions.
2022-08-29 09:09:41 -07:00
Alan Wu ea9ee31744 A64 Linux reports aarach64 in RUBY_PLATFORM
This should fix a version string test
2022-08-29 09:09:41 -07:00
Kevin Newton 1c67e90bde More work toward instruction enum (https://github.com/Shopify/ruby/pull/421)
* Operand iterators

There are a couple of times when we're dealing with instructions
that we need to iterate through their operands. At the moment this
is relatively easy because there's an opnds field and we can work
with it directly. When the instructions become enums, however, the
shape of each variant will be different so we'll need an iterator
to make sense of the shape.

This commit introduces two new iterators that are created from an
instruction. One iterates over references to each operand (for
instances where they don't need to be mutable like updating live
ranges) and one iterates over mutable references to each operand
(for instances where you need to mutate them like loading values in
arm64).

Note that because iterators can't have generic items (i.e., be
associated with lifetimes) the mutable iterator forces you to use
the `while let Some` syntax as opposed to the for-loop like we did
with instructions.

This commit eliminates the last reference to insn.opnds, which is
going to make it much easier to transition to an enum.

* Consolidate output operand fetching

Currently we always look at the .out field on instructions whenever
we want to access the output operand. When the instructions become
an enum, this is not going to be possible since the shape of the
variants will be different. Instead, this commit introduces two
functions on Insn: out_opnd() and out_opnd_mut(). These return an
Option containing a reference to the output operand and a mutable
reference to the output operand, respectively.

This commit then uses those functions to replace all instances of
accessing the output operand. For the most part this was
straightforward; when we previously checked if it was Opnd::None
we now check that it's None, when we assumed there was an output
operand we now unwrap.
2022-08-29 09:09:41 -07:00
Alan Wu 342459576d Use VALUE for callinfos that are on the heap (https://github.com/Shopify/ruby/pull/420)
Yet another case of `jit_mov_gc_ptr()` being yanked out during the
transition to the new backend, causing a crash after object movement.
The intresting wrinkle with this one is that not all callinfos are GC'ed
objects, so the old code had an implicit assumption.

b0b9f7201a/yjit/src/codegen.rs (L4087-L4095)
2022-08-29 09:09:41 -07:00
Takashi Kokubun 5114ddce3f Avoid marking op_type on gen_defined (https://github.com/Shopify/ruby/pull/419) 2022-08-29 09:09:41 -07:00
Takashi Kokubun a78bbef12f Use VALUE for block_iseq (https://github.com/Shopify/ruby/pull/417)
Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
2022-08-29 09:09:41 -07:00
Takashi Kokubun e0e63b1a01 Fix a bus error on regenerate_branch (https://github.com/Shopify/ruby/pull/408)
* Fix a bus error on regenerate_branch

* Fix pad_size
2022-08-29 09:09:41 -07:00
Kevin Newton b00606eb64 Even more prep for instruction enum (https://github.com/Shopify/ruby/pull/413)
* Mutate in place for register allocation

Currently we allocate a new instruction every time when we're
doing register allocation by first splitting up the instruction
into its component parts, mapping the operands and the output, and
then pushing all of its parts onto the new assembler.

Since we don't need the old instruction, we can mutate the existing
one in place. While it's not that big of a win in and of itself, it
matches much more closely to what we're going to have to do when we
switch the instruction from being a struct to being an enum,
because it's much easier for the instruction to modify itself since
it knows its own shape than it is to push a new instruction that
very closely matches.

* Mutate in place for arm64 split

When we're splitting instructions for the arm64 backend, we map all
of the operands for a given instruction when it has an Opnd::Value.
We can do this in place with the existing operand instead of
allocating a new vector each time. This enables us to pattern match
against the entire instruction instead of just the opcode, which is
much closer to matching against an enum.

* Match against entire instruction in arm64_emit

Instead of matching against the opcode and then accessing all of
the various fields on the instruction when emitting bytecode for
arm64, we should instead match against the entire instruction.
This makes it much closer to what's going to happen when we switch
it over to being an enum.

* Match against entire instruction in x86_64 backend

When we're splitting or emitting code for x86_64, we should match
against the entire instruction instead of matching against just the
opcode. This gets us closer to matching against an enum instead of
a struct.

* Reuse instructions for arm64_split

When we're splitting, the default behavior was previously to split
up the instruction into its component parts and then reassemble
them in a new instruction. Instead, we can reuse the existing
instruction.
2022-08-29 09:09:41 -07:00
Alan Wu c70d1471c1 Only check lowest bit for _Bool type (https://github.com/Shopify/ruby/pull/412)
* Only check lowest bit for _Bool type

The `test AL, AL` got lost during porting and we were
generating `test RAX, RAX` instead. The upper bits of a `_Bool` return
type is unspecified and we were failing
`TestClass#test_singleton_class_should_has_own_namespace`
due to interpreterting the return value incorrectly.

* Enable test_class for test-all on x86_64
2022-08-29 09:09:41 -07:00
Kevin Newton d57a9f61a0
Build output operands explicitly (https://github.com/Shopify/ruby/pull/411)
When we're pushing instructions onto the assembler, we previously
would iterate through the instruction's operands and then assign
the output operand to it through the push_insn function. This is
easy when all instructions have a vector of operands, but is much
more difficult when the shape differs in an enum.

This commit changes it so that we explicitly define the output
operand for each instruction before it gets pushed onto the
assembler. This has the added benefit of changing the definition
of push_insn to no longer require a mutable instruction.

This paves the way to make the out field on the instructions an
Option<Opnd> instead which is going to more accurately reflect
the behavior we're going to have once we switch the instructions
over to an enum instead of a struct.
2022-08-29 08:47:11 -07:00
Kevin Newton b735eb5ef3
Instruction builders for backend IR (https://github.com/Shopify/ruby/pull/410)
Currently we use macros to define the shape of each of the
instruction building methods. This works while all of the
instructions share the same fields, but is really hard to get
working when they're an enum with different shapes. This is an
incremental step toward a bigger refactor of changing the Insn
from a struct to an enum.
2022-08-29 08:47:11 -07:00
Maxime Chevalier-Boisvert 1cf9f56c55
Fix issue with expandarray, add missing jl, enable tests (https://github.com/Shopify/ruby/pull/409) 2022-08-29 08:47:11 -07:00
Takashi Kokubun c38e911147
Allow aarch64 to build YJIT 2022-08-29 08:47:11 -07:00
Maxime Chevalier-Boisvert 95dce1ccac
Temporarily disable rb_str_concat, add CI tests (https://github.com/Shopify/ruby/pull/407)
Make sure we can load the test-all runner and run test_yjit.rb
2022-08-29 08:47:11 -07:00
Noah Gibbs (and/or Benchmark CI) 09c12111d4
Port jit_rb_str_concat to new backend, re-enable cfunc lookup (https://github.com/Shopify/ruby/pull/402) 2022-08-29 08:47:11 -07:00
Maple Ong 5a76a15a0f
YJIT: Implement concatarray in yjit (https://github.com/Shopify/ruby/pull/405)
* Create code generation func

* Make rb_vm_concat_array available to use in Rust

* Map opcode to code gen func

* Implement code gen for concatarray

* Add test for concatarray

* Use new asm backend

* Add comment to C func wrapper
2022-08-29 08:47:11 -07:00
Alan Wu 2f9df46654
Use bindgen for old manual extern declarations (https://github.com/Shopify/ruby/pull/404)
We have a large extern block in cruby.rs leftover from the port. We can
use bindgen for it now and reserve the manual declaration for just a
handful of vm_insnhelper.c functions.

Fixup a few minor discrepencies bindgen found between the C declaration
and the manual declaration. Mostly missing `const` on the C side.
2022-08-29 08:47:11 -07:00
Kevin Newton ff3f1d15d2
Optimize bitmask immediates (https://github.com/Shopify/ruby/pull/403) 2022-08-29 08:47:11 -07:00
Kevin Newton be730cdae5
AArch64 Ruby immediates (https://github.com/Shopify/ruby/pull/400) 2022-08-29 08:47:10 -07:00
Maxime Chevalier-Boisvert c022a60540
Fix bugs in gen_opt_getinlinecache 2022-08-29 08:47:10 -07:00
Zack Deveau cb15886e61
Port opt_getinlinecache to the new backend (https://github.com/Shopify/ruby/pull/399) 2022-08-29 08:47:10 -07:00
Takashi Kokubun dca5e74aa1
Fix test_rubyoptions.rb for arm64 (https://github.com/Shopify/ruby/pull/396) 2022-08-29 08:47:10 -07:00
Noah Gibbs 471de2ab78
Enable skipdata on Capstone to allow embedded data without early stop to disasm (https://github.com/Shopify/ruby/pull/398) 2022-08-29 08:47:10 -07:00
Kevin Newton 7f4ab24f2b
Op::Xor for backend IR (https://github.com/Shopify/ruby/pull/397) 2022-08-29 08:47:10 -07:00
Alan Wu 4d811d7a2b
Fix code invalidation while OOM and OOM simulation (https://github.com/Shopify/ruby/pull/395)
`YJIT.simulate_oom!` used to leave one byte of space in the code block,
so our test didn't expose a problem with asserting that the write
position is in bounds in `CodeBlock::set_pos`. We do the following when
patching code:
  1. save current write position
  2. seek to middle of the code block and patch
  3. restore old write position
The bounds check fails on (3) when the code block is already filled up.

Leaving one byte of space also meant that when we write that byte, we
need to fill the entire code region with trapping instruction in
`VirtualMem`, which made the OOM tests unnecessarily slow.

Remove the incorrect bounds check and stop leaving space in the code
block when simulating OOM.
2022-08-29 08:47:10 -07:00
Takashi Kokubun ee1697ee07
Port opt_aref and opt_aset to the new backend IR (https://github.com/Shopify/ruby/pull/387)
* Port opt_aref and opt_aset to the new backend IR

* Recompute memory operands
2022-08-29 08:47:10 -07:00
Maxime Chevalier-Boisvert b54643d13a
Handle out of memory tests (https://github.com/Shopify/ruby/pull/393) 2022-08-29 08:47:10 -07:00
Takashi Kokubun df84832c75
Port getblockparamproxy and getblockparam (https://github.com/Shopify/ruby/pull/394) 2022-08-29 08:47:10 -07:00
Takashi Kokubun e5969f8587
Port invokesuper to the new backend IR (https://github.com/Shopify/ruby/pull/391) 2022-08-29 08:47:10 -07:00
Takashi Kokubun ca2afba4a7
Port the remaining method types in opt_send_without_block (https://github.com/Shopify/ruby/pull/390) 2022-08-29 08:47:09 -07:00
Maxime Chevalier-Boisvert 8c45b8a989
Update asm comments for gen_send_iseq 2022-08-29 08:47:09 -07:00
Noah Gibbs 6b9cec78a1
Port cfunc lookup, plus simpler cfunc generators. (https://github.com/Shopify/ruby/pull/388)
This port does *not* create invalidation regions to
ensure minimum invalidatable block sizes, and so it
does not port the to_s generator.
2022-08-29 08:47:09 -07:00
Maxime Chevalier-Boisvert cad35fb25c
Try to run make -j in CI backend tests (https://github.com/Shopify/ruby/pull/386) 2022-08-29 08:47:09 -07:00
Takashi Kokubun 1cafb1a7a6
Prefer asm.store over asm.mov (https://github.com/Shopify/ruby/pull/385)
* Prefer asm.store over asm.mov

* Reverse a couple of unsure changes

* Revert changes that don't work
2022-08-29 08:47:09 -07:00
Kevin Newton 3f42028e3e
Iterator (https://github.com/Shopify/ruby/pull/372)
* Iterator

* Use the new iterator for the X86 backend split

* Use iterator for reg alloc, remove forward pass

* Fix up iterator usage on AArch64

* Update yjit/src/backend/ir.rs

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>

* Various PR feedback for iterators for IR

* Use a local mutable reference for a64_split

* Move tests from ir.rs to tests.rs in backend

* Fix x86 shift instructions live range calculation

* Iterator

* Use the new iterator for the X86 backend split

* Fix up x86 iterator usage

* Fix ARM iterator usage

* Remove unintentionally duplicated tests
2022-08-29 08:47:09 -07:00
Takashi Kokubun 49c9f893f8
Port expandarray to the new backend IR (https://github.com/Shopify/ruby/pull/376)
* Port expandarray to the new backend IR

* More use of into()

* Break out live ranges

* Refactor the code further

* Reuse registers more
2022-08-29 08:47:09 -07:00
Takashi Kokubun 668b99b43b
Port gen_send_iseq to the new backend IR (https://github.com/Shopify/ruby/pull/381)
* Port gen_send_iseq to the new backend IR

* Replace occurrences of 8 by SIZEOF_VALUE

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
2022-08-29 08:47:09 -07:00
Maxime Chevalier-Boisvert 32d9eef562
Enable test_literal.rb and test_ractor.rb on arm 2022-08-29 08:47:09 -07:00
Kevin Newton cd7506593a
Fix tests on yjit_backend_ir for AArch64 backend (https://github.com/Shopify/ruby/pull/383) 2022-08-29 08:47:09 -07:00
Kevin Newton b8846dd2f8
Load mem displacement when necessary on AArch64 (https://github.com/Shopify/ruby/pull/382)
* LDR instruction for AArch64

* Split loads in arm64_split when memory address displacements do not fit
2022-08-29 08:47:08 -07:00
Maxime Chevalier-Boisvert 85d6d76e41
Enable test_insns.rb on arm 2022-08-29 08:47:08 -07:00
Kevin Newton a5ea577cc6
Update flags for data processing on ARM (https://github.com/Shopify/ruby/pull/380)
* Update flags for data processing on ARM

* Update yjit/src/backend/arm64/mod.rs

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2022-08-29 08:47:08 -07:00
Alan Wu a375784275
Use new assembler to support global invalidation on A64
Previously, we patched in an x64 JMP even on A64, which resulted in
invalid machine code. Use the new assembler to generate a jump instead.

Add an assert to make sure patches don't step on each other since it's
less clear cut on A64, where the size of the jump varies depending on
its placement relative to the target.

Fixes a lot of tests that use `set_trace_func` in `test_insns.rb`.

PR: https://github.com/Shopify/ruby/pull/379
2022-08-29 08:47:08 -07:00
Takashi Kokubun 726a451955
Port invokebuiltin* insns to the new backend IR (https://github.com/Shopify/ruby/pull/375)
* Port invokebuiltin* insns to the new backend IR

* Fix the C_ARG_OPNDS check boundary
2022-08-29 08:47:08 -07:00
Maxime Chevalier-Boisvert 46822ee13f
Enable btests now passing on arm (https://github.com/Shopify/ruby/pull/378) 2022-08-29 08:47:08 -07:00
Kevin Newton 8278d72290
Left and right shift for IR (https://github.com/Shopify/ruby/pull/374)
* Left and right shift for IR

* Update yjit/src/backend/x86_64/mod.rs

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2022-08-29 08:47:08 -07:00
Alan Wu 8fffff536d
More concise csel with Into 2022-08-29 08:47:08 -07:00
Takashi Kokubun 2429635bc7
Port send to the new backend and test it (https://github.com/Shopify/ruby/pull/373) 2022-08-29 08:47:08 -07:00
Takashi Kokubun ffdd09e22a
Port opt_eq and opt_neq to the new backend (https://github.com/Shopify/ruby/pull/371)
* Port opt_eq and opt_neq to the new backend

* Just use into() outside

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

* Use C_RET_OPND to share the register

* Revert "Use C_RET_OPND to share the register"

This reverts commit 99381765d0008ff0f03ea97c6c8db608a2298e2b.

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2022-08-29 08:47:08 -07:00
Takashi Kokubun 2b85295d28
Port objtostring to the new backend (https://github.com/Shopify/ruby/pull/369) 2022-08-29 08:47:07 -07:00