This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Optimize concatenation space usage


This patch improves on the previous concatenation work by avoiding
unwanted code space increase at -O0 for the common case of string
concatenation. This is done by calling out of line routines. These
calls are also done in -Os mode, and Opt.Optimize_Size is added to
allow checking for -Os.

The following test

with Text_IO; use Text_IO;
procedure Concatspace is
   X : String (1 .. 11);
   Y : String (1 .. 5) := "world";
begin
   X := Y & ' ' & "hello";
   Put_Line (X);
end Concatspace;

compiled with -gnatG -O0 generates

with text_io;
use text_io;
with system.system__concat_3;

procedure concatspace is
   subtype concatspace__TxS is string (1 .. 11);
   x : string (1 .. 11);
   subtype concatspace__TyS is string (1 .. 5);
   y : string (1 .. 5) := "world";
begin
   subtype concatspace__TS3bS is string (1 .. 11);
   S3b : string (1 .. 11);
   $system__concat_3__str_concat_3 (S3b, y, " ", "hello");
   x := S3b;
   ada__text_io__put_line__2 (x);
   return;
end concatspace;

and compiled with -gnatG -O2 generates:

with text_io;
use text_io;

procedure concatspace is
   subtype concatspace__TxS is string (1 .. 11);
   x : string (1 .. 11);
   subtype concatspace__TyS is string (1 .. 5);
   y : string (1 .. 5) := "world";
begin
   subtype concatspace__TS3bS is string (1 .. 11);
   S3b : string (1 .. 11);
   S3b (1 .. 5) := y;
   S3b (6) := ' ';
   S3b (7 .. 11) := "hello";
   x := S3b;
   ada__text_io__put_line__2 (x);
   return;
end concatspace;

The output in both cases is

world hello

Tested on x86_64-pc-linux-gnu, committed on trunk

2009-04-16  Robert Dewar  <dewar@adacore.com>

	* Makefile.rtl: Add entries for s-conca?

	* debug.adb: Add debug flags -gnatd.c and -gnatd.C to control behavior
	of concatenation expansion

	* exp_ch4.adb (Expand_Concatenation): Generate calls for certain
	string cases instead of expanding assignments inline.

	* opt.ads (Optimize_Size): New flag

	* s-conca2.ads, s-conca2.adb, s-conca3.adb, s-conca3.ads,
	s-conca4.adb, s-conca4.ads, s-conca5.adb, s-conca5.ads, s-conca6.adb,
	s-conca6.ads, s-conca7.ads, s-conca7.adb, s-conca8.adb, s-conca8.ads,
	s-conca9.adb, s-conca9.ads: New file.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]