Skip to content

Commit

Permalink
GCtrace: Make it possible to map between IR and mcode insns
Browse files Browse the repository at this point in the history
Add a 'szirmcode' array to GCtrace that keeps track of how many bytes
of machine code were assembled for each IR instruction.

This allows us to construct an association between IR code and mcode,
either to see the mcode that was assembled for a given IR instruction,
or to map a machine code instruction back to the relevant IR instruction.
  • Loading branch information
lukego committed Sep 3, 2017
1 parent d400946 commit ad14f45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lj_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,10 @@ void lj_asm_trace(jit_State *J, GCtrace *T)
as->loopinv = 0;
as->parent = J->parent ? traceref(J, J->parent) : NULL;

/* Initialize mcode size of IR instructions array. */
T->szirmcode = lj_mem_new(J->L, T->nins * sizeof(*T->szirmcode));
memset(T->szirmcode, 0, T->nins * sizeof(*T->szirmcode));

/* Reserve MCode memory. */
as->mctop = origtop = lj_mcode_reserve(J, &as->mcbot);
as->mcp = as->mctop;
Expand Down Expand Up @@ -2043,6 +2047,7 @@ void lj_asm_trace(jit_State *J, GCtrace *T)
/* Assemble a trace in linear backwards order. */
for (as->curins--; as->curins > as->stopins; as->curins--) {
IRIns *ir = IR(as->curins);
MCode *end = as->mcp;
lua_assert(!(LJ_32 && irt_isint64(ir->t))); /* Handled by SPLIT. */
if (!ra_used(ir) && !ir_sideeff(ir) && (as->flags & JIT_F_OPT_DCE))
continue; /* Dead-code elimination can be soooo easy. */
Expand All @@ -2051,6 +2056,7 @@ void lj_asm_trace(jit_State *J, GCtrace *T)
RA_DBG_REF();
checkmclim(as);
asm_ir(as, ir);
T->szirmcode[as->curins] = (uint16_t)(end - as->mcp);
}

if (as->realign && J->curfinal->nins >= T->nins)
Expand Down
1 change: 1 addition & 0 deletions src/lj_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ typedef struct GCtrace {
MSize szmcode; /* Size of machine code. */
MCode *mcode; /* Start of machine code. */
MSize mcloop; /* Offset of loop start in machine code. */
uint16_t *szirmcode; /* Bytes of mcode for each IR instruction (array.) */
uint16_t nchild; /* Number of child traces (root trace only). */
uint16_t spadjust; /* Stack pointer adjustment (offset in bytes). */
TraceNo1 traceno; /* Trace number. */
Expand Down

0 comments on commit ad14f45

Please sign in to comment.