From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 062D4C38A29 for ; Sat, 18 Apr 2020 16:23:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C139D2054F for ; Sat, 18 Apr 2020 16:23:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="T23yHe/G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C139D2054F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPqFf-0001CF-QD for qemu-devel@archiver.kernel.org; Sat, 18 Apr 2020 12:23:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48179) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPqBm-0004Ce-HJ for qemu-devel@nongnu.org; Sat, 18 Apr 2020 12:19:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jPqBl-0005FQ-8n for qemu-devel@nongnu.org; Sat, 18 Apr 2020 12:19:30 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:36456) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jPqBl-0005CF-2H for qemu-devel@nongnu.org; Sat, 18 Apr 2020 12:19:29 -0400 Received: by mail-pj1-x102a.google.com with SMTP id nu11so2474860pjb.1 for ; Sat, 18 Apr 2020 09:19:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=DuJkDhPEOnaROoc/1JyNu5wUbGL/01Lw8KOKVY4KSao=; b=T23yHe/Gr6i1dtamJBmXgruKsQmfGotnEi8hYEzqD+kVWQelxkqEPZfIpluhDa2hIU eMsbrN3skiuBbDBjZ9Txw5A+hFx1DpmMyhlIJef3+tme2f2c5R6r3heWeIrI96WT3yEH jIVdPbQgtGoVgzheW33yd88sJAUiaORJ2gH+qQvoPVEFd/5gceTEygWnxFENVbWDpxwn KMeHl5bqG4P1M4VtBO1qXYbY8kdO7SWWx905iu2X5P7/8Kc/nxFKlJbv1tzjq8qdi9AJ oeRdPNwtmHq7XCd3af7txIgKb7h51AUy3aj4YbJ2OeUaqCkM/t/uf9z+LOqXyI02QPHX Itdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DuJkDhPEOnaROoc/1JyNu5wUbGL/01Lw8KOKVY4KSao=; b=redk1x+Am4zvRYBCXFdcyGvtDYFoq1gbD2OF05DNCfS+0JZJTSdfFkoKFOvUjm60Wl CewMAOW7fXLQrD8XroElKNYExmAQEhjOVYLTKUGGfLviCtVb5afF0WG/U7zeBPZlDTou 37HqZsR5VcCMyMMPmWszGN+nx2s9uSt4I/GXnbd1vFcGX4++w9QsgBtn0+rZYL21Ff+d cyDWYZqxw4+P1O3tjPAGLsmgcs260AqhAKYYYolTQO4Yp+Kk8FdYpUr5jligdUp3f+iy T0PIVQyqTVXBqN7pUfyFGzG5m47YFvxQIgbSgrtgdAIp52aTodxqR3PLnj3/iNQQIu/l /8/g== X-Gm-Message-State: AGi0PuaWpvPidtfT/9uCZwS7YMRgU8B3efnR6l5/XrWAZxbfEsKzh3Zt 9PoJ7ztcK6Rbp1rfQVs+Eh5x6jEoxwI= X-Google-Smtp-Source: APiQypLuKyMJkNoKQtdrPcj16j0GK8ziTaGQ4hq/X1PdMIkRE4TusKWiDazIBnQsGFbp4E36OjdSfg== X-Received: by 2002:a17:90a:1743:: with SMTP id 3mr11389559pjm.106.1587226767247; Sat, 18 Apr 2020 09:19:27 -0700 (PDT) Received: from localhost.localdomain (174-21-149-226.tukw.qwest.net. [174.21.149.226]) by smtp.gmail.com with ESMTPSA id i187sm22398382pfc.112.2020.04.18.09.19.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Apr 2020 09:19:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 08/16] tcg/optimize: Adjust TempOptInfo allocation Date: Sat, 18 Apr 2020 09:19:06 -0700 Message-Id: <20200418161914.4387-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200418161914.4387-1-richard.henderson@linaro.org> References: <20200418161914.4387-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::102a 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.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(-) 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]); } } -- 2.20.1