Skip to content

Commit feca141

Browse files
authored
Merge pull request #7594 from apple/jan_svoboda/sloc-entry-opt
2 parents f051029 + 8c55390 commit feca141

File tree

11 files changed

+321
-199
lines changed

11 files changed

+321
-199
lines changed

clang/include/clang/Basic/SourceLocation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class FileID {
5858
friend class ASTWriter;
5959
friend class ASTReader;
6060
friend class SourceManager;
61+
friend class SourceManagerTestHelper;
6162

6263
static FileID get(int V) {
6364
FileID F;

clang/include/clang/Basic/SourceManager.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,14 @@ class SLocEntry {
504504
return Expansion;
505505
}
506506

507+
/// Creates an incomplete SLocEntry that is only able to report its offset.
508+
static SLocEntry getOffsetOnly(SourceLocation::UIntTy Offset) {
509+
assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large");
510+
SLocEntry E;
511+
E.Offset = Offset;
512+
return E;
513+
}
514+
507515
static SLocEntry get(SourceLocation::UIntTy Offset, const FileInfo &FI) {
508516
assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large");
509517
SLocEntry E;
@@ -538,6 +546,12 @@ class ExternalSLocEntrySource {
538546
/// entry from being loaded.
539547
virtual bool ReadSLocEntry(int ID) = 0;
540548

549+
/// Get the index ID for the loaded SourceLocation offset.
550+
///
551+
/// \returns Invalid index ID (0) if an error occurred that prevented the
552+
/// SLocEntry from being loaded.
553+
virtual int getSLocEntryID(SourceLocation::UIntTy SLocOffset) = 0;
554+
541555
/// Retrieve the module import location and name for the given ID, if
542556
/// in fact it was loaded from a module (rather than, say, a precompiled
543557
/// header).
@@ -706,6 +720,11 @@ class SourceManager : public RefCountedBase<SourceManager> {
706720
/// use (-ID - 2).
707721
SmallVector<SrcMgr::SLocEntry, 0> LoadedSLocEntryTable;
708722

723+
/// For each allocation in LoadedSLocEntryTable, we keep the first FileID.
724+
/// We assume exactly one allocation per AST file, and use that to determine
725+
/// whether two FileIDs come from the same AST file.
726+
SmallVector<FileID, 0> LoadedSLocEntryAllocBegin;
727+
709728
/// The starting offset of the next local SLocEntry.
710729
///
711730
/// This is LocalSLocEntryTable.back().Offset + the size of that entry.
@@ -728,6 +747,12 @@ class SourceManager : public RefCountedBase<SourceManager> {
728747
/// Same indexing as LoadedSLocEntryTable.
729748
llvm::BitVector SLocEntryLoaded;
730749

750+
/// A bitmap that indicates whether the entries of LoadedSLocEntryTable
751+
/// have already had their offset loaded from the external source.
752+
///
753+
/// Superset of SLocEntryLoaded. Same indexing as SLocEntryLoaded.
754+
llvm::BitVector SLocEntryOffsetLoaded;
755+
731756
/// An external source for source location entries.
732757
ExternalSLocEntrySource *ExternalSLocEntries = nullptr;
733758

@@ -1654,6 +1679,11 @@ class SourceManager : public RefCountedBase<SourceManager> {
16541679
isInTheSameTranslationUnit(std::pair<FileID, unsigned> &LOffs,
16551680
std::pair<FileID, unsigned> &ROffs) const;
16561681

1682+
/// Determines whether the two decomposed source location is in the same TU.
1683+
bool isInTheSameTranslationUnitImpl(
1684+
const std::pair<FileID, unsigned> &LOffs,
1685+
const std::pair<FileID, unsigned> &ROffs) const;
1686+
16571687
/// Determines the order of 2 source locations in the "source location
16581688
/// address space".
16591689
bool isBeforeInSLocAddrSpace(SourceLocation LHS, SourceLocation RHS) const {

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const unsigned VERSION_MAJOR = 29;
5151
/// for the previous version could still support reading the new
5252
/// version by ignoring new kinds of subblocks), this number
5353
/// should be increased.
54-
const unsigned VERSION_MINOR = 0;
54+
const unsigned VERSION_MINOR = 1;
5555

5656
/// An ID number that refers to an identifier in an AST file.
5757
///
@@ -535,13 +535,7 @@ enum ASTRecordTypes {
535535
/// of source-location information.
536536
SOURCE_LOCATION_OFFSETS = 14,
537537

538-
/// Record code for the set of source location entries
539-
/// that need to be preloaded by the AST reader.
540-
///
541-
/// This set contains the source location entry for the
542-
/// predefines buffer and for any file entries that need to be
543-
/// preloaded.
544-
SOURCE_LOCATION_PRELOADS = 15,
538+
// ID 15 used to be for source location entry preloads.
545539

546540
/// Record code for the set of ext_vector type names.
547541
EXT_VECTOR_DECLS = 16,

clang/include/clang/Serialization/ASTReader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,6 +2163,12 @@ class ASTReader
21632163

21642164
/// Read the source location entry with index ID.
21652165
bool ReadSLocEntry(int ID) override;
2166+
/// Get the index ID for the loaded SourceLocation offset.
2167+
int getSLocEntryID(SourceLocation::UIntTy SLocOffset) override;
2168+
/// Try to read the offset of the SLocEntry at the given index in the given
2169+
/// module file.
2170+
llvm::Expected<SourceLocation::UIntTy> readSLocOffset(ModuleFile *F,
2171+
unsigned Index);
21662172

21672173
/// Retrieve the module import location and module name for the
21682174
/// given source manager entry ID.

clang/include/clang/Serialization/ModuleFile.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,6 @@ class ModuleFile {
303303
/// AST file.
304304
const uint32_t *SLocEntryOffsets = nullptr;
305305

306-
/// SLocEntries that we're going to preload.
307-
SmallVector<uint64_t, 4> PreloadSLocEntries;
308-
309306
/// Remapping table for source locations in this module.
310307
ContinuousRangeMap<SourceLocation::UIntTy, SourceLocation::IntTy, 2>
311308
SLocRemap;

0 commit comments

Comments
 (0)