diff options
author | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2022-06-08 00:54:05 -0700 |
---|---|---|
committer | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2022-06-08 23:13:39 -0700 |
commit | e6a76a49356efd11f5f36690181f0f60cecb2e01 (patch) | |
tree | 08e38876d4b206eb9af2102a7261755199c5c8fd /clang/lib/CodeGen/CoverageMappingGen.cpp | |
parent | a4c97e19379972ca0eed1b11fc76a03b2ba19504 (diff) | |
download | llvm-e6a76a49356efd11f5f36690181f0f60cecb2e01.zip llvm-e6a76a49356efd11f5f36690181f0f60cecb2e01.tar.gz llvm-e6a76a49356efd11f5f36690181f0f60cecb2e01.tar.bz2 |
[Clang][CoverageMapping] Fix compile time explosions by adjusting only appropriated skipped ranges
D83592 added comments to be part of skipped regions, and as part of that, it
also shrinks a skipped range if it spans a line that contains a non-comment
token. This is done by `adjustSkippedRange`.
The `adjustSkippedRange` currently runs on skipped regions that are not
comments, causing a 5min regression while building a big C++ files without any
comments.
Fix the compile time introduced in D83592 by tagging SkippedRange with kind
information and use that to decide what needs additional processing.
Differential Revision: https://reviews.llvm.org/D127338
Diffstat (limited to 'clang/lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r-- | clang/lib/CodeGen/CoverageMappingGen.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 8952125..d1cbe10 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -60,26 +60,27 @@ CoverageMappingModuleGen::setUpCoverageCallbacks(Preprocessor &PP) { return CoverageInfo; } -void CoverageSourceInfo::AddSkippedRange(SourceRange Range) { +void CoverageSourceInfo::AddSkippedRange(SourceRange Range, + SkippedRange::Kind RangeKind) { if (EmptyLineCommentCoverage && !SkippedRanges.empty() && PrevTokLoc == SkippedRanges.back().PrevTokLoc && SourceMgr.isWrittenInSameFile(SkippedRanges.back().Range.getEnd(), Range.getBegin())) SkippedRanges.back().Range.setEnd(Range.getEnd()); else - SkippedRanges.push_back({Range, PrevTokLoc}); + SkippedRanges.push_back({Range, RangeKind, PrevTokLoc}); } void CoverageSourceInfo::SourceRangeSkipped(SourceRange Range, SourceLocation) { - AddSkippedRange(Range); + AddSkippedRange(Range, SkippedRange::PPIfElse); } void CoverageSourceInfo::HandleEmptyline(SourceRange Range) { - AddSkippedRange(Range); + AddSkippedRange(Range, SkippedRange::EmptyLine); } bool CoverageSourceInfo::HandleComment(Preprocessor &PP, SourceRange Range) { - AddSkippedRange(Range); + AddSkippedRange(Range, SkippedRange::Comment); return false; } @@ -335,6 +336,8 @@ public: /// This shrinks the skipped range if it spans a line that contains a /// non-comment token. If shrinking the skipped range would make it empty, /// this returns None. + /// Note this function can potentially be expensive because + /// getSpellingLineNumber uses getLineNumber, which is expensive. Optional<SpellingRegion> adjustSkippedRange(SourceManager &SM, SourceLocation LocStart, SourceLocation LocEnd, @@ -382,8 +385,13 @@ public: auto CovFileID = getCoverageFileID(LocStart); if (!CovFileID) continue; - Optional<SpellingRegion> SR = - adjustSkippedRange(SM, LocStart, LocEnd, I.PrevTokLoc, I.NextTokLoc); + Optional<SpellingRegion> SR; + if (I.isComment()) + SR = adjustSkippedRange(SM, LocStart, LocEnd, I.PrevTokLoc, + I.NextTokLoc); + else if (I.isPPIfElse() || I.isEmptyLine()) + SR = {SM, LocStart, LocEnd}; + if (!SR.hasValue()) continue; auto Region = CounterMappingRegion::makeSkipped( |