tcg: Reduce copies for plugin_gen_mem_callbacks
We only need to make copies for loads, when the destination overlaps the address. For now, only eliminate the copy for stores and 128-bit loads. Rename plugin_prep_mem_callbacks to plugin_maybe_preserve_addr, returning NULL if no copy is made. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
b6d9164518
commit
eb9d02f24b
@ -114,7 +114,8 @@ static void tcg_gen_req_mo(TCGBar type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline TCGv plugin_prep_mem_callbacks(TCGv vaddr)
|
/* Only required for loads, where value might overlap addr. */
|
||||||
|
static TCGv plugin_maybe_preserve_addr(TCGv vaddr)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_PLUGIN
|
#ifdef CONFIG_PLUGIN
|
||||||
if (tcg_ctx->plugin_insn != NULL) {
|
if (tcg_ctx->plugin_insn != NULL) {
|
||||||
@ -124,17 +125,20 @@ static inline TCGv plugin_prep_mem_callbacks(TCGv vaddr)
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return vaddr;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void plugin_gen_mem_callbacks(TCGv vaddr, MemOpIdx oi,
|
static void
|
||||||
enum qemu_plugin_mem_rw rw)
|
plugin_gen_mem_callbacks(TCGv copy_addr, TCGv orig_addr, MemOpIdx oi,
|
||||||
|
enum qemu_plugin_mem_rw rw)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_PLUGIN
|
#ifdef CONFIG_PLUGIN
|
||||||
if (tcg_ctx->plugin_insn != NULL) {
|
if (tcg_ctx->plugin_insn != NULL) {
|
||||||
qemu_plugin_meminfo_t info = make_plugin_meminfo(oi, rw);
|
qemu_plugin_meminfo_t info = make_plugin_meminfo(oi, rw);
|
||||||
plugin_gen_empty_mem_callback(vaddr, info);
|
plugin_gen_empty_mem_callback(copy_addr ? : orig_addr, info);
|
||||||
tcg_temp_free(vaddr);
|
if (copy_addr) {
|
||||||
|
tcg_temp_free(copy_addr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -143,6 +147,7 @@ void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, MemOp memop)
|
|||||||
{
|
{
|
||||||
MemOp orig_memop;
|
MemOp orig_memop;
|
||||||
MemOpIdx oi;
|
MemOpIdx oi;
|
||||||
|
TCGv copy_addr;
|
||||||
|
|
||||||
tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD);
|
tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD);
|
||||||
memop = tcg_canonicalize_memop(memop, 0, 0);
|
memop = tcg_canonicalize_memop(memop, 0, 0);
|
||||||
@ -157,9 +162,9 @@ void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, MemOp memop)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addr = plugin_prep_mem_callbacks(addr);
|
copy_addr = plugin_maybe_preserve_addr(addr);
|
||||||
gen_ldst_i32(INDEX_op_qemu_ld_i32, val, addr, memop, idx);
|
gen_ldst_i32(INDEX_op_qemu_ld_i32, val, addr, memop, idx);
|
||||||
plugin_gen_mem_callbacks(addr, oi, QEMU_PLUGIN_MEM_R);
|
plugin_gen_mem_callbacks(copy_addr, addr, oi, QEMU_PLUGIN_MEM_R);
|
||||||
|
|
||||||
if ((orig_memop ^ memop) & MO_BSWAP) {
|
if ((orig_memop ^ memop) & MO_BSWAP) {
|
||||||
switch (orig_memop & MO_SIZE) {
|
switch (orig_memop & MO_SIZE) {
|
||||||
@ -202,13 +207,12 @@ void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, MemOp memop)
|
|||||||
memop &= ~MO_BSWAP;
|
memop &= ~MO_BSWAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr = plugin_prep_mem_callbacks(addr);
|
|
||||||
if (TCG_TARGET_HAS_qemu_st8_i32 && (memop & MO_SIZE) == MO_8) {
|
if (TCG_TARGET_HAS_qemu_st8_i32 && (memop & MO_SIZE) == MO_8) {
|
||||||
gen_ldst_i32(INDEX_op_qemu_st8_i32, val, addr, memop, idx);
|
gen_ldst_i32(INDEX_op_qemu_st8_i32, val, addr, memop, idx);
|
||||||
} else {
|
} else {
|
||||||
gen_ldst_i32(INDEX_op_qemu_st_i32, val, addr, memop, idx);
|
gen_ldst_i32(INDEX_op_qemu_st_i32, val, addr, memop, idx);
|
||||||
}
|
}
|
||||||
plugin_gen_mem_callbacks(addr, oi, QEMU_PLUGIN_MEM_W);
|
plugin_gen_mem_callbacks(NULL, addr, oi, QEMU_PLUGIN_MEM_W);
|
||||||
|
|
||||||
if (swap) {
|
if (swap) {
|
||||||
tcg_temp_free_i32(swap);
|
tcg_temp_free_i32(swap);
|
||||||
@ -219,6 +223,7 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, MemOp memop)
|
|||||||
{
|
{
|
||||||
MemOp orig_memop;
|
MemOp orig_memop;
|
||||||
MemOpIdx oi;
|
MemOpIdx oi;
|
||||||
|
TCGv copy_addr;
|
||||||
|
|
||||||
if (TCG_TARGET_REG_BITS == 32 && (memop & MO_SIZE) < MO_64) {
|
if (TCG_TARGET_REG_BITS == 32 && (memop & MO_SIZE) < MO_64) {
|
||||||
tcg_gen_qemu_ld_i32(TCGV_LOW(val), addr, idx, memop);
|
tcg_gen_qemu_ld_i32(TCGV_LOW(val), addr, idx, memop);
|
||||||
@ -243,9 +248,9 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, MemOp memop)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addr = plugin_prep_mem_callbacks(addr);
|
copy_addr = plugin_maybe_preserve_addr(addr);
|
||||||
gen_ldst_i64(INDEX_op_qemu_ld_i64, val, addr, memop, idx);
|
gen_ldst_i64(INDEX_op_qemu_ld_i64, val, addr, memop, idx);
|
||||||
plugin_gen_mem_callbacks(addr, oi, QEMU_PLUGIN_MEM_R);
|
plugin_gen_mem_callbacks(copy_addr, addr, oi, QEMU_PLUGIN_MEM_R);
|
||||||
|
|
||||||
if ((orig_memop ^ memop) & MO_BSWAP) {
|
if ((orig_memop ^ memop) & MO_BSWAP) {
|
||||||
int flags = (orig_memop & MO_SIGN
|
int flags = (orig_memop & MO_SIGN
|
||||||
@ -300,9 +305,8 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, MemOp memop)
|
|||||||
memop &= ~MO_BSWAP;
|
memop &= ~MO_BSWAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr = plugin_prep_mem_callbacks(addr);
|
|
||||||
gen_ldst_i64(INDEX_op_qemu_st_i64, val, addr, memop, idx);
|
gen_ldst_i64(INDEX_op_qemu_st_i64, val, addr, memop, idx);
|
||||||
plugin_gen_mem_callbacks(addr, oi, QEMU_PLUGIN_MEM_W);
|
plugin_gen_mem_callbacks(NULL, addr, oi, QEMU_PLUGIN_MEM_W);
|
||||||
|
|
||||||
if (swap) {
|
if (swap) {
|
||||||
tcg_temp_free_i64(swap);
|
tcg_temp_free_i64(swap);
|
||||||
@ -419,7 +423,6 @@ void tcg_gen_qemu_ld_i128(TCGv_i128 val, TCGv addr, TCGArg idx, MemOp memop)
|
|||||||
tcg_debug_assert((memop & MO_SIGN) == 0);
|
tcg_debug_assert((memop & MO_SIGN) == 0);
|
||||||
|
|
||||||
tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD);
|
tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD);
|
||||||
addr = plugin_prep_mem_callbacks(addr);
|
|
||||||
|
|
||||||
/* TODO: For now, force 32-bit hosts to use the helper. */
|
/* TODO: For now, force 32-bit hosts to use the helper. */
|
||||||
if (TCG_TARGET_HAS_qemu_ldst_i128 && TCG_TARGET_REG_BITS == 64) {
|
if (TCG_TARGET_HAS_qemu_ldst_i128 && TCG_TARGET_REG_BITS == 64) {
|
||||||
@ -490,7 +493,7 @@ void tcg_gen_qemu_ld_i128(TCGv_i128 val, TCGv addr, TCGArg idx, MemOp memop)
|
|||||||
maybe_free_addr64(a64);
|
maybe_free_addr64(a64);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin_gen_mem_callbacks(addr, oi, QEMU_PLUGIN_MEM_R);
|
plugin_gen_mem_callbacks(NULL, addr, oi, QEMU_PLUGIN_MEM_R);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tcg_gen_qemu_st_i128(TCGv_i128 val, TCGv addr, TCGArg idx, MemOp memop)
|
void tcg_gen_qemu_st_i128(TCGv_i128 val, TCGv addr, TCGArg idx, MemOp memop)
|
||||||
@ -501,7 +504,6 @@ void tcg_gen_qemu_st_i128(TCGv_i128 val, TCGv addr, TCGArg idx, MemOp memop)
|
|||||||
tcg_debug_assert((memop & MO_SIGN) == 0);
|
tcg_debug_assert((memop & MO_SIGN) == 0);
|
||||||
|
|
||||||
tcg_gen_req_mo(TCG_MO_ST_LD | TCG_MO_ST_ST);
|
tcg_gen_req_mo(TCG_MO_ST_LD | TCG_MO_ST_ST);
|
||||||
addr = plugin_prep_mem_callbacks(addr);
|
|
||||||
|
|
||||||
/* TODO: For now, force 32-bit hosts to use the helper. */
|
/* TODO: For now, force 32-bit hosts to use the helper. */
|
||||||
|
|
||||||
@ -572,7 +574,7 @@ void tcg_gen_qemu_st_i128(TCGv_i128 val, TCGv addr, TCGArg idx, MemOp memop)
|
|||||||
maybe_free_addr64(a64);
|
maybe_free_addr64(a64);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin_gen_mem_callbacks(addr, oi, QEMU_PLUGIN_MEM_W);
|
plugin_gen_mem_callbacks(NULL, addr, oi, QEMU_PLUGIN_MEM_W);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tcg_gen_ext_i32(TCGv_i32 ret, TCGv_i32 val, MemOp opc)
|
static void tcg_gen_ext_i32(TCGv_i32 ret, TCGv_i32 val, MemOp opc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user