Skip to content

Commit

Permalink
tcg: Rearrange ldst label tracking
Browse files Browse the repository at this point in the history
Dispense with TCGBackendData, as it has never been used for more than
holding a single pointer.  Use a define in the cpu/tcg-target.h to
signal requirement for TCGLabelQemuLdst, so that we can drop the no-op
tcg-be-null.h stubs.  Rename tcg-be-ldst.h to tcg-ldst.inc.c.

Reviewed-by: Paolo Bonzini <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
  • Loading branch information
rth7680 committed Sep 7, 2017
1 parent a858339 commit 659ef5c
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 91 deletions.
4 changes: 4 additions & 0 deletions tcg/aarch64/tcg-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,8 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)

void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);

#ifdef CONFIG_SOFTMMU
#define TCG_TARGET_NEED_LDST_LABELS
#endif

#endif /* AARCH64_TCG_TARGET_H */
3 changes: 2 additions & 1 deletion tcg/aarch64/tcg-target.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* See the COPYING file in the top-level directory for details.
*/

#include "tcg-be-ldst.h"
#include "qemu/bitops.h"

/* We're going to re-use TCGType in setting of the SF bit, which controls
Expand Down Expand Up @@ -1070,6 +1069,8 @@ static void tcg_out_cltz(TCGContext *s, TCGType ext, TCGReg d,
}

#ifdef CONFIG_SOFTMMU
#include "tcg-ldst.inc.c"

/* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr,
* TCGMemOpIdx oi, uintptr_t ra)
*/
Expand Down
4 changes: 4 additions & 0 deletions tcg/arm/tcg-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,8 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
/* not defined -- call should be eliminated at compile time */
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);

#ifdef CONFIG_SOFTMMU
#define TCG_TARGET_NEED_LDST_LABELS
#endif

#endif
3 changes: 2 additions & 1 deletion tcg/arm/tcg-target.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

#include "elf.h"
#include "tcg-be-ldst.h"

int arm_arch = __ARM_ARCH;

Expand Down Expand Up @@ -1060,6 +1059,8 @@ static inline void tcg_out_mb(TCGContext *s, TCGArg a0)
}

#ifdef CONFIG_SOFTMMU
#include "tcg-ldst.inc.c"

/* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr,
* int mmu_idx, uintptr_t ra)
*/
Expand Down
4 changes: 4 additions & 0 deletions tcg/i386/tcg-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,8 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,

#define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD)

#ifdef CONFIG_SOFTMMU
#define TCG_TARGET_NEED_LDST_LABELS
#endif

#endif
4 changes: 2 additions & 2 deletions tcg/i386/tcg-target.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* THE SOFTWARE.
*/

#include "tcg-be-ldst.h"

#ifdef CONFIG_DEBUG_TCG
static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
#if TCG_TARGET_REG_BITS == 64
Expand Down Expand Up @@ -1214,6 +1212,8 @@ static void tcg_out_nopn(TCGContext *s, int n)
}

#if defined(CONFIG_SOFTMMU)
#include "tcg-ldst.inc.c"

/* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr,
* int mmu_idx, uintptr_t ra)
*/
Expand Down
4 changes: 4 additions & 0 deletions tcg/mips/tcg-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,8 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)

void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);

#ifdef CONFIG_SOFTMMU
#define TCG_TARGET_NEED_LDST_LABELS
#endif

#endif
4 changes: 2 additions & 2 deletions tcg/mips/tcg-target.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
* THE SOFTWARE.
*/

#include "tcg-be-ldst.h"

#ifdef HOST_WORDS_BIGENDIAN
# define MIPS_BE 1
#else
Expand Down Expand Up @@ -1112,6 +1110,8 @@ static void tcg_out_call(TCGContext *s, tcg_insn_unit *arg)
}

#if defined(CONFIG_SOFTMMU)
#include "tcg-ldst.inc.c"

static void * const qemu_ld_helpers[16] = {
[MO_UB] = helper_ret_ldub_mmu,
[MO_SB] = helper_ret_ldsb_mmu,
Expand Down
4 changes: 4 additions & 0 deletions tcg/ppc/tcg-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,8 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);

#define TCG_TARGET_DEFAULT_MO (0)

#ifdef CONFIG_SOFTMMU
#define TCG_TARGET_NEED_LDST_LABELS
#endif

#endif
4 changes: 2 additions & 2 deletions tcg/ppc/tcg-target.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* THE SOFTWARE.
*/

#include "tcg-be-ldst.h"

#if defined _CALL_DARWIN || defined __APPLE__
#define TCG_TARGET_CALL_DARWIN
#endif
Expand Down Expand Up @@ -1418,6 +1416,8 @@ static const uint32_t qemu_exts_opc[4] = {
};

#if defined (CONFIG_SOFTMMU)
#include "tcg-ldst.inc.c"

/* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr,
* int mmu_idx, uintptr_t ra)
*/
Expand Down
4 changes: 4 additions & 0 deletions tcg/s390/tcg-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
/* no need to flush icache explicitly */
}

#ifdef CONFIG_SOFTMMU
#define TCG_TARGET_NEED_LDST_LABELS
#endif

#endif
4 changes: 2 additions & 2 deletions tcg/s390/tcg-target.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
* THE SOFTWARE.
*/

#include "tcg-be-ldst.h"

/* We only support generating code for 64-bit mode. */
#if TCG_TARGET_REG_BITS != 64
#error "unsupported code generation mode"
Expand Down Expand Up @@ -1458,6 +1456,8 @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCGMemOp opc, TCGReg data,
}

#if defined(CONFIG_SOFTMMU)
#include "tcg-ldst.inc.c"

/* We're expecting to use a 20-bit signed offset on the tlb memory ops.
Using the offset of the second entry in the last tlb table ensures
that we can index all of the elements of the first entry. */
Expand Down
2 changes: 0 additions & 2 deletions tcg/sparc/tcg-target.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* THE SOFTWARE.
*/

#include "tcg-be-null.h"

#ifdef CONFIG_DEBUG_TCG
static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
"%g0",
Expand Down
44 changes: 0 additions & 44 deletions tcg/tcg-be-null.h

This file was deleted.

27 changes: 4 additions & 23 deletions tcg/tcg-be-ldst.h → tcg/tcg-ldst.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* THE SOFTWARE.
*/

#ifdef CONFIG_SOFTMMU

typedef struct TCGLabelQemuLdst {
bool is_ld; /* qemu_ld: true, qemu_st: false */
TCGMemOpIdx oi;
Expand All @@ -35,19 +33,6 @@ typedef struct TCGLabelQemuLdst {
struct TCGLabelQemuLdst *next;
} TCGLabelQemuLdst;

typedef struct TCGBackendData {
TCGLabelQemuLdst *labels;
} TCGBackendData;


/*
* Initialize TB backend data at the beginning of the TB.
*/

static inline void tcg_out_tb_init(TCGContext *s)
{
s->be->labels = NULL;
}

/*
* Generate TB finalization at the end of block
Expand All @@ -56,12 +41,12 @@ static inline void tcg_out_tb_init(TCGContext *s)
static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l);
static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l);

static bool tcg_out_tb_finalize(TCGContext *s)
static bool tcg_out_ldst_finalize(TCGContext *s)
{
TCGLabelQemuLdst *lb;

/* qemu_ld/st slow paths */
for (lb = s->be->labels; lb != NULL; lb = lb->next) {
for (lb = s->ldst_labels; lb != NULL; lb = lb->next) {
if (lb->is_ld) {
tcg_out_qemu_ld_slow_path(s, lb);
} else {
Expand All @@ -85,13 +70,9 @@ static bool tcg_out_tb_finalize(TCGContext *s)

static inline TCGLabelQemuLdst *new_ldst_label(TCGContext *s)
{
TCGBackendData *be = s->be;
TCGLabelQemuLdst *l = tcg_malloc(sizeof(*l));

l->next = be->labels;
be->labels = l;
l->next = s->ldst_labels;
s->ldst_labels = l;
return l;
}
#else
#include "tcg-be-null.h"
#endif /* CONFIG_SOFTMMU */
17 changes: 9 additions & 8 deletions tcg/tcg.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ static bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val,
static void tcg_out_call(TCGContext *s, tcg_insn_unit *target);
static int tcg_target_const_match(tcg_target_long val, TCGType type,
const TCGArgConstraint *arg_ct);
static void tcg_out_tb_init(TCGContext *s);
static bool tcg_out_tb_finalize(TCGContext *s);


#ifdef TCG_TARGET_NEED_LDST_LABELS
static bool tcg_out_ldst_finalize(TCGContext *s);
#endif

static TCGRegSet tcg_target_available_regs[2];
static TCGRegSet tcg_target_call_clobber_regs;
Expand Down Expand Up @@ -470,8 +469,6 @@ void tcg_func_start(TCGContext *s)
s->gen_op_buf[0].prev = 0;
s->gen_next_op_idx = 1;
s->gen_next_parm_idx = 0;

s->be = tcg_malloc(sizeof(TCGBackendData));
}

static inline int temp_idx(TCGContext *s, TCGTemp *ts)
Expand Down Expand Up @@ -2619,7 +2616,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
s->code_buf = tb->tc_ptr;
s->code_ptr = tb->tc_ptr;

tcg_out_tb_init(s);
#ifdef TCG_TARGET_NEED_LDST_LABELS
s->ldst_labels = NULL;
#endif

num_insns = -1;
for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) {
Expand Down Expand Up @@ -2694,9 +2693,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
s->gen_insn_end_off[num_insns] = tcg_current_code_size(s);

/* Generate TB finalization at the end of block */
if (!tcg_out_tb_finalize(s)) {
#ifdef TCG_TARGET_NEED_LDST_LABELS
if (!tcg_out_ldst_finalize(s)) {
return -1;
}
#endif

/* flush instruction cache */
flush_icache_range((uintptr_t)s->code_buf, (uintptr_t)s->code_ptr);
Expand Down
6 changes: 4 additions & 2 deletions tcg/tcg.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,10 @@ struct TCGContext {
CPUState *cpu; /* *_trans */
TCGv_env tcg_env; /* *_exec */

/* The TCGBackendData structure is private to tcg-target.inc.c. */
struct TCGBackendData *be;
/* These structures are private to tcg-target.inc.c. */
#ifdef TCG_TARGET_NEED_LDST_LABELS
struct TCGLabelQemuLdst *ldst_labels;
#endif

TCGTempSet free_temps[TCG_TYPE_COUNT * 2];
TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */
Expand Down
4 changes: 4 additions & 0 deletions tcg/tci/tcg-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,8 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
/* no need to flush icache explicitly */
}

#ifdef CONFIG_SOFTMMU
#define TCG_TARGET_NEED_LDST_LABELS
#endif

#endif /* TCG_TARGET_H */
2 changes: 0 additions & 2 deletions tcg/tci/tcg-target.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* THE SOFTWARE.
*/

#include "tcg-be-null.h"

/* TODO list:
* - See TODO comments in code.
*/
Expand Down

0 comments on commit 659ef5c

Please sign in to comment.