]> git.ipfire.org Git - thirdparty/gcc.git/commit
[Ada] Use static stack allocation for small dynamic string concatenations
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 27 May 2022 13:28:29 +0000 (15:28 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 4 Jul 2022 07:45:58 +0000 (07:45 +0000)
commit2cad8a59a8060b0897d18d4075d96eb7c541e845
treea27d06b646a7a93c8c3ec1620d04dde3cc45fdd9
parentf3451ba8aa3a54c6f09ee049a1a406603ed2ec30
[Ada] Use static stack allocation for small dynamic string concatenations

This changes the expanded code generated for dynamic concatenations to
use a static array subtype for the temporary created on the stack if a
small upper bound can be computed for the length of the result.  Static
stack allocation is preferred over dynamic allocation for code
generation purposes.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration.Rewrite_As_Renaming):
Be prepared for slices.
* exp_ch4.adb (Get_First_Index_Bounds): New procedure.
(Expand_Array_Comparison.Length_Less_Than_4): Call it.
(Expand_Concatenate): Try to compute a maximum length for
operands with variable length and a maximum total length at the
end.  If the concatenation is dynamic, but a sensible maximum
total length has been computed, use this length to create a
static array subtype for the temporary and return a slice of it.
gcc/ada/exp_ch3.adb
gcc/ada/exp_ch4.adb