summaryrefslogtreecommitdiff
path: root/zjit/src/codegen.rs
AgeCommit message (Collapse)Author
3 daysZJIT: Only write LIR output of HIR instructions with outputMax Bernstein
Notes: Merged: https://github.com/ruby/ruby/pull/13602
3 daysZJIT: Add codegen for SideExitMax Bernstein
Notes: Merged: https://github.com/ruby/ruby/pull/13602
3 daysZJIT: Write a callee frame on JIT-to-JIT calls (#13579)Takashi Kokubun
Co-authored-by: Max Bernstein <[email protected]> Notes: Merged-By: k0kubun <[email protected]>
6 daysZJIT: Support get/set on global variablesAaron Patterson
Adds support for code like: ```ruby $foo $foo = x ``` Notes: Merged: https://github.com/ruby/ruby/pull/13569
10 daysZJIT: Add codegen for uncached setinstancevariableMax Bernstein
Notes: Merged: https://github.com/ruby/ruby/pull/13527
10 daysZJIT: Add codegen for uncached getinstancevariableMax Bernstein
I didn't know `rb_ivar_get` existed until @Xrxr pointed me to it. Thanks, Alan! Notes: Merged: https://github.com/ruby/ruby/pull/13527
10 daysZJIT: Panic unimplemented for OOB basic block args (#13533)Shannon Skipper
Notes: Merged-By: k0kubun <[email protected]>
10 daysZJIT: Pass self through basic block params (#13529)Takashi Kokubun
* ZJIT: Pass self through basic block params Co-authored-by: Max Bernstein <[email protected]> * Add comments for self * Use self_param for ivar * Make self_param a loop local * Fix rest parameter type check * Push self_param first * Add a test case for putself * Use SELF_PARAM_IDX Co-authored-by: Max Bernstein <[email protected]> * Fix test_unknown --------- Co-authored-by: Max Bernstein <[email protected]> Notes: Merged-By: k0kubun <[email protected]>
11 daysZJIT: Add newrange support (#13505)Stan Lo
* Add newrange support to zjit * Add RangeType enum for Range insn's flag * Address other feedback Notes: Merged-By: k0kubun <[email protected]>
11 daysZJIT: Implement side exits for entry frames (#13469)Takashi Kokubun
Co-authored-by: Max Bernstein <[email protected]> Co-authored-by: Alan Wu <[email protected]> Notes: Merged-By: k0kubun <[email protected]>
12 daysZJIT: Spill to the stack using arguments instead of FrameStateAlan Wu
The FrameState on the SendWithoutBlock represents the entry state, but for instructions that push to the stack in the middle of the instruction before actually doing the send like opt_aref_with, the FrameState is incorrect. We need to write to the stack using the arguments for the instruction. Notes: Merged: https://github.com/ruby/ruby/pull/13468
2025-05-20ZJIT: Allow DCE to remove some CCalls (#13363)Max Bernstein
Allow DCE to remove some CCalls Add `elidable` field that signals that there would be no discernible effect if the call to the method were removed. The default is false. Notes: Merged-By: k0kubun <[email protected]>
2025-05-15ZJIT: Bail out of recursive compilation if we can't compile calleeMax Bernstein
Right now we just crash if we can't compile an ISEQ for any reason (unimplemented in HIR, unimplemented in codegen, ...) and this fixes that by bailing out. Notes: Merged: https://github.com/ruby/ruby/pull/13356
2025-04-28ZJIT: Drop a duplicated call into optimize (#13196)Takashi Kokubun
* ZJIT: Drop a duplicated call into optimize * Update a comment Co-authored-by: Max Bernstein <[email protected]> --------- Co-authored-by: Max Bernstein <[email protected]> Notes: Merged-By: k0kubun <[email protected]>
2025-04-24Make PatchPoint(CalleeModifiedLocals) implicitMax Bernstein
We don't have a good model for modeling weakref-like instruction dependency behavior and I don't think we should add it just for this. Notes: Merged: https://github.com/ruby/ruby/pull/13162
2025-04-22ZJIT: Add option to dump LIR (#13139)Max Bernstein
Now we can dump HIR, optimized HIR, LIR, and assembly. Notes: Merged-By: k0kubun <[email protected]>
2025-04-18Add codegen for NewArray instruction (https://github.com/Shopify/zjit/pull/110)Aiden Fox Ivey
* Show failing test * Add second test case * Add empty NewArray setup * Update opt_tests and fix NewArray instantiation * Add code generation for NewArray * Add NewArray ordering test Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Implement JIT-to-JIT calls (https://github.com/Shopify/zjit/pull/109)Takashi Kokubun
* Implement JIT-to-JIT calls * Use a closer dummy address for Arm64 * Revert an obsoleted change * Revert a few more obsoleted changes * Fix outdated comments * Explain PosMarkers for CCall * s/JIT code/machine code/ * Get rid of ParallelMov Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Add codegen support for ArrayDupAiden Fox Ivey
Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Add return_type to FnProperties and CCallMax Bernstein
Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Strength reduce to `CCall` for sends landing in simple C methodsAlan Wu
A new optimization pass. Also: - Printing for `Insn::CCall` - Wrap `ID` and add convenience method for printing, replacing calls to rb_id2name() Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Insert PatchPoint after each SendMax Bernstein
In case the callee writes to the caller's locals, we need to be able to immediately side-exit because our frame's invariants might have been invalidated. If in the course of optimization we rewrite the Send, we can choose to remove the PatchPoint too---but it's not an error to keep it around. Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Add miscellaneous Clippy 'corrections' pt. 2 ↵Aiden Fox Ivey
(https://github.com/Shopify/zjit/pull/95) * Remove immediately deferenced borrow operators source: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow * Remove unnecessary cast as i64 Since Const::CInt64 wraps i64, it is unnecessary to cast to i64. * Remove unnecessary borrow operators * Beautify assign operation syntax * Use .is_null() convenience method * Omit .into() call from u32 to u32 * Use more descriptive std::ptr::null<VALUE>() In lieu of casting a literal as a type, opt to use the convenience type. * Use sized integer literal * Simplify pattern matching to explicit check Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Print block param names in asm comment (https://github.com/Shopify/zjit/pull/93)Takashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Use find() in frame_state()Max Bernstein
We want to return representatives for the stack and locals. Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Rewrite SendWithoutBlock to SendWithoutBlockDirect when possibleMax Bernstein
In calls to top-level functions, we assume that call targets will not get rewritten, so we can insert a PatchPoint and do the lookup at compile-time. Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Compile Param into VReg and ParallelMov ↵Takashi Kokubun
(https://github.com/Shopify/zjit/pull/87) Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Fix s/Raw/Debug/gMax Bernstein
Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Add option to dump optimized HIRMax Bernstein
Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Make disassembly look nicer using InsnPrinterMax Bernstein
This makes the disassembly comments much easier to read because they use the more familiar `v2` rather than `InsnId(2)` and `Fixnum` rather than `Type { bits: ...... }`. Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Add constant folding pass (https://github.com/Shopify/zjit/pull/74)Max Bernstein
Add a constant folding pass for HIR. This pass uses the types left by `infer_types` to fold away: * `GuardType(val, ty)` where `val` is already `ty` * `FixnumAdd(l, r)` where `l` and `r` are constants * `FixnumLt(l, r)` where `l` and `r` are constants * `FixnumEq(l, r)` where `l` and `r` are constants * `Test(v)`, where `v` is a constant * `IfTrue(v)` and `IfFalse(v)` where `v` is a constant It does this by using the union-find data structure in the IR to avoid a complicated manual find-and-replace process for all the uses. Right now, for branch instructions that it deletes, we remove from the block completely. This is safe only because we have ensured that nothing refers to branch instructions---they produce no values. However, if we want to instead replace them with Nops that get ignored during codegen or removed by a later DCE pass, that works for me as well. Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Compile IfFalse, IfTrue, and Jump instructions ↵Takashi Kokubun
(https://github.com/Shopify/zjit/pull/72) * Compile IfFalse instruction * Add a TODO comment * Rename *s_len to num_*s * Run only gen_param() against block.params * Add a few more tests * Wrap label indexes with Label * Compile blocks in reverse post-order * Simplify a nested test * s/get_block/block/ * Return a number instead of an iterator * Clarify the allocator uses disjoint sets of registers * Use Display for Block and Insn * Compile IfTrue and Jump * Avoid resolving Param instructions * Always compile Insn::Param as basic block arguments * Remove an obsoleted variable * Change it back to use find * Use find for params too * Use Display more * Add more tests * nested if * if after if * if elsif else * loop after loop * nested loops * if in loop * loop in if Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Implement dynamic dispatch for opt_send_without_block ↵Takashi Kokubun
(https://github.com/Shopify/zjit/pull/63) * Implement dynamic dispatch for opt_send_without_block * Rename stack methods * Fix typos * More clarification on gen_save_sp() * Update a comment * Update a comment about spills * Rename name to method_name * Test no-arg and 2-arg method calls Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Implement codegen for Test insn (https://github.com/Shopify/zjit/pull/57)Maxime Chevalier-Boisvert
* Implement codegen for Test insn * Update zjit/src/codegen.rs Co-authored-by: Alan Wu <[email protected]> --------- Co-authored-by: Alan Wu <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Implement all basic Fixnum instructions ↵Takashi Kokubun
(https://github.com/Shopify/zjit/pull/50) * Implement all basic Fixnum instructions * Use opnd! macro for other instructions as well Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Compile FixnumLt (https://github.com/Shopify/zjit/pull/48)Max Bernstein
Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Set a return value before popping registers ↵Takashi Kokubun
(https://github.com/Shopify/zjit/pull/41) Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Fix a comment for subtractionTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Implement Insn::FixnumSub (https://github.com/Shopify/zjit/pull/42)Takashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Move lib.rs functions to appropriate modules ↵Takashi Kokubun
(https://github.com/Shopify/zjit/pull/43) Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Implement Insn::Param using the SP register ↵Takashi Kokubun
(https://github.com/Shopify/zjit/pull/39) Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Load an immediate into a register in the backend ↵Takashi Kokubun
(https://github.com/Shopify/zjit/pull/38) Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Load Param off of cfp->ep (https://github.com/Shopify/zjit/pull/31)Takashi Kokubun
* Load Param off of cfp->ep * Test with --zjit-call-threshold=1 as well * Fix get_opnd's debug output * Return Mem operand from gen_param * Test both first and second calls * Spell out the namespace for Opnd returns * Update a comment about gen_param * Explain why we take a lock * Fix a typo Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Share FrameState by storing it on FunctionMax Bernstein
Give every instruction a cheap ID to hold onto instead of owning a copy. Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Implement FixnumAdd and stub PatchPoint/GuardType ↵Takashi Kokubun
(https://github.com/Shopify/zjit/pull/30) * Implement FixnumAdd and stub PatchPoint/GuardType Co-authored-by: Max Bernstein <[email protected]> Co-authored-by: Maxime Chevalier-Boisvert <[email protected]> * Clone Target for arm64 * Use $create instead of use create Co-authored-by: Alan Wu <[email protected]> * Fix misindentation from suggested changes * Drop an unneeded variable for mut * Load operand into a register only if necessary --------- Co-authored-by: Max Bernstein <[email protected]> Co-authored-by: Maxime Chevalier-Boisvert <[email protected]> Co-authored-by: Alan Wu <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Add compact Type latticeMax Bernstein
This will be used for local type inference and potentially SCCP. Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Compile Insn::Const (https://github.com/Shopify/zjit/pull/18)Takashi Kokubun
* Compile Insn::Const * Update the comment on JITState * Print insn index like YJIT * Wrap and unwrap InsnId Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Rename --zjit-dump-ssa to --zjit-dump-hir ↵Takashi Kokubun
(https://github.com/Shopify/zjit/pull/17) * Rename --zjit-dump-ssa to --zjit-dump-hir * Update comments * Add a comment on iseq_to_hir Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Remove OpndMax Bernstein
Notes: Merged: https://github.com/ruby/ruby/pull/13131
2025-04-18Rename `backend::Opnd` to `backend::lir::Opnd` ↵Takashi Kokubun
(https://github.com/Shopify/zjit/pull/13) Notes: Merged: https://github.com/ruby/ruby/pull/13131