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) } 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 } 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) // 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) } } -// 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) // 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) } // 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( 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( // 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 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) 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) 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 } 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 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;