From patchwork Thu Dec 17 14:52:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 344935 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp1287898ejs; Thu, 17 Dec 2020 06:54:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzE68Yk4ouVaTxjkd2TgOG5vUMFNmIlrS0IsXFTGRxjRy3bhRqqkvw5CSmykYasbxNYqmfk X-Received: by 2002:a5b:c0b:: with SMTP id f11mr55076680ybq.158.1608216863084; Thu, 17 Dec 2020 06:54:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608216863; cv=none; d=google.com; s=arc-20160816; b=T/2MNJL2XbcONRKcI34QRmckV/oDpLbbwir7CjsnymHPe5GJmCzRW1NHEDMdaQgqmr CCrJrOHBLFWeAJPOEFj5wg31YF7SJAVExtHtyYC4HxA240CpTTmePi5K/TD1STEpk5F+ jUJUj8vFBy/4R5o5BauWiNUdi8QbiQvgeZlBCPHb8e0gSM5AEAN7PeUwzMXKwR2Z2vkF O9c8D5hwxQ7KUKkrgMWWU+2Ts5GxwtKYvZUKn4zseO5FTRvd6oVLYhvJOpdoTMhM+gTY N/fpPYujKbTteEWLbKRVfq8zJYzRBId4wtQUJ0KyyFUcjly2wzAYJXMIl65nYzjc5/Ti ulTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=1NhNPEIDsGzd2+XZQVnWFC0k3zKAB+Awk5/hTm4NEwE=; b=iXfo7rxoFrTmpYYMJPBWE4YUdl10Aa2Qfc/ZE3Ak+U9U9r6YT0BEOy+gX+gX6Klt79 GlAWptbKfc0QJ/29GzQrHZQN+MoFdrrlHpuSrjyHldG7jeRe0BvxhCX1SxhbjBDPL83U 2XUtt6vrrJV6MCFmPzQdWasasfNYF8KSBnb0IO3tZNuUj7swdK/EESXhaaLh/mr/bNv5 motH4oViu/oHWm5j3xdl2D7siEn4FIObwUpOI51jgfDbpngFWTVLJmYGERqX09lYXG7L pts6K494H1dAgsUDgEgkyrOBhEkOCEUSVLuxK3xSX5Q79NU52PiyGs5Im8NGCurSy4Vb oOKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="RBCr7+n/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z63si5189929ybf.99.2020.12.17.06.54.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Dec 2020 06:54:23 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="RBCr7+n/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpufe-0004yT-F3 for patch@linaro.org; Thu, 17 Dec 2020 09:54:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpudy-0003QO-5s for qemu-devel@nongnu.org; Thu, 17 Dec 2020 09:52:38 -0500 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]:44748) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kpudr-0004v8-Ek for qemu-devel@nongnu.org; Thu, 17 Dec 2020 09:52:37 -0500 Received: by mail-oi1-x236.google.com with SMTP id d189so32431807oig.11 for ; Thu, 17 Dec 2020 06:52:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1NhNPEIDsGzd2+XZQVnWFC0k3zKAB+Awk5/hTm4NEwE=; b=RBCr7+n/bBPQ15WBTjPdBzcKtFHeFj8t8I539Hk9zGHRkZDUyhoo3fGx96ltme7cVT b7wt7v1DCATNjOlKaqFp0H76k64C4pmBOQRgs1x8VMbjS0ASF3ugyUYoSsE8EsZAXlC/ oJRK+jd6bb1wO/ua2GlhcQB8NGhtrdEBxzPvejs1OgNLmBYBwSnrNk0W5+c+a5vu2UTh +UobkXw6xt2cV0cu5d+1IPFd6S9QBJOjCu1PPI2A7k2/AWVMK8jlBA103ZmQMyhZ7lHt uXzBZdzQ8CC54dILgb/TJ9XD0ec2rZmsY4FFXh9jZHtl0+HOeVQlPdfoU6fSw3mc2WLm PN9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1NhNPEIDsGzd2+XZQVnWFC0k3zKAB+Awk5/hTm4NEwE=; b=bkcUS8EvGsMW5+9rSnCnSOsKjFG95X4mtCmMf+lluuDp7lnC9x1pkbSK1IRmfhJjJy vxyXrTb4uwL0vObtFQiK/2U6nqKcfOHV5wTpx9CoFeBWv1nl/XvtIc3FzYsgFNcRpczH qs+28Pe9Ksucc7RwNnJ6Fqkw4POl9Izlg4u/W07SZAvBwMHjEMyVsHuHwDti/p6Jx6Z6 AwwL2NBPcnOsMKJI+otG81WK8v79jo6lN5L4ie8jLZfEt3tFYzQX+eTti7iVF1HF4v+P x9bimnjBmO+arrrpll/GXzW2OHjq+pwkhhoNjAq3gufC7WZYkcapbWRqc2EJ0SJ8QlZI K3Yg== X-Gm-Message-State: AOAM531GdWXhAC6aCj43ljEKDd2rQTxh7PX/rxHw2MKSAigjvz+bBuTv D389MUgP3VF8V/2ywVid2sZhp9q6brAsj+Me X-Received: by 2002:aca:c30b:: with SMTP id t11mr5182693oif.61.1608216748795; Thu, 17 Dec 2020 06:52:28 -0800 (PST) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id x130sm1136342oif.3.2020.12.17.06.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Dec 2020 06:52:28 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 10/23] tcg/optimize: Adjust TempOptInfo allocation Date: Thu, 17 Dec 2020 08:52:02 -0600 Message-Id: <20201217145215.534637-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201217145215.534637-1-richard.henderson@linaro.org> References: <20201217145215.534637-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::236; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x236.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Do not allocate a large block for indexing. Instead, allocate for each temporary as they are seen. In general, this will use less memory, if we consider that most TBs do not touch every target register. This also allows us to allocate TempOptInfo for new temps created during optimization. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- tcg/optimize.c | 60 ++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 26 deletions(-) -- 2.25.1 diff --git a/tcg/optimize.c b/tcg/optimize.c index bf2c2a3ce5..e269962932 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -89,35 +89,41 @@ static void reset_temp(TCGArg arg) } /* Initialize and activate a temporary. */ -static void init_ts_info(TempOptInfo *infos, - TCGTempSet *temps_used, TCGTemp *ts) +static void init_ts_info(TCGTempSet *temps_used, TCGTemp *ts) { size_t idx = temp_idx(ts); - if (!test_bit(idx, temps_used->l)) { - TempOptInfo *ti = &infos[idx]; + TempOptInfo *ti; + if (test_bit(idx, temps_used->l)) { + return; + } + set_bit(idx, temps_used->l); + + ti = ts->state_ptr; + if (ti == NULL) { + ti = tcg_malloc(sizeof(TempOptInfo)); ts->state_ptr = ti; - ti->next_copy = ts; - ti->prev_copy = ts; - if (ts->kind == TEMP_CONST) { - ti->is_const = true; - ti->val = ti->mask = ts->val; - if (TCG_TARGET_REG_BITS > 32 && ts->type == TCG_TYPE_I32) { - /* High bits of a 32-bit quantity are garbage. */ - ti->mask |= ~0xffffffffull; - } - } else { - ti->is_const = false; - ti->mask = -1; + } + + ti->next_copy = ts; + ti->prev_copy = ts; + if (ts->kind == TEMP_CONST) { + ti->is_const = true; + ti->val = ts->val; + ti->mask = ts->val; + if (TCG_TARGET_REG_BITS > 32 && ts->type == TCG_TYPE_I32) { + /* High bits of a 32-bit quantity are garbage. */ + ti->mask |= ~0xffffffffull; } - set_bit(idx, temps_used->l); + } else { + ti->is_const = false; + ti->mask = -1; } } -static void init_arg_info(TempOptInfo *infos, - TCGTempSet *temps_used, TCGArg arg) +static void init_arg_info(TCGTempSet *temps_used, TCGArg arg) { - init_ts_info(infos, temps_used, arg_temp(arg)); + init_ts_info(temps_used, arg_temp(arg)); } static TCGTemp *find_better_copy(TCGContext *s, TCGTemp *ts) @@ -604,9 +610,8 @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2) /* Propagate constants and copies, fold constant expressions. */ void tcg_optimize(TCGContext *s) { - int nb_temps, nb_globals; + int nb_temps, nb_globals, i; TCGOp *op, *op_next, *prev_mb = NULL; - TempOptInfo *infos; TCGTempSet temps_used; /* Array VALS has an element for each temp. @@ -616,12 +621,15 @@ void tcg_optimize(TCGContext *s) nb_temps = s->nb_temps; nb_globals = s->nb_globals; + bitmap_zero(temps_used.l, nb_temps); - infos = tcg_malloc(sizeof(TempOptInfo) * nb_temps); + for (i = 0; i < nb_temps; ++i) { + s->temps[i].state_ptr = NULL; + } QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) { uint64_t mask, partmask, affected, tmp; - int nb_oargs, nb_iargs, i; + int nb_oargs, nb_iargs; TCGOpcode opc = op->opc; const TCGOpDef *def = &tcg_op_defs[opc]; @@ -633,14 +641,14 @@ void tcg_optimize(TCGContext *s) for (i = 0; i < nb_oargs + nb_iargs; i++) { TCGTemp *ts = arg_temp(op->args[i]); if (ts) { - init_ts_info(infos, &temps_used, ts); + init_ts_info(&temps_used, ts); } } } else { nb_oargs = def->nb_oargs; nb_iargs = def->nb_iargs; for (i = 0; i < nb_oargs + nb_iargs; i++) { - init_arg_info(infos, &temps_used, op->args[i]); + init_arg_info(&temps_used, op->args[i]); } }