mirror of https://github.com/xemu-project/xemu.git
tcg: Remove opcodes instead of noping them out
With the linked list scheme we need not leave nops in the stream that we need to process later. Reviewed-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de> Signed-off-by: Richard Henderson <rth@twiddle.net>
This commit is contained in:
parent
c45cb8bb89
commit
0c627cdca2
|
@ -758,7 +758,7 @@ static void tcg_constant_folding(TCGContext *s)
|
||||||
break;
|
break;
|
||||||
do_mov3:
|
do_mov3:
|
||||||
if (temps_are_copies(args[0], args[1])) {
|
if (temps_are_copies(args[0], args[1])) {
|
||||||
op->opc = INDEX_op_nop;
|
tcg_op_remove(s, op);
|
||||||
} else {
|
} else {
|
||||||
tcg_opt_gen_mov(s, op, args, opc, args[0], args[1]);
|
tcg_opt_gen_mov(s, op, args, opc, args[0], args[1]);
|
||||||
}
|
}
|
||||||
|
@ -916,7 +916,7 @@ static void tcg_constant_folding(TCGContext *s)
|
||||||
if (affected == 0) {
|
if (affected == 0) {
|
||||||
assert(nb_oargs == 1);
|
assert(nb_oargs == 1);
|
||||||
if (temps_are_copies(args[0], args[1])) {
|
if (temps_are_copies(args[0], args[1])) {
|
||||||
op->opc = INDEX_op_nop;
|
tcg_op_remove(s, op);
|
||||||
} else if (temps[args[1]].state != TCG_TEMP_CONST) {
|
} else if (temps[args[1]].state != TCG_TEMP_CONST) {
|
||||||
tcg_opt_gen_mov(s, op, args, opc, args[0], args[1]);
|
tcg_opt_gen_mov(s, op, args, opc, args[0], args[1]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -948,7 +948,7 @@ static void tcg_constant_folding(TCGContext *s)
|
||||||
CASE_OP_32_64(and):
|
CASE_OP_32_64(and):
|
||||||
if (temps_are_copies(args[1], args[2])) {
|
if (temps_are_copies(args[1], args[2])) {
|
||||||
if (temps_are_copies(args[0], args[1])) {
|
if (temps_are_copies(args[0], args[1])) {
|
||||||
op->opc = INDEX_op_nop;
|
tcg_op_remove(s, op);
|
||||||
} else {
|
} else {
|
||||||
tcg_opt_gen_mov(s, op, args, opc, args[0], args[1]);
|
tcg_opt_gen_mov(s, op, args, opc, args[0], args[1]);
|
||||||
}
|
}
|
||||||
|
@ -979,7 +979,7 @@ static void tcg_constant_folding(TCGContext *s)
|
||||||
switch (opc) {
|
switch (opc) {
|
||||||
CASE_OP_32_64(mov):
|
CASE_OP_32_64(mov):
|
||||||
if (temps_are_copies(args[0], args[1])) {
|
if (temps_are_copies(args[0], args[1])) {
|
||||||
op->opc = INDEX_op_nop;
|
tcg_op_remove(s, op);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (temps[args[1]].state != TCG_TEMP_CONST) {
|
if (temps[args[1]].state != TCG_TEMP_CONST) {
|
||||||
|
@ -1074,7 +1074,7 @@ static void tcg_constant_folding(TCGContext *s)
|
||||||
op->opc = INDEX_op_br;
|
op->opc = INDEX_op_br;
|
||||||
args[0] = args[3];
|
args[0] = args[3];
|
||||||
} else {
|
} else {
|
||||||
op->opc = INDEX_op_nop;
|
tcg_op_remove(s, op);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1084,7 +1084,7 @@ static void tcg_constant_folding(TCGContext *s)
|
||||||
tmp = do_constant_folding_cond(opc, args[1], args[2], args[5]);
|
tmp = do_constant_folding_cond(opc, args[1], args[2], args[5]);
|
||||||
if (tmp != 2) {
|
if (tmp != 2) {
|
||||||
if (temps_are_copies(args[0], args[4-tmp])) {
|
if (temps_are_copies(args[0], args[4-tmp])) {
|
||||||
op->opc = INDEX_op_nop;
|
tcg_op_remove(s, op);
|
||||||
} else if (temps[args[4-tmp]].state == TCG_TEMP_CONST) {
|
} else if (temps[args[4-tmp]].state == TCG_TEMP_CONST) {
|
||||||
tcg_opt_gen_movi(s, op, args, opc,
|
tcg_opt_gen_movi(s, op, args, opc,
|
||||||
args[0], temps[args[4-tmp]].val);
|
args[0], temps[args[4-tmp]].val);
|
||||||
|
@ -1177,7 +1177,7 @@ static void tcg_constant_folding(TCGContext *s)
|
||||||
args[0] = args[5];
|
args[0] = args[5];
|
||||||
} else {
|
} else {
|
||||||
do_brcond_false:
|
do_brcond_false:
|
||||||
op->opc = INDEX_op_nop;
|
tcg_op_remove(s, op);
|
||||||
}
|
}
|
||||||
} else if ((args[4] == TCG_COND_LT || args[4] == TCG_COND_GE)
|
} else if ((args[4] == TCG_COND_LT || args[4] == TCG_COND_GE)
|
||||||
&& temps[args[2]].state == TCG_TEMP_CONST
|
&& temps[args[2]].state == TCG_TEMP_CONST
|
||||||
|
|
28
tcg/tcg.c
28
tcg/tcg.c
|
@ -1244,6 +1244,29 @@ void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tcg_op_remove(TCGContext *s, TCGOp *op)
|
||||||
|
{
|
||||||
|
int next = op->next;
|
||||||
|
int prev = op->prev;
|
||||||
|
|
||||||
|
if (next >= 0) {
|
||||||
|
s->gen_op_buf[next].prev = prev;
|
||||||
|
} else {
|
||||||
|
s->gen_last_op_idx = prev;
|
||||||
|
}
|
||||||
|
if (prev >= 0) {
|
||||||
|
s->gen_op_buf[prev].next = next;
|
||||||
|
} else {
|
||||||
|
s->gen_first_op_idx = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
*op = (TCGOp){ .opc = INDEX_op_nop, .next = -1, .prev = -1 };
|
||||||
|
|
||||||
|
#ifdef CONFIG_PROFILER
|
||||||
|
s->del_op_count++;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_LIVENESS_ANALYSIS
|
#ifdef USE_LIVENESS_ANALYSIS
|
||||||
/* liveness analysis: end of function: all temps are dead, and globals
|
/* liveness analysis: end of function: all temps are dead, and globals
|
||||||
should be in memory. */
|
should be in memory. */
|
||||||
|
@ -1466,10 +1489,7 @@ static void tcg_liveness_analysis(TCGContext *s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
do_remove:
|
do_remove:
|
||||||
op->opc = INDEX_op_nop;
|
tcg_op_remove(s, op);
|
||||||
#ifdef CONFIG_PROFILER
|
|
||||||
s->del_op_count++;
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
do_not_remove:
|
do_not_remove:
|
||||||
/* output args are dead */
|
/* output args are dead */
|
||||||
|
|
|
@ -743,6 +743,7 @@ void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs);
|
||||||
void tcg_gen_callN(TCGContext *s, void *func,
|
void tcg_gen_callN(TCGContext *s, void *func,
|
||||||
TCGArg ret, int nargs, TCGArg *args);
|
TCGArg ret, int nargs, TCGArg *args);
|
||||||
|
|
||||||
|
void tcg_op_remove(TCGContext *s, TCGOp *op);
|
||||||
void tcg_optimize(TCGContext *s);
|
void tcg_optimize(TCGContext *s);
|
||||||
|
|
||||||
/* only used for debugging purposes */
|
/* only used for debugging purposes */
|
||||||
|
|
Loading…
Reference in New Issue