Denis Koroskin wrote:
On Wed, 20 May 2009 13:09:37 +0400, Kagamin <s...@here.lot> wrote:
BCS Wrote:
smaller object code? OTOH a good implementation will noice when I can
fold
together several template expansions
That's the difference. You can't fold templates because they're binary
incompatible as opposite to generics.
You can fold /some/ templates. I believe LLVM already does merging of identical
functions (including templates, virtual functions etc) as a part of
optimization process. Not sure about LDC, though.
LLVM has a function merging pass, but LDC doesn't run it by default at any
optimization level. (You can pass -mergefunc to run it explicitly, as with any
LLVM pass)
It has some limitations though. Since it runs on IR, it matters what LLVM type
values have. That means it might merge Templ!(int) and Templ!(uint) since int
and uint are both an i32 to LLVM, but it normally wouldn't merge Templ!(int*)
and Templ(short*) even if the template compiles down to "return cast(T)
somefunc(cast(void*) arg);" because the types are still different (i32* vs i16*).
To do the latter transformation, the pass would need to be reimplemented to run
when the code is closer to machine code.