mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Refactor rb_vm_insn_addr2insn calls
It's been a way too much amount of ifdefs.
This commit is contained in:
parent
c32ce2cbf1
commit
070caf54d2
5 changed files with 19 additions and 31 deletions
|
@ -1383,11 +1383,7 @@ update_catch_except_flags(struct rb_iseq_constant_body *body)
|
|||
BREAK/NEXT/REDO catch table entries are used only when `throw` insn is used in the block. */
|
||||
pos = 0;
|
||||
while (pos < body->iseq_size) {
|
||||
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
||||
insn = rb_vm_insn_addr2insn((void *)body->iseq_encoded[pos]);
|
||||
#else
|
||||
insn = (int)body->iseq_encoded[pos];
|
||||
#endif
|
||||
insn = rb_vm_insn_decode(body->iseq_encoded[pos]);
|
||||
if (insn == BIN(throw)) {
|
||||
set_catch_except_p(body);
|
||||
break;
|
||||
|
|
|
@ -23,6 +23,7 @@ VALUE rb_insns_name_array(void);
|
|||
|
||||
/* iseq.c */
|
||||
int rb_vm_insn_addr2insn(const void *);
|
||||
int rb_vm_insn_decode(const VALUE encoded);
|
||||
|
||||
MJIT_SYMBOL_EXPORT_BEGIN
|
||||
/* iseq.c (export) */
|
||||
|
|
12
iseq.c
12
iseq.c
|
@ -3192,6 +3192,18 @@ rb_vm_insn_addr2insn(const void *addr)
|
|||
rb_bug("rb_vm_insn_addr2insn: invalid insn address: %p", addr);
|
||||
}
|
||||
|
||||
// Decode `iseq->body->iseq_encoded[i]` to an insn.
|
||||
int
|
||||
rb_vm_insn_decode(const VALUE encoded)
|
||||
{
|
||||
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
||||
int insn = rb_vm_insn_addr2insn((void *)encoded);
|
||||
#else
|
||||
int insn = (int)encoded;
|
||||
#endif
|
||||
return insn;
|
||||
}
|
||||
|
||||
static inline int
|
||||
encoded_iseq_trace_instrument(VALUE *iseq_encoded_insn, rb_event_flag_t turnon, bool remain_current_trace)
|
||||
{
|
||||
|
|
|
@ -222,18 +222,13 @@ static void
|
|||
compile_insns(FILE *f, const struct rb_iseq_constant_body *body, unsigned int stack_size,
|
||||
unsigned int pos, struct compile_status *status)
|
||||
{
|
||||
int insn;
|
||||
struct compile_branch branch;
|
||||
|
||||
branch.stack_size = stack_size;
|
||||
branch.finish_p = false;
|
||||
|
||||
while (pos < body->iseq_size && !ALREADY_COMPILED_P(status, pos) && !branch.finish_p) {
|
||||
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
||||
insn = rb_vm_insn_addr2insn((void *)body->iseq_encoded[pos]);
|
||||
#else
|
||||
insn = (int)body->iseq_encoded[pos];
|
||||
#endif
|
||||
int insn = rb_vm_insn_decode(body->iseq_encoded[pos]);
|
||||
status->stack_size_for_pos[pos] = (int)branch.stack_size;
|
||||
|
||||
fprintf(f, "\nlabel_%d: /* %s */\n", pos, insn_name(insn));
|
||||
|
@ -406,11 +401,7 @@ inlinable_iseq_p(const struct rb_iseq_constant_body *body)
|
|||
|
||||
unsigned int pos = 0;
|
||||
while (pos < body->iseq_size) {
|
||||
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
||||
int insn = rb_vm_insn_addr2insn((void *)body->iseq_encoded[pos]);
|
||||
#else
|
||||
int insn = (int)body->iseq_encoded[pos];
|
||||
#endif
|
||||
int insn = rb_vm_insn_decode(body->iseq_encoded[pos]);
|
||||
// All insns in the ISeq except `leave` (to be overridden in the inlined code)
|
||||
// should meet following strong assumptions:
|
||||
// * Do not require `cfp->sp` motion
|
||||
|
@ -468,11 +459,7 @@ init_ivar_compile_status(const struct rb_iseq_constant_body *body, struct compil
|
|||
status->ivar_serial = 0;
|
||||
|
||||
while (pos < body->iseq_size) {
|
||||
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
||||
int insn = rb_vm_insn_addr2insn((void *)body->iseq_encoded[pos]);
|
||||
#else
|
||||
int insn = (int)body->iseq_encoded[pos];
|
||||
#endif
|
||||
int insn = rb_vm_insn_decode(body->iseq_encoded[pos]);
|
||||
if (insn == BIN(getinstancevariable) || insn == BIN(setinstancevariable)) {
|
||||
IVC ic = (IVC)body->iseq_encoded[pos+2];
|
||||
IVC ic_copy = &(status->is_entries + ((union iseq_inline_storage_entry *)ic - body->is_entries))->iv_cache;
|
||||
|
@ -527,11 +514,7 @@ precompile_inlinable_iseqs(FILE *f, const rb_iseq_t *iseq, struct compile_status
|
|||
const struct rb_iseq_constant_body *body = iseq->body;
|
||||
unsigned int pos = 0;
|
||||
while (pos < body->iseq_size) {
|
||||
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
||||
int insn = rb_vm_insn_addr2insn((void *)body->iseq_encoded[pos]);
|
||||
#else
|
||||
int insn = (int)body->iseq_encoded[pos];
|
||||
#endif
|
||||
int insn = rb_vm_insn_decode(body->iseq_encoded[pos]);
|
||||
if (insn == BIN(opt_send_without_block)) { // `compile_inlined_cancel_handler` supports only `opt_send_without_block`
|
||||
CALL_DATA cd = (CALL_DATA)body->iseq_encoded[pos + 1];
|
||||
const struct rb_callinfo *ci = cd->ci;
|
||||
|
|
|
@ -734,11 +734,7 @@ set_compiling_iseqs(const rb_iseq_t *iseq)
|
|||
|
||||
unsigned int pos = 0;
|
||||
while (pos < iseq->body->iseq_size) {
|
||||
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
||||
int insn = rb_vm_insn_addr2insn((void *)iseq->body->iseq_encoded[pos]);
|
||||
#else
|
||||
int insn = (int)iseq->body->iseq_encoded[pos];
|
||||
#endif
|
||||
int insn = rb_vm_insn_decode(iseq->body->iseq_encoded[pos]);
|
||||
if (insn == BIN(opt_send_without_block)) {
|
||||
CALL_DATA cd = (CALL_DATA)iseq->body->iseq_encoded[pos + 1];
|
||||
extern const rb_iseq_t *rb_mjit_inlinable_iseq(const struct rb_callinfo *ci, const struct rb_callcache *cc);
|
||||
|
|
Loading…
Add table
Reference in a new issue