ruby-changes:73102
From: Maxime <ko1@a...>
Date: Tue, 30 Aug 2022 00:45:21 +0900 (JST)
Subject: [ruby-changes:73102] 92e9d1e661 (master): Switch IR to use Option<Target>
https://git.ruby-lang.org/ruby.git/commit/?id=92e9d1e661 From 92e9d1e66186d41a01f6116d1993fbfd66fdf1a6 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Thu, 12 May 2022 14:05:48 -0400 Subject: Switch IR to use Option<Target> --- yjit/src/ir.rs | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/yjit/src/ir.rs b/yjit/src/ir.rs index d3cc76d2d1..13f81f0af7 100644 --- a/yjit/src/ir.rs +++ b/yjit/src/ir.rs @@ -44,10 +44,7 @@ pub enum Op https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L44 // operand (typically generated by ir_str_ptr). Comment, - // Add a label into the IR at the point that this instruction is added. It - // will eventually be translated into an offset when generating code such - // that EIR_LABEL_IDX operands know where to jump to. Accepts as its only - // operand an EIR_LABEL_NAME operand (typically generated by ir_label_opnd). + // Add a label into the IR at the point that this instruction is added. Label, // Add two operands together, and return the result as a new operand. This @@ -323,7 +320,7 @@ enum Target https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L320 { CodePtr(CodePtr), // Pointer to a piece of code (e.g. side-exit) LabelName(String), // A label without an index in the output - LabelIdx(u32), // A label that has been indexed + LabelIdx(usize), // A label that has been indexed } /// YJIT IR instruction @@ -335,9 +332,8 @@ pub struct Insn https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L332 // List of input operands/values opnds: Vec<Opnd>, - // Kevin asks: do we really need multiple branch targets? // List of branch targets (branch instructions only) - targets: Vec<Target>, + target: Option<Target>, // Position in the generated machine code // Useful for comments and for patching jumps @@ -359,14 +355,14 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L355 } } - fn push_insn(&mut self, op: Op, opnds: Vec<Opnd>, targets: Vec<Target>) -> Opnd + fn push_insn(&mut self, op: Op, opnds: Vec<Opnd>, target: Option<Target>) -> Opnd { let insn_idx = self.insns.len(); let insn = Insn { op: op, opnds: opnds, - targets: targets, + target: target, pos: None }; self.insns.push(insn); @@ -375,10 +371,26 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L371 Opnd::InsnOut(insn_idx) } - // TODO: - //fn label(&self, name: &str) -> Target - //{ - //} + // Add a label at the current position + fn label(&mut self, name: &str) -> Target + { + let insn_idx = self.insns.len(); + + let insn = Insn { + op: Op::Label, + opnds: vec![], + target: None, + pos: None + }; + self.insns.push(insn); + + Target::LabelIdx(insn_idx) + } + + fn alloc_regs(&mut self) + { + // ??? + } // Optimize and compile the stored instructions fn compile() @@ -395,32 +407,25 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L407 // 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![]) + self.push_insn(Op::Add, vec![ Opnd::String(text.to_owned()) ], None); } - */ // Low-level, no output operand fn test(&mut self, opnd0: Opnd, opnd1: Opnd) { - self.push_insn(Op::Add, vec![opnd0, opnd1], vec![]); + self.push_insn(Op::Add, vec![opnd0, opnd1], None); } // Low-level, no output operand fn mov(&mut self, opnd0: Opnd, opnd1: Opnd) { - self.push_insn(Op::Add, vec![opnd0, opnd1], vec![]); + self.push_insn(Op::Add, vec![opnd0, opnd1], None); } // Jump if not zero fn jnz(&mut self, target: Target) { - self.push_insn(Op::Jnz, vec![], vec![target]); + self.push_insn(Op::Jnz, vec![], Some(target)); } } @@ -430,7 +435,7 @@ macro_rules! def_push_insn_2_opnd { https://github.com/ruby/ruby/blob/trunk/yjit/src/ir.rs#L435 { fn $op_name(&mut self, opnd0: Opnd, opnd1: Opnd) -> Opnd { - self.push_insn($opcode, vec![opnd0, opnd1], vec![]) + self.push_insn($opcode, vec![opnd0, opnd1], None) } } }; -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/