diff options
author | John Hawthorn <[email protected]> | 2021-06-22 19:22:30 -0700 |
---|---|---|
committer | Alan Wu <[email protected]> | 2021-10-20 18:19:37 -0400 |
commit | dfc5e5e35b927bcfc26af0b59d4952e97bdfb0f7 (patch) | |
tree | 3ff236a27d603e97c5245fdaceae536b241a2edf /yjit_codegen.c | |
parent | c3f264b62cfee09a90fd3f75de9eaa36bc06645d (diff) |
Support guards against symbols and integers
This adds guards
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r-- | yjit_codegen.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c index b5edf86460..0def2f9402 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -2250,9 +2250,29 @@ jit_guard_known_klass(jitstate_t *jit, ctx_t *ctx, VALUE known_klass, insn_opnd_ ctx_set_opnd_type(ctx, insn_opnd, TYPE_FALSE); } } - else if (known_klass == rb_cInteger || - known_klass == rb_cSymbol || - known_klass == rb_cFloat) { + else if (known_klass == rb_cInteger && FIXNUM_P(sample_instance)) { + // We will guard FIXNUM and BIGNUM as though they were separate classes + // BIGNUM can be handled by the general else case below + if (val_type.type != ETYPE_FIXNUM || !val_type.is_imm) { + ADD_COMMENT(cb, "guard object is fixnum"); + test(cb, REG0, imm_opnd(RUBY_FIXNUM_FLAG)); + jit_chain_guard(JCC_JZ, jit, ctx, max_chain_depth, side_exit); + ctx_set_opnd_type(ctx, insn_opnd, TYPE_FIXNUM); + } + } + else if (known_klass == rb_cSymbol && STATIC_SYM_P(sample_instance)) { + // We will guard STATIC vs DYNAMIC as though they were separate classes + // DYNAMIC symbols can be handled by the general else case below + if (val_type.type != ETYPE_SYMBOL || !val_type.is_imm) { + ADD_COMMENT(cb, "guard object is static symbol"); + STATIC_ASSERT(special_shift_is_8, RUBY_SPECIAL_SHIFT == 8); + cmp(cb, REG0_8, imm_opnd(RUBY_SYMBOL_FLAG)); + jit_chain_guard(JCC_JNE, jit, ctx, max_chain_depth, side_exit); + + ctx_set_opnd_type(ctx, insn_opnd, TYPE_STATIC_SYMBOL); + } + } + else if (known_klass == rb_cFloat) { // Can't guard for for these classes because they can have both // immediate (special const) instances and instances on the heap. Can // remove this by adding appropriate dynamic checks. |