Commit Graph

16 Commits

Author SHA1 Message Date
Reid Kleckner af450eabb9 Avoid including FileSystem.h from MemoryBuffer.h
Lots of headers pass around MemoryBuffer objects, but very few open
them. Let those that do include FileSystem.h.

Saves ~250 includes of Chrono.h & FileSystem.h:

$ diff -u thedeps-before.txt thedeps-after.txt | grep '^[-+] ' | sort | uniq -c | sort -nr
    254 -    ../llvm/include/llvm/Support/FileSystem.h
    253 -    ../llvm/include/llvm/Support/Chrono.h
    237 -    ../llvm/include/llvm/Support/NativeFormatting.h
    237 -    ../llvm/include/llvm/Support/FormatProviders.h
    192 -    ../llvm/include/llvm/ADT/StringSwitch.h
    190 -    ../llvm/include/llvm/Support/FormatVariadicDetails.h
...

This requires duplicating the file_t typedef, which is unfortunate. I
sunk the choice of mapping mode down into the cpp file using variable
template specializations instead of class members in headers.
2020-02-29 12:30:23 -08:00
Alex Lorenz 389530524b [clang-scan-deps] do not skip empty #if/#elif in the minimizer to avoid missing `__has_include` dependencies
This patch makes the minimizer more conservative to avoid missing dependency files that are brought in by __has_include
PP expressions that occur in a condition of an #if/#elif that was previously skipped. The __has_include PP expressions
can be used in an #if/#elif either directly, or through macro expansion, so we can't detect them at the time of minimization.

Differential Revision: https://reviews.llvm.org/D70936
2019-12-02 18:47:22 -08:00
Alex Lorenz a13f0da1d0 [clang-scan-deps] Improve string/character literal skipping
The existing string/character literal skipping code in the
dependency directives source minimizer has two issues:

- It doesn't stop the scanning when a newline is reached before the terminating character,
unlike the lexer which considers the token to be done (even if it's invalid) at the end of the line.

- It doesn't support whitespace between '\' and the newline when looking if the '\' is used as a line continuation character.

This commit fixes both issues.

Differential Revision: https://reviews.llvm.org/D68436

llvm-svn: 374127
2019-10-08 22:42:44 +00:00
Alex Lorenz 15d5f5dd35 [clang-scan-deps] Allow continuation line backslashes followed by whitespace
in the dependency source minimizer

Clang allows continuations that have whitespace between the backslash and the newline.
This patch ensures that the dependency source minimizer can handle the whitespace between
the backslash and the newline when looking for a line continuation.

Differential Revision: https://reviews.llvm.org/D68052

llvm-svn: 373007
2019-09-26 19:28:51 +00:00
Alex Lorenz ccf8d5b829 Fix for stringized function-macro args continued across lines
In case of certain #define'd macros, there's a space just before line continuation
that the minimized-source lexer was missing to include, resulting in invalid stringize.

Patch by: kousikk (Kousik Kumar)

Differential Revision: https://reviews.llvm.org/D67635

llvm-svn: 372360
2019-09-19 22:39:24 +00:00
Alex Lorenz ca6e60971e [clang-scan-deps] add skip excluded conditional preprocessor block preprocessing optimization
This commit adds an optimization to clang-scan-deps and clang's preprocessor that skips excluded preprocessor
blocks by bumping the lexer pointer, and not lexing the tokens until reaching appropriate #else/#endif directive.
The skip positions and lexer offsets are computed when the file is minimized, directly from the minimized tokens.

On an 18-core iMacPro with macOS Catalina Beta I got 10-15% speed-up from this optimization when running clang-scan-deps on
the compilation database for a recent LLVM and Clang (3511 files).

Differential Revision: https://reviews.llvm.org/D67127

llvm-svn: 371656
2019-09-11 20:40:31 +00:00
Alexandre Ganea 57b4e107e4 Re-land [clang-scan-deps] Minimizer: Correctly handle multi-line content with CR+LF line endings
Previously, an #error directive with quoted, multi-line content, along with CR+LF line endings wasn't handled correctly.

Differential Revision: https://reviews.llvm.org/D66556

llvm-svn: 370129
2019-08-28 00:04:06 +00:00
Richard Smith f3f00b2e5e Revert "[clang-scan-deps] Minimizer: Correctly handle multi-line content with CR+LF line endings"
This reverts commit r369986.

This change added a dependency on the 'dos2unix' tool, which is not one
of our accepted test dependencies and may not exist on all machines that
build Clang.

llvm-svn: 370000
2019-08-27 01:06:23 +00:00
Alexandre Ganea e6561e0068 [clang-scan-deps] Skip UTF-8 BOM in source minimizer
Differential Revision: https://reviews.llvm.org/D66511

llvm-svn: 369993
2019-08-27 00:13:52 +00:00
Alexandre Ganea 6137cecf87 [clang-scan-deps] Minimizer: Correctly skip over double slashes in angle bracket #include
Previously, double slashes (//) occurring in angle brackets #include were incorrectly interpreted as comments. eg. #include <dir//file.h>

Differential Revision: https://reviews.llvm.org/D66550

llvm-svn: 369988
2019-08-26 23:28:05 +00:00
Alexandre Ganea 2abca4f06c [clang-scan-deps] Minimizer: Correctly handle multi-line content with CR+LF line endings
Previously, an #error directive with quoted, multi-line content, along with CR+LF line endings wasn't handled correctly.

Differential Revision: https://reviews.llvm.org/D66556

llvm-svn: 369986
2019-08-26 23:19:21 +00:00
Michael J. Spencer 1861f4ea25 [clang-scan-deps] Add minimizer support for C++20 modules.
This only adds support to the minimizer, it doesn't actually capture the dependencies yet.

llvm-svn: 368381
2019-08-09 02:01:10 +00:00
Alex Lorenz 4cd905bdc1 [clang-scan-deps] Dependency directives source minimizer: handle #pragma once
We should re-emit `#pragma once` to ensure the preprocessor will
still honor it when running on minimized sources.

Differential Revision: https://reviews.llvm.org/D64945

llvm-svn: 366509
2019-07-18 22:33:14 +00:00
Alex Lorenz 9a6c17b5b8 [clang-scan-deps] Dependency directives source minimizer:
single quotes are not digit separators after a valid character literal prefix

The single quote character can act as a c++ digit separator.
However, the minimizer shouldn't treat it as such when it's actually following
a valid character literal prefix, like L, U, u, or u8.

Differential Revision: https://reviews.llvm.org/D64525

llvm-svn: 365700
2019-07-10 22:00:59 +00:00
Alex Lorenz bb39f78113 Fix windows build for commit r362459
llvm-svn: 362463
2019-06-03 23:17:21 +00:00
Alex Lorenz 6e2d36b60b Add clang source minimizer that reduces source to directives
that might affect the dependency list for a compilation

This commit introduces a dependency directives source minimizer to clang
that minimizes header and source files to the minimum necessary preprocessor
directives for evaluating includes. It reduces the source down to #define, #include,

The source minimizer works by lexing the input with a custom fast lexer that recognizes
the preprocessor directives it cares about, and emitting those directives in the minimized source.
It ignores source code, comments, and normalizes whitespace. It gives up and fails if seems
any directives that it doesn't recognize as valid (e.g. #define 0).

In addition to the source minimizer this patch adds a
-print-dependency-directives-minimized-source CC1 option that allows you to invoke the minimizer
from clang directly.

Differential Revision: https://reviews.llvm.org/D55463

llvm-svn: 362459
2019-06-03 22:59:17 +00:00