Skip to content

Commit 42823be

Browse files
committed
[Tooling/DependencyScanning] Make skipping excluded PP ranges during dependency scanning the default
This is to improve maintenance a bit and remove need to maintain the additional option and related code-paths. Differential Revision: https://reviews.llvm.org/D124558
1 parent 49942d5 commit 42823be

File tree

9 files changed

+23
-48
lines changed

9 files changed

+23
-48
lines changed

clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class DependencyScanningWorkerFilesystem : public llvm::vfs::ProxyFileSystem {
293293
DependencyScanningWorkerFilesystem(
294294
DependencyScanningFilesystemSharedCache &SharedCache,
295295
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
296-
ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings)
296+
ExcludedPreprocessorDirectiveSkipMapping &PPSkipMappings)
297297
: ProxyFileSystem(std::move(FS)), SharedCache(SharedCache),
298298
PPSkipMappings(PPSkipMappings) {}
299299

@@ -398,10 +398,10 @@ class DependencyScanningWorkerFilesystem : public llvm::vfs::ProxyFileSystem {
398398
/// The local cache is used by the worker thread to cache file system queries
399399
/// locally instead of querying the global cache every time.
400400
DependencyScanningFilesystemLocalCache LocalCache;
401-
/// The optional mapping structure which records information about the
401+
/// The mapping structure which records information about the
402402
/// excluded conditional directive skip mappings that are used by the
403403
/// currently active preprocessor.
404-
ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings;
404+
ExcludedPreprocessorDirectiveSkipMapping &PPSkipMappings;
405405
/// The set of files that should not be minimized.
406406
llvm::DenseSet<llvm::sys::fs::UniqueID> NotToBeMinimized;
407407
};

clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class DependencyScanningService {
4848
public:
4949
DependencyScanningService(ScanningMode Mode, ScanningOutputFormat Format,
5050
bool ReuseFileManager = true,
51-
bool SkipExcludedPPRanges = true,
5251
bool OptimizeArgs = false);
5352

5453
ScanningMode getMode() const { return Mode; }
@@ -57,8 +56,6 @@ class DependencyScanningService {
5756

5857
bool canReuseFileManager() const { return ReuseFileManager; }
5958

60-
bool canSkipExcludedPPRanges() const { return SkipExcludedPPRanges; }
61-
6259
bool canOptimizeArgs() const { return OptimizeArgs; }
6360

6461
DependencyScanningFilesystemSharedCache &getSharedCache() {
@@ -69,10 +66,6 @@ class DependencyScanningService {
6966
const ScanningMode Mode;
7067
const ScanningOutputFormat Format;
7168
const bool ReuseFileManager;
72-
/// Set to true to use the preprocessor optimization that skips excluded PP
73-
/// ranges by bumping the buffer pointer in the lexer instead of lexing the
74-
/// tokens in the range until reaching the corresponding directive.
75-
const bool SkipExcludedPPRanges;
7669
/// Whether to optimize the modules' command-line arguments.
7770
const bool OptimizeArgs;
7871
/// The global file system cache.

clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class DependencyScanningWorker {
6969

7070
private:
7171
std::shared_ptr<PCHContainerOperations> PCHContainerOps;
72-
std::unique_ptr<ExcludedPreprocessorDirectiveSkipMapping> PPSkipMappings;
72+
ExcludedPreprocessorDirectiveSkipMapping PPSkipMappings;
7373

7474
/// The physical filesystem overlaid by `InMemoryFS`.
7575
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> RealFS;

clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class MinimizedVFSFile final : public llvm::vfs::File {
309309

310310
static llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
311311
create(EntryRef Entry,
312-
ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings);
312+
ExcludedPreprocessorDirectiveSkipMapping &PPSkipMappings);
313313

314314
llvm::ErrorOr<llvm::vfs::Status> status() override { return Stat; }
315315

@@ -329,7 +329,7 @@ class MinimizedVFSFile final : public llvm::vfs::File {
329329
} // end anonymous namespace
330330

331331
llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>> MinimizedVFSFile::create(
332-
EntryRef Entry, ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings) {
332+
EntryRef Entry, ExcludedPreprocessorDirectiveSkipMapping &PPSkipMappings) {
333333
assert(!Entry.isError() && "error");
334334

335335
if (Entry.isDirectory())
@@ -342,8 +342,8 @@ llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>> MinimizedVFSFile::create(
342342
Entry.getStatus());
343343

344344
const auto *EntrySkipMappings = Entry.getPPSkippedRangeMapping();
345-
if (EntrySkipMappings && !EntrySkipMappings->empty() && PPSkipMappings)
346-
(*PPSkipMappings)[Result->Buffer->getBufferStart()] = EntrySkipMappings;
345+
if (EntrySkipMappings && !EntrySkipMappings->empty())
346+
PPSkipMappings[Result->Buffer->getBufferStart()] = EntrySkipMappings;
347347

348348
return llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>(
349349
std::unique_ptr<llvm::vfs::File>(std::move(Result)));

clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ using namespace dependencies;
1515

1616
DependencyScanningService::DependencyScanningService(
1717
ScanningMode Mode, ScanningOutputFormat Format, bool ReuseFileManager,
18-
bool SkipExcludedPPRanges, bool OptimizeArgs)
18+
bool OptimizeArgs)
1919
: Mode(Mode), Format(Format), ReuseFileManager(ReuseFileManager),
20-
SkipExcludedPPRanges(SkipExcludedPPRanges), OptimizeArgs(OptimizeArgs) {
20+
OptimizeArgs(OptimizeArgs) {
2121
// Initialize targets for object file support.
2222
llvm::InitializeAllTargets();
2323
llvm::InitializeAllTargetMCs();

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class DependencyScanningAction : public tooling::ToolAction {
137137
DependencyScanningAction(
138138
StringRef WorkingDirectory, DependencyConsumer &Consumer,
139139
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS,
140-
ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings,
140+
ExcludedPreprocessorDirectiveSkipMapping &PPSkipMappings,
141141
ScanningOutputFormat Format, bool OptimizeArgs,
142142
llvm::Optional<StringRef> ModuleName = None)
143143
: WorkingDirectory(WorkingDirectory), Consumer(Consumer),
@@ -204,9 +204,8 @@ class DependencyScanningAction : public tooling::ToolAction {
204204

205205
// Pass the skip mappings which should speed up excluded conditional block
206206
// skipping in the preprocessor.
207-
if (PPSkipMappings)
208-
ScanInstance.getPreprocessorOpts()
209-
.ExcludedConditionalDirectiveSkipMappings = PPSkipMappings;
207+
ScanInstance.getPreprocessorOpts()
208+
.ExcludedConditionalDirectiveSkipMappings = &PPSkipMappings;
210209
}
211210

212211
// Create the dependency collector that will collect the produced
@@ -263,7 +262,7 @@ class DependencyScanningAction : public tooling::ToolAction {
263262
StringRef WorkingDirectory;
264263
DependencyConsumer &Consumer;
265264
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
266-
ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings;
265+
ExcludedPreprocessorDirectiveSkipMapping &PPSkipMappings;
267266
ScanningOutputFormat Format;
268267
bool OptimizeArgs;
269268
llvm::Optional<StringRef> ModuleName;
@@ -288,12 +287,9 @@ DependencyScanningWorker::DependencyScanningWorker(
288287
OverlayFS->pushOverlay(InMemoryFS);
289288
RealFS = OverlayFS;
290289

291-
if (Service.canSkipExcludedPPRanges())
292-
PPSkipMappings =
293-
std::make_unique<ExcludedPreprocessorDirectiveSkipMapping>();
294290
if (Service.getMode() == ScanningMode::MinimizedSourcePreprocessing)
295-
DepFS = new DependencyScanningWorkerFilesystem(
296-
Service.getSharedCache(), RealFS, PPSkipMappings.get());
291+
DepFS = new DependencyScanningWorkerFilesystem(Service.getSharedCache(),
292+
RealFS, PPSkipMappings);
297293
if (Service.canReuseFileManager())
298294
Files = new FileManager(FileSystemOptions(), RealFS);
299295
}
@@ -344,9 +340,8 @@ llvm::Error DependencyScanningWorker::computeDependencies(
344340
return runWithDiags(CreateAndPopulateDiagOpts(FinalCCommandLine).release(),
345341
[&](DiagnosticConsumer &DC, DiagnosticOptions &DiagOpts) {
346342
DependencyScanningAction Action(
347-
WorkingDirectory, Consumer, DepFS,
348-
PPSkipMappings.get(), Format, OptimizeArgs,
349-
ModuleName);
343+
WorkingDirectory, Consumer, DepFS, PPSkipMappings,
344+
Format, OptimizeArgs, ModuleName);
350345
// Create an invocation that uses the underlying file
351346
// system to ensure that any file system requests that
352347
// are made by the driver do not go through the

clang/test/ClangScanDeps/regular_cdb.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 1 -mode preprocess | \
2121
// RUN: FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO,CHECK3 %s
2222

23-
// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 -mode preprocess-minimized-sources \
24-
// RUN: -skip-excluded-pp-ranges=0 | FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO,CHECK3 %s
25-
// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 1 -mode preprocess-minimized-sources \
26-
// RUN: -skip-excluded-pp-ranges=0 | FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO,CHECK3 %s
27-
//
2823
// Make sure we didn't produce any dependency files!
2924
// RUN: not cat %t.dir/regular_cdb.d
3025
// RUN: not cat %t.dir/regular_cdb_clangcl.d

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,6 @@ llvm::cl::opt<bool> ReuseFileManager(
191191
llvm::cl::desc("Reuse the file manager and its cache between invocations."),
192192
llvm::cl::init(true), llvm::cl::cat(DependencyScannerCategory));
193193

194-
llvm::cl::opt<bool> SkipExcludedPPRanges(
195-
"skip-excluded-pp-ranges",
196-
llvm::cl::desc(
197-
"Use the preprocessor optimization that skips excluded conditionals by "
198-
"bumping the buffer pointer in the lexer instead of lexing the tokens "
199-
"until reaching the end directive."),
200-
llvm::cl::init(true), llvm::cl::cat(DependencyScannerCategory));
201-
202194
llvm::cl::opt<std::string> ModuleName(
203195
"module-name", llvm::cl::Optional,
204196
llvm::cl::desc("the module of which the dependencies are to be computed"),
@@ -522,7 +514,7 @@ int main(int argc, const char **argv) {
522514
SharedStream DependencyOS(llvm::outs());
523515

524516
DependencyScanningService Service(ScanMode, Format, ReuseFileManager,
525-
SkipExcludedPPRanges, OptimizeArgs);
517+
OptimizeArgs);
526518
llvm::ThreadPool Pool(llvm::hardware_concurrency(NumThreads));
527519
std::vector<std::unique_ptr<DependencyScanningTool>> WorkerTools;
528520
for (unsigned I = 0; I < Pool.getThreadCount(); ++I)

clang/unittests/Tooling/DependencyScannerTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ TEST(DependencyScanningFilesystem, IgnoredFilesAreCachedSeparately1) {
212212
"// hi there!\n"));
213213

214214
DependencyScanningFilesystemSharedCache SharedCache;
215-
auto Mappings = std::make_unique<ExcludedPreprocessorDirectiveSkipMapping>();
216-
DependencyScanningWorkerFilesystem DepFS(SharedCache, VFS, Mappings.get());
215+
ExcludedPreprocessorDirectiveSkipMapping Mappings;
216+
DependencyScanningWorkerFilesystem DepFS(SharedCache, VFS, Mappings);
217217

218218
DepFS.enableMinimizationOfAllFiles(); // Let's be explicit for clarity.
219219
auto StatusMinimized0 = DepFS.status("/mod.h");
@@ -235,8 +235,8 @@ TEST(DependencyScanningFilesystem, IgnoredFilesAreCachedSeparately2) {
235235
"// hi there!\n"));
236236

237237
DependencyScanningFilesystemSharedCache SharedCache;
238-
auto Mappings = std::make_unique<ExcludedPreprocessorDirectiveSkipMapping>();
239-
DependencyScanningWorkerFilesystem DepFS(SharedCache, VFS, Mappings.get());
238+
ExcludedPreprocessorDirectiveSkipMapping Mappings;
239+
DependencyScanningWorkerFilesystem DepFS(SharedCache, VFS, Mappings);
240240

241241
DepFS.disableMinimization("/mod.h");
242242
auto StatusFull0 = DepFS.status("/mod.h");

0 commit comments

Comments
 (0)