diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -765,8 +765,8 @@ /// in a submodule. SubmoduleState *CurSubmoduleState; - /// The number of times each file was included. - llvm::DenseMap IncludedFiles; + /// The files that have been included. + llvm::DenseSet IncludedFiles; /// The set of known macros exported from modules. llvm::FoldingSet ModuleMacros; @@ -1230,9 +1230,7 @@ /// Increment the count for the number of times the specified FileEntry has /// been entered. Returns true if this is the first time it file was included. bool incrementIncludeCount(const FileEntry *File) { - auto It = IncludedFiles.insert({File, 0}); - ++It.first->second; - return It.second; + return IncludedFiles.insert(File).second; } /// Return true if this header has already been included. @@ -1240,12 +1238,11 @@ return IncludedFiles.count(File); } - /// Get the included files along with the include count. - llvm::DenseMap &getIncludedFiles() { + /// Get the included files. + llvm::DenseSet &getIncludedFiles() { return IncludedFiles; } - const llvm::DenseMap & - getIncludedFiles() const { + const llvm::DenseSet &getIncludedFiles() const { return IncludedFiles; } diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -286,15 +286,6 @@ << " token paste (##) operations performed, " << NumFastTokenPaste << " on the fast path.\n"; - unsigned MaxNumIncludes = 0, NumSingleIncludedFiles = 0; - for (const auto &IncludedFile : IncludedFiles) { - if (MaxNumIncludes < IncludedFile.second) - MaxNumIncludes = IncludedFile.second; - NumSingleIncludedFiles += IncludedFile.second == 1; - } - llvm::errs() << NumSingleIncludedFiles << " included exactly once.\n" - << MaxNumIncludes << " max times a file is included.\n"; - llvm::errs() << "\nPreprocessor Memory: " << getTotalMemory() << "B total"; llvm::errs() << "\n BumpPtr: " << BP.getTotalMemory(); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2966,16 +2966,13 @@ const unsigned char *D = (const unsigned char *)Blob.data(); unsigned FileCount = endian::readNext(D); - for (unsigned I = 0; I < FileCount; ++I) { - auto InputFileID = endian::readNext(D); - auto NumIncludes = endian::readNext(D); - - auto InputFileInfo = readInputFileInfo(F, InputFileID); - if (auto File = PP.getFileManager().getFile(InputFileInfo.Filename)) { - unsigned short &PPNumIncludes = PP.getIncludedFiles()[*File]; - PPNumIncludes = std::max(PPNumIncludes, NumIncludes); - } - } + for (unsigned I = 0; I < FileCount; ++D) + for (unsigned Bit = 0; Bit < 8 && I < FileCount; ++Bit, ++I) + if (*D & (1 << Bit)) { + auto InputFileInfo = readInputFileInfo(F, I); + if (auto File = PP.getFileManager().getFile(InputFileInfo.Filename)) + PP.getIncludedFiles().insert(*File); + } } llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2173,22 +2173,20 @@ void ASTWriter::writeIncludedFiles(raw_ostream &Out, const Preprocessor &PP) { using namespace llvm::support; - std::vector> IncludedInputFiles; + std::vector IncludedInputFiles; for (const auto &File : PP.getIncludedFiles()) { - auto InputFileIt = InputFileIDs.find(File.first); - if (InputFileIt != InputFileIDs.end()) - IncludedInputFiles.emplace_back(InputFileIt->second, File.second); + auto InputFileIt = InputFileIDs.find(File); + if (InputFileIt == InputFileIDs.end()) + continue; + auto InputFileID = InputFileIt->second; + if (IncludedInputFiles.size() <= InputFileID) + IncludedInputFiles.resize(InputFileID + 1); + IncludedInputFiles[InputFileIt->second] = true; } - llvm::sort(IncludedInputFiles); - endian::Writer LE(Out, little); LE.write(IncludedInputFiles.size()); - - for (const auto &IncludedInputFile : IncludedInputFiles) { - LE.write(IncludedInputFile.first); - LE.write(IncludedInputFile.second); - } + Out << bytes(IncludedInputFiles); } /// Writes the block containing the serialized form of the