Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ujit_codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,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);

Expand Down Expand Up @@ -1260,7 +1260,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;
Expand Down Expand Up @@ -1463,13 +1463,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;
Expand Down
33 changes: 12 additions & 21 deletions ujit_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,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)
{
Expand Down Expand Up @@ -322,7 +311,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);
}

Expand Down Expand Up @@ -399,7 +389,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);
Expand Down Expand Up @@ -435,8 +425,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);
}

Expand Down Expand Up @@ -557,7 +548,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;

Expand Down Expand Up @@ -596,8 +587,7 @@ void
ujit_free_block(block_t *block)
{
ujit_unlink_method_lookup_dependency(block);

free(block->incoming);
rb_darray_free(block->incoming);
free(block);
}

Expand Down Expand Up @@ -634,10 +624,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);
Expand All @@ -646,7 +637,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
);

Expand Down
5 changes: 3 additions & 2 deletions ujit_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ typedef struct BranchEntry

} branch_t;

typedef rb_darray(uint32_t) int32_array_t;

/**
Basic block version
Represents a portion of an iseq compiled with a given context
Expand All @@ -119,8 +121,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;
Expand Down