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>
This commit is contained in:
Richard Henderson 2023-03-03 13:47:27 -08:00
parent 533206f052
commit f85b1fc4a0
4 changed files with 53 additions and 25 deletions

View file

@ -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)
}
}
static void remove_label_use(TCGOp *op, int idx)
{
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)
{
TCGLabel *label;
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;