1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Rename to ctx_upgrade_opnd_type

This commit is contained in:
John Hawthorn 2021-07-14 11:52:00 -07:00 committed by Alan Wu
parent 53079ca585
commit 4ea69e5c0b
3 changed files with 25 additions and 17 deletions

View file

@ -1237,7 +1237,7 @@ gen_set_ivar(jitstate_t *jit, ctx_t *ctx, const int max_chain_depth, VALUE compt
ADD_COMMENT(cb, "guard value is immediate"); ADD_COMMENT(cb, "guard value is immediate");
test(cb, REG1, imm_opnd(RUBY_IMMEDIATE_MASK)); test(cb, REG1, imm_opnd(RUBY_IMMEDIATE_MASK));
jz_ptr(cb, COUNTED_EXIT(side_exit, setivar_val_heapobject)); jz_ptr(cb, COUNTED_EXIT(side_exit, setivar_val_heapobject));
ctx_set_opnd_type(ctx, OPND_STACK(0), TYPE_IMM); ctx_upgrade_opnd_type(ctx, OPND_STACK(0), TYPE_IMM);
} }
// Pop the value to write // Pop the value to write
@ -1704,8 +1704,8 @@ guard_two_fixnums(ctx_t* ctx, uint8_t* side_exit)
} }
// Set stack types in context // Set stack types in context
ctx_set_opnd_type(ctx, OPND_STACK(0), TYPE_FIXNUM); ctx_upgrade_opnd_type(ctx, OPND_STACK(0), TYPE_FIXNUM);
ctx_set_opnd_type(ctx, OPND_STACK(1), TYPE_FIXNUM); ctx_upgrade_opnd_type(ctx, OPND_STACK(1), TYPE_FIXNUM);
} }
// Conditional move operation used by comparison operators // Conditional move operation used by comparison operators
@ -2441,7 +2441,7 @@ jit_guard_known_klass(jitstate_t *jit, ctx_t *ctx, VALUE known_klass, insn_opnd_
cmp(cb, REG0, imm_opnd(Qnil)); cmp(cb, REG0, imm_opnd(Qnil));
jit_chain_guard(JCC_JNE, jit, ctx, max_chain_depth, side_exit); jit_chain_guard(JCC_JNE, jit, ctx, max_chain_depth, side_exit);
ctx_set_opnd_type(ctx, insn_opnd, TYPE_NIL); ctx_upgrade_opnd_type(ctx, insn_opnd, TYPE_NIL);
} }
} }
else if (known_klass == rb_cTrueClass) { else if (known_klass == rb_cTrueClass) {
@ -2453,7 +2453,7 @@ jit_guard_known_klass(jitstate_t *jit, ctx_t *ctx, VALUE known_klass, insn_opnd_
cmp(cb, REG0, imm_opnd(Qtrue)); cmp(cb, REG0, imm_opnd(Qtrue));
jit_chain_guard(JCC_JNE, jit, ctx, max_chain_depth, side_exit); jit_chain_guard(JCC_JNE, jit, ctx, max_chain_depth, side_exit);
ctx_set_opnd_type(ctx, insn_opnd, TYPE_TRUE); ctx_upgrade_opnd_type(ctx, insn_opnd, TYPE_TRUE);
} }
} }
else if (known_klass == rb_cFalseClass) { else if (known_klass == rb_cFalseClass) {
@ -2466,7 +2466,7 @@ jit_guard_known_klass(jitstate_t *jit, ctx_t *ctx, VALUE known_klass, insn_opnd_
test(cb, REG0, REG0); test(cb, REG0, REG0);
jit_chain_guard(JCC_JNZ, jit, ctx, max_chain_depth, side_exit); jit_chain_guard(JCC_JNZ, jit, ctx, max_chain_depth, side_exit);
ctx_set_opnd_type(ctx, insn_opnd, TYPE_FALSE); ctx_upgrade_opnd_type(ctx, insn_opnd, TYPE_FALSE);
} }
} }
else if (known_klass == rb_cInteger && FIXNUM_P(sample_instance)) { else if (known_klass == rb_cInteger && FIXNUM_P(sample_instance)) {
@ -2479,7 +2479,7 @@ jit_guard_known_klass(jitstate_t *jit, ctx_t *ctx, VALUE known_klass, insn_opnd_
ADD_COMMENT(cb, "guard object is fixnum"); ADD_COMMENT(cb, "guard object is fixnum");
test(cb, REG0, imm_opnd(RUBY_FIXNUM_FLAG)); test(cb, REG0, imm_opnd(RUBY_FIXNUM_FLAG));
jit_chain_guard(JCC_JZ, jit, ctx, max_chain_depth, side_exit); jit_chain_guard(JCC_JZ, jit, ctx, max_chain_depth, side_exit);
ctx_set_opnd_type(ctx, insn_opnd, TYPE_FIXNUM); ctx_upgrade_opnd_type(ctx, insn_opnd, TYPE_FIXNUM);
} }
} }
else if (known_klass == rb_cSymbol && STATIC_SYM_P(sample_instance)) { else if (known_klass == rb_cSymbol && STATIC_SYM_P(sample_instance)) {
@ -2493,7 +2493,7 @@ jit_guard_known_klass(jitstate_t *jit, ctx_t *ctx, VALUE known_klass, insn_opnd_
STATIC_ASSERT(special_shift_is_8, RUBY_SPECIAL_SHIFT == 8); STATIC_ASSERT(special_shift_is_8, RUBY_SPECIAL_SHIFT == 8);
cmp(cb, REG0_8, imm_opnd(RUBY_SYMBOL_FLAG)); cmp(cb, REG0_8, imm_opnd(RUBY_SYMBOL_FLAG));
jit_chain_guard(JCC_JNE, jit, ctx, max_chain_depth, side_exit); jit_chain_guard(JCC_JNE, jit, ctx, max_chain_depth, side_exit);
ctx_set_opnd_type(ctx, insn_opnd, TYPE_STATIC_SYMBOL); ctx_upgrade_opnd_type(ctx, insn_opnd, TYPE_STATIC_SYMBOL);
} }
} }
else if (known_klass == rb_cFloat && FLONUM_P(sample_instance)) { else if (known_klass == rb_cFloat && FLONUM_P(sample_instance)) {
@ -2507,7 +2507,7 @@ jit_guard_known_klass(jitstate_t *jit, ctx_t *ctx, VALUE known_klass, insn_opnd_
and(cb, REG1, imm_opnd(RUBY_FLONUM_MASK)); and(cb, REG1, imm_opnd(RUBY_FLONUM_MASK));
cmp(cb, REG1, imm_opnd(RUBY_FLONUM_FLAG)); cmp(cb, REG1, imm_opnd(RUBY_FLONUM_FLAG));
jit_chain_guard(JCC_JNE, jit, ctx, max_chain_depth, side_exit); jit_chain_guard(JCC_JNE, jit, ctx, max_chain_depth, side_exit);
ctx_set_opnd_type(ctx, insn_opnd, TYPE_FLONUM); ctx_upgrade_opnd_type(ctx, insn_opnd, TYPE_FLONUM);
} }
} }
else if (FL_TEST(known_klass, FL_SINGLETON) && sample_instance == rb_attr_get(known_klass, id__attached__)) { else if (FL_TEST(known_klass, FL_SINGLETON) && sample_instance == rb_attr_get(known_klass, id__attached__)) {
@ -2540,7 +2540,7 @@ jit_guard_known_klass(jitstate_t *jit, ctx_t *ctx, VALUE known_klass, insn_opnd_
cmp(cb, REG0, imm_opnd(Qnil)); cmp(cb, REG0, imm_opnd(Qnil));
jit_chain_guard(JCC_JBE, jit, ctx, max_chain_depth, side_exit); jit_chain_guard(JCC_JBE, jit, ctx, max_chain_depth, side_exit);
ctx_set_opnd_type(ctx, insn_opnd, TYPE_HEAP); ctx_upgrade_opnd_type(ctx, insn_opnd, TYPE_HEAP);
} }
x86opnd_t klass_opnd = mem_opnd(64, REG0, offsetof(struct RBasic, klass)); x86opnd_t klass_opnd = mem_opnd(64, REG0, offsetof(struct RBasic, klass));
@ -3085,7 +3085,7 @@ gen_send_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
ctx_set_local_type(&callee_ctx, arg_idx, arg_type); ctx_set_local_type(&callee_ctx, arg_idx, arg_type);
} }
val_type_t recv_type = ctx_get_opnd_type(ctx, OPND_STACK(argc)); val_type_t recv_type = ctx_get_opnd_type(ctx, OPND_STACK(argc));
ctx_set_opnd_type(&callee_ctx, OPND_SELF, recv_type); ctx_upgrade_opnd_type(&callee_ctx, OPND_SELF, recv_type);
// The callee might change locals through Kernel#binding and other means. // The callee might change locals through Kernel#binding and other means.
ctx_clear_local_types(ctx); ctx_clear_local_types(ctx);

View file

@ -153,13 +153,20 @@ ctx_get_opnd_type(const ctx_t* ctx, insn_opnd_t opnd)
rb_bug("unreachable"); rb_bug("unreachable");
} }
int type_diff(val_type_t src, val_type_t dst);
#define UPGRADE_TYPE(dest, src) do { \
RUBY_ASSERT(type_diff((src), (dest)) != INT_MAX); \
(dest) = (src); \
} while (false)
/** /**
Set the type of an instruction operand Set the type of an instruction operand
*/ */
void ctx_set_opnd_type(ctx_t* ctx, insn_opnd_t opnd, val_type_t type) void ctx_upgrade_opnd_type(ctx_t* ctx, insn_opnd_t opnd, val_type_t type)
{ {
if (opnd.is_self) { if (opnd.is_self) {
ctx->self_type = type; UPGRADE_TYPE(ctx->self_type, type);
return; return;
} }
@ -172,16 +179,17 @@ void ctx_set_opnd_type(ctx_t* ctx, insn_opnd_t opnd, val_type_t type)
switch (mapping.kind) switch (mapping.kind)
{ {
case TEMP_SELF: case TEMP_SELF:
ctx->self_type = type; UPGRADE_TYPE(ctx->self_type, type);
break; break;
case TEMP_STACK: case TEMP_STACK:
ctx->temp_types[ctx->stack_size - 1 - opnd.idx] = type; int stack_index = ctx->stack_size - 1 - opnd.idx;
UPGRADE_TYPE(ctx->temp_types[stack_index], type);
break; break;
case TEMP_LOCAL: case TEMP_LOCAL:
RUBY_ASSERT(mapping.idx < MAX_LOCAL_TYPES); RUBY_ASSERT(mapping.idx < MAX_LOCAL_TYPES);
ctx->local_types[mapping.idx] = type; UPGRADE_TYPE(ctx->local_types[mapping.idx], type);
break; break;
} }
} }

View file

@ -258,7 +258,7 @@ x86opnd_t ctx_stack_push_local(ctx_t* ctx, size_t local_idx);
x86opnd_t ctx_stack_pop(ctx_t* ctx, size_t n); x86opnd_t ctx_stack_pop(ctx_t* ctx, size_t n);
x86opnd_t ctx_stack_opnd(ctx_t* ctx, int32_t idx); x86opnd_t ctx_stack_opnd(ctx_t* ctx, int32_t idx);
val_type_t ctx_get_opnd_type(const ctx_t* ctx, insn_opnd_t opnd); val_type_t ctx_get_opnd_type(const ctx_t* ctx, insn_opnd_t opnd);
void ctx_set_opnd_type(ctx_t* ctx, insn_opnd_t opnd, val_type_t type); void ctx_upgrade_opnd_type(ctx_t* ctx, insn_opnd_t opnd, val_type_t type);
void ctx_set_local_type(ctx_t* ctx, size_t idx, val_type_t type); void ctx_set_local_type(ctx_t* ctx, size_t idx, val_type_t type);
void ctx_clear_local_types(ctx_t* ctx); void ctx_clear_local_types(ctx_t* ctx);
int ctx_diff(const ctx_t* src, const ctx_t* dst); int ctx_diff(const ctx_t* src, const ctx_t* dst);