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>
tcg_gen_op1(INDEX_op_set_label, label_arg(l));
}
-static inline void tcg_gen_br(TCGLabel *l)
-{
- l->refs++;
- tcg_gen_op1(INDEX_op_br, label_arg(l));
-}
-
+void tcg_gen_br(TCGLabel *l);
void tcg_gen_mb(TCGBar);
/* Helper calls. */
int type;
};
+typedef struct TCGOp TCGOp;
+typedef struct TCGLabelUse TCGLabelUse;
+struct TCGLabelUse {
+ QSIMPLEQ_ENTRY(TCGLabelUse) next;
+ TCGOp *op;
+};
+
typedef struct TCGLabel TCGLabel;
struct TCGLabel {
- unsigned present : 1;
- unsigned has_value : 1;
- unsigned id : 14;
- unsigned refs : 16;
+ bool present;
+ bool has_value;
+ uint16_t id;
union {
uintptr_t value;
const tcg_insn_unit *value_ptr;
} u;
+ QSIMPLEQ_HEAD(, TCGLabelUse) branches;
QSIMPLEQ_HEAD(, TCGRelocation) relocs;
QSIMPLEQ_ENTRY(TCGLabel) next;
};
#define SYNC_ARG (1 << 0)
typedef uint32_t TCGLifeData;
-typedef struct TCGOp {
+struct TCGOp {
TCGOpcode opc : 8;
unsigned nargs : 8;
/* Arguments for the opcode. */
TCGArg args[];
-} TCGOp;
+};
#define TCGOP_CALLI(X) (X)->param1
#define TCGOP_CALLO(X) (X)->param2
op->args[5] = a6;
}
+/* Generic ops. */
+
+static void add_last_as_label_use(TCGLabel *l)
+{
+ TCGLabelUse *u = tcg_malloc(sizeof(TCGLabelUse));
+
+ u->op = tcg_last_op();
+ QSIMPLEQ_INSERT_TAIL(&l->branches, u, next);
+}
+
+void tcg_gen_br(TCGLabel *l)
+{
+ tcg_gen_op1(INDEX_op_br, label_arg(l));
+ add_last_as_label_use(l);
+}
+
void tcg_gen_mb(TCGBar mb_type)
{
if (tcg_ctx->gen_tb->cflags & CF_PARALLEL) {
if (cond == TCG_COND_ALWAYS) {
tcg_gen_br(l);
} else if (cond != TCG_COND_NEVER) {
- l->refs++;
tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_arg(l));
+ add_last_as_label_use(l);
}
}
if (cond == TCG_COND_ALWAYS) {
tcg_gen_br(l);
} else if (cond != TCG_COND_NEVER) {
- l->refs++;
if (TCG_TARGET_REG_BITS == 32) {
tcg_gen_op6ii_i32(INDEX_op_brcond2_i32, TCGV_LOW(arg1),
TCGV_HIGH(arg1), TCGV_LOW(arg2),
tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond,
label_arg(l));
}
+ add_last_as_label_use(l);
}
}
} else if (cond == TCG_COND_ALWAYS) {
tcg_gen_br(l);
} else if (cond != TCG_COND_NEVER) {
- l->refs++;
tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
TCGV_LOW(arg1), TCGV_HIGH(arg1),
tcg_constant_i32(arg2),
tcg_constant_i32(arg2 >> 32),
cond, label_arg(l));
+ add_last_as_label_use(l);
}
}
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);
}
}
-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;
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.
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;