|
@@ -188,8 +188,7 @@ template <typename T> static bool hasBodyOrInit(const T *D) {
|
|
}
|
|
}
|
|
|
|
|
|
CrossTranslationUnitContext::CrossTranslationUnitContext(CompilerInstance &CI)
|
|
CrossTranslationUnitContext::CrossTranslationUnitContext(CompilerInstance &CI)
|
|
- : Context(CI.getASTContext()), ASTStorage(CI),
|
|
|
|
- CTULoadThreshold(CI.getAnalyzerOpts()->CTUImportThreshold) {}
|
|
|
|
|
|
+ : Context(CI.getASTContext()), ASTStorage(CI) {}
|
|
|
|
|
|
CrossTranslationUnitContext::~CrossTranslationUnitContext() {}
|
|
CrossTranslationUnitContext::~CrossTranslationUnitContext() {}
|
|
|
|
|
|
@@ -363,21 +362,38 @@ CrossTranslationUnitContext::ASTFileLoader::operator()(StringRef ASTFilePath) {
|
|
|
|
|
|
CrossTranslationUnitContext::ASTUnitStorage::ASTUnitStorage(
|
|
CrossTranslationUnitContext::ASTUnitStorage::ASTUnitStorage(
|
|
const CompilerInstance &CI)
|
|
const CompilerInstance &CI)
|
|
- : FileAccessor(CI) {}
|
|
|
|
|
|
+ : FileAccessor(CI), LoadGuard(const_cast<CompilerInstance &>(CI)
|
|
|
|
+ .getAnalyzerOpts()
|
|
|
|
+ ->CTUImportThreshold) {}
|
|
|
|
|
|
llvm::Expected<ASTUnit *>
|
|
llvm::Expected<ASTUnit *>
|
|
-CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFile(StringRef FileName) {
|
|
|
|
|
|
+CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFile(
|
|
|
|
+ StringRef FileName, bool DisplayCTUProgress) {
|
|
// Try the cache first.
|
|
// Try the cache first.
|
|
auto ASTCacheEntry = FileASTUnitMap.find(FileName);
|
|
auto ASTCacheEntry = FileASTUnitMap.find(FileName);
|
|
if (ASTCacheEntry == FileASTUnitMap.end()) {
|
|
if (ASTCacheEntry == FileASTUnitMap.end()) {
|
|
|
|
+
|
|
|
|
+ // Do not load if the limit is reached.
|
|
|
|
+ if (!LoadGuard) {
|
|
|
|
+ ++NumASTLoadThresholdReached;
|
|
|
|
+ return llvm::make_error<IndexError>(
|
|
|
|
+ index_error_code::load_threshold_reached);
|
|
|
|
+ }
|
|
|
|
+
|
|
// Load the ASTUnit from the pre-dumped AST file specified by ASTFileName.
|
|
// Load the ASTUnit from the pre-dumped AST file specified by ASTFileName.
|
|
std::unique_ptr<ASTUnit> LoadedUnit = FileAccessor(FileName);
|
|
std::unique_ptr<ASTUnit> LoadedUnit = FileAccessor(FileName);
|
|
|
|
|
|
// Need the raw pointer and the unique_ptr as well.
|
|
// Need the raw pointer and the unique_ptr as well.
|
|
- ASTUnit* Unit = LoadedUnit.get();
|
|
|
|
|
|
+ ASTUnit *Unit = LoadedUnit.get();
|
|
|
|
|
|
// Update the cache.
|
|
// Update the cache.
|
|
FileASTUnitMap[FileName] = std::move(LoadedUnit);
|
|
FileASTUnitMap[FileName] = std::move(LoadedUnit);
|
|
|
|
+
|
|
|
|
+ LoadGuard.indicateLoadSuccess();
|
|
|
|
+
|
|
|
|
+ if (DisplayCTUProgress)
|
|
|
|
+ llvm::errs() << "CTU loaded AST file: " << FileName << "\n";
|
|
|
|
+
|
|
return Unit;
|
|
return Unit;
|
|
|
|
|
|
} else {
|
|
} else {
|
|
@@ -388,7 +404,8 @@ CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFile(StringRef FileNam
|
|
|
|
|
|
llvm::Expected<ASTUnit *>
|
|
llvm::Expected<ASTUnit *>
|
|
CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFunction(
|
|
CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFunction(
|
|
- StringRef FunctionName, StringRef CrossTUDir, StringRef IndexName) {
|
|
|
|
|
|
+ StringRef FunctionName, StringRef CrossTUDir, StringRef IndexName,
|
|
|
|
+ bool DisplayCTUProgress) {
|
|
// Try the cache first.
|
|
// Try the cache first.
|
|
auto ASTCacheEntry = NameASTUnitMap.find(FunctionName);
|
|
auto ASTCacheEntry = NameASTUnitMap.find(FunctionName);
|
|
if (ASTCacheEntry == NameASTUnitMap.end()) {
|
|
if (ASTCacheEntry == NameASTUnitMap.end()) {
|
|
@@ -408,7 +425,7 @@ CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFunction(
|
|
// Search in the index for the filename where the definition of FuncitonName
|
|
// Search in the index for the filename where the definition of FuncitonName
|
|
// resides.
|
|
// resides.
|
|
if (llvm::Expected<ASTUnit *> FoundForFile =
|
|
if (llvm::Expected<ASTUnit *> FoundForFile =
|
|
- getASTUnitForFile(NameFileMap[FunctionName])) {
|
|
|
|
|
|
+ getASTUnitForFile(NameFileMap[FunctionName], DisplayCTUProgress)) {
|
|
|
|
|
|
// Update the cache.
|
|
// Update the cache.
|
|
NameASTUnitMap[FunctionName] = *FoundForFile;
|
|
NameASTUnitMap[FunctionName] = *FoundForFile;
|
|
@@ -462,19 +479,9 @@ llvm::Expected<ASTUnit *> CrossTranslationUnitContext::loadExternalAST(
|
|
// translation units contains decls with the same lookup name an
|
|
// translation units contains decls with the same lookup name an
|
|
// error will be returned.
|
|
// error will be returned.
|
|
|
|
|
|
- // RAII incrementing counter is used to count successful loads.
|
|
|
|
- LoadGuard LoadOperation(CTULoadThreshold, NumASTLoaded);
|
|
|
|
-
|
|
|
|
- // If import threshold is reached, don't import anything.
|
|
|
|
- if (!LoadOperation) {
|
|
|
|
- ++NumASTLoadThresholdReached;
|
|
|
|
- return llvm::make_error<IndexError>(
|
|
|
|
- index_error_code::load_threshold_reached);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// Try to get the value from the heavily cached storage.
|
|
// Try to get the value from the heavily cached storage.
|
|
- llvm::Expected<ASTUnit *> Unit =
|
|
|
|
- ASTStorage.getASTUnitForFunction(LookupName, CrossTUDir, IndexName);
|
|
|
|
|
|
+ llvm::Expected<ASTUnit *> Unit = ASTStorage.getASTUnitForFunction(
|
|
|
|
+ LookupName, CrossTUDir, IndexName, DisplayCTUProgress);
|
|
|
|
|
|
if (!Unit)
|
|
if (!Unit)
|
|
return Unit.takeError();
|
|
return Unit.takeError();
|
|
@@ -484,19 +491,6 @@ llvm::Expected<ASTUnit *> CrossTranslationUnitContext::loadExternalAST(
|
|
return llvm::make_error<IndexError>(
|
|
return llvm::make_error<IndexError>(
|
|
index_error_code::failed_to_get_external_ast);
|
|
index_error_code::failed_to_get_external_ast);
|
|
|
|
|
|
- // The backing pointer is not null, loading was successful. If anything goes
|
|
|
|
- // wrong from this point on, the AST is already stored, so the load part is
|
|
|
|
- // finished.
|
|
|
|
- LoadOperation.storedSuccessfully();
|
|
|
|
-
|
|
|
|
- if (DisplayCTUProgress) {
|
|
|
|
- if (llvm::Expected<std::string> FileName =
|
|
|
|
- ASTStorage.getFileForFunction(LookupName, CrossTUDir, IndexName))
|
|
|
|
- llvm::errs() << "CTU loaded AST file: " << *FileName << "\n";
|
|
|
|
- else
|
|
|
|
- return FileName.takeError();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
return Unit;
|
|
return Unit;
|
|
}
|
|
}
|
|
|
|
|