Lazily load the controlling macros for all of the headers known in the
PCH file. In the Cocoa-prefixed "Hello, World" benchmark, this takes
us from reading 503 identifiers down to 37 and from 470 macros down to
4. It also results in an 8% performance improvement.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70094 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp
index 344c4eb..8b74b20 100644
--- a/lib/Basic/IdentifierTable.cpp
+++ b/lib/Basic/IdentifierTable.cpp
@@ -42,6 +42,8 @@
 
 IdentifierInfoLookup::~IdentifierInfoLookup() {}
 
+ExternalIdentifierLookup::~ExternalIdentifierLookup() {}
+
 IdentifierTable::IdentifierTable(const LangOptions &LangOpts,
                                  IdentifierInfoLookup* externalLookup)
   : HashTable(8192), // Start with space for 8K identifiers.
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index 40e5c0d..c351a24 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -1717,7 +1717,7 @@
       HFI.isImport = Record[0];
       HFI.DirInfo = Record[1];
       HFI.NumIncludes = Record[2];
-      HFI.ControllingMacro = DecodeIdentifierInfo(Record[3]);
+      HFI.ControllingMacroID = Record[3];
       PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, NumHeaderInfos++);
       break;
     }
@@ -1854,6 +1854,7 @@
       }
       IdentifierOffsets = (const uint32_t *)BlobStart;
       IdentifiersLoaded.resize(Record[0]);
+      PP.getHeaderSearchInfo().SetExternalLookup(this);
       break;
 
     case pch::EXTERNAL_DEFINITIONS:
diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp
index ddea8e5..129fa1a 100644
--- a/lib/Lex/HeaderSearch.cpp
+++ b/lib/Lex/HeaderSearch.cpp
@@ -20,10 +20,23 @@
 #include <cstdio>
 using namespace clang;
 
+const IdentifierInfo *
+HeaderFileInfo::getControllingMacro(ExternalIdentifierLookup *External) {
+  if (ControllingMacro)
+    return ControllingMacro;
+
+  if (!ControllingMacroID || !External)
+    return 0;
+
+  ControllingMacro = External->GetIdentifier(ControllingMacroID);
+  return ControllingMacro;
+}
+
 HeaderSearch::HeaderSearch(FileManager &FM) : FileMgr(FM), FrameworkMap(64) {
   SystemDirIdx = 0;
   NoCurDirSearch = false;
-  
+ 
+  ExternalLookup = 0;
   NumIncluded = 0;
   NumMultiIncludeFileOptzn = 0;
   NumFrameworkLookups = NumSubFrameworkLookups = 0;
@@ -417,11 +430,12 @@
   
   // Next, check to see if the file is wrapped with #ifndef guards.  If so, and
   // if the macro that guards it is defined, we know the #include has no effect.
-  if (FileInfo.ControllingMacro &&
-      FileInfo.ControllingMacro->hasMacroDefinition()) {
-    ++NumMultiIncludeFileOptzn;
-    return false;
-  }
+  if (const IdentifierInfo *ControllingMacro 
+      = FileInfo.getControllingMacro(ExternalLookup))
+    if (ControllingMacro->hasMacroDefinition()) {
+      ++NumMultiIncludeFileOptzn;
+      return false;
+    }
   
   // Increment the number of times this file has been included.
   ++FileInfo.NumIncludes;