<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 27, 2019 at 6:29 AM Lubos Lunak <<a href="mailto:l.lunak@centrum.cz">l.lunak@centrum.cz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Let me merge answers to various parts into one mail:<br>
<br>
On Sunday 26 of May 2019, Richard Smith wrote:<br>
> This seems like a nice idea, and has a lot in common with our existing<br>
> "modular codegen" mode, which does largely the same thing but for PCMs<br>
> rather than PCHs. I'd hope we could share a lot of the implementation<br>
> between the two features.<br>
<br>
The core of my patch is basically an if statement in <br>
Sema::InstantiateFunctionDefinition() that decides whether to bail out and <br>
avoid doing something that'd eventually get thrown away anyway, so speaking <br>
of sharing implementation is probably bit of a stretch. Unless you mean that <br>
the problem should be rather handled by changing how PCHs internally work, <br>
which I have no idea about.<br>
<br>
On Monday 27 of May 2019, David Blaikie via cfe-dev wrote:<br>
> Though do you know if/how any of this could account for /more/ time spent<br>
> with pending instantiations with a PCH than without? (assuming the same<br>
> headers are included - and that's perhaps where the assumption is<br>
> incorrect/flawed, perhaps in Lubos's case the PCH is being added in<br>
> addition to the headers used in the non-PCH build, rather than instead of)<br>
<br>
That assumption is indeed incorrect. E.g. for libsclo we have <br>
precompiled_sc.hxx, which contains everything that makes sense to be in PCH <br>
for the library. And it is used as -include-pch precompiled_sc.hxx.pch, but <br>
only if PCH is enabled. That's the reasonable way to use it, except for MSVC <br>
PCHs are not considered worth it and so are not enabled by default, and it <br>
doesn't make sense to include more than necessary in the non-PCH case. So the <br>
increase in time spent in PerformPendingInstantiations() is (AFAICT) caused <br>
solely by the PCH bringing in more stuff. Presumably if we used <br>
precompiled_sc.hxx unconditionally we'd always have this cost.<br></blockquote><div><br>Ah, OK. Good to understand.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
On Sunday 26 of May 2019, David Blaikie wrote:<br>
> Lubos: Could you provide a small standalone example of this increase in<br>
> pending instantiations so it's a bit easier for me to understand the kind<br>
> of code & what's happening?<br>
<br>
$ cat a.cpp<br>
// empty source file<br>
$ cat a.h<br>
#include <vector><br>
struct F<br>
{<br>
std::vector< char > c;<br>
int size() { return c.size(); }<br>
};<br>
$ ... make Clang print info in Sema::InstantiateFunctionDefinition() ...<br>
$ clang++ -Wall -c a.cpp<br>
[nothing]<br>
$ clang++ -Wall -c a.cpp -include a.h<br>
INST:std::_Hash_impl::hash<br>
INST:std::_Hash_impl::hash<br>
INST:std::vector<char, std::allocator<char> >::size<br>
<br>
You get the same with -include-pch a.h.pch . Also, I'm on Linux, so this is <br>
libstdc++, but I assume it'll be similar with libc++.<br>
<br>
The important thing to note is that the resulting object file is the same in <br>
both cases, the instantiated functions eventually get thrown away. But Clang <br>
has to spend time processing that, and as you can see in the -ftime-trace <br>
graphs that can get very costly.<br></blockquote><div><br>OK. <br><br>So I'm not sure I understand this comment:<br><br>"<span style="font-family:Arial,Tahoma,Helvetica,FreeSans,sans-serif;font-size:13.2px">And, if you look carefully, 4 seconds more to generate code, most of it for those templates. And after the compiler spends all this time on templates in all the source files, it gets all passed to the linker, which will shrug and then throw most of it away (and that will too take a load of time, if you still happen to use the BFD linker instead of </span><a href="https://lists.freedesktop.org/archives/libreoffice/2018-July/080484.html" style="text-decoration-line:none;color:rgb(136,136,136);font-family:Arial,Tahoma,Helvetica,FreeSans,sans-serif;font-size:13.2px">gold/lld</a><span style="font-family:Arial,Tahoma,Helvetica,FreeSans,sans-serif;font-size:13.2px"> with </span><a href="https://lists.freedesktop.org/archives/libreoffice/2018-June/080437.html" style="text-decoration-line:none;color:rgb(136,136,136);font-family:Arial,Tahoma,Helvetica,FreeSans,sans-serif;font-size:13.2px">-gsplit-dwarf -Wl,--gdb-index</a><span style="font-family:Arial,Tahoma,Helvetica,FreeSans,sans-serif;font-size:13.2px">). What a marvel."<br></span><br>What extra code generation occurred with the PCH? Any change in generated code with a PCH would surprise me.<br><br>- Dave<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
-- <br>
Lubos Lunak<br>
</blockquote></div></div>