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

250 Коммитов

Автор SHA1 Сообщение Дата
Alan Wu d098c5560b Shave a few instructions off of leave
The code path for leave that returns to the interpreter
(gen_leave() -> yjit_gen_leave_exit()) used to have the logic:

```
    cfp->sp++;
    cfp->sp[-1] = return_val;
    cfp->sp--;
    return return_val;
```

The SP changes it made was unnecessary and this change removes it.

After this change, `leave` doesn't adjust the `cfp->sp` of the caller
and only writes `cfp->sp[0]`. To accomodate this in the JIT-to-JIT
return case, return stubs have an `sp_offset` of 1.

The change removes sp adjustment from the JIT-to-JIT return case, too,
making it more efficient. Also, since the C method case of `send`
has an `sp_offset` of 1 after the call, this change enables block
version sharing.
2021-10-20 18:19:39 -04:00
Alan Wu ed85e8a33a Use reg1 in GEN_COUNTER_INC to avoid clobbering RAX 2021-10-20 18:19:39 -04:00
John Hawthorn c210fade27 Implement newrange 2021-10-20 18:19:39 -04:00
John Hawthorn 3ecc6befcd Implement invokesuper using cfp->ep[ME] check
This fixes and re-enables invokesuper, replacing the existing guards
with a guard on the method entry for the EP.
2021-10-20 18:19:39 -04:00
John Hawthorn e527912fe0 Use jit_prepare_routine_call 2021-10-20 18:19:39 -04:00
John Hawthorn 69a2531249 Implement gen_putstring 2021-10-20 18:19:39 -04:00
Alan Wu 2bd99d7d7a typo, rename, comment 2021-10-20 18:19:39 -04:00
John Hawthorn 812597676b Avoid immediate side exits in checktype
Previously checktype only supported heap objects, however it's not
uncommon to receive an immediate, for example when string interpolating
a Symbol or Integer.
2021-10-20 18:19:39 -04:00
Alan Wu 54db64f7a5 filter out internal events. add comments. reorder 2021-10-20 18:19:39 -04:00
Alan Wu 4b815abb37 Lock, don't loock. 2021-10-20 18:19:39 -04:00
Alan Wu bd876c243a TracePoint support
This change fixes some cases where YJIT fails to fire tracing events.
Most of the situations YJIT did not handle correctly involves enabling
tracing while running inside generated code.

A new operation to invalidate all generated code is added, which uses
patching to make generated code exit at the next VM instruction
boundary. A new routine called `jit_prepare_routine_call()` is
introduced to facilitate this and should be used when generating code
that could allocate, or could otherwise use `RB_VM_LOCK_ENTER()`.

The `c_return` event is fired in the middle of an instruction as opposed
to at an instruction boundary, so it requires special handling. C method
call return points are patched to go to a fucntion which does everything
the interpreter does, including firing the `c_return` event. The
generated code for C method calls normally does not fire the event.

Invalided code should not change after patching so the exits are not
clobbered. A new variable is introduced to track the region of code that
should not change.
2021-10-20 18:19:39 -04:00
Maxime Chevalier-Boisvert 0562459473 Redo the ivtable lookp once the ivar is set 2021-10-20 18:19:39 -04:00
Maxime Chevalier-Boisvert b3e993a64b Make sure that there is always an index table entry for getivars 2021-10-20 18:19:39 -04:00
Jean Boussier 0dc3bba6f2 Allow to compile with --yjit-stats support but not the full RUBY_DEBUG
RUBY_DEBUG have a very significant performance overhead. Enough that
YJIT with RUBY_DEBUG is noticeably slower than the interpreter without
RUBY_DEBUG.

This makes it hard to collect yjit-stats in production environments.

By allowing to collect JIT statistics without the RUBy_DEBUG overhead,
I hope to make such use cases smoother.
2021-10-20 18:19:39 -04:00
eileencodes 2ba090a1f9 Add toregexp to yjit
The FIXME is there so we remember to investigate why insns clears the
temporary array. Is this necessary? If it's not we can remove it from
both.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-10-20 18:19:39 -04:00
Maxime Chevalier-Boisvert dd5082d7ca Use cmov to handle Qundef case in getivar instead of side-exit 2021-10-20 18:19:39 -04:00
Maxime Chevalier-Boisvert c4b99d6a42 Add ASM comment 2021-10-20 18:19:39 -04:00
John Hawthorn e18b0b6eba Implement putspecialobject 2021-10-20 18:19:39 -04:00
John Hawthorn 3edf29668e Add opt_regexpmatch2 2021-10-20 18:19:39 -04:00
John Hawthorn 595fdf8d66 Assign directly to C_ARG_REGS now when possible 2021-10-20 18:19:39 -04:00
John Hawthorn 8fa0ee4d40 Use callee-saved regs for REG_SP, REG_EP, REG_CFP 2021-10-20 18:19:39 -04:00
John Hawthorn 48dca3348a Move yjit_type_of_value into yjit_core.c 2021-10-20 18:19:38 -04:00
John Hawthorn d78ea4abec Implement verify_ctx for debugging 2021-10-20 18:19:38 -04:00
John Hawthorn a02002dc4f More detection of immediate constants 2021-10-20 18:19:38 -04:00
eileencodes d2e8b99b5b Implement tostring instruction for yjit
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-10-20 18:19:38 -04:00
John Hawthorn 6c80150d40 Introduce ctx_{get,set}_opnd_mapping 2021-10-20 18:19:38 -04:00
John Hawthorn 4ea69e5c0b Rename to ctx_upgrade_opnd_type 2021-10-20 18:19:38 -04:00
John Hawthorn 53079ca585 Return if fixnums impossible 2021-10-20 18:19:38 -04:00
Alan Wu f4f940e5a6 Save PC and SP before accessing globals
These instructions are marked as not leaf in insns.def, which indicate
that they could raise exceptions and/or call Ruby methods.
2021-10-20 18:19:38 -04:00
eileencodes b91078ea74 Add setglobal to yjit
Adds yjit support for setting global variables.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Co-authored-by: John Hawthorn <john@hawthorn.email>
2021-10-20 18:19:38 -04:00
eileencodes 50029fb127 Add getglobal to yjit
Adds getglobal to yjit and a test for it.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-10-20 18:19:38 -04:00
Aaron Patterson 84a1e04e58 Change register definitions to match the entry point calling convention
The JIT entry point passes the CFP as RSI and the EC as RDI.  Lets match
that so we don't have to shuffle registers around.
2021-10-20 18:19:38 -04:00
Aaron Patterson 05b5a7f011 Add a guard that we start executing on the first PC
Methods with optional parameters don't always start executing at the
first PC, but we compile all methods assuming that they do.  This commit
adds a guard to ensure that we're actually starting at the first PC for
methods with optional params
2021-10-20 18:19:37 -04:00
Aaron Patterson 0fdcdd267f fix alignment 2021-10-20 18:19:37 -04:00
Aaron Patterson d0174d99c6 Always use `ret` to return to the interpreter
Always using `ret` to return to the interpreter means that we never have
to check the VM_FRAME_FLAG_FINISH flag.

In the case that we return `Qundef`, the interpreter will execute the
cfp.  We can take advantage of this by setting the PC to the instruction
we can't handle, and let the interpreter pick up the ball from there.

If we return a value other than Qundef, the interpreter will take that
value as the "return value" from the JIT and push that to the SP of the
caller

The leave instruction puts the return value on the top of the calling
frame's stack.  YJIT does the same thing for leave instructions.
However, when we're returning back to the interpreter, the leave
instruction _should not_ put the return value on the top of the stack,
but put it in RAX and use RET.  This commit pops the last value from the
stack pointer and puts it in RAX so that the interpreter is happy with
SP.
2021-10-20 18:19:37 -04:00
Kevin Newton 9a436da064 Ensure we guard the value before we return
Otherwise you can end up not implicitly calling `to_ary`, which if it has side-effects will result in different behavior.
2021-10-20 18:19:37 -04:00
Kevin Newton 341d5bdcb2 Code review for expandarray and tests 2021-10-20 18:19:37 -04:00
Kevin Newton 97025db90e Convert jumps to cmov 2021-10-20 18:19:37 -04:00
Kevin Deisz bfde30c326 Implement expandarray 2021-10-20 18:19:37 -04:00
Kevin Newton be648e0940 Implement splatarray 2021-10-20 18:19:37 -04:00
John Hawthorn dc8aca1883 Use push and pop in jit_rb_obj_not to avoid corrupting types 2021-10-20 18:19:37 -04:00
John Hawthorn 0c390e9965 Add assertions of types in jit_guard_known_klass 2021-10-20 18:19:37 -04:00
Kevin Deisz ba9aa1f8ef Implement opt_div 2021-10-20 18:19:37 -04:00
Kevin Deisz b0ae4fdcfb Implement opt_mult
Basically the same thing as opt_mod, but for multiplying.
2021-10-20 18:19:37 -04:00
Maxime Chevalier-Boisvert 6cb4edd73f Implement swap instruction 2021-10-20 18:19:37 -04:00
John Hawthorn 9e0a56fb24 Add FLONUM detection 2021-10-20 18:19:37 -04:00
John Hawthorn dfc5e5e35b Support guards against symbols and integers
This adds guards
2021-10-20 18:19:37 -04:00
John Hawthorn c3f264b62c Allow chaining on immediate guard
In jit_guard_known_klass whenever we encounter a new class should
recompile the current instruction.

However, previously once jit_guard_known_klass had guarded for a heap
object it would not recompile for  any immediate (special const) objects
arriving afterwards and would take a plain side-exit instead of a chain
guard.

This commit uses jit_chain_guard inside jit_guard_known_klass instead of
the plain side exit, so that we can recompile for any special constants
arriving afterwards.
2021-10-20 18:19:37 -04:00
John Hawthorn 94cb5a6b1e Implement opt_neq 2021-10-20 18:19:36 -04:00
Alan Wu 3996e0ab07 Add tests, comments, and an assert for invokesuper 2021-10-20 18:19:36 -04:00
John Hawthorn 71560f8804 Add opt_size and opt_length 2021-10-20 18:19:36 -04:00
John Hawthorn e4bf905a28 Use an st_table for optimized method codegen
We recently added the ability to optimize a known cfunc with custom code
generation for it.

Previously we performed this lookup with a switch statement on the
address of the c function being called. This commit swaps that out for a
hash lookup on the method definition. For now I've kept this limited
this to cfuncs, but it wouldn't take significant changes to make this
work for other method types.

This implemenation is similar to how the interpreter keeps track of
which BOPs (basic operations) are redefined

This has a few advantages:
- Doesn't the C function's symbol to be exported (they're often static)
- This could support VM_METHOD_TYPE_OPTIMIZED in the future.
- This could support VM_METHOD_TYPE_ISEQ in the future. Kernel#class
  would be a good candidate for this since to yjit it will just be a
  constant push as we already know the class through BBV.
- Slightly cleaner to declare
- Less tightly coupled to each method's implementation

And a couple minor trade-offs:
- The looser coupling could be seen as a disadvantage (I don't think so,
- If a cfunc is defined multiple times we would need to declare it on
  each definition. ex. BasicObject#== and BasicObject#equal?. This is
  rare compared to using an alias.
2021-10-20 18:19:36 -04:00
Alan Wu 0cd3b97e02 Handle non-material empty singleton class properly
As an optimization, multiple objects could share the same singleton
class. The optimization introduced in 6698e43393
wasn't handling this correctly so was generating guards that never pass
for the inputs we defer compilation to wait for. After generating
identical code multiple times and failing, the call site is falsely
recognized as megamorphic and it side exits. See disassembly for the
following before this commit:

    def foo(obj)
      obj.itself
    end

    o = Object.new.singleton_class
    foo(o)
    puts YJIT.disasm(method(:foo))

See also: comment in rb_singleton_class_clone_and_attach().
2021-10-20 18:19:36 -04:00
Alan Wu 89110590a3 Disable invokesuper codegen for now. Add test
The added test fails with SystemStackError with --yjit-call-threshold=1.
2021-10-20 18:19:36 -04:00
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
Alan Wu 10c0275b11 Use jmp with memory operand for smaller code size 2021-10-20 18:19:34 -04:00
Alan Wu 1610dc0864 YJIT: use a context-free landing pad to optimize `leave`
This allows gen_leave to always do an indirect to cfp->jit_return.
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert 9bd779cbf9 Don't check if value is immediate if context has type info 2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert e66c9f8c62 Remove redundant mov 2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert adbd7ff332 Fix frozen check (use jnz) and move heap object check. 2021-10-20 18:19:34 -04:00
Aaron Patterson 435d7c5088 Improve set instance variable
This commit improves the set ivar implementation.
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert 60496b6666 Pass self type through method calls 2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert 0cc73ca2a9 Malloc branch entries (#112)
* Malloc branch entries

* Add ASM comment for stack overflow check

* WIP

* Fix branch GC code. Add rb_darray_remove_unordered().

* Fix block end_pos after branch rewriting. Remove dst_patched bits.
2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert 33c975b813 Merge pull request #114 from Shopify/yjit-dup-comments
YJIT: Avoid adding duplicate code comments
2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert 23f88957e6 Switch to 2-comparison heap object check 2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert f2530f884e Improve codegen and type tracking in putobject 2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert 6250506de2 Remove debug prints 2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert edaf12def6 Fix local type tracking in getlocal, setlocal. Add test. 2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert 791f20af6e WIP 2021-10-20 18:19:33 -04:00
Alan Wu 476a3f4be7 Use a insn_opnd instead of a bool 2021-10-20 18:19:33 -04:00
Alan Wu 4442029ec4 move assert. opnd.idx doesn't make sense for OPND_SELF 2021-10-20 18:19:33 -04:00
Alan Wu 4ea2e753f6 YJIT: implement calls to ivar getter methods 2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert 6164274c76 Re-enable local type tracking, until first call 2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert 0805cba735 Update yjit_codegen.c 2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert 2404ff691d Factor our guard_two_fixnums(). Implement opt_or. 2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert f6e3f75c2b Introduce concept of YJIT instruction operands 2021-10-20 18:19:33 -04:00
Alan Wu b626dd7211 YJIT: Fancier opt_getinlinecache
Make sure `opt_getinlinecache` is in a block all on its own, and
invalidate it from the interpreter when `opt_setinlinecache`.
It will recompile with a filled cache the second time around.
This lets YJIT runs well when the IC for constant is cold.
2021-10-20 18:19:33 -04:00
Alan Wu 515fb988fe YJIT: add comments to disassembly
Introduce a new macro `ADD_COMMENT(cb, comment)` that records a comment
for the current write position in the code block.

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Aaron Patterson <aaron.patterson@shopify.com>
2021-10-20 18:19:33 -04:00
Alan Wu 7f4b9e8e61 YJIT: make ratio_in_yjit more accurate
Don't count instructions that take exit to the interpreter.
2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert 54312d777c Disable local type tracking for now 2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert cbbae12a96 Keep track of local types in the context 2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert c299112fd7 use ctx_stack_push_self() 2021-10-20 18:19:32 -04:00
Maxime Chevalier-Boisvert aee44e4f2b Part 1 of improved type tracking logic 2021-10-20 18:19:32 -04:00
Maxime Chevalier-Boisvert ac1aa84c1a First sketch at temp type mapping 2021-10-20 18:19:32 -04:00
Alan Wu d03b7f77d4 Fix GCC warnings
Mostly unused and uninitialized warnings here and there
2021-10-20 18:19:32 -04:00
Alan Wu 2b09e2fe7b Add a comment 2021-10-20 18:19:32 -04:00
Maxime Chevalier-Boisvert fe784d1449 Track interpreter return as an exit reason for leave instr 2021-10-20 18:19:32 -04:00
Maxime Chevalier-Boisvert 0e5c3d66b8 Implement opt_gt 2021-10-20 18:19:32 -04:00
Alan Wu 63f875b841 Factor out protected callee guard, check for private callees
We didn't need the private check before because we were lifting from the
interpreter's cache, and the interpreter only caches when visibility
checks go through.
2021-10-20 18:19:32 -04:00
Alan Wu 8173d54020 Factor out jit_jump_to_next_insn 2021-10-20 18:19:32 -04:00
Alan Wu fbb514f67e Introduce yjit_guard_known_klass() 2021-10-20 18:19:32 -04:00
Alan Wu a8f7eb2f35 Polymorphic opt_send_without_block 2021-10-20 18:19:32 -04:00
Alan Wu ec1cbbb07d Get rid of dependency on rb_call_cache 2021-10-20 18:19:32 -04:00
Alan Wu 0cd9120f17 YJIT: hash specialization for opt_aref
Make it lazy and add a hash specialization in addition to the array
specialization.
2021-10-20 18:19:32 -04:00
Alan Wu db53decad6 Exit reason breakdown for opt_aref 2021-10-20 18:19:32 -04:00
Alan Wu c04e5188d5 YJIT: use a flat array for finding codegen functions
Simpler and faster.
2021-10-20 18:19:32 -04:00
Alan Wu 927ead9f75 YJIT: unify exits. Patch iseqs only when necessary
* YJIT: unify exits. Patch iseqs only when necessary

This fixes the gotcha that returning YJIT_CANT_COPMILE for an
instruction at entry position leading to infinite loop.

Also, iseq patching is only done only when necessary, which should make
most exits faster.

* Now that exits are the same, return YJIT_CANT_COMPILE
2021-10-20 18:19:32 -04:00
Alan Wu 5d834bcf9f YJIT: lazy polymorphic getinstancevariable
Lazily compile out a chain of checks for different known classes and
whether `self` embeds its ivars or not.

* Remove trailing whitespaces

* Get proper addresss in Capstone disassembly

* Lowercase address in Capstone disassembly

Capstone uses lowercase for jump targets in generated listings. Let's
match it.

* Use the same successor in getivar guard chains

Cuts down on duplication

* Address reviews

* Fix copypasta error

* Add a comment
2021-10-20 18:19:31 -04:00
Maxime Chevalier-Boisvert c6156e5113 Fix trailing spaces 2021-10-20 18:19:31 -04:00
Aaron Patterson c15a577eda Make Blocks depend on BOPS
When a BOP is redefined, the BOP redefinition callback will invalidate
any blocks that depend on BOPS.  This allows us to eliminate runtime
checks for BOP redefinition.
2021-10-20 18:19:31 -04:00
Jose Narvaez 4e2eb7695e Yet Another Ruby JIT!
Renaming uJIT to YJIT. AKA s/ujit/yjit/g.
2021-10-20 18:19:31 -04:00