[PATCH,committed] fortran: Replace large structs as function parameters by references [PR124259]

Harald Anlauf <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
Dear all,

the attached simple patch is a small performance improvement.
It replaces large structs passed by value by const references in
two places as suggested by cppcheck.

Regtested on x86_64-pc-linux-gnu, OK'd in the PR by David Binderman,
and pushed as r16-8251-g15bccf4412d7ae .

Thanks,
Harald
pr124259.diff (text/x-patch, 3.2 KB)
From 15bccf4412d7ae99ee448420b6deccd88081bcab Mon Sep 17 00:00:00 2001
From: Harald Anlauf <[email protected]>
Date: Sun, 22 Mar 2026 21:58:37 +0100
Subject: [PATCH] fortran: Replace large structs as function parameters by
 references [PR124259]

Large structs passed by value as function parameters can be replaced by
const references to improve performance.

	PR fortran/124259

gcc/fortran/ChangeLog:

	* target-memory.cc (gfc_merge_initializers): Change struct
	gfc_typespec argument into a const reference.
	* target-memory.h (gfc_merge_initializers): Adjust prototype.
	* trans.cc (gfc_finalize_tree_expr): Change struct symbol_attribute
	argument into a const reference.
	* trans.h (gfc_finalize_tree_expr): Adjust prototype.
---
 gcc/fortran/target-memory.cc | 2 +-
 gcc/fortran/target-memory.h  | 2 +-
 gcc/fortran/trans.cc         | 2 +-
 gcc/fortran/trans.h          | 3 ++-
 4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/target-memory.cc b/gcc/fortran/target-memory.cc
index 08180b59908..cf1bfa87950 100644
--- a/gcc/fortran/target-memory.cc
+++ b/gcc/fortran/target-memory.cc
@@ -737,7 +737,7 @@ expr_to_char (gfc_expr *e, locus *loc,
    the union declaration.  */
 
 size_t
-gfc_merge_initializers (gfc_typespec ts, gfc_expr *e, locus *loc,
+gfc_merge_initializers (const gfc_typespec &ts, gfc_expr *e, locus *loc,
 			unsigned char *data,
 			unsigned char *chk, size_t length)
 {
diff --git a/gcc/fortran/target-memory.h b/gcc/fortran/target-memory.h
index 5463510f537..bbb5789068f 100644
--- a/gcc/fortran/target-memory.h
+++ b/gcc/fortran/target-memory.h
@@ -44,7 +44,7 @@ int gfc_interpret_derived (unsigned char *, size_t, gfc_expr *);
 size_t gfc_target_interpret_expr (unsigned char *, size_t, gfc_expr *, bool);
 
 /* Merge overlapping equivalence initializers for trans-common.cc. */
-size_t gfc_merge_initializers (gfc_typespec, gfc_expr *, locus *,
+size_t gfc_merge_initializers (const gfc_typespec &, gfc_expr *, locus *,
 			       unsigned char *, unsigned char *,
 			       size_t);
 
diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index dc74819cced..1d7006a6963 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -1609,7 +1609,7 @@ gfc_assignment_finalizer_call (gfc_se *lse, gfc_expr *expr1, bool init_flag)
 
 void
 gfc_finalize_tree_expr (gfc_se *se, gfc_symbol *derived,
-			symbol_attribute attr, int rank)
+			const symbol_attribute &attr, int rank)
 {
   tree vptr, final_fndecl, desc, tmp, size, is_final;
   tree data_ptr, data_null, cond;
diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h
index f5359e4131d..f97fefd2ac0 100644
--- a/gcc/fortran/trans.h
+++ b/gcc/fortran/trans.h
@@ -457,7 +457,8 @@ tree gfc_get_vptr_from_expr (tree);
 tree gfc_copy_class_to_class (tree, tree, tree, bool);
 bool gfc_add_finalizer_call (stmtblock_t *, gfc_expr *, tree = NULL_TREE);
 bool gfc_add_comp_finalizer_call (stmtblock_t *, tree, gfc_component *, bool);
-void gfc_finalize_tree_expr (gfc_se *, gfc_symbol *, symbol_attribute, int);
+void gfc_finalize_tree_expr (gfc_se *, gfc_symbol *, const symbol_attribute &,
+			     int);
 bool gfc_assignment_finalizer_call (gfc_se *, gfc_expr *, bool);
 
 void gfc_class_array_data_assign (stmtblock_t *, tree, tree, bool);
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.