Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion zjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def dump_locations # :nodoc:
filename = "zjit_exits_#{Process.pid}.dump"
n_bytes = dump_exit_locations(filename)

$stderr.puts("#{n_bytes} bytes written to #{filename}.")
absolute_filename = File.expand_path(filename)
$stderr.puts("#{n_bytes} bytes written to #{absolute_filename}")
end
end
5 changes: 4 additions & 1 deletion zjit/src/asm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub mod arm64;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Label(pub usize);

/// The object that knows how to encode the branch instruction.
type BranchEncoder = Box<dyn Fn(&mut CodeBlock, i64, i64)>;

/// Reference to an ASM label
pub struct LabelRef {
// Position in the code block where the label reference exists
Expand All @@ -33,7 +36,7 @@ pub struct LabelRef {
num_bytes: usize,

/// The object that knows how to encode the branch instruction.
encode: Box<dyn Fn(&mut CodeBlock, i64, i64)>,
encode: BranchEncoder,
}

/// Block of memory into which instructions can be assembled
Expand Down
9 changes: 4 additions & 5 deletions zjit/src/backend/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg(test)]
use crate::asm::CodeBlock;
use crate::backend::lir::*;
use crate::cruby::*;
Expand Down Expand Up @@ -63,10 +62,10 @@ fn test_alloc_regs() {
}

fn setup_asm() -> (Assembler, CodeBlock) {
return (
(
Assembler::new(),
CodeBlock::new_dummy()
);
)
}

// Test full codegen pipeline
Expand Down Expand Up @@ -198,8 +197,8 @@ fn test_c_call()
#[test]
fn test_alloc_ccall_regs() {
let mut asm = Assembler::new();
let out1 = asm.ccall(0 as *const u8, vec![]);
let out2 = asm.ccall(0 as *const u8, vec![out1]);
let out1 = asm.ccall(std::ptr::null::<u8>(), vec![]);
let out2 = asm.ccall(std::ptr::null::<u8>(), vec![out1]);
asm.mov(EC, out2);
let mut cb = CodeBlock::new_dummy();
asm.compile_with_regs(&mut cb, Assembler::get_alloc_regs()).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion zjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,7 @@ fn function_stub_hit_body(cb: &mut CodeBlock, iseq_call: &IseqCallRef) -> Result

// We currently don't support JIT-to-JIT calls for ISEQs with optional arguments.
// So we only need to use jit_entry_ptrs[0] for now. TODO(Shopify/ruby#817): Support optional arguments.
let Some(&jit_entry_ptr) = jit_entry_ptrs.get(0) else {
let Some(&jit_entry_ptr) = jit_entry_ptrs.first() else {
return Err(CompileError::JitToJitOptional)
};

Expand Down
11 changes: 6 additions & 5 deletions zjit/src/cruby_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ pub fn init() -> Annotations {

annotate!(rb_mKernel, "itself", inline_kernel_itself);
annotate!(rb_mKernel, "block_given?", inline_kernel_block_given_p);
annotate!(rb_cString, "bytesize", types::Fixnum, no_gc, leaf);
annotate!(rb_cString, "bytesize", types::Fixnum, no_gc, leaf, elidable);
annotate!(rb_cString, "size", types::Fixnum, no_gc, leaf, elidable);
annotate!(rb_cString, "length", types::Fixnum, no_gc, leaf, elidable);
Expand Down Expand Up @@ -226,6 +225,9 @@ pub fn init() -> Annotations {
annotate_builtin!(rb_mKernel, "Float", types::Float);
annotate_builtin!(rb_mKernel, "Integer", types::Integer);
annotate_builtin!(rb_mKernel, "class", types::Class, leaf);
annotate_builtin!(rb_mKernel, "frozen?", types::BoolExact);
annotate_builtin!(rb_cSymbol, "name", types::StringExact);
annotate_builtin!(rb_cSymbol, "to_s", types::StringExact);

Annotations {
cfuncs: std::mem::take(cfuncs),
Expand All @@ -238,15 +240,15 @@ fn no_inline(_fun: &mut hir::Function, _block: hir::BlockId, _recv: hir::InsnId,
}

fn inline_string_to_s(fun: &mut hir::Function, block: hir::BlockId, recv: hir::InsnId, args: &[hir::InsnId], state: hir::InsnId) -> Option<hir::InsnId> {
if args.len() == 0 && fun.likely_a(recv, types::StringExact, state) {
if args.is_empty() && fun.likely_a(recv, types::StringExact, state) {
let recv = fun.coerce_to(block, recv, types::StringExact, state);
return Some(recv);
}
None
}

fn inline_kernel_itself(_fun: &mut hir::Function, _block: hir::BlockId, recv: hir::InsnId, args: &[hir::InsnId], _state: hir::InsnId) -> Option<hir::InsnId> {
if args.len() == 0 {
if args.is_empty() {
// No need to coerce the receiver; that is done by the SendWithoutBlock rewriting.
return Some(recv);
}
Expand All @@ -256,8 +258,7 @@ fn inline_kernel_itself(_fun: &mut hir::Function, _block: hir::BlockId, recv: hi
fn inline_kernel_block_given_p(fun: &mut hir::Function, block: hir::BlockId, _recv: hir::InsnId, args: &[hir::InsnId], _state: hir::InsnId) -> Option<hir::InsnId> {
let &[] = args else { return None; };
// TODO(max): In local iseq types that are not ISEQ_TYPE_METHOD, rewrite to Constant false.
let result = fun.push_insn(block, hir::Insn::IsBlockGiven);
return Some(result);
Some(fun.push_insn(block, hir::Insn::IsBlockGiven))
}

fn inline_array_aref(fun: &mut hir::Function, block: hir::BlockId, recv: hir::InsnId, args: &[hir::InsnId], state: hir::InsnId) -> Option<hir::InsnId> {
Expand Down
Loading