[gcc(refs/users/mikael/heads/refactor_descriptor_v206.01)] fortran: array descriptor: Simplify scalar dtype initialization [PR122521]
Mikael Morin via Gcc-cvs <[email protected]>
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:4b7eaf7f5b57e224afba0e106bb015b8d831e210 commit 4b7eaf7f5b57e224afba0e106bb015b8d831e210 Author: Mikael Morin <[email protected]> Date: Tue Aug 18 14:19:32 2026 +0200 fortran: array descriptor: Simplify scalar dtype initialization [PR122521] Fortran-tested on aarch64-unknown-linux-gnu. OK for mainline? -- >8 -- The function gfc_set_descriptor_from_scalar creates a new scalar descriptor type that is only used as argument to gfc_get_dtype, to get the dtype initialization value. gfc_get_dtype extracts two pieces of information from that descriptor type: the rank, and the element type. As the rank is known to be zero, and the element type was part of the input to create the descriptor type, we can avoid the roundtrip through the descriptor type creation, and use directly the zero rank and the element type. This change does that. It permits the removal of one argument from gfc_set_descriptor_from_scalar. With the call to the descriptor type creation function removed, the pointer unwrapping of the element type the function was doing is removed as well. Add it back to the gfc_set_descriptor_from_scalar code. PR fortran/122521 gcc/fortran/ChangeLog: * trans-descriptor.h (gfc_set_descriptor_from_scalar, gfc_set_descriptor_from_scalar_class): Remove expression argument. * trans-descriptor.cc (gfc_set_descriptor_from_scalar_class): (gfc_set_descriptor_from_scalar): Ditto. Explicitly unwrap element type if it's pointer-typed. Use gfc_get_dtype_rank_type instead of gfc_get_dtype. Remove scalar descriptor type creation. * trans-expr.cc (gfc_conv_derived_to_class, gfc_conv_class_to_class): Update callers. Diff: --- gcc/fortran/trans-descriptor.cc | 16 ++++++++-------- gcc/fortran/trans-descriptor.h | 5 ++--- gcc/fortran/trans-expr.cc | 4 ++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc index 534e9fe88dc8..f6af3d2a8cfc 100644 --- a/gcc/fortran/trans-descriptor.cc +++ b/gcc/fortran/trans-descriptor.cc @@ -858,17 +858,18 @@ gfc_create_null_actual_descriptor (stmtblock_t *block, gfc_typespec *ts, assumed-rank dummy argument. */ void -gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, - tree scalar, gfc_expr *scalar_expr, +gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree scalar, tree cond_presence, tree caf_token) { if (flag_coarray == GFC_FCOARRAY_LIB && caf_token) gfc_conv_descriptor_token_set (block, descr, caf_token); - tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar), - gfc_expr_attr (scalar_expr)); + tree scalar_type = TREE_TYPE (scalar); + tree etype = POINTER_TYPE_P (scalar_type) + ? TREE_TYPE (scalar_type) + : scalar_type; gfc_conv_descriptor_dtype_set (block, descr, - gfc_get_dtype (type)); + gfc_get_dtype_rank_type (0, etype)); gfc_copy_coarray_desc_part (block, descr, scalar); if (cond_presence) scalar = build3_loc (input_location, COND_EXPR, @@ -910,11 +911,10 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree scalar) void gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr, - tree scalar, gfc_expr *scalar_expr) + tree scalar) { tree tmp = gfc_class_data_get (scalar); - gfc_set_descriptor_from_scalar (block, descr, tmp, scalar_expr, NULL_TREE, - NULL_TREE); + gfc_set_descriptor_from_scalar (block, descr, tmp, NULL_TREE, NULL_TREE); } diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h index 2154411602da..9ccae12e11c6 100644 --- a/gcc/fortran/trans-descriptor.h +++ b/gcc/fortran/trans-descriptor.h @@ -73,10 +73,9 @@ tree gfc_create_unallocated_library_result_descriptor (stmtblock_t *, tree, tree gfc_create_null_actual_descriptor (stmtblock_t *, gfc_typespec *, symbol_attribute, int); -void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, gfc_expr *, - tree, tree); +void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, tree, tree); void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree); -void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr *); +void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree); tree gfc_conv_descriptor_size (tree, int); tree gfc_conv_descriptor_cosize (tree, int, int); diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 7338cf2b97ff..84da2aa600c6 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -896,7 +896,7 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, gfc_symbol *fsym, /* Scalar to an assumed-rank array. */ if (fsym->ts.u.derived->components->as) gfc_set_descriptor_from_scalar (&parmse->pre, ctree, parmse->expr, - e, cond_optional, caf_token); + cond_optional, caf_token); else { tmp = fold_convert (TREE_TYPE (ctree), parmse->expr); @@ -1324,7 +1324,7 @@ gfc_conv_class_to_class (gfc_se *parmse, gfc_expr *e, gfc_typespec class_ts, && e->rank != class_ts.u.derived->components->as->rank) { if (e->rank == 0) - gfc_set_descriptor_from_scalar_class (&block, ctree, parmse->expr, e); + gfc_set_descriptor_from_scalar_class (&block, ctree, parmse->expr); else gfc_class_array_data_assign (&block, ctree, parmse->expr, false); }