summaryrefslogtreecommitdiff
path: root/yjit_core.c
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>2021-04-08 16:40:08 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:33 -0400
commitf6e3f75c2b7503eb89f517c57ac4ea97dc2752b4 (patch)
tree2f93077875cb816937a24568a2ff18e5db3696e5 /yjit_core.c
parent40b329096660c55f9f30069a1b72aec026ee19b1 (diff)
Introduce concept of YJIT instruction operands
Diffstat (limited to 'yjit_core.c')
-rw-r--r--yjit_core.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/yjit_core.c b/yjit_core.c
index 3be45c12e5..f0b7c31984 100644
--- a/yjit_core.c
+++ b/yjit_core.c
@@ -132,18 +132,20 @@ ctx_stack_opnd(ctx_t* ctx, int32_t idx)
}
/**
-Get the type of a value on the temp stack
-Returns T_NONE if unknown
+Get the type of an instruction operand
*/
val_type_t
-ctx_get_temp_type(const ctx_t* ctx, size_t idx)
+ctx_get_opnd_type(const ctx_t* ctx, insn_opnd_t opnd)
{
- RUBY_ASSERT(idx < ctx->stack_size);
+ RUBY_ASSERT(opnd.idx < ctx->stack_size);
+
+ if (opnd.is_self)
+ return ctx->self_type;
if (ctx->stack_size > MAX_TEMP_TYPES)
return TYPE_UNKNOWN;
- temp_mapping_t mapping = ctx->temp_mapping[ctx->stack_size - 1 - idx];
+ temp_mapping_t mapping = ctx->temp_mapping[ctx->stack_size - 1 - opnd.idx];
switch (mapping.kind)
{
@@ -151,7 +153,7 @@ ctx_get_temp_type(const ctx_t* ctx, size_t idx)
return ctx->self_type;
case TEMP_STACK:
- return ctx->temp_types[ctx->stack_size - 1 - idx];
+ return ctx->temp_types[ctx->stack_size - 1 - opnd.idx];
case TEMP_LOCAL:
RUBY_ASSERT(mapping.idx < MAX_LOCAL_TYPES);
@@ -162,16 +164,21 @@ ctx_get_temp_type(const ctx_t* ctx, size_t idx)
}
/**
-Set the type of a value in the temporary stack
+Set the type of an instruction operand
*/
-void ctx_set_temp_type(ctx_t* ctx, size_t idx, val_type_t type)
+void ctx_set_opnd_type(ctx_t* ctx, insn_opnd_t opnd, val_type_t type)
{
- RUBY_ASSERT(idx < ctx->stack_size);
+ RUBY_ASSERT(opnd.idx < ctx->stack_size);
+
+ if (opnd.is_self) {
+ ctx->self_type = type;
+ return;
+ }
if (ctx->stack_size > MAX_TEMP_TYPES)
return;
- temp_mapping_t mapping = ctx->temp_mapping[ctx->stack_size - 1 - idx];
+ temp_mapping_t mapping = ctx->temp_mapping[ctx->stack_size - 1 - opnd.idx];
switch (mapping.kind)
{
@@ -180,7 +187,7 @@ void ctx_set_temp_type(ctx_t* ctx, size_t idx, val_type_t type)
break;
case TEMP_STACK:
- ctx->temp_types[ctx->stack_size - 1 - idx] = type;
+ ctx->temp_types[ctx->stack_size - 1 - opnd.idx] = type;
break;
case TEMP_LOCAL:
@@ -275,8 +282,8 @@ int ctx_diff(const ctx_t* src, const ctx_t* dst)
// For each value on the temp stack
for (size_t i = 0; i < src->stack_size; ++i)
{
- val_type_t t_src = ctx_get_temp_type(src, i);
- val_type_t t_dst = ctx_get_temp_type(dst, i);
+ val_type_t t_src = ctx_get_opnd_type(src, OPND_STACK(i));
+ val_type_t t_dst = ctx_get_opnd_type(dst, OPND_STACK(i));
int temp_diff = type_diff(t_src, t_dst);
if (temp_diff == INT_MAX)