ruby-changes:73097
From: Maxime <ko1@a...>
Date: Tue, 30 Aug 2022 00:45:18 +0900 (JST)
Subject: [ruby-changes:73097] 909d214708 (master): Progress on IR sketch
https://git.ruby-lang.org/ruby.git/commit/?id=909d214708 From 909d214708d87e1dab618a04b4780dd926c721ca Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Wed, 11 May 2022 16:45:15 -0400 Subject: Progress on IR sketch --- yjit/src/ir.rs | 80 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/yjit/src/ir.rs b/yjit/src/ir.rs index a20a982493..8c35f7f615 100644 --- a/yjit/src/ir.rs +++ b/yjit/src/ir.rs @@ -319,7 +319,7 @@ impl From<X86Opnd> for Opnd { https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L319 /// Branch target (something that we can jump to) /// for branch instructions #[derive(Clone, PartialEq, Eq, Debug)] -enum BranchTarget +enum Target { CodePtr(CodePtr), // Pointer to a piece of code (e.g. side-exit) LabelName(String), // A label without an index in the output @@ -336,7 +336,7 @@ pub struct Insn https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L336 opnds: Vec<Opnd>, // List of branch targets (branch instructions only) - targets: Vec<BranchTarget>, + targets: Vec<Target>, // Position in the generated machine code // Useful for comments and for patching jumps @@ -358,7 +358,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L358 } } - fn push_insn(&mut self, op: Op, opnds: Vec<Opnd>, targets: Vec<BranchTarget>) -> Opnd + fn push_insn(&mut self, op: Op, opnds: Vec<Opnd>, targets: Vec<Target>) -> Opnd { let insn_idx = self.insns.len(); @@ -375,7 +375,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L375 } // TODO: - //fn label(&self, name: &str) -> BranchTarget + //fn label(&self, name: &str) -> Target //{ //} @@ -391,18 +391,41 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L391 impl Assembler { + // Add a comment, no output operand + fn comment(&mut self, text: &str) + { + self.push_insn(Op::Add, vec![ Opnd::String(text.to_owned()) ], vec![]); + } + fn add(&mut self, opnd0: Opnd, opnd1: Opnd) -> Opnd { self.push_insn(Op::Add, vec![opnd0, opnd1], vec![]) } - fn mov(&mut self, opnd0: Opnd, opnd1: Opnd) -> Opnd + // Low-level, no output operand + fn test(&mut self, opnd0: Opnd, opnd1: Opnd) + { + self.push_insn(Op::Add, vec![opnd0, opnd1], vec![]); + } + + // Jump if not zero + fn jnz(&mut self, target: Target) + { + self.push_insn(Op::Jnz, vec![], vec![target]); + } + + // Low-level, no output operand + fn mov(&mut self, opnd0: Opnd, opnd1: Opnd) { self.push_insn(Op::Add, vec![opnd0, opnd1], vec![]); - Opnd::None } } + + + + + // NOTE: these methods are temporary and will likely move // to context.rs later // They are just wrappers to convert from X86Opnd into the IR Opnd type @@ -424,7 +447,7 @@ impl Context https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L447 #[cfg(test)] mod tests { use super::*; - + use crate::cruby::*; use crate::core::*; use InsnOpnd::*; @@ -443,6 +466,23 @@ mod tests { https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L466 + // TODO + fn guard_object_is_heap( + asm: &mut Assembler, + object_opnd: Opnd, + ctx: &mut Context, + side_exit: CodePtr, + ) { + asm.comment("guard object is heap"); + + // Test that the object is not an immediate + asm.test(object_opnd, Opnd::UImm(RUBY_IMMEDIATE_MASK as u64)); + asm.jnz(Target::CodePtr(side_exit)); + + // Test that the object is not false or nil + //cmp(cb, object_opnd, uimm_opnd(Qnil.into())); + //jbe_ptr(cb, side_exit); + } #[test] fn test_add() { @@ -451,29 +491,3 @@ mod tests { https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L491 asm.add(out, Opnd::UImm(2)); } } - - - - - -// TODO: we need a test instruction -// Can we combine this with a branch? -// -/* -fn guard_object_is_heap( - cb: &mut CodeBlock, - object_opnd: X86Opnd, - _ctx: &mut Context, - side_exit: CodePtr, -) { - add_comment(cb, "guard object is heap"); - - // Test that the object is not an immediate - test(cb, object_opnd, uimm_opnd(RUBY_IMMEDIATE_MASK as u64)); - jnz_ptr(cb, side_exit); - - // Test that the object is not false or nil - cmp(cb, object_opnd, uimm_opnd(Qnil.into())); - jbe_ptr(cb, side_exit); -} -*/ \ No newline at end of file -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/