diff --git a/include/swift/Subsystems.h b/include/swift/Subsystems.h index 948e42af517..0e718af4d7f 100644 --- a/include/swift/Subsystems.h +++ b/include/swift/Subsystems.h @@ -259,8 +259,9 @@ namespace swift { /// If you set an outModuleHash, then you need to call performLLVM. std::unique_ptr performIRGeneration(IRGenOptions &Opts, ModuleDecl *M, - std::unique_ptr SILMod, StringRef ModuleName, - PrimarySpecificPaths PSPs, llvm::LLVMContext &LLVMContext, + std::unique_ptr SILMod, + StringRef ModuleName, PrimarySpecificPaths PSPs, + llvm::LLVMContext &LLVMContext, ArrayRef parallelOutputFilenames, llvm::GlobalVariable **outModuleHash = nullptr); @@ -269,8 +270,9 @@ namespace swift { /// If you set an outModuleHash, then you need to call performLLVM. std::unique_ptr performIRGeneration(IRGenOptions &Opts, SourceFile &SF, - std::unique_ptr SILMod, StringRef ModuleName, - PrimarySpecificPaths PSPs, llvm::LLVMContext &LLVMContext, + std::unique_ptr SILMod, + StringRef ModuleName, PrimarySpecificPaths PSPs, + llvm::LLVMContext &LLVMContext, unsigned StartElem = 0, llvm::GlobalVariable **outModuleHash = nullptr); @@ -287,7 +289,7 @@ namespace swift { /// Turn the given LLVM module into native code and return true on error. bool performLLVM(IRGenOptions &Opts, ASTContext &Ctx, llvm::Module *Module, StringRef OutputFilename, - UnifiedStatsReporter *Stats = nullptr); + UnifiedStatsReporter *Stats=nullptr); /// Run the LLVM passes. In multi-threaded compilation this will be done for /// multiple LLVM modules in parallel. diff --git a/lib/Frontend/FrontendInputsAndOutputs.cpp b/lib/Frontend/FrontendInputsAndOutputs.cpp index 7718e77793b..6e434379d68 100644 --- a/lib/Frontend/FrontendInputsAndOutputs.cpp +++ b/lib/Frontend/FrontendInputsAndOutputs.cpp @@ -309,7 +309,7 @@ void FrontendInputsAndOutputs::setMainAndSupplementaryOutputs( } SupplementaryOutputs = supplementaryOutputs; - if (hasInputs() && primaryInputCount() < 2) { + if (hasUniquePrimaryInput() || (hasInputs() && isWholeModule())) { // When batch mode is fully implemented, each InputFile will own // a PrimarySpecificPaths. PrimarySpecificPathsForAtMostOnePrimary.OutputFilename = diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index e3bc689ed35..b97f9e05bc7 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -826,11 +826,16 @@ generateSILModules(CompilerInvocation &Invocation, CompilerInstance &Instance) { return PSGIs; } -static bool performCompileStepsPostSILGen( - CompilerInstance &Instance, CompilerInvocation &Invocation, - std::unique_ptr SM, bool astGuaranteedToCorrespondToSIL, - ModuleOrSourceFile MSF, PrimarySpecificPaths PSPs, bool moduleIsPublic, - int &ReturnValue, FrontendObserver *observer, UnifiedStatsReporter *Stats); +static bool performCompileStepsPostSILGen(CompilerInstance &Instance, + CompilerInvocation &Invocation, + std::unique_ptr SM, + bool astGuaranteedToCorrespondToSIL, + ModuleOrSourceFile MSF, + PrimarySpecificPaths PSPs, + bool moduleIsPublic, + int &ReturnValue, + FrontendObserver *observer, + UnifiedStatsReporter *Stats); /// Performs the compile requested by the user. /// \param Instance Will be reset after performIRGeneration when the verifier @@ -950,10 +955,13 @@ static bool performCompile(CompilerInstance &Instance, while (!PSGIs.empty()) { auto PSGI = std::move(PSGIs.front()); PSGIs.pop_front(); - if (performCompileStepsPostSILGen( - Instance, Invocation, std::move(PSGI.TheSILModule), - PSGI.ASTGuaranteedToCorrespondToSIL, PSGI.ModuleOrPrimarySourceFile, - PSGI.PSPs, moduleIsPublic, ReturnValue, observer, Stats)) + if (performCompileStepsPostSILGen(Instance, Invocation, + std::move(PSGI.TheSILModule), + PSGI.ASTGuaranteedToCorrespondToSIL, + PSGI.ModuleOrPrimarySourceFile, + PSGI.PSPs, + moduleIsPublic, + ReturnValue, observer, Stats)) return true; } return false; @@ -1074,8 +1082,8 @@ static bool serializeSIB(FrontendOptions &opts, SILModule *SM, } static void generateIR(IRGenOptions &IRGenOpts, std::unique_ptr SM, - PrimarySpecificPaths PSPs, StringRef OutputFilename, - ModuleOrSourceFile MSF, + PrimarySpecificPaths PSPs, + StringRef OutputFilename, ModuleOrSourceFile MSF, std::unique_ptr &IRModule, llvm::GlobalVariable *&HashGlobal, std::vector parallelOutputFilenames) { @@ -1170,12 +1178,16 @@ static bool generateCode(CompilerInvocation &Invocation, EffectiveLanguageVersion, OutputFilename, Stats); } -static bool performCompileStepsPostSILGen( - CompilerInstance &Instance, CompilerInvocation &Invocation, - std::unique_ptr SM, bool astGuaranteedToCorrespondToSIL, - ModuleOrSourceFile MSF, const PrimarySpecificPaths PSPs, - bool moduleIsPublic, int &ReturnValue, FrontendObserver *observer, - UnifiedStatsReporter *Stats) { +static bool performCompileStepsPostSILGen(CompilerInstance &Instance, + CompilerInvocation &Invocation, + std::unique_ptr SM, + bool astGuaranteedToCorrespondToSIL, + ModuleOrSourceFile MSF, + const PrimarySpecificPaths PSPs, + bool moduleIsPublic, + int &ReturnValue, + FrontendObserver *observer, + UnifiedStatsReporter *Stats) { FrontendOptions opts = Invocation.getFrontendOptions(); FrontendOptions::ActionType Action = opts.RequestedAction; diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index 4a79c501c73..5b7968e58d7 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -675,8 +675,9 @@ swift::irgen::createIRGenModule(SILModule *SILMod, PrimarySpecificPaths PSPs, return std::make_pair(nullptr, nullptr); // Create the IR emitter. - IRGenModule *IGM = new IRGenModule(*irgen, std::move(targetMachine), nullptr, - LLVMContext, "", PSPs); + IRGenModule *IGM = + new IRGenModule(*irgen, std::move(targetMachine), nullptr, LLVMContext, + "", PSPs); initLLVMModule(*IGM); @@ -711,11 +712,15 @@ static void runIRGenPreparePasses(SILModule &Module, /// Generates LLVM IR, runs the LLVM passes and produces the output file. /// All this is done in a single thread. -static std::unique_ptr performIRGeneration( - IRGenOptions &Opts, swift::ModuleDecl *M, std::unique_ptr SILMod, - StringRef ModuleName, const PrimarySpecificPaths PSPs, - llvm::LLVMContext &LLVMContext, SourceFile *SF = nullptr, - llvm::GlobalVariable **outModuleHash = nullptr, unsigned StartElem = 0) { +static std::unique_ptr performIRGeneration(IRGenOptions &Opts, + swift::ModuleDecl *M, + std::unique_ptr SILMod, + StringRef ModuleName, + const PrimarySpecificPaths PSPs, + llvm::LLVMContext &LLVMContext, + SourceFile *SF = nullptr, + llvm::GlobalVariable **outModuleHash = nullptr, + unsigned StartElem = 0) { auto &Ctx = M->getASTContext(); assert(!Ctx.hadError()); @@ -725,8 +730,8 @@ static std::unique_ptr performIRGeneration( if (!targetMachine) return nullptr; // Create the IR emitter. - IRGenModule IGM(irgen, std::move(targetMachine), nullptr, LLVMContext, - ModuleName, PSPs); + IRGenModule IGM(irgen, std::move(targetMachine), nullptr, + LLVMContext, ModuleName, PSPs); initLLVMModule(IGM); @@ -836,9 +841,12 @@ static std::unique_ptr performIRGeneration( static void ThreadEntryPoint(IRGenerator *irgen, llvm::sys::Mutex *DiagMutex, int ThreadIdx) { while (IRGenModule *IGM = irgen->fetchFromQueue()) { - DEBUG(DiagMutex->lock(); dbgs() << "thread " << ThreadIdx << ": fetched " - << IGM->PSPs.OutputFilename << "\n"; - DiagMutex->unlock();); + DEBUG( + DiagMutex->lock(); + dbgs() << "thread " << ThreadIdx << ": fetched " << + IGM->PSPs.OutputFilename << "\n"; + DiagMutex->unlock(); + ); embedBitcode(IGM->getModule(), irgen->Opts); performLLVM(irgen->Opts, &IGM->Context.Diags, DiagMutex, IGM->ModuleHash, IGM->getModule(), IGM->TargetMachine.get(), @@ -907,10 +915,12 @@ static void performParallelIRGeneration(IRGenOptions &Opts, auto Context = new LLVMContext(); // Create the IR emitter. - IRGenModule *IGM = new IRGenModule( - irgen, std::move(targetMachine), nextSF, *Context, ModuleName, - PrimarySpecificPaths(*OutputIter++, nextSF->getFilename(), - PSPs.SupplementaryOutputs)); + IRGenModule *IGM = new IRGenModule(irgen, std::move(targetMachine), + nextSF, *Context, + ModuleName, + PrimarySpecificPaths(*OutputIter++, + nextSF->getFilename(), + PSPs.SupplementaryOutputs)); IGMcreated = true; initLLVMModule(*IGM); @@ -1070,12 +1080,13 @@ static void performParallelIRGeneration(IRGenOptions &Opts, } } -std::unique_ptr swift::performIRGeneration( - IRGenOptions &Opts, swift::ModuleDecl *M, std::unique_ptr SILMod, - StringRef ModuleName, const PrimarySpecificPaths PSPs, - llvm::LLVMContext &LLVMContext, - ArrayRef parallelOutputFilenames, - llvm::GlobalVariable **outModuleHash) { +std::unique_ptr swift:: +performIRGeneration(IRGenOptions &Opts, swift::ModuleDecl *M, + std::unique_ptr SILMod, + StringRef ModuleName, const PrimarySpecificPaths PSPs, + llvm::LLVMContext &LLVMContext, + ArrayRef parallelOutputFilenames, + llvm::GlobalVariable **outModuleHash) { if (SILMod->getOptions().shouldPerformIRGenerationInParallel() && !parallelOutputFilenames.empty()) { auto NumThreads = SILMod->getOptions().NumThreads; @@ -1089,18 +1100,22 @@ std::unique_ptr swift::performIRGeneration( LLVMContext, nullptr, outModuleHash); } -std::unique_ptr swift::performIRGeneration( - IRGenOptions &Opts, SourceFile &SF, std::unique_ptr SILMod, - StringRef ModuleName, const PrimarySpecificPaths PSPs, - llvm::LLVMContext &LLVMContext, unsigned StartElem, - llvm::GlobalVariable **outModuleHash) { - return ::performIRGeneration(Opts, SF.getParentModule(), std::move(SILMod), - ModuleName, PSPs, LLVMContext, &SF, - outModuleHash, StartElem); +std::unique_ptr swift:: +performIRGeneration(IRGenOptions &Opts, SourceFile &SF, + std::unique_ptr SILMod, + StringRef ModuleName, const PrimarySpecificPaths PSPs, + llvm::LLVMContext &LLVMContext, + unsigned StartElem, + llvm::GlobalVariable **outModuleHash) { + return ::performIRGeneration(Opts, SF.getParentModule(), + std::move(SILMod), ModuleName, + PSPs, + LLVMContext, &SF, outModuleHash, StartElem); } -void swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer, - StringRef OutputPath) { +void +swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer, + StringRef OutputPath) { LLVMContext VMContext; auto &Ctx = SILMod.getASTContext(); @@ -1144,7 +1159,8 @@ void swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer, ASTSym->setSection(Section); ASTSym->setAlignment(8); ::performLLVM(Opts, &Ctx.Diags, nullptr, nullptr, IGM.getModule(), - IGM.TargetMachine.get(), Ctx.LangOpts.EffectiveLanguageVersion, + IGM.TargetMachine.get(), + Ctx.LangOpts.EffectiveLanguageVersion, OutputPath); } @@ -1158,7 +1174,8 @@ bool swift::performLLVM(IRGenOptions &Opts, ASTContext &Ctx, embedBitcode(Module, Opts); if (::performLLVM(Opts, &Ctx.Diags, nullptr, nullptr, Module, - TargetMachine.get(), Ctx.LangOpts.EffectiveLanguageVersion, + TargetMachine.get(), + Ctx.LangOpts.EffectiveLanguageVersion, OutputFilename, Stats)) return true; return false; diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 9eca48aefe7..754d39e41b7 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -1453,9 +1453,9 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts, ClangImporter &CI, IRGenModule &IGM, llvm::Module &M, StringRef MainOutputFilenameForDebugInfo) - : Opts(Opts), CI(CI), SM(IGM.Context.SourceMgr), DBuilder(M), IGM(IGM), - MetadataTypeDecl(nullptr), InternalType(nullptr), LastDebugLoc({}), - LastScope(nullptr) { + : Opts(Opts), CI(CI), SM(IGM.Context.SourceMgr), DBuilder(M), + IGM(IGM), MetadataTypeDecl(nullptr), InternalType(nullptr), + LastDebugLoc({}), LastScope(nullptr) { assert(Opts.DebugInfoKind > IRGenDebugInfoKind::None && "no debug info should be generated"); StringRef SourceFileName = MainOutputFilenameForDebugInfo; diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index 1bcfba11e10..be01b7b3cbf 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -412,8 +412,8 @@ IRGenModule::IRGenModule(IRGenerator &irgen, SwiftCC = llvm::CallingConv::Swift; if (IRGen.Opts.DebugInfoKind > IRGenDebugInfoKind::None) - DebugInfo = IRGenDebugInfo::createIRGenDebugInfo( - IRGen.Opts, *CI, *this, Module, PSPs.MainInputFilenameForDebugInfo); + DebugInfo = IRGenDebugInfo::createIRGenDebugInfo(IRGen.Opts, *CI, *this, + Module, PSPs.MainInputFilenameForDebugInfo); initClangTypeConverter(); diff --git a/lib/IRGen/IRGenModule.h b/lib/IRGen/IRGenModule.h index b12fda91a45..b9b5fd4fbdb 100644 --- a/lib/IRGen/IRGenModule.h +++ b/lib/IRGen/IRGenModule.h @@ -1039,9 +1039,11 @@ public: /// /// The \p SF is the source file for which the llvm module is generated when /// doing multi-threaded whole-module compilation. Otherwise it is null. - IRGenModule(IRGenerator &irgen, std::unique_ptr &&target, + IRGenModule(IRGenerator &irgen, + std::unique_ptr &&target, SourceFile *SF, llvm::LLVMContext &LLVMContext, - StringRef ModuleName, PrimarySpecificPaths PSPs); + StringRef ModuleName, + PrimarySpecificPaths PSPs); ~IRGenModule(); llvm::LLVMContext &getLLVMContext() const { return LLVMContext; } diff --git a/lib/Immediate/Immediate.cpp b/lib/Immediate/Immediate.cpp index 071750624e4..22df617242e 100644 --- a/lib/Immediate/Immediate.cpp +++ b/lib/Immediate/Immediate.cpp @@ -251,8 +251,8 @@ bool swift::immediate::IRGenImportedModules( if (!ImportedModules.insert(import).second) continue; - std::unique_ptr SILMod = - performSILGeneration(import, CI.getSILOptions()); + std::unique_ptr SILMod = performSILGeneration(import, + CI.getSILOptions()); performSILLinking(SILMod.get()); if (runSILDiagnosticPasses(*SILMod)) { hadError = true; diff --git a/lib/RemoteAST/RemoteAST.cpp b/lib/RemoteAST/RemoteAST.cpp index 97214c1b469..11c0c22d9bc 100644 --- a/lib/RemoteAST/RemoteAST.cpp +++ b/lib/RemoteAST/RemoteAST.cpp @@ -65,11 +65,11 @@ struct IRGenContext { private: IRGenContext(ASTContext &ctx, ModuleDecl *module) - : SILMod(SILModule::createEmptyModule(module, SILOpts)), - IRGen(IROpts, *SILMod), - IGM(IRGen, IRGen.createTargetMachine(), /*SourceFile*/ nullptr, - LLVMContext, "", - PrimarySpecificPaths("", + : SILMod(SILModule::createEmptyModule(module, SILOpts)), + IRGen(IROpts, *SILMod), + IGM(IRGen, IRGen.createTargetMachine(), /*SourceFile*/ nullptr, + LLVMContext, "", + PrimarySpecificPaths("", "")) {} public: diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index 58c9212ecd8..4d2ee227709 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -1412,7 +1412,8 @@ void SILGenModule::emitSourceFile(SourceFile *sf, unsigned startElem) { std::unique_ptr SILModule::constructSIL(ModuleDecl *mod, SILOptions &options, FileUnit *SF, - Optional startElem, bool isWholeModule) { + Optional startElem, + bool isWholeModule) { SharedTimer timer("SILGen"); const DeclContext *DC; if (startElem) { @@ -1426,7 +1427,8 @@ SILModule::constructSIL(ModuleDecl *mod, SILOptions &options, FileUnit *SF, DC = mod; } - std::unique_ptr M(new SILModule(mod, options, DC, isWholeModule)); + std::unique_ptr M( + new SILModule(mod, options, DC, isWholeModule)); SILGenModule SGM(*M, mod); if (SF) { @@ -1483,7 +1485,8 @@ SILModule::constructSIL(ModuleDecl *mod, SILOptions &options, FileUnit *SF, } std::unique_ptr -swift::performSILGeneration(ModuleDecl *mod, SILOptions &options, +swift::performSILGeneration(ModuleDecl *mod, + SILOptions &options, bool wholeModuleCompilation) { return SILModule::constructSIL(mod, options, nullptr, None, wholeModuleCompilation);