From patchwork Thu Jan 14 02:16:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 362803 Delivered-To: patch@linaro.org Received: by 2002:a02:ccad:0:0:0:0:0 with SMTP id t13csp70896jap; Wed, 13 Jan 2021 18:28:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwn6E66ahmM0xSVI0dJIRhhf6FsunEHpdbkRroSwHxGMpNIXtfshQlJHiMItiS7OyEoWT3f X-Received: by 2002:a25:7e05:: with SMTP id z5mr7383020ybc.497.1610591306705; Wed, 13 Jan 2021 18:28:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610591306; cv=none; d=google.com; s=arc-20160816; b=hJLy4BBk8N1clN+3EWYLWAmK6BSIYEyQE6hufmv/HHwcz/43MIa5U9uDglZK1//oqc WSJ3b04gxV3gAu/+xhRglfDPb5cYmdGrKiDQrYKi6DEo6yOlXd0BMxSQx7r1FD6CXqs8 MqNVAGDtiMULb7A4Em2nWMz6Gk4HZ6ARpvZWBvEyiKf+HR80sYEH5jSzTl2EuOHtJblT HxkOqjZnWDVa+maKWS/NuHaAMOrNP6UNGv9oAkvZF/2qluAh1sw4nme7/EtXjgdqKA5n SGzmhZ5Ami3TgwuWo60gq4t5erbnaWd4CYzG93RQvNLqckLO9sPOazVRf0OocOyzh4+0 mfOg== 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=cRVnylJXcFc8ozdMeUWi6zX6AVte8Tt6BWKvI+IXZu0=; b=OIPUOWTVg0Q/kQZEkgRxiHYzZXSzylzwrXJR337QFbrsldjzqE11UeFWD03cb/j1wc 06URG6N/XtVScQfxW4Hy8VWCh8kvNHN1byfHmFlSXlmoSWZvNzdKRyBNMtlUdM66qsB/ SjPH1VlKuj0i2auQKTYET8wAegYc/N8PVR/AhK+O/2rJhRwKyq29Xgz7l+I3cDOjrKK+ lduyjnYiagDwUV6fodoyEeYQghe5cXgOPAH9kNAzOWNYq7WIo8sJJxzmsA+A0n31Hw1l LiHqREvhQ4z3Bxi8rw4rV/9A4mahixG5YQWFJBZWUIeS/YYibwgWGySJ0O2Kw4504yn3 OW5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bLorooYi; 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 n69si3825124yba.80.2021.01.13.18.28.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jan 2021 18:28:26 -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=bLorooYi; 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]:38058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzsN8-0000Ai-6o for patch@linaro.org; Wed, 13 Jan 2021 21:28:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzsCT-0003bw-0w for qemu-devel@nongnu.org; Wed, 13 Jan 2021 21:17:27 -0500 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:45622) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kzsCN-0003T2-Uv for qemu-devel@nongnu.org; Wed, 13 Jan 2021 21:17:24 -0500 Received: by mail-pf1-x42f.google.com with SMTP id c13so2438814pfi.12 for ; Wed, 13 Jan 2021 18:17:16 -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=cRVnylJXcFc8ozdMeUWi6zX6AVte8Tt6BWKvI+IXZu0=; b=bLorooYirPcJAVCEmLckCHwa8AxY0G3YfgXVfOm1jzwtVEqa5nmHV05bmwAY3KgGcD Ah6MdlQkx9++7+3hj6kiHAZlLUkW1CmCSpKx0TqKINxml9KPrlh83KZh1shzJWKyLCwf HMPaC6TLpxyVrprCcxGJTMMLGSYGlSzgEGBBknEe82EicSnellCvOQo6w2jCQfAO3cdO 5iDmGrMd0Bpx/TwoJAPCgtUiALxTF1lJFdnqsxYL+NuTHbFwD283MsAX/KZjOaz52CqY uDqRMisHofAqfPvKC0sPgiZqjuEflP2kJ/u8WN7m7TiLqcew8xgglPrk+E60hSKL7ta7 uZVg== 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=cRVnylJXcFc8ozdMeUWi6zX6AVte8Tt6BWKvI+IXZu0=; b=TrZhrY7x/G7SJjCNlD1REmpf1rp9CV7u1NpzD5wmm+SLhxWKhPMA96ccc77FDxGOAp DcfxsC4h4fiwOegzcMP0PGhD0/qiALLxuJgTk4H3rswFuYZTR323m+Bh94v4qvlWfyly SrWqj2VAyKVKn3IiZ0rK0lDzngLzrZmixIR+ROGNIUD6LW5qb1bgK7iIlq1lHtQv+ECJ HmgzVQdurg/xflvjmP4lJAoEEKNL3uLqmH+3xFX86kfx7sKAMnTslFutFokH3LMSTzUe iOYB+rIliqeoc5G0642N1WoiaSNGpL7Vsj6Kx5a8nDs+2x8hgXf4kJzmj6LLQylevuQt cNWg== X-Gm-Message-State: AOAM530QbRjNoVcCD/jYrGk/ijBd4cgUwefOa2BIiBd7ZbQsdYE5aZXm 19C9D4VGplvpQUrN/08X7+d9s1WiXlBrcA== X-Received: by 2002:a63:cf43:: with SMTP id b3mr4896930pgj.387.1610590635356; Wed, 13 Jan 2021 18:17:15 -0800 (PST) Received: from localhost.localdomain (rrcs-173-197-107-21.west.biz.rr.com. [173.197.107.21]) by smtp.gmail.com with ESMTPSA id i7sm3771687pfc.50.2021.01.13.18.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 18:17:14 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 10/24] tcg/optimize: Adjust TempOptInfo allocation Date: Wed, 13 Jan 2021 16:16:40 -1000 Message-Id: <20210114021654.647242-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210114021654.647242-1-richard.henderson@linaro.org> References: <20210114021654.647242-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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: peter.maydell@linaro.org, =?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 e42f9c89a8..49bf1386c7 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]); } }