Add a single-entry cache for macro instantation locations. This significantly

reduces the number of FileID's made and tracked.

llvm-svn: 38752
This commit is contained in:
Chris Lattner 2006-07-20 06:48:52 +00:00
parent a5f4c882e2
commit 7fa8c889e2
2 changed files with 25 additions and 5 deletions

View File

@ -121,11 +121,24 @@ SourceLocation SourceManager::getInstantiationLoc(SourceLocation PhysLoc,
// Resolve InstantLoc down to a real logical location.
InstantLoc = getLogicalLoc(InstantLoc);
// Add a FileID for this. FIXME: should cache these!
FileIDs.push_back(FileIDInfo::getMacroExpansion(InstantLoc,
PhysLoc.getFileID()));
unsigned InstantiationFileID = FileIDs.size();
unsigned InstantiationFileID;
// If this is the same instantiation as was requested last time, return this
// immediately.
if (PhysLoc.getFileID() == LastInstantiationLoc_MacroFID &&
InstantLoc == LastInstantiationLoc_InstantLoc) {
InstantiationFileID = LastInstantiationLoc_Result;
} else {
// Add a FileID for this. FIXME: should cache these!
FileIDs.push_back(FileIDInfo::getMacroExpansion(InstantLoc,
PhysLoc.getFileID()));
InstantiationFileID = FileIDs.size();
// Remember this in the single-entry cache for next time.
LastInstantiationLoc_MacroFID = PhysLoc.getFileID();
LastInstantiationLoc_InstantLoc = InstantLoc;
LastInstantiationLoc_Result = InstantiationFileID;
}
return SourceLocation(InstantiationFileID, PhysLoc.getRawFilePos());
}

View File

@ -165,7 +165,14 @@ class SourceManager {
/// FileIDs - Information about each FileID. FileID #0 is not valid, so all
/// entries are off by one.
std::vector<SrcMgr::FileIDInfo> FileIDs;
/// LastInstantiationLoc_* - Cache the last instantiation request for fast
/// lookup. Macros often want many tokens instantated at the same location.
SourceLocation LastInstantiationLoc_InstantLoc;
unsigned LastInstantiationLoc_MacroFID;
unsigned LastInstantiationLoc_Result;
public:
SourceManager() { LastInstantiationLoc_MacroFID = ~0U; }
~SourceManager();
/// createFileID - Create a new FileID that represents the specified file