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]

totally folding string operations


Hello,

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?
-- 
Giovanni Bajo




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