diff options
author | Alex Lorenz <arphaman@gmail.com> | 2019-09-11 20:40:31 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2019-09-11 20:40:31 +0000 |
commit | 2f84230495c48ff3c1374151ce35a6c0a54ad01e (patch) | |
tree | be335ae9f499dbbe2db0326747589630ee7c70de /unittests/Lex | |
parent | f5d449a52774ee2e43614ab6cffd5408247a598b (diff) | |
download | clang-2f84230495c48ff3c1374151ce35a6c0a54ad01e.tar.gz |
[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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@371656 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Lex')
-rw-r--r-- | unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp b/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp index 8770050c86..530519573a 100644 --- a/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp +++ b/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp @@ -617,4 +617,46 @@ ort \ minimize_source_to_dependency_directives::cxx_module_decl); } +TEST(MinimizeSourceToDependencyDirectivesTest, SkippedPPRangesBasic) { + SmallString<128> Out; + SmallVector<Token, 32> Toks; + StringRef Source = "#ifndef GUARD\n" + "#define GUARD\n" + "void foo();\n" + "#endif\n"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out, Toks)); + SmallVector<SkippedRange, 4> Ranges; + ASSERT_FALSE(computeSkippedRanges(Toks, Ranges)); + EXPECT_EQ(Ranges.size(), 1u); + EXPECT_EQ(Ranges[0].Offset, 0); + EXPECT_EQ(Ranges[0].Length, (int)Out.find("#endif")); +} + +TEST(MinimizeSourceToDependencyDirectivesTest, SkippedPPRangesNested) { + SmallString<128> Out; + SmallVector<Token, 32> Toks; + StringRef Source = "#ifndef GUARD\n" + "#define GUARD\n" + "#if FOO\n" + "#include hello\n" + "#elif BAR\n" + "#include bye\n" + "#endif\n" + "#else\n" + "#include nothing\n" + "#endif\n"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out, Toks)); + SmallVector<SkippedRange, 4> Ranges; + ASSERT_FALSE(computeSkippedRanges(Toks, Ranges)); + EXPECT_EQ(Ranges.size(), 4u); + EXPECT_EQ(Ranges[0].Offset, (int)Out.find("#if FOO")); + EXPECT_EQ(Ranges[0].Offset + Ranges[0].Length, (int)Out.find("#elif")); + EXPECT_EQ(Ranges[1].Offset, (int)Out.find("#elif BAR")); + EXPECT_EQ(Ranges[1].Offset + Ranges[1].Length, (int)Out.find("#endif")); + EXPECT_EQ(Ranges[2].Offset, 0); + EXPECT_EQ(Ranges[2].Length, (int)Out.find("#else")); + EXPECT_EQ(Ranges[3].Offset, (int)Out.find("#else")); + EXPECT_EQ(Ranges[3].Offset + Ranges[3].Length, (int)Out.rfind("#endif")); +} + } // end anonymous namespace |