diff options
author | Takashi Kokubun <[email protected]> | 2022-11-23 09:14:43 -0800 |
---|---|---|
committer | GitHub <[email protected]> | 2022-11-23 12:14:43 -0500 |
commit | a50aabde9cf3b58c63563427b2e7d22c60370cdd (patch) | |
tree | 65c078da68929b09d5b57f8acf9a3cc285dbcef6 /yjit/src | |
parent | 5ee947314eac6bc8ce2ee28a0619beb0250f704a (diff) |
YJIT: Simplify Insn::CCall to obviate Target::FunPtr (#6793)
Notes
Notes:
Merged-By: maximecb <[email protected]>
Diffstat (limited to 'yjit/src')
-rw-r--r-- | yjit/src/backend/arm64/mod.rs | 10 | ||||
-rw-r--r-- | yjit/src/backend/ir.rs | 12 | ||||
-rw-r--r-- | yjit/src/backend/x86_64/mod.rs | 16 |
3 files changed, 10 insertions, 28 deletions
diff --git a/yjit/src/backend/arm64/mod.rs b/yjit/src/backend/arm64/mod.rs index 5ff0ac3709..a34b844c8f 100644 --- a/yjit/src/backend/arm64/mod.rs +++ b/yjit/src/backend/arm64/mod.rs @@ -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) => { diff --git a/yjit/src/backend/ir.rs b/yjit/src/backend/ir.rs index de8bac7465..a2020b97eb 100644 --- a/yjit/src/backend/ir.rs +++ b/yjit/src/backend/ir.rs @@ -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 } diff --git a/yjit/src/backend/x86_64/mod.rs b/yjit/src/backend/x86_64/mod.rs index 7186879f98..297a0fd852 100644 --- a/yjit/src/backend/x86_64/mod.rs +++ b/yjit/src/backend/x86_64/mod.rs @@ -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!() } } |