From: Mikael Morin <mikael@gcc.gnu.org>
To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [PATCH 03/14] fortran: Outline data reference descriptor evaluation
Date: Thu, 13 Jul 2023 10:52:25 +0200 [thread overview]
Message-ID: <20230713085236.330222-4-mikael@gcc.gnu.org> (raw)
In-Reply-To: <20230713085236.330222-1-mikael@gcc.gnu.org>
gcc/fortran/ChangeLog:
* trans.cc (get_var_descr): New function.
(gfc_build_final_call): Outline the data reference descriptor
evaluation code to get_var_descr.
---
gcc/fortran/trans.cc | 149 ++++++++++++++++++++++++-------------------
1 file changed, 83 insertions(+), 66 deletions(-)
diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index 1e4779f94af..9807b7eb9d9 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -1124,6 +1124,83 @@ get_elem_size (gfc_se *se, gfc_typespec *ts, gfc_expr *class_size)
}
+/* Generate the data reference (array) descriptor corresponding to the
+ expression passed as argument in VAR. Use type in TS to pilot code
+ generation. */
+
+static void
+get_var_descr (gfc_se *se, gfc_typespec *ts, gfc_expr *var)
+{
+ gfc_se tmp_se;
+ symbol_attribute attr;
+
+ gcc_assert (var);
+
+ gfc_init_se (&tmp_se, NULL);
+
+ if (ts->type == BT_DERIVED)
+ {
+ tmp_se.want_pointer = 1;
+ if (var->rank)
+ {
+ tmp_se.descriptor_only = 1;
+ gfc_conv_expr_descriptor (&tmp_se, var);
+ }
+ else
+ {
+ gfc_conv_expr (&tmp_se, var);
+// gcc_assert (se.pre.head == NULL_TREE && se.post.head == NULL_TREE);
+
+ /* No copy back needed, hence set attr's allocatable/pointer
+ to zero. */
+ gfc_clear_attr (&attr);
+ tmp_se.expr = gfc_conv_scalar_to_descriptor (&tmp_se, tmp_se.expr,
+ attr);
+ gcc_assert (tmp_se.post.head == NULL_TREE);
+ }
+ }
+ else
+ {
+ gfc_expr *array_expr;
+
+ array_expr = gfc_copy_expr (var);
+
+ tmp_se.want_pointer = 1;
+ if (array_expr->rank)
+ {
+ gfc_add_class_array_ref (array_expr);
+ tmp_se.descriptor_only = 1;
+ gfc_conv_expr_descriptor (&tmp_se, array_expr);
+ }
+ else
+ {
+ gfc_add_data_component (array_expr);
+ gfc_conv_expr (&tmp_se, array_expr);
+ gcc_assert (tmp_se.post.head == NULL_TREE);
+
+ if (!gfc_is_coarray (array_expr))
+ {
+ /* No copy back needed, hence set attr's allocatable/pointer
+ to zero. */
+ gfc_clear_attr (&attr);
+ tmp_se.expr = gfc_conv_scalar_to_descriptor (&tmp_se, tmp_se.expr,
+ attr);
+ }
+ gcc_assert (tmp_se.post.head == NULL_TREE);
+ }
+ gfc_free_expr (array_expr);
+ }
+
+ if (!POINTER_TYPE_P (TREE_TYPE (tmp_se.expr)))
+ tmp_se.expr = gfc_build_addr_expr (NULL, tmp_se.expr);
+
+ gfc_add_block_to_block (&se->pre, &tmp_se.pre);
+ gfc_add_block_to_block (&se->post, &tmp_se.post);
+ se->expr = tmp_se.expr;
+}
+
+
+
/* Build a call to a FINAL procedure, which finalizes "var". */
static tree
@@ -1131,10 +1208,8 @@ gfc_build_final_call (gfc_typespec ts, gfc_expr *final_wrapper, gfc_expr *var,
bool fini_coarray, gfc_expr *class_size)
{
stmtblock_t block;
- gfc_se final_se, size_se;
- gfc_se se;
+ gfc_se final_se, size_se, desc_se;
tree final_fndecl, array, size, tmp;
- symbol_attribute attr;
gcc_assert (var);
@@ -1150,74 +1225,16 @@ gfc_build_final_call (gfc_typespec ts, gfc_expr *final_wrapper, gfc_expr *var,
gfc_add_block_to_block (&block, &size_se.pre);
size = size_se.expr;
- if (ts.type == BT_DERIVED)
- {
- gfc_init_se (&se, NULL);
- se.want_pointer = 1;
- if (var->rank)
- {
- se.descriptor_only = 1;
- gfc_conv_expr_descriptor (&se, var);
- array = se.expr;
- }
- else
- {
- gfc_conv_expr (&se, var);
-// gcc_assert (se.pre.head == NULL_TREE && se.post.head == NULL_TREE);
- array = se.expr;
+ gfc_init_se (&desc_se, NULL);
+ get_var_descr (&desc_se, &ts, var);
+ gfc_add_block_to_block (&block, &desc_se.pre);
+ array = desc_se.expr;
- /* No copy back needed, hence set attr's allocatable/pointer
- to zero. */
- gfc_clear_attr (&attr);
- gfc_init_se (&se, NULL);
- array = gfc_conv_scalar_to_descriptor (&se, array, attr);
- gcc_assert (se.post.head == NULL_TREE);
- }
- }
- else
- {
- gfc_expr *array_expr;
-
- array_expr = gfc_copy_expr (var);
- gfc_init_se (&se, NULL);
- se.want_pointer = 1;
- if (array_expr->rank)
- {
- gfc_add_class_array_ref (array_expr);
- se.descriptor_only = 1;
- gfc_conv_expr_descriptor (&se, array_expr);
- array = se.expr;
- }
- else
- {
- gfc_add_data_component (array_expr);
- gfc_conv_expr (&se, array_expr);
- gfc_add_block_to_block (&block, &se.pre);
- gcc_assert (se.post.head == NULL_TREE);
- array = se.expr;
-
- if (!gfc_is_coarray (array_expr))
- {
- /* No copy back needed, hence set attr's allocatable/pointer
- to zero. */
- gfc_clear_attr (&attr);
- gfc_init_se (&se, NULL);
- array = gfc_conv_scalar_to_descriptor (&se, array, attr);
- }
- gcc_assert (se.post.head == NULL_TREE);
- }
- gfc_free_expr (array_expr);
- }
-
- if (!POINTER_TYPE_P (TREE_TYPE (array)))
- array = gfc_build_addr_expr (NULL, array);
-
- gfc_add_block_to_block (&block, &se.pre);
tmp = build_call_expr_loc (input_location,
final_fndecl, 3, array,
size, fini_coarray ? boolean_true_node
: boolean_false_node);
- gfc_add_block_to_block (&block, &se.post);
+ gfc_add_block_to_block (&block, &desc_se.post);
gfc_add_expr_to_block (&block, tmp);
return gfc_finish_block (&block);
}
--
2.40.1
next prev 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 ` Mikael Morin [this message]
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 ` [PATCH 08/14] fortran: Push final procedure expr gen close to its one usage Mikael Morin
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-4-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).