1 #ifndef RUBY_INSNHELPER_H
2 #define RUBY_INSNHELPER_H
15 RUBY_EXTERN rb_serial_t ruby_vm_constant_cache_invalidations;
16 RUBY_EXTERN rb_serial_t ruby_vm_constant_cache_misses;
19 #if USE_YJIT || USE_RJIT
23 #define JIT_COLLECT_USAGE_INSN(insn) rb_vm_insns_count++
25 #define JIT_COLLECT_USAGE_INSN(insn)
28 #if VM_COLLECT_USAGE_DETAILS
29 #define COLLECT_USAGE_INSN(insn) vm_collect_usage_insn(insn)
30 #define COLLECT_USAGE_OPERAND(insn, n, op) vm_collect_usage_operand((insn), (n), ((VALUE)(op)))
31 #define COLLECT_USAGE_REGISTER(reg, s) vm_collect_usage_register((reg), (s))
33 #define COLLECT_USAGE_INSN(insn) JIT_COLLECT_USAGE_INSN(insn)
34 #define COLLECT_USAGE_OPERAND(insn, n, op)
35 #define COLLECT_USAGE_REGISTER(reg, s)
42 #define PUSH(x) (SET_SV(x), INC_SP(1))
43 #define TOPN(n) (*(GET_SP()-(n)-1))
44 #define POPN(n) (DEC_SP(n))
45 #define POP() (DEC_SP(1))
46 #define STACK_ADDR_FROM_TOP(n) (GET_SP()-(n))
52 #define VM_REG_CFP (reg_cfp)
53 #define VM_REG_PC (VM_REG_CFP->pc)
54 #define VM_REG_SP (VM_REG_CFP->sp)
55 #define VM_REG_EP (VM_REG_CFP->ep)
57 #define RESTORE_REGS() do { \
58 VM_REG_CFP = ec->cfp; \
61 typedef enum call_type {
74 #if VM_COLLECT_USAGE_DETAILS
75 enum vm_regan_regtype {
83 enum vm_regan_acttype {
88 #define COLLECT_USAGE_REGISTER_HELPER(a, b, v) \
89 (COLLECT_USAGE_REGISTER((VM_REGAN_##a), (VM_REGAN_ACT_##b)), (v))
91 #define COLLECT_USAGE_REGISTER_HELPER(a, b, v) (v)
95 #define GET_PC() (COLLECT_USAGE_REGISTER_HELPER(PC, GET, VM_REG_PC))
96 #define SET_PC(x) (VM_REG_PC = (COLLECT_USAGE_REGISTER_HELPER(PC, SET, (x))))
97 #define GET_CURRENT_INSN() (*GET_PC())
98 #define GET_OPERAND(n) (GET_PC()[(n)])
99 #define ADD_PC(n) (SET_PC(VM_REG_PC + (n)))
100 #define JUMP(dst) (SET_PC(VM_REG_PC + (dst)))
103 #define GET_CFP() (COLLECT_USAGE_REGISTER_HELPER(CFP, GET, VM_REG_CFP))
104 #define GET_EP() (COLLECT_USAGE_REGISTER_HELPER(EP, GET, VM_REG_EP))
105 #define SET_EP(x) (VM_REG_EP = (COLLECT_USAGE_REGISTER_HELPER(EP, SET, (x))))
106 #define GET_LEP() (VM_EP_LEP(GET_EP()))
109 #define GET_SP() (COLLECT_USAGE_REGISTER_HELPER(SP, GET, VM_REG_SP))
110 #define SET_SP(x) (VM_REG_SP = (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
111 #define INC_SP(x) (VM_REG_SP += (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
112 #define DEC_SP(x) (VM_REG_SP -= (COLLECT_USAGE_REGISTER_HELPER(SP, SET, (x))))
113 #define SET_SV(x) (*GET_SP() = rb_ractor_confirm_belonging(x))
117 #define GET_ISEQ() (GET_CFP()->iseq)
123 #define GET_PREV_EP(ep) ((VALUE *)((ep)[VM_ENV_DATA_INDEX_SPECVAL] & ~0x03))
129 #define GET_SELF() (COLLECT_USAGE_REGISTER_HELPER(SELF, GET, GET_CFP()->self))
140 CC_SET_FASTPATH(
const struct rb_callcache *cc, vm_call_handler func,
bool enabled)
142 if (LIKELY(enabled)) {
143 vm_cc_call_set(cc, func);
147 #define GET_BLOCK_HANDLER() (GET_LEP()[VM_ENV_DATA_INDEX_SPECVAL])
158 #if VM_CHECK_MODE > 0
159 #define SETUP_CANARY(cond) \
163 SET_SV(vm_stack_canary); \
168 #define CHECK_CANARY(cond, insn) \
170 if (*canary == vm_stack_canary) { \
174 rb_vm_canary_is_found_dead(insn, *canary); \
178 #define SETUP_CANARY(cond) if (cond) {} else {}
179 #define CHECK_CANARY(cond, insn) if (cond) {(void)(insn);}
186 #define CALL_SIMPLE_METHOD() do { \
187 rb_snum_t insn_width = attr_width_opt_send_without_block(0); \
188 ADD_PC(-insn_width); \
189 DISPATCH_ORIGINAL_INSN(opt_send_without_block); \
192 #define GET_GLOBAL_CVAR_STATE() (ruby_vm_global_cvar_state)
193 #define INC_GLOBAL_CVAR_STATE() (++ruby_vm_global_cvar_state)
199 *((
VALUE *)&obj->throw_obj) = val;
201 obj->throw_state = st;
209 VM_ASSERT(THROW_DATA_P(obj));
210 return obj->throw_obj;
216 VM_ASSERT(THROW_DATA_P(obj));
217 return obj->catch_frame;
223 VM_ASSERT(THROW_DATA_P(obj));
224 return obj->throw_state;
230 VM_ASSERT(THROW_DATA_P(obj));
231 return obj->flags & THROW_DATA_CONSUMED;
237 VM_ASSERT(THROW_DATA_P(obj));
238 obj->catch_frame = cfp;
244 VM_ASSERT(THROW_DATA_P(obj));
245 obj->throw_state = st;
251 if (THROW_DATA_P(obj) &&
252 THROW_DATA_STATE(obj) == TAG_BREAK) {
253 obj->flags |= THROW_DATA_CONSUMED;
257 #define IS_ARGS_SPLAT(ci) (vm_ci_flag(ci) & VM_CALL_ARGS_SPLAT)
258 #define IS_ARGS_KEYWORD(ci) (vm_ci_flag(ci) & VM_CALL_KWARG)
259 #define IS_ARGS_KW_SPLAT(ci) (vm_ci_flag(ci) & VM_CALL_KW_SPLAT)
260 #define IS_ARGS_KW_OR_KW_SPLAT(ci) (vm_ci_flag(ci) & (VM_CALL_KWARG | VM_CALL_KW_SPLAT))
261 #define IS_ARGS_KW_SPLAT_MUT(ci) (vm_ci_flag(ci) & VM_CALL_KW_SPLAT_MUT)
266 return !(vm_ci_flag(ci) & VM_CALL_FORWARDING) && ((vm_ci_flag(ci) & VM_CALL_FCALL) ||
267 METHOD_ENTRY_VISI(vm_cc_cme(cc)) != METHOD_VISI_PROTECTED);
274 return !IS_ARGS_SPLAT(ci) && !IS_ARGS_KEYWORD(ci) && vm_call_cacheable(ci, cc);
#define RUBY_EXTERN
Declaration of externally visible global variables.
uintptr_t VALUE
Type that represents a Ruby object.