[cfe-commits] r40390 - in /cfe/trunk: Lex/HeaderSearch.cpp include/clang/Lex/HeaderSearch.h
Chris Lattner
sabre at nondot.org
Sun Jul 22 00:28:03 PDT 2007
Author: lattner
Date: Sun Jul 22 02:28:00 2007
New Revision: 40390
URL: http://llvm.org/viewvc/llvm-project?rev=40390&view=rev
Log:
Implement a simple cache in headersearch. This speeds up
preprocessing 483.xalancbmk by about 10%, reducing the number
of file lookup queries from 2139411 to 199466 (over 10x)
Modified:
cfe/trunk/Lex/HeaderSearch.cpp
cfe/trunk/include/clang/Lex/HeaderSearch.h
Modified: cfe/trunk/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/HeaderSearch.cpp?rev=40390&r1=40389&r2=40390&view=diff
==============================================================================
--- cfe/trunk/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/Lex/HeaderSearch.cpp Sun Jul 22 02:28:00 2007
@@ -163,6 +163,26 @@
if (FromDir)
i = FromDir-&SearchDirs[0];
+ // Cache all of the lookups performed by this method. Many headers are
+ // multiply included, and the "pragma once" optimization prevents them from
+ // being relex/pp'd, but they would still have to search through a
+ // (potentially huge) series of SearchDirs to find it.
+ std::pair<unsigned, unsigned> &CacheLookup =
+ LookupFileCache.GetOrCreateValue(FilenameStart, FilenameEnd).getValue();
+
+ // If the entry has been previously looked up, the first value will be
+ // non-zero. If the value is equal to i (the start point of our search), then
+ // this is a matching hit.
+ if (CacheLookup.first == i+1) {
+ // Skip querying potentially lots of directories for this lookup.
+ i = CacheLookup.second;
+ } else {
+ // Otherwise, this is the first query, or the previous query didn't match
+ // our search start. We will fill in our found location below, so prime the
+ // start point value.
+ CacheLookup.first = i+1;
+ }
+
// Check each directory in sequence to see if it contains this file.
for (; i != SearchDirs.size(); ++i) {
const FileEntry *FE = 0;
@@ -183,11 +203,15 @@
// This file is a system header or C++ unfriendly if the dir is.
getFileInfo(FE).DirInfo = CurDir->getDirCharacteristic();
+
+ // Remember this location for the next lookup we do.
+ CacheLookup.second = i;
return FE;
}
}
- // Otherwise, didn't find it.
+ // Otherwise, didn't find it. Remember we didn't find this.
+ CacheLookup.second = SearchDirs.size();
return 0;
}
Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=40390&r1=40389&r2=40390&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Sun Jul 22 02:28:00 2007
@@ -68,6 +68,15 @@
///
std::vector<PerFileInfo> FileInfo;
+ /// LookupFileCache - This is keeps track of each lookup performed by
+ /// LookupFile. The first part of the value is the starting index in
+ /// SearchDirs that the cached search was performed from. If there is a hit
+ /// and this value doesn't match the current query, the cache has to be
+ /// ignored. The second value is the entry in SearchDirs that satisfied the
+ /// query.
+ llvm::StringMap<std::pair<unsigned, unsigned> > LookupFileCache;
+
+
/// FrameworkMap - This is a collection mapping a framework or subframework
/// name like "Carbon" to the Carbon.framework directory.
llvm::StringMap<const DirectoryEntry *> FrameworkMap;
@@ -88,6 +97,7 @@
SearchDirs = dirs;
SystemDirIdx = systemDirIdx;
NoCurDirSearch = noCurDirSearch;
+ //LookupFileCache.clear();
}
/// ClearFileInfo - Forget everything we know about headers so far.
More information about the cfe-commits
mailing list