@@ -28,14 +28,14 @@ struct CachedFileContents {
28
28
CachedFileContents (std::unique_ptr<llvm::MemoryBuffer> Original)
29
29
: Original(std::move(Original)), MinimizedAccess(nullptr ) {}
30
30
31
- // / Owning storage for the minimized contents.
31
+ // / Owning storage for the original contents.
32
32
std::unique_ptr<llvm::MemoryBuffer> Original;
33
33
34
- // / The mutex that must be locked before mutating minimized contents .
34
+ // / The mutex that must be locked before mutating directive tokens .
35
35
std::mutex ValueLock;
36
36
// / Owning storage for the minimized contents.
37
37
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.
39
39
std::atomic<llvm::MemoryBuffer *> MinimizedAccess;
40
40
// / Skipped range mapping of the minimized contents.
41
41
// / This is initialized iff `MinimizedAccess != nullptr`.
@@ -46,8 +46,8 @@ struct CachedFileContents {
46
46
// / the dependency scanning filesystem.
47
47
// /
48
48
// / 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,
51
51
// / - directory entry with its stat value,
52
52
// / - filesystem error.
53
53
// /
@@ -84,8 +84,9 @@ class CachedFileSystemEntry {
84
84
return Contents->Original ->getBuffer ();
85
85
}
86
86
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 {
89
90
assert (!isError () && " error" );
90
91
assert (!MaybeStat->isDirectory () && " not a file" );
91
92
assert (Contents && " contents not initialized" );
@@ -119,8 +120,8 @@ class CachedFileSystemEntry {
119
120
return Contents->PPSkippedRangeMapping ;
120
121
}
121
122
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 {
124
125
assert (!isError () && " error" );
125
126
assert (!isDirectory () && " not a file" );
126
127
return Contents;
@@ -145,7 +146,7 @@ class CachedFileSystemEntry {
145
146
};
146
147
147
148
// / 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
149
150
// / files.
150
151
// /
151
152
// / It is sharded based on the hash of the key to reduce the lock contention for
@@ -210,8 +211,7 @@ class DependencyScanningFilesystemSharedCache {
210
211
};
211
212
212
213
// / 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.
215
215
class DependencyScanningFilesystemLocalCache {
216
216
llvm::StringMap<const CachedFileSystemEntry *, llvm::BumpPtrAllocator> Cache;
217
217
@@ -234,9 +234,8 @@ class DependencyScanningFilesystemLocalCache {
234
234
};
235
235
236
236
// / 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.
240
239
class EntryRef {
241
240
// / For entry that is an opened file, this bit signifies whether its contents
242
241
// / are minimized.
@@ -270,8 +269,7 @@ class EntryRef {
270
269
}
271
270
272
271
StringRef getContents () const {
273
- return Minimized ? Entry.getMinimizedContents ()
274
- : Entry.getOriginalContents ();
272
+ return Minimized ? Entry.getDirectiveTokens () : Entry.getOriginalContents ();
275
273
}
276
274
277
275
const PreprocessorSkippedRangeMapping *getPPSkippedRangeMapping () const {
@@ -301,33 +299,33 @@ class DependencyScanningWorkerFilesystem : public llvm::vfs::ProxyFileSystem {
301
299
llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
302
300
openFileForRead (const Twine &Path) override ;
303
301
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 (); }
308
306
309
307
private:
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);
312
310
313
311
// / Returns entry for the given filename.
314
312
// /
315
313
// / Attempts to use the local and shared caches first, then falls back to
316
314
// / using the underlying filesystem.
317
315
llvm::ErrorOr<EntryRef>
318
316
getOrCreateFileSystemEntry (StringRef Filename,
319
- bool DisableMinimization = false );
317
+ bool DisableDirectivesScanning = false );
320
318
321
319
// / For a filename that's not yet associated with any entry in the caches,
322
320
// / uses the underlying filesystem to either look up the entry based in the
323
321
// / shared cache indexed by unique ID, or creates new entry from scratch.
324
322
llvm::ErrorOr<const CachedFileSystemEntry &>
325
323
computeAndStoreResult (StringRef Filename);
326
324
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);
331
329
332
330
// / Represents a filesystem entry that has been stat-ed (and potentially read)
333
331
// / and that's about to be inserted into the cache as `CachedFileSystemEntry`.
@@ -402,8 +400,8 @@ class DependencyScanningWorkerFilesystem : public llvm::vfs::ProxyFileSystem {
402
400
// / excluded conditional directive skip mappings that are used by the
403
401
// / currently active preprocessor.
404
402
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 ;
407
405
};
408
406
409
407
} // end namespace dependencies
0 commit comments