2018-12-27 01:12:09 -05:00
|
|
|
% # -*- C -*-
|
2018-10-14 05:24:43 -04:00
|
|
|
% # 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.
|
2018-10-14 07:25:36 -04:00
|
|
|
#if OPT_IC_FOR_IVAR
|
2018-10-14 05:24:43 -04:00
|
|
|
{
|
|
|
|
% # 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
|
2018-10-21 09:21:28 -04:00
|
|
|
% # compiler: Use copied IC to avoid race condition
|
|
|
|
IC ic_copy = &(status->is_entries + ((union iseq_inline_storage_entry *)ic - body->is_entries))->cache;
|
2018-10-14 05:24:43 -04:00
|
|
|
%
|
2018-10-21 09:21:28 -04:00
|
|
|
% # compiler: Consider cfp->self as T_OBJECT if ic_copy->ic_serial is set
|
2019-04-14 00:52:02 -04:00
|
|
|
if (!status->compile_info->disable_ivar_cache && ic_copy->ic_serial) {
|
2018-10-14 05:24:43 -04:00
|
|
|
% # 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");
|
2018-10-21 09:21:28 -04:00
|
|
|
fprintf(f, " const rb_serial_t ic_serial = (rb_serial_t)%"PRI_SERIALT_PREFIX"u;\n", ic_copy->ic_serial);
|
|
|
|
fprintf(f, " const st_index_t index = %"PRIuSIZE";\n", ic_copy->ic_value.index);
|
2018-10-24 11:41:14 -04:00
|
|
|
% # JIT: cache hit path of vm_getivar, or cancel JIT.
|
2018-10-14 09:25:21 -04:00
|
|
|
% if insn.name == 'setinstancevariable'
|
|
|
|
fprintf(f, " VALUE val = stack[%d];\n", b->stack_size - 1);
|
2018-10-14 05:24:43 -04:00
|
|
|
fprintf(f, " if (LIKELY(RB_TYPE_P(obj, T_OBJECT) && ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass) && index < ROBJECT_NUMIV(obj))) {\n");
|
2018-10-14 09:25:21 -04:00
|
|
|
fprintf(f, " VALUE *ptr = ROBJECT_IVPTR(obj);\n");
|
|
|
|
fprintf(f, " RB_OBJ_WRITE(obj, &ptr[index], val);\n");
|
2018-10-24 11:41:14 -04:00
|
|
|
fprintf(f, " }\n");
|
2018-10-14 09:25:21 -04:00
|
|
|
% else
|
2018-10-24 11:41:14 -04:00
|
|
|
fprintf(f, " VALUE val;\n");
|
|
|
|
fprintf(f, " if (LIKELY(RB_TYPE_P(obj, T_OBJECT) && ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass) && index < ROBJECT_NUMIV(obj) && (val = ROBJECT_IVPTR(obj)[index]) != Qundef)) {\n");
|
|
|
|
fprintf(f, " stack[%d] = val;\n", b->stack_size);
|
2018-10-14 05:24:43 -04:00
|
|
|
fprintf(f, " }\n");
|
2018-10-24 11:41:14 -04:00
|
|
|
% end
|
2018-10-14 05:24:43 -04:00
|
|
|
fprintf(f, " else {\n");
|
|
|
|
fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", pos);
|
2019-03-25 10:26:11 -04:00
|
|
|
fprintf(f, " reg_cfp->sp = vm_base_ptr(reg_cfp) + %d;\n", b->stack_size);
|
2019-03-29 09:54:29 -04:00
|
|
|
fprintf(f, " RB_DEBUG_COUNTER_INC(mjit_cancel_ivar);\n");
|
2019-04-14 08:25:23 -04:00
|
|
|
fprintf(f, " goto ivar_cancel;\n");
|
2018-10-14 05:24:43 -04:00
|
|
|
fprintf(f, " }\n");
|
|
|
|
|
|
|
|
% # compiler: Move JIT compiler's internal stack pointer
|
|
|
|
b->stack_size += <%= insn.call_attribute('sp_inc') %>;
|
|
|
|
fprintf(f, "}\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-14 01:26:46 -04:00
|
|
|
#endif // OPT_IC_FOR_IVAR
|