Skip to content

Commit 59ae518

Browse files
committed
[NFC] Used SILOption field for copy propagation.
Replaced the quad-state (of state which one was illegal) of two booleans (EnableCopyPropagation and DisableCopyPropagation) with an enum.
1 parent 868ae0e commit 59ae518

File tree

5 files changed

+47
-23
lines changed

5 files changed

+47
-23
lines changed

include/swift/AST/SILOptions.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ enum class LexicalLifetimesOption : uint8_t {
4444
On,
4545
};
4646

47+
enum class CopyPropagationOption : uint8_t {
48+
// Do not add any copy propagation passes.
49+
Off = 0,
50+
51+
// Only add the copy propagation passes requested by other flags, currently
52+
// just -enable-ossa-modules.
53+
RequestedPassesOnly,
54+
55+
// Add all relevant copy propagation passes. If a setting, e.g.
56+
// -enable-ossa-modules, requests to add copy propagation to the pipeline, do
57+
// so.
58+
On
59+
};
60+
4761
class SILModule;
4862

4963
class SILOptions {
@@ -64,15 +78,12 @@ class SILOptions {
6478
LexicalLifetimesOption LexicalLifetimes =
6579
LexicalLifetimesOption::DiagnosticMarkersOnly;
6680

67-
/// Force-run SIL copy propagation to shorten object lifetime in whatever
68-
/// optimization pipeline is currently used.
69-
/// When this is 'false' the pipeline has default behavior.
70-
bool EnableCopyPropagation = false;
71-
72-
/// Disable SIL copy propagation to preserve object lifetime in whatever
81+
/// Whether to run SIL copy propagation to shorten object lifetime in whatever
7382
/// optimization pipeline is currently used.
74-
/// When this is 'false' the pipeline has default behavior.
75-
bool DisableCopyPropagation = false;
83+
///
84+
/// When this is 'RequestedPassesOnly' the pipeline has default behavior.
85+
CopyPropagationOption CopyPropagation =
86+
CopyPropagationOption::RequestedPassesOnly;
7687

7788
/// Controls whether the SIL ARC optimizations are run.
7889
bool EnableARCOptimizations = true;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,10 +1557,18 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
15571557
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination,
15581558
"enable-copy-propagation", "disable-copy-propagation");
15591559
return true;
1560+
} else if (Args.hasArg(OPT_enable_copy_propagation) &&
1561+
!Args.hasArg(OPT_disable_copy_propagation)) {
1562+
Opts.CopyPropagation = CopyPropagationOption::On;
1563+
} else if (!Args.hasArg(OPT_enable_copy_propagation) &&
1564+
Args.hasArg(OPT_disable_copy_propagation)) {
1565+
Opts.CopyPropagation = CopyPropagationOption::Off;
1566+
} else /*if (!Args.hasArg(OPT_enable_copy_propagation) &&
1567+
!Args.hasArg(OPT_disable_copy_propagation))*/
1568+
{
1569+
Opts.CopyPropagation = CopyPropagationOption::RequestedPassesOnly;
15601570
}
15611571

1562-
Opts.EnableCopyPropagation |= Args.hasArg(OPT_enable_copy_propagation);
1563-
Opts.DisableCopyPropagation |= Args.hasArg(OPT_disable_copy_propagation);
15641572
Opts.EnableARCOptimizations &= !Args.hasArg(OPT_disable_arc_opts);
15651573
Opts.EnableOSSAModules |= Args.hasArg(OPT_enable_ossa_modules);
15661574
Opts.EnableOSSAOptimizations &= !Args.hasArg(OPT_disable_ossa_opts);

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
194194

195195
// Only issue weak lifetime warnings for users who select object lifetime
196196
// optimization. The risk of spurious warnings outweighs the benefits.
197-
if (P.getOptions().EnableCopyPropagation) {
197+
if (P.getOptions().CopyPropagation == CopyPropagationOption::On) {
198198
P.addDiagnoseLifetimeIssues();
199199
}
200-
200+
201201
P.addGlobalOpt();
202202
P.addPerformanceDiagnostics();
203203

@@ -412,7 +412,7 @@ void addFunctionPasses(SILPassPipelinePlan &P,
412412
if (P.getOptions().EnableOSSAModules) {
413413
// We earlier eliminated ownership if we are not compiling the stdlib. Now
414414
// handle the stdlib functions, re-simplifying, eliminating ARC as we do.
415-
if (!P.getOptions().DisableCopyPropagation) {
415+
if (P.getOptions().CopyPropagation != CopyPropagationOption::Off) {
416416
P.addCopyPropagation();
417417
}
418418
P.addSemanticARCOpts();
@@ -436,7 +436,7 @@ void addFunctionPasses(SILPassPipelinePlan &P,
436436

437437
// Clean up Semantic ARC before we perform additional post-inliner opts.
438438
if (P.getOptions().EnableOSSAModules) {
439-
if (!P.getOptions().DisableCopyPropagation) {
439+
if (P.getOptions().CopyPropagation != CopyPropagationOption::Off) {
440440
P.addCopyPropagation();
441441
}
442442
P.addSemanticARCOpts();
@@ -503,7 +503,7 @@ void addFunctionPasses(SILPassPipelinePlan &P,
503503

504504
// Run a final round of ARC opts when ownership is enabled.
505505
if (P.getOptions().EnableOSSAModules) {
506-
if (!P.getOptions().DisableCopyPropagation) {
506+
if (P.getOptions().CopyPropagation != CopyPropagationOption::Off) {
507507
P.addCopyPropagation();
508508
}
509509
P.addSemanticARCOpts();
@@ -539,7 +539,7 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
539539
// Cleanup after SILGen: remove trivial copies to temporaries.
540540
P.addTempRValueOpt();
541541
// Cleanup after SILGen: remove unneeded borrows/copies.
542-
if (P.getOptions().EnableCopyPropagation) {
542+
if (P.getOptions().CopyPropagation == CopyPropagationOption::On) {
543543
P.addCopyPropagation();
544544
}
545545
P.addSemanticARCOpts();
@@ -863,7 +863,7 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
863863
// Run one last copy propagation/semantic arc opts run before serialization/us
864864
// lowering ownership.
865865
if (P.getOptions().EnableOSSAModules) {
866-
if (!P.getOptions().DisableCopyPropagation) {
866+
if (P.getOptions().CopyPropagation != CopyPropagationOption::Off) {
867867
P.addCopyPropagation();
868868
}
869869
P.addSemanticARCOpts();
@@ -915,7 +915,7 @@ SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
915915
P.startPipeline("non-Diagnostic Enabling Mandatory Optimizations");
916916
P.addForEachLoopUnroll();
917917
P.addMandatoryCombine();
918-
if (P.getOptions().EnableCopyPropagation) {
918+
if (P.getOptions().CopyPropagation == CopyPropagationOption::On) {
919919
// MandatoryCopyPropagation should only be run at -Onone, not -O.
920920
P.addMandatoryCopyPropagation();
921921
}

lib/SILOptimizer/SILCombiner/SILCombine.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,11 @@ class SILCombine : public SILFunctionTransform {
537537
auto *CHA = PM->getAnalysis<ClassHierarchyAnalysis>();
538538
auto *NLABA = PM->getAnalysis<NonLocalAccessBlockAnalysis>();
539539

540-
bool enableCopyPropagation = getOptions().EnableCopyPropagation;
540+
bool enableCopyPropagation =
541+
getOptions().CopyPropagation == CopyPropagationOption::On;
541542
if (getOptions().EnableOSSAModules) {
542-
enableCopyPropagation = !getOptions().DisableCopyPropagation;
543+
enableCopyPropagation =
544+
getOptions().CopyPropagation != CopyPropagationOption::Off;
543545
}
544546

545547
SILOptFunctionBuilder FuncBuilder(*this);

tools/sil-opt/SILOpt.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,14 @@ int main(int argc, char **argv) {
529529
fprintf(stderr, "Error! Cannot specify both -enable-copy-propagation "
530530
"and -disable-copy-propagation.");
531531
exit(-1);
532+
} else if (EnableCopyPropagation && !DisableCopyPropagation) {
533+
SILOpts.CopyPropagation = CopyPropagationOption::On;
534+
} else if (!EnableCopyPropagation && DisableCopyPropagation) {
535+
SILOpts.CopyPropagation = CopyPropagationOption::Off;
536+
} else /*if (!EnableCopyPropagation && !DisableCopyPropagation)*/ {
537+
SILOpts.CopyPropagation = CopyPropagationOption::RequestedPassesOnly;
532538
}
533539

534-
SILOpts.EnableCopyPropagation = EnableCopyPropagation;
535-
SILOpts.DisableCopyPropagation = DisableCopyPropagation;
536-
537540
if (EnableCopyPropagation)
538541
SILOpts.LexicalLifetimes = LexicalLifetimesOption::On;
539542
if (DisableCopyPropagation)

0 commit comments

Comments
 (0)