aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/VirtualFileSystem.cpp
diff options
context:
space:
mode:
authorMichael Spencer <bigcheesegs@gmail.com>2024-01-30 15:39:18 -0800
committerGitHub <noreply@github.com>2024-01-30 15:39:18 -0800
commit7847e44594aa932c0a5f5d2cd15940d2a815c059 (patch)
treedebc338a0ad7726ec484fab51fcf6504d8f3b357 /llvm/lib/Support/VirtualFileSystem.cpp
parent16c15b5f84836d81084e9987701ca011da5a864f (diff)
downloadllvm-7847e44594aa932c0a5f5d2cd15940d2a815c059.zip
llvm-7847e44594aa932c0a5f5d2cd15940d2a815c059.tar.gz
llvm-7847e44594aa932c0a5f5d2cd15940d2a815c059.tar.bz2
[clang][DependencyScanner] Remove unused -ivfsoverlay files (#73734)
`-ivfsoverlay` files are unused when building most modules. Enable removing them by, * adding a way to visit the filesystem tree with extensible RTTI to access each `RedirectingFileSystem`. * Adding tracking to `RedirectingFileSystem` to record when it actually redirects a file access. * Storing this information in each PCM. Usage tracking is only enabled when iterating over the source manager and affecting modulemaps. Here each path is stated to cause an access. During scanning these stats all hit the cache.
Diffstat (limited to 'llvm/lib/Support/VirtualFileSystem.cpp')
-rw-r--r--llvm/lib/Support/VirtualFileSystem.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index d6c787c..c341170 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -480,6 +480,13 @@ OverlayFileSystem::getRealPath(const Twine &Path,
return errc::no_such_file_or_directory;
}
+void OverlayFileSystem::visitChildFileSystems(VisitCallbackTy Callback) {
+ for (IntrusiveRefCntPtr<FileSystem> FS : overlays_range()) {
+ Callback(*FS);
+ FS->visitChildFileSystems(Callback);
+ }
+}
+
void OverlayFileSystem::printImpl(raw_ostream &OS, PrintType Type,
unsigned IndentLevel) const {
printIndent(OS, IndentLevel);
@@ -1581,6 +1588,13 @@ void RedirectingFileSystem::printEntry(raw_ostream &OS,
}
}
+void RedirectingFileSystem::visitChildFileSystems(VisitCallbackTy Callback) {
+ if (ExternalFS) {
+ Callback(*ExternalFS);
+ ExternalFS->visitChildFileSystems(Callback);
+ }
+}
+
/// A helper class to hold the common YAML parsing state.
class llvm::vfs::RedirectingFileSystemParser {
yaml::Stream &Stream;
@@ -2263,12 +2277,18 @@ RedirectingFileSystem::makeCanonical(SmallVectorImpl<char> &Path) const {
ErrorOr<RedirectingFileSystem::LookupResult>
RedirectingFileSystem::lookupPath(StringRef Path) const {
+ // RedirectOnly means the VFS is always used.
+ if (UsageTrackingActive && Redirection == RedirectKind::RedirectOnly)
+ HasBeenUsed = true;
+
sys::path::const_iterator Start = sys::path::begin(Path);
sys::path::const_iterator End = sys::path::end(Path);
llvm::SmallVector<Entry *, 32> Entries;
for (const auto &Root : Roots) {
ErrorOr<RedirectingFileSystem::LookupResult> Result =
lookupPathImpl(Start, End, Root.get(), Entries);
+ if (UsageTrackingActive && Result && isa<RemapEntry>(Result->E))
+ HasBeenUsed = true;
if (Result || Result.getError() != llvm::errc::no_such_file_or_directory) {
Result->Parents = std::move(Entries);
return Result;
@@ -2863,3 +2883,9 @@ recursive_directory_iterator::increment(std::error_code &EC) {
return *this;
}
+
+const char FileSystem::ID = 0;
+const char OverlayFileSystem::ID = 0;
+const char ProxyFileSystem::ID = 0;
+const char InMemoryFileSystem::ID = 0;
+const char RedirectingFileSystem::ID = 0;