FileManager.cpp 21 KB

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