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

368 Коммитов

Автор SHA1 Сообщение Дата
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
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
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
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
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
Zack Deveau e06c86fada
Port opt_str_uminus to new backend IR (https://github.com/Shopify/ruby/pull/370) 2022-08-29 08:47:07 -07:00
Zack Deveau db22a560a4
Port gen_opt_str_freeze to new backend IR (https://github.com/Shopify/ruby/pull/366) 2022-08-29 08:47:07 -07:00
Noah Gibbs 0a680912e9
x86 TEST should do a load for mem opnds first (https://github.com/Shopify/ruby/pull/368) 2022-08-29 08:47:07 -07:00
Takashi Kokubun 7908eabf6f
Port setivar to the new backend IR (https://github.com/Shopify/ruby/pull/362)
* Port setivar to the new backend IR

* Add a few more setivar test cases

* Prefer const_ptr

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2022-08-29 08:47:07 -07:00
Takashi Kokubun a55a3f8ad1
Port opt_minus, opt_or, and opt_and to the new IR (https://github.com/Shopify/ruby/pull/364)
* Port opt_minus, opt_or, and opt_and to the new IR

* Fix the Op::Or issue with push_insn

* Prefer asm.store for clarity
2022-08-29 08:47:07 -07:00
Takashi Kokubun dcb6fc16e5
Port opt_mod to the new backend IR (https://github.com/Shopify/ruby/pull/363) 2022-08-29 08:47:07 -07:00
Maxime Chevalier-Boisvert e24037267f
Add Opnd::None error message to x86 backend as well 2022-08-29 08:47:07 -07:00
Noah Gibbs d131b41025
Fix to float guard in jit_guard_known_klass to use the correct output operand. (https://github.com/Shopify/ruby/pull/365) 2022-08-29 08:47:07 -07:00
Takashi Kokubun 74527a764d
Port send-only insns and write tests (https://github.com/Shopify/ruby/pull/360) 2022-08-29 08:47:07 -07:00
Maxime Chevalier-Boisvert b024b18f56
Fix block invalidation with new backend. Enable more btests on x86 (https://github.com/Shopify/ruby/pull/359) 2022-08-29 08:47:06 -07:00
Alan Wu ddee4d3af8
Opnd::Value fixes (https://github.com/Shopify/ruby/pull/354)
* Fix asm.load(VALUE)

- `<VALUE as impl Into<Opnd>>` didn't track that the value is a value
- `Iterator::map` doesn't evaluate the closure you give it until you
  call `collect`. Use a for loop instead so we put the gc offsets
  into the compiled block properly.

* x64: Mov(mem, VALUE) should load the value first

Tripped in codegen for putobject now that we are actually feeding
`Opnd::Value` into the backend.

* x64 split: Canonicallize VALUE loads

* Update yjit/src/backend/x86_64/mod.rs
2022-08-29 08:47:06 -07:00
Takashi Kokubun 4539c21367
Port gen_send_cfunc to the new backend (https://github.com/Shopify/ruby/pull/357)
* Port gen_send_cfunc to the new backend

* Remove an obsoleted test

* Add more cfunc tests

* Use csel_e instead and more into()

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

* Add a missing lea for build_kwargs

* Split cfunc test cases

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2022-08-29 08:47:06 -07:00
Maxime Chevalier-Boisvert c91a44cba4
Fix forward_pass usage in arm backend following John's PR 2022-08-29 08:47:06 -07:00
John Hawthorn 24ddc07d6e
Fix live_ranges idx calculation (https://github.com/Shopify/ruby/pull/353)
forward_pass adjusts the indexes of our opnds to reflect the new
instructions as they are generated in the forward pass. However, we were
using the old live_ranges array, for which the new indexes are
incorrect.

This caused us to previously generate an IR which contained unnecessary
trivial load instructions (ex. mov rax, rax), because it was looking at
the wrong lifespans. Presumably this could also cause bugs because the
lifespan of the incorrectly considered operand idx could be short.

We've added an assert which would have failed on the previous trivial
case (but not necessarily all cases).

Co-authored-by: Matthew Draper <matthew@trebex.net>
2022-08-29 08:47:06 -07:00
Takashi Kokubun fe172aac04
Convert getinstancevariable to new backend IR (https://github.com/Shopify/ruby/pull/352)
* Convert getinstancevariable to new backend IR

* Support mem-based mem

* Use more into()

* Add tests for getivar

* Just load obj_opnd to a register

* Apply another into()

* Flip the nil-out condition

* Fix duplicated counts of side_exit
2022-08-29 08:47:06 -07:00
Kevin Newton a95422a691
Binary OR instruction for the IR (https://github.com/Shopify/ruby/pull/355) 2022-08-29 08:47:06 -07:00
Maxime Chevalier-Boisvert 9db2ca723c
Add 1 more allocatable reg on arm 2022-08-29 08:47:06 -07:00
Maxime Chevalier-Boisvert ca68ccdadd
Fix C call reg alloc bug reported by Noah & Kokubun 2022-08-29 08:47:06 -07:00
Kevin Newton 0823260546
Implement iterators and double-linked list for IR SSA 2022-08-29 08:47:05 -07:00
Maxime Chevalier-Boisvert a75a6f7d7a
Remove empty lines 2022-08-29 08:47:05 -07:00
Zack Deveau dea4238544
Port gen_concatstring to new backend IR (https://github.com/Shopify/ruby/pull/350)
* Port gen_concatstring to new backend IR

* Update yjit/src/codegen.rs

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2022-08-29 08:47:05 -07:00
Takashi Kokubun 330c9e9850
Port anytostring, intern, and toregexp (https://github.com/Shopify/ruby/pull/348)
* Port anytostring, intern, and toregexp

* Port getspecial to the new backend (#349)

PR: https://github.com/Shopify/ruby/pull/349
2022-08-29 08:47:05 -07:00
Takashi Kokubun 16307adf8f
Port only ATTRSET of opt_send_without_block (https://github.com/Shopify/ruby/pull/351) 2022-08-29 08:47:05 -07:00
Maxime Chevalier-Boisvert 45da697450
Push first pass at SSA IR sketch 2022-08-29 08:47:05 -07:00
Takashi Kokubun a674b8d8a1
Port class variable instructions (https://github.com/Shopify/ruby/pull/346) 2022-08-29 08:47:05 -07:00
Takashi Kokubun 1446e22aeb
Port setglobal to the new backend (https://github.com/Shopify/ruby/pull/347) 2022-08-29 08:47:05 -07:00
Alan Wu 869b0ba6e0
Minor cleanups (https://github.com/Shopify/ruby/pull/345)
* Move allocation into Assembler::pos_marker

We wanted to do this to begin with but didn't because we were confused
about the lifetime parameter. It's actually talking about the lifetime
of the references that the closure captures. Since all of our usages
capture no references (they use `move`), it's fine to put a `+ 'static`
here.

* Use optional token syntax for calling convention macro

* Explicitly request C ABI on ARM

It looks like the Rust calling convention for functions are the same as
the C ABI for now and it's unlikely to change, but it's easy for us to
be explicit here. I also tried saying `extern "aapcs"` but that
unfortunately doesn't work.
2022-08-29 08:47:05 -07:00
Zack Deveau 6ab71a8598
Port gen_checktype to the new IR assembler backend (https://github.com/Shopify/ruby/pull/343) 2022-08-29 08:47:05 -07:00
Noah Gibbs 4b1ab009c4
Port the YJIT defined opcode; fix C_ARG_REGS (https://github.com/Shopify/ruby/pull/342) 2022-08-29 08:47:05 -07:00
Alan Wu b2d255ad3c
A64: Fix off by one in offset encoding for BL (https://github.com/Shopify/ruby/pull/344)
* A64: Fix off by one in offset encoding for BL

It's relative to the address of the instruction not the end of it.

* A64: Fix off by one when encoding B

It's relative to the start of the instruction not the end.

* A64: Add some tests for boundary offsets
2022-08-29 08:47:04 -07:00
Maxime Chevalier-Boisvert 2d9b98f9bc
Fix a bug in the x86 backend wrt large integer values, enable more tests 2022-08-29 08:47:04 -07:00
Noah Gibbs c9a947e5d8
Port and test checkkeyword (https://github.com/Shopify/ruby/pull/339) 2022-08-29 08:47:04 -07:00
Alan Wu 8617bac950
Fix IncrCounter on ARM
The order of operands to LDADDAL were flipped and the destination
pointer was dereferenced instead of passed as an address.
2022-08-29 08:47:04 -07:00
Alan Wu 813df1f27a
Add LiveReg IR instruction to fix stats leave exit code (https://github.com/Shopify/ruby/pull/341)
It allows for reserving a specific register and prevents the register
allocator from clobbering it. Without this
`./miniruby --yjit-stats --yjit-callthreshold=1 -e0` was crashing because
the counter incrementing code was clobbering RAX incorrectly.
2022-08-29 08:47:04 -07:00
Kevin Newton 13e5b56a5d
Fixes (https://github.com/Shopify/ruby/pull/340)
* Fix conditional jumps to label

* Bitmask immediates cannot be u64::MAX
2022-08-29 08:47:04 -07:00
Kevin Newton f593b2c6db
Fixes for AArch64 (https://github.com/Shopify/ruby/pull/338)
* Better splitting for Op::Add, Op::Sub, and Op::Cmp

* Split stores if the displacement is too large

* Use a shifted immediate argument

* Split all places where shifted immediates are used

* Add more tests to the cirrus workflow
2022-08-29 08:47:04 -07:00
Noah Gibbs b1ed4d9b94
Port and test duparray and splatarray (https://github.com/Shopify/ruby/pull/337)
* Port duparray opcode

* Port and test splatarray
2022-08-29 08:47:03 -07:00
Maxime Chevalier-Boisvert e9f9b8f43b
Fix bug with opt_lt, csel on x86 2022-08-29 08:47:03 -07:00
Maxime Chevalier-Boisvert 477c2df3fa
Work on opt_lt, fix x86 backend bug in cmp() 2022-08-29 08:47:03 -07:00
Kevin Newton 70e117d512
Fixes (https://github.com/Shopify/ruby/pull/336)
* Fix bitmask encoding to u32

* Fix splitting for Op::And to account for bitmask immediate
2022-08-29 08:47:03 -07:00
Kevin Newton 76b05ba9e8
Better splitting for Op::Test on AArch64 (https://github.com/Shopify/ruby/pull/335) 2022-08-29 08:47:03 -07:00
Maxime Chevalier-Boisvert b1dbc5f1a6
Fix crash in newhash ccall 2022-08-29 08:47:03 -07:00
Maxime Chevalier-Boisvert 8605efdd94
Fix corrupted X29 causing segfault, thanks Alan! 2022-08-29 08:47:03 -07:00
Maxime Chevalier-Boisvert 85872eecdd
Port over newrange 2022-08-29 08:47:03 -07:00
Maxime Chevalier-Boisvert 8d2560f1f5
Port over setlocal and getglobal 2022-08-29 08:47:02 -07:00
Maxime Chevalier-Boisvert 8259813bc3
Temporarily simplify code for emit_conditional_jump to fix a bug 2022-08-29 08:47:02 -07:00
Maxime Chevalier-Boisvert f833d75bee
Refactor YJIT branches to use PosMarker (https://github.com/Shopify/ruby/pull/333)
* Refactor defer_compilation to use PosMarker

* Port gen_direct_jump() to use PosMarker

* Port gen_branch, branchunless

* Port over gen_jump()

* Port over branchif and branchnil

* Fix use od record_boundary_patch_point in jump_to_next_insn
2022-08-29 08:47:02 -07:00
Noah Gibbs f5f58d8283
Update disasm to work on ARM (https://github.com/Shopify/ruby/pull/331) 2022-08-29 08:47:02 -07:00
Noah Gibbs cbf7a7cd23
Fix dupn (https://github.com/Shopify/ruby/pull/330)
* get_dupn was allocating and throwing away an Assembler object instead of using the one passed in

* Uncomment remaining tests in codegen.rs, which seem to work now
2022-08-29 08:47:02 -07:00
Maxime Chevalier-Boisvert 90137f5194
Implement PosMarker instruction (https://github.com/Shopify/ruby/pull/328)
* Implement PosMarker instruction

* Implement PosMarker in the arm backend

* Make bindgen run only for clang image

* Fix if-else in cirrus CI file

* Add missing semicolon

* Try removing trailing semicolon

* Try to fix shell/YAML syntax

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2022-08-29 08:47:02 -07:00
Kevin Newton 4ae2c744ac
A lot of fixes coming from our pairing session (https://github.com/Shopify/ruby/pull/329)
* Move to/from SP on AArch64

* Consolidate loads and stores

* Implement LDR post-index and LDR pre-index for AArch64

* Implement STR post-index and STR pre-index for AArch64

* Module entrypoints for LDR pre/post -index and STR pre/post -index

* Use STR (pre-index) and LDR (post-index) to implement push/pop

* Go back to using MOV for to/from SP
2022-08-29 08:47:02 -07:00
Maxime Chevalier-Boisvert c9484fe0c1
Fix push/pop and frame setup/teardown with Kevin & Alan 2022-08-29 08:47:02 -07:00
Noah Gibbs b3cd7a9cd3
Fix some of the codegen.rs tests (https://github.com/Shopify/ruby/pull/327) 2022-08-29 08:47:02 -07:00
Kevin Newton f09fd032d8
Assert not the same register in AArch64 2022-08-29 08:47:02 -07:00
Kevin Newton db84d2921f
BLR instruction for AArch64 (https://github.com/Shopify/ruby/pull/325) 2022-08-29 08:47:01 -07:00
Maxime Chevalier-Boisvert fd97f8ebc7
Use frame_setup() and frame_teardown() 2022-08-29 08:47:01 -07:00
Kevin Newton 10d50031e6
AArch64 frames (https://github.com/Shopify/ruby/pull/324) 2022-08-29 08:47:01 -07:00
Maxime Chevalier-Boisvert e907aaa3fe
ADR fixes for LeaLabel and calls 2022-08-29 08:47:01 -07:00
Kevin Newton f9e24ca8dd
Conditionals (https://github.com/Shopify/ruby/pull/323)
* CSEL on AArch64

* Implement various Op::CSel* instructions
2022-08-29 08:47:01 -07:00
Kevin Newton 0da253e72c
Port print_int to the new backend (https://github.com/Shopify/ruby/pull/321)
* Port print_int to the new backend

* Tests for print_int and print_str
2022-08-29 08:47:01 -07:00
Kevin Newton c83198911a
Fix jumps (https://github.com/Shopify/ruby/pull/322) 2022-08-29 08:47:01 -07:00
Maxime Chevalier-Boisvert 95e5c5227c
Fix bug with LeaLabel on x86, add CI test 2022-08-29 08:47:01 -07:00
Maxime Chevalier-Boisvert 34ec89252b
Fix comment typo 2022-08-29 08:47:00 -07:00
Kevin Newton 160e29b9e5
Port print_str to new backend (https://github.com/Shopify/ruby/pull/318)
* ADR and ADRP for AArch64

* Implement Op::Jbe on X86

* Lera instruction

* Op::BakeString

* LeaPC -> LeaLabel

* Port print_str to the new backend

* Port print_value to the new backend

* Port print_ptr to the new backend

* Write null-terminators in Op::BakeString

* Fix up rebase issues on print-str port

* Add back in panic for X86 backend for unsupported instructions being lowered

* Fix target architecture
2022-08-29 08:47:00 -07:00
Maxime Chevalier-Boisvert 6c50089599
Port newhash, add tests for newhash, duphash 2022-08-29 08:47:00 -07:00
Maxime Chevalier-Boisvert a1ea018fd6
Add extra assertion in new_label for Kevin 2022-08-29 08:47:00 -07:00
Maxime Chevalier-Boisvert 5e834195fd
Exclude X0 (C_RET_REG) from allocatable registers on arm (https://github.com/Shopify/ruby/pull/319)
* Exclude X0 (C_RET_REG) from allocatable registers on arm

* Add another small test snippett
2022-08-29 08:47:00 -07:00
Kevin Newton 159566fef9
Op::CPushAll and Op::CPopAll (https://github.com/Shopify/ruby/pull/317)
Instructions for pushing all caller-save registers and the flags so that
we can implement dump_insns.
2022-08-29 08:47:00 -07:00
Kevin Newton ac77d151d6
Assert that the # of bytes matches for label refs (https://github.com/Shopify/ruby/pull/316) 2022-08-29 08:47:00 -07:00
Kevin Newton 15c6aacd39
Encode MRS and MSR for AArch64 (https://github.com/Shopify/ruby/pull/315) 2022-08-29 08:47:00 -07:00
Maxime Chevalier-Boisvert 8d743e965e
Fix compile errors on arm on the CI (https://github.com/Shopify/ruby/pull/313)
* Fix compile errors on arm on the CI

* Fix typo
2022-08-29 08:47:00 -07:00
Maxime Chevalier-Boisvert 6e5382780f
Port over putstring 2022-08-29 08:47:00 -07:00
Maxime Chevalier-Boisvert 86606e01ee
Port over setlocal_wc0 2022-08-29 08:47:00 -07:00
Maxime Chevalier-Boisvert b45b29fdbf
Port gen_getlocal() 2022-08-29 08:46:59 -07:00
Kevin Newton 8864691bde
Better label refs (https://github.com/Shopify/ruby/pull/310)
Previously we were using a `Box<dyn FnOnce>` to support patching the
code when jumping to labels. We needed to do this because some of the
closures that were being used to patch needed to capture local variables
(on both X86 and ARM it was the type of condition for the conditional
jumps).

To get around that, we can instead use const generics since the
condition codes are always known at compile-time. This means that the
closures go from polymorphic to monomorphic, which means they can be
represented as an `fn` instead of a `Box<dyn FnOnce>`, which means they
can fall back to a plain function pointer. This simplifies the storage
of the `LabelRef` structs and should hopefully be a better default
going forward.
2022-08-29 08:46:59 -07:00
Kevin Newton e1f3f038e9
Fix jumps (https://github.com/Shopify/ruby/pull/309)
* Jumps for A64 should be in # of instructions

* More splitting for Arm64

https://github.com/Shopify/ruby/pull/309
2022-08-29 08:46:59 -07:00
Kevin Newton 6773832ab9
More Arm64 lowering/backend work (https://github.com/Shopify/ruby/pull/307)
* More Arm64 lowering/backend work

* We now have encoding support for the LDR instruction for loading a PC-relative memory location
* You can now call add/adds/sub/subs with signed immediates, which switches appropriately based on sign
* We can now load immediates into registers appropriately, attempting to keep the minimal number of instructions:
  * If it fits into 16 bytes, we use just a single movz.
  * Else if it can be encoded into a bitmask immediate, we use a single mov.
  * Otherwise we use a movz, a movk, and then optionally another one or two movks.
* Fixed a bunch of code to do with the Op::Load opcode.
* We now handle GC-offsets properly for Op::Load by skipping around them with a jump instruction. (This will be made better by constant pools in the future.)
* Op::Lea is doing what it's supposed to do now.
* Fixed a bug in the backend tests to do with not using the result of an Op::Add.

* Fix the remaining tests for Arm64

* Move split loads logic into each backend
2022-08-29 08:46:59 -07:00
Maxime Chevalier-Boisvert 0551115912
Add #[must_use] annotations to asm instructions 2022-08-29 08:46:59 -07:00
Maxime Chevalier-Boisvert ab2fa6ebdd
Add a backend test with a load of a GC'd VALUE 2022-08-29 08:46:59 -07:00
Maxime Chevalier-Boisvert 580f26959e
Get started on branchunless port 2022-08-29 08:46:59 -07:00
Maxime Chevalier-Boisvert 65019ed60c
Get codegen for deferred compilation working 2022-08-29 08:46:59 -07:00
Maxime Chevalier-Boisvert aab53e2868
Add test for direct jump to a code pointer 2022-08-29 08:46:59 -07:00
Kevin Newton 7a9b581e08
Arm64 progress (https://github.com/Shopify/ruby/pull/304)
* Get initial wiring up

* Split IncrCounter instruction

* Breakpoints in Arm64

* Support for ORR

* MOV instruction encodings

* Implement JmpOpnd and CRet

* Add ORN

* Add MVN

* PUSH, POP, CCALL for Arm64

* Some formatting and implement Op::Not for Arm64

* Consistent constants when working with the Arm64 SP

* Allow OR-ing values into the memory buffer

* Test lowering Arm64 ADD

* Emit unconditional jumps consistently in Arm64

* Begin emitting conditional jumps for A64

* Back out some labelref changes

* Remove label API that no longer exists

* Use a trait for the label encoders

* Encode nop

* Add in nops so jumps are the same width no matter what on Arm64

* Op::Jbe for CodePtr

* Pass src_addr and dst_addr instead of calculated offset to label refs

* Even more jump work for Arm64

* Fix up jumps to use consistent assertions

* Handle splitting Add, Sub, and Not insns for Arm64

* More Arm64 splits and various fixes

* PR feedback for Arm64 support

* Split up jumps and conditional jump logic
2022-08-29 08:46:58 -07:00
Kevin Newton b272c57f27
LSL, LSR, B.cond (https://github.com/Shopify/ruby/pull/303)
* LSL and LSR

* B.cond

* Move A64 files around to make more sense

* offset -> byte_offset for bcond
2022-08-29 08:46:58 -07:00
Alan Wu d916328078
Conscise IR disassembly (https://github.com/Shopify/ruby/pull/302)
The output from `dbg!` was too verbose. For `test_jo` the output went
from 37 lines to 5 lines. The added index helps parsing InsnOut
indicies.

Samples:

```
test backend::tests::test_jo ... [src/backend/ir.rs:589] &self = Assembler
    000 Load(Mem64[Reg(3) + 8]) -> Out64(0)
    001 Sub(Out64(0), 1_i64) -> Out64(1)
    002 Load(Out64(1)) -> Out64(2)
    003 Add(Out64(2), Mem64[Reg(3)]) -> Out64(3)
    004 Jo() target=CodePtr(CodePtr(0x5)) -> Out64(4)
    005 Mov(Mem64[Reg(3)], Out64(3)) -> Out64(5)

test backend::tests::test_reuse_reg ... [src/backend/ir.rs:589] &self = Assembler
    000 Load(Mem64[Reg(3)]) -> Out64(0)
    001 Add(Out64(0), 1_u64) -> Out64(1)
    002 Load(Mem64[Reg(3) + 8]) -> Out64(2)
    003 Add(Out64(2), 1_u64) -> Out64(3)
    004 Add(Out64(1), 1_u64) -> Out64(4)
    005 Add(Out64(1), Out64(4)) -> Out64(5)
    006 Store(Mem64[Reg(3)], Out64(4)) -> Out64(6)
    007 Store(Mem64[Reg(3) + 8], Out64(5)) -> Out64(7)
```
2022-08-29 08:46:58 -07:00
Alan Wu 0a96a39189
Delete dbg!() calls 2022-08-29 08:46:58 -07:00
Maxime Chevalier-Boisvert f1b188143b
Fix backend transform bug, add test 2022-08-29 08:46:58 -07:00
Maxime Chevalier-Boisvert 4c0a440b18
Port over duphash and newarray 2022-08-29 08:46:58 -07:00
Maxime Chevalier-Boisvert 2eba6aef72
Port over get_branch_target() 2022-08-29 08:46:58 -07:00
Maxime Chevalier-Boisvert 4254174ca7
Port over setn 2022-08-29 08:46:58 -07:00
Maxime Chevalier-Boisvert 24db233fc7
Add jo insn and test for jo 2022-08-29 08:46:58 -07:00
Maxime Chevalier-Boisvert 8bb7421d8e
Port topn, adjuststack, most of opt_plus 2022-08-29 08:46:58 -07:00
Maxime Chevalier-Boisvert d0204e51e2
Port guard_two_fixnums 2022-08-29 08:46:58 -07:00
Maxime Chevalier-Boisvert 00ad14f8c9
Port gen_full_cfunc_return 2022-08-29 08:46:57 -07:00
Maxime Chevalier-Boisvert b89d878ea6
Port getlocal_WC0 2022-08-29 08:46:57 -07:00
Maxime Chevalier-Boisvert 4c7d7080d2
Port over gen_putspecialobject 2022-08-29 08:46:57 -07:00
Maxime Chevalier-Boisvert c5ae52630f
Port gen_putself, log what can't be compiled in --yjit-dump-insns 2022-08-29 08:46:57 -07:00
Kevin Newton 27dd43bbc5
TST, CMP, AND/ANDS with registers (https://github.com/Shopify/ruby/pull/301)
* Add TST instruction and AND/ANDS entrypoints for immediates

* TST/AND/ANDS for registers

* CMP instruction
2022-08-29 08:46:57 -07:00
Maxime Chevalier-Boisvert 57e64f70c0
Make sure allocated reg size in bits matches insn out size 2022-08-29 08:46:57 -07:00
Kevin Newton eb4c7b4ea5
AND/ANDS for A64 (https://github.com/Shopify/ruby/pull/300) 2022-08-29 08:46:57 -07:00
Maxime Chevalier-Boisvert 67de662c44
Add Opnd.rm_num_bits() method 2022-08-29 08:46:57 -07:00
Maxime Chevalier-Boisvert 084d4bb192
Implement X86Reg::sub_reg() method 2022-08-29 08:46:57 -07:00
Maxime Chevalier-Boisvert 4932a6ef75
Fix small bug in x86_split 2022-08-29 08:46:57 -07:00
Maxime Chevalier-Boisvert b8fc9909bf
Get rid of temporary context methods 2022-08-29 08:46:56 -07:00
Maxime Chevalier-Boisvert 40ac79ada8
Add bitwise and to x86 backend 2022-08-29 08:46:56 -07:00
Maxime Chevalier-Boisvert abea8c8983
Add stores to one of the tests 2022-08-29 08:46:56 -07:00
Maxime Chevalier-Boisvert 1923842b3d
Move backend tests to their own file 2022-08-29 08:46:56 -07:00
Maxime Chevalier-Boisvert 59b818ec87
Add support for using InsnOut as memory operand base 2022-08-29 08:46:56 -07:00
Maxime Chevalier-Boisvert 401521ca14
Rename transform_insns to forward_pass 2022-08-29 08:46:56 -07:00
Maxime Chevalier-Boisvert ae9bcfec8c
Add assert 2022-08-29 08:46:56 -07:00
Maxime Chevalier-Boisvert e743e3bf20
Remove unused code, add backend asm test 2022-08-29 08:46:56 -07:00
Maxime Chevalier-Boisvert 4dbc1e1d82
Port bitwise not, gen_check_ints() 2022-08-29 08:46:56 -07:00
Maxime Chevalier-Boisvert 9d18e6c300
Port gen_code_for_exit_from_stub() 2022-08-29 08:46:56 -07:00
Maxime Chevalier-Boisvert e72dab304e
Add atomic counter increment instruction 2022-08-29 08:46:55 -07:00
Maxime Chevalier-Boisvert 27fcab995e
Get side exits working, get miniruby to boot with threshold=1 2022-08-29 08:46:55 -07:00
Kevin Newton c10e018e1c
LDADDAL, STUR, BL (https://github.com/Shopify/ruby/pull/299)
* LDADDAL instruction

* STUR

* BL instruction

* Remove num_bits from imm and uimm

* Tests for imm_fits_bits and uimm_fits_bits

* Reorder arguments to LDADDAL
2022-08-29 08:46:55 -07:00
Kevin Newton 1daa5942b8
MOVK, MOVZ, BR (https://github.com/Shopify/ruby/pull/296)
* MOVK instruction

* More tests for the A64 entrypoints

* Finish testing entrypoints

* MOVZ

* BR instruction
2022-08-29 08:46:55 -07:00
Maxime Chevalier-Boisvert 0000984fed
Port over putnil, putobject, and gen_leave()
* Remove x86-64 dependency from codegen.rs

* Port over putnil and putobject

* Port over gen_leave()

* Complete port of gen_leave()

* Fix bug in x86 instruction splitting
2022-08-29 08:46:55 -07:00
Maxime Chevalier-Boisvert d75c346c1c
Port gen_leave_exit(), add support for labels to backend 2022-08-29 08:46:55 -07:00
Maxime Chevalier-Boisvert ea9abe547d
Add cpush and cpop IR instructions 2022-08-29 08:46:55 -07:00
Maxime Chevalier-Boisvert 77383b3958
Add conditional jumps 2022-08-29 08:46:55 -07:00
Kevin Newton b63f8bb456
LDUR (https://github.com/Shopify/ruby/pull/295)
* LDUR

* Fix up immediate masking

* Consume operands directly

* Consistency and cleanup

* More consistency and entrypoints

* Cleaner syntax for masks

* Cleaner shifting for encodings
2022-08-29 08:46:55 -07:00
Maxime Chevalier-Boisvert 71770ceee5
Map comments in backend 2022-08-29 08:46:55 -07:00
Maxime Chevalier-Boisvert c2fdec93a9
First pass at porting gen_entry_prologue() 2022-08-29 08:46:55 -07:00
Maxime Chevalier-Boisvert 03ed50310d
Have Assembler::compile() return a list of GC offsets 2022-08-29 08:46:54 -07:00
Kevin Newton 26ba0a454c
RET A64 instructions (https://github.com/Shopify/ruby/pull/294) 2022-08-29 08:46:54 -07:00
Maxime Chevalier-Boisvert e22134277b
Remove x86_64 dependency in core.rs 2022-08-29 08:46:54 -07:00
Maxime Chevalier-Boisvert 3133540be7
Progress on codegen.rs port 2022-08-29 08:46:54 -07:00
Maxime Chevalier-Boisvert a1b8c94738
* Arm64 Beginnings (https://github.com/Shopify/ruby/pull/291)
* Initial setup for aarch64

* ADDS and SUBS

* ADD and SUB for immediates

* Revert moved code

* Documentation

* Rename Arm64* to A64*

* Comments on shift types

* Share sig_imm_size and unsig_imm_size
2022-08-29 08:46:54 -07:00
Maxime Chevalier-Boisvert 39dd8b2dfb
Add test for lea and ret. Fix codegen for lea and ret. 2022-08-29 08:46:54 -07:00
Maxime Chevalier-Boisvert 04e2ccede4
Change codegen.rs to use backend Assembler directly 2022-08-29 08:46:54 -07:00
Maxime Chevalier-Boisvert 7c83a904a4
Implement gc offset logic 2022-08-29 08:46:54 -07:00
Maxime Chevalier-Boisvert efb45acb29
Load GC Value operands into registers 2022-08-29 08:46:54 -07:00
Maxime Chevalier-Boisvert a88fc48b3a
Add CCall IR insn, implement gen_swap() 2022-08-29 08:46:54 -07:00
Maxime Chevalier-Boisvert 0032b02045
Add gen_dupn 2022-08-29 08:46:53 -07:00
Maxime Chevalier-Boisvert 872940e215
Add test with register reuse 2022-08-29 08:46:53 -07:00
Maxime Chevalier-Boisvert 151cc55baa
Fix issue with load, gen_dup 2022-08-29 08:46:53 -07:00
Maxime Chevalier-Boisvert 1b2ee62149
Implement target-specific insn splitting with Kevin. Add tests. 2022-08-29 08:46:53 -07:00
Maxime Chevalier-Boisvert 564f950360
Make assembler methods public, sketch gen_dup with new backend 2022-08-29 08:46:53 -07:00
Maxime Chevalier-Boisvert 99cfbdca6b
Fix bug with asm.comment() 2022-08-29 08:46:53 -07:00
Maxime Chevalier-Boisvert 75c995b0d1
Bias register allocator to reuse first operand 2022-08-29 08:46:53 -07:00
Maxime Chevalier-Boisvert 369911d31d
Add dbg!() for Assembler. Fix regalloc issue. 2022-08-29 08:46:53 -07:00
Maxime Chevalier-Boisvert a2aa289594
Function to map from Opnd => X86Opnd 2022-08-29 08:46:53 -07:00
Maxime Chevalier-Boisvert e9cc17dcc9
Start work on platform-specific codegen 2022-08-29 08:46:53 -07:00
Kevin Newton a3d8e20cea
Split insns (https://github.com/Shopify/ruby/pull/290)
* Split instructions if necessary

* Add a reusable transform_insns function

* Split out comments labels from transform_insns

* Refactor alloc_regs to use transform_insns
2022-08-29 08:37:49 -07:00
Kevin Newton 2b7d4f277d
IR register allocation
PR: https://github.com/Shopify/ruby/pull/289
2022-08-29 08:37:49 -07:00
Maxime Chevalier-Boisvert 7753b6b8b6
Removed String opnd so that we can derive Copy for Opnd 2022-08-29 08:37:49 -07:00
Maxime Chevalier-Boisvert 5021f26b4b
Complete sketch for guard_object_is_heap 2022-08-29 08:37:49 -07:00
Maxime Chevalier-Boisvert 884cbaabd9
Change push insn macros 2022-08-29 08:37:49 -07:00
Maxime Chevalier-Boisvert 92e9d1e661
Switch IR to use Option<Target> 2022-08-29 08:37:48 -07:00
Maxime Chevalier-Boisvert 96e5f9def0
Add macro to define ops 2022-08-29 08:37:48 -07:00
Maxime Chevalier-Boisvert 909d214708
Progress on IR sketch 2022-08-29 08:37:48 -07:00
Maxime Chevalier-Boisvert 2ffaa377c2
WIP backend IR sketch 2022-08-29 08:37:48 -07:00
Noah Gibbs b4be3c00c5 add --yjit-dump-iseqs param (https://github.com/Shopify/ruby/pull/332) 2022-08-24 10:42:45 -07:00
Takashi Kokubun 485019c2bd
Rename mjit_exec to jit_exec (#6262)
* Rename mjit_exec to jit_exec

* Rename mjit_exec_slowpath to mjit_check_iseq

* Remove mjit_exec references from comments
2022-08-19 23:57:17 -07:00
Jeremy Evans b7e492fa9e Regen YJIT bindings 2022-08-09 22:19:46 -07:00
Noah Gibbs 1e7a2415a4
YJIT: Allow str-concat arg to be any string subtype, not just rb_cString (#6205)
Allow str-concat arg to be any string subtype, not just rb_cString
2022-08-04 12:19:14 -04:00
John Hawthorn 7f5f9d19c5
YJIT: Add known_* helpers for Type (#6208)
* YJIT: Add known_* helpers for Type

This adds a few helpers to Type which all return Options representing
what is known, from a Ruby perspective, about the type.

This includes:
* known_class_of: If known, the class represented by this type
* known_value_type: If known, the T_ value type
* known_exact_value: If known, the exact VALUE represented by this type
  (currently this is only available for true/false/nil)
* known_truthy: If known, whether or not this value evaluates as true
  (not false or nil)

The goal of this is to abstract away the specifics of the mappings
between types wherever possible from the codegen. For example previously
by introducing Type::CString as a more specific version of
Type::TString, uses of Type::TString in codegen needed to be updated to
check either case. Now by using known_value_type, at least in theory we
can introduce new types with minimal (if any) codegen changes.

I think rust's Option type allows us to represent this uncertainty
fairly well, and should help avoid mistakes, and the matching using this
turned out pretty cleanly.

* YJIT: Use known_value_type for checktype

* YJIT: Use known_value_type for T_STRING check

* YJIT: Use known_class_of in guard_known_klass

* YJIT: Use known truthyness in jit_rb_obj_not

* YJIT: Rename known_class_of => known_class
2022-08-04 11:18:24 -04:00
John Hawthorn 0e85586ecc Add --enable-yjit=dev_nodebug configure option 2022-07-29 16:32:14 -07:00
John Hawthorn fbd24793cb Add --enable-yjit=stats configure option 2022-07-29 16:32:14 -07:00
Matthew Draper ab08a43ec5
YJIT: Teach getblockparamproxy to handle the no-block case without exiting (#6191)
Teach getblockparamproxy to handle the no-block case without exiting

Co-authored-by: John Hawthorn <john@hawthorn.email>

Co-authored-by: John Hawthorn <john@hawthorn.email>
2022-07-28 11:38:07 -04:00
John Hawthorn 660b1e973c
YJIT: Skip setlocal WB check for immediate values (#6122)
Write barriers may be required when VM_ENV_FLAG_WB_REQUIRED is set,
however write barriers only affect heap objects being written. If we
know an immediate value is being written we can skip this check.
2022-07-20 12:31:40 -04:00
Jemma Issroff ecff334995 Extract vm_ic_entry API to mimic vm_cc behavior 2022-07-18 12:44:01 -07:00
Peter Zhu 7424ea184f Implement Objects on VWA
This commit implements Objects on Variable Width Allocation. This allows
Objects with more ivars to be embedded (i.e. contents directly follow the
object header) which improves performance through better cache locality.
2022-07-15 09:21:07 -04:00
Eileen M. Uchitelle 59c6b7b7ab
Speed up --yjit-trace-exits code (#6106)
In a small script the speed of this feature isn't really noticeable but
on Rails it's very noticeable how slow this can be. This PR aims to
speed up two parts of the functionality.

1) The Rust exit recording code

Instead of adding all samples as we see them to the yjit_raw_samples and
yjit_line_samples, we can increment the counter on the ones we've seen
before. This will be faster on traces where we are hitting the same
stack often. In a crude measurement of booting just the active record
base test (`test/cases/base_test.rb`) we found that this improved the
speed by 1 second.

This also results in a smaller marshal dump file which sped up the test
boot time by 4 seconds with trace exits on.

2) The Ruby parsing code

Previously we were allocating new arrays using `shift` and
`each_with_index`. This change avoids allocating new arrays by using an
index. This change saves us the most amount of time, gaining 11 seconds.

Before this change the test boot time took 62 seconds, after it took 47
seconds. This is still too long but it's a step closer to faster
functionality. Next we're going to tackle allowing you to collect trace
exits for a specific instruction. There is also some potential slowness
in the GC code that I'd like to take a second look at.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2022-07-12 16:40:49 -04:00
Noah Gibbs (and/or Benchmark CI) a2e0815e27 Switch YJIT to using rb_str_buf_append rather than rb_str_append when encodings don't match, as discussed with byroot 2022-07-06 17:25:58 +02:00
Maxime Chevalier-Boisvert 3c61e1e77f
YJIT: add a counter for gc object refs in the machine code (#6089)
Add a counter for gc object refs in the machine code

This is to gather data for the eventual implementation of
a constant pool.
2022-07-06 11:13:22 -04:00
Dave Schwantes b6f6fc6e87
YJIT: Refactor gen_opt_mod (#6078)
Refactor gen_opt_mod in YJIT
2022-06-30 10:26:46 -04:00
Noah Gibbs 118e3edc32
Add a check-yjit-bindgen-unused target. Add to CI. (#6066)
This fails if there are any unused rust-bindgen "allow" entries. For
that target we turn on Rust warnings (there are a lot) and grep for the
ones that correspond to unused allow entries.

I've added check-yjit-bindgen-unused as a dependency of
check-yjit-bindings, so unused allow entries will now fail CI.

This change also removes our single unused allow entry (VM_CALL.*) which
was known to be bad.
2022-06-29 12:49:46 -04:00
Noah Gibbs (and/or Benchmark CI) 0fab06f3c3 Separate Type::String into Type::CString and Type::TString.
Also slightly broaden the cases where << on two strings will generate
specialised code rather than a plain method call.
2022-06-27 09:25:57 -07:00
Alan Wu ef79f0a9e5 YJIT: Fix copy pasted comment [ci skip] 2022-06-26 08:36:17 -04:00
John Hawthorn 0c1f64396f Skip protected ancestry guard for FCALLs in YJIT 2022-06-21 18:33:51 -07:00
Alan Wu 9f09397bfe
YJIT: On-demand executable memory allocation; faster boot (#5944)
This commit makes YJIT allocate memory for generated code gradually as
needed. Previously, YJIT allocates all the memory it needs on boot in
one go, leading to higher than necessary resident set size (RSS) and
time spent on boot initializing the memory with a large memset().

Users should no longer need to search for a magic number to pass to
`--yjit-exec-mem` since physical memory consumption should now more
accurately reflect the requirement of the workload.

YJIT now reserves a range of addresses on boot. This region start out
with no access permission at all so buggy attempts to jump to the region
crashes like before this change. To get this hardening at finer
granularity than the page size, we fill each page with trapping
instructions when we first allocate physical memory for the page.

Most of the time applications don't need 256 MiB of executable code, so
allocating on-demand ends up doing less total work than before. Case in
point, a simple `ruby --yjit-call-threshold=1 -eitself` takes about
half as long after this change. In terms of memory consumption, here is
a table to give a rough summary of the impact:

    | Peak RSS in MiB | -eitself example | railsbench once |
    | :-------------: | ---------------: | --------------: |
    |     before      |              265 |             377 |
    |      after      |               11 |             143 |
    |     no YJIT     |               10 |             101 |

A new module is introduced to handle allocation bookkeeping.
`CodePtr` is moved into the module since it has a close relationship
with the new `VirtualMemory` struct. This new interface has a slightly
smaller surface than before in that marking a region as writable is no
longer a public operation.
2022-06-14 10:23:13 -04:00
Noah Gibbs 9ed9cc9852
Add tests for a variety of string-subclass operations (#5999)
This way YJIT has to match CRuby for each of them.
Remove unused string_p() Rust function
2022-06-10 13:52:43 -04:00
Noah Gibbs e777ac9161
Don't return a value from jit_guard_known_klass. We never return anything but true at this point and we don't usually check the returned value. (#6000) 2022-06-10 12:29:26 -04:00
Eileen M. Uchitelle 473ee328c5
Add ability to trace exit locations in yjit (#5970)
When running with `--yjit-stats` turned on, yjit can inform the user
what the most common exits are. While this is useful information it
doesn't tell you the source location of the code that exited or what the
code that exited looks like. This change intends to fix that.

To use the feature, run yjit with the `--yjit-trace-exits` option,
which will record the backtrace for every exit that occurs. This functionality
requires the stats feature to be turned on. Calling `--yjit-trace-exits`
will automatically set the `--yjit-stats` option.

Users must call `RubyVM::YJIT.dump_exit_locations(filename)` which will
Marshal dump the contents of `RubyVM::YJIT.exit_locations` into a file
based on the passed filename.

*Example usage:*

Given the following script, we write to a file called
`concat_array.dump` the results of `RubyVM::YJIT.exit_locations`.

```ruby
def concat_array
  ["t", "r", *x = "u", "e"].join
end

1000.times do
  concat_array
end

RubyVM::YJIT.dump_exit_locations("concat_array.dump")
```

When we run the file with this branch and the appropriate flags the
stacktrace will be recorded. Note Stackprof needs to be installed or you
need to point to the library directly.

```
./ruby --yjit --yjit-call-threshold=1 --yjit-trace-exits -I/Users/eileencodes/open_source/stackprof/lib test.rb
```

We can then read the dump file with Stackprof:

```
./ruby -I/Users/eileencodes/open_source/stackprof/lib/ /Users/eileencodes/open_source/stackprof/bin/stackprof --text concat_array.dump
```

Results will look similar to the following:

```
==================================
  Mode: ()
  Samples: 1817 (0.00% miss rate)
  GC: 0 (0.00%)
==================================
     TOTAL    (pct)     SAMPLES    (pct)     FRAME
      1001  (55.1%)        1001  (55.1%)     concatarray
       335  (18.4%)         335  (18.4%)     invokeblock
       178   (9.8%)         178   (9.8%)     send
       140   (7.7%)         140   (7.7%)     opt_getinlinecache
       ...etc...
```

Simply inspecting the `concatarray` method will give `SOURCE
UNAVAILABLE` because the source is insns.def.

```
./ruby -I/Users/eileencodes/open_source/stackprof/lib/ /Users/eileencodes/open_source/stackprof/bin/stackprof --text concat_array.dump --method concatarray
```

Result:

```
concatarray (nonexistent.def:1)
  samples:  1001 self (55.1%)  /   1001 total (55.1%)
  callers:
    1000  (   99.9%)  Object#concat_array
       1  (    0.1%)  Gem.suffixes
  callees (0 total):
  code:
        SOURCE UNAVAILABLE
```

However if we go deeper to the callee we can see the exact
source of the `concatarray` exit.

```
./ruby -I/Users/eileencodes/open_source/stackprof/lib/ /Users/eileencodes/open_source/stackprof/bin/stackprof --text concat_array.dump --method Object#concat_array
```

```
Object#concat_array (/Users/eileencodes/open_source/rust_ruby/test.rb:1)
  samples:     0 self (0.0%)  /   1000 total (55.0%)
  callers:
    1000  (  100.0%)  block in <main>
  callees (1000 total):
    1000  (  100.0%)  concatarray
  code:
                                  |     1  | def concat_array
 1000   (55.0%)                   |     2  |   ["t", "r", *x = "u", "e"].join
                                  |     3  | end
```

The `--walk` option is recommended for this feature as it make it
easier to traverse the tree of exits.

*Goals of this feature:*

This feature is meant to give more information when working on YJIT.
The idea is that if we know what code is exiting we can decide what
areas to prioritize when fixing exits. In some cases this means adding
prioritizing avoiding certain exits in yjit. In more complex cases it
might mean changing the Ruby code to be more performant when run with
yjit. Ultimately the more information we have about what code is exiting
AND why, the better we can make yjit.

*Known limitations:*

* Due to tracing exits, running this on large codebases like Rails
can be quite slow.
* On complex methods it can still be difficult to pinpoint the exact cause of
an exit.
* Stackprof is a requirement to to view the backtrace information from
the dump file.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2022-06-09 12:59:39 -04:00
Noah Gibbs 1598c9458a
Add special-case code for the String unary plus operator (#5982) 2022-06-07 11:20:57 -04:00
Noah Gibbs 653e517eef
Use bindgen to import Ruby constants wherever possible. (#5943)
Constants that can't be imported via bindgen should have
a comment saying why not.
2022-06-06 13:47:24 -04:00
Nobuyoshi Nakada 689b5ae752
Split YJIT rules for CODEOWNERS 2022-06-02 10:12:34 +09:00
Noah Gibbs 9d18661e1d
Revert incorrect string-guard optimisation. (#5969)
Also add jhawthorn's test to for this bug.
Fix String#to_s invalidation test
2022-06-01 10:22:08 -04:00