ruby-changes:69038
From: John <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:37 +0900 (JST)
Subject: [ruby-changes:69038] 764740c661 (master): Merge pull request #50 from jhawthorn/detect_type
https://git.ruby-lang.org/ruby.git/commit/?id=764740c661 From 764740c6615292dc994707b964c135871149fb2b Mon Sep 17 00:00:00 2001 From: John Hawthorn <john@h...> Date: Tue, 25 May 2021 13:12:48 -0700 Subject: Merge pull request #50 from jhawthorn/detect_type Detect types from putobject and getinlinecache --- yjit_codegen.c | 34 +++++++++++++++++++++++++++++++--- 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) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L114 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) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L638 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) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L2716 // 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); https://github.com/ruby/ruby/blob/trunk/yjit_core.h#L67 #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 { -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/