From patchwork Wed Sep 9 00:16:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249412 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp5017039ilg; Tue, 8 Sep 2020 17:26:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+VwNCKn1/3ixKDCSGFZKJqooAic1Hp89sPvH+iHHvzaOhzJtJo+u8SEs8imcdvJmYUpI5 X-Received: by 2002:a25:c07:: with SMTP id 7mr2120179ybm.200.1599611163191; Tue, 08 Sep 2020 17:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599611163; cv=none; d=google.com; s=arc-20160816; b=t7lzMHpfJb9KMfKZ9F2xN0MKvzauhaql3rxcjZzn+8JU4Opo/Y+JsPXAEtJ4AbqnIu ADnTIdkoMT1YsE7/OHngWuMHwTW0rcx9Yz/5KL1HOHgOxPJbVFIB/PvZo5md6KMZYge+ SHXaYJsQhjs63GCcBbhDshnSalwPYHBFjtoE9A0F4gERblqxzWKa678sIXQltOouU3wl +uFG1UPEAGNjp9IrAgznm7H6p4286qmyjemEhVPvn1UxsyPPD3GtFgyMUKZqDcCWLqyZ ePuQLI+/ARB58noy9oGVlz+qupmWUHaVl3XrxrYhkjpQ6pX10qgV0GsDiCxb/dKXdpU8 ChVg== 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=MAaQxqRrv0XEufX9Bhlu49mG+GoJAa0lxg3BB+FDVKi8vzxvXZvC7iwUO4eygnKHN4 +75fRN3lSsWdYueta4hbdQMoSbGhA6xRYx5iIVT/eViDpe9fPBVVI60tacq8i+OyTTYe uFOVzJ+BwQkTdd3CfWm8urNMVStbbFZ7qpy8TQFc3nK/0zrVcNSdOPBBdXDXuQaWa/Yb IyJbKGjHMo5Sye/y5K5sqC+P/uLTze/ZAp6VHv3GFQNAKQZJlXTzCByVPvRXMbJkE1ZQ 7WmN0RwAM4FaiWlDGf0rl3PAU5uWqU5WDeJ+hiAHZr7o20Ug93zxtnKQTqv8FHhcc+oC gEvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fV1LqSRE; 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 e138si975733ybb.133.2020.09.08.17.26.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Sep 2020 17:26:03 -0700 (PDT) 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=fV1LqSRE; 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]:47686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFnw2-00039w-Hd for patch@linaro.org; Tue, 08 Sep 2020 20:26:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFnna-0008QJ-Gv for qemu-devel@nongnu.org; Tue, 08 Sep 2020 20:17:18 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:39475) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kFnnY-0002Ff-FU for qemu-devel@nongnu.org; Tue, 08 Sep 2020 20:17:18 -0400 Received: by mail-pj1-x1042.google.com with SMTP id s2so426078pjr.4 for ; Tue, 08 Sep 2020 17:17:16 -0700 (PDT) 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=fV1LqSREgOEiUJmb7AH6Z7MTZwMsxQ0vHK0Bm0EDMeCsIMI6nZNa2SNCh9rrgYVTi6 nT+Dya25DqJG+W14bXeZ/a9U6h7o+4n18YvO+iQlaHHQW5GUD+/+vamKMlMiyQfmjhhM BS578KPqLPxEPgjbJU5MN8RXkbFSzD/3Lt5F9vrWntiAJt3hs0N+v8swRpW7r6+N90Qm jy5oviYkldsy+mYtVqJV2Tg5FDsEizta8wGFQ9RXMKJrJHCg49Aq6jBJ6wlk69bhZN4v MKw9BOu0T+5+uK4zR5x1hTvoIILIcK5gIg2wrreYCmBg3+2S8/+C36hUul6qgE6Ps0NS M5Ew== 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=lKPWTY6MdDpBp/ikbaNFltn92YZoc4RduzSuUQ6KFV/Ii/5Inb+37e22c6Z3F2mmwW chjbbVGMMzv6vgREdDm94EHsUmvQqaJNeqUrKlUXIbt7Nqb3sEdFH2RZPTc98uDtSDLQ xwiOPXYn/3ptdM1ykzyJtBjb3Benu5+D8zXDwZxQGTcLr15HYmx/2AolRsO+x+aOo0ze /NE8Sx/3izPOsQfllEOaMoahiLGFW2B6yAPyrR46E1WDcbQ01UeA5Af8c+j2qwPuAVlq mhKDLT/xQToY0D6FYDIvEbocdA0wUcGSVe7SliZXHLpzMh5DKeG0v95eFrIPyY0QrAeh f0og== X-Gm-Message-State: AOAM532QZLd3fYdFDLU81YHBsHFF2c4Y6BouWeqI5WQMoKF20hN1vAED p7whDjLNJzJkFTdYb/Jc9Pqp2FcIO08eAg== X-Received: by 2002:a17:90a:5609:: with SMTP id r9mr1186624pjf.217.1599610634646; Tue, 08 Sep 2020 17:17:14 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 137sm505437pfu.149.2020.09.08.17.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 17:17:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 20/43] tcg/optimize: Adjust TempOptInfo allocation Date: Tue, 8 Sep 2020 17:16:24 -0700 Message-Id: <20200909001647.532249-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200909001647.532249-1-richard.henderson@linaro.org> References: <20200909001647.532249-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1042; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1042.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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]); } }