summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <[email protected]>2021-03-05 15:45:44 -0500
committerAlan Wu <[email protected]>2021-10-20 18:19:31 -0400
commit7f4000b1f430c22fd35c50201271d0abd4fff358 ()
tree19df66a7015d924311d8587e58785cf62a1bff8c
parentf8b4082be4e63876b6bf7d1aa66eaaa9bcb5d4ca (diff)
Machinery to implement deferred compilation
-rw-r--r--bootstraptest/test_yjit.rb22
-rw-r--r--ujit_codegen.c47
-rw-r--r--ujit_core.c54
-rw-r--r--ujit_core.h18
-rw-r--r--version.c2
5 files changed, 94 insertions, 49 deletions
@@ -190,6 +190,28 @@ assert_normal_exit %q{
end
}
# Test that getinstancevariable codegen checks for extended table size
assert_equal "nil\n", %q{
class A
@@ -82,17 +82,17 @@ jit_mov_gc_ptr(jitstate_t* jit, codeblock_t* cb, x86opnd_t reg, VALUE ptr)
// Check if we are compiling the instruction at the stub PC
// Meaning we are compiling the instruction that is next to execute
static bool
-jit_at_current_insn(jitstate_t* jit, ctx_t* ctx)
{
- const VALUE* stub_pc = jit->ec->cfp->pc;
- return (stub_pc == jit->pc);
}
// Peek at the topmost value on the Ruby stack
static VALUE
jit_peek_at_stack(jitstate_t* jit, ctx_t* ctx)
{
- RUBY_ASSERT(jit_at_current_insn(jit, ctx));
VALUE* sp = jit->ec->cfp->sp + ctx->sp_offset;
@@ -317,7 +317,13 @@ ujit_gen_block(ctx_t* ctx, block_t* block, rb_execution_context_t* ec)
// Call the code generation function
bool continue_generating = p_desc->gen_fn(&jit, ctx);
- if (!continue_generating) {
break;
}
@@ -572,32 +578,20 @@ gen_getinstancevariable(jitstate_t* jit, ctx_t* ctx)
return UJIT_CANT_COMPILE;
}
-
-
- /*
- num_versions = count_block_versions(this_instruction);
-
- if (num_versions > N)
- return JIT_CANT_COMPILE;
-
-
- if (defer_compilation(this_instruction, ctx))
- return JIT_END_BLOCK;
-
-
- VALUE top_val = jit_peek_at_stack();
-
-
-
-
- class = get_ruby_class(top_val);
- guard_object_class(class, current_instr);
- */
@@ -1452,7 +1446,6 @@ gen_oswb_iseq(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_ca
cmp(cb, klass_opnd, REG1);
jne_ptr(cb, COUNTED_EXIT(side_exit, oswb_se_cc_klass_differ));
-
if (METHOD_ENTRY_VISI(cme) == METHOD_VISI_PROTECTED) {
// Generate ancestry guard for protected callee.
jit_protected_guard(jit, cb, cme, side_exit);
@@ -113,6 +113,15 @@ Returns INT_MAX if incompatible
*/
int ctx_diff(const ctx_t* src, const ctx_t* dst)
{
if (dst->stack_size != src->stack_size)
return INT_MAX;
@@ -353,6 +362,7 @@ uint8_t* branch_stub_hit(uint32_t branch_idx, uint32_t target_idx, rb_execution_
//fprintf(stderr, "\nstub hit, branch idx: %d, target idx: %d\n", branch_idx, target_idx);
//fprintf(stderr, "blockid.iseq=%p, blockid.idx=%d\n", target.iseq, target.idx);
// Update the PC in the current CFP, because it
// may be out of sync in JITted code
@@ -376,7 +386,7 @@ uint8_t* branch_stub_hit(uint32_t branch_idx, uint32_t target_idx, rb_execution_
generic_ctx.sp_offset = target_ctx->sp_offset;
if (get_num_versions(target) >= MAX_VERSIONS - 1)
{
- fprintf(stderr, "version limit hit in branch_stub_hit\n");
target_ctx = &generic_ctx;
}
@@ -542,7 +552,7 @@ void gen_direct_jump(
generic_ctx.sp_offset = ctx->sp_offset;
if (get_num_versions(target0) >= MAX_VERSIONS - 1)
{
- fprintf(stderr, "version limit hit in gen_direct_jump\n");
ctx = &generic_ctx;
}
@@ -588,42 +598,50 @@ void gen_direct_jump(
// Create a stub to force the code up to this point to be executed
void defer_compilation(
block_t* block,
- ctx_t* cur_ctx,
- uint32_t insn_idx
)
{
-
-
-
-
-
-
-
- /*
RUBY_ASSERT(num_branches < MAX_BRANCHES);
uint32_t branch_idx = num_branches++;
// Register this branch entry
branch_t branch_entry = {
start_pos,
end_pos,
- *ctx,
{ target0, BLOCKID_NULL },
- { *ctx, *ctx },
{ dst_addr0, NULL },
gen_jump_branch,
- branch_shape
};
branch_entries[branch_idx] = branch_entry;
- */
-
-
}
// Remove all references to a block then free it.
@@ -20,12 +20,18 @@
// Maximum number of temp value types we keep track of
#define MAX_TEMP_TYPES 8
/**
Code generation context
Contains information we can use to optimize code
*/
typedef struct CtxStruct
{
// Temporary variable types we keep track of
// Values are `ruby_value_type`
// T_NONE==0 is the unknown type
@@ -58,12 +64,12 @@ typedef struct BlockId
static const blockid_t BLOCKID_NULL = { 0, 0 };
/// Branch code shape enumeration
-enum uint8_t
{
SHAPE_NEXT0, // Target 0 is next
SHAPE_NEXT1, // Target 1 is next
SHAPE_DEFAULT // Neither target is next
-};
// Branch code generation function signature
typedef void (*branchgen_fn)(codeblock_t* cb, uint8_t* target0, uint8_t* target1, uint8_t shape);
@@ -92,7 +98,7 @@ typedef struct BranchEntry
branchgen_fn gen_fn;
// Shape of the branch
- uint8_t shape;
} branch_t;
@@ -159,6 +165,12 @@ void gen_direct_jump(
blockid_t target0
);
void invalidate_block_version(block_t* block);
void ujit_init_core(void);
@@ -126,7 +126,7 @@ ruby_show_version(void)
}
if (rb_ujit_enabled_p()) {
- fputs("uJIT is enabled\n", stdout);
}
#ifdef RUBY_LAST_COMMIT_TITLE
fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);