summaryrefslogtreecommitdiff
path: root/yjit_codegen.c
AgeCommit message (Collapse)Author
2021-10-20More detection of immediate constantsJohn Hawthorn
2021-10-20Implement tostring instruction for yjiteileencodes
Co-authored-by: Aaron Patterson <[email protected]>
2021-10-20Introduce ctx_{get,set}_opnd_mappingJohn Hawthorn
2021-10-20Rename to ctx_upgrade_opnd_typeJohn Hawthorn
2021-10-20Return if fixnums impossibleJohn Hawthorn
2021-10-20Save PC and SP before accessing globalsAlan Wu
These instructions are marked as not leaf in insns.def, which indicate that they could raise exceptions and/or call Ruby methods.
2021-10-20Add setglobal to yjiteileencodes
Adds yjit support for setting global variables. Co-authored-by: Aaron Patterson <[email protected]> Co-authored-by: John Hawthorn <[email protected]>
2021-10-20Add getglobal to yjiteileencodes
Adds getglobal to yjit and a test for it. Co-authored-by: Aaron Patterson <[email protected]>
2021-10-20Change register definitions to match the entry point calling conventionAaron Patterson
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-20Add a guard that we start executing on the first PCAaron Patterson
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-20fix alignmentAaron Patterson
2021-10-20Always use `ret` to return to the interpreterAaron Patterson
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-20Ensure we guard the value before we returnKevin Newton
Otherwise you can end up not implicitly calling `to_ary`, which if it has side-effects will result in different behavior.
2021-10-20Code review for expandarray and testsKevin Newton
2021-10-20Convert jumps to cmovKevin Newton
2021-10-20Implement expandarrayKevin Deisz
2021-10-20Implement splatarrayKevin Newton
2021-10-20Use push and pop in jit_rb_obj_not to avoid corrupting typesJohn Hawthorn
2021-10-20Add assertions of types in jit_guard_known_klassJohn Hawthorn
2021-10-20Implement opt_divKevin Deisz
2021-10-20Implement opt_multKevin Deisz
Basically the same thing as opt_mod, but for multiplying.
2021-10-20Implement swap instructionMaxime Chevalier-Boisvert
2021-10-20Add FLONUM detectionJohn Hawthorn
2021-10-20Support guards against symbols and integersJohn Hawthorn
This adds guards
2021-10-20Allow chaining on immediate guardJohn Hawthorn
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-20Implement opt_neqJohn Hawthorn
2021-10-20Add tests, comments, and an assert for invokesuperAlan Wu
2021-10-20Add opt_size and opt_lengthJohn Hawthorn
2021-10-20Use an st_table for optimized method codegenJohn Hawthorn
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-20Handle non-material empty singleton class properlyAlan Wu
As an optimization, multiple objects could share the same singleton class. The optimization introduced in 6698e433934d810b16ee3636b63974c0a75c07f0 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-20Disable invokesuper codegen for now. Add testAlan Wu
The added test fails with SystemStackError with --yjit-call-threshold=1.
2021-10-20Fix bug in generic case for gen_checktypeAlan Wu
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-20Simplify known class check for singletonsJohn Hawthorn
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-20Delay and be selective about when to discard local typesAlan Wu
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-20Improve opt_not by expanding cfunc codegenAlan Wu
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 <[email protected]> Co-authored-by: Noah Gibbs <[email protected]>
2021-10-20Add invokebuiltin_delegate_leaveJohn Hawthorn
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-20Implement invokebuiltin_delegateJohn Hawthorn
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-20Fix compiler warningMaxime Chevalier-Boisvert
2021-10-20Implement topn instructionAaron Patterson
This commit implements the topn instruction Co-Authored-By: Maxime Chevalier-Boisvert <[email protected]> Co-Authored-By: Noah Gibbs <[email protected]>
2021-10-20Better commentsJohn Hawthorn
2021-10-20Avoid looping on invokesuper on module included multiple timesJohn Hawthorn
2021-10-20Check for refinements in gen_invokesuperJohn Hawthorn
2021-10-20Guard against implicitly forwarded blockJohn Hawthorn
2021-10-20Add invokesuperJohn Hawthorn
2021-10-20Implement gen_getlocalJohn Hawthorn
This extracts the generation code from getlocal_wc1, since this is the same just with more loops inside vm_get_ep.
2021-10-20Can't add comments to the outlined code blockMaxime Chevalier-Boisvert
2021-10-20Add duparray to YJIT codegenJohn Hawthorn
2021-10-20Fix check for leaf invokebuiltinJohn Hawthorn
Also added a comment when inlining a leaf builtin
2021-10-20Use builtin_inline_p to avoid pushing a frame for primitive C methods (#63)Maxime Chevalier-Boisvert
* 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 <[email protected]>
2021-10-20Add concatstrings to yjit codegen (#58)John Hawthorn
* Add ETYPE_TRUE and ETYPE_FALSE * Implement checktype * Implement concatstrings * Update deps