[前][次][番号順一覧][スレッド一覧]

ruby-changes:73120

From: Maxime <ko1@a...>
Date: Tue, 30 Aug 2022 00:53:34 +0900 (JST)
Subject: [ruby-changes:73120] efb45acb29 (master): Load GC Value operands into registers

https://git.ruby-lang.org/ruby.git/commit/?id=efb45acb29

From efb45acb2932dd8ebd60853584370ca75653cdf8 Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...>
Date: Tue, 24 May 2022 16:30:18 -0400
Subject: Load GC Value operands into registers

---
 yjit/src/backend/ir.rs | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/yjit/src/backend/ir.rs b/yjit/src/backend/ir.rs
index 9ed8f34c3e..63a0478984 100644
--- a/yjit/src/backend/ir.rs
+++ b/yjit/src/backend/ir.rs
@@ -219,7 +219,7 @@ pub enum Opnd https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/ir.rs#L219
 
 impl Opnd
 {
-    // Convenience constructor for memory operands
+    /// Convenience constructor for memory operands
     pub fn mem(num_bits: u8, base: Opnd, disp: i32) -> Self {
         match base {
             Opnd::Reg(base_reg) => {
@@ -233,6 +233,11 @@ impl Opnd https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/ir.rs#L233
             _ => unreachable!()
         }
     }
+
+    /// Constant pointer operand
+    pub fn const_ptr(ptr: *const u8) -> Self {
+        Opnd::UImm(ptr as u64)
+    }
 }
 
 /// NOTE: this is useful during the port but can probably be removed once
@@ -436,7 +441,32 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/ir.rs#L441
     /// can.
     pub(super) fn split_loads(self) -> Assembler
     {
+        // Load operands that are GC values into a register
+        fn load_gc_opnds(op: Op, opnds: Vec<Opnd>, asm: &mut Assembler) -> Vec<Opnd>
+        {
+            if op == Op::Load || op == Op::Mov {
+                return opnds;
+            }
+
+            fn map_opnd(opnd: Opnd, asm: &mut Assembler) -> Opnd {
+                if let Opnd::Value(val) = opnd {
+                    // If this is a heap object, load it into a register
+                    if !val.special_const_p() {
+                        asm.load(opnd);
+                    }
+                }
+
+                opnd
+            }
+
+            opnds.into_iter().map(|opnd| map_opnd(opnd, asm)).collect()
+        }
+
         self.transform_insns(|asm, _, op, opnds, target| {
+            // Load heap object operands into registers because most
+            // instructions can't directly work with 64-bit constants
+            let opnds = load_gc_opnds(op, opnds, asm);
+
             match op {
                 // Check for Add, Sub, And, Mov, with two memory operands.
                 // Load one operand into memory.
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]