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

ruby-changes:69203

From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:02 +0900 (JST)
Subject: [ruby-changes:69203] 791f20af6e (master): WIP

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

From 791f20af6e9a5db37e69ed33c6b91fc15d9fe824 Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...>
Date: Thu, 15 Apr 2021 12:21:51 -0400
Subject: WIP

---
 yjit_codegen.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 75 insertions(+), 8 deletions(-)

diff --git a/yjit_codegen.c b/yjit_codegen.c
index 7f012cdeff..7e98e21a55 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -350,9 +350,9 @@ yjit_gen_block(ctx_t *ctx, block_t *block, rb_execution_context_t *ec) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L350
             break;
         }
 
-        if (0) {
+        if (1) {
             fprintf(stderr, "compiling %d: %s\n", insn_idx, insn_name(opcode));
-            print_str(cb, insn_name(opcode));
+            //print_str(cb, insn_name(opcode));
         }
 
         // :count-placement:
@@ -521,19 +521,47 @@ gen_putself(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L521
 static codegen_status_t
 gen_getlocal_wc0(jitstate_t* jit, ctx_t* ctx)
 {
-    // Load environment pointer EP from CFP
-    mov(cb, REG0, member_opnd(REG_CFP, rb_control_frame_t, ep));
-
     // Compute the offset from BP to the local
     int32_t local_idx = (int32_t)jit_get_arg(jit, 0);
     const int32_t offs = -(SIZEOF_VALUE * local_idx);
 
+
+
+    /*
+    if (local_idx < 8)
+    {
+        val_type_t local_type = ctx->local_types[local_idx];
+
+        if (local_type.type == ETYPE_FIXNUM) {
+            fprintf(stderr, "local_idx=%d is fixnum\n", local_idx);
+            ADD_COMMENT(cb, "local is fixnum");
+        }
+        else {
+            fprintf(stderr, "local_idx=%d not fixnum\n", local_idx);
+            ADD_COMMENT(cb, "local not fixnum");
+        }
+    }
+    else
+    {
+        fprintf(stderr, "local_idx=%d\n", local_idx);
+    }
+    */
+
+
+    fprintf(stderr, "local_idx=%d\n", local_idx);
+
+
+
+
+
+    // Load environment pointer EP from CFP
+    mov(cb, REG0, member_opnd(REG_CFP, rb_control_frame_t, ep));
+
     // Load the local from the EP
     mov(cb, REG0, mem_opnd(64, REG0, offs));
 
     // Write the local at SP
     x86opnd_t stack_top = ctx_stack_push_local(ctx, local_idx);
-    //x86opnd_t stack_top = ctx_stack_push(ctx, TYPE_UNKNOWN);
     mov(cb, stack_top, REG0);
 
     return YJIT_KEEP_COMPILING;
@@ -1763,6 +1791,43 @@ gen_oswb_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L1791
     // Stub so we can return to JITted code
     blockid_t return_block = { jit->iseq, jit_next_insn_idx(jit) };
 
+
+    // Create a context for the callee
+    ctx_t callee_ctx = DEFAULT_CTX;
+
+    // Set the argument type in the callee's context
+    for (int32_t arg_idx = 0; arg_idx < argc; ++arg_idx) {
+        fprintf(stderr, "set arg type, arg_idx=%d\n", arg_idx);
+
+        // x is arg0, but pushed last
+
+        val_type_t arg_type = ctx_get_opnd_type(ctx, OPND_STACK(argc - arg_idx - 1));
+
+        if (arg_type.type == ETYPE_FIXNUM)
+            fprintf(stderr, "is fixnum\n");
+        else
+            fprintf(stderr, "not fixnum\n");
+
+        ctx_set_local_type(&callee_ctx, arg_idx, arg_type);
+    }
+
+
+
+    fprintf(stderr, "local types\n");
+    for (int32_t local_idx = 0; local_idx < argc; ++local_idx) {
+        fprintf(stderr, "local_idx=%d\n", local_idx);
+
+        val_type_t type = callee_ctx.local_types[local_idx];
+
+        if (type.type == ETYPE_FIXNUM)
+            fprintf(stderr, "is fixnum\n");
+        else
+            fprintf(stderr, "not fixnum\n");
+    }
+
+
+
+
     // Pop arguments and receiver in return context, push the return value
     // After the return, the JIT and interpreter SP will match up
     ctx_t return_ctx = *ctx;
@@ -1784,12 +1849,12 @@ gen_oswb_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L1849
     //print_str(cb, "calling Ruby func:");
     //print_str(cb, rb_id2name(vm_ci_mid(ci)));
 
-    // Load the updated SP
+    // Load the updated SP from the CFP
     mov(cb, REG_SP, member_opnd(REG_CFP, rb_control_frame_t, sp));
 
     // Directly jump to the entry point of the callee
     gen_direct_jump(
-        &DEFAULT_CTX,
+        &callee_ctx,
         (blockid_t){ iseq, 0 }
     );
 
@@ -1943,6 +2008,7 @@ gen_leave(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L2008
     mov(cb, REG0, member_opnd(REG_CFP, rb_control_frame_t, ep));
 
     // if (flags & VM_FRAME_FLAG_FINISH) != 0
+    ADD_COMMENT(cb, "check for finish frame");
     x86opnd_t flags_opnd = mem_opnd(64, REG0, sizeof(VALUE) * VM_ENV_DATA_INDEX_FLAGS);
     test(cb, flags_opnd, imm_opnd(VM_FRAME_FLAG_FINISH));
     jnz_ptr(cb, COUNTED_EXIT(side_exit, leave_se_finish_frame));
@@ -1968,6 +2034,7 @@ gen_leave(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L2034
     mov(cb, mem_opnd(64, REG_SP, -SIZEOF_VALUE), REG0);
 
     // If the return address is NULL, fall back to the interpreter
+    ADD_COMMENT(cb, "check for jit return");
     int FALLBACK_LABEL = cb_new_label(cb, "FALLBACK");
     test(cb, REG1, REG1);
     jz_label(cb, FALLBACK_LABEL);
-- 
cgit v1.2.1


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

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