summaryrefslogtreecommitdiff
path: root/yjit/src/codegen.rs
AgeCommit message (Collapse)Author
2022-09-30A bunch of clippy auto fixes for yjit (#6476)Jimmy Miller
Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-09-28This commit implements the Object Shapes technique in CRuby.Jemma Issroff
Object Shapes is used for accessing instance variables and representing the "frozenness" of objects. Object instances have a "shape" and the shape represents some attributes of the object (currently which instance variables are set and the "frozenness"). Shapes form a tree data structure, and when a new instance variable is set on an object, that object "transitions" to a new shape in the shape tree. Each shape has an ID that is used for caching. The shape structure is independent of class, so objects of different types can have the same shape. For example: ```ruby class Foo def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end class Bar def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end foo = Foo.new # `foo` has shape id 2 bar = Bar.new # `bar` has shape id 2 ``` Both `foo` and `bar` instances have the same shape because they both set instance variables of the same name in the same order. This technique can help to improve inline cache hits as well as generate more efficient machine code in JIT compilers. This commit also adds some methods for debugging shapes on objects. See `RubyVM::Shape` for more details. For more context on Object Shapes, see [Feature: #18776] Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org> Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com> Co-Authored-By: John Hawthorn <john@hawthorn.email>
2022-09-26Revert this until we can figure out WB issues or remove shapes from GCAaron Patterson
Revert "* expand tabs. [ci skip]" This reverts commit 830b5b5c351c5c6efa5ad461ae4ec5085e5f0275. Revert "This commit implements the Object Shapes technique in CRuby." This reverts commit 9ddfd2ca004d1952be79cf1b84c52c79a55978f4.
2022-09-26This commit implements the Object Shapes technique in CRuby.Jemma Issroff
Object Shapes is used for accessing instance variables and representing the "frozenness" of objects. Object instances have a "shape" and the shape represents some attributes of the object (currently which instance variables are set and the "frozenness"). Shapes form a tree data structure, and when a new instance variable is set on an object, that object "transitions" to a new shape in the shape tree. Each shape has an ID that is used for caching. The shape structure is independent of class, so objects of different types can have the same shape. For example: ```ruby class Foo def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end class Bar def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end foo = Foo.new # `foo` has shape id 2 bar = Bar.new # `bar` has shape id 2 ``` Both `foo` and `bar` instances have the same shape because they both set instance variables of the same name in the same order. This technique can help to improve inline cache hits as well as generate more efficient machine code in JIT compilers. This commit also adds some methods for debugging shapes on objects. See `RubyVM::Shape` for more details. For more context on Object Shapes, see [Feature: #18776] Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org> Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com> Co-Authored-By: John Hawthorn <john@hawthorn.email> Notes: Merged: https://github.com/ruby/ruby/pull/6386
2022-09-22YJIT: add chain guards in `guard_two_fixnums` (#6422)Maxime Chevalier-Boisvert
* Add chain guards in guard_two_fixnums, opt_eq with symbols * Remove symbol comparison in gen_equality_specialized Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-09-22YJIT: Refactor into gen_push_frame (#6412)John Hawthorn
This refactors the "push frame" operation common to both gen_send_iseq and gen_send_cfunc into its own method. This allows that logic to live in one place. Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-09-19YJIT: Check if the processor supports --yjit-stats (#6401)Takashi Kokubun
* YJIT: Add asm comment for incr_counter * YJIT: Check if the processor supports --yjit-stats Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-09-19Only exit if ruby2_keywords and splat together (#6395)Jimmy Miller
Before this change railsbench spent less time in yjit than before splat. This brings it back to parity. Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-09-16Fix splat args (#6385)Jimmy Miller
* Fix splat args Cfuncs were not working properly so I disabled them right now. There were some checks above that were also actually preventing splat args from being called. Finally I did some basic code cleanup after realizing I didn't need to mutate argc so much * Add can't compile for direct cfunc splat call * Fix typo * Update yjit/src/codegen.rs Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-09-15Add asm comments to make disasm more readable (#6377)Maxime Chevalier-Boisvert
Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-09-14YJIT: Implement specialized respond_to? (#6363)John Hawthorn
* Add rb_callable_method_entry_or_negative * YJIT: Implement specialized respond_to? This implements a specialized respond_to? in YJIT. * Update yjit/src/codegen.rs Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-09-14Initial support for VM_CALL_ARGS_SPLAT (#6341)Jimmy Miller
* Initial support for VM_CALL_ARGS_SPLAT This implements support for calls with splat (*) for some methods. In benchmarks this made very little difference for most benchmarks, but a large difference for binarytrees. Looking at side exits, many benchmarks now don't exit for splat, but exit for some other reason. Binarytrees however had a number of calls that used splat args that are now much faster. In my non-scientific benchmarking this made splat args performance on par with not using splat args at all. * Fix wording and whitespace Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> * Get rid of side_effect reassignment Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-09-14YJIT: Add Opnd#with_num_bits to use only 8 bits (#6359)Takashi Kokubun
* YJIT: Add Opnd#sub_opnd to use only 8 bits * Add with_num_bits and let arm64_split use it * Add another assertion to with_num_bits * Use only with_num_bits Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-09-09YJIT: Branch directly when nil? is known from typesJohn Hawthorn
Notes: Merged: https://github.com/ruby/ruby/pull/6350
2022-09-09YJIT: Branch directly when truthyness is knownJohn Hawthorn
Notes: Merged: https://github.com/ruby/ruby/pull/6350
2022-09-01New constant caching insn: opt_getconstant_pathJohn Hawthorn
Previously YARV bytecode implemented constant caching by having a pair of instructions, opt_getinlinecache and opt_setinlinecache, wrapping a series of getconstant calls (with putobject providing supporting arguments). This commit replaces that pattern with a new instruction, opt_getconstant_path, handling both getting/setting the inline cache and fetching the constant on a cache miss. This is implemented by storing the full constant path as a null-terminated array of IDs inside of the IC structure. idNULL is used to signal an absolute constant reference. $ ./miniruby --dump=insns -e '::Foo::Bar::Baz' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,13)> (catch: FALSE) 0000 opt_getconstant_path <ic:0 ::Foo::Bar::Baz> ( 1)[Li] 0002 leave The motivation for this is that we had increasingly found the need to disassemble the instructions between the opt_getinlinecache and opt_setinlinecache in order to determine the constant we are fetching, or otherwise store metadata. This disassembly was done: * In opt_setinlinecache, to register the IC against the constant names it is using for granular invalidation. * In rb_iseq_free, to unregister the IC from the invalidation table. * In YJIT to find the position of a opt_getinlinecache instruction to invalidate it when the cache is populated * In YJIT to register the constant names being used for invalidation. With this change we no longe need disassemly for these (in fact rb_iseq_each is now unused), as the list of constant names being referenced is held in the IC. This should also make it possible to make more optimizations in the future. This may also reduce the size of iseqs, as previously each segment required 32 bytes (on 64-bit platforms) for each constant segment. This implementation only stores one ID per-segment. There should be no significant performance change between this and the previous implementation. Previously opt_getinlinecache was a "leaf" instruction, but it included a jump (almost always to a separate cache line). Now opt_getconstant_path is a non-leaf (it may raise/autoload/call const_missing) but it does not jump. These seem to even out. Notes: Merged: https://github.com/ruby/ruby/pull/6187
2022-09-01Let --yjit-dump-disasm=all dump ocb code as well (#6309)Takashi Kokubun
* Let --yjit-dump-disasm=all dump ocb code as well * Use an enum instead * Add a None Option to DumpDisasm (#444) * Add a None Option to DumpDisasm * Update yjit/src/asm/mod.rs Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> * Fix a build failure * Use only a single name * Only None will be a disabled case * Fix cargo test * Fix --yjit-dump-disasm=all to print outlined cb Co-authored-by: Jimmy Miller <jimmyhmiller@gmail.com> Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-08-29Check only symbol flag bits (#6301)Takashi Kokubun
* Check only symbol flag bits * Check all 4 bits Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-08-29Remove ir_ssa.rs as we aren't using it and it's now outdatedMaxime Chevalier-Boisvert
Notes: Merged: https://github.com/ruby/ruby/pull/6289
2022-08-29Add --yjit-dump-disasm to dump every compiled code ↵Takashi Kokubun
(https://github.com/Shopify/ruby/pull/430) * Add --yjit-dump-disasm to dump every compiled code * Just use get_option * Carve out disasm_from_addr * Avoid push_str with format! * Share the logic through asm.compile * This seems to negatively impact the compilation speed Notes: Merged: https://github.com/ruby/ruby/pull/6289
2022-08-29Various AArch64 optimizations (https://github.com/Shopify/ruby/pull/433)Kevin Newton
* When we're storing an immediate 0 value at a memory address, we can use STUR XZR, Xd instead of loading 0 into a register and then storing that register. * When we're moving 0 into an argument register, we can use MOV Xd, XZR instead of loading the value into a register first. * In the newarray instruction, we can skip looking at the stack at all if the number of values we're using is 0. Notes: Merged: https://github.com/ruby/ruby/pull/6289
2022-08-29Fix and re-enable String to_s, << and unary plus ↵Noah Gibbs
(https://github.com/Shopify/ruby/pull/429) Notes: Merged: https://github.com/ruby/ruby/pull/6289
2022-08-29Use VALUE for callinfos that are on the heap ↵Alan Wu
(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. https://github.com/ruby/ruby/blob/b0b9f7201acab05c2a3ad92c3043a1f01df3e17f/yjit/src/codegen.rs#L4087-L4095 Notes: Merged: https://github.com/ruby/ruby/pull/6289
2022-08-29Avoid marking op_type on gen_defined (https://github.com/Shopify/ruby/pull/419)Takashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/6289
2022-08-29Use VALUE for block_iseq (https://github.com/Shopify/ruby/pull/417)Takashi Kokubun
Co-authored-by: Alan Wu <alansi.xingwu@shopify.com> Notes: Merged: https://github.com/ruby/ruby/pull/6289
2022-08-29Fix a bus error on regenerate_branch (https://github.com/Shopify/ruby/pull/408)Takashi Kokubun
* Fix a bus error on regenerate_branch * Fix pad_size Notes: Merged: https://github.com/ruby/ruby/pull/6289
2022-08-29Only check lowest bit for _Bool type (https://github.com/Shopify/ruby/pull/412)Alan Wu
* 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 Notes: Merged: https://github.com/ruby/ruby/pull/6289
2022-08-29Fix issue with expandarray, add missing jl, enable tests ↵Maxime Chevalier-Boisvert
(https://github.com/Shopify/ruby/pull/409)
2022-08-29Temporarily disable rb_str_concat, add CI tests ↵Maxime Chevalier-Boisvert
(https://github.com/Shopify/ruby/pull/407) Make sure we can load the test-all runner and run test_yjit.rb
2022-08-29Port jit_rb_str_concat to new backend, re-enable cfunc lookup ↵Noah Gibbs (and/or Benchmark CI)
(https://github.com/Shopify/ruby/pull/402)
2022-08-29YJIT: Implement concatarray in yjit (https://github.com/Shopify/ruby/pull/405)Maple Ong
* 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-29Use bindgen for old manual extern declarations ↵Alan Wu
(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-29Fix bugs in gen_opt_getinlinecacheMaxime Chevalier-Boisvert
2022-08-29Port opt_getinlinecache to the new backend ↵Zack Deveau
(https://github.com/Shopify/ruby/pull/399)
2022-08-29Port opt_aref and opt_aset to the new backend IR ↵Takashi Kokubun
(https://github.com/Shopify/ruby/pull/387) * Port opt_aref and opt_aset to the new backend IR * Recompute memory operands
2022-08-29Port getblockparamproxy and getblockparam ↵Takashi Kokubun
(https://github.com/Shopify/ruby/pull/394)
2022-08-29Port invokesuper to the new backend IR ↵Takashi Kokubun
(https://github.com/Shopify/ruby/pull/391)
2022-08-29Port the remaining method types in opt_send_without_block ↵Takashi Kokubun
(https://github.com/Shopify/ruby/pull/390)
2022-08-29Update asm comments for gen_send_iseqMaxime Chevalier-Boisvert
2022-08-29Port cfunc lookup, plus simpler cfunc generators. ↵Noah Gibbs
(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-29Prefer asm.store over asm.mov (https://github.com/Shopify/ruby/pull/385)Takashi Kokubun
* Prefer asm.store over asm.mov * Reverse a couple of unsure changes * Revert changes that don't work
2022-08-29Port expandarray to the new backend IR ↵Takashi Kokubun
(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-29Port gen_send_iseq to the new backend IR ↵Takashi Kokubun
(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-29Port invokebuiltin* insns to the new backend IR ↵Takashi Kokubun
(https://github.com/Shopify/ruby/pull/375) * Port invokebuiltin* insns to the new backend IR * Fix the C_ARG_OPNDS check boundary
2022-08-29More concise csel with IntoAlan Wu
2022-08-29Port send to the new backend and test it ↵Takashi Kokubun
(https://github.com/Shopify/ruby/pull/373)
2022-08-29Port opt_eq and opt_neq to the new backend ↵Takashi Kokubun
(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-29Port objtostring to the new backend (https://github.com/Shopify/ruby/pull/369)Takashi Kokubun
2022-08-29Port opt_str_uminus to new backend IR ↵Zack Deveau
(https://github.com/Shopify/ruby/pull/370)
2022-08-29Port gen_opt_str_freeze to new backend IR ↵Zack Deveau
(https://github.com/Shopify/ruby/pull/366)