Skip to content

Commit d3f1622

Browse files
committed
Tweaks to shorten performCompile* a bit more.
# Conflicts: # lib/FrontendTool/FrontendTool.cpp
1 parent 5b443c0 commit d3f1622

File tree

5 files changed

+41
-42
lines changed

5 files changed

+41
-42
lines changed

include/swift/Migrator/Migrator.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ class CompilerInstance;
2525

2626
namespace migrator {
2727

28-
/// Run the migrator on the compiler invocation's input file and emit a
29-
/// "replacement map" describing the requested changes to the source file.
30-
bool updateCodeAndEmitRemap(CompilerInstance *Instance,
31-
const CompilerInvocation &Invocation);
28+
/// If needed, run the migrator on the compiler invocation's input file and emit
29+
/// a "replacement map" describing the requested changes to the source file.
30+
/// \return true on error.
31+
bool updateCodeAndEmitRemapIfNeeded(CompilerInstance *Instance,
32+
const CompilerInvocation &Invocation);
3233

3334
struct Migrator {
3435
CompilerInstance *StartInstance;

include/swift/SILOptimizer/PassManager/Passes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ namespace swift {
6565
/// \brief Convert SIL to a lowered form suitable for IRGen.
6666
void runSILLoweringPasses(SILModule &M);
6767

68-
/// \brief Perform SIL Inst Count on M.
69-
void performSILInstCount(SILModule *M);
68+
/// \brief Perform SIL Inst Count on M if needed.
69+
void performSILInstCountIfNeeded(SILModule *M);
7070

7171
/// \brief Identifiers for all passes. Used to procedurally create passes from
7272
/// lists of passes.

lib/FrontendTool/FrontendTool.cpp

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -850,27 +850,25 @@ static bool performCompile(CompilerInstance &Instance,
850850
if (Action == FrontendOptions::ActionType::Parse)
851851
return Instance.getASTContext().hadError();
852852

853-
if (observer) {
853+
if (observer)
854854
observer->performedSemanticAnalysis(Instance);
855-
}
856855

857-
if (Stats) {
856+
if (Stats)
858857
countStatsPostSema(*Stats, Instance);
859-
}
860858

861-
FrontendOptions::DebugCrashMode CrashMode = opts.CrashMode;
862-
if (CrashMode == FrontendOptions::DebugCrashMode::AssertAfterParse)
863-
debugFailWithAssertion();
864-
else if (CrashMode == FrontendOptions::DebugCrashMode::CrashAfterParse)
865-
debugFailWithCrash();
859+
{
860+
FrontendOptions::DebugCrashMode CrashMode = opts.CrashMode;
861+
if (CrashMode == FrontendOptions::DebugCrashMode::AssertAfterParse)
862+
debugFailWithAssertion();
863+
else if (CrashMode == FrontendOptions::DebugCrashMode::CrashAfterParse)
864+
debugFailWithCrash();
865+
}
866866

867867
ASTContext &Context = Instance.getASTContext();
868868

869869
verifyGenericSignaturesIfNeeded(Invocation, Context);
870870

871-
if (Invocation.getMigratorOptions().shouldRunMigrator()) {
872-
migrator::updateCodeAndEmitRemap(&Instance, Invocation);
873-
}
871+
(void)migrator::updateCodeAndEmitRemapIfNeeded(&Instance, Invocation);
874872

875873
if (Action == FrontendOptions::ActionType::REPL) {
876874
runREPL(Instance, ProcessCmdLine(Args.begin(), Args.end()),
@@ -913,6 +911,7 @@ static bool performCompile(CompilerInstance &Instance,
913911
if (!opts.ObjCHeaderOutputPath.empty())
914912
return printAsObjC(opts.ObjCHeaderOutputPath, Instance.getMainModule(),
915913
opts.ImplicitObjCHeaderPath, moduleIsPublic);
914+
916915
return emitIndexDataIfNeeded(Instance.getPrimarySourceFile(), Invocation,
917916
Instance) ||
918917
Context.hadError();
@@ -1037,15 +1036,16 @@ static void setPrivateDiscriminatorIfNeeded(IRGenOptions &IRGenOpts,
10371036
IRGenOpts.DWARFDebugFlags += (" -private-discriminator " + PD.str()).str();
10381037
}
10391038

1040-
static bool serializeSIB(FrontendOptions &opts, SILModule *SM,
1041-
ASTContext &Context, ModuleOrSourceFile MSF) {
1039+
static bool serializeSIBIfNeeded(FrontendOptions &opts, SILModule *SM,
1040+
ASTContext &Context, ModuleOrSourceFile MSF) {
10421041
const std::string &moduleOutputPath = opts.ModuleOutputPath;
10431042
assert(!moduleOutputPath.empty() && "must have an output path");
10441043

10451044
SerializationOptions serializationOpts;
10461045
serializationOpts.OutputPath = moduleOutputPath.c_str();
10471046
serializationOpts.SerializeAllSIL = true;
10481047
serializationOpts.IsSIB = true;
1048+
10491049
serialize(MSF, serializationOpts, SM);
10501050
return Context.hadError();
10511051
}
@@ -1166,12 +1166,11 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
11661166
SILOptions &SILOpts = Invocation.getSILOptions();
11671167
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
11681168

1169-
if (observer) {
1169+
if (observer)
11701170
observer->performedSILGeneration(*SM);
1171-
}
1172-
if (Stats) {
1171+
1172+
if (Stats)
11731173
countStatsPostSILGen(*Stats, *SM);
1174-
}
11751174

11761175
// We've been told to emit SIL after SILGen, so write it now.
11771176
if (Action == FrontendOptions::ActionType::EmitSILGen) {
@@ -1181,8 +1180,8 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
11811180

11821181
if (Action == FrontendOptions::ActionType::EmitSIBGen) {
11831182
linkAllIfNeeded(Invocation, SM.get());
1184-
serializeSIB(Invocation.getFrontendOptions(), SM.get(),
1185-
Instance.getASTContext(), MSF);
1183+
serializeSIBIfNeeded(Invocation.getFrontendOptions(), SM.get(),
1184+
Instance.getASTContext(), MSF);
11861185
return Context.hadError();
11871186
}
11881187

@@ -1222,22 +1221,18 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
12221221

12231222
performSILOptimizations(Invocation, SM.get());
12241223

1225-
if (observer) {
1224+
if (observer)
12261225
observer->performedSILOptimization(*SM);
1227-
}
1228-
if (Stats) {
1226+
1227+
if (Stats)
12291228
countStatsPostSILOpt(*Stats, *SM);
1230-
}
12311229

12321230
{
12331231
SharedTimer timer("SIL verification, post-optimization");
12341232
SM->verify();
12351233
}
12361234

1237-
// Gather instruction counts if we are asked to do so.
1238-
if (SM->getOptions().PrintInstCounts) {
1239-
performSILInstCount(&*SM);
1240-
}
1235+
performSILInstCountIfNeeded(&*SM);
12411236

12421237
setPrivateDiscriminatorIfNeeded(IRGenOpts, MSF);
12431238

@@ -1247,8 +1242,8 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
12471242
}
12481243

12491244
if (Action == FrontendOptions::ActionType::EmitSIB)
1250-
return serializeSIB(Invocation.getFrontendOptions(), SM.get(),
1251-
Instance.getASTContext(), MSF);
1245+
return serializeSIBIfNeeded(Invocation.getFrontendOptions(), SM.get(),
1246+
Instance.getASTContext(), MSF);
12521247

12531248
const bool haveModulePath =
12541249
!opts.ModuleOutputPath.empty() || !opts.ModuleDocOutputPath.empty();
@@ -1280,7 +1275,6 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
12801275
if (Context.hadError())
12811276
return true;
12821277

1283-
// Convert SIL to a lowered form suitable for IRGen.
12841278
runSILLoweringPasses(*SM);
12851279

12861280
// TODO: remove once the frontend understands what action it should perform
@@ -1307,9 +1301,8 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
13071301
// If the AST Context has no errors but no IRModule is available,
13081302
// parallelIRGen happened correctly, since parallel IRGen produces multiple
13091303
// modules.
1310-
if (!IRModule) {
1304+
if (!IRModule)
13111305
return HadError;
1312-
}
13131306

13141307
if (validateTBDIfNeeded(Invocation, MSF, astGuaranteedToCorrespondToSIL,
13151308
*IRModule))

lib/Migrator/Migrator.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
using namespace swift;
2727
using namespace swift::migrator;
2828

29-
bool migrator::updateCodeAndEmitRemap(CompilerInstance *Instance,
30-
const CompilerInvocation &Invocation) {
29+
bool migrator::updateCodeAndEmitRemapIfNeeded(
30+
CompilerInstance *Instance, const CompilerInvocation &Invocation) {
31+
if (!Invocation.getMigratorOptions().shouldRunMigrator())
32+
return false;
33+
3134
// Delete the remap file, in case someone is re-running the Migrator. If the
3235
// file fails to compile and we don't get a chance to overwrite it, the old
3336
// changes may get picked up.

lib/SILOptimizer/UtilityPasses/InstCount.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ SILTransform *swift::createInstCount() {
152152
return new InstCount();
153153
}
154154

155-
void swift::performSILInstCount(SILModule *M) {
155+
void swift::performSILInstCountIfNeeded(SILModule *M) {
156+
if (!M->getOptions().PrintInstCounts)
157+
return;
156158
SILPassManager PrinterPM(M);
157159
PrinterPM.executePassPipelinePlan(
158160
SILPassPipelinePlan::getInstCountPassPipeline());

0 commit comments

Comments
 (0)