MK_PrebuiltModule
};
+/// The input file info that has been loaded from an AST file.
+struct InputFileInfo {
+ std::string Filename;
+ uint64_t ContentHash;
+ off_t StoredSize;
+ time_t StoredTime;
+ bool Overridden;
+ bool Transient;
+ bool TopLevelModuleMap;
+};
+
/// The input file that has been loaded from this AST file, along with
/// bools indicating whether this was an overridden buffer or if it was
/// out-of-date or not-found.
/// The input files that have been loaded from this AST file.
std::vector<InputFile> InputFilesLoaded;
+ /// The input file infos that have been loaded from this AST file.
+ std::vector<InputFileInfo> InputFileInfosLoaded;
+
// All user input files reside at the index range [0, NumUserInputFiles), and
// system input files reside at [NumUserInputFiles, InputFilesLoaded.size()).
unsigned NumUserInputFiles = 0;
return false;
}
-ASTReader::InputFileInfo
-ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) {
+InputFileInfo ASTReader::getInputFileInfo(ModuleFile &F, unsigned ID) {
+ // If this ID is bogus, just return an empty input file.
+ if (ID == 0 || ID > F.InputFileInfosLoaded.size())
+ return InputFileInfo();
+
+ // If we've already loaded this input file, return it.
+ if (!F.InputFileInfosLoaded[ID - 1].Filename.empty())
+ return F.InputFileInfosLoaded[ID - 1];
+
// Go find this input file.
BitstreamCursor &Cursor = F.InputFilesCursor;
SavedStreamPosition SavedPosition(Cursor);
}
R.ContentHash = (static_cast<uint64_t>(Record[1]) << 32) |
static_cast<uint64_t>(Record[0]);
+
+ // Note that we've loaded this input file info.
+ F.InputFileInfosLoaded[ID - 1] = R;
return R;
}
consumeError(std::move(Err));
}
- InputFileInfo FI = readInputFileInfo(F, ID);
+ InputFileInfo FI = getInputFileInfo(F, ID);
off_t StoredSize = FI.StoredSize;
time_t StoredTime = FI.StoredTime;
bool Overridden = FI.Overridden;
: NumUserInputs;
for (unsigned I = 0; I < N; ++I) {
bool IsSystem = I >= NumUserInputs;
- InputFileInfo FI = readInputFileInfo(F, I+1);
+ InputFileInfo FI = getInputFileInfo(F, I + 1);
Listener->visitInputFile(FI.Filename, IsSystem, FI.Overridden,
F.Kind == MK_ExplicitModule ||
F.Kind == MK_PrebuiltModule);
F.InputFileOffsets =
(const llvm::support::unaligned_uint64_t *)Blob.data();
F.InputFilesLoaded.resize(NumInputs);
+ F.InputFileInfosLoaded.resize(NumInputs);
F.NumUserInputFiles = NumUserInputs;
break;
}
for (unsigned I = 0; I < FileCount; ++I) {
size_t ID = endian::readNext<uint32_t, little, unaligned>(D);
- InputFileInfo IFI = readInputFileInfo(F, ID);
+ InputFileInfo IFI = getInputFileInfo(F, ID);
if (llvm::ErrorOr<const FileEntry *> File =
PP.getFileManager().getFile(IFI.Filename))
PP.getIncludedFiles().insert(*File);
llvm::function_ref<void(FileEntryRef FE)> Visitor) {
unsigned NumInputs = MF.InputFilesLoaded.size();
for (unsigned I = 0; I < NumInputs; ++I) {
- InputFileInfo IFI = readInputFileInfo(MF, I + 1);
+ InputFileInfo IFI = getInputFileInfo(MF, I + 1);
if (IFI.TopLevelModuleMap)
- // FIXME: This unnecessarily re-reads the InputFileInfo.
if (auto FE = getInputFile(MF, I + 1).getFile())
Visitor(*FE);
}