YJIT: Simplify Insn::CCall to obviate Target::FunPtr (#6793)

This commit is contained in:
Takashi Kokubun 2022-11-23 09:14:43 -08:00 committed by GitHub
parent 5ee947314e
commit a50aabde9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
Notes: git 2022-11-23 17:15:03 +00:00
Merged-By: maximecb <maximecb@ruby-lang.org>
3 changed files with 10 additions and 28 deletions

View File

@ -317,7 +317,7 @@ impl Assembler
let (opnd0, opnd1) = split_boolean_operands(asm, left, right);
asm.xor(opnd0, opnd1);
},
Insn::CCall { opnds, target, .. } => {
Insn::CCall { opnds, fptr, .. } => {
assert!(opnds.len() <= C_ARG_OPNDS.len());
// Load each operand into the corresponding argument
@ -339,7 +339,7 @@ impl Assembler
// Now we push the CCall without any arguments so that it
// just performs the call.
asm.ccall(target.unwrap_fun_ptr(), vec![]);
asm.ccall(fptr, vec![]);
},
Insn::Cmp { left, right } => {
let opnd0 = split_load_operand(asm, left);
@ -676,7 +676,6 @@ impl Assembler
bcond(cb, CONDITION, InstructionOffset::from_bytes(bytes));
});
},
Target::FunPtr(_) => unreachable!()
};
}
@ -938,10 +937,10 @@ impl Assembler
emit_pop(cb, A64Opnd::Reg(reg));
}
},
Insn::CCall { target, .. } => {
Insn::CCall { fptr, .. } => {
// The offset to the call target in bytes
let src_addr = cb.get_write_ptr().into_i64();
let dst_addr = target.unwrap_fun_ptr() as i64;
let dst_addr = *fptr as i64;
// Use BL if the offset is short enough to encode as an immediate.
// Otherwise, use BLR with a register.
@ -983,7 +982,6 @@ impl Assembler
b(cb, InstructionOffset::from_bytes(bytes));
});
},
_ => unreachable!()
};
},
Insn::Je(target) | Insn::Jz(target) => {

View File

@ -256,19 +256,11 @@ pub enum Target
{
CodePtr(CodePtr), // Pointer to a piece of YJIT-generated code
SideExitPtr(CodePtr), // Pointer to a side exit code
FunPtr(*const u8), // Pointer to a C function
Label(usize), // A label within the generated code
}
impl Target
{
pub fn unwrap_fun_ptr(&self) -> *const u8 {
match self {
Target::FunPtr(ptr) => *ptr,
_ => unreachable!("trying to unwrap {:?} into fun ptr", self)
}
}
pub fn unwrap_label_idx(&self) -> usize {
match self {
Target::Label(idx) => *idx,
@ -330,7 +322,7 @@ pub enum Insn {
CPushAll,
// C function call with N arguments (variadic)
CCall { opnds: Vec<Opnd>, target: Target, out: Opnd },
CCall { opnds: Vec<Opnd>, fptr: *const u8, out: Opnd },
// C function return
CRet(Opnd),
@ -1297,7 +1289,7 @@ impl Assembler {
pub fn ccall(&mut self, fptr: *const u8, opnds: Vec<Opnd>) -> Opnd {
let out = self.next_opnd_out(Opnd::match_num_bits(&opnds));
self.push_insn(Insn::CCall { target: Target::FunPtr(fptr), opnds, out });
self.push_insn(Insn::CCall { fptr, opnds, out });
out
}

View File

@ -304,7 +304,7 @@ impl Assembler
asm.not(opnd0);
},
Insn::CCall { opnds, target, .. } => {
Insn::CCall { opnds, fptr, .. } => {
assert!(opnds.len() <= C_ARG_OPNDS.len());
// Load each operand into the corresponding argument
@ -315,7 +315,7 @@ impl Assembler
// Now we push the CCall without any arguments so that it
// just performs the call.
asm.ccall(target.unwrap_fun_ptr(), vec![]);
asm.ccall(*fptr, vec![]);
},
_ => {
if insn.out_opnd().is_some() {
@ -533,8 +533,8 @@ impl Assembler
},
// C function call
Insn::CCall { target, .. } => {
call_ptr(cb, RAX, target.unwrap_fun_ptr());
Insn::CCall { fptr, .. } => {
call_ptr(cb, RAX, *fptr);
},
Insn::CRet(opnd) => {
@ -583,7 +583,6 @@ impl Assembler
match *target {
Target::CodePtr(code_ptr) | Target::SideExitPtr(code_ptr) => jmp_ptr(cb, code_ptr),
Target::Label(label_idx) => jmp_label(cb, label_idx),
_ => unreachable!()
}
}
@ -591,7 +590,6 @@ impl Assembler
match *target {
Target::CodePtr(code_ptr) | Target::SideExitPtr(code_ptr) => je_ptr(cb, code_ptr),
Target::Label(label_idx) => je_label(cb, label_idx),
_ => unreachable!()
}
}
@ -599,7 +597,6 @@ impl Assembler
match *target {
Target::CodePtr(code_ptr) | Target::SideExitPtr(code_ptr) => jne_ptr(cb, code_ptr),
Target::Label(label_idx) => jne_label(cb, label_idx),
_ => unreachable!()
}
}
@ -607,7 +604,6 @@ impl Assembler
match *target {
Target::CodePtr(code_ptr) | Target::SideExitPtr(code_ptr) => jl_ptr(cb, code_ptr),
Target::Label(label_idx) => jl_label(cb, label_idx),
_ => unreachable!()
}
},
@ -615,7 +611,6 @@ impl Assembler
match *target {
Target::CodePtr(code_ptr) | Target::SideExitPtr(code_ptr) => jbe_ptr(cb, code_ptr),
Target::Label(label_idx) => jbe_label(cb, label_idx),
_ => unreachable!()
}
},
@ -623,7 +618,6 @@ impl Assembler
match *target {
Target::CodePtr(code_ptr) | Target::SideExitPtr(code_ptr) => jz_ptr(cb, code_ptr),
Target::Label(label_idx) => jz_label(cb, label_idx),
_ => unreachable!()
}
}
@ -631,7 +625,6 @@ impl Assembler
match *target {
Target::CodePtr(code_ptr) | Target::SideExitPtr(code_ptr) => jnz_ptr(cb, code_ptr),
Target::Label(label_idx) => jnz_label(cb, label_idx),
_ => unreachable!()
}
}
@ -639,7 +632,6 @@ impl Assembler
match *target {
Target::CodePtr(code_ptr) | Target::SideExitPtr(code_ptr) => jo_ptr(cb, code_ptr),
Target::Label(label_idx) => jo_label(cb, label_idx),
_ => unreachable!()
}
}