From 42ceae5e47d3df7dfe5f7953c46ebd919387f9b6 Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Wed, 24 May 2017 15:24:37 +0200 Subject: Clang: Add patch improving reparse performance on windows Patch provides faster preamble loading by improving the handling of diagnostics. Change-Id: I61a79160e0272335d6d4e76478a7a35760cdf9ef Reviewed-by: Marco Bubke --- ...when-translating-diagnostics-in-PCH-files.patch | 25 ----------- ...493_Cache-source-locations-on-PCH-loading.patch | 51 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 25 deletions(-) delete mode 100644 dist/clang/patches/D29755_Cache-FileID-when-translating-diagnostics-in-PCH-files.patch create mode 100644 dist/clang/patches/D33493_Cache-source-locations-on-PCH-loading.patch (limited to 'dist/clang') diff --git a/dist/clang/patches/D29755_Cache-FileID-when-translating-diagnostics-in-PCH-files.patch b/dist/clang/patches/D29755_Cache-FileID-when-translating-diagnostics-in-PCH-files.patch deleted file mode 100644 index 41e7c1d2c3..0000000000 --- a/dist/clang/patches/D29755_Cache-FileID-when-translating-diagnostics-in-PCH-files.patch +++ /dev/null @@ -1,25 +0,0 @@ -diff --git a/tools/clang/lib/Frontend/ASTUnit.cpp b/tools/clang/lib/Frontend/ASTUnit.cpp -index d892996..5148a8b 100644 ---- a/tools/clang/lib/Frontend/ASTUnit.cpp -+++ b/tools/clang/lib/Frontend/ASTUnit.cpp -@@ -2534,6 +2534,8 @@ void ASTUnit::TranslateStoredDiagnostics( - - SmallVector Result; - Result.reserve(Diags.size()); -+ const FileEntry *PreviousFE = nullptr; -+ FileID FID; - for (const StandaloneDiagnostic &SD : Diags) { - // Rebuild the StoredDiagnostic. - if (SD.Filename.empty()) -@@ -2541,7 +2543,10 @@ void ASTUnit::TranslateStoredDiagnostics( - const FileEntry *FE = FileMgr.getFile(SD.Filename); - if (!FE) - continue; -- FileID FID = SrcMgr.translateFile(FE); -+ if (FE != PreviousFE) { -+ FID = SrcMgr.translateFile(FE); -+ PreviousFE = FE; -+ } - SourceLocation FileLoc = SrcMgr.getLocForStartOfFile(FID); - if (FileLoc.isInvalid()) - continue; diff --git a/dist/clang/patches/D33493_Cache-source-locations-on-PCH-loading.patch b/dist/clang/patches/D33493_Cache-source-locations-on-PCH-loading.patch new file mode 100644 index 0000000000..7a781ece28 --- /dev/null +++ b/dist/clang/patches/D33493_Cache-source-locations-on-PCH-loading.patch @@ -0,0 +1,51 @@ +diff --git a/tools/clang/include/clang/Frontend/ASTUnit.h b/tools/clang/include/clang/Frontend/ASTUnit.h +index 04e6dce511..3eaf054139 100644 +--- a/tools/clang/include/clang/Frontend/ASTUnit.h ++++ b/tools/clang/include/clang/Frontend/ASTUnit.h +@@ -184,6 +184,14 @@ private: + /// some number of calls. + unsigned PreambleRebuildCounter; + ++ /// \brief Cache pairs "filename - source location" ++ /// ++ /// Cache contains only source locations from preamble so it is ++ /// guaranteed that they stay valid when the SourceManager is recreated. ++ /// This cache is used when loading preambule to increase performance ++ /// of that loading. It must be cleared when preamble is recreated. ++ llvm::StringMap PreambleSrcLocCache; ++ + public: + class PreambleData { + const FileEntry *File; +diff --git a/tools/clang/lib/Frontend/ASTUnit.cpp b/tools/clang/lib/Frontend/ASTUnit.cpp +index 76fd00a132..c1c2680dcd 100644 +--- a/tools/clang/lib/Frontend/ASTUnit.cpp ++++ b/tools/clang/lib/Frontend/ASTUnit.cpp +@@ -1142,6 +1142,8 @@ bool ASTUnit::Parse(std::shared_ptr PCHContainerOps, + if (SavedMainFileBuffer) + TranslateStoredDiagnostics(getFileManager(), getSourceManager(), + PreambleDiagnostics, StoredDiagnostics); ++ else ++ PreambleSrcLocCache.clear(); + + if (!Act->Execute()) + goto error; +@@ -2544,8 +2546,16 @@ void ASTUnit::TranslateStoredDiagnostics( + const FileEntry *FE = FileMgr.getFile(SD.Filename); + if (!FE) + continue; +- FileID FID = SrcMgr.translateFile(FE); +- SourceLocation FileLoc = SrcMgr.getLocForStartOfFile(FID); ++ SourceLocation FileLoc; ++ auto ItFileID = PreambleSrcLocCache.find(SD.Filename); ++ if (ItFileID == PreambleSrcLocCache.end()) { ++ FileID FID = SrcMgr.translateFile(FE); ++ FileLoc = SrcMgr.getLocForStartOfFile(FID); ++ PreambleSrcLocCache[SD.Filename] = FileLoc; ++ } else { ++ FileLoc = ItFileID->getValue(); ++ } ++ + if (FileLoc.isInvalid()) + continue; + SourceLocation L = FileLoc.getLocWithOffset(SD.LocOffset); -- cgit v1.2.1