aboutsummaryrefslogtreecommitdiff
path: root/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-07-20 18:00:12 +0000
committerChris Lattner <sabre@nondot.org>2007-07-20 18:00:12 +0000
commit31bb8be680ee2facf7fbb3c6c87b9bbd20248328 (patch)
tree98b4ef62ca73a3e8f867efa2deda7b8bd4f57f19 /Basic/SourceManager.cpp
parent60c3a1ba7a9d7ce31fcf39690631e716c3d356e9 (diff)
improve comments, implement a trivial single-entry cache in
SourceManager::getInstantiationLoc. With this change, every token expanded from a macro doesn't get its own MacroID. :) This reduces # macro IDs in carbon.h from 16805 to 9197 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40108 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Basic/SourceManager.cpp')
-rw-r--r--Basic/SourceManager.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/Basic/SourceManager.cpp b/Basic/SourceManager.cpp
index 3e2623c8e4..09941635da 100644
--- a/Basic/SourceManager.cpp
+++ b/Basic/SourceManager.cpp
@@ -165,16 +165,35 @@ unsigned SourceManager::createFileID(const InfoRec *File,
/// getInstantiationLoc - Return a new SourceLocation that encodes the fact
/// that a token from physloc PhysLoc should actually be referenced from
/// InstantiationLoc.
-SourceLocation SourceManager::getInstantiationLoc(SourceLocation VirtLoc,
+SourceLocation SourceManager::getInstantiationLoc(SourceLocation PhysLoc,
SourceLocation InstantLoc) {
// The specified source location may be a mapped location, due to a macro
// instantiation or #line directive. Strip off this information to find out
// where the characters are actually located.
- SourceLocation PhysLoc = getPhysicalLoc(VirtLoc);
+ PhysLoc = getPhysicalLoc(PhysLoc);
// Resolve InstantLoc down to a real logical location.
InstantLoc = getLogicalLoc(InstantLoc);
+
+ // If the last macro id is close to the currently requested location, try to
+ // reuse it. This implements a single-entry cache.
+ if (!MacroIDs.empty()) {
+ MacroIDInfo &LastOne = MacroIDs.back();
+ if (LastOne.getInstantiationLoc() == InstantLoc &&
+ LastOne.getPhysicalLoc().getFileID() == PhysLoc.getFileID()) {
+
+ int PhysDelta = PhysLoc.getRawFilePos() -
+ LastOne.getPhysicalLoc().getRawFilePos();
+ if (unsigned(PhysDelta) < (1 << SourceLocation::MacroPhysOffsBits))
+ return SourceLocation::getMacroLoc(MacroIDs.size()-1,
+ (unsigned)PhysDelta, 0);
+
+ }
+ }
+
+
+
// FIXME: intelligently cache macroid's.
MacroIDs.push_back(MacroIDInfo::get(InstantLoc, PhysLoc));