From patchwork Thu Jul 13 08:52:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 119670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1684429vqm; Thu, 13 Jul 2023 01:55:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlFnGHAWaKi5hmwAaIEVsgg3WoLyF6PjuKRenX4R0JATLEmKbX5XeyWIABhsnU639rChwcG8 X-Received: by 2002:a17:906:8251:b0:992:61c5:dab0 with SMTP id f17-20020a170906825100b0099261c5dab0mr849471ejx.62.1689238543155; Thu, 13 Jul 2023 01:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689238543; cv=none; d=google.com; s=arc-20160816; b=brfwh7IX9tQHn4CcztvCYSktTtpD6GDtizUVwaq9OTRutzoJyviawrWUnLtxWYuOO6 pdFTuRH4dV/cB/wTNIAUdzhb3xCIzl9jGE1+j2mSB3ovWr6wq1slwgKCGE+ns5ajzWgR UL7jTHTVl2SMrtY/rAoDKmO5U1Aog2W2vKJtYxJ0svUOEtMscQrBcgrlpT856hiLCGJE C7op7jROcmkGX0LafEEHk5HoHCvKBtdn1KWj6vE6SCwmJoBRkw1dNHEbC4/kPSxN7vQi gkz/mDGRG3PJ0XgvwKs8tgjzsGZTqOPZ0JuJYAj9XwjSwQxo4zHkRNG+vZ2Ay4W8lT/q J+jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from: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:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=BNG4zJnodo7o828Hze2Fi0n8fW7doYgW4UjAPhpoUHM=; fh=EAqAZnhg4AYtcBjfPm18lEF5V0R2rkI9MSWQf+svVaI=; b=ATuu0Rn6hHuKHNLkhHzvA7yFOqIYyhLbB/CrmaIOwzI0BlDIO4qRHKHfxh20bSfvuK hnUTKqOkJR8gRwl2r3Wur/TofmW54P7VKAiOczSbqi6ncQ19NOyPaE+UBzxsBiW+Ub3K Ju0ykJ6v6JGf9jiEtXcn5NnsgyWIj0gw97I+mjzoKwd+XEA77Y4WxCxIWH77jhLshNLa x2C+Aqtc61/QGscqFSSnu7xQmRDqt3Mf9ECw3eDARriZnkVuYnRLH53S/k1MsN0SjZhi XdPuI+OBa5uIzS1AriVT18cyN5t8C0wOzWnJgg0aALzesggZEKujYWhgsQKklSlsnkn6 eP1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DhE6tWV4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id br12-20020a170906d14c00b0098888ba2920si6686407ejb.818.2023.07.13.01.55.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 01:55:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DhE6tWV4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F2B00385735D for ; Thu, 13 Jul 2023 08:53:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F2B00385735D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689238432; bh=BNG4zJnodo7o828Hze2Fi0n8fW7doYgW4UjAPhpoUHM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=DhE6tWV40UHXYiHX5DZ1U89y/OoZt2BD+Imc5e/OYt5/gzEkEm+qfi/RUSv/5ADGY xx53L5itF/L4ubvLPRk0abiJ5sgJnGjpLoDUl+ZiSCxogM0Bdl1fXAcg5o/wR8xwvu /1WA70a4ZDdDzGmwjtL7JuccHqsVBIAxhJ056dyE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp-13.smtpout.orange.fr [80.12.242.13]) by sourceware.org (Postfix) with ESMTPS id C11813858002 for ; Thu, 13 Jul 2023 08:52:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C11813858002 Received: from cyrano.home ([86.215.161.51]) by smtp.orange.fr with ESMTPA id Js3wqzoJKtImzJs44q0yVh; Thu, 13 Jul 2023 10:52:44 +0200 X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Thu, 13 Jul 2023 10:52:44 +0200 X-ME-IP: 86.215.161.51 To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 07/14] fortran: Push element size expression generation close to its usage Date: Thu, 13 Jul 2023 10:52:29 +0200 Message-Id: <20230713085236.330222-8-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230713085236.330222-1-mikael@gcc.gnu.org> References: <20230713085236.330222-1-mikael@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mikael Morin via Gcc-patches From: Mikael Morin Reply-To: Mikael Morin Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771294994423310865 X-GMAIL-MSGID: 1771294994423310865 gfc_add_finalizer_call creates one expression which is only used by the get_final_proc_ref function. Move the expression generation there. gcc/fortran/ChangeLog: * trans.cc (gfc_add_finalizer_call): Remove local variable elem_size. Pass expression to get_elem_size and move the element size expression generation close to its usage there. (get_elem_size): Add argument expr, remove class_size argument and rebuild it from expr. Remove ts argument and use the type of expr instead. --- gcc/fortran/trans.cc | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc index 3750d4eca82..e5ad67199e7 100644 --- a/gcc/fortran/trans.cc +++ b/gcc/fortran/trans.cc @@ -1100,24 +1100,26 @@ get_final_proc_ref (gfc_se *se, gfc_expr *final_wrapper) } -/* Generate the code to obtain the value of the element size whose expression - is passed as argument in CLASS_SIZE. */ +/* Generate the code to obtain the value of the element size of the expression + passed as argument in EXPR. */ static void -get_elem_size (gfc_se *se, gfc_typespec *ts, gfc_expr *class_size) +get_elem_size (gfc_se *se, gfc_expr *expr) { - gcc_assert (ts->type == BT_DERIVED || ts->type == BT_CLASS); + gcc_assert (expr->ts.type == BT_DERIVED || expr->ts.type == BT_CLASS); - if (ts->type == BT_DERIVED) + if (expr->ts.type == BT_DERIVED) { - gcc_assert (!class_size); - se->expr = gfc_typenode_for_spec (ts); + se->expr = gfc_typenode_for_spec (&expr->ts); se->expr = TYPE_SIZE_UNIT (se->expr); se->expr = fold_convert (gfc_array_index_type, se->expr); } else { - gcc_assert (class_size); + gfc_expr *class_size = gfc_copy_expr (expr); + gfc_add_vptr_component (class_size); + gfc_add_size_component (class_size); + gfc_conv_expr (se, class_size); gcc_assert (se->post.head == NULL_TREE); } @@ -1307,7 +1309,6 @@ gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2) gfc_ref *ref; gfc_expr *expr; gfc_expr *final_expr = NULL; - gfc_expr *elem_size = NULL; bool has_finalizer = false; if (!expr2 || (expr2->ts.type != BT_DERIVED && expr2->ts.type != BT_CLASS)) @@ -1361,10 +1362,6 @@ gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2) final_expr = gfc_copy_expr (expr); gfc_add_vptr_component (final_expr); gfc_add_final_component (final_expr); - - elem_size = gfc_copy_expr (expr); - gfc_add_vptr_component (elem_size); - gfc_add_size_component (elem_size); } gcc_assert (final_expr->expr_type == EXPR_VARIABLE); @@ -1379,7 +1376,7 @@ gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2) gfc_se size_se; gfc_init_se (&size_se, NULL); - get_elem_size (&size_se, &expr->ts, elem_size); + get_elem_size (&size_se, expr); gfc_add_block_to_block (&tmp_block, &size_se.pre); gfc_se desc_se;