Skip to content

Commit b2e7e5d

Browse files
authored
Merge branch 'main' into lldb-mcp-binder-win32
2 parents 9432dfe + 0b543e3 commit b2e7e5d

File tree

49 files changed

+2386
-564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2386
-564
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,8 +1258,9 @@ def offload_compression_level_EQ : Joined<["--"], "offload-compression-level=">,
12581258
HelpText<"Compression level for offload device binaries (HIP only)">;
12591259

12601260
def offload_jobs_EQ : Joined<["--"], "offload-jobs=">,
1261-
HelpText<"Specify the number of threads to use for device offloading tasks"
1262-
" during compilation.">;
1261+
HelpText<"Specify the number of threads to use for device offloading tasks "
1262+
"during compilation. Can be a positive integer or the string "
1263+
"'jobserver' to use the make-style jobserver from the environment.">;
12631264

12641265
defm offload_via_llvm : BoolFOption<"offload-via-llvm",
12651266
LangOpts<"OffloadViaLLVM">, DefaultFalse,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9224,14 +9224,20 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
92249224
addOffloadCompressArgs(Args, CmdArgs);
92259225

92269226
if (Arg *A = Args.getLastArg(options::OPT_offload_jobs_EQ)) {
9227-
int NumThreads;
9228-
if (StringRef(A->getValue()).getAsInteger(10, NumThreads) ||
9229-
NumThreads <= 0)
9230-
C.getDriver().Diag(diag::err_drv_invalid_int_value)
9231-
<< A->getAsString(Args) << A->getValue();
9232-
else
9233-
CmdArgs.push_back(
9234-
Args.MakeArgString("--wrapper-jobs=" + Twine(NumThreads)));
9227+
StringRef Val = A->getValue();
9228+
9229+
if (Val.equals_insensitive("jobserver"))
9230+
CmdArgs.push_back(Args.MakeArgString("--wrapper-jobs=jobserver"));
9231+
else {
9232+
int NumThreads;
9233+
if (Val.getAsInteger(10, NumThreads) || NumThreads <= 0) {
9234+
C.getDriver().Diag(diag::err_drv_invalid_int_value)
9235+
<< A->getAsString(Args) << Val;
9236+
} else {
9237+
CmdArgs.push_back(
9238+
Args.MakeArgString("--wrapper-jobs=" + Twine(NumThreads)));
9239+
}
9240+
}
92359241
}
92369242

92379243
const char *Exec =

clang/lib/Tooling/DependencyScanning/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ add_clang_library(clangDependencyScanning
2424
clangFrontend
2525
clangLex
2626
clangSerialization
27-
clangTooling
2827
${LLVM_PTHREAD_LIB}
2928
)

clang/lib/Tooling/DependencyScanning/DependencyScannerImpl.cpp

Lines changed: 229 additions & 50 deletions
Large diffs are not rendered by default.

clang/lib/Tooling/DependencyScanning/DependencyScannerImpl.h

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
#ifndef LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNER_H
1010
#define LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNER_H
1111

12+
#include "clang/Driver/Compilation.h"
1213
#include "clang/Frontend/CompilerInstance.h"
1314
#include "clang/Frontend/CompilerInvocation.h"
15+
#include "clang/Frontend/TextDiagnosticPrinter.h"
1416
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
1517
#include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
1618
#include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
@@ -30,12 +32,12 @@ class DependencyScanningAction {
3032
DependencyScanningAction(
3133
DependencyScanningService &Service, StringRef WorkingDirectory,
3234
DependencyConsumer &Consumer, DependencyActionController &Controller,
33-
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS,
35+
IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS,
3436
std::optional<StringRef> ModuleName = std::nullopt)
3537
: Service(Service), WorkingDirectory(WorkingDirectory),
3638
Consumer(Consumer), Controller(Controller), DepFS(std::move(DepFS)),
3739
ModuleName(ModuleName) {}
38-
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
40+
bool runInvocation(std::unique_ptr<CompilerInvocation> Invocation,
3941
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
4042
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
4143
DiagnosticConsumer *DiagConsumer);
@@ -63,7 +65,7 @@ class DependencyScanningAction {
6365
StringRef WorkingDirectory;
6466
DependencyConsumer &Consumer;
6567
DependencyActionController &Controller;
66-
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
68+
IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
6769
std::optional<StringRef> ModuleName;
6870
std::optional<CompilerInstance> ScanInstanceStorage;
6971
std::shared_ptr<ModuleDepCollector> MDC;
@@ -72,9 +74,81 @@ class DependencyScanningAction {
7274
bool DiagConsumerFinished = false;
7375
};
7476

75-
// Helper functions
76-
void sanitizeDiagOpts(DiagnosticOptions &DiagOpts);
77+
// Helper functions and data types.
78+
std::unique_ptr<DiagnosticOptions>
79+
createDiagOptions(ArrayRef<std::string> CommandLine);
7780

81+
struct DignosticsEngineWithDiagOpts {
82+
// We need to bound the lifetime of the DiagOpts used to create the
83+
// DiganosticsEngine with the DiagnosticsEngine itself.
84+
std::unique_ptr<DiagnosticOptions> DiagOpts;
85+
IntrusiveRefCntPtr<DiagnosticsEngine> DiagEngine;
86+
87+
DignosticsEngineWithDiagOpts(ArrayRef<std::string> CommandLine,
88+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
89+
DiagnosticConsumer &DC);
90+
};
91+
92+
struct TextDiagnosticsPrinterWithOutput {
93+
// We need to bound the lifetime of the data that supports the DiagPrinter
94+
// with it together so they have the same lifetime.
95+
std::string DiagnosticOutput;
96+
llvm::raw_string_ostream DiagnosticsOS;
97+
std::unique_ptr<DiagnosticOptions> DiagOpts;
98+
TextDiagnosticPrinter DiagPrinter;
99+
100+
TextDiagnosticsPrinterWithOutput(ArrayRef<std::string> CommandLine)
101+
: DiagnosticsOS(DiagnosticOutput),
102+
DiagOpts(createDiagOptions(CommandLine)),
103+
DiagPrinter(DiagnosticsOS, *DiagOpts) {}
104+
};
105+
106+
std::pair<std::unique_ptr<driver::Driver>, std::unique_ptr<driver::Compilation>>
107+
buildCompilation(ArrayRef<std::string> ArgStrs, DiagnosticsEngine &Diags,
108+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
109+
110+
std::unique_ptr<CompilerInvocation>
111+
createCompilerInvocation(ArrayRef<std::string> CommandLine,
112+
DiagnosticsEngine &Diags);
113+
114+
std::pair<IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::vector<std::string>>
115+
initVFSForTUBuferScanning(IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
116+
ArrayRef<std::string> CommandLine,
117+
StringRef WorkingDirectory,
118+
llvm::MemoryBufferRef TUBuffer);
119+
120+
std::pair<IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::vector<std::string>>
121+
initVFSForByNameScanning(IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
122+
ArrayRef<std::string> CommandLine,
123+
StringRef WorkingDirectory, StringRef ModuleName);
124+
125+
bool initializeScanCompilerInstance(
126+
CompilerInstance &ScanInstance,
127+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
128+
DiagnosticConsumer *DiagConsumer, DependencyScanningService &Service,
129+
IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS);
130+
131+
SmallVector<StringRef>
132+
getInitialStableDirs(const CompilerInstance &ScanInstance);
133+
134+
std::optional<PrebuiltModulesAttrsMap>
135+
computePrebuiltModulesASTMap(CompilerInstance &ScanInstance,
136+
SmallVector<StringRef> &StableDirs);
137+
138+
std::unique_ptr<DependencyOutputOptions>
139+
takeDependencyOutputOptionsFrom(CompilerInstance &ScanInstance);
140+
141+
/// Create the dependency collector that will collect the produced
142+
/// dependencies. May return the created ModuleDepCollector depending
143+
/// on the scanning format.
144+
std::shared_ptr<ModuleDepCollector> initializeScanInstanceDependencyCollector(
145+
CompilerInstance &ScanInstance,
146+
std::unique_ptr<DependencyOutputOptions> DepOutputOpts,
147+
StringRef WorkingDirectory, DependencyConsumer &Consumer,
148+
DependencyScanningService &Service, CompilerInvocation &Inv,
149+
DependencyActionController &Controller,
150+
PrebuiltModulesAttrsMap PrebuiltModulesASTMap,
151+
llvm::SmallVector<StringRef> &StableDirs);
78152
} // namespace dependencies
79153
} // namespace tooling
80154
} // namespace clang

0 commit comments

Comments
 (0)