r369958 - ContentCache: Drop getBuffer's dependency on SourceManager
Duncan P. N. Exon Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 26 13:32:05 PDT 2019
Author: dexonsmith
Date: Mon Aug 26 13:32:05 2019
New Revision: 369958
URL: http://llvm.org/viewvc/llvm-project?rev=369958&view=rev
Log:
ContentCache: Drop getBuffer's dependency on SourceManager
Refactor ContentCache::IsSystemFile to IsFileVolatile, checking
SourceManager::userFilesAreVolatile at construction time. This is a
step toward lowering ContentCache down from SourceManager to
FileManager.
No functionality change intended.
https://reviews.llvm.org/D66713
Modified:
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=369958&r1=369957&r2=369958&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Mon Aug 26 13:32:05 2019
@@ -140,9 +140,9 @@ namespace SrcMgr {
/// exist.
unsigned BufferOverridden : 1;
- /// True if this content cache was initially created for a source
- /// file considered as a system one.
- unsigned IsSystemFile : 1;
+ /// True if this content cache was initially created for a source file
+ /// considered to be volatile (likely to change between stat and open).
+ unsigned IsFileVolatile : 1;
/// True if this file may be transient, that is, if it might not
/// exist at some later point in time when this content entry is used,
@@ -152,15 +152,15 @@ namespace SrcMgr {
ContentCache(const FileEntry *Ent = nullptr) : ContentCache(Ent, Ent) {}
ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
- : Buffer(nullptr, false), OrigEntry(Ent), ContentsEntry(contentEnt),
- BufferOverridden(false), IsSystemFile(false), IsTransient(false) {}
+ : Buffer(nullptr, false), OrigEntry(Ent), ContentsEntry(contentEnt),
+ BufferOverridden(false), IsFileVolatile(false), IsTransient(false) {}
/// The copy ctor does not allow copies where source object has either
/// a non-NULL Buffer or SourceLineCache. Ownership of allocated memory
/// is not transferred, so this is a logical error.
ContentCache(const ContentCache &RHS)
- : Buffer(nullptr, false), BufferOverridden(false), IsSystemFile(false),
- IsTransient(false) {
+ : Buffer(nullptr, false), BufferOverridden(false),
+ IsFileVolatile(false), IsTransient(false) {
OrigEntry = RHS.OrigEntry;
ContentsEntry = RHS.ContentsEntry;
@@ -185,7 +185,7 @@ namespace SrcMgr {
///
/// \param Invalid If non-NULL, will be set \c true if an error occurred.
const llvm::MemoryBuffer *getBuffer(DiagnosticsEngine &Diag,
- const SourceManager &SM,
+ FileManager &FM,
SourceLocation Loc = SourceLocation(),
bool *Invalid = nullptr) const;
@@ -986,8 +986,8 @@ public:
return getFakeBufferForRecovery();
}
- return Entry.getFile().getContentCache()->getBuffer(Diag, *this, Loc,
- Invalid);
+ return Entry.getFile().getContentCache()->getBuffer(Diag, getFileManager(),
+ Loc, Invalid);
}
const llvm::MemoryBuffer *getBuffer(FileID FID,
@@ -1001,9 +1001,8 @@ public:
return getFakeBufferForRecovery();
}
- return Entry.getFile().getContentCache()->getBuffer(Diag, *this,
- SourceLocation(),
- Invalid);
+ return Entry.getFile().getContentCache()->getBuffer(
+ Diag, getFileManager(), SourceLocation(), Invalid);
}
/// Returns the FileEntry record for the provided FileID.
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=369958&r1=369957&r2=369958&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Aug 26 13:32:05 2019
@@ -8503,8 +8503,9 @@ Expected<FileID> ASTImporter::Import(Fil
if (ToID.isInvalid() || IsBuiltin) {
// FIXME: We want to re-use the existing MemoryBuffer!
bool Invalid = true;
- const llvm::MemoryBuffer *FromBuf = Cache->getBuffer(
- FromContext.getDiagnostics(), FromSM, SourceLocation{}, &Invalid);
+ const llvm::MemoryBuffer *FromBuf =
+ Cache->getBuffer(FromContext.getDiagnostics(),
+ FromSM.getFileManager(), SourceLocation{}, &Invalid);
if (!FromBuf || Invalid)
// FIXME: Use a new error kind?
return llvm::make_error<ImportError>(ImportError::Unknown);
Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=369958&r1=369957&r2=369958&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Mon Aug 26 13:32:05 2019
@@ -96,7 +96,7 @@ void ContentCache::replaceBuffer(const l
}
const llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag,
- const SourceManager &SM,
+ FileManager &FM,
SourceLocation Loc,
bool *Invalid) const {
// Lazily create the Buffer for ContentCaches that wrap files. If we already
@@ -134,9 +134,7 @@ const llvm::MemoryBuffer *ContentCache::
return Buffer.getPointer();
}
- bool isVolatile = SM.userFilesAreVolatile() && !IsSystemFile;
- auto BufferOrError =
- SM.getFileManager().getBufferForFile(ContentsEntry, isVolatile);
+ auto BufferOrError = FM.getBufferForFile(ContentsEntry, IsFileVolatile);
// If we were unable to open the file, then we are in an inconsistent
// situation where the content cache referenced a file which no longer
@@ -389,7 +387,7 @@ void SourceManager::initializeForReplay(
Clone->OrigEntry = Cache->OrigEntry;
Clone->ContentsEntry = Cache->ContentsEntry;
Clone->BufferOverridden = Cache->BufferOverridden;
- Clone->IsSystemFile = Cache->IsSystemFile;
+ Clone->IsFileVolatile = Cache->IsFileVolatile;
Clone->IsTransient = Cache->IsTransient;
Clone->replaceBuffer(Cache->getRawBuffer(), /*DoNotFree*/true);
return Clone;
@@ -438,7 +436,7 @@ SourceManager::getOrCreateContentCache(c
new (Entry) ContentCache(FileEnt);
}
- Entry->IsSystemFile = isSystemFile;
+ Entry->IsFileVolatile = UserFilesAreVolatile && !isSystemFile;
Entry->IsTransient = FilesAreTransient;
return Entry;
@@ -645,7 +643,7 @@ const llvm::MemoryBuffer *
SourceManager::getMemoryBufferForFile(const FileEntry *File, bool *Invalid) {
const SrcMgr::ContentCache *IR = getOrCreateContentCache(File);
assert(IR && "getOrCreateContentCache() cannot return NULL");
- return IR->getBuffer(Diag, *this, SourceLocation(), Invalid);
+ return IR->getBuffer(Diag, getFileManager(), SourceLocation(), Invalid);
}
void SourceManager::overrideFileContents(const FileEntry *SourceFile,
@@ -699,7 +697,7 @@ StringRef SourceManager::getBufferData(F
}
const llvm::MemoryBuffer *Buf = SLoc.getFile().getContentCache()->getBuffer(
- Diag, *this, SourceLocation(), &MyInvalid);
+ Diag, getFileManager(), SourceLocation(), &MyInvalid);
if (Invalid)
*Invalid = MyInvalid;
@@ -1130,7 +1128,7 @@ const char *SourceManager::getCharacterD
}
const llvm::MemoryBuffer *Buffer =
Entry.getFile().getContentCache()->getBuffer(
- Diag, *this, SourceLocation(), &CharDataInvalid);
+ Diag, getFileManager(), SourceLocation(), &CharDataInvalid);
if (Invalid)
*Invalid = CharDataInvalid;
return Buffer->getBufferStart() + (CharDataInvalid? 0 : LocInfo.second);
@@ -1227,7 +1225,7 @@ static void ComputeLineNumbers(Diagnosti
const SourceManager &SM, bool &Invalid) {
// Note that calling 'getBuffer()' may lazily page in the file.
const MemoryBuffer *Buffer =
- FI->getBuffer(Diag, SM, SourceLocation(), &Invalid);
+ FI->getBuffer(Diag, SM.getFileManager(), SourceLocation(), &Invalid);
if (Invalid)
return;
@@ -1458,7 +1456,7 @@ PresumedLoc SourceManager::getPresumedLo
if (C->OrigEntry)
Filename = C->OrigEntry->getName();
else
- Filename = C->getBuffer(Diag, *this)->getBufferIdentifier();
+ Filename = C->getBuffer(Diag, getFileManager())->getBufferIdentifier();
unsigned LineNo = getLineNumber(LocInfo.first, LocInfo.second, &Invalid);
if (Invalid)
@@ -1658,13 +1656,13 @@ SourceLocation SourceManager::translateL
}
if (Line > Content->NumLines) {
- unsigned Size = Content->getBuffer(Diag, *this)->getBufferSize();
+ unsigned Size = Content->getBuffer(Diag, getFileManager())->getBufferSize();
if (Size > 0)
--Size;
return FileLoc.getLocWithOffset(Size);
}
- const llvm::MemoryBuffer *Buffer = Content->getBuffer(Diag, *this);
+ const llvm::MemoryBuffer *Buffer = Content->getBuffer(Diag, getFileManager());
unsigned FilePos = Content->SourceLineCache[Line - 1];
const char *Buf = Buffer->getBufferStart() + FilePos;
unsigned BufLength = Buffer->getBufferSize() - FilePos;
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=369958&r1=369957&r2=369958&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Mon Aug 26 13:32:05 2019
@@ -1804,12 +1804,12 @@ void ASTWriter::WriteInputFiles(SourceMa
InputFileEntry Entry;
Entry.File = Cache->OrigEntry;
- Entry.IsSystemFile = Cache->IsSystemFile;
+ Entry.IsSystemFile = isSystem(File.getFileCharacteristic());
Entry.IsTransient = Cache->IsTransient;
Entry.BufferOverridden = Cache->BufferOverridden;
Entry.IsTopLevelModuleMap = isModuleMap(File.getFileCharacteristic()) &&
File.getIncludeLoc().isInvalid();
- if (Cache->IsSystemFile)
+ if (Entry.IsSystemFile)
SortedFiles.push_back(Entry);
else
SortedFiles.push_front(Entry);
@@ -2315,8 +2315,8 @@ void ASTWriter::WriteSourceManagerBlock(
// We add one to the size so that we capture the trailing NULL
// that is required by llvm::MemoryBuffer::getMemBuffer (on
// the reader side).
- const llvm::MemoryBuffer *Buffer
- = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager());
+ const llvm::MemoryBuffer *Buffer =
+ Content->getBuffer(PP.getDiagnostics(), PP.getFileManager());
StringRef Name = Buffer->getBufferIdentifier();
Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record,
StringRef(Name.data(), Name.size() + 1));
@@ -2330,7 +2330,7 @@ void ASTWriter::WriteSourceManagerBlock(
// Include the implicit terminating null character in the on-disk buffer
// if we're writing it uncompressed.
const llvm::MemoryBuffer *Buffer =
- Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager());
+ Content->getBuffer(PP.getDiagnostics(), PP.getFileManager());
StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1);
emitBlob(Stream, Blob, SLocBufferBlobCompressedAbbrv,
SLocBufferBlobAbbrv);
More information about the cfe-commits
mailing list