diff options
author | John Hawthorn <john@hawthorn.email> | 2021-05-25 13:12:48 -0700 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:35 -0400 |
commit | 764740c6615292dc994707b964c135871149fb2b (patch) | |
tree | 1188ab34a32cd3023b44e7cf1b3fc2471947329d | |
parent | 844067f7ee40a406314c6b570df82fc43d519131 (diff) |
Merge pull request #50 from jhawthorn/detect_type
Detect types from putobject and getinlinecache
-rw-r--r-- | yjit_codegen.c | 34 | ||||
-rw-r--r-- | yjit_core.h | 1 |
2 files changed, 32 insertions, 3 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c index f98283f338..791095efb7 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -114,6 +114,34 @@ jit_peek_at_self(jitstate_t *jit, ctx_t *ctx) return jit->ec->cfp->self; } +// When we know a VALUE to be static, this returns an appropriate val_type_t +static val_type_t +jit_type_of_value(VALUE val) +{ + if (SPECIAL_CONST_P(val)) { + if (FIXNUM_P(val)) { + return TYPE_FIXNUM; + } else if (NIL_P(val)) { + return TYPE_NIL; + } else { + // generic immediate + return TYPE_IMM; + } + } else { + switch (BUILTIN_TYPE(val)) { + case T_ARRAY: + return TYPE_ARRAY; + case T_HASH: + return TYPE_HASH; + case T_STRING: + return TYPE_STRING; + default: + // generic heap object + return TYPE_HEAP; + } + } +} + // Save the incremented PC on the CFP // This is necessary when calleees can raise or allocate void @@ -610,8 +638,7 @@ gen_putobject(jitstate_t* jit, ctx_t* ctx) VALUE put_val = jit_get_arg(jit, 0); jit_mov_gc_ptr(jit, cb, REG0, put_val); - // TODO: check for more specific types like array, string, symbol, etc. - val_type_t val_type = SPECIAL_CONST_P(put_val)? TYPE_IMM:TYPE_HEAP; + val_type_t val_type = jit_type_of_value(put_val); // Write argument at SP x86opnd_t stack_top = ctx_stack_push(ctx, val_type); @@ -2689,7 +2716,8 @@ gen_opt_getinlinecache(jitstate_t *jit, ctx_t *ctx) // FIXME: This leaks when st_insert raises NoMemoryError assume_stable_global_constant_state(jit->block); - x86opnd_t stack_top = ctx_stack_push(ctx, TYPE_UNKNOWN); + val_type_t type = jit_type_of_value(ice->value); + x86opnd_t stack_top = ctx_stack_push(ctx, type); jit_mov_gc_ptr(jit, cb, REG0, ice->value); mov(cb, stack_top, REG0); diff --git a/yjit_core.h b/yjit_core.h index 948ea3bd72..d9cce3fe56 100644 --- a/yjit_core.h +++ b/yjit_core.h @@ -67,6 +67,7 @@ STATIC_ASSERT(val_type_size, sizeof(val_type_t) == 1); #define TYPE_FIXNUM ( (val_type_t){ .is_imm = 1, .type = ETYPE_FIXNUM } ) #define TYPE_ARRAY ( (val_type_t){ .is_heap = 1, .type = ETYPE_ARRAY } ) #define TYPE_HASH ( (val_type_t){ .is_heap = 1, .type = ETYPE_HASH } ) +#define TYPE_STRING ( (val_type_t){ .is_heap = 1, .type = ETYPE_STRING } ) enum yjit_temp_loc { |