This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: totally folding string operations
- From: Loren James Rittle <rittle at latour dot waar dot labs dot mot dot com>
- To: libstdc++ at gcc dot gnu dot org
- Cc: giovannibajo at libero dot it
- Date: Wed, 29 Sep 2004 22:21:02 -0500 (CDT)
- Subject: Re: totally folding string operations
- Organization: Applications, Content and Services CoE (IL02/2240), Motorola Labs
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