public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mikael Morin <mikael@gcc.gnu.org>
To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [PATCH 08/14] fortran: Push final procedure expr gen close to its one usage.
Date: Thu, 13 Jul 2023 10:52:30 +0200	[thread overview]
Message-ID: <20230713085236.330222-9-mikael@gcc.gnu.org> (raw)
In-Reply-To: <20230713085236.330222-1-mikael@gcc.gnu.org>

Final procedure pointer expression is generated in gfc_build_final_call
and only used in get_final_proc_ref.  Move the generation there.

gcc/fortran/ChangeLog:

	* trans.cc (gfc_add_finalizer_call): Remove local variable
	final_expr.  Pass down expr to get_final_proc_ref and move
	final procedure expression generation down to its one usage
	in get_final_proc_ref.
	(get_final_proc_ref): Add argument expr.  Remove argument
	final_wrapper.  Recreate final_wrapper from expr.
---
 gcc/fortran/trans.cc | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index e5ad67199e7..c6a65c87c5c 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -1085,12 +1085,25 @@ gfc_call_free (tree var)
 }
 
 
-/* Generate the data reference to the finalization procedure pointer passed as
-   argument in FINAL_WRAPPER.  */
+/* Generate the data reference to the finalization procedure pointer associated
+   with the expression passed as argument in EXPR.  */
 
 static void
-get_final_proc_ref (gfc_se *se, gfc_expr *final_wrapper)
+get_final_proc_ref (gfc_se *se, gfc_expr *expr)
 {
+  gfc_expr *final_wrapper = NULL;
+
+  gcc_assert (expr->ts.type == BT_DERIVED || expr->ts.type == BT_CLASS);
+
+  if (expr->ts.type == BT_DERIVED)
+    gfc_is_finalizable (expr->ts.u.derived, &final_wrapper);
+  else
+    {
+      final_wrapper = gfc_copy_expr (expr);
+      gfc_add_vptr_component (final_wrapper);
+      gfc_add_final_component (final_wrapper);
+    }
+
   gcc_assert (final_wrapper->expr_type == EXPR_VARIABLE);
 
   gfc_conv_expr (se, final_wrapper);
@@ -1308,7 +1321,6 @@ gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2)
   tree tmp;
   gfc_ref *ref;
   gfc_expr *expr;
-  gfc_expr *final_expr = NULL;
   bool has_finalizer = false;
 
   if (!expr2 || (expr2->ts.type != BT_DERIVED && expr2->ts.type != BT_CLASS))
@@ -1322,12 +1334,9 @@ gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2)
       && expr2->ts.u.derived->attr.defined_assign_comp)
     return false;
 
-  if (expr2->ts.type == BT_DERIVED)
-    {
-      gfc_is_finalizable (expr2->ts.u.derived, &final_expr);
-      if (!final_expr)
-        return false;
-    }
+  if (expr2->ts.type == BT_DERIVED
+      && !gfc_is_finalizable (expr2->ts.u.derived, NULL))
+    return false;
 
   /* If we have a class array, we need go back to the class
      container.  */
@@ -1358,20 +1367,14 @@ gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2)
 
       if (!expr2->rank && !expr2->ref && CLASS_DATA (expr2->symtree->n.sym)->as)
 	expr->rank = CLASS_DATA (expr2->symtree->n.sym)->as->rank;
-
-      final_expr = gfc_copy_expr (expr);
-      gfc_add_vptr_component (final_expr);
-      gfc_add_final_component (final_expr);
     }
 
-  gcc_assert (final_expr->expr_type == EXPR_VARIABLE);
-
   stmtblock_t tmp_block;
   gfc_start_block (&tmp_block);
 
   gfc_se final_se;
   gfc_init_se (&final_se, NULL);
-  get_final_proc_ref (&final_se, final_expr);
+  get_final_proc_ref (&final_se, expr);
   gfc_add_block_to_block (block, &final_se.pre);
 
   gfc_se size_se;
-- 
2.40.1


  parent reply	other threads:[~2023-07-13  8:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-13  8:52 [PATCH 00/14] fortran: Use precalculated class container for deallocation [PR110618] Mikael Morin
2023-07-13  8:52 ` [PATCH 01/14] fortran: Outline final procedure pointer evaluation Mikael Morin
2023-07-13  8:52 ` [PATCH 02/14] fortran: Outline element size evaluation Mikael Morin
2023-07-13  8:52 ` [PATCH 03/14] fortran: Outline data reference descriptor evaluation Mikael Morin
2023-07-13  8:52 ` [PATCH 04/14] fortran: Inline gfc_build_final_call Mikael Morin
2023-07-13  8:52 ` [PATCH 05/14] fortran: Add missing cleanup blocks Mikael Morin
2023-07-13  8:52 ` [PATCH 06/14] fortran: Reuse final procedure pointer expression Mikael Morin
2023-07-13  8:52 ` [PATCH 07/14] fortran: Push element size expression generation close to its usage Mikael Morin
2023-07-13  8:52 ` Mikael Morin [this message]
2023-07-13  8:52 ` [PATCH 09/14] fortran: Inline variable definition Mikael Morin
2023-07-13  8:52 ` [PATCH 10/14] fortran: Remove redundant argument in get_var_descr Mikael Morin
2023-07-13  8:52 ` [PATCH 11/14] fortran: Outline virtual table pointer evaluation Mikael Morin
2023-07-13  8:52 ` [PATCH 12/14] fortran: Factor scalar descriptor generation Mikael Morin
2023-07-13  8:52 ` [PATCH 13/14] fortran: Use pre-evaluated class container if available [PR110618] Mikael Morin
2023-07-13  8:52 ` [PATCH 14/14] fortran: Pass pre-calculated class container argument [pr110618] Mikael Morin
2023-07-14  5:55   ` Paul Richard Thomas
2023-07-14  7:43     ` Mikael Morin
2023-07-13 18:40 ` [PATCH 00/14] fortran: Use precalculated class container for deallocation [PR110618] Paul Richard Thomas
2023-07-15  6:11   ` Paul Richard Thomas
2023-07-15 10:08     ` Mikael Morin
2023-07-16 17:09       ` Mikael Morin
2023-07-17  6:12         ` Paul Richard Thomas
2023-07-17 17:43     ` Mikael Morin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230713085236.330222-9-mikael@gcc.gnu.org \
    --to=mikael@gcc.gnu.org \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).