[cfe-dev] Module build - tokenized form of intermediate source stream

Sean Silva via cfe-dev cfe-dev at lists.llvm.org
Mon Oct 12 19:52:55 PDT 2015


On Mon, Oct 12, 2015 at 12:13 PM, Richard Smith via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> On Mon, Oct 12, 2015 at 11:33 AM, Serge Pavlov via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
>> Hi all,
>>
>> Now building a module involves creation of intermediate source streams
>> that includes/imports each header composing the  module. This source stream
>> is then parsed as if it were a source file. So to build a module several
>> transformations must be done:
>> - Module map is parsed to produce module objects(clang::Module),
>> - Module objects are used to build source stream (llvm::MemoryBuffer),
>> which contains include directives,
>> - The source stream is parsed to produce module content.
>>
>> The build process could be simpler, if instead of text source stream we
>> prepared a sequence of annotation tokens, annot_module_begin,
>> annot_module_end and some new token, say annot_module_header, which
>> represented a header of a module. It would be something like pretokenized
>> header but without a counterpart in file system.
>>
>> Such redesign would help in solving performance degradation reported in
>> PR24667 ([Regression] Quadratic module build time due to
>> Preprocessor::LeaveSubmodule). The reason of the problem is leaving module
>> after each header, even if the next header is of the same module.
>>
>
> We generally recommend that each header goes in its own submodule, so
> optimizing for this case doesn't address the problem for a lot of cases.
>

The "one huge submodule" approach with no local visibility is actually very
useful to have because it (for better or for worse) is very close to the
semantics of PCH (which are very simple). This makes it a nice incremental
step away from PCH and very easy to understand.

Also, I think "we generally recommend" is a bit strong considering that
this isn't documented anywhere to my knowledge. In fact, the documentation
I've written internally for my customers recommends the exact opposite for
the reason described above.

-- Sean Silva


>
> Leaving module after the last header would be a solution but it is
>> problematic to reveal if the header just parsed is the last one, - there is
>> no such thing as look ahead of the next include directive. Using tokenized
>> input would mark module ends easily.
>>
>
> I have a different approach in mind for that case: namely, to produce a
> separate submodule state for distinct submodules even when not in local
> visibility mode, and lazily populate its Macros map when identifiers are
> queried. That way, the performance is linear in the number of macros the
> submodule actually defines or uses, not in the total number defined or used
> by the top-level module.
>
>
>> Is there any reason why textual form of the intermediate source stream
>> should be kept? Does implementing tokenized form of it make sense?
>>
>> Thanks,
>> --Serge
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151012/e1abfaf3/attachment.html>


More information about the cfe-dev mailing list