Skip to content

Commit dec7890

Browse files
committed
Only use supplementary outputs for first parallel-generated input.
1 parent e7a120f commit dec7890

File tree

5 files changed

+33
-31
lines changed

5 files changed

+33
-31
lines changed

include/swift/Basic/SupplementaryOutputPaths.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ struct SupplementaryOutputPaths {
4747

4848
SupplementaryOutputPaths() = default;
4949
SupplementaryOutputPaths(const SupplementaryOutputPaths &) = default;
50+
51+
bool empty() const {
52+
return ObjCHeaderOutputPath.empty() && ModuleOutputPath.empty() &&
53+
ModuleDocOutputPath.empty() && DependenciesFilePath.empty() &&
54+
ReferenceDependenciesFilePath.empty() &&
55+
SerializedDiagnosticsPath.empty() && LoadedModuleTracePath.empty() &&
56+
TBDPath.empty();
57+
}
5058
};
5159
} // namespace swift
5260

include/swift/Frontend/FrontendInputsAndOutputs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ class FrontendInputsAndOutputs {
226226
/// to tell it which primary input you wanted the outputs for.
227227
///
228228
/// Must not be constructed on-the-fly because some parts of the compiler
229-
/// truck in StringRef's to its components, so it must live as long as the
229+
/// receive StringRefs to its components, so it must live as long as the
230230
/// compiler.
231231
PrimarySpecificPaths &getPrimarySpecificPathsForAtMostOnePrimary();
232232

233-
PrimarySpecificPaths &getPrimarySpecificPathsForPrimary(StringRef);
233+
PrimarySpecificPaths &getPrimarySpecificPathsForPrimary(StringRef filename);
234234

235235
bool hasDependenciesPath() const;
236236
bool hasReferenceDependenciesPath() const;

lib/FrontendTool/FrontendTool.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,9 +1065,8 @@ static void setPrivateDiscriminatorIfNeeded(IRGenOptions &IRGenOpts,
10651065
IRGenOpts.DWARFDebugFlags += (" -private-discriminator " + PD.str()).str();
10661066
}
10671067

1068-
static bool serializeSIB(FrontendOptions &opts, SILModule *SM,
1069-
const PrimarySpecificPaths &PSPs, ASTContext &Context,
1070-
ModuleOrSourceFile MSF) {
1068+
static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs,
1069+
ASTContext &Context, ModuleOrSourceFile MSF) {
10711070
const std::string &moduleOutputPath =
10721071
PSPs.SupplementaryOutputs.ModuleOutputPath;
10731072
assert(!moduleOutputPath.empty() && "must have an output path");
@@ -1209,8 +1208,7 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
12091208

12101209
if (Action == FrontendOptions::ActionType::EmitSIBGen) {
12111210
linkAllIfNeeded(Invocation, SM.get());
1212-
serializeSIB(Invocation.getFrontendOptions(), SM.get(), PSPs,
1213-
Instance.getASTContext(), MSF);
1211+
serializeSIB(SM.get(), PSPs, Instance.getASTContext(), MSF);
12141212
return Context.hadError();
12151213
}
12161214

@@ -1271,8 +1269,7 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
12711269
opts.ImplicitObjCHeaderPath, moduleIsPublic);
12721270

12731271
if (Action == FrontendOptions::ActionType::EmitSIB)
1274-
return serializeSIB(Invocation.getFrontendOptions(), SM.get(), PSPs,
1275-
Instance.getASTContext(), MSF);
1272+
return serializeSIB(SM.get(), PSPs, Instance.getASTContext(), MSF);
12761273

12771274
const bool haveModulePath =
12781275
!PSPs.SupplementaryOutputs.ModuleOutputPath.empty() ||

lib/IRGen/IRGen.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -865,12 +865,11 @@ static void ThreadEntryPoint(IRGenerator *irgen,
865865

866866
/// Generates LLVM IR, runs the LLVM passes and produces the output files.
867867
/// All this is done in multiple threads.
868-
static void performParallelIRGeneration(IRGenOptions &Opts,
869-
swift::ModuleDecl *M,
870-
std::unique_ptr<SILModule> SILMod,
871-
const PrimarySpecificPaths &PSPs,
872-
StringRef ModuleName, int numThreads,
873-
ArrayRef<std::string> outputFilenames) {
868+
static void performParallelIRGeneration(
869+
IRGenOptions &Opts, swift::ModuleDecl *M, std::unique_ptr<SILModule> SILMod,
870+
const SupplementaryOutputPaths &supplementaryOutputPathsForFirstInput,
871+
StringRef ModuleName, int numThreads,
872+
ArrayRef<std::string> outputFilenames) {
874873

875874
IRGenerator irgen(Opts, *SILMod);
876875

@@ -903,7 +902,6 @@ static void performParallelIRGeneration(IRGenOptions &Opts,
903902
// There must be an output filename for each source file.
904903
// We ignore additional output filenames.
905904
if (OutputIter == outputFilenames.end()) {
906-
// TODO: Check this already at argument parsing.
907905
Ctx.Diags.diagnose(SourceLoc(), diag::too_few_output_filenames);
908906
return;
909907
}
@@ -916,12 +914,12 @@ static void performParallelIRGeneration(IRGenOptions &Opts,
916914
auto Context = new LLVMContext();
917915

918916
// Create the IR emitter.
919-
IRGenModule *IGM = new IRGenModule(irgen, std::move(targetMachine),
920-
nextSF, *Context,
921-
ModuleName,
922-
PrimarySpecificPaths(*OutputIter++,
923-
nextSF->getFilename(),
924-
PSPs.SupplementaryOutputs));
917+
const bool isFirst = OutputIter == outputFilenames.begin();
918+
IRGenModule *IGM = new IRGenModule(
919+
irgen, std::move(targetMachine), nextSF, *Context, ModuleName,
920+
PrimarySpecificPaths(*OutputIter++, nextSF->getFilename(),
921+
isFirst ? supplementaryOutputPathsForFirstInput
922+
: SupplementaryOutputPaths()));
925923
IGMcreated = true;
926924

927925
initLLVMModule(*IGM);
@@ -1081,17 +1079,17 @@ static void performParallelIRGeneration(IRGenOptions &Opts,
10811079
}
10821080
}
10831081

1084-
std::unique_ptr<llvm::Module> swift::
1085-
performIRGeneration(IRGenOptions &Opts, swift::ModuleDecl *M,
1086-
std::unique_ptr<SILModule> SILMod,
1087-
StringRef ModuleName, const PrimarySpecificPaths &PSPs,
1088-
llvm::LLVMContext &LLVMContext,
1089-
ArrayRef<std::string> parallelOutputFilenames,
1090-
llvm::GlobalVariable **outModuleHash) {
1082+
std::unique_ptr<llvm::Module> swift::performIRGeneration(
1083+
IRGenOptions &Opts, swift::ModuleDecl *M, std::unique_ptr<SILModule> SILMod,
1084+
StringRef ModuleName, const PrimarySpecificPaths &PSPs,
1085+
llvm::LLVMContext &LLVMContext,
1086+
ArrayRef<std::string> parallelOutputFilenames,
1087+
llvm::GlobalVariable **outModuleHash) {
10911088
if (SILMod->getOptions().shouldPerformIRGenerationInParallel() &&
10921089
!parallelOutputFilenames.empty()) {
10931090
auto NumThreads = SILMod->getOptions().NumThreads;
1094-
::performParallelIRGeneration(Opts, M, std::move(SILMod), PSPs, ModuleName,
1091+
::performParallelIRGeneration(Opts, M, std::move(SILMod),
1092+
PSPs.SupplementaryOutputs, ModuleName,
10951093
NumThreads, parallelOutputFilenames);
10961094
// TODO: Parallel LLVM compilation cannot be used if a (single) module is
10971095
// needed as return value.

lib/SIL/SILModule.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "swift/AST/GenericEnvironment.h"
1616
#include "swift/AST/ProtocolConformance.h"
1717
#include "swift/AST/Substitution.h"
18-
#include "swift/Basic/PrimarySpecificPaths.h"
1918
#include "swift/SIL/FormalLinkage.h"
2019
#include "swift/SIL/SILDebugScope.h"
2120
#include "swift/SIL/SILModule.h"

0 commit comments

Comments
 (0)