Skip to content

Commit a9bbaf7

Browse files
committed
Assume a SILModule is whole-module when SILGen-ing from a ModuleDecl
No functionality change. Unfortunately we still need the flag in SILModule itself because of the ability to create an empty SILModule and parse SIL into it incrementally, which can happen before there's a FileUnit to use as the associated DeclContext instead of a CompilerInstance's main module.
1 parent 985dbee commit a9bbaf7

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

include/swift/SIL/SILModule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ class SILModule {
345345
/// If a source file is provided, SIL will only be emitted for decls in that
346346
/// source file.
347347
static std::unique_ptr<SILModule>
348-
constructSIL(ModuleDecl *M, SILOptions &Options, FileUnit *sf = nullptr,
349-
bool isWholeModule = false);
348+
constructSIL(ModuleDecl *M, SILOptions &Options, FileUnit *sf = nullptr);
350349

351350
/// \brief Create and return an empty SIL module that we can
352351
/// later parse SIL bodies directly into, without converting from an AST.

include/swift/Subsystems.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,10 @@ namespace swift {
237237

238238
/// Turn the given module into SIL IR.
239239
///
240-
/// The module must contain source files.
241-
///
242-
/// if \p wholeModuleCompilation is true, the optimizer assumes that the SIL
243-
/// of all files in the module is present in the SILModule.
240+
/// The module must contain source files. The optimizer will assume that the
241+
/// SIL of all files in the module is present in the SILModule.
244242
std::unique_ptr<SILModule>
245-
performSILGeneration(ModuleDecl *M, SILOptions &options,
246-
bool wholeModuleCompilation = false);
243+
performSILGeneration(ModuleDecl *M, SILOptions &options);
247244

248245
/// Turn a source file into SIL IR.
249246
std::unique_ptr<SILModule>

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ generateSILModules(CompilerInvocation &Invocation, CompilerInstance &Instance) {
819819
if (!opts.InputsAndOutputs.hasPrimaryInputs()) {
820820
// If there are no primary inputs the compiler is in WMO mode and builds one
821821
// SILModule for the entire module.
822-
auto SM = performSILGeneration(mod, SILOpts, true);
822+
auto SM = performSILGeneration(mod, SILOpts);
823823
std::deque<PostSILGenInputs> PSGIs;
824824
const PrimarySpecificPaths PSPs =
825825
Instance.getPrimarySpecificPathsForWholeModuleOptimizationMode();

lib/Immediate/REPL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,9 @@ class REPLEnvironment {
873873
std::unique_ptr<SILModule> sil;
874874

875875
if (!CI.getASTContext().hadError()) {
876-
sil = performSILGeneration(M, CI.getSILOptions());
876+
// We don't want anything to get stripped, so pretend we're doing a
877+
// non-whole-module generation.
878+
sil = performSILGeneration(*M->getFiles().front(), CI.getSILOptions());
877879
runSILDiagnosticPasses(*sil);
878880
runSILLoweringPasses(*sil);
879881
}

lib/SILGen/SILGen.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,8 +1602,7 @@ void SILGenModule::emitSourceFile(SourceFile *sf) {
16021602
//===----------------------------------------------------------------------===//
16031603

16041604
std::unique_ptr<SILModule>
1605-
SILModule::constructSIL(ModuleDecl *mod, SILOptions &options, FileUnit *SF,
1606-
bool isWholeModule) {
1605+
SILModule::constructSIL(ModuleDecl *mod, SILOptions &options, FileUnit *SF) {
16071606
SharedTimer timer("SILGen");
16081607
const DeclContext *DC;
16091608
if (SF) {
@@ -1613,7 +1612,7 @@ SILModule::constructSIL(ModuleDecl *mod, SILOptions &options, FileUnit *SF,
16131612
}
16141613

16151614
std::unique_ptr<SILModule> M(
1616-
new SILModule(mod, options, DC, isWholeModule));
1615+
new SILModule(mod, options, DC, /*wholeModule*/ SF == nullptr));
16171616
SILGenModule SGM(*M, mod);
16181617

16191618
if (SF) {
@@ -1670,13 +1669,11 @@ SILModule::constructSIL(ModuleDecl *mod, SILOptions &options, FileUnit *SF,
16701669
}
16711670

16721671
std::unique_ptr<SILModule>
1673-
swift::performSILGeneration(ModuleDecl *mod,
1674-
SILOptions &options,
1675-
bool wholeModuleCompilation) {
1676-
return SILModule::constructSIL(mod, options, nullptr, wholeModuleCompilation);
1672+
swift::performSILGeneration(ModuleDecl *mod, SILOptions &options) {
1673+
return SILModule::constructSIL(mod, options, nullptr);
16771674
}
16781675

16791676
std::unique_ptr<SILModule>
16801677
swift::performSILGeneration(FileUnit &sf, SILOptions &options) {
1681-
return SILModule::constructSIL(sf.getParentModule(), options, &sf, false);
1678+
return SILModule::constructSIL(sf.getParentModule(), options, &sf);
16821679
}

0 commit comments

Comments
 (0)