summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>2021-03-03 14:58:42 -0500
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:30 -0400
commitb3b3a8c62020caca849e4b3a1325eb53811e6f7a (patch)
tree5036dd2e8190b5d268c473b0c107027fdcbf2f3e
parent316f757c44513b43a831f44a1a9b64337b69b181 (diff)
At jit_at_current_insn, jit_peek_at_stack functions
-rw-r--r--ujit_codegen.c41
-rw-r--r--ujit_core.c41
-rw-r--r--ujit_core.h1
3 files changed, 83 insertions, 0 deletions
diff --git a/ujit_codegen.c b/ujit_codegen.c
index 25328c6ee8..8249c1b1d5 100644
--- a/ujit_codegen.c
+++ b/ujit_codegen.c
@@ -79,6 +79,26 @@ 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;
+
+ return *(sp - 1);
+}
+
// Save uJIT registers prior to a C call
static void
ujit_save_regs(codeblock_t* cb)
@@ -552,6 +572,27 @@ gen_getinstancevariable(jitstate_t* jit, ctx_t* ctx)
return UJIT_CANT_COMPILE;
}
+
+
+
+
+
+
+ /*
+ if (defer_compilation(this_instruction, ctx))
+ return JIT_END_BLOCK;
+
+ VALUE top_val = jit_peek_at_stack();
+ */
+
+
+
+
+
+
+
+
+
// If the class uses the default allocator, instances should all be T_OBJECT
// NOTE: This assumes nobody changes the allocator of the class after allocation.
// Eventually, we can encode whether an object is T_OBJECT or not
diff --git a/ujit_core.c b/ujit_core.c
index 5690734d30..b07d8450ad 100644
--- a/ujit_core.c
+++ b/ujit_core.c
@@ -604,6 +604,47 @@ void gen_direct_jump(
branch_entries[branch_idx] = branch_entry;
}
+// 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.
void
ujit_free_block(block_t *block)
diff --git a/ujit_core.h b/ujit_core.h
index 0b8e3dd465..bfd44b145e 100644
--- a/ujit_core.h
+++ b/ujit_core.h
@@ -35,6 +35,7 @@ typedef struct CtxStruct
uint16_t stack_size;
// Offset of the JIT SP relative to the interpreter SP
+ // This represents how far the JIT's SP is from the "real" SP
int16_t sp_offset;
// Whether we know self is a heap object