From patchwork Tue Jan 19 18:34:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 366210 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp1058173jam; Tue, 19 Jan 2021 11:34:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyyqD/5DuXmCZE/MtI4ibN5Hnk0W+FVkOOXFiTNLCS6OqbWEKvHLJRvQS6HDj6Bjrw6g3t3 X-Received: by 2002:a25:254e:: with SMTP id l75mr8329598ybl.110.1611084848881; Tue, 19 Jan 2021 11:34:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611084848; cv=none; d=google.com; s=arc-20160816; b=nQORPWhizrdaZY7yJVtPvPOV84XYb7nVFbWbJBUTBg2n/qDio0hitcsU8Iq+lTHvhC qus8IynB7VSCYR+c9Eog/B5x8DHBIdiyQ4HlHSQCt5JLKY7Squ+kJ44y8QqSthFLWE4e G0anNBKmwYok+MwRTuoCMEJFOJ9xl/X5Z59W1zE4ygRP4US+NbCLaEfcu1J5jqOqCM1X RTNoAPPe6lDf4TRF/iyNoCv01l+c+qGoJYoqdVBRb5VL+giXK6M0L40fmu715rsshOwT j1r1L9Zd74eBgGfNNwQ7uwnKYQerIFhoEwLkHAbN6OF3tKpyBze25mJPzx6tZW0u7irF oSYA== 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=Lb0UT912r2GMFw/dFnRGb/nKNqr4nsQ4gGmPTzEJSYY=; b=h9pP8gcr8wu3C2YlO+8zgnMqODTyf1McOx59n6ZP3FYriOxiND9VfzoKUU5IG3S1t0 ++EJAk6WmOvzHBJROXHqgN9IPHf4pugDW9DDEEA9wmXHtXSWvIHyp2JtHerIaDv4RD2v jihrmX1Ps5ayQeduYT2RPcrxKoQmxGl1YYsTVHP1A0Z7mSskIwI4lNVvlm6geWQPKcs7 G2o+6hjEnJPFGOKCQSGoRPQIVTd36GqDzFJuL9XtZL+sEuRFXA5+uHrvgygUMNzod/RM 9reUiNr30HL9RSuz5PK58bL8LF+AWTx3V9yWL7OmfK8dRT8S6DyEM0N4oxsDmrcdujmi 4SUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=AAQqhaRB; 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=fail (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 186si21881618ybl.414.2021.01.19.11.34.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Jan 2021 11:34:08 -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=fail header.i=@linaro.org header.s=google header.b=AAQqhaRB; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wlU-0000vo-Bw for patch@linaro.org; Tue, 19 Jan 2021 14:34:08 -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) 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-Received: by 2002:a17:90b:8d7:: with SMTP id ds23mr1120143pjb.116.1611081273549; Tue, 19 Jan 2021 10:34:33 -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) 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- include/tcg/tcg.h | 5 ++--- tcg/tcg.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) -- 2.25.1 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; 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) static inline size_t temp_idx(TCGTemp *ts) { - ptrdiff_t n = ts - tcg_ctx->temps; - tcg_debug_assert(n >= 0 && n < tcg_ctx->nb_temps); - return n; + return ts->index; } 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); } -static inline TCGTemp *tcg_temp_alloc(TCGContext *s) +static TCGTemp *tcg_temp_alloc(TCGContext *s) { int n = s->nb_temps++; + TCGTemp *ret; + tcg_debug_assert(n < TCG_MAX_TEMPS); - return memset(&s->temps[n], 0, sizeof(TCGTemp)); + ret = &s->temps[n]; + memset(ret, 0, sizeof(TCGTemp)); + ret->index = n; + + return ret; } static inline TCGTemp *tcg_global_alloc(TCGContext *s) From patchwork Tue Jan 19 18:34:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 366206 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp1039069jam; Tue, 19 Jan 2021 11:07:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbfIXXsxvB+/Y9BXzoRVm/+DGFxmeWk3uUnJvXLulPyBaOITxu7//ZbwwPomw/d+LHOFnK X-Received: by 2002:a25:6851:: with SMTP id d78mr7980539ybc.433.1611083240860; Tue, 19 Jan 2021 11:07:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611083240; cv=none; d=google.com; s=arc-20160816; b=qh1wtgNtbJqCpg+1eTNwVzQMFk6OR3Rp2+SFcIWp6md8BkSV7mHdXw6eqfBwni2sq8 dCHShYpmV+RDNYOmtTGGLycmbP2BkMhSQJNZXbcAyHqE0mp2bzAemuXYP090ZMemb5t6 8p6MZhv2FqyZTClET2BapJG0I382cZpnbnVYwph/mSNyrOqCcZikTZhRQFJz3aHALcrB R0vAXHllNLFSuqIgop9pPwPjXbpxVUeTaRbqKDih/57FYvjVOS/D5lxVK9QfX/84JX7q 9oHud8DyzQASNJ2YesaX5di1CcI4ERKQTVJdeKTTrORjx7uSBE2qgo3ofblR7XX95Twp juZQ== 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=0qp18WNANcXFrE2K7B3cvwfkNuDH1MH1NJQQgujUOMM=; b=drAYkzhwO5S+m+Ph2ApgTbNxHnPQBzjfXoYON6//uARXIlqPJO9s3eJf05QMYpIU3K uQTGY6HpWLUwa+aUjMp3RYOAxYc0npyEQZt7utW/+PHhdK/zDAxC9ao7Z0Dnhz5CQs4l eN7pO9cczo09u9johALyCc8F7SKvZT0aChWHbRcYj0LiI7mbWCj0aswei8y0mdRYnyAO GzwVB9fFvpUIalzEwF0w7vQPAuVZjgoex2aD/ASOwZ3TdmIeJe7VB+nYaoew2spRUhp4 KHaavRSFob1bA1wkwL1ydoNphjPpyc5zKe73LW8r1NUXo8Z8FxhE+0nLSrGu+W6y9xYk 6vpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=EdEzdWi2; 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=fail (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 x18si20525712ybj.403.2021.01.19.11.07.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Jan 2021 11:07:20 -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=fail header.i=@linaro.org header.s=google header.b=EdEzdWi2; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wLY-0005j7-9D for patch@linaro.org; Tue, 19 Jan 2021 14:07:20 -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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- include/tcg/tcg.h | 6 ++++ tcg/optimize.c | 5 ++-- tcg/tcg.c | 71 ++++++++++++++++++++++++++--------------------- 3 files changed, 48 insertions(+), 34 deletions(-) -- 2.25.1 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 +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) memset(&temps_used, 0, sizeof(temps_used)); for (i = 0; i < nb_temps; ++i) { - s->temps[i].state_ptr = NULL; + TCGTemp *ts = tcg_temp(s, i); + ts->state_ptr = NULL; } 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 = 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) /* Relink mem_base. */ for (i = 0, n = tcg_init_ctx.nb_globals; i < n; ++i) { - if (tcg_init_ctx.temps[i].mem_base) { - ptrdiff_t b = tcg_init_ctx.temps[i].mem_base - tcg_init_ctx.temps; - tcg_debug_assert(b >= 0 && b < n); - s->temps[i].mem_base = &s->temps[b]; + TCGTemp *its = tcg_temp(&tcg_init_ctx, i); + if (its->mem_base) { + TCGTemp *ots = tcg_temp(s, i); + ots->mem_base = tcg_temp(s, temp_idx(its->mem_base)); } } @@ -1332,7 +1332,7 @@ TCGTemp *tcg_temp_new_internal(TCGType type, bool temp_local) /* There is already an available temp with the right type. */ clear_bit(idx, s->free_temps[k].l); - ts = &s->temps[idx]; + ts = tcg_temp(s, idx); ts->temp_allocated = 1; tcg_debug_assert(ts->base_type == type); tcg_debug_assert(ts->kind == kind); @@ -2016,7 +2016,7 @@ static void tcg_reg_alloc_start(TCGContext *s) int i, n; for (i = 0, n = s->nb_temps; i < n; i++) { - TCGTemp *ts = &s->temps[i]; + TCGTemp *ts = tcg_temp(s, i); TCGTempVal val = TEMP_VAL_MEM; switch (ts->kind) { @@ -2654,12 +2654,14 @@ static void la_func_end(TCGContext *s, int ng, int nt) int i; for (i = 0; i < ng; ++i) { - s->temps[i].state = TS_DEAD | TS_MEM; - la_reset_pref(&s->temps[i]); + TCGTemp *ts = tcg_temp(s, i); + ts->state = TS_DEAD | TS_MEM; + la_reset_pref(ts); } for (i = ng; i < nt; ++i) { - s->temps[i].state = TS_DEAD; - la_reset_pref(&s->temps[i]); + TCGTemp *ts = tcg_temp(s, i); + ts->state = TS_DEAD; + la_reset_pref(ts); } } @@ -2670,7 +2672,7 @@ static void la_bb_end(TCGContext *s, int ng, int nt) int i; for (i = 0; i < nt; ++i) { - TCGTemp *ts = &s->temps[i]; + TCGTemp *ts = tcg_temp(s, i); int state; switch (ts->kind) { @@ -2697,11 +2699,13 @@ static void la_global_sync(TCGContext *s, int ng) int i; for (i = 0; i < ng; ++i) { - int state = s->temps[i].state; - s->temps[i].state = state | TS_MEM; + TCGTemp *ts = tcg_temp(s, i); + int state = ts->state; + + ts->state = state | TS_MEM; if (state == 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); for (int i = ng; i < nt; ++i) { - TCGTemp *ts = &s->temps[i]; + TCGTemp *ts = tcg_temp(s, i); int state; switch (ts->kind) { @@ -2727,14 +2731,14 @@ static void la_bb_sync(TCGContext *s, int ng, int nt) } break; case TEMP_NORMAL: - s->temps[i].state = TS_DEAD; + ts->state = TS_DEAD; break; case TEMP_CONST: continue; default: g_assert_not_reached(); } - la_reset_pref(&s->temps[i]); + la_reset_pref(ts); } } @@ -2744,8 +2748,9 @@ static void la_global_kill(TCGContext *s, int ng) int i; for (i = 0; i < ng; i++) { - s->temps[i].state = TS_DEAD | TS_MEM; - la_reset_pref(&s->temps[i]); + TCGTemp *ts = tcg_temp(s, i); + ts->state = TS_DEAD | TS_MEM; + la_reset_pref(ts); } } @@ -2756,7 +2761,8 @@ static void la_cross_call(TCGContext *s, int nt) int i; for (i = 0; i < nt; i++) { - TCGTemp *ts = &s->temps[i]; + TCGTemp *ts = tcg_temp(s, i); + if (!(ts->state & TS_DEAD)) { TCGRegSet *pset = la_temp_pref(ts); TCGRegSet set = *pset; @@ -2784,7 +2790,8 @@ static void liveness_pass_1(TCGContext *s) prefs = tcg_malloc(sizeof(TCGRegSet) * nb_temps); for (i = 0; i < nb_temps; ++i) { - s->temps[i].state_ptr = prefs + i; + TCGTemp *ts = tcg_temp(s, i); + ts->state_ptr = prefs + i; } /* ??? Should be redundant with the exit_tb that ends the TB. */ @@ -3094,7 +3101,7 @@ static bool liveness_pass_2(TCGContext *s) /* Create a temporary for each indirect global. */ for (i = 0; i < nb_globals; ++i) { - TCGTemp *its = &s->temps[i]; + TCGTemp *its = tcg_temp(s, i); if (its->indirect_reg) { TCGTemp *dts = tcg_temp_alloc(s); dts->type = its->type; @@ -3107,7 +3114,7 @@ static bool liveness_pass_2(TCGContext *s) its->state = TS_DEAD; } for (nb_temps = s->nb_temps; i < nb_temps; ++i) { - TCGTemp *its = &s->temps[i]; + TCGTemp *its = tcg_temp(s, i); its->state_ptr = NULL; its->state = TS_DEAD; } @@ -3190,7 +3197,7 @@ static bool liveness_pass_2(TCGContext *s) for (i = 0; i < nb_globals; ++i) { /* Liveness should see that globals are synced back, that is, either TS_DEAD or TS_MEM. */ - arg_ts = &s->temps[i]; + arg_ts = tcg_temp(s, i); tcg_debug_assert(arg_ts->state_ptr == 0 || arg_ts->state != 0); } @@ -3198,7 +3205,7 @@ static bool liveness_pass_2(TCGContext *s) for (i = 0; i < nb_globals; ++i) { /* Liveness should see that globals are saved back, that is, TS_DEAD, waiting to be reloaded. */ - arg_ts = &s->temps[i]; + arg_ts = tcg_temp(s, i); tcg_debug_assert(arg_ts->state_ptr == 0 || arg_ts->state == 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]; for(i = 0; i < s->nb_temps; i++) { - ts = &s->temps[i]; + TCGTemp *ts = 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 = 0; k < s->nb_temps; k++) { - ts = &s->temps[k]; + ts = tcg_temp(s, k); if (ts->val_type == TEMP_VAL_REG && ts->kind != TEMP_FIXED && s->reg_to_temp[ts->reg] != ts) { @@ -3594,7 +3600,7 @@ static void save_globals(TCGContext *s, TCGRegSet allocated_regs) int i, n; for (i = 0, n = s->nb_globals; i < n; i++) { - temp_save(s, &s->temps[i], allocated_regs); + temp_save(s, tcg_temp(s, i), allocated_regs); } } @@ -3606,7 +3612,7 @@ static void sync_globals(TCGContext *s, TCGRegSet allocated_regs) int i, n; for (i = 0, n = s->nb_globals; i < n; i++) { - TCGTemp *ts = &s->temps[i]; + TCGTemp *ts = tcg_temp(s, i); tcg_debug_assert(ts->val_type != TEMP_VAL_REG || ts->kind == TEMP_FIXED || ts->mem_coherent); @@ -3620,7 +3626,7 @@ static void tcg_reg_alloc_bb_end(TCGContext *s, TCGRegSet allocated_regs) int i; for (i = s->nb_globals; i < s->nb_temps; i++) { - TCGTemp *ts = &s->temps[i]; + TCGTemp *ts = tcg_temp(s, i); switch (ts->kind) { case TEMP_LOCAL: @@ -3652,7 +3658,8 @@ static void tcg_reg_alloc_cbranch(TCGContext *s, TCGRegSet allocated_regs) sync_globals(s, allocated_regs); for (int i = s->nb_globals; i < s->nb_temps; i++) { - TCGTemp *ts = &s->temps[i]; + TCGTemp *ts = tcg_temp(s, i); + /* * The liveness analysis already ensures that temps are dead. * Keep tcg_debug_asserts for safety. From patchwork Tue Jan 19 18:34:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 366207 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp1043275jam; Tue, 19 Jan 2021 11:12:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3Jafjl3a9cc5T/qN5LJWUemAHVQJaHleUaOgzaXTVkJg81M+3PJ17pGSltJemCKJh8StM X-Received: by 2002:a25:9d83:: with SMTP id v3mr7535864ybp.368.1611083570660; Tue, 19 Jan 2021 11:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611083570; cv=none; d=google.com; s=arc-20160816; b=PZtc9yoVKp8kChWJWZ2x95VaOods0Kwd9b+F7LHMfY8SSGLyS8xmo6RosmucHkElEY wzmDz1di6jTnvaXqrhggvThnKmLUD87lGj7V9//WWb++oOk6xgNXfn+tCh91E6VE6Kxq RL8OTcDeri1Ta4bbrmsX+wAMmeslFav9S+hRXW247NRRMZZQIm55YYKqkaQb6Ua8qMJ7 cd1p/MlCjrViABd+GqMFcIYrSd4u8pP/89Fw9a7UTtUF3Vbeh5lB88R4QB6fOrp7fh08 uM3oSVJ9X1c20C4UQLZxjvDf3gmctewF4iAI5IKeNRrjM5ktEwe8mwt/6UvFqucj9dLR hLxw== 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=zocLtIhc1566xSbUUG3fVWgPSfFwYEU16pDGR5baprU=; b=a82L0nkQ4a/roFQJp+LB3RTdYewlh5v16Dc8ytIJ+tu1tplNaur7eT/WhvPj+bDdEJ IkwFkaYw9j0oWQHqMwId4Tv/Lg81QrJG2NYw351TxhXbZUCTGlfuOOrvtH1B9I0AWXJR WrHhKQtZyPjHAiE0BVZ51kPz+aWqcHvsVgonF9YyPWbhFOjiOrVysk2rOMZOzDokwN+/ MLRItmuMiXaBAcaOzSJYWec4OTKeuOIvfps+h5t6h65hOuh5jcr5SWfdyaCsWO8MWsIm A4AnQE31Ys3r4Ck00oJg/Cgd6dFpqs7qJPhN+EFhVntawWxBcfl6A92h8HEFVrH9gcvU e11g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CUbXQvsk; 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=fail (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 e8si9205426ybp.331.2021.01.19.11.12.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Jan 2021 11:12:50 -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=fail header.i=@linaro.org header.s=google header.b=CUbXQvsk; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wQs-0000Mz-6A for patch@linaro.org; Tue, 19 Jan 2021 14:12:50 -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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- include/tcg/tcg.h | 28 +++++++++++++++++++++++++- tcg/optimize.c | 18 ++++++++--------- tcg/tcg.c | 51 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 80 insertions(+), 17 deletions(-) -- 2.25.1 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; typedef struct TCGTempSet { - unsigned long l[BITS_TO_LONGS(TCG_MAX_TEMPS)]; + unsigned long *data; + size_t word_len; } TCGTempSet; +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 = i / BITS_PER_LONG; + size_t b = i % BITS_PER_LONG; + if (likely(l < set->word_len)) { + set->data[l] &= ~BIT(b); + } +} + +static inline bool tempset_test(const TCGTempSet *set, size_t i) +{ + size_t l = i / BITS_PER_LONG; + size_t b = 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) = 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, TCGTemp *ts) size_t idx = temp_idx(ts); TempOptInfo *ti; - 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); ti = ts->state_ptr; if (ti == NULL) { @@ -612,7 +612,7 @@ void tcg_optimize(TCGContext *s) nb_temps = s->nb_temps; nb_globals = s->nb_globals; - memset(&temps_used, 0, sizeof(temps_used)); + tempset_init(&temps_used, nb_temps); for (i = 0; i < nb_temps; ++i) { TCGTemp *ts = tcg_temp(s, i); ts->state_ptr = NULL; @@ -1254,7 +1254,7 @@ void tcg_optimize(TCGContext *s) op->args[1], op->args[2]); if (tmp != 2) { if (tmp) { - memset(&temps_used, 0, sizeof(temps_used)); + tempset_clear_all(&temps_used); op->opc = INDEX_op_br; op->args[0] = op->args[3]; } else { @@ -1338,7 +1338,7 @@ void tcg_optimize(TCGContext *s) if (tmp != 2) { if (tmp) { do_brcond_true: - memset(&temps_used, 0, sizeof(temps_used)); + tempset_clear_all(&temps_used); op->opc = INDEX_op_br; op->args[0] = 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 = INDEX_op_brcond_i32; op->args[0] = op->args[1]; op->args[1] = 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 = INDEX_op_brcond_i32; op->args[1] = op->args[2]; op->args[2] = 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 = 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 = 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 = s->nb_globals; /* No temps have been previously allocated for size or locality. */ - memset(s->free_temps, 0, sizeof(s->free_temps)); + for (int i = 0; i < ARRAY_SIZE(s->free_temps); ++i) { + tempset_init(&s->free_temps[i], TCG_MAX_TEMPS); + } /* No constant temps have been previously allocated. */ for (int i = 0; i < TCG_TYPE_COUNT; ++i) { @@ -1324,13 +1326,12 @@ TCGTemp *tcg_temp_new_internal(TCGType type, bool temp_local) TCGContext *s = tcg_ctx; TCGTempKind kind = temp_local ? TEMP_LOCAL : TEMP_NORMAL; TCGTemp *ts; - int idx, k; + size_t idx, k; k = type + (temp_local ? TCG_TYPE_COUNT : 0); - idx = 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); ts = tcg_temp(s, idx); ts->temp_allocated = 1; @@ -1403,7 +1404,7 @@ TCGv_vec tcg_temp_new_vec_matching(TCGv_vec match) void tcg_temp_free_internal(TCGTemp *ts) { TCGContext *s = tcg_ctx; - int k, idx; + size_t k, idx; /* In order to simplify users of tcg_constant_*, silently ignore free. */ if (ts->kind == TEMP_CONST) { @@ -1423,7 +1424,7 @@ void tcg_temp_free_internal(TCGTemp *ts) idx = temp_idx(ts); k = ts->base_type + (ts->kind == TEMP_NORMAL ? 0 : TCG_TYPE_COUNT); - set_bit(idx, s->free_temps[k].l); + tempset_set(&s->free_temps[k], idx); } 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); } +void tempset_init(TCGTempSet *set, size_t len) +{ + size_t word_len = BITS_TO_LONGS(len); + + set->word_len = word_len; + set->data = 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 = i / BITS_PER_LONG; + size_t b = i % BITS_PER_LONG; + + if (l >= set->word_len) { + size_t old_blen = set->word_len * sizeof(unsigned long); + size_t new_wlen = set->word_len * 2; + unsigned long *new_data = tcg_malloc(old_blen * 2); + + memcpy(new_data, set->data, old_blen); + memset((char *)new_data + old_blen, 0, old_blen); + + set->data = new_data; + set->word_len = new_wlen; + } + set->data[l] |= BIT(b); +} + +bool tempset_find_first(const TCGTempSet *set, size_t *i) +{ + size_t max = set->word_len * BITS_PER_LONG; + size_t ret = find_first_bit(set->data, max); + *i = ret; + return ret < max; +} + #ifdef CONFIG_PROFILER void tcg_dump_info(void) { From patchwork Tue Jan 19 18:34:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 366211 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp1060764jam; Tue, 19 Jan 2021 11:38:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMYIfZ87B3aRwsxNbC4LRP3UoXrJ1sOcbvPLgVQTvdaZ232MpwZxlFoKsEEVQWRdSXjQ7i X-Received: by 2002:a25:848b:: with SMTP id v11mr7857576ybk.383.1611085101227; Tue, 19 Jan 2021 11:38:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611085101; cv=none; d=google.com; s=arc-20160816; b=duJlSv2ua0DVFMyow6K5wtmFlmBHuCJPToq6wiPMFLx9iU6oZs0xD8brvT5y086W6f vruabullUX3opshsQmzNgI8FeTgxgvfrLMPxqFSQlUqqdqOixf6TymbBjSLCOSYPv8gU 0uAB+ACySywdOgDFSxoFGS+dFDLdGn4cWEeWtFcY6VkbbGptYUhLRBVSAqCNhiCJ7nzW 4eGW86qtHLtqs/Swv5Bc9gT9QFG4ge1Dr9SLS8KIJp3/oaBp6qTY9cUKAq+LMHIW1yb/ kMw4OR4pn632QfBsYK6yKHe6HzWoRd861DLohsqMH0oRrR9qRbf+9LovcDS+6JWf9yrd cC4w== 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=jyybQjiFDPMiQ/WR1CPOwhtb/3DBjHCNWIqS94AKGQU=; b=MSHEyyY94+koJ2yoCGNzImfNu6nfO4/QHnJ77bfrxY+CFFvD3BbfkqnYnbfNzTEgqy ul2Oj7oq8iKNzbUTwJjMcT/kKdzyVuQyB+huhFEd65TbPfJm24hJwgVvQJBrQUaGN2OH 6ejZoQjgQjnh2tP/NMN9PHutv0wTb25RYuSdLwufefyQLvRtQPsqDafuQG1CZn+Ok3z6 UF7dxBCoKXEVtmhLUaYlGHet3HkPOTIUAr/9HcfNWafGuWvHSCxEsDl8K/sT0m55Ljxy UWsvZdq62Kc7Zv/aq5sGOdVa7wBRHxNjsaWcjCji2xYmrCVVMtigNN2qtXp6aXUxVe/C Lkyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mlnPAlxF; 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=fail (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 m19si2677440ybm.359.2021.01.19.11.38.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Jan 2021 11:38:21 -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=fail header.i=@linaro.org header.s=google header.b=mlnPAlxF; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wpY-0004oc-LF for patch@linaro.org; Tue, 19 Jan 2021 14:38:20 -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) 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-Received: by 2002:a17:90a:9414:: with SMTP id r20mr1072743pjo.222.1611081278645; 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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- include/tcg/tcg.h | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) -- 2.25.1 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; } +/* + * 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; } -/* 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 = (uintptr_t)v; - TCGTemp *t = (void *)tcg_ctx + o; - tcg_debug_assert(offsetof(TCGContext, temps[temp_idx(t)]) == o); - return t; + return v ? tcg_temp(tcg_ctx, (uintptr_t)v - 1) : NULL; } static inline TCGTemp *tcgv_i64_temp(TCGv_i64 v) @@ -815,8 +820,7 @@ static inline TCGArg tcgv_vec_arg(TCGv_vec v) 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); } 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 == 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; } 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 From patchwork Tue Jan 19 18:34:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 366209 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp1057715jam; Tue, 19 Jan 2021 11:33:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwosJgpp3NFbpIRi4QdZDOEwDnaOETN2WottLjBqjj0C9vb+z9FlXf29IdAkdibrjh1N2Zw X-Received: by 2002:a25:2d0c:: with SMTP id t12mr8391462ybt.253.1611084798327; Tue, 19 Jan 2021 11:33:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611084798; cv=none; d=google.com; s=arc-20160816; b=nDopwZfbV1utv7cDEOJ/Xk3pNbM0c479E3vaT4CNDhaGw426d90YAg8AxvH1YUMpyT Bt9D2HYba8pQstRR9RutPZpSKTu2uYI3WVUHwxpQSOcMQPTGu9V6vjgEB1NaKBSlY/vR uv297rXgikauG9rcgbcqsMrG4+zF7VSfK1KulqfNJ3XRatOcAr211kbWLdrgK79PGVmX 2i6m1mtfRJTcdzLjndGlt+rI/1kqEOYmfmKj/iTdDLPp9sWW01Hb/23pAKVrOeZhjf01 QJ7xAK9dMNlGie5pNpQpiz8Na+/I3A1/IlfE0mycD/YlvE3zfdY28Q8t8pYfWvsAK66S TTCg== 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=zOwDuzEJMzDZCUyUS+fhCAa4pwhGVLCD5TGZAxSX0pU=; b=ZJ2y4VFy5z2CrSiDo2syz3KlmFNzhOABLZOjqgvDO/Wn08rfT23Ymxs7BipVWJbu1p jqseu0fUPxi37rWoFdrOxMB/DEhbJp52Y59McLhTSbe08KiXIV5gBdT0FQbDEimg2BJ3 B2JxOfwZhLhboJFJF5Lc+MVUcyd7Ezu9kAeiFTGpQhqCYwQmEgbHyBxVxQUVbejYVxWt wgbHA9lz1Rh0p7HEOLCVWRC1BX1hlH3EyQd3CThpS4HJ47ebh5UCZChCWC5AizYq4O5y 9s3Pnje/CDLgCExd3wFCMLuogNlL7lesXu+ZP3JV6VxL20Rgpx9DZ1pPjKooi8P7PTqW wlEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rzOUb5ZF; 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=fail (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 f8si5419750ybm.306.2021.01.19.11.33.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Jan 2021 11:33:18 -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=fail header.i=@linaro.org header.s=google header.b=rzOUb5ZF; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wkf-000830-Om for patch@linaro.org; Tue, 19 Jan 2021 14:33:17 -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) 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-Received: by 2002:a17:90a:2e88:: with SMTP id r8mr1151552pjd.84.1611081280372; Tue, 19 Jan 2021 10:34:40 -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) 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- include/tcg/tcg.h | 6 ++-- tcg/tcg.c | 74 +++++++++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 31 deletions(-) -- 2.25.1 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 { #define TCG_POOL_CHUNK_SIZE 32768 -#define TCG_MAX_TEMPS 512 +#define TCG_INIT_TEMPS 512 #define TCG_MAX_INSNS 512 /* when the size of the arguments of a called function is smaller than @@ -696,7 +696,7 @@ struct TCGContext { 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 */ 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); } 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 = MACHINE(qdev_get_machine()); - TCGContext *s = g_malloc(sizeof(*s)); - unsigned int i, n; + TCGContext *s = g_memdup(&tcg_init_ctx, sizeof(*s)); + unsigned int i, n = tcg_init_ctx.nb_globals; + TCGTemp *glob; bool err; - *s = tcg_init_ctx; - - /* Relink mem_base. */ - for (i = 0, n = tcg_init_ctx.nb_globals; i < n; ++i) { + /* Copy the globals. */ + s->temps = g_ptr_array_sized_new(TCG_INIT_TEMPS); + glob = g_new(TCGTemp, n); + for (i = 0; i < n; ++i) { TCGTemp *its = tcg_temp(&tcg_init_ctx, i); + TCGTemp *ots = glob + i; + + *ots = *its; if (its->mem_base) { - TCGTemp *ots = tcg_temp(s, i); - ots->mem_base = tcg_temp(s, temp_idx(its->mem_base)); + /* Relink mem_base. */ + ots->mem_base = glob + temp_idx(its->mem_base); } + g_ptr_array_add(s->temps, ots); } /* Claim an entry in tcg_ctxs */ @@ -986,11 +991,11 @@ void tcg_context_init(TCGContext *s) memset(s, 0, sizeof(*s)); s->nb_globals = 0; + s->temps = g_ptr_array_sized_new(TCG_INIT_TEMPS); - /* Count total number of arguments and allocate the corresponding - space */ + /* Count total number of arguments and allocate the corresponding space */ total_args = 0; - for(op = 0; op < NB_OPS; op++) { + for (op = 0; op < NB_OPS; op++) { def = &tcg_op_defs[op]; n = def->nb_iargs + def->nb_oargs; total_args += n; @@ -998,7 +1003,7 @@ void tcg_context_init(TCGContext *s) args_ct = g_new0(TCGArgConstraint, total_args); - for(op = 0; op < NB_OPS; op++) { + for (op = 0; op < NB_OPS; op++) { def = &tcg_op_defs[op]; def->args_ct = args_ct; n = 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 = s->nb_globals; + g_ptr_array_set_size(s->temps, s->nb_globals); /* No temps have been previously allocated for size or locality. */ for (int i = 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); } /* No constant temps have been previously allocated. */ @@ -1208,27 +1215,40 @@ void tcg_func_start(TCGContext *s) static TCGTemp *tcg_temp_alloc(TCGContext *s) { - int n = s->nb_temps++; TCGTemp *ret; + int n = s->nb_temps; - tcg_debug_assert(n < TCG_MAX_TEMPS); - ret = &s->temps[n]; + /* Note that TCGTemp.index is 16 bits. */ + tcg_debug_assert(n <= UINT16_MAX); + s->nb_temps = n + 1; + + /* Non-global temps are allocated from the pool. */ + ret = tcg_malloc(sizeof(TCGTemp)); memset(ret, 0, sizeof(TCGTemp)); ret->index = n; + g_ptr_array_add(s->temps, ret); return ret; } -static inline TCGTemp *tcg_global_alloc(TCGContext *s) +static TCGTemp *tcg_global_alloc(TCGContext *s) { - TCGTemp *ts; + TCGTemp *ret; + int n = s->nb_globals; + /* Note that TCGTemp.index is 16 bits. */ + tcg_debug_assert(n <= UINT16_MAX); tcg_debug_assert(s->nb_globals == s->nb_temps); - s->nb_globals++; - ts = tcg_temp_alloc(s); - ts->kind = TEMP_GLOBAL; + s->nb_globals = n + 1; + s->nb_temps = n + 1; - return ts; + /* Global temps are allocated from the main heap and live forever. */ + ret = g_new0(TCGTemp, 1); + ret->index = n; + ret->kind = TEMP_GLOBAL; + + g_ptr_array_add(s->temps, ret); + return ret; } static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type, @@ -1236,9 +1256,7 @@ static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type, { TCGTemp *ts; - if (TCG_TARGET_REG_BITS == 32 && type != TCG_TYPE_I32) { - tcg_abort(); - } + tcg_debug_assert(TCG_TARGET_REG_BITS != 32 || type == TCG_TYPE_I32); ts = tcg_global_alloc(s); ts->base_type = type; @@ -1299,7 +1317,7 @@ TCGTemp *tcg_global_mem_new_internal(TCGType type, TCGv_ptr base, pstrcat(buf, sizeof(buf), "_0"); ts->name = strdup(buf); - tcg_debug_assert(ts2 == ts + 1); + tcg_debug_assert(temp_idx(ts2) == temp_idx(ts) + 1); ts2->base_type = TCG_TYPE_I64; ts2->type = TCG_TYPE_I32; ts2->indirect_reg = indirect_reg; @@ -1347,7 +1365,7 @@ TCGTemp *tcg_temp_new_internal(TCGType type, bool temp_local) ts->temp_allocated = 1; ts->kind = kind; - tcg_debug_assert(ts2 == ts + 1); + tcg_debug_assert(temp_idx(ts2) == temp_idx(ts) + 1); ts2->base_type = TCG_TYPE_I64; ts2->type = TCG_TYPE_I32; ts2->temp_allocated = 1; @@ -1456,7 +1474,7 @@ TCGTemp *tcg_constant_internal(TCGType type, int64_t val) */ ts->val = val; - tcg_debug_assert(ts2 == ts + 1); + tcg_debug_assert(temp_idx(ts2) == temp_idx(ts) + 1); ts2->base_type = TCG_TYPE_I64; ts2->type = TCG_TYPE_I32; ts2->kind = TEMP_CONST;