@@ -28,14 +28,14 @@ struct CachedFileContents {
2828 CachedFileContents (std::unique_ptr<llvm::MemoryBuffer> Original)
2929 : Original(std::move(Original)), MinimizedAccess(nullptr ) {}
3030
31- // / Owning storage for the minimized contents.
31+ // / Owning storage for the original contents.
3232 std::unique_ptr<llvm::MemoryBuffer> Original;
3333
34- // / The mutex that must be locked before mutating minimized contents .
34+ // / The mutex that must be locked before mutating directive tokens .
3535 std::mutex ValueLock;
3636 // / Owning storage for the minimized contents.
3737 std::unique_ptr<llvm::MemoryBuffer> MinimizedStorage;
38- // / Accessor to the minimized contents that's atomic to avoid data races.
38+ // / Accessor to the directive tokens that's atomic to avoid data races.
3939 std::atomic<llvm::MemoryBuffer *> MinimizedAccess;
4040 // / Skipped range mapping of the minimized contents.
4141 // / This is initialized iff `MinimizedAccess != nullptr`.
@@ -46,8 +46,8 @@ struct CachedFileContents {
4646// / the dependency scanning filesystem.
4747// /
4848// / It represents one of the following:
49- // / - opened file with original contents and a stat value,
50- // / - opened file with original contents, minimized contents and a stat value,
49+ // / - opened file with contents and a stat value,
50+ // / - opened file with contents, directive tokens and a stat value,
5151// / - directory entry with its stat value,
5252// / - filesystem error.
5353// /
@@ -84,8 +84,9 @@ class CachedFileSystemEntry {
8484 return Contents->Original ->getBuffer ();
8585 }
8686
87- // / \returns Minimized contents of the file.
88- StringRef getMinimizedContents () const {
87+ // / \returns The scanned preprocessor directive tokens of the file that are
88+ // / used to speed up preprocessing, if available.
89+ StringRef getDirectiveTokens () const {
8990 assert (!isError () && " error" );
9091 assert (!MaybeStat->isDirectory () && " not a file" );
9192 assert (Contents && " contents not initialized" );
@@ -119,8 +120,8 @@ class CachedFileSystemEntry {
119120 return Contents->PPSkippedRangeMapping ;
120121 }
121122
122- // / \returns The data structure holding both original and minimized contents .
123- CachedFileContents *getContents () const {
123+ // / \returns The data structure holding both contents and directive tokens .
124+ CachedFileContents *getCachedContents () const {
124125 assert (!isError () && " error" );
125126 assert (!isDirectory () && " not a file" );
126127 return Contents;
@@ -145,7 +146,7 @@ class CachedFileSystemEntry {
145146};
146147
147148// / This class is a shared cache, that caches the 'stat' and 'open' calls to the
148- // / underlying real file system. It distinguishes between minimized and original
149+ // / underlying real file system, and the scanned preprocessor directives of
149150// / files.
150151// /
151152// / It is sharded based on the hash of the key to reduce the lock contention for
@@ -210,8 +211,7 @@ class DependencyScanningFilesystemSharedCache {
210211};
211212
212213// / This class is a local cache, that caches the 'stat' and 'open' calls to the
213- // / underlying real file system. It distinguishes between minimized and original
214- // / files.
214+ // / underlying real file system.
215215class DependencyScanningFilesystemLocalCache {
216216 llvm::StringMap<const CachedFileSystemEntry *, llvm::BumpPtrAllocator> Cache;
217217
@@ -234,9 +234,8 @@ class DependencyScanningFilesystemLocalCache {
234234};
235235
236236// / Reference to a CachedFileSystemEntry.
237- // / If the underlying entry is an opened file, this wrapper returns the correct
238- // / contents (original or minimized) and ensures consistency with file size
239- // / reported by status.
237+ // / If the underlying entry is an opened file, this wrapper returns the file
238+ // / contents and the scanned preprocessor directives.
240239class EntryRef {
241240 // / For entry that is an opened file, this bit signifies whether its contents
242241 // / are minimized.
@@ -270,8 +269,7 @@ class EntryRef {
270269 }
271270
272271 StringRef getContents () const {
273- return Minimized ? Entry.getMinimizedContents ()
274- : Entry.getOriginalContents ();
272+ return Minimized ? Entry.getDirectiveTokens () : Entry.getOriginalContents ();
275273 }
276274
277275 const PreprocessorSkippedRangeMapping *getPPSkippedRangeMapping () const {
@@ -301,33 +299,33 @@ class DependencyScanningWorkerFilesystem : public llvm::vfs::ProxyFileSystem {
301299 llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
302300 openFileForRead (const Twine &Path) override ;
303301
304- // / Disable minimization of the given file.
305- void disableMinimization (StringRef Filename);
306- // / Enable minimization of all files.
307- void enableMinimizationOfAllFiles () { NotToBeMinimized .clear (); }
302+ // / Disable directives scanning of the given file.
303+ void disableDirectivesScanning (StringRef Filename);
304+ // / Enable directives scanning of all files.
305+ void enableDirectivesScanningOfAllFiles () { NotToBeScanned .clear (); }
308306
309307private:
310- // / Check whether the file should be minimized .
311- bool shouldMinimize (StringRef Filename, llvm::sys::fs::UniqueID UID);
308+ // / Check whether the file should be scanned for preprocessor directives .
309+ bool shouldScanForDirectives (StringRef Filename, llvm::sys::fs::UniqueID UID);
312310
313311 // / Returns entry for the given filename.
314312 // /
315313 // / Attempts to use the local and shared caches first, then falls back to
316314 // / using the underlying filesystem.
317315 llvm::ErrorOr<EntryRef>
318316 getOrCreateFileSystemEntry (StringRef Filename,
319- bool DisableMinimization = false );
317+ bool DisableDirectivesScanning = false );
320318
321319 // / For a filename that's not yet associated with any entry in the caches,
322320 // / uses the underlying filesystem to either look up the entry based in the
323321 // / shared cache indexed by unique ID, or creates new entry from scratch.
324322 llvm::ErrorOr<const CachedFileSystemEntry &>
325323 computeAndStoreResult (StringRef Filename);
326324
327- // / Minimizes the given entry if necessary and returns a wrapper object with
328- // / reference semantics.
329- EntryRef minimizeIfNecessary (const CachedFileSystemEntry &Entry,
330- StringRef Filename, bool Disable);
325+ // / Scan for preprocessor directives for the given entry if necessary and
326+ // / returns a wrapper object with reference semantics.
327+ EntryRef scanForDirectivesIfNecessary (const CachedFileSystemEntry &Entry,
328+ StringRef Filename, bool Disable);
331329
332330 // / Represents a filesystem entry that has been stat-ed (and potentially read)
333331 // / and that's about to be inserted into the cache as `CachedFileSystemEntry`.
@@ -402,8 +400,8 @@ class DependencyScanningWorkerFilesystem : public llvm::vfs::ProxyFileSystem {
402400 // / excluded conditional directive skip mappings that are used by the
403401 // / currently active preprocessor.
404402 ExcludedPreprocessorDirectiveSkipMapping &PPSkipMappings;
405- // / The set of files that should not be minimized .
406- llvm::DenseSet<llvm::sys::fs::UniqueID> NotToBeMinimized ;
403+ // / The set of files that should not be scanned for PP directives .
404+ llvm::DenseSet<llvm::sys::fs::UniqueID> NotToBeScanned ;
407405};
408406
409407} // end namespace dependencies
0 commit comments