[PATCH] D114968: [clang][deps] Avoid reading file for stat calls
Jan Svoboda via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 2 09:38:50 PST 2021
jansvoboda11 created this revision.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Depends on D114966 <https://reviews.llvm.org/D114966>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D114968
Files:
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===================================================================
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -290,7 +290,7 @@
llvm::ErrorOr<FileSystemEntryResult>
DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
- StringRef Filename) {
+ StringRef Filename, RequestedInformation RI) {
SharedStat *SharedStat = nullptr;
llvm::Optional<std::unique_lock<std::mutex>> GuardLock;
@@ -304,6 +304,12 @@
llvm::sys::fs::UniqueID UID = (*LocalStat)->getUniqueID();
if (!shouldMinimize(Filename)) {
+ if (RI == RI_Status) {
+ // If the caller wants a status of a file that doesn't need minimization,
+ // reading it is not necessary.
+ return FileSystemEntryResult(*LocalStat, nullptr, nullptr);
+ }
+
const OriginalContents *LocalOriginalContents =
getOrCreateLocalOriginalContents(Filename, UID, SharedStat, GuardLock);
return FileSystemEntryResult(*LocalStat, LocalOriginalContents, nullptr);
@@ -321,7 +327,7 @@
DependencyScanningWorkerFilesystem::status(const Twine &Path) {
SmallString<256> OwnedFilename;
StringRef Filename = Path.toStringRef(OwnedFilename);
- auto Result = getOrCreateFileSystemEntry(Filename);
+ auto Result = getOrCreateFileSystemEntry(Filename, RI_Status);
if (!Result)
return Result.getError();
return Result->Status;
@@ -381,7 +387,7 @@
SmallString<256> OwnedFilename;
StringRef Filename = Path.toStringRef(OwnedFilename);
- auto Result = getOrCreateFileSystemEntry(Filename);
+ auto Result = getOrCreateFileSystemEntry(Filename, RI_Contents);
if (!Result)
return Result.getError();
if (!Result->Status)
Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
===================================================================
--- clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -223,10 +223,16 @@
StringRef Filename, llvm::sys::fs::UniqueID UID, SharedStat *&SharedStat,
llvm::Optional<std::unique_lock<std::mutex>> &Lock);
+ /// The information requested from \c getOrCreateFileSystemEntry.
+ enum RequestedInformation {
+ RI_Status,
+ RI_Contents,
+ };
+
/// Get the full filesystem entry for \p Path from local cache, populating it
/// if necessary.
llvm::ErrorOr<FileSystemEntryResult>
- getOrCreateFileSystemEntry(StringRef Path);
+ getOrCreateFileSystemEntry(StringRef Path, RequestedInformation RI);
/// The global cache shared between worker threads.
DependencyScanningFilesystemSharedCache &SharedCache;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114968.391360.patch
Type: text/x-patch
Size: 2831 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211202/80120a3a/attachment-0001.bin>
More information about the cfe-commits
mailing list