totally folding string operations

Nathan Myers ncm-nospam@cantrip.org
Thu Sep 30 03:26:00 GMT 2004


On Thu, Sep 30, 2004 at 04:48:13AM +0200, Giovanni Bajo wrote:
> Hello,
> 
> I am investigating the fesability of totally folding constant string
> operations at compile time. 
> ...
> 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().

We can overload constructors and operators that take a literal array 
argument.  It seems as if there are many optimizations remaining to 
be done purely at the library level by overloading on string literals.  
(In the next revision of the standard, we may expect better support 
for non-string array literals.)  For example, looping operations may 
be simpler when we know that the argument is word-aligned, and the 
number of iterations is fixed.  

Unrolling the loop, then (either at library or compiler level), the 
optimizer might recognize array accesses to a constant literal string 
and substitute the literal values directly.  Would this approach
improve a wider variety of programs than optimizations tuned for a 
few particular operations on string literals?

Nathan Myers
ncm@cantrip.org



More information about the Libstdc++ mailing list