FileManager.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. //===--- FileManager.cpp - File System Probing and Caching ----------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the FileManager interface.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // TODO: This should index all interesting directories with dirent calls.
  15. // getdirentries ?
  16. // opendir/readdir_r/closedir ?
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #include "clang/Basic/FileManager.h"
  20. #include "clang/Basic/FileSystemStatCache.h"
  21. #include "llvm/ADT/SmallString.h"
  22. #include "llvm/Support/FileSystem.h"
  23. #include "llvm/Support/MemoryBuffer.h"
  24. #include "llvm/Support/raw_ostream.h"
  25. #include "llvm/Support/Path.h"
  26. #include "llvm/Support/system_error.h"
  27. #include "llvm/Config/llvm-config.h"
  28. #include <map>
  29. #include <set>
  30. #include <string>
  31. // FIXME: This is terrible, we need this for ::close.
  32. #if !defined(_MSC_VER) && !defined(__MINGW32__)
  33. #include <unistd.h>
  34. #include <sys/uio.h>
  35. #else
  36. #include <io.h>
  37. #endif
  38. using namespace clang;
  39. // FIXME: Enhance libsystem to support inode and other fields.
  40. #include <sys/stat.h>
  41. /// NON_EXISTENT_DIR - A special value distinct from null that is used to
  42. /// represent a dir name that doesn't exist on the disk.
  43. #define NON_EXISTENT_DIR reinterpret_cast<DirectoryEntry*>((intptr_t)-1)
  44. /// NON_EXISTENT_FILE - A special value distinct from null that is used to
  45. /// represent a filename that doesn't exist on the disk.
  46. #define NON_EXISTENT_FILE reinterpret_cast<FileEntry*>((intptr_t)-1)
  47. FileEntry::~FileEntry() {
  48. // If this FileEntry owns an open file descriptor that never got used, close
  49. // it.
  50. if (FD != -1) ::close(FD);
  51. }
  52. //===----------------------------------------------------------------------===//
  53. // Windows.
  54. //===----------------------------------------------------------------------===//
  55. #ifdef LLVM_ON_WIN32
  56. namespace {
  57. static std::string GetFullPath(const char *relPath) {
  58. char *absPathStrPtr = _fullpath(NULL, relPath, 0);
  59. assert(absPathStrPtr && "_fullpath() returned NULL!");
  60. std::string absPath(absPathStrPtr);
  61. free(absPathStrPtr);
  62. return absPath;
  63. }
  64. }
  65. class FileManager::UniqueDirContainer {
  66. /// UniqueDirs - Cache from full path to existing directories/files.
  67. ///
  68. llvm::StringMap<DirectoryEntry> UniqueDirs;
  69. public:
  70. /// getDirectory - Return an existing DirectoryEntry with the given
  71. /// name if there is already one; otherwise create and return a
  72. /// default-constructed DirectoryEntry.
  73. DirectoryEntry &getDirectory(const char *Name,
  74. const struct stat & /*StatBuf*/) {
  75. std::string FullPath(GetFullPath(Name));
  76. return UniqueDirs.GetOrCreateValue(FullPath).getValue();
  77. }
  78. size_t size() const { return UniqueDirs.size(); }
  79. };
  80. class FileManager::UniqueFileContainer {
  81. /// UniqueFiles - Cache from full path to existing directories/files.
  82. ///
  83. llvm::StringMap<FileEntry, llvm::BumpPtrAllocator> UniqueFiles;
  84. public:
  85. /// getFile - Return an existing FileEntry with the given name if
  86. /// there is already one; otherwise create and return a
  87. /// default-constructed FileEntry.
  88. FileEntry &getFile(const char *Name, const struct stat & /*StatBuf*/) {
  89. std::string FullPath(GetFullPath(Name));
  90. // Lowercase string because Windows filesystem is case insensitive.
  91. FullPath = StringRef(FullPath).lower();
  92. return UniqueFiles.GetOrCreateValue(FullPath).getValue();
  93. }
  94. size_t size() const { return UniqueFiles.size(); }
  95. void erase(const FileEntry *Entry) {
  96. std::string FullPath(GetFullPath(Entry->getName()));
  97. // Lowercase string because Windows filesystem is case insensitive.
  98. FullPath = StringRef(FullPath).lower();
  99. UniqueFiles.erase(FullPath);
  100. }
  101. };
  102. //===----------------------------------------------------------------------===//
  103. // Unix-like Systems.
  104. //===----------------------------------------------------------------------===//
  105. #else
  106. class FileManager::UniqueDirContainer {
  107. /// UniqueDirs - Cache from ID's to existing directories/files.
  108. std::map<std::pair<dev_t, ino_t>, DirectoryEntry> UniqueDirs;
  109. public:
  110. /// getDirectory - Return an existing DirectoryEntry with the given
  111. /// ID's if there is already one; otherwise create and return a
  112. /// default-constructed DirectoryEntry.
  113. DirectoryEntry &getDirectory(const char * /*Name*/,
  114. const struct stat &StatBuf) {
  115. return UniqueDirs[std::make_pair(StatBuf.st_dev, StatBuf.st_ino)];
  116. }
  117. size_t size() const { return UniqueDirs.size(); }
  118. };
  119. class FileManager::UniqueFileContainer {
  120. /// UniqueFiles - Cache from ID's to existing directories/files.
  121. std::set<FileEntry> UniqueFiles;
  122. public:
  123. /// getFile - Return an existing FileEntry with the given ID's if
  124. /// there is already one; otherwise create and return a
  125. /// default-constructed FileEntry.
  126. FileEntry &getFile(const char * /*Name*/, const struct stat &StatBuf) {
  127. return
  128. const_cast<FileEntry&>(
  129. *UniqueFiles.insert(FileEntry(StatBuf.st_dev,
  130. StatBuf.st_ino,
  131. StatBuf.st_mode)).first);
  132. }
  133. size_t size() const { return UniqueFiles.size(); }
  134. void erase(const FileEntry *Entry) { UniqueFiles.erase(*Entry); }
  135. };
  136. #endif
  137. //===----------------------------------------------------------------------===//
  138. // Common logic.
  139. //===----------------------------------------------------------------------===//
  140. FileManager::FileManager(const FileSystemOptions &FSO)
  141. : FileSystemOpts(FSO),
  142. UniqueRealDirs(*new UniqueDirContainer()),
  143. UniqueRealFiles(*new UniqueFileContainer()),
  144. SeenDirEntries(64), SeenFileEntries(64), NextFileUID(0) {
  145. NumDirLookups = NumFileLookups = 0;
  146. NumDirCacheMisses = NumFileCacheMisses = 0;
  147. }
  148. FileManager::~FileManager() {
  149. delete &UniqueRealDirs;
  150. delete &UniqueRealFiles;
  151. for (unsigned i = 0, e = VirtualFileEntries.size(); i != e; ++i)
  152. delete VirtualFileEntries[i];
  153. for (unsigned i = 0, e = VirtualDirectoryEntries.size(); i != e; ++i)
  154. delete VirtualDirectoryEntries[i];
  155. }
  156. void FileManager::addStatCache(FileSystemStatCache *statCache,
  157. bool AtBeginning) {
  158. assert(statCache && "No stat cache provided?");
  159. if (AtBeginning || StatCache.get() == 0) {
  160. statCache->setNextStatCache(StatCache.take());
  161. StatCache.reset(statCache);
  162. return;
  163. }
  164. FileSystemStatCache *LastCache = StatCache.get();
  165. while (LastCache->getNextStatCache())
  166. LastCache = LastCache->getNextStatCache();
  167. LastCache->setNextStatCache(statCache);
  168. }
  169. void FileManager::removeStatCache(FileSystemStatCache *statCache) {
  170. if (!statCache)
  171. return;
  172. if (StatCache.get() == statCache) {
  173. // This is the first stat cache.
  174. StatCache.reset(StatCache->takeNextStatCache());
  175. return;
  176. }
  177. // Find the stat cache in the list.
  178. FileSystemStatCache *PrevCache = StatCache.get();
  179. while (PrevCache && PrevCache->getNextStatCache() != statCache)
  180. PrevCache = PrevCache->getNextStatCache();
  181. assert(PrevCache && "Stat cache not found for removal");
  182. PrevCache->setNextStatCache(statCache->getNextStatCache());
  183. }
  184. void FileManager::clearStatCaches() {
  185. StatCache.reset(0);
  186. }
  187. /// \brief Retrieve the directory that the given file name resides in.
  188. /// Filename can point to either a real file or a virtual file.
  189. static const DirectoryEntry *getDirectoryFromFile(FileManager &FileMgr,
  190. StringRef Filename,
  191. bool CacheFailure) {
  192. if (Filename.empty())
  193. return NULL;
  194. if (llvm::sys::path::is_separator(Filename[Filename.size() - 1]))
  195. return NULL; // If Filename is a directory.
  196. StringRef DirName = llvm::sys::path::parent_path(Filename);
  197. // Use the current directory if file has no path component.
  198. if (DirName.empty())
  199. DirName = ".";
  200. return FileMgr.getDirectory(DirName, CacheFailure);
  201. }
  202. /// Add all ancestors of the given path (pointing to either a file or
  203. /// a directory) as virtual directories.
  204. void FileManager::addAncestorsAsVirtualDirs(StringRef Path) {
  205. StringRef DirName = llvm::sys::path::parent_path(Path);
  206. if (DirName.empty())
  207. return;
  208. llvm::StringMapEntry<DirectoryEntry *> &NamedDirEnt =
  209. SeenDirEntries.GetOrCreateValue(DirName);
  210. // When caching a virtual directory, we always cache its ancestors
  211. // at the same time. Therefore, if DirName is already in the cache,
  212. // we don't need to recurse as its ancestors must also already be in
  213. // the cache.
  214. if (NamedDirEnt.getValue())
  215. return;
  216. // Add the virtual directory to the cache.
  217. DirectoryEntry *UDE = new DirectoryEntry;
  218. UDE->Name = NamedDirEnt.getKeyData();
  219. NamedDirEnt.setValue(UDE);
  220. VirtualDirectoryEntries.push_back(UDE);
  221. // Recursively add the other ancestors.
  222. addAncestorsAsVirtualDirs(DirName);
  223. }
  224. const DirectoryEntry *FileManager::getDirectory(StringRef DirName,
  225. bool CacheFailure) {
  226. // stat doesn't like trailing separators except for root directory.
  227. // At least, on Win32 MSVCRT, stat() cannot strip trailing '/'.
  228. // (though it can strip '\\')
  229. if (DirName.size() > 1 &&
  230. DirName != llvm::sys::path::root_path(DirName) &&
  231. llvm::sys::path::is_separator(DirName.back()))
  232. DirName = DirName.substr(0, DirName.size()-1);
  233. ++NumDirLookups;
  234. llvm::StringMapEntry<DirectoryEntry *> &NamedDirEnt =
  235. SeenDirEntries.GetOrCreateValue(DirName);
  236. // See if there was already an entry in the map. Note that the map
  237. // contains both virtual and real directories.
  238. if (NamedDirEnt.getValue())
  239. return NamedDirEnt.getValue() == NON_EXISTENT_DIR
  240. ? 0 : NamedDirEnt.getValue();
  241. ++NumDirCacheMisses;
  242. // By default, initialize it to invalid.
  243. NamedDirEnt.setValue(NON_EXISTENT_DIR);
  244. // Get the null-terminated directory name as stored as the key of the
  245. // SeenDirEntries map.
  246. const char *InterndDirName = NamedDirEnt.getKeyData();
  247. // Check to see if the directory exists.
  248. struct stat StatBuf;
  249. if (getStatValue(InterndDirName, StatBuf, 0/*directory lookup*/)) {
  250. // There's no real directory at the given path.
  251. if (!CacheFailure)
  252. SeenDirEntries.erase(DirName);
  253. return 0;
  254. }
  255. // It exists. See if we have already opened a directory with the
  256. // same inode (this occurs on Unix-like systems when one dir is
  257. // symlinked to another, for example) or the same path (on
  258. // Windows).
  259. DirectoryEntry &UDE = UniqueRealDirs.getDirectory(InterndDirName, StatBuf);
  260. NamedDirEnt.setValue(&UDE);
  261. if (!UDE.getName()) {
  262. // We don't have this directory yet, add it. We use the string
  263. // key from the SeenDirEntries map as the string.
  264. UDE.Name = InterndDirName;
  265. }
  266. return &UDE;
  267. }
  268. const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
  269. bool CacheFailure) {
  270. ++NumFileLookups;
  271. // See if there is already an entry in the map.
  272. llvm::StringMapEntry<FileEntry *> &NamedFileEnt =
  273. SeenFileEntries.GetOrCreateValue(Filename);
  274. // See if there is already an entry in the map.
  275. if (NamedFileEnt.getValue())
  276. return NamedFileEnt.getValue() == NON_EXISTENT_FILE
  277. ? 0 : NamedFileEnt.getValue();
  278. ++NumFileCacheMisses;
  279. // By default, initialize it to invalid.
  280. NamedFileEnt.setValue(NON_EXISTENT_FILE);
  281. // Get the null-terminated file name as stored as the key of the
  282. // SeenFileEntries map.
  283. const char *InterndFileName = NamedFileEnt.getKeyData();
  284. // Look up the directory for the file. When looking up something like
  285. // sys/foo.h we'll discover all of the search directories that have a 'sys'
  286. // subdirectory. This will let us avoid having to waste time on known-to-fail
  287. // searches when we go to find sys/bar.h, because all the search directories
  288. // without a 'sys' subdir will get a cached failure result.
  289. const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename,
  290. CacheFailure);
  291. if (DirInfo == 0) { // Directory doesn't exist, file can't exist.
  292. if (!CacheFailure)
  293. SeenFileEntries.erase(Filename);
  294. return 0;
  295. }
  296. // FIXME: Use the directory info to prune this, before doing the stat syscall.
  297. // FIXME: This will reduce the # syscalls.
  298. // Nope, there isn't. Check to see if the file exists.
  299. int FileDescriptor = -1;
  300. struct stat StatBuf;
  301. if (getStatValue(InterndFileName, StatBuf, &FileDescriptor)) {
  302. // There's no real file at the given path.
  303. if (!CacheFailure)
  304. SeenFileEntries.erase(Filename);
  305. return 0;
  306. }
  307. if (FileDescriptor != -1 && !openFile) {
  308. close(FileDescriptor);
  309. FileDescriptor = -1;
  310. }
  311. // It exists. See if we have already opened a file with the same inode.
  312. // This occurs when one dir is symlinked to another, for example.
  313. FileEntry &UFE = UniqueRealFiles.getFile(InterndFileName, StatBuf);
  314. NamedFileEnt.setValue(&UFE);
  315. if (UFE.getName()) { // Already have an entry with this inode, return it.
  316. // If the stat process opened the file, close it to avoid a FD leak.
  317. if (FileDescriptor != -1)
  318. close(FileDescriptor);
  319. return &UFE;
  320. }
  321. // Otherwise, we don't have this directory yet, add it.
  322. // FIXME: Change the name to be a char* that points back to the
  323. // 'SeenFileEntries' key.
  324. UFE.Name = InterndFileName;
  325. UFE.Size = StatBuf.st_size;
  326. UFE.ModTime = StatBuf.st_mtime;
  327. UFE.Dir = DirInfo;
  328. UFE.UID = NextFileUID++;
  329. UFE.FD = FileDescriptor;
  330. return &UFE;
  331. }
  332. const FileEntry *
  333. FileManager::getVirtualFile(StringRef Filename, off_t Size,
  334. time_t ModificationTime) {
  335. ++NumFileLookups;
  336. // See if there is already an entry in the map.
  337. llvm::StringMapEntry<FileEntry *> &NamedFileEnt =
  338. SeenFileEntries.GetOrCreateValue(Filename);
  339. // See if there is already an entry in the map.
  340. if (NamedFileEnt.getValue() && NamedFileEnt.getValue() != NON_EXISTENT_FILE)
  341. return NamedFileEnt.getValue();
  342. ++NumFileCacheMisses;
  343. // By default, initialize it to invalid.
  344. NamedFileEnt.setValue(NON_EXISTENT_FILE);
  345. addAncestorsAsVirtualDirs(Filename);
  346. FileEntry *UFE = 0;
  347. // Now that all ancestors of Filename are in the cache, the
  348. // following call is guaranteed to find the DirectoryEntry from the
  349. // cache.
  350. const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename,
  351. /*CacheFailure=*/true);
  352. assert(DirInfo &&
  353. "The directory of a virtual file should already be in the cache.");
  354. // Check to see if the file exists. If so, drop the virtual file
  355. int FileDescriptor = -1;
  356. struct stat StatBuf;
  357. const char *InterndFileName = NamedFileEnt.getKeyData();
  358. if (getStatValue(InterndFileName, StatBuf, &FileDescriptor) == 0) {
  359. // If the stat process opened the file, close it to avoid a FD leak.
  360. if (FileDescriptor != -1)
  361. close(FileDescriptor);
  362. StatBuf.st_size = Size;
  363. StatBuf.st_mtime = ModificationTime;
  364. UFE = &UniqueRealFiles.getFile(InterndFileName, StatBuf);
  365. NamedFileEnt.setValue(UFE);
  366. // If we had already opened this file, close it now so we don't
  367. // leak the descriptor. We're not going to use the file
  368. // descriptor anyway, since this is a virtual file.
  369. if (UFE->FD != -1) {
  370. close(UFE->FD);
  371. UFE->FD = -1;
  372. }
  373. // If we already have an entry with this inode, return it.
  374. if (UFE->getName())
  375. return UFE;
  376. }
  377. if (!UFE) {
  378. UFE = new FileEntry();
  379. VirtualFileEntries.push_back(UFE);
  380. NamedFileEnt.setValue(UFE);
  381. }
  382. UFE->Name = InterndFileName;
  383. UFE->Size = Size;
  384. UFE->ModTime = ModificationTime;
  385. UFE->Dir = DirInfo;
  386. UFE->UID = NextFileUID++;
  387. UFE->FD = -1;
  388. return UFE;
  389. }
  390. void FileManager::FixupRelativePath(SmallVectorImpl<char> &path) const {
  391. StringRef pathRef(path.data(), path.size());
  392. if (FileSystemOpts.WorkingDir.empty()
  393. || llvm::sys::path::is_absolute(pathRef))
  394. return;
  395. SmallString<128> NewPath(FileSystemOpts.WorkingDir);
  396. llvm::sys::path::append(NewPath, pathRef);
  397. path = NewPath;
  398. }
  399. llvm::MemoryBuffer *FileManager::
  400. getBufferForFile(const FileEntry *Entry, std::string *ErrorStr,
  401. bool isVolatile) {
  402. OwningPtr<llvm::MemoryBuffer> Result;
  403. llvm::error_code ec;
  404. uint64_t FileSize = Entry->getSize();
  405. // If there's a high enough chance that the file have changed since we
  406. // got its size, force a stat before opening it.
  407. if (isVolatile)
  408. FileSize = -1;
  409. const char *Filename = Entry->getName();
  410. // If the file is already open, use the open file descriptor.
  411. if (Entry->FD != -1) {
  412. ec = llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, Result, FileSize);
  413. if (ErrorStr)
  414. *ErrorStr = ec.message();
  415. close(Entry->FD);
  416. Entry->FD = -1;
  417. return Result.take();
  418. }
  419. // Otherwise, open the file.
  420. if (FileSystemOpts.WorkingDir.empty()) {
  421. ec = llvm::MemoryBuffer::getFile(Filename, Result, FileSize);
  422. if (ec && ErrorStr)
  423. *ErrorStr = ec.message();
  424. return Result.take();
  425. }
  426. SmallString<128> FilePath(Entry->getName());
  427. FixupRelativePath(FilePath);
  428. ec = llvm::MemoryBuffer::getFile(FilePath.str(), Result, FileSize);
  429. if (ec && ErrorStr)
  430. *ErrorStr = ec.message();
  431. return Result.take();
  432. }
  433. llvm::MemoryBuffer *FileManager::
  434. getBufferForFile(StringRef Filename, std::string *ErrorStr) {
  435. OwningPtr<llvm::MemoryBuffer> Result;
  436. llvm::error_code ec;
  437. if (FileSystemOpts.WorkingDir.empty()) {
  438. ec = llvm::MemoryBuffer::getFile(Filename, Result);
  439. if (ec && ErrorStr)
  440. *ErrorStr = ec.message();
  441. return Result.take();
  442. }
  443. SmallString<128> FilePath(Filename);
  444. FixupRelativePath(FilePath);
  445. ec = llvm::MemoryBuffer::getFile(FilePath.c_str(), Result);
  446. if (ec && ErrorStr)
  447. *ErrorStr = ec.message();
  448. return Result.take();
  449. }
  450. /// getStatValue - Get the 'stat' information for the specified path,
  451. /// using the cache to accelerate it if possible. This returns true
  452. /// if the path points to a virtual file or does not exist, or returns
  453. /// false if it's an existent real file. If FileDescriptor is NULL,
  454. /// do directory look-up instead of file look-up.
  455. bool FileManager::getStatValue(const char *Path, struct stat &StatBuf,
  456. int *FileDescriptor) {
  457. // FIXME: FileSystemOpts shouldn't be passed in here, all paths should be
  458. // absolute!
  459. if (FileSystemOpts.WorkingDir.empty())
  460. return FileSystemStatCache::get(Path, StatBuf, FileDescriptor,
  461. StatCache.get());
  462. SmallString<128> FilePath(Path);
  463. FixupRelativePath(FilePath);
  464. return FileSystemStatCache::get(FilePath.c_str(), StatBuf, FileDescriptor,
  465. StatCache.get());
  466. }
  467. bool FileManager::getNoncachedStatValue(StringRef Path,
  468. struct stat &StatBuf) {
  469. SmallString<128> FilePath(Path);
  470. FixupRelativePath(FilePath);
  471. return ::stat(FilePath.c_str(), &StatBuf) != 0;
  472. }
  473. void FileManager::invalidateCache(const FileEntry *Entry) {
  474. assert(Entry && "Cannot invalidate a NULL FileEntry");
  475. SeenFileEntries.erase(Entry->getName());
  476. // FileEntry invalidation should not block future optimizations in the file
  477. // caches. Possible alternatives are cache truncation (invalidate last N) or
  478. // invalidation of the whole cache.
  479. UniqueRealFiles.erase(Entry);
  480. }
  481. void FileManager::GetUniqueIDMapping(
  482. SmallVectorImpl<const FileEntry *> &UIDToFiles) const {
  483. UIDToFiles.clear();
  484. UIDToFiles.resize(NextFileUID);
  485. // Map file entries
  486. for (llvm::StringMap<FileEntry*, llvm::BumpPtrAllocator>::const_iterator
  487. FE = SeenFileEntries.begin(), FEEnd = SeenFileEntries.end();
  488. FE != FEEnd; ++FE)
  489. if (FE->getValue() && FE->getValue() != NON_EXISTENT_FILE)
  490. UIDToFiles[FE->getValue()->getUID()] = FE->getValue();
  491. // Map virtual file entries
  492. for (SmallVector<FileEntry*, 4>::const_iterator
  493. VFE = VirtualFileEntries.begin(), VFEEnd = VirtualFileEntries.end();
  494. VFE != VFEEnd; ++VFE)
  495. if (*VFE && *VFE != NON_EXISTENT_FILE)
  496. UIDToFiles[(*VFE)->getUID()] = *VFE;
  497. }
  498. void FileManager::modifyFileEntry(FileEntry *File,
  499. off_t Size, time_t ModificationTime) {
  500. File->Size = Size;
  501. File->ModTime = ModificationTime;
  502. }
  503. void FileManager::PrintStats() const {
  504. llvm::errs() << "\n*** File Manager Stats:\n";
  505. llvm::errs() << UniqueRealFiles.size() << " real files found, "
  506. << UniqueRealDirs.size() << " real dirs found.\n";
  507. llvm::errs() << VirtualFileEntries.size() << " virtual files found, "
  508. << VirtualDirectoryEntries.size() << " virtual dirs found.\n";
  509. llvm::errs() << NumDirLookups << " dir lookups, "
  510. << NumDirCacheMisses << " dir cache misses.\n";
  511. llvm::errs() << NumFileLookups << " file lookups, "
  512. << NumFileCacheMisses << " file cache misses.\n";
  513. //llvm::errs() << PagesMapped << BytesOfPagesMapped << FSLookups;
  514. }