From nobody Mon Feb 9 17:36:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500237301918323.2829758146062; Sun, 16 Jul 2017 13:35:01 -0700 (PDT) Received: from localhost ([::1]:46835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWqFo-00010i-Nl for importer@patchew.org; Sun, 16 Jul 2017 16:35:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWpme-0001Bb-HR for qemu-devel@nongnu.org; Sun, 16 Jul 2017 16:04:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dWpmZ-0008QD-9f for qemu-devel@nongnu.org; Sun, 16 Jul 2017 16:04:52 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:39975) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dWpmZ-0008PO-2o for qemu-devel@nongnu.org; Sun, 16 Jul 2017 16:04:47 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C4E8D20A72; Sun, 16 Jul 2017 16:04:46 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 16 Jul 2017 16:04:46 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 6CA6F24606; Sun, 16 Jul 2017 16:04:46 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=1/h H4vnMuwfH96H3aNbuZU6rdzAgqBWwcqGUDchDgkw=; b=k1p2xUMLbfQj9sAQ38i VLcoU7L1yS70HGXZOqTG/Xbh6Rnp1umEyQoWRtts4ZX0Jv7ioHaWtsE1V4TT8t6L iwtfTjPlDiKnAn5yP4EQr2+Obr5NxvpOcJceDkXEMuOqB+rZx78tYc4opamrDl/2 lcY2+orpSfuXB7e7lgYt2bPw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=1/hH4vnMuwfH96H3aNbuZU6rdzAgqBWwcqGUDchDg kw=; b=jS1Dg4QClQOP2Vwm9LJ6sYGV74GIHYWIhjayYsTPwNXx+t+YFrol0tryL XQAKB1rLcG1B16tD4J4AznKuiwwosvPdUlYkXzzjWpVSRAoM7+sKUPwi7i0w6nzP HtxG84VHJW1qVUOGc/vG+RhFNThBS9hx4WeinRi5cu5fWtdVFeE3r6nU53rwLZYl +lMjfHq4AGNmUKgJFho50lJxKyTrFgb/alJkGY4pXUvBrVfxECaSBFdX6xPREnAi uMzKKdnoGGuzrsuxsLYSoVNbAsfeEGwJgt9aD2BuPATSt0S4vXEP02OdEYfJRTZG id4B0RVezlRjOlabhi04R3RIdkZPw== X-ME-Sender: X-Sasl-enc: svz8YHtxiGoQ76KWa57/TDVTY8PUDosMy0lPcBiHQ6PD 1500235486 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 16 Jul 2017 16:04:19 -0400 Message-Id: <1500235468-15341-37-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500235468-15341-1-git-send-email-cota@braap.org> References: <1500235468-15341-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH v2 36/45] tcg: dynamically allocate optimizer globals + fold into TCGContext 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Groundwork for supporting multiple TCG contexts. Signed-off-by: Emilio G. Cota --- tcg/tcg.h | 12 ++++++++++++ tcg/optimize.c | 40 +++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/tcg/tcg.h b/tcg/tcg.h index 569f823..175d4de 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -641,6 +641,14 @@ QEMU_BUILD_BUG_ON(OPPARAM_BUF_SIZE > (1 << 14)); /* Make sure that we don't overflow 64 bits without noticing. */ QEMU_BUILD_BUG_ON(sizeof(TCGOp) > 8); =20 +struct tcg_temp_info { + bool is_const; + uint16_t prev_copy; + uint16_t next_copy; + tcg_target_ulong val; + tcg_target_ulong mask; +}; + struct TCGContext { uint8_t *pool_cur, *pool_end; TCGPool *pool_first, *pool_current, *pool_first_large; @@ -717,6 +725,10 @@ struct TCGContext { TCGTempSet free_temps[TCG_TYPE_COUNT * 2]; TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */ =20 + /* optimizer */ + struct tcg_temp_info *opt_temps; + TCGTempSet opt_temps_used; + /* Tells which temporary holds a given register. It does not take into account fixed registers */ TCGTemp *reg_to_temp[TCG_TARGET_NB_REGS]; diff --git a/tcg/optimize.c b/tcg/optimize.c index adfc56c..61ca870 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -32,30 +32,21 @@ glue(glue(case INDEX_op_, x), _i32): \ glue(glue(case INDEX_op_, x), _i64) =20 -struct tcg_temp_info { - bool is_const; - uint16_t prev_copy; - uint16_t next_copy; - tcg_target_ulong val; - tcg_target_ulong mask; -}; - -static struct tcg_temp_info temps[TCG_MAX_TEMPS]; -static TCGTempSet temps_used; - static inline bool temp_is_const(TCGArg arg) { - return temps[arg].is_const; + return tcg_ctx->opt_temps[arg].is_const; } =20 static inline bool temp_is_copy(TCGArg arg) { - return temps[arg].next_copy !=3D arg; + return tcg_ctx->opt_temps[arg].next_copy !=3D arg; } =20 /* Reset TEMP's state, possibly removing the temp for the list of copies. = */ static void reset_temp(TCGArg temp) { + struct tcg_temp_info *temps =3D tcg_ctx->opt_temps; + temps[temps[temp].next_copy].prev_copy =3D temps[temp].prev_copy; temps[temps[temp].prev_copy].next_copy =3D temps[temp].next_copy; temps[temp].next_copy =3D temp; @@ -67,18 +58,20 @@ static void reset_temp(TCGArg temp) /* Reset all temporaries, given that there are NB_TEMPS of them. */ static void reset_all_temps(int nb_temps) { - bitmap_zero(temps_used.l, nb_temps); + bitmap_zero(tcg_ctx->opt_temps_used.l, nb_temps); } =20 /* Initialize and activate a temporary. */ static void init_temp_info(TCGArg temp) { - if (!test_bit(temp, temps_used.l)) { + struct tcg_temp_info *temps =3D tcg_ctx->opt_temps; + + if (!test_bit(temp, tcg_ctx->opt_temps_used.l)) { temps[temp].next_copy =3D temp; temps[temp].prev_copy =3D temp; temps[temp].is_const =3D false; temps[temp].mask =3D -1; - set_bit(temp, temps_used.l); + set_bit(temp, tcg_ctx->opt_temps_used.l); } } =20 @@ -118,6 +111,7 @@ static TCGOpcode op_to_movi(TCGOpcode op) =20 static TCGArg find_better_copy(TCGContext *s, TCGArg temp) { + struct tcg_temp_info *temps =3D tcg_ctx->opt_temps; TCGArg i; =20 /* If this is already a global, we can't do better. */ @@ -147,6 +141,7 @@ static TCGArg find_better_copy(TCGContext *s, TCGArg te= mp) =20 static bool temps_are_copies(TCGArg arg1, TCGArg arg2) { + struct tcg_temp_info *temps =3D tcg_ctx->opt_temps; TCGArg i; =20 if (arg1 =3D=3D arg2) { @@ -169,6 +164,7 @@ static bool temps_are_copies(TCGArg arg1, TCGArg arg2) static void tcg_opt_gen_movi(TCGContext *s, TCGOp *op, TCGArg *args, TCGArg dst, TCGArg val) { + struct tcg_temp_info *temps =3D tcg_ctx->opt_temps; TCGOpcode new_op =3D op_to_movi(op->opc); tcg_target_ulong mask; =20 @@ -196,6 +192,7 @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, T= CGArg *args, return; } =20 + struct tcg_temp_info *temps =3D tcg_ctx->opt_temps; TCGOpcode new_op =3D op_to_mov(op->opc); tcg_target_ulong mask; =20 @@ -466,6 +463,8 @@ static bool do_constant_folding_cond_eq(TCGCond c) static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x, TCGArg y, TCGCond c) { + struct tcg_temp_info *temps =3D tcg_ctx->opt_temps; + if (temp_is_const(x) && temp_is_const(y)) { switch (op_bits(op)) { case 32: @@ -494,6 +493,7 @@ static TCGArg do_constant_folding_cond(TCGOpcode op, TC= GArg x, of the condition (0 or 1) if it can */ static TCGArg do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c) { + struct tcg_temp_info *temps =3D tcg_ctx->opt_temps; TCGArg al =3D p1[0], ah =3D p1[1]; TCGArg bl =3D p2[0], bh =3D p2[1]; =20 @@ -558,9 +558,15 @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2) /* Propagate constants and copies, fold constant expressions. */ void tcg_optimize(TCGContext *s) { + struct tcg_temp_info *temps; int oi, oi_next, nb_temps, nb_globals; TCGArg *prev_mb_args =3D NULL; =20 + if (tcg_ctx->opt_temps =3D=3D NULL) { + tcg_ctx->opt_temps =3D g_new(struct tcg_temp_info, TCG_MAX_TEMPS); + } + temps =3D tcg_ctx->opt_temps; + /* Array VALS has an element for each temp. If this temp holds a constant then its value is kept in VALS' eleme= nt. If this temp is a copy of other ones then the other copies are @@ -1360,7 +1366,7 @@ void tcg_optimize(TCGContext *s) if (!(args[nb_oargs + nb_iargs + 1] & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS)= )) { for (i =3D 0; i < nb_globals; i++) { - if (test_bit(i, temps_used.l)) { + if (test_bit(i, tcg_ctx->opt_temps_used.l)) { reset_temp(i); } } --=20 2.7.4