[COMMITTED] algol68: optimize a68_low_dup for non-row values that do not contain rows
Jose E. Marchesi
jemarch@gnu.org
Sat May 3 14:26:08 GMT 2025
---
gcc/algol68/a68-low.cc | 58 +++++++++++++++++++++---------------------
1 file changed, 29 insertions(+), 29 deletions(-)
diff --git a/gcc/algol68/a68-low.cc b/gcc/algol68/a68-low.cc
index f54158bb26c..04da444609f 100644
--- a/gcc/algol68/a68-low.cc
+++ b/gcc/algol68/a68-low.cc
@@ -474,9 +474,8 @@ a68_low_dup (tree expr, bool use_heap)
}
else
{
- /* We calculate num_elems by dividing new_elements_size by the byte
- size of the type of the elements. This includes elements that are
- not accessible due to trimming. */
+ /* Note that num_elems includes elements that are not accessible due
+ to trimming. */
tree num_elems = a68_lower_tmpvar ("numelems%", size_type_node,
fold_build2 (TRUNC_DIV_EXPR, sizetype,
new_elements_size,
@@ -537,35 +536,35 @@ a68_low_dup (tree expr, bool use_heap)
new_elements,
new_elements_size);
}
+ else if (!HAS_ROWS (m))
+ {
+ /* Non-multiple values that do not contain rows do not need to be dupped,
+ since they can be just moved around using the semantics of
+ MODIFY_EXPR. */
+ dup = expr;
+ }
else if (A68_STRUCT_TYPE_P (type))
{
- if (TREE_CONSTANT (expr))
- /* Copying the array descriptor is enough, it can share the constant
- elements with the original arrays. */
- dup = expr;
- else
+ /* Since struct value can contain multiples and unions and other values
+ that require deep copy, we cannot simply rely on the C semantics of a
+ MODIFY_EXPR. */
+ tree struct_type = type;
+ vec <constructor_elt, va_gc> *ce = NULL;
+
+ expr = save_expr (expr);
+ for (tree field = TYPE_FIELDS (struct_type);
+ field;
+ field = TREE_CHAIN (field))
{
- /* Since struct value can contain multiples and unions and other
- values that require deep copy, we cannot simply rely on the C
- semantics of a MODIFY_EXPR. */
- tree struct_type = type;
- vec <constructor_elt, va_gc> *ce = NULL;
-
- expr = save_expr (expr);
- for (tree field = TYPE_FIELDS (struct_type);
- field;
- field = TREE_CHAIN (field))
- {
- CONSTRUCTOR_APPEND_ELT (ce, field,
- a68_low_dup (fold_build3 (COMPONENT_REF,
- TREE_TYPE (field),
- expr,
- field,
- NULL_TREE),
- use_heap));
- }
- dup = build_constructor (struct_type, ce);
+ CONSTRUCTOR_APPEND_ELT (ce, field,
+ a68_low_dup (fold_build3 (COMPONENT_REF,
+ TREE_TYPE (field),
+ expr,
+ field,
+ NULL_TREE),
+ use_heap));
}
+ dup = build_constructor (struct_type, ce);
}
else if (A68_UNION_TYPE_P (type))
{
@@ -629,7 +628,8 @@ a68_low_dup (tree expr, bool use_heap)
dup = a68_pop_range ();
}
else
- dup = expr;
+ /* Not an Algol 68 value. */
+ gcc_unreachable ();
return dup;
}
--
2.30.2
More information about the Algol68
mailing list