> Hi, > > We recently got a bug report for the GCC D compiler frontend which shows that > we > currently don't inline any templated functions. The reason seems to be that > decl_replaceable_p always returns true for D template functions. > > We currently just mark such template function instances using > make_decl_one_only > but this seems to prevent inlining. I've tried to set DECL_COMDAT additionally > and this fixes the inlining problem. Unfortunately it also leads to many > undefined reference errors as we probably don't generate the template > instances > in all translation units as we should. > > So what's the best/preferred way to put out template function instances so > that: > * Instances in different objects files are merged > * GCC can still inline such functions > * Force the instances to be put out, even if they seem to be not used > > How does the C++ frontend handle this?
See logic in cgraph_function_body_availability. When function is weak (that is effect of make_decl_one_only) it will be inlinable only if it is declared inline. This happens to be the case of C++ weaks because of the implicit inline scheme. I suppose we need a flag on DECL saying that declaration is overwritable but all copies of the functions must be semantically equivalent per ABI specification. In that case the function should return AVAIABLE same way as it is doing for DECL_EXTERNAL stuff already. In fact has a comment for long time ??? Does the C++ one definition rule allow us to always return AVAIL_AVAILABLE here? That would be good reason to preserve this bit. */ Honza > > Thanks, > > Johannes.