From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B68FDC433EF for ; Thu, 28 Oct 2021 03:14:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 29A7C60F0F for ; Thu, 28 Oct 2021 03:14:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 29A7C60F0F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:39176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfvrx-0000UU-6e for qemu-devel@archiver.kernel.org; Wed, 27 Oct 2021 23:14:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfvMT-0004mf-Rm for qemu-devel@nongnu.org; Wed, 27 Oct 2021 22:41:51 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:46742) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfvMQ-0003P6-Gk for qemu-devel@nongnu.org; Wed, 27 Oct 2021 22:41:49 -0400 Received: by mail-pg1-x52c.google.com with SMTP id m21so4887620pgu.13 for ; Wed, 27 Oct 2021 19:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nnJy1DPqTKH9tszR9agXW3yGGHUuzxkGQ+Lpc0L3P3o=; b=Ymy5Nw6jkrsatq+ege3iJlxwRNEPr7WsfGC5WbyzEARpqOl1wPht9iMxDozCelq6Au ykt4wXG1y322yLGbxgrInxZQGfmCqRdNGooQZtgPMYB7Eb09a7ncClLtQSGh18oaHzOR Sxt3p1P3DqTGw1K1Cjwjz7tMP76c8JERHB9QC5QvdlnN75D6freGF3nhYW/ecr7g3txQ VBr57pVu1HSiDv2ZIVARsPsblhaHo38z4Ps5DPEdv4+eeCpRra3oW3GQgk+MKjTeupf6 VuIxuepG6SfgSKpm7VaR0gwqKX+w0td8O10tvzKpxSjNpl03tMjlAu49952FjbqD6+KQ JjZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nnJy1DPqTKH9tszR9agXW3yGGHUuzxkGQ+Lpc0L3P3o=; b=Vq+Z1Kj/QPzZFHIDS0eduKmHxQeBUBGMuPtVj4uJA7sIz2Zw5Gmn9wts/cYEJ/Lgi9 8rQfGJ9sMdHehB++HHftnYUNhxf4IpNvWLDguKN6RmBkDr/87GcQE9T1zhKn6OR1ODPZ sSq8KREwNeXQCJzhSHrf1vj5fWMj6HO9jsnsPY4xoMky5ubQieEJyTo70Lu0uEbCOtpk ztFBpQhepseIkV5D1Arlg7r1Lse6JH5XOvmFwzfLhiCkoTrg41oh69PtsKDvpEX3fkFv p7GLoJPtcb1fYLjg7iREQnW3zPySiqwAUUBgCSfUQqKhfvZxrmKjBAX7ydGcWXuTwF2j svpQ== X-Gm-Message-State: AOAM5338EEUI2nJ6LD5i/4KNuoXPDDS6GgEEjRnf8Y7h1CN5fLOqYqoH ldFtjYh5mwQ2CNz7M7QELCd3W8iiilcb6Q== X-Google-Smtp-Source: ABdhPJyoRrJZJqioL0JAvr6iufjMXmyuifs+nlGDAIlkHYz4MSTUC0OvXpwrfHH10CisJCR8ZkPGIg== X-Received: by 2002:a63:7010:: with SMTP id l16mr1221333pgc.32.1635388905212; Wed, 27 Oct 2021 19:41:45 -0700 (PDT) Received: from localhost.localdomain ([71.212.134.125]) by smtp.gmail.com with ESMTPSA id c25sm1218824pfn.159.2021.10.27.19.41.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 19:41:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 19/56] tcg/optimize: Split out fold_mb, fold_qemu_{ld,st} Date: Wed, 27 Oct 2021 19:40:54 -0700 Message-Id: <20211028024131.1492790-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028024131.1492790-1-richard.henderson@linaro.org> References: <20211028024131.1492790-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Luis Pires , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This puts the separate mb optimization into the same framework as the others. While fold_qemu_{ld,st} are currently identical, that won't last as more code gets moved. Reviewed-by: Luis Pires Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- tcg/optimize.c | 89 +++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 38 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 699476e2f1..159a5a9ee5 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -692,6 +692,44 @@ static bool fold_call(OptContext *ctx, TCGOp *op) return true; } +static bool fold_mb(OptContext *ctx, TCGOp *op) +{ + /* Eliminate duplicate and redundant fence instructions. */ + if (ctx->prev_mb) { + /* + * Merge two barriers of the same type into one, + * or a weaker barrier into a stronger one, + * or two weaker barriers into a stronger one. + * mb X; mb Y => mb X|Y + * mb; strl => mb; st + * ldaq; mb => ld; mb + * ldaq; strl => ld; mb; st + * Other combinations are also merged into a strong + * barrier. This is stricter than specified but for + * the purposes of TCG is better than not optimizing. + */ + ctx->prev_mb->args[0] |= op->args[0]; + tcg_op_remove(ctx->tcg, op); + } else { + ctx->prev_mb = op; + } + return true; +} + +static bool fold_qemu_ld(OptContext *ctx, TCGOp *op) +{ + /* Opcodes that touch guest memory stop the mb optimization. */ + ctx->prev_mb = NULL; + return false; +} + +static bool fold_qemu_st(OptContext *ctx, TCGOp *op) +{ + /* Opcodes that touch guest memory stop the mb optimization. */ + ctx->prev_mb = NULL; + return false; +} + /* Propagate constants and copies, fold constant expressions. */ void tcg_optimize(TCGContext *s) { @@ -1599,6 +1637,19 @@ void tcg_optimize(TCGContext *s) } break; + case INDEX_op_mb: + done = fold_mb(&ctx, op); + break; + case INDEX_op_qemu_ld_i32: + case INDEX_op_qemu_ld_i64: + done = fold_qemu_ld(&ctx, op); + break; + case INDEX_op_qemu_st_i32: + case INDEX_op_qemu_st8_i32: + case INDEX_op_qemu_st_i64: + done = fold_qemu_st(&ctx, op); + break; + default: break; } @@ -1606,43 +1657,5 @@ void tcg_optimize(TCGContext *s) if (!done) { finish_folding(&ctx, op); } - - /* Eliminate duplicate and redundant fence instructions. */ - if (ctx.prev_mb) { - switch (opc) { - case INDEX_op_mb: - /* Merge two barriers of the same type into one, - * or a weaker barrier into a stronger one, - * or two weaker barriers into a stronger one. - * mb X; mb Y => mb X|Y - * mb; strl => mb; st - * ldaq; mb => ld; mb - * ldaq; strl => ld; mb; st - * Other combinations are also merged into a strong - * barrier. This is stricter than specified but for - * the purposes of TCG is better than not optimizing. - */ - ctx.prev_mb->args[0] |= op->args[0]; - tcg_op_remove(s, op); - break; - - default: - /* Opcodes that end the block stop the optimization. */ - if ((def->flags & TCG_OPF_BB_END) == 0) { - break; - } - /* fallthru */ - case INDEX_op_qemu_ld_i32: - case INDEX_op_qemu_ld_i64: - case INDEX_op_qemu_st_i32: - case INDEX_op_qemu_st8_i32: - case INDEX_op_qemu_st_i64: - /* Opcodes that touch guest memory stop the optimization. */ - ctx.prev_mb = NULL; - break; - } - } else if (opc == INDEX_op_mb) { - ctx.prev_mb = op; - } } } -- 2.25.1