[cfe-dev] Controlling instantiation of templates from PCH

Lubos Lunak via cfe-dev cfe-dev at lists.llvm.org
Sat Jul 6 05:28:20 PDT 2019


On Tuesday 18 of June 2019, David Blaikie wrote:
> I'm getting a bit confused by the layers of this thread, so I'll see if I
> can sum up my understanding & see if that's any use.
>
> Currently there's a difference between PCH and Clang Header Modules
> semantics with regard to pending instantiations
> In PCH, pending instantiations are all performed at any use of the PCH.
> In modules pending instantiations are done at the end of building the
> header module (so they're performed once).
> This difference is the cause of the original compile time cost you were
> investigating (somewhat independent of the duplicate code in object files)


 Yes (I don't know about modules, but presumably those parts are correct too).

> So, step 1) perhaps we can just remove the PCH mode ^ here, and do the
> header module thing (perform pending instantiations at the end of building
> the PCH) for PCH as well.
> If you want to do this ^ work,


 Theoretically yes, but in practice no. Besides what Ilya Biryukov commented, 
this would also prevent the case of instantiating those templates only in the 
PCH's object file, and I consider that approach to be a better one.

> Separate from that, there's some desire to be able to build an object file
> from a PCH to remove duplicate template instantiations in object files.
> (reducing compile time, reducing object size, maybe reducing link time).
> To do this - it sounds like there's already a flag (-building-pch-with-obj)
> for building PCHs that will have a separate object file.

 Yes.

> I've no idea what 
> this flag does today - does it already do what you want in terms of moving
> template instantiations and inline functions into that object? Or does it
> do something else (what else?)?


 The flag marks the PCH with a flag that the PCH comes with an object file and 
that's it. Code in Clang then can check the flag and act based on that. 
Currently it is used only for avoiding repeatedly emitting exported inline 
functions (https://reviews.llvm.org/D48426).

> If it doesn't do what you want already, and 
> you want to extend it to do what you want - yes, I'd recommend
> piggy-backing on the exsiting Clang Header Modules modular code generation
> features for this.


 I think taking Clang Header Modules into this is a needless complication. My 
patch is basically a glorified "if(special_condition) skip_instantiating;".


> & yes, potentially the pending instantiations could be moved over from the
> PCH-or-header-module generation step, to the PCH-or-header-module->Object
> step. (to benefit both PCH and header modules)


 I have updated my patch, made it based on -building-pch-with-obj and resolved 
some issues: https://reviews.llvm.org/D64284 . It is now capable of handling 
an entire LibreOffice debug build. I still need help with some of the 
problems described in the review submission summary.

>  (to benefit both PCH and header modules)


 Sorry, but I still have no idea how header modules are actually related to my 
patch.

-- 
 Lubos Lunak



More information about the cfe-dev mailing list