clang 24.0.0git
DependencyScanningWorker.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H
10#define LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H
11
15#include "clang/Basic/LLVM.h"
19#include "llvm/ADT/IntrusiveRefCntPtr.h"
20#include "llvm/Support/FileSystem.h"
21#include "llvm/Support/MemoryBufferRef.h"
22#include "llvm/Support/VirtualFileSystem.h"
23#include <memory>
24#include <optional>
25#include <string>
26
27namespace clang {
28
30
31namespace dependencies {
32
35
36std::unique_ptr<DiagnosticOptions>
37createScanningDiagOptions(ArrayRef<std::string> CommandLine);
38
39/// An individual dependency scanning worker that is able to run on its own
40/// thread.
41///
42/// The worker computes the dependencies for the input files by preprocessing
43/// sources either using a fast mode where the source files are minimized, or
44/// using the regular processing run.
46public:
47 /// Construct a dependency scanning worker.
48 ///
49 /// @param Service The parent service. Must outlive the worker.
51
53
54 /// Run the dependency scanning tool for all given frontend command-lines,
55 /// and report the discovered dependencies to the provided consumer. The
56 /// \c OverlayFS will be used to call \c makeEffectiveVFS().
57 ///
58 /// \returns false if any errors occurred (with diagnostics reported to
59 /// \c DiagConsumer), true otherwise.
61 StringRef WorkingDirectory, ArrayRef<ArrayRef<std::string>> CommandLines,
62 DependencyConsumer &DepConsumer, DependencyActionController &Controller,
63 DiagnosticConsumer &DiagConsumer,
65
66 /// By-name scanning over a single cc1 command line. Builds a scanning session
67 /// local to this call, then pulls module names from \p getNextName until it
68 /// returns std::nullopt. Results flow to \p DepConsumer (per-name status via
69 /// finishQuery); diagnostics flow to \p DiagConsumer.
70 /// \returns false if session setup failed, true otherwise.
72 StringRef CWD, ArrayRef<std::string> CC1CommandLine,
74 DiagnosticConsumer &DiagConsumer, DependencyActionController &Controller,
75 llvm::function_ref<std::optional<std::string>()> getNextName,
76 DependencyConsumer &DepConsumer);
77
78 /// Creates the effective VFS that will be used for the scan.
79 ///
80 /// If provided, OverlayFS will be overlaid on top of the Worker's dependency
81 /// scanning file-system and can be used to provide any input specified on the
82 /// command-line as in-memory file. If no overlay file-system is provided, the
83 /// Worker's dependency scanning file-system is used directly.
85 StringRef WorkingDirectory,
86 IntrusiveRefCntPtr<llvm::vfs::FileSystem> OverlayFS = nullptr) const;
87
88 /// Returns the worker tracing VFS, if it was requested via the service.
89 llvm::vfs::TracingFileSystem *getTracingVFS() const {
90 return TracingFS.get();
91 }
92
93 // MaxNumOfByNameQueries is the upper limit of the number of names the by-name
94 // scanning API (computeDependenciesByName) can drain per call. At the time of
95 // this commit, the estimated number of total unique importable names is
96 // around 3000 from Apple's SDKs. We usually import them in parallel, so it is
97 // unlikely that all names are scanned by the same worker. Therefore the 64k
98 // (20x our estimate) size is sufficient to hold the unique source locations
99 // to report diagnostics per worker.
100 static const int32_t MaxNumOfByNameQueries = 1 << 16;
101
102private:
103 /// The parent dependency scanning service.
105 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
106 /// This is the caching (and optionally dependency-directives-providing) VFS
107 /// overlaid on top of the base VFS.
109 /// The tracing VFS overlaid on top of the base VFS.
111
113};
114} // end namespace dependencies
115} // end namespace clang
116
117#endif // LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H
Defines the Diagnostic-related interfaces.
Defines the clang::FileManager interface and associated types.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Dependency scanner callbacks that are used during scanning to influence the behaviour of the scan - f...
The dependency scanning service contains shared configuration and state that is used by the individua...
A virtual file system optimized for the dependency discovery.
DependencyScanningWorker(DependencyScanningService &Service)
Construct a dependency scanning worker.
llvm::vfs::TracingFileSystem * getTracingVFS() const
Returns the worker tracing VFS, if it was requested via the service.
bool computeDependenciesByName(StringRef CWD, ArrayRef< std::string > CC1CommandLine, IntrusiveRefCntPtr< llvm::vfs::FileSystem > OverlayFS, DiagnosticConsumer &DiagConsumer, DependencyActionController &Controller, llvm::function_ref< std::optional< std::string >()> getNextName, DependencyConsumer &DepConsumer)
By-name scanning over a single cc1 command line.
bool computeDependencies(StringRef WorkingDirectory, ArrayRef< ArrayRef< std::string > > CommandLines, DependencyConsumer &DepConsumer, DependencyActionController &Controller, DiagnosticConsumer &DiagConsumer, IntrusiveRefCntPtr< llvm::vfs::FileSystem > OverlayFS=nullptr)
Run the dependency scanning tool for all given frontend command-lines, and report the discovered depe...
IntrusiveRefCntPtr< llvm::vfs::FileSystem > makeEffectiveVFS(StringRef WorkingDirectory, IntrusiveRefCntPtr< llvm::vfs::FileSystem > OverlayFS=nullptr) const
Creates the effective VFS that will be used for the scan.
std::unique_ptr< DiagnosticOptions > createScanningDiagOptions(ArrayRef< std::string > CommandLine)
Top level wrappers for InstallAPI frontend operations.
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 int32_t