diff options
author | Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> | 2022-12-09 17:12:15 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-09 14:12:15 -0800 |
commit | daa893db412c6ae814d0291b4ac6fc62a466d394 (patch) | |
tree | 055ea7d05c1b94be296bcb31bf03e28f14d5d885 /yjit | |
parent | 1c057cfc2fd84369a2ebff048c4a5fdf5fa08fff (diff) |
YJIT: implement `getconstant` YARV instruction (#6884)
* YJIT: implement getconstant YARV instruction
* Constant id is not a pointer
* Stack operands must be read after jit_prepare_routine_call
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
Notes
Notes:
Merged-By: k0kubun <takashikkbn@gmail.com>
Diffstat (limited to 'yjit')
-rw-r--r-- | yjit/src/codegen.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index d890775f2b..6a4026e947 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -6590,6 +6590,41 @@ fn gen_setclassvariable( KeepCompiling } +fn gen_getconstant( + jit: &mut JITState, + ctx: &mut Context, + asm: &mut Assembler, + _ocb: &mut OutlinedCb, +) -> CodegenStatus { + + let id = jit_get_arg(jit, 0).as_usize(); + + // vm_get_ev_const can raise exceptions. + jit_prepare_routine_call(jit, ctx, asm); + + let allow_nil_opnd = ctx.stack_pop(1); + let klass_opnd = ctx.stack_pop(1); + + extern "C" { + fn rb_vm_get_ev_const(ec: EcPtr, klass: VALUE, id: ID, allow_nil: VALUE) -> VALUE; + } + + let val_opnd = asm.ccall( + rb_vm_get_ev_const as *const u8, + vec![ + EC, + klass_opnd, + id.into(), + allow_nil_opnd + ], + ); + + let top = ctx.stack_push(Type::Unknown); + asm.mov(top, val_opnd); + + KeepCompiling +} + fn gen_opt_getconstant_path( jit: &mut JITState, ctx: &mut Context, @@ -6993,6 +7028,7 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> { YARVINSN_opt_size => Some(gen_opt_size), YARVINSN_opt_length => Some(gen_opt_length), YARVINSN_opt_regexpmatch2 => Some(gen_opt_regexpmatch2), + YARVINSN_getconstant => Some(gen_getconstant), YARVINSN_opt_getconstant_path => Some(gen_opt_getconstant_path), YARVINSN_invokebuiltin => Some(gen_invokebuiltin), YARVINSN_opt_invokebuiltin_delegate => Some(gen_opt_invokebuiltin_delegate), |