<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Mar 4, 2013, at 12:15 PM, Chad Rosier <<a href="mailto:mcrosier@apple.com">mcrosier@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br class="Apple-interchange-newline">On Jan 25, 2013, at 4:55 PM, Douglas Gregor <<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>> wrote:</div><br class="Apple-interchange-newline" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">Author: dgregor<br>Date: Fri Jan 25 18:55:12 2013<br>New Revision: 173542<br><br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=173542&view=rev">http://llvm.org/viewvc/llvm-project?rev=173542&view=rev</a><br>Log:<br>Since we're stuck with realpath for the header <-> module mapping,<br>factor the realpath calls into FileManager::getCanonicalName() so we<br>can cache the results of this epically slow operation. 5% speedup on<br>my modules test, and realpath drops out of the profile.<br><br>Modified:<br>   cfe/trunk/include/clang/Basic/FileManager.h<br>   cfe/trunk/lib/Basic/FileManager.cpp<br>   cfe/trunk/lib/Lex/HeaderSearch.cpp<br>   cfe/trunk/lib/Lex/ModuleMap.cpp<br><br>Modified: cfe/trunk/include/clang/Basic/FileManager.h<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=173542&r1=173541&r2=173542&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=173542&r1=173541&r2=173542&view=diff</a><br>==============================================================================<br>--- cfe/trunk/include/clang/Basic/FileManager.h (original)<br>+++ cfe/trunk/include/clang/Basic/FileManager.h Fri Jan 25 18:55:12 2013<br>@@ -17,6 +17,7 @@<br><br>#include "clang/Basic/FileSystemOptions.h"<br>#include "clang/Basic/LLVM.h"<br>+#include "llvm/ADT/DenseMap.h"<br>#include "llvm/ADT/IntrusiveRefCntPtr.h"<br>#include "llvm/ADT/OwningPtr.h"<br>#include "llvm/ADT/SmallVector.h"<br>@@ -152,6 +153,12 @@ class FileManager : public RefCountedBas<br>  /// \see SeenDirEntries<br>  llvm::StringMap<FileEntry*, llvm::BumpPtrAllocator> SeenFileEntries;<br><br>+  /// \brief The canonical names of directories.<br>+  llvm::DenseMap<const DirectoryEntry *, llvm::StringRef> CanonicalDirNames;<br>+<br>+  /// \brief Storage for canonical names that we have computed.<br>+  llvm::BumpPtrAllocator CanonicalNameStorage;<br>+<br>  /// \brief Each FileEntry we create is assigned a unique ID #.<br>  ///<br>  unsigned NextFileUID;<br>@@ -257,6 +264,13 @@ public:<br>  static void modifyFileEntry(FileEntry *File, off_t Size,<br>                              time_t ModificationTime);<br><br>+  /// \brief Retrieve the canonical name for a given directory.<br>+  ///<br>+  /// This is a very expensive operation, despite its results being cached,<br>+  /// and should only be used when the physical layout of the file system is<br>+  /// required, which is (almost) never.<br>+  StringRef getCanonicalName(const DirectoryEntry *Dir);<br>+<br>  void PrintStats() const;<br>};<br><br><br>Modified: cfe/trunk/lib/Basic/FileManager.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=173542&r1=173541&r2=173542&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=173542&r1=173541&r2=173542&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/Basic/FileManager.cpp (original)<br>+++ cfe/trunk/lib/Basic/FileManager.cpp Fri Jan 25 18:55:12 2013<br>@@ -40,6 +40,11 @@<br>#define S_ISFIFO(x) (0)<br>#endif<br>#endif<br>+#if defined(LLVM_ON_UNIX)<br>+#if defined(__linux__)<br>+#include <linux/limits.h><br>+#endif<br>+#endif<br>using namespace clang;<br><br>// FIXME: Enhance libsystem to support inode and other fields.<br>@@ -620,6 +625,29 @@ void FileManager::modifyFileEntry(FileEn<br>  File->ModTime = ModificationTime;<br>}<br><br>+StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {<br>+  // FIXME: use llvm::sys::fs::canonical() when it gets implemented<br>+#ifdef LLVM_ON_UNIX<br>+  llvm::DenseMap<const DirectoryEntry *, llvm::StringRef>::iterator Known<br>+    = CanonicalDirNames.find(Dir);<br>+  if (Known != CanonicalDirNames.end())<br>+    return Known->second;<br>+<br>+  StringRef CanonicalName(Dir->getName());<br>+  char CanonicalNameBuf[PATH_MAX];<br>+  if (realpath(Dir->getName(), CanonicalNameBuf)) {<br>+    unsigned Len = strlen(CanonicalNameBuf);<br>+    char *Mem = static_cast<char *>(CanonicalNameStorage.Allocate(Len, 1));<br>+    memcpy(Mem, CanonicalNameBuf, Len);<br>+    CanonicalName = StringRef(Mem, Len);<br>+  }<br>+<br>+  CanonicalDirNames.insert(std::make_pair(Dir, CanonicalName));<br>+  return CanonicalName;<br>+#else<br>+  return StringRef(Dir->getName());<br>+#endif<br>+}<br><br>void FileManager::PrintStats() const {<br>  llvm::errs() << "\n*** File Manager Stats:\n";<br><br>Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=173542&r1=173541&r2=173542&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=173542&r1=173541&r2=173542&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)<br>+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Fri Jan 25 18:55:12 2013<br>@@ -268,6 +268,10 @@ const FileEntry *DirectoryLookup::Lookup<br>  return Result;<br>}<br><br>+/// FIXME: HACK HACK HACK!<br>+static llvm::DenseMap<const DirectoryEntry *, const DirectoryEntry *><br>+  TopFrameworkDirs;<br>+<br></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">Hi Doug,</div></blockquote><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">Is the TopFrameworkDirs map actually used?</div></blockquote><br>Thankfully, no. Removed in r176535.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">  </span>- Doug</div><div><br></div><br></body></html>