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/ADT/StringMap.h"
21#include "llvm/Support/FileSystem.h"
22#include "llvm/Support/MemoryBufferRef.h"
23#include "llvm/Support/VirtualFileSystem.h"
24#include <memory>
25#include <optional>
26#include <string>
27
28namespace clang {
29
31
32namespace dependencies {
33
36
37std::unique_ptr<DiagnosticOptions>
38createScanningDiagOptions(ArrayRef<std::string> CommandLine);
39
40/// An individual dependency scanning worker that is able to run on its own
41/// thread.
42///
43/// The worker computes the dependencies for the input files by preprocessing
44/// sources either using a fast mode where the source files are minimized, or
45/// using the regular processing run.
47public:
48 /// Construct a dependency scanning worker.
49 ///
50 /// @param Service The parent service. Must outlive the worker.
54
56
57 /// Run the dependency scanning tool for all given frontend command-lines,
58 /// and report the discovered dependencies to the provided consumer. The
59 /// \c OverlayFS will be used to call \c makeEffectiveVFS().
60 ///
61 /// \returns false if any errors occurred (with diagnostics reported to
62 /// \c DiagConsumer), true otherwise.
64 StringRef WorkingDirectory, ArrayRef<ArrayRef<std::string>> CommandLines,
65 DependencyConsumer &DepConsumer, DependencyActionController &Controller,
66 DiagnosticConsumer &DiagConsumer,
68
69 /// By-name scanning over a single cc1 command line. Builds a scanning session
70 /// local to this call, then pulls module names from \p getNextName until it
71 /// returns std::nullopt. Results flow to \p DepConsumer (per-name status via
72 /// finishQuery); diagnostics flow to \p DiagConsumer.
73 /// \returns false if session setup failed, true otherwise.
75 StringRef CWD, ArrayRef<std::string> CC1CommandLine,
77 DiagnosticConsumer &DiagConsumer, DependencyActionController &Controller,
78 llvm::function_ref<std::optional<std::string>()> getNextName,
79 DependencyConsumer &DepConsumer);
80
81 /// Creates a compiler instance to return a map of module names to their
82 /// defined module map path.
83 std::optional<llvm::StringMap<std::string>> computeModuleMapsForModules(
84 StringRef CWD, ArrayRef<std::string> CC1CommandLine,
86 DiagnosticConsumer &DiagConsumer, DependencyActionController &Controller,
87 ArrayRef<StringRef> ModuleNames);
88
89 /// Creates the effective VFS that will be used for the scan.
90 ///
91 /// If provided, OverlayFS will be overlaid on top of the Worker's dependency
92 /// scanning file-system and can be used to provide any input specified on the
93 /// command-line as in-memory file. If no overlay file-system is provided, the
94 /// Worker's dependency scanning file-system is used directly.
96 StringRef WorkingDirectory,
97 IntrusiveRefCntPtr<llvm::vfs::FileSystem> OverlayFS = nullptr) const;
98
99 /// Returns the worker tracing VFS, if it was requested via the service.
100 llvm::vfs::TracingFileSystem *getTracingVFS() const {
101 return TracingFS.get();
102 }
103
104 DependencyScanningService &getService() const { return Service; }
105
106 // MaxNumOfByNameQueries is the upper limit of the number of names the by-name
107 // scanning API (computeDependenciesByName) can drain per call. At the time of
108 // this commit, the estimated number of total unique importable names is
109 // around 3000 from Apple's SDKs. We usually import them in parallel, so it is
110 // unlikely that all names are scanned by the same worker. Therefore the 64k
111 // (20x our estimate) size is sufficient to hold the unique source locations
112 // to report diagnostics per worker.
113 static const int32_t MaxNumOfByNameQueries = 1 << 16;
114
115private:
116 /// The parent dependency scanning service.
118 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
119 /// This is the caching (and optionally dependency-directives-providing) VFS
120 /// overlaid on top of the base VFS.
122 /// The tracing VFS overlaid on top of the base VFS.
124
126};
127} // end namespace dependencies
128} // end namespace clang
129
130#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.
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.
DependencyScanningWorker(DependencyScanningService &Service, IntrusiveRefCntPtr< llvm::vfs::FileSystem > LocalFS=nullptr)
Construct a dependency scanning worker.
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::optional< llvm::StringMap< std::string > > computeModuleMapsForModules(StringRef CWD, ArrayRef< std::string > CC1CommandLine, IntrusiveRefCntPtr< llvm::vfs::FileSystem > OverlayFS, DiagnosticConsumer &DiagConsumer, DependencyActionController &Controller, ArrayRef< StringRef > ModuleNames)
Creates a compiler instance to return a map of module names to their defined module map path.
std::unique_ptr< DiagnosticOptions > createScanningDiagOptions(ArrayRef< std::string > CommandLine)
Top level wrappers for InstallAPI frontend operations.
__builtin_bitreverse32 uint32_t __builtin_riscv_aaddu_u32 __builtin_riscv_asubu_u32 __builtin_elementwise_add_sat __builtin_elementwise_sub_sat int32_t