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

ruby-changes:68793

From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:13:35 +0900 (JST)
Subject: [ruby-changes:68793] 1a937dd196 (master): Use darray for incoming branches

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

From 1a937dd1964cf8f1f02093d5d2a53f00792668f3 Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...>
Date: Fri, 19 Feb 2021 16:04:23 -0500
Subject: Use darray for incoming branches

---
 ujit_codegen.c |  8 ++++----
 ujit_core.c    | 33 ++++++++++++---------------------
 ujit_core.h    |  6 ++----
 3 files changed, 18 insertions(+), 29 deletions(-)

diff --git a/ujit_codegen.c b/ujit_codegen.c
index ac911eee58..590fb29821 100644
--- a/ujit_codegen.c
+++ b/ujit_codegen.c
@@ -1050,7 +1050,7 @@ gen_jump(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L1050
 }
 
 static bool
-gen_opt_swb_cfunc(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_callable_method_entry_t *cme, int32_t argc)
+gen_oswb_cfunc(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_callable_method_entry_t *cme, int32_t argc)
 {
     const rb_method_cfunc_t *cfunc = UNALIGNED_MEMBER_PTR(cme->def, body.cfunc);
 
@@ -1276,7 +1276,7 @@ gen_return_branch(codeblock_t* cb, uint8_t* target0, uint8_t* target1, uint8_t s https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L1276
 }
 
 static bool
-gen_opt_swb_iseq(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_callable_method_entry_t *cme, int32_t argc)
+gen_oswb_iseq(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_callable_method_entry_t *cme, int32_t argc)
 {
     const rb_iseq_t *iseq = def_iseq_ptr(cme->def);
     const VALUE* start_pc = iseq->body->iseq_encoded;
@@ -1494,13 +1494,13 @@ gen_opt_send_without_block(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L1494
     // If this is a C call
     if (cme->def->type == VM_METHOD_TYPE_CFUNC)
     {
-        return gen_opt_swb_cfunc(jit, ctx, cd, cme, argc);
+        return gen_oswb_cfunc(jit, ctx, cd, cme, argc);
     }
 
     // If this is a Ruby call
     if (cme->def->type == VM_METHOD_TYPE_ISEQ)
     {
-        return gen_opt_swb_iseq(jit, ctx, cd, cme, argc);
+        return gen_oswb_iseq(jit, ctx, cd, cme, argc);
     }
 
     return false;
diff --git a/ujit_core.c b/ujit_core.c
index a73fb78dbc..4f20477c50 100644
--- a/ujit_core.c
+++ b/ujit_core.c
@@ -209,17 +209,6 @@ add_block_version(blockid_t blockid, block_t* block) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L209
     }
 }
 
-// Add an incoming branch for a given block version
-static void add_incoming(block_t* p_block, uint32_t branch_idx)
-{
-    // Add this branch to the list of incoming branches for the target
-    uint32_t* new_list = malloc(sizeof(uint32_t) * (p_block->num_incoming + 1));
-    memcpy(new_list, p_block->incoming, sizeof(uint32_t) * p_block->num_incoming);
-    new_list[p_block->num_incoming] = branch_idx;
-    p_block->incoming = new_list;
-    p_block->num_incoming += 1;
-}
-
 // Count the number of block versions matching a given blockid
 static size_t count_block_versions(blockid_t blockid)
 {
@@ -333,7 +322,8 @@ block_t* gen_block_version(blockid_t blockid, const ctx_t* start_ctx) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L322
 
         // Patch the last branch address
         last_branch->dst_addrs[0] = cb_get_ptr(cb, block->start_pos);
-        add_incoming(block, branch_idx);
+        rb_darray_append(&block->incoming, branch_idx);
+
         RUBY_ASSERT(block->start_pos == last_branch->end_pos);
     }
 
@@ -410,7 +400,7 @@ uint8_t* branch_stub_hit(uint32_t branch_idx, uint32_t target_idx) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L400
     }
 
     // Add this branch to the list of incoming branches for the target
-    add_incoming(p_block, branch_idx);
+    rb_darray_append(&p_block->incoming, branch_idx);
 
     // Update the branch target address
     dst_addr = cb_get_ptr(cb, p_block->start_pos);
@@ -446,8 +436,9 @@ uint8_t* get_branch_target( https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L436
     if (p_block)
     {
         // Add an incoming branch for this version
-        add_incoming(p_block, branch_idx);
+        rb_darray_append(&p_block->incoming, branch_idx);
 
+        // Return a pointer to the compiled code
         return cb_get_ptr(cb, p_block->start_pos);
     }
 
@@ -568,7 +559,7 @@ void gen_direct_jump( https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L559
     // If the version already exists
     if (p_block)
     {
-        add_incoming(p_block, branch_idx);
+        rb_darray_append(&p_block->incoming, branch_idx);
         dst_addr0 = cb_get_ptr(cb, p_block->start_pos);
         branch_shape = SHAPE_DEFAULT;
 
@@ -607,8 +598,7 @@ void https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L598
 ujit_free_block(block_t *block)
 {
     ujit_unlink_method_lookup_dependency(block);
-
-    free(block->incoming);
+    rb_darray_free(block->incoming);
     free(block);
     rb_darray_free(block->gc_object_offsets);
 }
@@ -645,10 +635,11 @@ invalidate_block_version(block_t* block) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L635
     uint8_t* code_ptr = cb_get_ptr(cb, block->start_pos);
 
     // For each incoming branch
-    for (uint32_t i = 0; i < block->num_incoming; ++i)
+    uint32_t* branch_idx;
+    rb_darray_foreach(block->incoming, i, branch_idx)
     {
-        uint32_t branch_idx = block->incoming[i];
-        branch_t* branch = &branch_entries[branch_idx];
+        //uint32_t branch_idx = block->incoming[i];
+        branch_t* branch = &branch_entries[*branch_idx];
         uint32_t target_idx = (branch->dst_addrs[0] == code_ptr)? 0:1;
         //fprintf(stderr, "branch_idx=%d, target_idx=%d\n", branch_idx, target_idx);
         //fprintf(stderr, "blockid.iseq=%p, blockid.idx=%d\n", block->blockid.iseq, block->blockid.idx);
@@ -657,7 +648,7 @@ invalidate_block_version(block_t* block) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L648
         branch->dst_addrs[target_idx] = get_branch_target(
             block->blockid,
             &block->ctx,
-            branch_idx,
+            *branch_idx,
             target_idx
         );
 
diff --git a/ujit_core.h b/ujit_core.h
index 710a9fb8de..64de5ad979 100644
--- a/ujit_core.h
+++ b/ujit_core.h
@@ -95,8 +95,7 @@ typedef struct BranchEntry https://github.com/ruby/ruby/blob/trunk/ujit_core.h#L95
 
 } branch_t;
 
-
-typedef rb_darray(uint32_t) offset_array_t;
+typedef rb_darray(uint32_t) int32_array_t;
 
 /**
 Basic block version
@@ -119,8 +118,7 @@ typedef struct ujit_block_version https://github.com/ruby/ruby/blob/trunk/ujit_core.h#L118
     uint32_t end_pos;
 
     // List of incoming branches indices
-    uint32_t *incoming;
-    uint32_t num_incoming;
+    int32_array_t incoming;
 
     // Next block version for this blockid (singly-linked list)
     struct ujit_block_version *next;
-- 
cgit v1.2.1


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

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