Split out from the CCall changes since we discussed during pairing that
this is useful to unblock some other changes. No tests since no one
consumes this profiling data yet.
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: ...... }`.
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.
* 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
This gives output stability while still showing address equality and
inequality.
This mapping mechanism is only turned on for FunctionPrinter, so
implementation of Display and Debug can share the same code but not go
through the mapping process. Outside of `cfg!(test)` we don't want
and need to stabilize the addresses.
Prism hides the objects from the GC by setting the objects' class fields
to 0, so class_of returns 0 (unexpectedly, at least to me). Instead, use
builtin_type.
* Convert send (with block) to HIR
* Remove newline
Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
---------
Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
This reverts commit e2eae71d44ced602946d54a083f600848eab79e9.
The $state exists for switching Fixnum insn, so guard_two_fixnums and
SendWithoutBlock shouldn't need to use $state. The other macro argument
pattern doesn't have $state, so it's now inconsistent.
Key here is calling rb_call_builtin_inits(), which sticking to public
API for robustness is done by calling ruby_options().
Fixes: https://github.com/Shopify/zjit/issues/61
* 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
* Implement codegen for Test insn
* Update zjit/src/codegen.rs
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
---------
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
* Explicitly give function parameters types
Entrypoint blocks have no predecessors, so they are not otherwise typed.
This means we have to explicitly mark them as being Object.
* Refactor some tests
* Add union and predicates for testing if immediate
* Add tests
* Improve description for Primitive
* Add undef to immediates
Also partition Any into (Primitive | Value), where Value is
(Object | Undef)
* Add BasicObject to hierarchy
* Rename Value to RubyValue and Primitive to CValue