miniruby --zjit -e nil
runs through iseq_to_ssa
This commit is contained in:
parent
0f9557e9a7
commit
1d95139bf6
Notes:
git
2025-04-18 13:49:48 +00:00
3
vm.c
3
vm.c
@ -496,6 +496,9 @@ jit_compile_exception(rb_execution_context_t *ec)
|
|||||||
if (body->jit_exception_calls == rb_yjit_call_threshold) {
|
if (body->jit_exception_calls == rb_yjit_call_threshold) {
|
||||||
rb_yjit_compile_iseq(iseq, ec, true);
|
rb_yjit_compile_iseq(iseq, ec, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return body->jit_exception;
|
return body->jit_exception;
|
||||||
}
|
}
|
||||||
|
28
zjit.c
28
zjit.c
@ -134,3 +134,31 @@ rb_zjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit
|
|||||||
|
|
||||||
RB_VM_LOCK_LEAVE();
|
RB_VM_LOCK_LEAVE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
rb_iseq_encoded_size(const rb_iseq_t *iseq)
|
||||||
|
{
|
||||||
|
return iseq->body->iseq_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the opcode given a program counter. Can return trace opcode variants.
|
||||||
|
int
|
||||||
|
rb_iseq_opcode_at_pc(const rb_iseq_t *iseq, const VALUE *pc)
|
||||||
|
{
|
||||||
|
// YJIT should only use iseqs after AST to bytecode compilation
|
||||||
|
RUBY_ASSERT_ALWAYS(FL_TEST_RAW((VALUE)iseq, ISEQ_TRANSLATED));
|
||||||
|
|
||||||
|
const VALUE at_pc = *pc;
|
||||||
|
return rb_vm_insn_addr2opcode((const void *)at_pc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the PC for a given index in an iseq
|
||||||
|
VALUE *
|
||||||
|
rb_iseq_pc_at_idx(const rb_iseq_t *iseq, uint32_t insn_idx)
|
||||||
|
{
|
||||||
|
RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(iseq, imemo_iseq));
|
||||||
|
RUBY_ASSERT_ALWAYS(insn_idx < iseq->body->iseq_size);
|
||||||
|
VALUE *encoded = iseq->body->iseq_encoded;
|
||||||
|
VALUE *pc = &encoded[insn_idx];
|
||||||
|
return pc;
|
||||||
|
}
|
||||||
|
@ -158,7 +158,7 @@ fn to_ssa(opcodes: &Vec<RubyOpcode>) -> Function {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iseq_to_ssa(iseq: *const rb_iseq_t) -> Function {
|
pub fn iseq_to_ssa(iseq: *const rb_iseq_t) {
|
||||||
let mut result = Function::new();
|
let mut result = Function::new();
|
||||||
let mut state = FrameState::new();
|
let mut state = FrameState::new();
|
||||||
let block = result.entry_block;
|
let block = result.entry_block;
|
||||||
@ -206,13 +206,14 @@ fn iseq_to_ssa(iseq: *const rb_iseq_t) -> Function {
|
|||||||
YARVINSN_leave => {
|
YARVINSN_leave => {
|
||||||
result.push_insn(block, Insn::Return { val: state.pop() });
|
result.push_insn(block, Insn::Return { val: state.pop() });
|
||||||
}
|
}
|
||||||
_ => todo!(),
|
_ => eprintln!("zjit: unknown opcode {opcode}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move to the next instruction to compile
|
// Move to the next instruction to compile
|
||||||
insn_idx += insn_len(opcode as usize);
|
insn_idx += insn_len(opcode as usize);
|
||||||
}
|
}
|
||||||
return result;
|
dbg!(result);
|
||||||
|
return;
|
||||||
|
|
||||||
fn get_arg(pc: *const VALUE, arg_idx: isize) -> VALUE {
|
fn get_arg(pc: *const VALUE, arg_idx: isize) -> VALUE {
|
||||||
unsafe { *(pc.offset(arg_idx + 1)) }
|
unsafe { *(pc.offset(arg_idx + 1)) }
|
||||||
|
@ -25,7 +25,7 @@ pub extern "C" fn rb_zjit_parse_option() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rb_zjit_iseq_gen_entry_point(_iseq: IseqPtr, _ec: EcPtr) -> *const u8 {
|
pub extern "C" fn rb_zjit_iseq_gen_entry_point(iseq: IseqPtr, _ec: EcPtr) -> *const u8 {
|
||||||
println!("compiling zjit");
|
ir::iseq_to_ssa(iseq);
|
||||||
std::ptr::null()
|
std::ptr::null()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user