From 7847e44594aa932c0a5f5d2cd15940d2a815c059 Mon Sep 17 00:00:00 2001 From: Michael Spencer Date: Tue, 30 Jan 2024 15:39:18 -0800 Subject: [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. --- llvm/lib/Support/VirtualFileSystem.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'llvm/lib/Support/VirtualFileSystem.cpp') diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index d6c787cb91b3..c34117068803 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 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 &Path) const { ErrorOr 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 Entries; for (const auto &Root : Roots) { ErrorOr Result = lookupPathImpl(Start, End, Root.get(), Entries); + if (UsageTrackingActive && Result && isa(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; -- cgit v1.2.3