Stealing ideas from the latest GCC release
Johan Tibell
johan.tibell at gmail.com
Thu Mar 22 22:09:15 CET 2012
Hi all,
While looking at the GCC 4.7 [1] release notes I saw something that's
perhaps worth stealing. Taken from the release notes:
The inter-procedural constant propagation pass has been rewritten. It
now performs generic function specialization. For example when
compiling the following:
void foo(bool flag)
{
if (flag)
... do something ...
else
... do something else ...
}
void bar (void)
{
foo (false);
foo (true);
foo (false);
foo (true);
foo (false);
foo (true);
}
GCC will now produce two copies of foo. One with flag being true,
while other with flag being false. This leads to performance
improvements previously possibly only by inlining all calls. Cloning
causes a lot less code size growth.
I found myself wanting something like this just today. A common
pattern I see in code is this:
data Options = Options { ... }
defaultOptions :: Options
defaultOptions = ...
foo :: ...
foo = fooWith defaultOptions
fooWith :: Options -> ...
fooWith = ...
It'd be nice if we could get foo to specialize on its input arguments,
without having to mark all of fooWith as INLINE.
1. http://gcc.gnu.org/gcc-4.7/changes.html
-- Johan
More information about the Glasgow-haskell-users
mailing list