Skip to content

Commit bf2f4af

Browse files
committed
NFC: Move NumThreads from SILOptions to IRGenOptions
The option is only needed for IRGen.
1 parent c65246f commit bf2f4af

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ class IRGenOptions {
284284
/// Whether to disable using mangled names for accessing concrete type metadata.
285285
unsigned DisableConcreteTypeMetadataMangledNameAccessors : 1;
286286

287+
/// The number of threads for multi-threaded code generation.
288+
unsigned NumThreads = 0;
289+
287290
/// Path to the profdata file to be used for PGO, or the empty string.
288291
std::string UseProfile = "";
289292

@@ -383,6 +386,10 @@ class IRGenOptions {
383386
llvm::hash_code getPCHHashComponents() const {
384387
return llvm::hash_value(0);
385388
}
389+
390+
bool hasMultipleIRGenThreads() const { return NumThreads > 1; }
391+
bool shouldPerformIRGenerationInParallel() const { return NumThreads != 0; }
392+
bool hasMultipleIGMs() const { return hasMultipleIRGenThreads(); }
386393
};
387394

388395
} // end namespace swift

include/swift/AST/SILOptions.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ class SILOptions {
4040
/// Controls the aggressiveness of the loop unroller.
4141
int UnrollThreshold = 250;
4242

43-
/// The number of threads for multi-threaded code generation.
44-
unsigned NumThreads = 0;
45-
4643
/// Controls whether to pull in SIL from partial modules during the
4744
/// merge modules step. Could perhaps be merged with the link mode
4845
/// above but the interactions between all the flags are tricky.
@@ -183,10 +180,6 @@ class SILOptions {
183180
bool shouldOptimize() const {
184181
return OptMode > OptimizationMode::NoOptimization;
185182
}
186-
187-
bool hasMultipleIRGenThreads() const { return NumThreads > 1; }
188-
bool shouldPerformIRGenerationInParallel() const { return NumThreads != 0; }
189-
bool hasMultipleIGMs() const { return hasMultipleIRGenThreads(); }
190183
};
191184

192185
} // end namespace swift

lib/Frontend/CompilerInvocation.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -993,18 +993,6 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
993993
return true;
994994
}
995995
}
996-
if (const Arg *A = Args.getLastArg(OPT_num_threads)) {
997-
if (StringRef(A->getValue()).getAsInteger(10, Opts.NumThreads)) {
998-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
999-
A->getAsString(Args), A->getValue());
1000-
return true;
1001-
}
1002-
if (environmentVariableRequestedMaximumDeterminism()) {
1003-
Opts.NumThreads = 1;
1004-
Diags.diagnose(SourceLoc(), diag::remark_max_determinism_overriding,
1005-
"-num-threads");
1006-
}
1007-
}
1008996

1009997
// If we're only emitting a module, stop optimizations once we've serialized
1010998
// the SIL for the module.
@@ -1209,7 +1197,7 @@ static bool ParseTBDGenArgs(TBDGenOptions &Opts, ArgList &Args,
12091197
CompilerInvocation &Invocation) {
12101198
using namespace options;
12111199

1212-
Opts.HasMultipleIGMs = Invocation.getSILOptions().hasMultipleIGMs();
1200+
Opts.HasMultipleIGMs = Invocation.getIRGenOptions().hasMultipleIGMs();
12131201

12141202
if (const Arg *A = Args.getLastArg(OPT_module_link_name)) {
12151203
Opts.ModuleLinkName = A->getValue();
@@ -1543,6 +1531,19 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
15431531
getRuntimeCompatVersion();
15441532
}
15451533

1534+
if (const Arg *A = Args.getLastArg(OPT_num_threads)) {
1535+
if (StringRef(A->getValue()).getAsInteger(10, Opts.NumThreads)) {
1536+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
1537+
A->getAsString(Args), A->getValue());
1538+
return true;
1539+
}
1540+
if (environmentVariableRequestedMaximumDeterminism()) {
1541+
Opts.NumThreads = 1;
1542+
Diags.diagnose(SourceLoc(), diag::remark_max_determinism_overriding,
1543+
"-num-threads");
1544+
}
1545+
}
1546+
15461547
return false;
15471548
}
15481549

lib/IRGen/IRGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ static void performParallelIRGeneration(
12801280

12811281
// Start all the threads and do the LLVM compilation.
12821282

1283-
LLVMCodeGenThreads codeGenThreads(&irgen, &DiagMutex, SILMod->getOptions().NumThreads - 1);
1283+
LLVMCodeGenThreads codeGenThreads(&irgen, &DiagMutex, Opts.NumThreads - 1);
12841284
codeGenThreads.startThreads();
12851285

12861286
// Free the memory occupied by the SILModule.
@@ -1301,7 +1301,7 @@ GeneratedModule swift::performIRGeneration(
13011301
const PrimarySpecificPaths &PSPs,
13021302
ArrayRef<std::string> parallelOutputFilenames,
13031303
llvm::GlobalVariable **outModuleHash, llvm::StringSet<> *LinkerDirectives) {
1304-
if (SILMod->getOptions().shouldPerformIRGenerationInParallel() &&
1304+
if (Opts.shouldPerformIRGenerationInParallel() &&
13051305
!parallelOutputFilenames.empty()) {
13061306
::performParallelIRGeneration(Opts, M, std::move(SILMod), ModuleName,
13071307
parallelOutputFilenames, LinkerDirectives);

0 commit comments

Comments
 (0)