From nobody Tue Nov 18 15:26:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1611084997; cv=none; d=zohomail.com; s=zohoarc; b=LtxVPxjopsfKe1LIbVgQIo4beq4/RGwBLPq2hizH4E7IQ0yvxyAismAasfYLkdJr6X8tuHPSg5lr4XZWtae5gf9Q/olEYnAGcYsEWp+JW5rq6DWBXgr75xBZaw8nAPaYPMWbrdb85YobqOUJI1m/Mrfo5kRjj4MjluzvQBd1vnk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611084997; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Lb0UT912r2GMFw/dFnRGb/nKNqr4nsQ4gGmPTzEJSYY=; b=dLKPKvto/jdL9asJ2zEGHlX1R1BTwPe6NhYUBlQJhOZ3OCPQBqTqNN0wZKkqMNpxRDgzxra3GHLJ+IT7HEybymEj5PpvRWV+dczLTSQ8ITvgdTR2GHb+kU3VtPwqLRBTrDn89l+YSJmq3rrznqzgywu0wSCxi1cp9n+IC6/CQfc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1611084997892359.2148621667592; Tue, 19 Jan 2021 11:36:37 -0800 (PST) Received: from localhost ([::1]:41122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wns-0002mU-P3 for importer@patchew.org; Tue, 19 Jan 2021 14:36:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vpt-0002Yw-67 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:34:37 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:36237) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1vpr-0001Fe-2o for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:34:36 -0500 Received: by mail-pl1-x630.google.com with SMTP id e9so6849823plh.3 for ; Tue, 19 Jan 2021 10:34:34 -0800 (PST) Received: from localhost.localdomain (cpe-66-75-72-126.hawaii.res.rr.com. [66.75.72.126]) by smtp.gmail.com with ESMTPSA id a136sm20651359pfd.149.2021.01.19.10.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 10:34:33 -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=Lb0UT912r2GMFw/dFnRGb/nKNqr4nsQ4gGmPTzEJSYY=; b=AAQqhaRBRmkAucA1zbvkxQyFlt6CE4BV4cC6Uc9nJnaPWQ+3srAyGJyEQp8ulLSzmM JlUg/aXBp5mwwhXzDddV+79+6jbSkyooHy4QceB/dxPC7bawU1N80pYCa+oBx+wdC24B 1JbMLGlqb+z/UvCbJqjVFRnZcp4bk3DT4SPxjIHmt10aMY1ms/UegkjZ04E8PYCz4Rz+ V6NcJ+8Ef/sA5jTOsF5G58Dr/u/j75f33b5qLGJsKwGqCmfzbpkeJSLcCafmAktqGOJ/ GEu1MUA+ZNu01q1+tUPhD8+IMkoFyi6rqf0SP4tlzF4hkZvnW2cvBZ0+AGoR1JITRmDT t2nA== 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=Lb0UT912r2GMFw/dFnRGb/nKNqr4nsQ4gGmPTzEJSYY=; b=EnydheSkl+FX3z12oURM1WleYyn+PTS6xz0cPG6IjlSBD+4tGQ8hVU1QRlSo/gNQL3 InK9oKvyzLKar4KAImOicbEtQiI2Lp3JAhONO/gVxXAl0Xj3b2IlZfB1e7+Fasegmyss RXklByME9NdjQvvO+YSVk7zdbBguRVqlkc2gEUx7NMkBfN3MoDODb41NAjTWdN1R18i1 lYwskRWylFy2mnZbWGDVPbbW3JFUuhch8P4HOurcEw4FwJ5IuGWG1uLIeM1VLiW/Xrde N+agWfSXnpKBRc4sPJRNGMld07RFIgsiQDsPDeGk47sGUaMsC41x0XYjVW+zPTC753dU Y5Ew== X-Gm-Message-State: AOAM533ZoHymJuRUnSXQ6P+i8z/3++LKK46SqScQLmBgSynQ7h5odllV RRBLbJMsl/mEl2lRPv7oOY+h1QyHkHnXsQ== X-Google-Smtp-Source: ABdhPJym74nEAtQzlqxZV9lynZGgqc+heTYVtryceffxMxK4cvxZMxK+aNZUvMHehhNdBLsbDHV3PA== X-Received: by 2002:a17:90b:8d7:: with SMTP id ds23mr1120143pjb.116.1611081273549; Tue, 19 Jan 2021 10:34:33 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 1/5] tcg: Add an index to TCGTemp Date: Tue, 19 Jan 2021 08:34:24 -1000 Message-Id: <20210119183428.556706-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210119183428.556706-1-richard.henderson@linaro.org> References: <20210119183428.556706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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: lvivier@redhat.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This allows to break the tie between the memory location of TCGTemp and TCGContext->temps[]. Which is the first step to allowing the array to be reallocated. Signed-off-by: Richard Henderson Tested-by: BALATON Zoltan --- include/tcg/tcg.h | 5 ++--- tcg/tcg.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 504c5e9bb0..5ef644ceae 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -497,6 +497,7 @@ typedef enum TCGTempKind { } TCGTempKind; =20 typedef struct TCGTemp { + unsigned int index:16; TCGReg reg:8; TCGTempVal val_type:8; TCGType base_type:8; @@ -721,9 +722,7 @@ static inline void *tcg_splitwx_to_rw(const void *rx) =20 static inline size_t temp_idx(TCGTemp *ts) { - ptrdiff_t n =3D ts - tcg_ctx->temps; - tcg_debug_assert(n >=3D 0 && n < tcg_ctx->nb_temps); - return n; + return ts->index; } =20 static inline TCGArg temp_arg(TCGTemp *ts) diff --git a/tcg/tcg.c b/tcg/tcg.c index 8f8badb61c..4a8dfb8f67 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1204,11 +1204,17 @@ void tcg_func_start(TCGContext *s) QSIMPLEQ_INIT(&s->labels); } =20 -static inline TCGTemp *tcg_temp_alloc(TCGContext *s) +static TCGTemp *tcg_temp_alloc(TCGContext *s) { int n =3D s->nb_temps++; + TCGTemp *ret; + tcg_debug_assert(n < TCG_MAX_TEMPS); - return memset(&s->temps[n], 0, sizeof(TCGTemp)); + ret =3D &s->temps[n]; + memset(ret, 0, sizeof(TCGTemp)); + ret->index =3D n; + + return ret; } =20 static inline TCGTemp *tcg_global_alloc(TCGContext *s) --=20 2.25.1 From nobody Tue Nov 18 15:26:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1611083452; cv=none; d=zohomail.com; s=zohoarc; b=PDV4xSTDDLO2CYlIpf8R1PkHXKY3ddgRubH4nhW1zPOjv0RDdMTjdihBsRQlvGAp+qxeDMEFx6HE89iR9kHo++ekiGTDr8s62AWWQiHauLCXaFI+NpdN0npFF42W2F0AL5stJ6N134GQ8KFcgKOm3LTM6VxNHaUdU/CNuJVwi04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611083452; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0qp18WNANcXFrE2K7B3cvwfkNuDH1MH1NJQQgujUOMM=; b=XecFeEIfUvp5Wxg4iJ5hYC1Uq9oVG0nbSKqgUdnLowfIaiJAQDqwi3q1rKWukqM9IxuxQWByJxhvvRVBjrrPkeBJeFhaF8dYac1R6kAwxhjKE826j4CB/KIZD6EnlRRkLDwjJbjZU8YvcLaJmQmhk8afENdjjc7gt+fuPYcd3RU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1611083452652968.3491997928876; Tue, 19 Jan 2021 11:10:52 -0800 (PST) Received: from localhost ([::1]:51506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wOx-0007LZ-9M for importer@patchew.org; Tue, 19 Jan 2021 14:10:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vpv-0002cq-1P for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:34:39 -0500 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:37710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1vps-0001Fr-Ry for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:34:38 -0500 Received: by mail-pf1-x432.google.com with SMTP id 11so12779691pfu.4 for ; Tue, 19 Jan 2021 10:34:36 -0800 (PST) Received: from localhost.localdomain (cpe-66-75-72-126.hawaii.res.rr.com. [66.75.72.126]) by smtp.gmail.com with ESMTPSA id a136sm20651359pfd.149.2021.01.19.10.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 10:34:34 -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=0qp18WNANcXFrE2K7B3cvwfkNuDH1MH1NJQQgujUOMM=; b=EdEzdWi2DH3x63dyGo8z/aNiG2WgzCRPSLlTS8d6/5CBBzUY4bftTLkuviXxOue8PJ IuYP/bV7SwIKdwQB8JxcKPlHv+9ZiEa/Tz4jYkkvZwNjUTIROV9Uwo2DhGhZzrJWNLZA r/beu91lBo53BQBJCQk63dwyxskdfQ8mn2+pkbYYfF4VupazjzXfVxl/eZFnazBaE38o O6l40t78DKI2TVrOvJRo9UggwyJ5JMLmLH9ipyoVz+foOy9qqUPPzvjrQNueuk9ps7Qa xk7IPrUHKuAQMYKzxbYPYHa1r8GxWb8gsW2T3SnfJoWsnphKLEEMtnqGRlvHBgQHc5Mp EvgQ== 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=0qp18WNANcXFrE2K7B3cvwfkNuDH1MH1NJQQgujUOMM=; b=jUrDihDbqiAbgi3kzVSDNNgZ+AhDE0f40mtuIsUSbie7sjLrNrIQc+xbZ4tXExDOxO pGhX3o4y9p4572wyidwSj0Uix3FJ76tpNWweKFCBMpsp8CID1tdQXuAfifDptvMXeCvZ gCKpwKSQf7YuDnmQsyOnrwEM0jbMA7p74yl7HngoYJhHCQRYKEKLYx1Bs3HVeWNxJ6vJ LcWZNhipOmEW2YM9YaE5XeaBFpxqWCMQf3Ns4+W8WA3RiGRWjp+kexq+Eww9OAZqd69k H0qPzWp9c+hVXhOqNTOc/zPgCCsNurcuVJgUCe9bhRpRKZiSYQiyZzvWo852PRXngSaB IwyA== X-Gm-Message-State: AOAM532Io8zD2p3M9Dxn7pOAwDXvD4y2nBJQ4OYFBka+PVTh+BjqEjd6 zfdKslGSNkg3ESbCMlZOZmEtuAKTcEKgBA== X-Google-Smtp-Source: ABdhPJwSHV/y67zAtiiIoe8yhadT/nVU9ub5Bu1+BRkgCAF6jzUKYDoNyhZyUypnRiwO1sUxAPz6/w== X-Received: by 2002:a62:1d46:0:b029:1b7:fe6e:4bb4 with SMTP id d67-20020a621d460000b02901b7fe6e4bb4mr5560537pfd.4.1611081275247; Tue, 19 Jan 2021 10:34:35 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 2/5] tcg: Introduce and use tcg_temp Date: Tue, 19 Jan 2021 08:34:25 -1000 Message-Id: <20210119183428.556706-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210119183428.556706-1-richard.henderson@linaro.org> References: <20210119183428.556706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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: lvivier@redhat.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We're about to change the representation of the array of TCGTemps. Wrap the indexing into an inline to minimize changes later. Signed-off-by: Richard Henderson Tested-by: BALATON Zoltan --- include/tcg/tcg.h | 6 ++++ tcg/optimize.c | 5 ++-- tcg/tcg.c | 71 ++++++++++++++++++++++++++--------------------- 3 files changed, 48 insertions(+), 34 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 5ef644ceae..0d90701dcd 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -720,6 +720,12 @@ static inline void *tcg_splitwx_to_rw(const void *rx) } #endif =20 +static inline TCGTemp *tcg_temp(TCGContext *s, size_t idx) +{ + tcg_debug_assert(idx < s->nb_temps); + return &s->temps[idx]; +} + static inline size_t temp_idx(TCGTemp *ts) { return ts->index; diff --git a/tcg/optimize.c b/tcg/optimize.c index 37c902283e..2aa491605e 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -614,7 +614,8 @@ void tcg_optimize(TCGContext *s) =20 memset(&temps_used, 0, sizeof(temps_used)); for (i =3D 0; i < nb_temps; ++i) { - s->temps[i].state_ptr =3D NULL; + TCGTemp *ts =3D tcg_temp(s, i); + ts->state_ptr =3D NULL; } =20 QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) { @@ -1485,7 +1486,7 @@ void tcg_optimize(TCGContext *s) & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS)= )) { for (i =3D 0; i < nb_globals; i++) { if (test_bit(i, temps_used.l)) { - reset_ts(&s->temps[i]); + reset_ts(tcg_temp(s, i)); } } } diff --git a/tcg/tcg.c b/tcg/tcg.c index 4a8dfb8f67..7284209cff 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -824,10 +824,10 @@ void tcg_register_thread(void) =20 /* Relink mem_base. */ for (i =3D 0, n =3D tcg_init_ctx.nb_globals; i < n; ++i) { - if (tcg_init_ctx.temps[i].mem_base) { - ptrdiff_t b =3D tcg_init_ctx.temps[i].mem_base - tcg_init_ctx.= temps; - tcg_debug_assert(b >=3D 0 && b < n); - s->temps[i].mem_base =3D &s->temps[b]; + TCGTemp *its =3D tcg_temp(&tcg_init_ctx, i); + if (its->mem_base) { + TCGTemp *ots =3D tcg_temp(s, i); + ots->mem_base =3D tcg_temp(s, temp_idx(its->mem_base)); } } =20 @@ -1332,7 +1332,7 @@ TCGTemp *tcg_temp_new_internal(TCGType type, bool tem= p_local) /* There is already an available temp with the right type. */ clear_bit(idx, s->free_temps[k].l); =20 - ts =3D &s->temps[idx]; + ts =3D tcg_temp(s, idx); ts->temp_allocated =3D 1; tcg_debug_assert(ts->base_type =3D=3D type); tcg_debug_assert(ts->kind =3D=3D kind); @@ -2016,7 +2016,7 @@ static void tcg_reg_alloc_start(TCGContext *s) int i, n; =20 for (i =3D 0, n =3D s->nb_temps; i < n; i++) { - TCGTemp *ts =3D &s->temps[i]; + TCGTemp *ts =3D tcg_temp(s, i); TCGTempVal val =3D TEMP_VAL_MEM; =20 switch (ts->kind) { @@ -2654,12 +2654,14 @@ static void la_func_end(TCGContext *s, int ng, int = nt) int i; =20 for (i =3D 0; i < ng; ++i) { - s->temps[i].state =3D TS_DEAD | TS_MEM; - la_reset_pref(&s->temps[i]); + TCGTemp *ts =3D tcg_temp(s, i); + ts->state =3D TS_DEAD | TS_MEM; + la_reset_pref(ts); } for (i =3D ng; i < nt; ++i) { - s->temps[i].state =3D TS_DEAD; - la_reset_pref(&s->temps[i]); + TCGTemp *ts =3D tcg_temp(s, i); + ts->state =3D TS_DEAD; + la_reset_pref(ts); } } =20 @@ -2670,7 +2672,7 @@ static void la_bb_end(TCGContext *s, int ng, int nt) int i; =20 for (i =3D 0; i < nt; ++i) { - TCGTemp *ts =3D &s->temps[i]; + TCGTemp *ts =3D tcg_temp(s, i); int state; =20 switch (ts->kind) { @@ -2697,11 +2699,13 @@ static void la_global_sync(TCGContext *s, int ng) int i; =20 for (i =3D 0; i < ng; ++i) { - int state =3D s->temps[i].state; - s->temps[i].state =3D state | TS_MEM; + TCGTemp *ts =3D tcg_temp(s, i); + int state =3D ts->state; + + ts->state =3D state | TS_MEM; if (state =3D=3D TS_DEAD) { /* If the global was previously dead, reset prefs. */ - la_reset_pref(&s->temps[i]); + la_reset_pref(ts); } } } @@ -2715,7 +2719,7 @@ static void la_bb_sync(TCGContext *s, int ng, int nt) la_global_sync(s, ng); =20 for (int i =3D ng; i < nt; ++i) { - TCGTemp *ts =3D &s->temps[i]; + TCGTemp *ts =3D tcg_temp(s, i); int state; =20 switch (ts->kind) { @@ -2727,14 +2731,14 @@ static void la_bb_sync(TCGContext *s, int ng, int n= t) } break; case TEMP_NORMAL: - s->temps[i].state =3D TS_DEAD; + ts->state =3D TS_DEAD; break; case TEMP_CONST: continue; default: g_assert_not_reached(); } - la_reset_pref(&s->temps[i]); + la_reset_pref(ts); } } =20 @@ -2744,8 +2748,9 @@ static void la_global_kill(TCGContext *s, int ng) int i; =20 for (i =3D 0; i < ng; i++) { - s->temps[i].state =3D TS_DEAD | TS_MEM; - la_reset_pref(&s->temps[i]); + TCGTemp *ts =3D tcg_temp(s, i); + ts->state =3D TS_DEAD | TS_MEM; + la_reset_pref(ts); } } =20 @@ -2756,7 +2761,8 @@ static void la_cross_call(TCGContext *s, int nt) int i; =20 for (i =3D 0; i < nt; i++) { - TCGTemp *ts =3D &s->temps[i]; + TCGTemp *ts =3D tcg_temp(s, i); + if (!(ts->state & TS_DEAD)) { TCGRegSet *pset =3D la_temp_pref(ts); TCGRegSet set =3D *pset; @@ -2784,7 +2790,8 @@ static void liveness_pass_1(TCGContext *s) =20 prefs =3D tcg_malloc(sizeof(TCGRegSet) * nb_temps); for (i =3D 0; i < nb_temps; ++i) { - s->temps[i].state_ptr =3D prefs + i; + TCGTemp *ts =3D tcg_temp(s, i); + ts->state_ptr =3D prefs + i; } =20 /* ??? Should be redundant with the exit_tb that ends the TB. */ @@ -3094,7 +3101,7 @@ static bool liveness_pass_2(TCGContext *s) =20 /* Create a temporary for each indirect global. */ for (i =3D 0; i < nb_globals; ++i) { - TCGTemp *its =3D &s->temps[i]; + TCGTemp *its =3D tcg_temp(s, i); if (its->indirect_reg) { TCGTemp *dts =3D tcg_temp_alloc(s); dts->type =3D its->type; @@ -3107,7 +3114,7 @@ static bool liveness_pass_2(TCGContext *s) its->state =3D TS_DEAD; } for (nb_temps =3D s->nb_temps; i < nb_temps; ++i) { - TCGTemp *its =3D &s->temps[i]; + TCGTemp *its =3D tcg_temp(s, i); its->state_ptr =3D NULL; its->state =3D TS_DEAD; } @@ -3190,7 +3197,7 @@ static bool liveness_pass_2(TCGContext *s) for (i =3D 0; i < nb_globals; ++i) { /* Liveness should see that globals are synced back, that is, either TS_DEAD or TS_MEM. */ - arg_ts =3D &s->temps[i]; + arg_ts =3D tcg_temp(s, i); tcg_debug_assert(arg_ts->state_ptr =3D=3D 0 || arg_ts->state !=3D 0); } @@ -3198,7 +3205,7 @@ static bool liveness_pass_2(TCGContext *s) for (i =3D 0; i < nb_globals; ++i) { /* Liveness should see that globals are saved back, that is, TS_DEAD, waiting to be reloaded. */ - arg_ts =3D &s->temps[i]; + arg_ts =3D tcg_temp(s, i); tcg_debug_assert(arg_ts->state_ptr =3D=3D 0 || arg_ts->state =3D=3D TS_DEAD); } @@ -3277,12 +3284,11 @@ static bool liveness_pass_2(TCGContext *s) #ifdef CONFIG_DEBUG_TCG static void dump_regs(TCGContext *s) { - TCGTemp *ts; int i; char buf[64]; =20 for(i =3D 0; i < s->nb_temps; i++) { - ts =3D &s->temps[i]; + TCGTemp *ts =3D tcg_temp(s, i); printf(" %10s: ", tcg_get_arg_str_ptr(s, buf, sizeof(buf), ts)); switch(ts->val_type) { case TEMP_VAL_REG: @@ -3332,7 +3338,7 @@ static void check_regs(TCGContext *s) } } for (k =3D 0; k < s->nb_temps; k++) { - ts =3D &s->temps[k]; + ts =3D tcg_temp(s, k); if (ts->val_type =3D=3D TEMP_VAL_REG && ts->kind !=3D TEMP_FIXED && s->reg_to_temp[ts->reg] !=3D ts) { @@ -3594,7 +3600,7 @@ static void save_globals(TCGContext *s, TCGRegSet all= ocated_regs) int i, n; =20 for (i =3D 0, n =3D s->nb_globals; i < n; i++) { - temp_save(s, &s->temps[i], allocated_regs); + temp_save(s, tcg_temp(s, i), allocated_regs); } } =20 @@ -3606,7 +3612,7 @@ static void sync_globals(TCGContext *s, TCGRegSet all= ocated_regs) int i, n; =20 for (i =3D 0, n =3D s->nb_globals; i < n; i++) { - TCGTemp *ts =3D &s->temps[i]; + TCGTemp *ts =3D tcg_temp(s, i); tcg_debug_assert(ts->val_type !=3D TEMP_VAL_REG || ts->kind =3D=3D TEMP_FIXED || ts->mem_coherent); @@ -3620,7 +3626,7 @@ static void tcg_reg_alloc_bb_end(TCGContext *s, TCGRe= gSet allocated_regs) int i; =20 for (i =3D s->nb_globals; i < s->nb_temps; i++) { - TCGTemp *ts =3D &s->temps[i]; + TCGTemp *ts =3D tcg_temp(s, i); =20 switch (ts->kind) { case TEMP_LOCAL: @@ -3652,7 +3658,8 @@ static void tcg_reg_alloc_cbranch(TCGContext *s, TCGR= egSet allocated_regs) sync_globals(s, allocated_regs); =20 for (int i =3D s->nb_globals; i < s->nb_temps; i++) { - TCGTemp *ts =3D &s->temps[i]; + TCGTemp *ts =3D tcg_temp(s, i); + /* * The liveness analysis already ensures that temps are dead. * Keep tcg_debug_asserts for safety. --=20 2.25.1 From nobody Tue Nov 18 15:26:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1611083750; cv=none; d=zohomail.com; s=zohoarc; b=f1p+t7F37q7/JlVMOTILVvdCdYyPyIP0BSQlGoCHr7YKGnGh0I60U88AA8AHecTM+AaAB7rE8x96HJxsuW0g02H2UDtmk9gaPj67C2iAOr1bkWanV6+5suOcjj5iXkZ3WclMtIVIfixrOEiyrURzqT7iAakiPeS7vS0QHynaqqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611083750; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zocLtIhc1566xSbUUG3fVWgPSfFwYEU16pDGR5baprU=; b=TaGTEDq03D+f96/EGwdrYeV3kPCSdRt3Ztr0QegaP3aEIVKgd6hxkfkipL2xvIbXho6olV1C1PG1odMdIq3L8X6CNZxiRZcSFkjdEnJh6ZigWEci5WuAPMujwFpuVjT366/I4C3ua+Oq96/cgdEOl267KMw51dT81VJ/y26wFpI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1611083750276850.4158184874732; Tue, 19 Jan 2021 11:15:50 -0800 (PST) Received: from localhost ([::1]:57616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wTk-0001dE-VK for importer@patchew.org; Tue, 19 Jan 2021 14:15:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vpw-0002gK-K5 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:34:40 -0500 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:46236) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1vpu-0001GA-IV for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:34:40 -0500 Received: by mail-pg1-x52c.google.com with SMTP id c22so13447746pgg.13 for ; Tue, 19 Jan 2021 10:34:38 -0800 (PST) Received: from localhost.localdomain (cpe-66-75-72-126.hawaii.res.rr.com. [66.75.72.126]) by smtp.gmail.com with ESMTPSA id a136sm20651359pfd.149.2021.01.19.10.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 10:34:36 -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=zocLtIhc1566xSbUUG3fVWgPSfFwYEU16pDGR5baprU=; b=CUbXQvskoLgMtVjz9NeSFfUaOm7HyNG1AvGIPFigdXfCJkY8D1HgMmUNfZ8lAbmZzY eNAStYP7Q4csk0cSG27nR8zgME4rVDtVcZSA/RtXpFLOhNlYRbqKPGiobTiNynpDuZTI /4QIGw0LOtcX0qKuT7nWMpqaD+akxb+9NVguw4VRI4GcvZepMqX9G4issv6RDtsDa2ch kL6u/2GVBm6MvUisDUjfHy0nyu4x/QSZ8R+F4s4iDKirEEodPc1s6W5s2QL0wC7EmK3B SrAw44IXkriC+Xmg/Q4L5agaYJM9Ehzh5e0wcLAJFNCZBosTw4Sq3bcqpF4+3q4+VUss xfdA== 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=zocLtIhc1566xSbUUG3fVWgPSfFwYEU16pDGR5baprU=; b=Y2oUNlnaRwvMz8LpiLaF7FBeBmihEtVPaor+3y9Xc6aoyvlWl79xd2xCHYXWyQFTvA i9ueXLWA2n5YbqfJ65yTZaRi3puwApjMNhpRDmyCs0bLy53MSifzhG10v3A/nB6winUv BlrH8L5sFHZuhiIl2W2c6RC3Z859EiDp0i0yVUFH944TZ60uuoMwahWsqDBm+6AIiww7 0dfZIPbP03GRyhY2X1zeKWj0Crbxq1dcSX4ZWFyj6ppZr1roG1VvZr/oMM60AWIiMKGG QxFBJ39R2PvYTqWWHs+c9h/nTCMtgRv0mg712eKOsupRdscWbqySHKRYH3NYNhyjvaMK 6zRg== X-Gm-Message-State: AOAM533QSReAhh7gqq46zx64rB9h7q8JQTHPxCLwSGWMpX41Gc91Usuk +hzIuBZSbb/OwSkeh9mZGKB9mKXuDS7Czg== X-Google-Smtp-Source: ABdhPJwWXMl9xBuRlY3xjo9yFV6STgaX8ZJC0CEBymUjpdkqiBU17rKO9FZ5NoTn5trlu2V71cJyRQ== X-Received: by 2002:a62:7fc1:0:b029:19f:1dab:5029 with SMTP id a184-20020a627fc10000b029019f1dab5029mr5324708pfd.13.1611081277012; Tue, 19 Jan 2021 10:34:37 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 3/5] tcg: Make TCGTempSet expandable Date: Tue, 19 Jan 2021 08:34:26 -1000 Message-Id: <20210119183428.556706-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210119183428.556706-1-richard.henderson@linaro.org> References: <20210119183428.556706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.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: lvivier@redhat.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Introduce a complete set of operations on TCGTempSet, and do not directly call functions. Expand the array as necessary on SET. Use the tcg allocation pool so that we do not have to worry about explicitly freeing the array. Signed-off-by: Richard Henderson Tested-by: BALATON Zoltan --- include/tcg/tcg.h | 28 +++++++++++++++++++++++++- tcg/optimize.c | 18 ++++++++--------- tcg/tcg.c | 51 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 80 insertions(+), 17 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 0d90701dcd..4d001fed39 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -524,9 +524,35 @@ typedef struct TCGTemp { typedef struct TCGContext TCGContext; =20 typedef struct TCGTempSet { - unsigned long l[BITS_TO_LONGS(TCG_MAX_TEMPS)]; + unsigned long *data; + size_t word_len; } TCGTempSet; =20 +void tempset_init(TCGTempSet *set, size_t len); +bool tempset_find_first(const TCGTempSet *set, size_t *i); +void tempset_set(TCGTempSet *set, size_t i); + +static inline void tempset_clear_all(TCGTempSet *set) +{ + memset(set->data, 0, set->word_len * sizeof(unsigned long)); +} + +static inline void tempset_clear(TCGTempSet *set, size_t i) +{ + size_t l =3D i / BITS_PER_LONG; + size_t b =3D i % BITS_PER_LONG; + if (likely(l < set->word_len)) { + set->data[l] &=3D ~BIT(b); + } +} + +static inline bool tempset_test(const TCGTempSet *set, size_t i) +{ + size_t l =3D i / BITS_PER_LONG; + size_t b =3D i % BITS_PER_LONG; + return l < set->word_len && (set->data[l] & BIT(b)); +} + /* While we limit helpers to 6 arguments, for 32-bit hosts, with padding, this imples a max of 6*2 (64-bit in) + 2 (64-bit out) =3D 14 operands. There are never more than 2 outputs, which means that we can store all diff --git a/tcg/optimize.c b/tcg/optimize.c index 2aa491605e..b0ecef1fb6 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -94,10 +94,10 @@ static void init_ts_info(TCGTempSet *temps_used, TCGTem= p *ts) size_t idx =3D temp_idx(ts); TempOptInfo *ti; =20 - if (test_bit(idx, temps_used->l)) { + if (tempset_test(temps_used, idx)) { return; } - set_bit(idx, temps_used->l); + tempset_set(temps_used, idx); =20 ti =3D ts->state_ptr; if (ti =3D=3D NULL) { @@ -612,7 +612,7 @@ void tcg_optimize(TCGContext *s) nb_temps =3D s->nb_temps; nb_globals =3D s->nb_globals; =20 - memset(&temps_used, 0, sizeof(temps_used)); + tempset_init(&temps_used, nb_temps); for (i =3D 0; i < nb_temps; ++i) { TCGTemp *ts =3D tcg_temp(s, i); ts->state_ptr =3D NULL; @@ -1254,7 +1254,7 @@ void tcg_optimize(TCGContext *s) op->args[1], op->args[2]); if (tmp !=3D 2) { if (tmp) { - memset(&temps_used, 0, sizeof(temps_used)); + tempset_clear_all(&temps_used); op->opc =3D INDEX_op_br; op->args[0] =3D op->args[3]; } else { @@ -1338,7 +1338,7 @@ void tcg_optimize(TCGContext *s) if (tmp !=3D 2) { if (tmp) { do_brcond_true: - memset(&temps_used, 0, sizeof(temps_used)); + tempset_clear_all(&temps_used); op->opc =3D INDEX_op_br; op->args[0] =3D op->args[5]; } else { @@ -1354,7 +1354,7 @@ void tcg_optimize(TCGContext *s) /* Simplify LT/GE comparisons vs zero to a single compare vs the high word of the input. */ do_brcond_high: - memset(&temps_used, 0, sizeof(temps_used)); + tempset_clear_all(&temps_used); op->opc =3D INDEX_op_brcond_i32; op->args[0] =3D op->args[1]; op->args[1] =3D op->args[3]; @@ -1380,7 +1380,7 @@ void tcg_optimize(TCGContext *s) goto do_default; } do_brcond_low: - memset(&temps_used, 0, sizeof(temps_used)); + tempset_clear_all(&temps_used); op->opc =3D INDEX_op_brcond_i32; op->args[1] =3D op->args[2]; op->args[2] =3D op->args[4]; @@ -1485,7 +1485,7 @@ void tcg_optimize(TCGContext *s) if (!(op->args[nb_oargs + nb_iargs + 1] & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS)= )) { for (i =3D 0; i < nb_globals; i++) { - if (test_bit(i, temps_used.l)) { + if (tempset_test(&temps_used, i)) { reset_ts(tcg_temp(s, i)); } } @@ -1500,7 +1500,7 @@ void tcg_optimize(TCGContext *s) block, otherwise we only trash the output args. "mask" is the non-zero bits mask for the first output arg. */ if (def->flags & TCG_OPF_BB_END) { - memset(&temps_used, 0, sizeof(temps_used)); + tempset_clear_all(&temps_used); } else { do_reset_output: for (i =3D 0; i < nb_oargs; i++) { diff --git a/tcg/tcg.c b/tcg/tcg.c index 7284209cff..a505457cee 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1182,7 +1182,9 @@ void tcg_func_start(TCGContext *s) s->nb_temps =3D s->nb_globals; =20 /* No temps have been previously allocated for size or locality. */ - memset(s->free_temps, 0, sizeof(s->free_temps)); + for (int i =3D 0; i < ARRAY_SIZE(s->free_temps); ++i) { + tempset_init(&s->free_temps[i], TCG_MAX_TEMPS); + } =20 /* No constant temps have been previously allocated. */ for (int i =3D 0; i < TCG_TYPE_COUNT; ++i) { @@ -1324,13 +1326,12 @@ TCGTemp *tcg_temp_new_internal(TCGType type, bool t= emp_local) TCGContext *s =3D tcg_ctx; TCGTempKind kind =3D temp_local ? TEMP_LOCAL : TEMP_NORMAL; TCGTemp *ts; - int idx, k; + size_t idx, k; =20 k =3D type + (temp_local ? TCG_TYPE_COUNT : 0); - idx =3D find_first_bit(s->free_temps[k].l, TCG_MAX_TEMPS); - if (idx < TCG_MAX_TEMPS) { + if (tempset_find_first(&s->free_temps[k], &idx)) { /* There is already an available temp with the right type. */ - clear_bit(idx, s->free_temps[k].l); + tempset_clear(&s->free_temps[k], idx); =20 ts =3D tcg_temp(s, idx); ts->temp_allocated =3D 1; @@ -1403,7 +1404,7 @@ TCGv_vec tcg_temp_new_vec_matching(TCGv_vec match) void tcg_temp_free_internal(TCGTemp *ts) { TCGContext *s =3D tcg_ctx; - int k, idx; + size_t k, idx; =20 /* In order to simplify users of tcg_constant_*, silently ignore free.= */ if (ts->kind =3D=3D TEMP_CONST) { @@ -1423,7 +1424,7 @@ void tcg_temp_free_internal(TCGTemp *ts) =20 idx =3D temp_idx(ts); k =3D ts->base_type + (ts->kind =3D=3D TEMP_NORMAL ? 0 : TCG_TYPE_COUN= T); - set_bit(idx, s->free_temps[k].l); + tempset_set(&s->free_temps[k], idx); } =20 TCGTemp *tcg_constant_internal(TCGType type, int64_t val) @@ -4665,6 +4666,42 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) return tcg_current_code_size(s); } =20 +void tempset_init(TCGTempSet *set, size_t len) +{ + size_t word_len =3D BITS_TO_LONGS(len); + + set->word_len =3D word_len; + set->data =3D tcg_malloc(word_len * sizeof(unsigned long)); + memset(set->data, 0, word_len * sizeof(unsigned long)); +} + +void tempset_set(TCGTempSet *set, size_t i) +{ + size_t l =3D i / BITS_PER_LONG; + size_t b =3D i % BITS_PER_LONG; + + if (l >=3D set->word_len) { + size_t old_blen =3D set->word_len * sizeof(unsigned long); + size_t new_wlen =3D set->word_len * 2; + unsigned long *new_data =3D tcg_malloc(old_blen * 2); + + memcpy(new_data, set->data, old_blen); + memset((char *)new_data + old_blen, 0, old_blen); + + set->data =3D new_data; + set->word_len =3D new_wlen; + } + set->data[l] |=3D BIT(b); +} + +bool tempset_find_first(const TCGTempSet *set, size_t *i) +{ + size_t max =3D set->word_len * BITS_PER_LONG; + size_t ret =3D find_first_bit(set->data, max); + *i =3D ret; + return ret < max; +} + #ifdef CONFIG_PROFILER void tcg_dump_info(void) { --=20 2.25.1 From nobody Tue Nov 18 15:26:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1611085184; cv=none; d=zohomail.com; s=zohoarc; b=TZ5/J01cX4vo/dNc+egvvxj/iUQ/GfqX8m9RLV/OzVcQD0C09NiSC55Vc+irMa4GPO/zDfIYHh8/1j+KEE0fr2FzOuwArh+DXt/n+cfXi6ToLvfna4F1w3pQPteUNgHb9JiA9EoF/OcSIY/BLWiXG7LhPaSQZj8DhIxAeWU4xYw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611085184; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jyybQjiFDPMiQ/WR1CPOwhtb/3DBjHCNWIqS94AKGQU=; b=HZzESAxlSelHgE9y8YTZP2d3lp2pHzmC+jlAwTFyUuG8BnnpUjhlILCOEHaaTuImDpXdGorc52cXnCgbBYHfigZGlPFKLymdph9nx4BlhFIXMDHnOxpgSasQBLKzAxUzbTrSEziEOTEeoGUHV4XLlfqJGvdLeVvXN3aOBr2mGx0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1611085184425839.6680929504001; Tue, 19 Jan 2021 11:39:44 -0800 (PST) Received: from localhost ([::1]:49890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wqt-0006kQ-7Z for importer@patchew.org; Tue, 19 Jan 2021 14:39:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vpx-0002iE-IE for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:34:41 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:45818) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1vpv-0001GR-TB for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:34:41 -0500 Received: by mail-pl1-x634.google.com with SMTP id b8so10996807plh.12 for ; Tue, 19 Jan 2021 10:34:39 -0800 (PST) Received: from localhost.localdomain (cpe-66-75-72-126.hawaii.res.rr.com. [66.75.72.126]) by smtp.gmail.com with ESMTPSA id a136sm20651359pfd.149.2021.01.19.10.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 10:34:38 -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=jyybQjiFDPMiQ/WR1CPOwhtb/3DBjHCNWIqS94AKGQU=; b=mlnPAlxF+QMsUe2tvcfgE/6Fp8U9beg1EWAgYVXFRqyH4PF7MEtHALAOkvFTUkI4hC KLY2P0D3DXlDwdYQStDmt4RvGkqYzU83wiuhxtolrIwHj3rRSJ0dRPq+qgucJB2roH0O QFfAko9NFBd0TVrUAb3QkBUJMqx2yUR69TxWZq1hOxW+20TThM4toN5xOM6TwHTcUgjy p0FOjRRaYWGaLuMYfl9Z/EAY9LDpkhIzi9Lwcmf87Ug30kC2Mjq9BbXD857vNee+kGtA t0wUyYPAC+XlYnIFVswGKJuPbUQH/7ERaLoePD2YNN10om7Ng+HtW66W4n0DtB0FRsDq AnKg== 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=jyybQjiFDPMiQ/WR1CPOwhtb/3DBjHCNWIqS94AKGQU=; b=Tpa4W2plXm7yoPgcFdugawqisZp6qsKxS8LwplDUmXEFIPIyz5zVEAFEoxkLgepyxM qgI7Zzv63M971GZOLG2KEH6/m/mbq+D6+EUMYzs3hV2r5zeJ1DzdIBgEJte5ZfBQHu8v eXUkfdtDlUa0HYIaAL4uUmHT2MGBAUKhKFfZNMl3DUxJAmrGhXOub6q1OjhhCr+7oIB+ hYE70UfMBQFRsgXcPB31UVTJyLXE/S4ANtpwPBx8TbAgihj+Mfu4g79bkhjCyGs56cYs llMDaPDyca33jd0ZCVVvd/J6m2ObEbDSKXM5e3SvdRC6YKH6QnJC+9ch+UEdXqB0Erfs 1guQ== X-Gm-Message-State: AOAM5333UBONVoNhJU/NXXyMb6hCV/Xxj+Pdqw0khF9e56jEtKb/xmTh pJ9rSeaMNg6inM/c/WOBeux/bnkLFQn+8g== X-Google-Smtp-Source: ABdhPJyi6/RhqAtUI+Vn2Qfg2jmvtYCVJwe2+9v9MlcFj1DNXbJ3VBLgE4jozQgNm0QWqfBLmBryVA== X-Received: by 2002:a17:90a:9414:: with SMTP id r20mr1072743pjo.222.1611081278645; Tue, 19 Jan 2021 10:34:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 4/5] tcg: Adjust tcgv_*_temp/temp_tcgv_* Date: Tue, 19 Jan 2021 08:34:27 -1000 Message-Id: <20210119183428.556706-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210119183428.556706-1-richard.henderson@linaro.org> References: <20210119183428.556706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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: lvivier@redhat.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Encode the index of the temporary within the "pointer" rather than its offset. This breaks a tie with a statically allocated array of temps. Signed-off-by: Richard Henderson Tested-by: BALATON Zoltan --- include/tcg/tcg.h | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 4d001fed39..996addd90c 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -757,6 +757,11 @@ static inline size_t temp_idx(TCGTemp *ts) return ts->index; } =20 +/* + * TCGArg is a convenience for TCGOps, and never exist outside of + * code generation with a specific TCGContext. Simply store the + * pointer value within the TCGArg. + */ static inline TCGArg temp_arg(TCGTemp *ts) { return (uintptr_t)ts; @@ -767,15 +772,15 @@ static inline TCGTemp *arg_temp(TCGArg a) return (TCGTemp *)(uintptr_t)a; } =20 -/* Using the offset of a temporary, relative to TCGContext, rather than - its index means that we don't use 0. That leaves offset 0 free for - a NULL representation without having to leave index 0 unused. */ +/* + * TCGv_{i32,i64,ptr,vec} must be independent of TCGContext, + * so that the globals that we allocate at startup are valid for + * the thread-specfic TCGContext when we generate code. + * Reserve 0 for NULL, and use the temp index + 1 otherwise. + */ static inline TCGTemp *tcgv_i32_temp(TCGv_i32 v) { - uintptr_t o =3D (uintptr_t)v; - TCGTemp *t =3D (void *)tcg_ctx + o; - tcg_debug_assert(offsetof(TCGContext, temps[temp_idx(t)]) =3D=3D o); - return t; + return v ? tcg_temp(tcg_ctx, (uintptr_t)v - 1) : NULL; } =20 static inline TCGTemp *tcgv_i64_temp(TCGv_i64 v) @@ -815,8 +820,7 @@ static inline TCGArg tcgv_vec_arg(TCGv_vec v) =20 static inline TCGv_i32 temp_tcgv_i32(TCGTemp *t) { - (void)temp_idx(t); /* trigger embedded assert */ - return (TCGv_i32)((void *)t - (void *)tcg_ctx); + return (TCGv_i32)(t ? (uintptr_t)temp_idx(t) + 1 : 0); } =20 static inline TCGv_i64 temp_tcgv_i64(TCGTemp *t) @@ -837,12 +841,20 @@ static inline TCGv_vec temp_tcgv_vec(TCGTemp *t) #if TCG_TARGET_REG_BITS =3D=3D 32 static inline TCGv_i32 TCGV_LOW(TCGv_i64 t) { - return temp_tcgv_i32(tcgv_i64_temp(t)); + /* + * The 64-bit value is a pair of TCGv_i32, with the low part at index = 0. + * Since we're encoding the index in @t, pass it through unchanged. + */ + return (TCGv_i32)t; } =20 static inline TCGv_i32 TCGV_HIGH(TCGv_i64 t) { - return temp_tcgv_i32(tcgv_i64_temp(t) + 1); + /* + * The 64-bit value is a pair of TCGv_i32, with the high part at index= 1. + * Since we're encoding the index in @t, add one. + */ + return (TCGv_i32)((uintptr_t)t + 1); } #endif =20 --=20 2.25.1 From nobody Tue Nov 18 15:26:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1611084897; cv=none; d=zohomail.com; s=zohoarc; b=KD0BctihK2bA5+7afRnwQ+LYkMI6AfB0ZoQEsXU5JaA/yJnVCafu33QBF95xSBbh2EmDv75jWRZ74K1rSpy6O4URCBUSODM8/VZt4zRLptmoB86K0UfAOkz1n2Fm9gERQV1VrzDBkXsPqJVry9xvB5s0E3u9yQuDkiKiPcuCoLM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611084897; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zOwDuzEJMzDZCUyUS+fhCAa4pwhGVLCD5TGZAxSX0pU=; b=TluwMKp5CTEBdqhHpYTrW6r91FEgoYXBzGviicay1AZwbmSm9HjwxZ9YQ/nti4ELylzyTWrwbe97d2WzsyA22QIvfuxRjgfsLlc6jpGHTN6B06TfeiQHKu2vXu+EAPsR3vmW4avtdo2sBjx2o1v2cinx7Xz3oCY4nLh9GvpbhA8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1611084897130637.1562415274094; Tue, 19 Jan 2021 11:34:57 -0800 (PST) Received: from localhost ([::1]:37898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wmF-0001Hz-In for importer@patchew.org; Tue, 19 Jan 2021 14:34:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vq0-0002oD-5f for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:34:44 -0500 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:33024) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1vpx-0001Gh-TP for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:34:43 -0500 Received: by mail-pj1-x1032.google.com with SMTP id lw17so1807767pjb.0 for ; Tue, 19 Jan 2021 10:34:41 -0800 (PST) Received: from localhost.localdomain (cpe-66-75-72-126.hawaii.res.rr.com. [66.75.72.126]) by smtp.gmail.com with ESMTPSA id a136sm20651359pfd.149.2021.01.19.10.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 10:34:39 -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=zOwDuzEJMzDZCUyUS+fhCAa4pwhGVLCD5TGZAxSX0pU=; b=rzOUb5ZF/eVr/EnXqI9R72RKraBsGeZqOyoR/rU9u2X8ly60Q9BAnoyHgml96LeAIt lBDiwsL9OOD1U/UuUAseHZRwSq4Aqd9wo9vgjngsDoffnIRtsoVZEOEVCUR0dmeELEYp AtN0+8p+5GACoNhThUBy+a2ygZ8vnQSCTAFxWijvsbTI8I1Um4Z9Ndl+mlhzt7As/ZNS pkmGXT7b6oZR1lcy5whsiVWFQ07q5GK0kow0DMbjZI6wdec+vpBe/9uQU3Qlkmx0pcvh w44aHeBAtWytcKPjeF9xWsl5RduY1eneQ1Md4ZtH4avSIGFJ+Bkppt9MgGrv3MG6+IXU 5JcQ== 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=zOwDuzEJMzDZCUyUS+fhCAa4pwhGVLCD5TGZAxSX0pU=; b=iTLZeJmGb2280U7YB9dFzZpzDt9mlvFOEIu2GjFqQpUY2GnuE6+AIMPhDwA4eFu/Wa pxJC8IjewbJ05/iKIa6KYhkRNna7JxOYmLQ9SMjamSFSGB+XzXGlMYqvZ6Q0Zyc8jlbf uqlh7BLEJY3A7j9qXEc8U/VKWW2gZ2YD9Vwgt5bRlSkU4MUtRaZCqUXiQT1qsWdifm7h sc3Wdr81bU1DzXnRnUYI5ILCiTOj4W/sly2EX/dYjulo9R9dNBoy2YEWWbgPCWyBSzGY Q+E47CIVwzInVcJUTe8gA5fnDc5OOiKLjngq/P9HxUSvuHuplHQYae7bmErHIpnJgwIQ w9Eg== X-Gm-Message-State: AOAM532YhYVh4xw5FdNhxw9UgmTlLdAWtkxwHXS/jnCYJ+fcA+qgD+Ab bQ92xOpey385HOpSWvP27OcxQW06CYV6aA== X-Google-Smtp-Source: ABdhPJw9yoU5YlYF41miGrl9hFEQV05YtavaRu2k31e7V5sNcp8q9LjMU2UM5pbP9GnHp4UfDnDYRA== X-Received: by 2002:a17:90a:2e88:: with SMTP id r8mr1151552pjd.84.1611081280372; Tue, 19 Jan 2021 10:34:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 5/5] tcg: Dynamically allocate temporaries Date: Tue, 19 Jan 2021 08:34:28 -1000 Message-Id: <20210119183428.556706-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210119183428.556706-1-richard.henderson@linaro.org> References: <20210119183428.556706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.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: lvivier@redhat.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The caching of constant temps has resulted in a larger overall usage, overflowing the statically allocated array. Instead, allocate temps as needed, placing pointers to the allocated temps into a GPtrArray for later indexing. Buglink: https://bugs.launchpad.net/bugs/1912065 Signed-off-by: Richard Henderson Tested-by: BALATON Zoltan --- include/tcg/tcg.h | 6 ++-- tcg/tcg.c | 74 +++++++++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 996addd90c..1da3bce0c8 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -275,7 +275,7 @@ typedef struct TCGPool { =20 #define TCG_POOL_CHUNK_SIZE 32768 =20 -#define TCG_MAX_TEMPS 512 +#define TCG_INIT_TEMPS 512 #define TCG_MAX_INSNS 512 =20 /* when the size of the arguments of a called function is smaller than @@ -696,7 +696,7 @@ struct TCGContext { =20 GHashTable *const_table[TCG_TYPE_COUNT]; TCGTempSet free_temps[TCG_TYPE_COUNT * 2]; - TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */ + GPtrArray *temps; /* globals first, temps after */ =20 QTAILQ_HEAD(, TCGOp) ops, free_ops; QSIMPLEQ_HEAD(, TCGLabel) labels; @@ -749,7 +749,7 @@ static inline void *tcg_splitwx_to_rw(const void *rx) static inline TCGTemp *tcg_temp(TCGContext *s, size_t idx) { tcg_debug_assert(idx < s->nb_temps); - return &s->temps[idx]; + return g_ptr_array_index(s->temps, idx); } =20 static inline size_t temp_idx(TCGTemp *ts) diff --git a/tcg/tcg.c b/tcg/tcg.c index a505457cee..5ca6860107 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -816,19 +816,24 @@ void tcg_register_thread(void) void tcg_register_thread(void) { MachineState *ms =3D MACHINE(qdev_get_machine()); - TCGContext *s =3D g_malloc(sizeof(*s)); - unsigned int i, n; + TCGContext *s =3D g_memdup(&tcg_init_ctx, sizeof(*s)); + unsigned int i, n =3D tcg_init_ctx.nb_globals; + TCGTemp *glob; bool err; =20 - *s =3D tcg_init_ctx; - - /* Relink mem_base. */ - for (i =3D 0, n =3D tcg_init_ctx.nb_globals; i < n; ++i) { + /* Copy the globals. */ + s->temps =3D g_ptr_array_sized_new(TCG_INIT_TEMPS); + glob =3D g_new(TCGTemp, n); + for (i =3D 0; i < n; ++i) { TCGTemp *its =3D tcg_temp(&tcg_init_ctx, i); + TCGTemp *ots =3D glob + i; + + *ots =3D *its; if (its->mem_base) { - TCGTemp *ots =3D tcg_temp(s, i); - ots->mem_base =3D tcg_temp(s, temp_idx(its->mem_base)); + /* Relink mem_base. */ + ots->mem_base =3D glob + temp_idx(its->mem_base); } + g_ptr_array_add(s->temps, ots); } =20 /* Claim an entry in tcg_ctxs */ @@ -986,11 +991,11 @@ void tcg_context_init(TCGContext *s) =20 memset(s, 0, sizeof(*s)); s->nb_globals =3D 0; + s->temps =3D g_ptr_array_sized_new(TCG_INIT_TEMPS); =20 - /* Count total number of arguments and allocate the corresponding - space */ + /* Count total number of arguments and allocate the corresponding spac= e */ total_args =3D 0; - for(op =3D 0; op < NB_OPS; op++) { + for (op =3D 0; op < NB_OPS; op++) { def =3D &tcg_op_defs[op]; n =3D def->nb_iargs + def->nb_oargs; total_args +=3D n; @@ -998,7 +1003,7 @@ void tcg_context_init(TCGContext *s) =20 args_ct =3D g_new0(TCGArgConstraint, total_args); =20 - for(op =3D 0; op < NB_OPS; op++) { + for (op =3D 0; op < NB_OPS; op++) { def =3D &tcg_op_defs[op]; def->args_ct =3D args_ct; n =3D def->nb_iargs + def->nb_oargs; @@ -1179,11 +1184,13 @@ void tcg_prologue_init(TCGContext *s) void tcg_func_start(TCGContext *s) { tcg_pool_reset(s); + s->nb_temps =3D s->nb_globals; + g_ptr_array_set_size(s->temps, s->nb_globals); =20 /* No temps have been previously allocated for size or locality. */ for (int i =3D 0; i < ARRAY_SIZE(s->free_temps); ++i) { - tempset_init(&s->free_temps[i], TCG_MAX_TEMPS); + tempset_init(&s->free_temps[i], TCG_INIT_TEMPS); } =20 /* No constant temps have been previously allocated. */ @@ -1208,27 +1215,40 @@ void tcg_func_start(TCGContext *s) =20 static TCGTemp *tcg_temp_alloc(TCGContext *s) { - int n =3D s->nb_temps++; TCGTemp *ret; + int n =3D s->nb_temps; =20 - tcg_debug_assert(n < TCG_MAX_TEMPS); - ret =3D &s->temps[n]; + /* Note that TCGTemp.index is 16 bits. */ + tcg_debug_assert(n <=3D UINT16_MAX); + s->nb_temps =3D n + 1; + + /* Non-global temps are allocated from the pool. */ + ret =3D tcg_malloc(sizeof(TCGTemp)); memset(ret, 0, sizeof(TCGTemp)); ret->index =3D n; =20 + g_ptr_array_add(s->temps, ret); return ret; } =20 -static inline TCGTemp *tcg_global_alloc(TCGContext *s) +static TCGTemp *tcg_global_alloc(TCGContext *s) { - TCGTemp *ts; + TCGTemp *ret; + int n =3D s->nb_globals; =20 + /* Note that TCGTemp.index is 16 bits. */ + tcg_debug_assert(n <=3D UINT16_MAX); tcg_debug_assert(s->nb_globals =3D=3D s->nb_temps); - s->nb_globals++; - ts =3D tcg_temp_alloc(s); - ts->kind =3D TEMP_GLOBAL; + s->nb_globals =3D n + 1; + s->nb_temps =3D n + 1; =20 - return ts; + /* Global temps are allocated from the main heap and live forever. */ + ret =3D g_new0(TCGTemp, 1); + ret->index =3D n; + ret->kind =3D TEMP_GLOBAL; + + g_ptr_array_add(s->temps, ret); + return ret; } =20 static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type, @@ -1236,9 +1256,7 @@ static TCGTemp *tcg_global_reg_new_internal(TCGContex= t *s, TCGType type, { TCGTemp *ts; =20 - if (TCG_TARGET_REG_BITS =3D=3D 32 && type !=3D TCG_TYPE_I32) { - tcg_abort(); - } + tcg_debug_assert(TCG_TARGET_REG_BITS !=3D 32 || type =3D=3D TCG_TYPE_I= 32); =20 ts =3D tcg_global_alloc(s); ts->base_type =3D type; @@ -1299,7 +1317,7 @@ TCGTemp *tcg_global_mem_new_internal(TCGType type, TC= Gv_ptr base, pstrcat(buf, sizeof(buf), "_0"); ts->name =3D strdup(buf); =20 - tcg_debug_assert(ts2 =3D=3D ts + 1); + tcg_debug_assert(temp_idx(ts2) =3D=3D temp_idx(ts) + 1); ts2->base_type =3D TCG_TYPE_I64; ts2->type =3D TCG_TYPE_I32; ts2->indirect_reg =3D indirect_reg; @@ -1347,7 +1365,7 @@ TCGTemp *tcg_temp_new_internal(TCGType type, bool tem= p_local) ts->temp_allocated =3D 1; ts->kind =3D kind; =20 - tcg_debug_assert(ts2 =3D=3D ts + 1); + tcg_debug_assert(temp_idx(ts2) =3D=3D temp_idx(ts) + 1); ts2->base_type =3D TCG_TYPE_I64; ts2->type =3D TCG_TYPE_I32; ts2->temp_allocated =3D 1; @@ -1456,7 +1474,7 @@ TCGTemp *tcg_constant_internal(TCGType type, int64_t = val) */ ts->val =3D val; =20 - tcg_debug_assert(ts2 =3D=3D ts + 1); + tcg_debug_assert(temp_idx(ts2) =3D=3D temp_idx(ts) + 1); ts2->base_type =3D TCG_TYPE_I64; ts2->type =3D TCG_TYPE_I32; ts2->kind =3D TEMP_CONST; --=20 2.25.1