Commit graph

196 commits

Author SHA1 Message Date
Alan Wu
da20ff1644 Fix bug in generic case for gen_checktype
When checking for T_HASH, which is Qnil and when the type check succeeds
we were outputting to the stack a Qnil instead of a Qtrue.
2021-10-20 18:19:36 -04:00
John Hawthorn
7d252186fe Simplify known class check for singletons
Singleton classes should only ever be attached to one object. This means
that checking for the object should be the same as checking for the
class. This should be slightly faster by avoiding one memory acccess as
well as allowing us to skip checking if the receiver is a heap object.

This will be most common for calling class methods.
2021-10-20 18:19:36 -04:00
Alan Wu
8c68f112d8 Delay and be selective about when to discard local types
jit_rb_obj_not() wants to access the type information of the receiver,
but we were discarding type info of locals before jit_rb_obj_not() runs
unncessarily.

There are also cases we are unncessarily discarding local type info. For
example, ivar reader and setter methods can never change local
variables.
2021-10-20 18:19:36 -04:00
Alan Wu
936ee55562 Improve opt_not by expanding cfunc codegen
This commit improves opt_not by making it correct when TrueClass#!
and/or FalseClass#! is defined and genearting better code when the
receiver is a heap object.

guard_known_class() can now handle true, false, and nil, and we
introduce a codegen function reimplementing rb_obj_not(), used when we
know we are calling into rb_obj_not().

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Noah Gibbs <the.codefolio.guy@gmail.com>
2021-10-20 18:19:36 -04:00
John Hawthorn
78f64d14d4 Add invokebuiltin_delegate_leave
invokebuiltin_delegate can be run in place of
invokebuiltin_delegate_leave because there is always a leave instruction
afterwards (the interpreter takes advantage of this as well when
rewriting iseqs for tracing).
2021-10-20 18:19:36 -04:00
John Hawthorn
b93f59ced0 Implement invokebuiltin_delegate
invokebuiltin_delegate is a special version of invokebuiltin used for
sending a contiguous subset of the current method's locals.

In some cases YJIT would already handle this for trivial cases it could
be inlined, implementing this OP allows it to work when the method isn't
inlinable (not marked as 'inline', does more than just call, not called
from yjit, etc).
2021-10-20 18:19:36 -04:00
Maxime Chevalier-Boisvert
364cdda0f1 Fix compiler warning 2021-10-20 18:19:36 -04:00
Aaron Patterson
9043ad3d74 Implement topn instruction
This commit implements the topn instruction

Co-Authored-By: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-Authored-By: Noah Gibbs <noah.gibbs@shopify.com>
2021-10-20 18:19:36 -04:00
John Hawthorn
986b9b47d1 Better comments 2021-10-20 18:19:36 -04:00
John Hawthorn
0a3ee8b2e3 Avoid looping on invokesuper on module included multiple times 2021-10-20 18:19:36 -04:00
John Hawthorn
3fedf8329d Check for refinements in gen_invokesuper 2021-10-20 18:19:36 -04:00
John Hawthorn
0fb2926097 Guard against implicitly forwarded block 2021-10-20 18:19:36 -04:00
John Hawthorn
83c7f27ade Add invokesuper 2021-10-20 18:19:35 -04:00
John Hawthorn
67c2cdc59a Implement gen_getlocal
This extracts the generation code from getlocal_wc1, since this is the
same just with more loops inside vm_get_ep.
2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
5432f46f6a Can't add comments to the outlined code block 2021-10-20 18:19:35 -04:00
John Hawthorn
ed636b59ed Add duparray to YJIT codegen 2021-10-20 18:19:35 -04:00
John Hawthorn
d77c989ac7 Fix check for leaf invokebuiltin
Also added a comment when inlining a leaf builtin
2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
860589c7fa Use builtin_inline_p to avoid pushing a frame for primitive C methods (#63)
* Use builtin_inline_p to skip a frame of C methods

* Fix bugs in primitive cfunc call code

* Remove if (push_frame) {}

* Remove if (push_frame) {}

* Push Aaron's fix to avoid hardcoding insn lengths

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2021-10-20 18:19:35 -04:00
John Hawthorn
ea33b0a9ba Add concatstrings to yjit codegen (#58)
* Add ETYPE_TRUE and ETYPE_FALSE

* Implement checktype

* Implement concatstrings

* Update deps
2021-10-20 18:19:35 -04:00
John Hawthorn
eb6e5be038 Add newhash and newarray instructions to yjit codegen (#48)
* Implement gen_newarray

* Implement newhash for n=0

* Add yjit tests for newhash/newarray

* Fix integer size warning on clang

* Save PC and SP in newhash and newarray

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
d01204a15d Disable extra T_OBJECT check added because of Nokogiri 2021-10-20 18:19:35 -04:00
John Hawthorn
546ca8167d Guard for T_OBJECT at compile time (#53)
Previously this could crash on Nokogiri when JITing the getivar
instruction because we would attempt to treat Nokogiri::XML::Document's
T_DATA as a T_OBJECT in calling rb_iv_index_tbl_lookup.

This commit also checks for T_OBJECT at compile time and emits the
rb_ivar_get fallback in that case.

Co-authored-by: HParker <HParker@github.com>
Co-authored-by: Dinah Shi <dinahshi@github.com>

Co-authored-by: HParker <HParker@github.com>
Co-authored-by: Dinah Shi <dinahshi@github.com>
2021-10-20 18:19:35 -04:00
John Hawthorn
9283fc1bb5 Implement opt_freeze and opt_uminus (#49) 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
b415ceb92e Increase default YJIT call threshold to 10. Add exec mem size arg. (#52) 2021-10-20 18:19:35 -04:00
John Hawthorn
764740c661 Merge pull request #50 from jhawthorn/detect_type
Detect types from putobject and getinlinecache
2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
1aace65dc0 Add comment 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
03da234eb0 Add T_OBJECT check to getivar 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
a66dce146a Implement opt_not with deferred compilation (#44) 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
0db85218aa Avoid interrupt checks for forward branches (#41) 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
54fe43b45c Implement defined bytecode (#39) 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
3677b233dd Implement opt_nil_p and opt_empty_b by delegating to send (#35) 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
d6412126bc Implement setivar with a plain old function call (#34)
* Implement setivar with a plain old function call

* Remove return
2021-10-20 18:19:35 -04:00
Alan Wu
7eef8f09c0 Implement getblockparamproxy
* Implement getblockparamproxy

* Parallel runner: wait for timeout thread to terminate after killing

Or else the leak cheaker could sees the thread as running and cause test
failures in test-tool.

* Add a comment, use jne

* Comment about where 0x3 comes from
2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
ce928473d0 Deletate to opt_send_without_block for opt_ltlt (#33) 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
0c3842d154 Implement opt_aset as interpreter handler call 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
c9feb72b65 Implement opt_mod as call to interpreter function (#29) 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
e2c1d69331 Implement opt_eq by calling interpreter function (#28) 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert
e22657b887 Implement branchnil bytecode (#26) 2021-10-20 18:19:34 -04:00
Alan Wu
0d64f5e8a8 Check for easy-to-handle cases of block param (#24)
In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert
e5f8b41786 Implement send with alias method (#23)
* Implement send with alias method

* Add alias_method tests
2021-10-20 18:19:34 -04:00
Alan Wu
0758115d11 Implement send with blocks
* Implement send with blocks

Not that much extra work compared to `opt_send_without_block`.
Moved the stack over flow check because it could've exited after changes
are made to cfp.

* rename oswb counters

* Might as well implement sending block to cfuncs

* Disable sending blocks to cfuncs for now

* Reconstruct interpreter sp before calling into cfuncs

In case the callee cfunc calls a method or delegates to a block.
This also has the side benefit of letting call sites that sometimes are
iseq calls and sometimes cfunc call share the same successor.

* only sync with interpreter sp when passing a block


Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Aaron Patterson <aaron.patterson@shopify.com>
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert
59e5f6b83b Implement dupn for n==2 (only case used in RDoc/railsbench) (#20)
* Implement dupn for n==2 (only case used in RDoc/railsbench)

* Implement adjuststack bytecode
2021-10-20 18:19:34 -04:00
Alan Wu
684e84df7c Use rb_ivar_get() for general case of getivar (#17)
* Use rb_ivar_get() for general case of getivar

Pretty straight forward. Buys about 1% coverage on railsbench.

* Update yjit_codegen.c

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert
62c1297e24 Implement setn bytecode (#15) 2021-10-20 18:19:34 -04:00
Alan Wu
36134f7d29 Implement calls to methods with simple optional params
* Implement calls to methods with simple optional params

* Remove unnecessary MJIT_STATIC

See comment for MJIT_STATIC. I added it not knowing whether it's
required because the function next to it has it. Don't use it and wait
for problems to come up instead.

* Better naming, some comments

* Count bailing on kw only iseqs

On railsbench:
```
opt_send_without_block exit reasons:
                  bmethod      59729 (27.7%)
         optimized_method      59137 (27.5%)
      iseq_complex_callee      41362 (19.2%)
             alias_method      33346 (15.5%)
      callsite_not_simple      19170 ( 8.9%)
       iseq_only_keywords       1300 ( 0.6%)
                 kw_splat       1299 ( 0.6%)
    cfunc_ruby_array_varg         18 ( 0.0%)
```
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert
96f4f918b0 Implement greedy versioning. Refactor versioning logic. (#10)
* Implement eager versioning. Refactor versioning logic.

* Add --version-limit and --greedy-versioning command-line args
2021-10-20 18:19:34 -04:00
Alan Wu
4c7afa64b4 Make gen_opt_aref() delegate to gen_opt_send_without_block() (#9)
Basically mirroring the interpreter for the general case.
2021-10-20 18:19:34 -04:00
Alan Wu
f1b11fa454 Comment edits 2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert
3e80104024 Aesthetic changes and add missing counter 2021-10-20 18:19:34 -04:00
Alan Wu
8106a95efb English 2021-10-20 18:19:34 -04:00