Skip to content

Commit 85a31fc

Browse files
authored
Merge pull request #245 from RinHizakura/master
Remove tailcall member in rv_insn_t
2 parents f471aec + 1d8694b commit 85a31fc

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/decode.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,14 @@ typedef struct rv_insn {
283283
* optimization enables the self-recursive function to reuse the same
284284
* function stack frame.
285285
*
286-
* The @tailcall member indicates whether an intermediate representation
287-
* (IR) is the final instruction in a basic block. The @impl member
288-
* facilitates the direct invocation of the next instruction emulation
289-
* without the need to compute the jump address. By utilizing these two
290-
* members, all instruction emulations can be rewritten into a
286+
* The @next member indicates the next intermediate representation
287+
* (IR) or is NULL if it is the final instruction in a basic block. The
288+
* @impl member facilitates the direct invocation of the next instruction
289+
* emulation without the need to compute the jump address. By utilizing
290+
* these two members, all instruction emulations can be rewritten into a
291291
* self-recursive version, enabling the compiler to leverage TCO.
292292
*/
293-
bool tailcall;
293+
struct rv_insn *next;
294294
bool (*impl)(riscv_t *, const struct rv_insn *);
295295

296296
/* Two pointers, 'branch_taken' and 'branch_untaken', are employed to
@@ -302,7 +302,6 @@ typedef struct rv_insn {
302302
*/
303303
struct rv_insn *branch_taken, *branch_untaken;
304304

305-
struct rv_insn *next;
306305
} rv_insn_t;
307306

308307
/* decode the RISC-V instruction */

src/emulate.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ enum {
356356
};
357357

358358
#if RV32_HAS(GDBSTUB)
359-
#define RVOP_NO_NEXT(ir) (ir->tailcall | rv->debug_mode)
359+
#define RVOP_NO_NEXT(ir) (!ir->next | rv->debug_mode)
360360
#else
361-
#define RVOP_NO_NEXT(ir) (ir->tailcall)
361+
#define RVOP_NO_NEXT(ir) (!ir->next)
362362
#endif
363363

364364
/* record whether the branch is taken or not during emulation */
@@ -601,7 +601,7 @@ static void block_translate(riscv_t *rv, block_map_t *map, block_t *block)
601601

602602
assert(prev_ir);
603603
block->ir_tail = prev_ir;
604-
block->ir_tail->tailcall = true;
604+
block->ir_tail->next = NULL;
605605
}
606606

607607
#define COMBINE_MEM_OPS(RW) \
@@ -611,7 +611,7 @@ static void block_translate(riscv_t *rv, block_map_t *map, block_t *block)
611611
if (next_ir->opcode != IIF(RW)(rv_insn_lw, rv_insn_sw)) \
612612
break; \
613613
count++; \
614-
if (next_ir->tailcall) \
614+
if (!next_ir->next) \
615615
break; \
616616
next_ir = next_ir->next; \
617617
} \
@@ -683,7 +683,6 @@ FORCE_INLINE void remove_next_nth_ir(riscv_t *rv,
683683
}
684684
if (!ir->next) {
685685
block->ir_tail = ir;
686-
ir->tailcall = true;
687686
}
688687
block->n_insn -= n;
689688
}
@@ -794,7 +793,6 @@ static void match_pattern(riscv_t *rv, block_t *block)
794793
else
795794
ir->rs1 = next_ir->rs2;
796795
ir->impl = dispatch_table[ir->opcode];
797-
ir->tailcall = next_ir->tailcall;
798796
remove_next_nth_ir(rv, ir, block, 1);
799797
}
800798
break;
@@ -804,7 +802,7 @@ static void match_pattern(riscv_t *rv, block_t *block)
804802
if (!IF_insn(next_ir, lui))
805803
break;
806804
count++;
807-
if (next_ir->tailcall)
805+
if (!next_ir->next)
808806
break;
809807
next_ir = next_ir->next;
810808
}
@@ -841,7 +839,7 @@ static void match_pattern(riscv_t *rv, block_t *block)
841839
!IF_insn(next_ir, srai))
842840
break;
843841
count++;
844-
if (next_ir->tailcall)
842+
if (!next_ir->next)
845843
break;
846844
next_ir = next_ir->next;
847845
}

0 commit comments

Comments
 (0)