Merge remote-tracking branch 'origin/master' into master-next

This commit is contained in:
swift_jenkins
2020-02-28 10:40:34 -08:00
28 changed files with 234 additions and 179 deletions

View File

@@ -785,8 +785,7 @@ static bool buildModuleFromInterface(const CompilerInvocation &Invocation,
}
static bool compileLLVMIR(const CompilerInvocation &Invocation,
CompilerInstance &Instance,
UnifiedStatsReporter *Stats) {
CompilerInstance &Instance) {
auto &LLVMContext = getGlobalLLVMContext();
// Load in bitcode file.
@@ -823,8 +822,7 @@ static bool compileLLVMIR(const CompilerInvocation &Invocation,
return performLLVM(Invocation.getIRGenOptions(),
Instance.getASTContext(), Module.get(),
Invocation.getFrontendOptions()
.InputsAndOutputs.getSingleOutputFilename(),
Stats);
.InputsAndOutputs.getSingleOutputFilename());
}
static void verifyGenericSignaturesIfNeeded(const CompilerInvocation &Invocation,
@@ -1082,15 +1080,13 @@ static bool performCompileStepsPostSILGen(
CompilerInstance &Instance, const CompilerInvocation &Invocation,
std::unique_ptr<SILModule> SM, bool astGuaranteedToCorrespondToSIL,
ModuleOrSourceFile MSF, const PrimarySpecificPaths &PSPs,
bool moduleIsPublic, int &ReturnValue, FrontendObserver *observer,
UnifiedStatsReporter *Stats);
bool moduleIsPublic, int &ReturnValue, FrontendObserver *observer);
static bool
performCompileStepsPostSema(const CompilerInvocation &Invocation,
CompilerInstance &Instance,
bool moduleIsPublic, int &ReturnValue,
FrontendObserver *observer,
UnifiedStatsReporter *Stats) {
FrontendObserver *observer) {
auto mod = Instance.getMainModule();
if (auto SM = Instance.takeSILModule()) {
const PrimarySpecificPaths PSPs =
@@ -1098,7 +1094,7 @@ performCompileStepsPostSema(const CompilerInvocation &Invocation,
return performCompileStepsPostSILGen(Instance, Invocation, std::move(SM),
/*ASTGuaranteedToCorrespondToSIL=*/false,
mod, PSPs, moduleIsPublic,
ReturnValue, observer, Stats);
ReturnValue, observer);
}
const SILOptions &SILOpts = Invocation.getSILOptions();
@@ -1119,7 +1115,7 @@ performCompileStepsPostSema(const CompilerInvocation &Invocation,
return performCompileStepsPostSILGen(Instance, Invocation, std::move(SM),
astGuaranteedToCorrespondToSIL,
mod, PSPs, moduleIsPublic,
ReturnValue, observer, Stats);
ReturnValue, observer);
}
// If there are primary source files, build a separate SILModule for
// each source file, and run the remaining SILOpt-Serialize-IRGen-LLVM
@@ -1133,7 +1129,7 @@ performCompileStepsPostSema(const CompilerInvocation &Invocation,
result |= performCompileStepsPostSILGen(Instance, Invocation, std::move(SM),
/*ASTGuaranteedToCorrespondToSIL*/true,
PrimaryFile, PSPs, moduleIsPublic,
ReturnValue, observer, Stats);
ReturnValue, observer);
}
return result;
@@ -1152,7 +1148,7 @@ performCompileStepsPostSema(const CompilerInvocation &Invocation,
result |= performCompileStepsPostSILGen(Instance, Invocation, std::move(SM),
!fileIsSIB(SASTF),
mod, PSPs, moduleIsPublic,
ReturnValue, observer, Stats);
ReturnValue, observer);
}
}
@@ -1230,8 +1226,7 @@ static bool performCompile(CompilerInstance &Instance,
const CompilerInvocation &Invocation,
ArrayRef<const char *> Args,
int &ReturnValue,
FrontendObserver *observer,
UnifiedStatsReporter *Stats) {
FrontendObserver *observer) {
FrontendOptions opts = Invocation.getFrontendOptions();
FrontendOptions::ActionType Action = opts.RequestedAction;
@@ -1253,7 +1248,7 @@ static bool performCompile(CompilerInstance &Instance,
return buildModuleFromInterface(Invocation, Instance);
if (Invocation.getInputKind() == InputFileKind::LLVM)
return compileLLVMIR(Invocation, Instance, Stats);
return compileLLVMIR(Invocation, Instance);
if (FrontendOptions::shouldActionOnlyParse(Action)) {
// Disable delayed parsing of type and function bodies when we've been
@@ -1281,8 +1276,9 @@ static bool performCompile(CompilerInstance &Instance,
if (observer)
observer->performedSemanticAnalysis(Instance);
if (Stats)
if (auto *Stats = Context.Stats) {
countStatsPostSema(*Stats, Instance);
}
{
FrontendOptions::DebugCrashMode CrashMode = opts.CrashMode;
@@ -1355,7 +1351,7 @@ static bool performCompile(CompilerInstance &Instance,
"All actions not requiring SILGen must have been handled!");
return performCompileStepsPostSema(Invocation, Instance, moduleIsPublic,
ReturnValue, observer, Stats);
ReturnValue, observer);
}
static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs,
@@ -1461,34 +1457,72 @@ static bool validateTBDIfNeeded(const CompilerInvocation &Invocation,
Opts, allSymbols);
}
enum class DeallocatableResources {
None,
SILModule,
SILModuleAndASTContext,
};
static DeallocatableResources
computeDeallocatableResources(const CompilerInvocation &Invocation,
const CompilerInstance &Instance) {
// If the stats reporter is installed, we need the ASTContext and SILModule
// to live through the entire compilation process.
if (Instance.getASTContext().Stats) {
return DeallocatableResources::None;
}
// If we're going to dump the API of the module, we cannot tear down
// the ASTContext, as that would cause the module to be freed prematurely.
if (!Invocation.getFrontendOptions().DumpAPIPath.empty()) {
return DeallocatableResources::SILModule;
}
// If there are multiple primary inputs it is too soon to free
// the ASTContext, etc.. OTOH, if this compilation generates code for > 1
// primary input, then freeing it after processing the last primary is
// unlikely to reduce the peak heap size. So, only optimize the
// single-primary-case (or WMO).
if (Invocation.getFrontendOptions()
.InputsAndOutputs.hasMultiplePrimaryInputs()) {
return DeallocatableResources::SILModule;
}
return DeallocatableResources::SILModuleAndASTContext;
}
static void
freeDeallocatableResourcesIfPossible(const CompilerInvocation &Invocation,
CompilerInstance &Instance) {
switch (computeDeallocatableResources(Invocation, Instance)) {
case DeallocatableResources::None:
break;
case DeallocatableResources::SILModule:
Instance.freeSILModule();
break;
case DeallocatableResources::SILModuleAndASTContext:
Instance.freeSILModule();
Instance.freeASTContext();
break;
}
}
static bool generateCode(const CompilerInvocation &Invocation,
CompilerInstance &Instance, StringRef OutputFilename,
llvm::Module *IRModule,
llvm::GlobalVariable *HashGlobal,
UnifiedStatsReporter *Stats) {
llvm::GlobalVariable *HashGlobal) {
std::unique_ptr<llvm::TargetMachine> TargetMachine = createTargetMachine(
Invocation.getIRGenOptions(), Instance.getASTContext());
version::Version EffectiveLanguageVersion =
Instance.getASTContext().LangOpts.EffectiveLanguageVersion;
if (!Stats) {
// Free up some compiler resources now that we have an IRModule.
Instance.freeSILModule();
// If there are multiple primary inputs it is too soon to free
// the ASTContext, etc.. OTOH, if this compilation generates code for > 1
// primary input, then freeing it after processing the last primary is
// unlikely to reduce the peak heap size. So, only optimize the
// single-primary-case (or WMO).
if (!Invocation.getFrontendOptions()
.InputsAndOutputs.hasMultiplePrimaryInputs())
Instance.freeASTContext();
}
// Free up some compiler resources now that we have an IRModule.
freeDeallocatableResourcesIfPossible(Invocation, Instance);
// Now that we have a single IR Module, hand it over to performLLVM.
return performLLVM(Invocation.getIRGenOptions(), &Instance.getDiags(),
return performLLVM(Invocation.getIRGenOptions(), Instance.getDiags(),
nullptr, HashGlobal, IRModule, TargetMachine.get(),
EffectiveLanguageVersion, OutputFilename, Stats);
EffectiveLanguageVersion, OutputFilename,
Instance.getStatsReporter());
}
static void collectLinkerDirectives(const CompilerInvocation &Invocation,
@@ -1506,8 +1540,7 @@ static bool performCompileStepsPostSILGen(
CompilerInstance &Instance, const CompilerInvocation &Invocation,
std::unique_ptr<SILModule> SM, bool astGuaranteedToCorrespondToSIL,
ModuleOrSourceFile MSF, const PrimarySpecificPaths &PSPs,
bool moduleIsPublic, int &ReturnValue, FrontendObserver *observer,
UnifiedStatsReporter *Stats) {
bool moduleIsPublic, int &ReturnValue, FrontendObserver *observer) {
FrontendOptions opts = Invocation.getFrontendOptions();
FrontendOptions::ActionType Action = opts.RequestedAction;
@@ -1522,6 +1555,7 @@ static bool performCompileStepsPostSILGen(
if (observer)
observer->performedSILGeneration(*SM);
auto *Stats = Instance.getASTContext().Stats;
if (Stats)
countStatsPostSILGen(*Stats, *SM);
@@ -1565,7 +1599,7 @@ static bool performCompileStepsPostSILGen(
SM->setSerializeSILAction(SerializeSILModuleAction);
// Perform optimizations and mandatory/diagnostic passes.
if (Instance.performSILProcessing(SM.get(), Stats))
if (Instance.performSILProcessing(SM.get()))
return true;
if (observer)
@@ -1659,7 +1693,7 @@ static bool performCompileStepsPostSILGen(
return true;
return generateCode(Invocation, Instance, OutputFilename, IRModule.get(),
HashGlobal, Stats) ||
HashGlobal) ||
HadError;
}
@@ -1776,51 +1810,6 @@ static bool dumpAPI(ModuleDecl *Mod, StringRef OutDir) {
return false;
}
static StringRef
silOptModeArgStr(OptimizationMode mode) {
switch (mode) {
case OptimizationMode::ForSpeed:
return "O";
case OptimizationMode::ForSize:
return "Osize";
default:
return "Onone";
}
}
static std::unique_ptr<UnifiedStatsReporter>
computeStatsReporter(const CompilerInvocation &Invocation, CompilerInstance *Instance) {
const std::string &StatsOutputDir =
Invocation.getFrontendOptions().StatsOutputDir;
std::unique_ptr<UnifiedStatsReporter> StatsReporter;
if (StatsOutputDir.empty())
return std::unique_ptr<UnifiedStatsReporter>();
auto &FEOpts = Invocation.getFrontendOptions();
auto &LangOpts = Invocation.getLangOptions();
auto &SILOpts = Invocation.getSILOptions();
std::string InputName =
FEOpts.InputsAndOutputs.getStatsFileMangledInputName();
StringRef OptType = silOptModeArgStr(SILOpts.OptMode);
const std::string &OutFile =
FEOpts.InputsAndOutputs.lastInputProducingOutput().outputFilename();
StringRef OutputType = llvm::sys::path::extension(OutFile);
std::string TripleName = LangOpts.Target.normalize();
auto Trace = Invocation.getFrontendOptions().TraceStats;
auto ProfileEvents = Invocation.getFrontendOptions().ProfileEvents;
auto ProfileEntities = Invocation.getFrontendOptions().ProfileEntities;
SourceManager *SM = &Instance->getSourceMgr();
clang::SourceManager *CSM = nullptr;
if (auto *clangImporter = static_cast<ClangImporter *>(
Instance->getASTContext().getClangModuleLoader())) {
CSM = &clangImporter->getClangASTContext().getSourceManager();
}
return std::make_unique<UnifiedStatsReporter>(
"swift-frontend", FEOpts.ModuleName, InputName, TripleName, OutputType,
OptType, StatsOutputDir, SM, CSM, Trace,
ProfileEvents, ProfileEntities);
}
/// Creates a diagnostic consumer that handles dispatching diagnostics to
/// multiple output files, based on the supplementary output paths specified by
/// \p inputsAndOutputs.
@@ -2181,15 +2170,6 @@ int swift::performFrontend(ArrayRef<const char *> Args,
return finishDiagProcessing(1);
}
std::unique_ptr<UnifiedStatsReporter> StatsReporter =
computeStatsReporter(Invocation, Instance.get());
if (StatsReporter) {
// Install stats-reporter somewhere visible for subsystems that
// need to bump counters as they work, rather than measure
// accumulated work on completion (mostly: TypeChecker).
Instance->getASTContext().setStatsReporter(StatsReporter.get());
}
// The compiler instance has been configured; notify our observer.
if (observer) {
observer->configuredCompiler(*Instance);
@@ -2197,8 +2177,7 @@ int swift::performFrontend(ArrayRef<const char *> Args,
int ReturnValue = 0;
bool HadError =
performCompile(*Instance, Invocation, Args, ReturnValue, observer,
StatsReporter.get());
performCompile(*Instance, Invocation, Args, ReturnValue, observer);
if (!HadError) {
Mangle::printManglingStats();
@@ -2226,7 +2205,7 @@ int swift::performFrontend(ArrayRef<const char *> Args,
}
auto r = finishDiagProcessing(HadError ? 1 : ReturnValue);
if (StatsReporter)
if (auto *StatsReporter = Instance->getStatsReporter())
StatsReporter->noteCurrentProcessExitStatus(r);
return r;
}