]> granicus.if.org Git - clang/commitdiff
[modules] Make the include guard optimization fire a bit more when considering
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 1 Jul 2015 01:51:38 +0000 (01:51 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 1 Jul 2015 01:51:38 +0000 (01:51 +0000)
re-entering a modular header.

When we do the include guard check, we're in the visibility state for the file
with the #include; the include guard may not be visible there, but we don't
actually need it to be: if we've already parsed the submodule we're considering
entering, it's always safe to skip it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241135 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/HeaderSearch.h
lib/Lex/HeaderSearch.cpp
lib/Lex/PPDirectives.cpp

index 0406c6d586ff21255cb764485882f153e53be0ee..da640e232549131cf8076cf2a4df853848f59e5d 100644 (file)
@@ -421,7 +421,7 @@ public:
   /// \return false if \#including the file will have no effect or true
   /// if we should include it.
   bool ShouldEnterIncludeFile(Preprocessor &PP, const FileEntry *File,
-                              bool isImport);
+                              bool isImport, Module *CorrespondingModule);
 
   /// \brief Return whether the specified file is a normal header,
   /// a system header, or a C++ friendly system header.
index 7a98f5418334f54f10b426d49ff9f0ca02ecd2cb..67a00586a64c32c91be02de84f1690a5e0a9fd1e 100644 (file)
@@ -1025,7 +1025,7 @@ void HeaderSearch::MarkFileModuleHeader(const FileEntry *FE,
 
 bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP,
                                           const FileEntry *File,
-                                          bool isImport) {
+                                          bool isImport, Module *M) {
   ++NumIncluded; // Count # of attempted #includes.
 
   // Get information about this file.
@@ -1050,7 +1050,11 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP,
   // if the macro that guards it is defined, we know the #include has no effect.
   if (const IdentifierInfo *ControllingMacro
       = FileInfo.getControllingMacro(ExternalLookup))
-    if (PP.isMacroDefined(ControllingMacro)) {
+    // If the include file is part of a module, and we already know what its
+    // controlling macro is, then we've already parsed it and can safely just
+    // make it visible. This saves us needing to switch into the visibility
+    // state of the module just to check whether the macro is defined within it.
+    if (M || PP.isMacroDefined(ControllingMacro)) {
       ++NumMultiIncludeFileOptzn;
       return false;
     }
index 33ce799228197553e802b5e2ad31dbb39a368b04..ce64538de41b22a13fbce6342409f28e63275d00 100644 (file)
@@ -1749,7 +1749,8 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
   // Ask HeaderInfo if we should enter this #include file.  If not, #including
   // this file will have no effect.
   if (ShouldEnter &&
-      !HeaderInfo.ShouldEnterIncludeFile(*this, File, isImport)) {
+      !HeaderInfo.ShouldEnterIncludeFile(*this, File, isImport,
+                                         SuggestedModule.getModule())) {
     ShouldEnter = false;
     if (Callbacks)
       Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);