% # -*- mode:c; style:ruby; coding: utf-8; indent-tabs-mode: nil -*- % # Copyright (c) 2018 Takashi Kokubun. All rights reserved. % # % # This file is a part of the programming language Ruby. Permission is hereby % # granted, to either redistribute and/or modify this file, provided that the % # conditions mentioned in the file COPYING are met. Consult the file for % # details. % % # Optimized case of get_instancevariable instruction. #if OPT_IC_FOR_IVAR { % # compiler: Prepare operands which may be used by `insn.call_attribute` % insn.opes.each_with_index do |ope, i| MAYBE_UNUSED(<%= ope.fetch(:decl) %>) = (<%= ope.fetch(:type) %>)operands[<%= i %>]; % end % % # compiler: Consider cfp->self as T_OBJECT if ic->ic_serial is set if (ic->ic_serial >= RUBY_VM_CLASS_SERIAL_MIN_VALID_VALUE) { % # JIT: optimize away motion of sp and pc. This path does not call rb_warning() and so it's always leaf and not `handles_sp`. % # <%= render 'mjit_compile_pc_and_sp', locals: { insn: insn } -%> % % # JIT: prepare vm_getivar's arguments and variables fprintf(f, "{\n"); fprintf(f, " VALUE obj = GET_SELF();\n"); fprintf(f, " const rb_serial_t ic_serial = (rb_serial_t)%"PRI_SERIALT_PREFIX"u;\n", ic->ic_serial); fprintf(f, " const st_index_t index = %"PRIuSIZE";\n", ic->ic_value.index); % if insn.name == 'setinstancevariable' fprintf(f, " VALUE val = stack[%d];\n", b->stack_size - 1); % end % % # JIT: cache hit path of vm_getivar, or cancel JIT. fprintf(f, " if (LIKELY(RB_TYPE_P(obj, T_OBJECT) && ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass) && index < ROBJECT_NUMIV(obj))) {\n"); % if insn.name == 'setinstancevariable' fprintf(f, " VALUE *ptr = ROBJECT_IVPTR(obj);\n"); fprintf(f, " RB_OBJ_WRITE(obj, &ptr[index], val);\n"); % else fprintf(f, " stack[%d] = ROBJECT_IVPTR(obj)[index];\n", b->stack_size); % end fprintf(f, " }\n"); fprintf(f, " else {\n"); fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", pos); fprintf(f, " reg_cfp->sp = (VALUE *)reg_cfp->bp + %d;\n", b->stack_size + 1); fprintf(f, " goto cancel;\n"); fprintf(f, " }\n"); % # compiler: Move JIT compiler's internal stack pointer b->stack_size += <%= insn.call_attribute('sp_inc') %>; fprintf(f, "}\n"); break; } } #endif /* OPT_IC_FOR_IVAR */