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.
This commit is contained in:
Jordan Rose
2018-09-22 13:44:46 -07:00
parent 985dbee199
commit a9bbaf751f
5 changed files with 13 additions and 18 deletions

View File

@@ -345,8 +345,7 @@ public:
/// If a source file is provided, SIL will only be emitted for decls in that
/// source file.
static std::unique_ptr<SILModule>
constructSIL(ModuleDecl *M, SILOptions &Options, FileUnit *sf = nullptr,
bool isWholeModule = false);
constructSIL(ModuleDecl *M, SILOptions &Options, FileUnit *sf = nullptr);
/// \brief Create and return an empty SIL module that we can
/// later parse SIL bodies directly into, without converting from an AST.

View File

@@ -237,13 +237,10 @@ namespace swift {
/// Turn the given module into SIL IR.
///
/// The module must contain source files.
///
/// if \p wholeModuleCompilation is true, the optimizer assumes that the SIL
/// of all files in the module is present in the SILModule.
/// The module must contain source files. The optimizer will assume that the
/// SIL of all files in the module is present in the SILModule.
std::unique_ptr<SILModule>
performSILGeneration(ModuleDecl *M, SILOptions &options,
bool wholeModuleCompilation = false);
performSILGeneration(ModuleDecl *M, SILOptions &options);
/// Turn a source file into SIL IR.
std::unique_ptr<SILModule>

View File

@@ -819,7 +819,7 @@ generateSILModules(CompilerInvocation &Invocation, CompilerInstance &Instance) {
if (!opts.InputsAndOutputs.hasPrimaryInputs()) {
// If there are no primary inputs the compiler is in WMO mode and builds one
// SILModule for the entire module.
auto SM = performSILGeneration(mod, SILOpts, true);
auto SM = performSILGeneration(mod, SILOpts);
std::deque<PostSILGenInputs> PSGIs;
const PrimarySpecificPaths PSPs =
Instance.getPrimarySpecificPathsForWholeModuleOptimizationMode();

View File

@@ -873,7 +873,9 @@ private:
std::unique_ptr<SILModule> sil;
if (!CI.getASTContext().hadError()) {
sil = performSILGeneration(M, CI.getSILOptions());
// We don't want anything to get stripped, so pretend we're doing a
// non-whole-module generation.
sil = performSILGeneration(*M->getFiles().front(), CI.getSILOptions());
runSILDiagnosticPasses(*sil);
runSILLoweringPasses(*sil);
}

View File

@@ -1602,8 +1602,7 @@ void SILGenModule::emitSourceFile(SourceFile *sf) {
//===----------------------------------------------------------------------===//
std::unique_ptr<SILModule>
SILModule::constructSIL(ModuleDecl *mod, SILOptions &options, FileUnit *SF,
bool isWholeModule) {
SILModule::constructSIL(ModuleDecl *mod, SILOptions &options, FileUnit *SF) {
SharedTimer timer("SILGen");
const DeclContext *DC;
if (SF) {
@@ -1613,7 +1612,7 @@ SILModule::constructSIL(ModuleDecl *mod, SILOptions &options, FileUnit *SF,
}
std::unique_ptr<SILModule> M(
new SILModule(mod, options, DC, isWholeModule));
new SILModule(mod, options, DC, /*wholeModule*/ SF == nullptr));
SILGenModule SGM(*M, mod);
if (SF) {
@@ -1670,13 +1669,11 @@ SILModule::constructSIL(ModuleDecl *mod, SILOptions &options, FileUnit *SF,
}
std::unique_ptr<SILModule>
swift::performSILGeneration(ModuleDecl *mod,
SILOptions &options,
bool wholeModuleCompilation) {
return SILModule::constructSIL(mod, options, nullptr, wholeModuleCompilation);
swift::performSILGeneration(ModuleDecl *mod, SILOptions &options) {
return SILModule::constructSIL(mod, options, nullptr);
}
std::unique_ptr<SILModule>
swift::performSILGeneration(FileUnit &sf, SILOptions &options) {
return SILModule::constructSIL(sf.getParentModule(), options, &sf, false);
return SILModule::constructSIL(sf.getParentModule(), options, &sf);
}