diff options
author | Richard Henderson <richard.henderson@linaro.org> | 2023-03-03 13:47:27 -0800 |
---|---|---|
committer | Richard Henderson <richard.henderson@linaro.org> | 2023-03-05 13:44:07 -0800 |
commit | f85b1fc4a0a572b0b92f5199deac1fb57e6f2aa3 (patch) | |
tree | 5dcbb497577b31738aaf50bc5429632f257c5bb5 /tcg/tcg.c | |
parent | 533206f0520e2d46362e4e6d920c8b9fa7ec1bb4 (diff) |
tcg: Link branches to the labels
This allows us to easily find all branches that use a label.
Since 'refs' is only tested vs zero, remove it and test for
an empty list instead. Drop the use of bitfields, which had
been used to pack refs into a single 32-bit word.
Reviewed-by: Taylor Simpson <tsimpson@quicinc.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'tcg/tcg.c')
-rw-r--r-- | tcg/tcg.c | 30 |
1 files changed, 20 insertions, 10 deletions
@@ -283,6 +283,7 @@ TCGLabel *gen_new_label(void) memset(l, 0, sizeof(TCGLabel)); l->id = s->nb_labels++; + QSIMPLEQ_INIT(&l->branches); QSIMPLEQ_INIT(&l->relocs); QSIMPLEQ_INSERT_TAIL(&s->labels, l, next); @@ -2520,23 +2521,32 @@ static void process_op_defs(TCGContext *s) } } -void tcg_op_remove(TCGContext *s, TCGOp *op) +static void remove_label_use(TCGOp *op, int idx) { - TCGLabel *label; + TCGLabel *label = arg_label(op->args[idx]); + TCGLabelUse *use; + QSIMPLEQ_FOREACH(use, &label->branches, next) { + if (use->op == op) { + QSIMPLEQ_REMOVE(&label->branches, use, TCGLabelUse, next); + return; + } + } + g_assert_not_reached(); +} + +void tcg_op_remove(TCGContext *s, TCGOp *op) +{ switch (op->opc) { case INDEX_op_br: - label = arg_label(op->args[0]); - label->refs--; + remove_label_use(op, 0); break; case INDEX_op_brcond_i32: case INDEX_op_brcond_i64: - label = arg_label(op->args[3]); - label->refs--; + remove_label_use(op, 3); break; case INDEX_op_brcond2_i32: - label = arg_label(op->args[5]); - label->refs--; + remove_label_use(op, 5); break; default: break; @@ -2648,7 +2658,7 @@ reachable_code_pass(TCGContext *s) dead = false; } - if (label->refs == 0) { + if (QSIMPLEQ_EMPTY(&label->branches)) { /* * While there is an occasional backward branch, virtually * all branches generated by the translators are forward. @@ -4892,7 +4902,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, target_ulong pc_start) bool error = false; QSIMPLEQ_FOREACH(l, &s->labels, next) { - if (unlikely(!l->present) && l->refs) { + if (unlikely(!l->present) && !QSIMPLEQ_EMPTY(&l->branches)) { qemu_log_mask(CPU_LOG_TB_OP, "$L%d referenced but not present.\n", l->id); error = true; |