forked from OSchip/llvm-project
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:
parent
a5f4c882e2
commit
7fa8c889e2
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue