From 4fcaabf38ca946c16b46a165d86225047351a726 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Fri, 9 Feb 2018 13:03:25 -0500 Subject: [PATCH] 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. Backports commit 0c627cdca20155753a536c51385abb73941a59a0 from qemu --- qemu/aarch64.h | 1 + qemu/aarch64eb.h | 1 + qemu/arm.h | 1 + qemu/armeb.h | 1 + qemu/header_gen.py | 1 + qemu/m68k.h | 1 + qemu/mips.h | 1 + qemu/mips64.h | 1 + qemu/mips64el.h | 1 + qemu/mipsel.h | 1 + qemu/powerpc.h | 1 + qemu/sparc.h | 1 + qemu/sparc64.h | 1 + qemu/tcg/optimize.c | 14 +++++++------- qemu/tcg/tcg.c | 27 +++++++++++++++++++++++++++ qemu/tcg/tcg.h | 1 + qemu/x86_64.h | 1 + 17 files changed, 49 insertions(+), 7 deletions(-) diff --git a/qemu/aarch64.h b/qemu/aarch64.h index 5f7ec8c4..50636d52 100644 --- a/qemu/aarch64.h +++ b/qemu/aarch64.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_aarch64 #define tcg_malloc_internal tcg_malloc_internal_aarch64 #define tcg_op_defs_org tcg_op_defs_org_aarch64 +#define tcg_op_remove tcg_op_remove_aarch64 #define tcg_opt_gen_mov tcg_opt_gen_mov_aarch64 #define tcg_opt_gen_movi tcg_opt_gen_movi_aarch64 #define tcg_optimize tcg_optimize_aarch64 diff --git a/qemu/aarch64eb.h b/qemu/aarch64eb.h index 482d9323..5c8a1c6a 100644 --- a/qemu/aarch64eb.h +++ b/qemu/aarch64eb.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_aarch64eb #define tcg_malloc_internal tcg_malloc_internal_aarch64eb #define tcg_op_defs_org tcg_op_defs_org_aarch64eb +#define tcg_op_remove tcg_op_remove_aarch64eb #define tcg_opt_gen_mov tcg_opt_gen_mov_aarch64eb #define tcg_opt_gen_movi tcg_opt_gen_movi_aarch64eb #define tcg_optimize tcg_optimize_aarch64eb diff --git a/qemu/arm.h b/qemu/arm.h index 005d8842..a13434dc 100644 --- a/qemu/arm.h +++ b/qemu/arm.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_arm #define tcg_malloc_internal tcg_malloc_internal_arm #define tcg_op_defs_org tcg_op_defs_org_arm +#define tcg_op_remove tcg_op_remove_arm #define tcg_opt_gen_mov tcg_opt_gen_mov_arm #define tcg_opt_gen_movi tcg_opt_gen_movi_arm #define tcg_optimize tcg_optimize_arm diff --git a/qemu/armeb.h b/qemu/armeb.h index 7516015c..d58adae6 100644 --- a/qemu/armeb.h +++ b/qemu/armeb.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_armeb #define tcg_malloc_internal tcg_malloc_internal_armeb #define tcg_op_defs_org tcg_op_defs_org_armeb +#define tcg_op_remove tcg_op_remove_armeb #define tcg_opt_gen_mov tcg_opt_gen_mov_armeb #define tcg_opt_gen_movi tcg_opt_gen_movi_armeb #define tcg_optimize tcg_optimize_armeb diff --git a/qemu/header_gen.py b/qemu/header_gen.py index 8a011359..45b83149 100644 --- a/qemu/header_gen.py +++ b/qemu/header_gen.py @@ -2876,6 +2876,7 @@ symbols = ( 'tcg_malloc', 'tcg_malloc_internal', 'tcg_op_defs_org', + 'tcg_op_remove', 'tcg_opt_gen_mov', 'tcg_opt_gen_movi', 'tcg_optimize', diff --git a/qemu/m68k.h b/qemu/m68k.h index e51689c8..2fc963db 100644 --- a/qemu/m68k.h +++ b/qemu/m68k.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_m68k #define tcg_malloc_internal tcg_malloc_internal_m68k #define tcg_op_defs_org tcg_op_defs_org_m68k +#define tcg_op_remove tcg_op_remove_m68k #define tcg_opt_gen_mov tcg_opt_gen_mov_m68k #define tcg_opt_gen_movi tcg_opt_gen_movi_m68k #define tcg_optimize tcg_optimize_m68k diff --git a/qemu/mips.h b/qemu/mips.h index 0b9dd49b..dc9a148b 100644 --- a/qemu/mips.h +++ b/qemu/mips.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_mips #define tcg_malloc_internal tcg_malloc_internal_mips #define tcg_op_defs_org tcg_op_defs_org_mips +#define tcg_op_remove tcg_op_remove_mips #define tcg_opt_gen_mov tcg_opt_gen_mov_mips #define tcg_opt_gen_movi tcg_opt_gen_movi_mips #define tcg_optimize tcg_optimize_mips diff --git a/qemu/mips64.h b/qemu/mips64.h index fa233c54..8a69f244 100644 --- a/qemu/mips64.h +++ b/qemu/mips64.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_mips64 #define tcg_malloc_internal tcg_malloc_internal_mips64 #define tcg_op_defs_org tcg_op_defs_org_mips64 +#define tcg_op_remove tcg_op_remove_mips64 #define tcg_opt_gen_mov tcg_opt_gen_mov_mips64 #define tcg_opt_gen_movi tcg_opt_gen_movi_mips64 #define tcg_optimize tcg_optimize_mips64 diff --git a/qemu/mips64el.h b/qemu/mips64el.h index ddb2021f..8e7dfb89 100644 --- a/qemu/mips64el.h +++ b/qemu/mips64el.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_mips64el #define tcg_malloc_internal tcg_malloc_internal_mips64el #define tcg_op_defs_org tcg_op_defs_org_mips64el +#define tcg_op_remove tcg_op_remove_mips64el #define tcg_opt_gen_mov tcg_opt_gen_mov_mips64el #define tcg_opt_gen_movi tcg_opt_gen_movi_mips64el #define tcg_optimize tcg_optimize_mips64el diff --git a/qemu/mipsel.h b/qemu/mipsel.h index 195d319a..7e0db97e 100644 --- a/qemu/mipsel.h +++ b/qemu/mipsel.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_mipsel #define tcg_malloc_internal tcg_malloc_internal_mipsel #define tcg_op_defs_org tcg_op_defs_org_mipsel +#define tcg_op_remove tcg_op_remove_mipsel #define tcg_opt_gen_mov tcg_opt_gen_mov_mipsel #define tcg_opt_gen_movi tcg_opt_gen_movi_mipsel #define tcg_optimize tcg_optimize_mipsel diff --git a/qemu/powerpc.h b/qemu/powerpc.h index a08b8e90..8b8a98ae 100644 --- a/qemu/powerpc.h +++ b/qemu/powerpc.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_powerpc #define tcg_malloc_internal tcg_malloc_internal_powerpc #define tcg_op_defs_org tcg_op_defs_org_powerpc +#define tcg_op_remove tcg_op_remove_powerpc #define tcg_opt_gen_mov tcg_opt_gen_mov_powerpc #define tcg_opt_gen_movi tcg_opt_gen_movi_powerpc #define tcg_optimize tcg_optimize_powerpc diff --git a/qemu/sparc.h b/qemu/sparc.h index fd3c016e..9a7b533b 100644 --- a/qemu/sparc.h +++ b/qemu/sparc.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_sparc #define tcg_malloc_internal tcg_malloc_internal_sparc #define tcg_op_defs_org tcg_op_defs_org_sparc +#define tcg_op_remove tcg_op_remove_sparc #define tcg_opt_gen_mov tcg_opt_gen_mov_sparc #define tcg_opt_gen_movi tcg_opt_gen_movi_sparc #define tcg_optimize tcg_optimize_sparc diff --git a/qemu/sparc64.h b/qemu/sparc64.h index 848153cd..fc26445f 100644 --- a/qemu/sparc64.h +++ b/qemu/sparc64.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_sparc64 #define tcg_malloc_internal tcg_malloc_internal_sparc64 #define tcg_op_defs_org tcg_op_defs_org_sparc64 +#define tcg_op_remove tcg_op_remove_sparc64 #define tcg_opt_gen_mov tcg_opt_gen_mov_sparc64 #define tcg_opt_gen_movi tcg_opt_gen_movi_sparc64 #define tcg_optimize tcg_optimize_sparc64 diff --git a/qemu/tcg/optimize.c b/qemu/tcg/optimize.c index 066dae95..c3d9b2b1 100644 --- a/qemu/tcg/optimize.c +++ b/qemu/tcg/optimize.c @@ -759,7 +759,7 @@ static void tcg_constant_folding(TCGContext *s) break; do_mov3: if (temps_are_copies(s, args[0], args[1])) { - op->opc = INDEX_op_nop; + tcg_op_remove(s, op); } else { tcg_opt_gen_mov(s, op, args, opc, args[0], args[1]); } @@ -917,7 +917,7 @@ static void tcg_constant_folding(TCGContext *s) if (affected == 0) { assert(nb_oargs == 1); if (temps_are_copies(s, args[0], args[1])) { - op->opc = INDEX_op_nop; + tcg_op_remove(s, op); } else if (temps[args[1]].state != TCG_TEMP_CONST) { tcg_opt_gen_mov(s, op, args, opc, args[0], args[1]); } else { @@ -949,7 +949,7 @@ static void tcg_constant_folding(TCGContext *s) CASE_OP_32_64(and): if (temps_are_copies(s, args[1], args[2])) { if (temps_are_copies(s, args[0], args[1])) { - op->opc = INDEX_op_nop; + tcg_op_remove(s, op); } else { tcg_opt_gen_mov(s, op, args, opc, args[0], args[1]); } @@ -980,7 +980,7 @@ static void tcg_constant_folding(TCGContext *s) switch (opc) { CASE_OP_32_64(mov): if (temps_are_copies(s, args[0], args[1])) { - op->opc = INDEX_op_nop; + tcg_op_remove(s, op); break; } if (temps[args[1]].state != TCG_TEMP_CONST) { @@ -1075,7 +1075,7 @@ static void tcg_constant_folding(TCGContext *s) op->opc = INDEX_op_br; args[0] = args[3]; } else { - op->opc = INDEX_op_nop; + tcg_op_remove(s, op); } break; } @@ -1085,7 +1085,7 @@ static void tcg_constant_folding(TCGContext *s) tmp = do_constant_folding_cond(s, opc, args[1], args[2], args[5]); if (tmp != 2) { if (temps_are_copies(s, 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) { tcg_opt_gen_movi(s, op, args, opc, args[0], temps[args[4-tmp]].val); @@ -1178,7 +1178,7 @@ static void tcg_constant_folding(TCGContext *s) args[0] = args[5]; } else { 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) && temps[args[2]].state == TCG_TEMP_CONST diff --git a/qemu/tcg/tcg.c b/qemu/tcg/tcg.c index b141f359..b28af67e 100644 --- a/qemu/tcg/tcg.c +++ b/qemu/tcg/tcg.c @@ -1286,6 +1286,33 @@ void tcg_add_target_add_op_defs(TCGContext *s, const TCGTargetOpDef *tdefs) #endif } +void tcg_op_remove(TCGContext *s, TCGOp *op) +{ + int next = op->next; + int prev = op->prev; + TCGOp opp = {0}; + + 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; + } + + opp.opc = INDEX_op_nop; + opp.next = -1; + opp.prev = -1; + *op = opp; + +#ifdef CONFIG_PROFILER + s->del_op_count++; +#endif +} + #ifdef USE_LIVENESS_ANALYSIS /* liveness analysis: end of function: all temps are dead, and globals diff --git a/qemu/tcg/tcg.h b/qemu/tcg/tcg.h index ee27ac98..cb2126ab 100644 --- a/qemu/tcg/tcg.h +++ b/qemu/tcg/tcg.h @@ -866,6 +866,7 @@ void tcg_add_target_add_op_defs(TCGContext *s, const TCGTargetOpDef *tdefs); void tcg_gen_callN(TCGContext *s, void *func, TCGArg ret, int nargs, TCGArg *args); +void tcg_op_remove(TCGContext *s, TCGOp *op); void tcg_optimize(TCGContext *s); static inline void *tcg_malloc(TCGContext *s, int size) diff --git a/qemu/x86_64.h b/qemu/x86_64.h index 2ceac41f..ad083eb9 100644 --- a/qemu/x86_64.h +++ b/qemu/x86_64.h @@ -2870,6 +2870,7 @@ #define tcg_malloc tcg_malloc_x86_64 #define tcg_malloc_internal tcg_malloc_internal_x86_64 #define tcg_op_defs_org tcg_op_defs_org_x86_64 +#define tcg_op_remove tcg_op_remove_x86_64 #define tcg_opt_gen_mov tcg_opt_gen_mov_x86_64 #define tcg_opt_gen_movi tcg_opt_gen_movi_x86_64 #define tcg_optimize tcg_optimize_x86_64