From patchwork Thu Mar 15 19:19:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 886414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 402JNQ2Jplz9sBt for ; Fri, 16 Mar 2018 06:21:10 +1100 (AEDT) Received: from localhost ([::1]:53011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewYR2-0000c8-3l for incoming@patchwork.ozlabs.org; Thu, 15 Mar 2018 15:21:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewYQM-0000Yk-0c for qemu-devel@nongnu.org; Thu, 15 Mar 2018 15:20:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewYQI-0005xt-Ry for qemu-devel@nongnu.org; Thu, 15 Mar 2018 15:20:26 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:45177) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ewYQI-0005wl-C6 for qemu-devel@nongnu.org; Thu, 15 Mar 2018 15:20:22 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue007 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MNRSn-1ez3OW3Faz-006yfB; Thu, 15 Mar 2018 20:20:13 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 15 Mar 2018 20:19:56 +0100 Message-Id: <20180315191958.28937-2-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180315191958.28937-1-laurent@vivier.eu> References: <20180315191958.28937-1-laurent@vivier.eu> X-Provags-ID: V03:K0:3TDN7e6pznfv4k98CGgae/qJ7MSuH3nBTzT2uMoSCH2f74RIDDf MemEnup0Nff3qokq/2IlS4QxoP2/Mv2g7ONI0mj8lqE+zUYOv1QS7AX2JzKAeSi628ioX5M jqSvUusTXveqwiUVWeoSA2lhWgbeww5WYiLQFOcGEbiPBC0Eie2zj5n8jMrd1zC6uOGnVif dTAI67Gz3RBemwYxrBPuA== X-UI-Out-Filterresults: notjunk:1; V01:K0:kbUZHL3e4Kg=:FdYqxKJlNFWGxgI3SDNGZC ivNbZUyh8V/GHdukWPhZoeBj4dAaDT0LUtFnV4sN38QV6ASxj9rTvMILhXapJjKRyaKTqMlVC WERfx5XvDTnhUwSRylT4E3RL8wettQG9Oc6kZyN85/iULTEmYxnYKBwXQA2qMzxXvI0JnSjWt KxiuMZnNIiWXw8SUbgP0PmrAXHmhnUXmTcRESM5RrCnfaB88yQjKPf+8qLgyMbVALTNAhZ54i sREm/p70w0/N9XVEJ5F8ruv3o5ag+R9zKR7g3M4wmuqC3C/GMzSAyArGoXZaISI/Efjiv/eJA RWBz0XmZZOsP7ven25W/yPk6YMDnodRHsVGtvxgP4SOZxdzcvBL3xFkIrcswZ45zyon1t4U+6 u4QmyuUc5CnW/VuGo7penddG3mshL13KdmTNdYjkmWi45Guh2cdjtyXXy2OCWWmMTVC7dJL0q RhLycytwRohsfaIxiKkW0T2k62cj2nASyG0ToECH+KcZiqLchpx8kjPzDi6B2koLqPoyzHVl8 daZ7QorwJQJr0o70/MlmLI2S0/VLLbjEfVSkvByExzdwI4pw9X+OwC+t3Mm4taFXcHslJy3yd 8V332/0hNmqjKjpYIsh0oFpUnV+0YOzT7+Rzm49JPfkGFAOngAOejhL8RgsvN7vIqV/n2Gd94 iqOPUA6W6xTTFM5igY4X7AnnXa7F9SYX9PM1KLJYJPj32NPglUApHlYnrpLuj6hjd2ppvrr8n JmrecPcr6NmcRjdnb4cARXmU6nIOBmXTEfpvUA== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.133 Subject: [Qemu-devel] [RFC 1/3] tcg: introduce tcg_temp_try_free() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" m68k has some functions returning either locally allocated TCGv or memory allocated TCGv (registers). We want to free locally allocated TCGv to avoid overflow in sequence like: 0xc00ae406: movel %fp@(-132),%fp@(-268) 0xc00ae40c: movel %fp@(-128),%fp@(-264) 0xc00ae412: movel %fp@(-20),%fp@(-212) 0xc00ae418: movel %fp@(-16),%fp@(-208) 0xc00ae41e: movel %fp@(-60),%fp@(-220) 0xc00ae424: movel %fp@(-56),%fp@(-216) 0xc00ae42a: movel %fp@(-124),%fp@(-252) 0xc00ae430: movel %fp@(-120),%fp@(-248) 0xc00ae436: movel %fp@(-12),%fp@(-260) 0xc00ae43c: movel %fp@(-8),%fp@(-256) 0xc00ae442: movel %fp@(-52),%fp@(-276) 0xc00ae448: movel %fp@(-48),%fp@(-272) ... That can fill a lot of TCGv entries in a sequence, especially since 15fa08f845 ("tcg: Dynamically allocate TCGOps") Signed-off-by: Laurent Vivier --- tcg/tcg-op.h | 2 ++ tcg/tcg.c | 28 +++++++++++++++++++++------- tcg/tcg.h | 3 +++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index 75bb55aeac..564e310426 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -811,6 +811,7 @@ void tcg_gen_lookup_and_goto_ptr(void); #define tcg_global_mem_new tcg_global_mem_new_i32 #define tcg_temp_local_new() tcg_temp_local_new_i32() #define tcg_temp_free tcg_temp_free_i32 +#define tcg_temp_try_free tcg_temp_try_free_i32 #define tcg_gen_qemu_ld_tl tcg_gen_qemu_ld_i32 #define tcg_gen_qemu_st_tl tcg_gen_qemu_st_i32 #else @@ -819,6 +820,7 @@ void tcg_gen_lookup_and_goto_ptr(void); #define tcg_global_mem_new tcg_global_mem_new_i64 #define tcg_temp_local_new() tcg_temp_local_new_i64() #define tcg_temp_free tcg_temp_free_i64 +#define tcg_temp_try_free tcg_temp_try_free_i64 #define tcg_gen_qemu_ld_tl tcg_gen_qemu_ld_i64 #define tcg_gen_qemu_st_tl tcg_gen_qemu_st_i64 #endif diff --git a/tcg/tcg.c b/tcg/tcg.c index bb24526c93..9d02c07e7a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1072,11 +1072,15 @@ TCGv_vec tcg_temp_new_vec_matching(TCGv_vec match) return temp_tcgv_vec(t); } -static void tcg_temp_free_internal(TCGTemp *ts) +static void tcg_temp_free_internal(TCGTemp *ts, bool try) { TCGContext *s = tcg_ctx; int k, idx; + if (try && ts->temp_allocated == 0) { + return; + } + #if defined(CONFIG_DEBUG_TCG) s->temps_in_use--; if (s->temps_in_use < 0) { @@ -1095,17 +1099,27 @@ static void tcg_temp_free_internal(TCGTemp *ts) void tcg_temp_free_i32(TCGv_i32 arg) { - tcg_temp_free_internal(tcgv_i32_temp(arg)); + tcg_temp_free_internal(tcgv_i32_temp(arg), false); } void tcg_temp_free_i64(TCGv_i64 arg) { - tcg_temp_free_internal(tcgv_i64_temp(arg)); + tcg_temp_free_internal(tcgv_i64_temp(arg), false); +} + +void tcg_temp_try_free_i32(TCGv_i32 arg) +{ + tcg_temp_free_internal(tcgv_i32_temp(arg), true); +} + +void tcg_temp_try_free_i64(TCGv_i64 arg) +{ + tcg_temp_free_internal(tcgv_i64_temp(arg), true); } void tcg_temp_free_vec(TCGv_vec arg) { - tcg_temp_free_internal(tcgv_vec_temp(arg)); + tcg_temp_free_internal(tcgv_vec_temp(arg), false); } TCGv_i32 tcg_const_i32(int32_t val) @@ -1572,8 +1586,8 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) for (i = real_args = 0; i < orig_nargs; ++i) { int is_64bit = orig_sizemask & (1 << (i+1)*2); if (is_64bit) { - tcg_temp_free_internal(args[real_args++]); - tcg_temp_free_internal(args[real_args++]); + tcg_temp_free_internal(args[real_args++], false); + tcg_temp_free_internal(args[real_args++], false); } else { real_args++; } @@ -1590,7 +1604,7 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) for (i = 0; i < nargs; ++i) { int is_64bit = sizemask & (1 << (i+1)*2); if (!is_64bit) { - tcg_temp_free_internal(args[i]); + tcg_temp_free_internal(args[i], false); } } #endif /* TCG_TARGET_EXTEND_ARGS */ diff --git a/tcg/tcg.h b/tcg/tcg.h index 9e2d909a4a..e6d9dc0643 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -890,6 +890,9 @@ void tcg_temp_free_i32(TCGv_i32 arg); void tcg_temp_free_i64(TCGv_i64 arg); void tcg_temp_free_vec(TCGv_vec arg); +void tcg_temp_try_free_i32(TCGv_i32 arg); +void tcg_temp_try_free_i64(TCGv_i64 arg); + static inline TCGv_i32 tcg_global_mem_new_i32(TCGv_ptr reg, intptr_t offset, const char *name) {