This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Re: totally folding string operations


Giovanni Bajo writes:

> I am investigating the fesability of totally folding constant string
> operations at compile time. For instance, given:

> void foo(void)
> {
>   std::string a("123");
>   std::string b("345");
>   std::cout << a+b << "\n";
> }

> I would like my compiler to be able to generate the equivalent of:

> void foo(void)
> {
>  std::cout << "123456" << "\n";
> }

> By looking at the optimized tree dump of this example, there are two
> major blockers here: the first is that the std::string methods
> involved are not inlined, prolly because they are defined elsewhere
> (right?). The second problem (for later) is that we do heap
> allocations even if we could not do that. An idea here would be to
> construct a new optimizer pass which transforms closed pairs of
> new/delete calls of constant size into alloca().

> Comments?

First thought: This seems like a very special optimizer for a corner
case.  How often would one code the first foo()?

Ah, your second problem.  Now, there is something interesting IMHO
(since it looks like the general problem).  It would be very
interesting indeed to consider a paired compiler & standard library
implementation change which allowed the compiler to detect memory
allocation optimizations based on final context of use.  At least
according to OOPSLA papers circa 2000, escape analysis (and rewrite)
has been applied successfully to large Java programs.

Regards,
Loren


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