From c4436f675d8f5903303fc13d2c2eff2c5800d49b Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Wed, 16 Nov 2022 16:07:34 -0800 Subject: [clang] Use InMemoryModuleCache for readASTFileControlBlock NFC When a pcm has already been loaded from disk, reuse it from the InMemoryModuleCache in readASTFileControlBlock. This avoids potentially reading it again. As noted in the FIXME, ideally we would also add the module to the cache if it will be used again later, but that could modify its build state and we do not have enough context currenlty to know if it's correct. Differential Revision: https://reviews.llvm.org/D138160 --- clang/lib/Frontend/CompilerInstance.cpp | 3 ++- clang/lib/Frontend/FrontendAction.cpp | 5 +++-- clang/lib/Frontend/FrontendActions.cpp | 10 ++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'clang/lib/Frontend') diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 6402f16..79bbf37 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -252,7 +252,8 @@ static void collectIncludePCH(CompilerInstance &CI, // used here since we're not interested in validating the PCH at this time, // but only to check whether this is a file containing an AST. if (!ASTReader::readASTFileControlBlock( - Dir->path(), FileMgr, CI.getPCHContainerReader(), + Dir->path(), FileMgr, CI.getModuleCache(), + CI.getPCHContainerReader(), /*FindModuleFileExtensions=*/false, Validator, /*ValidateDiagnosticOptions=*/false)) MDC->addFile(Dir->path()); diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 76ef0cb..8fa96be2 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -778,8 +778,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, Dir != DirEnd && !EC; Dir.increment(EC)) { // Check whether this is an acceptable AST file. if (ASTReader::isAcceptableASTFile( - Dir->path(), FileMgr, CI.getPCHContainerReader(), - CI.getLangOpts(), CI.getTargetOpts(), CI.getPreprocessorOpts(), + Dir->path(), FileMgr, CI.getModuleCache(), + CI.getPCHContainerReader(), CI.getLangOpts(), + CI.getTargetOpts(), CI.getPreprocessorOpts(), SpecificModuleCachePath, /*RequireStrictOptionMatches=*/true)) { PPOpts.ImplicitPCHInclude = std::string(Dir->path()); Found = true; diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index b4ec389..dfb7267 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -851,7 +851,8 @@ void DumpModuleInfoAction::ExecuteAction() { assert(isCurrentFileAST() && "dumping non-AST?"); // Set up the output file. std::unique_ptr OutFile; - StringRef OutputFileName = getCompilerInstance().getFrontendOpts().OutputFile; + CompilerInstance &CI = getCompilerInstance(); + StringRef OutputFileName = CI.getFrontendOpts().OutputFile; if (!OutputFileName.empty() && OutputFileName != "-") { std::error_code EC; OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC, @@ -861,14 +862,14 @@ void DumpModuleInfoAction::ExecuteAction() { llvm::raw_ostream &Out = OutputStream ? *OutputStream : llvm::outs(); Out << "Information for module file '" << getCurrentFile() << "':\n"; - auto &FileMgr = getCompilerInstance().getFileManager(); + auto &FileMgr = CI.getFileManager(); auto Buffer = FileMgr.getBufferForFile(getCurrentFile()); StringRef Magic = (*Buffer)->getMemBufferRef().getBuffer(); bool IsRaw = (Magic.size() >= 4 && Magic[0] == 'C' && Magic[1] == 'P' && Magic[2] == 'C' && Magic[3] == 'H'); Out << " Module format: " << (IsRaw ? "raw" : "obj") << "\n"; - Preprocessor &PP = getCompilerInstance().getPreprocessor(); + Preprocessor &PP = CI.getPreprocessor(); DumpModuleInfoListener Listener(Out); HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); @@ -966,7 +967,8 @@ void DumpModuleInfoAction::ExecuteAction() { // The reminder of the output is produced from the listener as the AST // FileCcontrolBlock is (re-)parsed. ASTReader::readASTFileControlBlock( - getCurrentFile(), FileMgr, getCompilerInstance().getPCHContainerReader(), + getCurrentFile(), FileMgr, CI.getModuleCache(), + CI.getPCHContainerReader(), /*FindModuleFileExtensions=*/true, Listener, HSOpts.ModulesValidateDiagnosticOptions); } -- cgit v1.1