diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index 2d98868d8fe03ece6075c6bf2da40b437356361c..d3e51b15afb45b2e7da6a6388b5c01f7c7cdcccc 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -255,6 +255,7 @@ static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2, static inline void gen_set_label(TCGLabel *l) { + l->present = 1; tcg_gen_op1(INDEX_op_set_label, label_arg(l)); } diff --git a/tcg/tcg.c b/tcg/tcg.c index 20a5d8f315d391e1ce3e244d87412d75bbd76ed4..9b2bf7f43976e60023197dafcab6dff8241a627d 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -305,6 +305,9 @@ TCGLabel *gen_new_label(void) *l = (TCGLabel){ .id = s->nb_labels++ }; +#ifdef CONFIG_DEBUG_TCG + QSIMPLEQ_INSERT_TAIL(&s->labels, l, next); +#endif return l; } @@ -1092,6 +1095,9 @@ void tcg_func_start(TCGContext *s) QTAILQ_INIT(&s->ops); QTAILQ_INIT(&s->free_ops); +#ifdef CONFIG_DEBUG_TCG + QSIMPLEQ_INIT(&s->labels); +#endif } static inline TCGTemp *tcg_temp_alloc(TCGContext *s) @@ -3841,6 +3847,23 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) } #endif +#ifdef CONFIG_DEBUG_TCG + /* Ensure all labels referenced have been emitted. */ + { + TCGLabel *l; + bool error = false; + + QSIMPLEQ_FOREACH(l, &s->labels, next) { + if (unlikely(!l->present) && l->refs) { + qemu_log_mask(CPU_LOG_TB_OP, + "$L%d referenced but not present.\n", l->id); + error = true; + } + } + assert(!error); + } +#endif + #ifdef CONFIG_PROFILER atomic_set(&prof->opt_time, prof->opt_time - profile_getclock()); #endif diff --git a/tcg/tcg.h b/tcg/tcg.h index 045c24a35783ffce530c0ebe57df71de22fed86e..32b7cf34898eeac832a6015ddfbf7063347af995 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -244,16 +244,21 @@ typedef struct TCGRelocation { intptr_t addend; } TCGRelocation; -typedef struct TCGLabel { +typedef struct TCGLabel TCGLabel; +struct TCGLabel { + unsigned present : 1; unsigned has_value : 1; - unsigned id : 15; + unsigned id : 14; unsigned refs : 16; union { uintptr_t value; tcg_insn_unit *value_ptr; TCGRelocation *first_reloc; } u; -} TCGLabel; +#ifdef CONFIG_DEBUG_TCG + QSIMPLEQ_ENTRY(TCGLabel) next; +#endif +}; typedef struct TCGPool { struct TCGPool *next; @@ -685,6 +690,7 @@ struct TCGContext { #endif #ifdef CONFIG_DEBUG_TCG + QSIMPLEQ_HEAD(, TCGLabel) labels; int temps_in_use; int goto_tb_issue_mask; #endif