From patchwork Wed Apr 22 01:17:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 185634 Delivered-To: patch@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp167877ilf; Tue, 21 Apr 2020 18:28:41 -0700 (PDT) X-Google-Smtp-Source: APiQypIzQV6EkkLimxdLuEM3VVULL+dittJ0C4hB/i4Yfx/i80eY2VicSglto9ZGxwsj/xI2o309 X-Received: by 2002:ac8:468d:: with SMTP id g13mr23519981qto.59.1587518921528; Tue, 21 Apr 2020 18:28:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587518921; cv=none; d=google.com; s=arc-20160816; b=vQHdN3sKDWJ0NUwOpe4rlQuJJiVzirbybXsGB1FS2esN3Z1AyKAfqQlyhVuAMx4LlL M+Wt7nz1OMeDuC6zkhqVSoDj3zLlYYbVkGwWTezlNm8c1boCLlOl8tAM8YrcWUGYjk4z RNWluVSDtV1Vx5y1lCXr4wqJ+y6skI58Q3qKql8FLGjZaCCGtkyfGvDQHx1YVTbA89gw Fg7yyyWKHA6Rc+7aFPAy3r4FnNcCM1Vi2dYOjRaD588jmXCQuF8H7pmcz6y8yZ/PhzfS 7OZ10qrC9jbdf3+qS2tkJWuiULj6Vp2wQmD0jmP+t7RzrIUm5RgObMQy4wxR00E1KyQ/ TWzQ== 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=DuJkDhPEOnaROoc/1JyNu5wUbGL/01Lw8KOKVY4KSao=; b=E5Aefimg80TsTiQLCMKw4mKrcp4vESNaJ3pc0XyZW4JkqbTAakFR7tXPaUiksFqQor /2TiS+CSB/kaST9htj2E5NQlqOA5qMtkkEp1IctHZb3VCN7Dy94u69yPA78OOQ1alFkA 8tiHPMFhOm0OeJq/E6JYRucF6qVFfLv90gS90bE3K7tTRLUgFLlRdMTJ9DkVWubJkbvh +R8mHSiuHQ/lNMhIjtl/N79iHKEV0f8M0xpZZot+QGx9f8GlX4oo/+3GzxzCOPJXEWiE b20V88QxcgtCe29Ml4YyqKWrIwK0coCU7Ey7LV8qC0pJDlEff9OIS6+wMUekyTzPW4NS pQAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RcyL6Dwg; 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 w23si2460075qtn.98.2020.04.21.18.28.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Apr 2020 18:28:41 -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=RcyL6Dwg; 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]:38844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR4Bt-0002Qo-1C for patch@linaro.org; Tue, 21 Apr 2020 21:28:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35158) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR41O-0001gJ-2g for qemu-devel@nongnu.org; Tue, 21 Apr 2020 21:17:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jR41N-0001zK-9m for qemu-devel@nongnu.org; Tue, 21 Apr 2020 21:17:49 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:42611) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jR41M-0001vh-PI for qemu-devel@nongnu.org; Tue, 21 Apr 2020 21:17:48 -0400 Received: by mail-pf1-x434.google.com with SMTP id f7so212102pfa.9 for ; Tue, 21 Apr 2020 18:17:48 -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=DuJkDhPEOnaROoc/1JyNu5wUbGL/01Lw8KOKVY4KSao=; b=RcyL6DwgogtDh0tDQS1mF5ZYbfPbm7Z4xiv30qgO99gDnELvAxiqz9iC2CKMd6b9vn zHNjZPdT1mhcjKndU1B21AQb4WGx2KyooA9boeHd8VEuix5/LlFEp0vBZpBUro55FFug aN9PJF8GZGvurK+w9vgiL45JpmiITQ7pIp0oQT4qQ5cH59iZjzbFrmF1ZZKx+SSXir+1 j+U3mgaVXctEKYPPX9XO/yKvYwXXVDL6+2XiAOoBqjyG6u0g/XRw6dDhoACMazsm2qWg //Y5+HJfjSKnLgQzJFOscWsHdhYubuz9dSxzIYN16kZauROIg1/bYtovAJfYVbpD+c7V 3tZw== 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=DuJkDhPEOnaROoc/1JyNu5wUbGL/01Lw8KOKVY4KSao=; b=pyqQQFhjG1243t8KItS4xIq5rit+PUN6clTpmMTdG66rtE17PUQvjNZyllIhGNX2oN 2eUFFaQN2mYsW8gPmNZsx9nNMfQNljUJ8XSqytVw/tkHLqRIXRuBgEjUOibO+Wb+IG18 M8Zer3LgEvAN+fwByhypAItHXuVd4aGgIqQ0KsR90OsyqRuKBA5758N583CO3bfYcHTT gx0j7LRrRze7Xn6E9/BrL8R8try0VDU0avjtvcHXucQt5vu8m2QxS7fcLmyX0VOR0vPO gQzpcmqso8d+OuDJnxxVts6SkqBjY/HpV9vQvGk9wrLMZc0tFkZ0lV9A2cdCpPOmY3+b 8J7w== X-Gm-Message-State: AGi0PuZRZA/ZxbCilxUkGTl5JWSJfhjIi6E8XDr/DO8TzWSuSlAmgu3Z NrLrNMY8Fkd7qpFXeuH44+5Bcm0far0= X-Received: by 2002:aa7:9e07:: with SMTP id y7mr18435551pfq.257.1587518266036; Tue, 21 Apr 2020 18:17:46 -0700 (PDT) Received: from localhost.localdomain (174-21-149-226.tukw.qwest.net. [174.21.149.226]) by smtp.gmail.com with ESMTPSA id m4sm3673561pfm.26.2020.04.21.18.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 18:17:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 17/36] tcg/optimize: Adjust TempOptInfo allocation Date: Tue, 21 Apr 2020 18:17:03 -0700 Message-Id: <20200422011722.13287-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200422011722.13287-1-richard.henderson@linaro.org> References: <20200422011722.13287-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2607:f8b0:4864:20::434 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: alex.bennee@linaro.org 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. Signed-off-by: Richard Henderson --- tcg/optimize.c | 60 ++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 26 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/tcg/optimize.c b/tcg/optimize.c index b86bf3d707..d36d7e1d7f 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) @@ -603,9 +609,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. @@ -615,12 +620,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) { tcg_target_ulong mask, partmask, affected; - int nb_oargs, nb_iargs, i; + int nb_oargs, nb_iargs; TCGArg tmp; 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]); } }