[PATCH] D33493: Speed up preamble loading, reduce global completion cache calls
Ivan Donchevskii via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 24 06:08:29 PDT 2017
yvvan created this revision.
On Windows loading preamble and caching global completion takes a while.
This is the way to improve it.
Please comment if I misuse something.
https://reviews.llvm.org/D33493
Files:
include/clang/Frontend/ASTUnit.h
lib/Frontend/ASTUnit.cpp
Index: lib/Frontend/ASTUnit.cpp
===================================================================
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -455,7 +455,7 @@
}
// Save the current top-level hash value.
- CompletionCacheTopLevelHashValue = CurrentTopLevelHashValue;
+ CompletionCacheTopLevelHashValue = PreambleTopLevelHashValue;
}
void ASTUnit::ClearCachedCompletionResults() {
@@ -1126,6 +1126,8 @@
if (SavedMainFileBuffer)
TranslateStoredDiagnostics(getFileManager(), getSourceManager(),
PreambleDiagnostics, StoredDiagnostics);
+ else
+ FIDsCache.clear();
if (!Act->Execute())
goto error;
@@ -1476,6 +1478,8 @@
SimpleTimer PreambleTimer(WantTiming);
PreambleTimer.setOutput("Precompiling preamble");
+ CompletionCacheTopLevelHashValue = 0;
+
// Save the preamble text for later; we'll need to compare against it for
// subsequent reparses.
StringRef MainFilename = FrontendOpts.Inputs[0].getFile();
@@ -1626,7 +1630,6 @@
// entities the last time we rebuilt the preamble, clear out the completion
// cache.
if (CurrentTopLevelHashValue != PreambleTopLevelHashValue) {
- CompletionCacheTopLevelHashValue = 0;
PreambleTopLevelHashValue = CurrentTopLevelHashValue;
}
@@ -2061,7 +2064,7 @@
// If we're caching global code-completion results, and the top-level
// declarations have changed, clear out the code-completion cache.
if (!Result && ShouldCacheCodeCompletionResults &&
- CurrentTopLevelHashValue != CompletionCacheTopLevelHashValue)
+ PreambleTopLevelHashValue != CompletionCacheTopLevelHashValue)
CacheCodeCompletionResults();
// We now need to clear out the completion info related to this translation
@@ -2531,8 +2534,7 @@
SmallVector<StoredDiagnostic, 4> Result;
Result.reserve(Diags.size());
- const FileEntry *PreviousFE = nullptr;
- FileID FID;
+
for (const StandaloneDiagnostic &SD : Diags) {
// Rebuild the StoredDiagnostic.
if (SD.Filename.empty())
@@ -2540,11 +2542,17 @@
const FileEntry *FE = FileMgr.getFile(SD.Filename);
if (!FE)
continue;
- if (FE != PreviousFE) {
+ FileID FID;
+ SourceLocation FileLoc;
+ auto ItFileID = FIDsCache.find(SD.Filename);
+ if (ItFileID == FIDsCache.end()) {
FID = SrcMgr.translateFile(FE);
- PreviousFE = FE;
+ FileLoc = SrcMgr.getLocForStartOfFile(FID);
+ FIDsCache.insert(std::make_pair(SD.Filename, FileLoc));
+ } else {
+ FileLoc = ItFileID->second;
}
- SourceLocation FileLoc = SrcMgr.getLocForStartOfFile(FID);
+
if (FileLoc.isInvalid())
continue;
SourceLocation L = FileLoc.getLocWithOffset(SD.LocOffset);
Index: include/clang/Frontend/ASTUnit.h
===================================================================
--- include/clang/Frontend/ASTUnit.h
+++ include/clang/Frontend/ASTUnit.h
@@ -181,6 +181,8 @@
/// some number of calls.
unsigned PreambleRebuildCounter;
+ std::map<const std::string, SourceLocation> FIDsCache;
+
public:
class PreambleData {
const FileEntry *File;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33493.100074.patch
Type: text/x-patch
Size: 3127 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170524/9dd9e0d2/attachment-0001.bin>
More information about the cfe-commits
mailing list