From eb2307ce1618cca67fa1cbdae8a129c071b1c8c1 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 19 Feb 2016 22:43:58 +0000 Subject: [PATCH] [modules] Do less scanning of macro definition chains when computing the set of exported module macros outside local submodule visibility mode. Related to PR24667. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261373 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/PPLexerChange.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp index 2f09841c5b..235cc3f463 100644 --- a/lib/Lex/PPLexerChange.cpp +++ b/lib/Lex/PPLexerChange.cpp @@ -681,21 +681,36 @@ void Preprocessor::LeaveSubmodule() { Module *LeavingMod = Info.M; SourceLocation ImportLoc = Info.ImportLoc; + if ((!getLangOpts().CompilingModule || + LeavingMod->getTopLevelModuleName() != getLangOpts().CurrentModule) && + !getLangOpts().ModulesLocalVisibility) { + // Fast path: if we're leaving a modular header that we included textually, + // and we're not building the interface for that module, and we're not + // providing submodule visibility semantics regardless, then we don't need + // to create ModuleMacros. (We'd never use them.) + BuildingSubmoduleStack.pop_back(); + makeModuleVisible(LeavingMod, ImportLoc); + return; + } + // Create ModuleMacros for any macros defined in this submodule. for (auto &Macro : CurSubmoduleState->Macros) { auto *II = const_cast(Macro.first); // Find the starting point for the MacroDirective chain in this submodule. MacroDirective *OldMD = nullptr; - if (getLangOpts().ModulesLocalVisibility) { + auto *OldState = Info.OuterSubmoduleState; + if (getLangOpts().ModulesLocalVisibility) + OldState = &NullSubmoduleState; + if (OldState && OldState != CurSubmoduleState) { // FIXME: It'd be better to start at the state from when we most recently // entered this submodule, but it doesn't really matter. - auto &PredefMacros = NullSubmoduleState.Macros; - auto PredefMacroIt = PredefMacros.find(Macro.first); - if (PredefMacroIt == PredefMacros.end()) + auto &OldMacros = OldState->Macros; + auto OldMacroIt = OldMacros.find(Macro.first); + if (OldMacroIt == OldMacros.end()) OldMD = nullptr; else - OldMD = PredefMacroIt->second.getLatest(); + OldMD = OldMacroIt->second.getLatest(); } // This module may have exported a new macro. If so, create a ModuleMacro -- 2.40.0