<div dir="ltr"><div dir="ltr">Hi Alex,</div><div dir="ltr"><br><div>Sorry for the late reply here.</div><div>This seems like a very useful tool, that (at least in the current implementation) comes at the cost of adding complexity to various layers of clang.</div><div>Is the 10x speedup vs invoking the preprocessor programmatically? That indeed seems like a lot. What is the performance target (e.g. is that speed up just nice-to-have, is it sufficient, are further wins needed?). Did you measure what running the preprocessor directly buys you? (Your prototype runs Eonly by invoking clang in a subshell through the driver).</div><div><br></div><div>The design seems to leave headroom in a couple of dimensions:</div><div> - performance: avoiding reprocessing files (in any capacity) could in principle be a pretty big win, as the average number of transitive includers scales somewhat with codebase size</div><div> - complexity: the full power of the lexer/preprocessor system is not needed for the vast majority of include-scanning cases. (This also impacts performance).</div><div><br></div><div>How important is it that scanning is precise w.r.t preprocessor state (e.g. #ifdef'd out headers are not considered dependencies), and accurate in edge cases (#include SOME_MACRO)? Do you have any measurements on how often these scenarios occur?</div><div><br></div><div>> We also would like to integrate this service into Clangd as part of our migration to Clangd to help us determine a good compilation command for a header file from a set of known compilation invocations.</div><div>We introduced a heuristic approach to this (simply examining filenames to find a decent match) into Tooling as a CompilationDatabase, it would be great if it's possible to do something similar with dep scanning so it's reusable by other tools and layering is preserved.</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 17, 2018 at 3:54 AM Alex L via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue"">Hi,</p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue";min-height:14px"><br></p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue"">Bruno (CCed), Duncan (CCed) and I have been exploring if we can migrate some of our clients to explicit modules. As part of this work Duncan and I developed a new prototype dependency scanning service tool (clang-scan-deps) that computes the set of file dependencies for a particular compiler invocation using some optimizations that are outlined below. This tool makes the non-modular dependency scanning up to 10 times faster for particular workloads (e.g. llc target, 1542 C++ files) on one of our machines, when compared to parallel invocations of clang with -Eonly. We are still in the early stages of proper modules support, but our initial crude prototype can get up to 4x when run on the first 1000 files from clang’s compilation database for a build of LLVM with modules turned on.</p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue";min-height:14px"><br></p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue"">We still run the full Clang preprocessor. Here’s what we do to reduce its workload:</p>
<ul>
<li style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue"">Minimize sources by stripping away unused tokens. We keep only the interesting PP directives (#define, #if, #include, etc.), i.e. those that might impact the set of dependencies. </li>
<li style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue"">Assume the filesystem is immutable for one run of the service, and cache the files and their minimized contents in memory in a global cache.</li>
<li style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue"">Skip over excluded preprocessor ranges by bumping up the buffer pointer in the lexer instead of lexing the skipped tokens.</li>
</ul>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue";min-height:14px"><br></p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue"">We intend to upstream this service in the upcoming months. We also would like to integrate this service into Clangd as part of our migration to Clangd to help us determine a good compilation command for a header file from a set of known compilation invocations.</p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue";min-height:14px"><br></p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue"">I posted a very rough WIP patch on Phabricator (<a href="https://reviews.llvm.org/D53354" target="_blank"><span style="color:rgb(220,161,13)">https://reviews.llvm.org/D53354</span></a>). It’s based on LLVM checkout r343343. Please take a look if you’re interested.</p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue"">Duncan, Bruno and I will be at the LLVM dev meeting. We are interested in discussing this prototype and collecting feedback from anyone who might be interested in this work.</p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue";min-height:14px"><br></p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue"">Thanks,</p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue"">Alex</p></div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>