Skip to content

Commit b689b1d

Browse files
committed
Rename GuaranteedARCOpts to MandatoryARCOpts.
This bleeds into the implementation where "guaranteed" is used everywhere to talk about optimization of guaranteed values. We need to use mandatory to indicate we're talking about the pass pipeline.
1 parent cb1ed89 commit b689b1d

File tree

14 files changed

+36
-35
lines changed

14 files changed

+36
-35
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ PASS(GlobalOpt, "global-opt",
202202
"SIL Global Optimization")
203203
PASS(GlobalPropertyOpt, "global-property-opt",
204204
"Global Property Optimization")
205-
PASS(GuaranteedARCOpts, "guaranteed-arc-opts",
206-
"Guaranteed ARC Optimization")
205+
PASS(MandatoryARCOpts, "mandatory-arc-opts",
206+
"Mandatory ARC Optimization")
207207
PASS(HighLevelCSE, "high-level-cse",
208208
"Common Subexpression Elimination on High-Level SIL")
209209
PASS(HighLevelLICM, "high-level-licm",

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,9 @@ SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
837837
P.addMandatoryCombine();
838838
// MandatoryCopyPropagation should only be run at -Onone, not -O.
839839
P.addMandatoryCopyPropagation();
840-
// TODO: GuaranteedARCOpts should be subsumed by CopyPropagation. There should
840+
// TODO: MandatoryARCOpts should be subsumed by CopyPropagation. There should
841841
// be no need to run another analysis of copies at -Onone.
842-
P.addGuaranteedARCOpts();
842+
P.addMandatoryARCOpts();
843843

844844
// First serialize the SIL if we are asked to.
845845
P.startPipeline("Serialization");

lib/SILOptimizer/SemanticARC/Context.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct LLVM_LIBRARY_VISIBILITY Context {
109109
/// As an example, we do not do load [copy] optimizations here since they
110110
/// generally involve more complex analysis, but simple peepholes of
111111
/// copy_values we /do/ allow.
112-
bool onlyGuaranteedOpts;
112+
bool onlyMandatoryOpts;
113113

114114
/// Callbacks that we must use to remove or RAUW values.
115115
InstModCallbacks instModCallbacks;
@@ -119,11 +119,11 @@ struct LLVM_LIBRARY_VISIBILITY Context {
119119

120120
DeadEndBlocks &getDeadEndBlocks() { return deadEndBlocks; }
121121

122-
Context(SILFunction &fn, DeadEndBlocks &deBlocks, bool onlyGuaranteedOpts,
122+
Context(SILFunction &fn, DeadEndBlocks &deBlocks, bool onlyMandatoryOpts,
123123
InstModCallbacks callbacks)
124124
: fn(fn), deadEndBlocks(deBlocks), lifetimeFrontier(),
125125
addressToExhaustiveWriteListCache(constructCacheValue),
126-
onlyGuaranteedOpts(onlyGuaranteedOpts), instModCallbacks(callbacks) {}
126+
onlyMandatoryOpts(onlyMandatoryOpts), instModCallbacks(callbacks) {}
127127

128128
void verify() const;
129129

lib/SILOptimizer/SemanticARC/CopyValueOpts.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,11 @@ using namespace swift::semanticarc;
6666
// are within the borrow scope.
6767
//
6868
// TODO: This needs a better name.
69-
//
70-
// FIXME: CanonicalizeOSSALifetime replaces this once it supports borrows.
7169
bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(
7270
CopyValueInst *cvi) {
73-
// For now, do not run this optimization. This is just to be careful.
74-
if (ctx.onlyGuaranteedOpts)
71+
// All mandatory copy optimization is handled by CanonicalizeOSSALifetime,
72+
// which knows how to preserve lifetimes for debugging.
73+
if (ctx.onlyMandatoryOpts)
7574
return false;
7675

7776
SmallVector<BorrowedValue, 4> borrowScopeIntroducers;
@@ -721,11 +720,11 @@ bool SemanticARCOptVisitor::tryJoiningCopyValueLiveRangeWithOperand(
721720

722721
/// Given an owned value that is completely enclosed within its parent owned
723722
/// value and is not consumed, eliminate the copy.
724-
///
725-
/// FIXME: CanonicalizeOSSALifetime replaces this.
726723
bool SemanticARCOptVisitor::tryPerformOwnedCopyValueOptimization(
727724
CopyValueInst *cvi) {
728-
if (ctx.onlyGuaranteedOpts)
725+
// All mandatory copy optimization is handled by CanonicalizeOSSALifetime,
726+
// which knows how to preserve lifetimes for debugging.
727+
if (ctx.onlyMandatoryOpts)
729728
return false;
730729

731730
auto originalValue = cvi->getOperand();

lib/SILOptimizer/SemanticARC/LoadCopyToLoadBorrowOpt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static bool isWrittenTo(Context &ctx, LoadInst *load,
321321
bool SemanticARCOptVisitor::visitLoadInst(LoadInst *li) {
322322
// This optimization can use more complex analysis. We should do some
323323
// experiments before enabling this by default as a guaranteed optimization.
324-
if (ctx.onlyGuaranteedOpts)
324+
if (ctx.onlyMandatoryOpts)
325325
return false;
326326

327327
// If we are not supposed to perform this transform, bail.

lib/SILOptimizer/SemanticARC/OwnershipConversionElimination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using namespace semanticarc;
2424
bool SemanticARCOptVisitor::visitUncheckedOwnershipConversionInst(
2525
UncheckedOwnershipConversionInst *uoci) {
2626
// Return false if we are supposed to only be running guaranteed opts.
27-
if (ctx.onlyGuaranteedOpts)
27+
if (ctx.onlyMandatoryOpts)
2828
return false;
2929

3030
// Then check if we are running tests and shouldn't perform this optimization

lib/SILOptimizer/SemanticARC/SemanticARCOptVisitor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ struct LLVM_LIBRARY_VISIBILITY SemanticARCOptVisitor
5050
Context ctx;
5151

5252
explicit SemanticARCOptVisitor(SILFunction &fn, DeadEndBlocks &deBlocks,
53-
bool onlyGuaranteedOpts)
54-
: ctx(fn, deBlocks, onlyGuaranteedOpts,
53+
bool onlyMandatoryOpts)
54+
: ctx(fn, deBlocks, onlyMandatoryOpts,
5555
InstModCallbacks(
5656
[this](SILInstruction *inst) { eraseInstruction(inst); },
5757
[this](Operand *use, SILValue newValue) {

lib/SILOptimizer/SemanticARC/SemanticARCOpts.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ namespace {
6666
// case DiagnosticConstantPropagation exposed anything new in this assert
6767
// configuration.
6868
struct SemanticARCOpts : SILFunctionTransform {
69-
bool guaranteedOptsOnly;
69+
bool mandatoryOptsOnly;
7070

71-
SemanticARCOpts(bool guaranteedOptsOnly)
72-
: guaranteedOptsOnly(guaranteedOptsOnly) {}
71+
SemanticARCOpts(bool mandatoryOptsOnly)
72+
: mandatoryOptsOnly(mandatoryOptsOnly) {}
7373

7474
#ifndef NDEBUG
7575
void performCommandlineSpecifiedTransforms(SemanticARCOptVisitor &visitor) {
@@ -153,7 +153,7 @@ struct SemanticARCOpts : SILFunctionTransform {
153153

154154
auto *deBlocksAnalysis = getAnalysis<DeadEndBlocksAnalysis>();
155155
SemanticARCOptVisitor visitor(f, *deBlocksAnalysis->get(&f),
156-
guaranteedOptsOnly);
156+
mandatoryOptsOnly);
157157

158158
#ifndef NDEBUG
159159
// If we are being asked for testing purposes to run a series of transforms
@@ -185,9 +185,9 @@ struct SemanticARCOpts : SILFunctionTransform {
185185
} // end anonymous namespace
186186

187187
SILTransform *swift::createSemanticARCOpts() {
188-
return new SemanticARCOpts(false /*guaranteed*/);
188+
return new SemanticARCOpts(false /*mandatory*/);
189189
}
190190

191-
SILTransform *swift::createGuaranteedARCOpts() {
192-
return new SemanticARCOpts(true /*guaranteed*/);
191+
SILTransform *swift::createMandatoryARCOpts() {
192+
return new SemanticARCOpts(true /*mandatory*/);
193193
}

lib/SILOptimizer/Transforms/CopyPropagation.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ void CopyPropagation::run() {
135135
}
136136
}
137137

138-
SILTransform *swift::createCopyPropagation() {
139-
return new CopyPropagation(/*pruneDebug*/ true);
138+
SILTransform *swift::createMandatoryCopyPropagation() {
139+
return new CopyPropagation(/*pruneDebug*/ true, /*unownedRemnant*/ true,
140+
/*canonicalizeAll*/ true);
140141
}
141142

142-
SILTransform *swift::createMandatoryCopyPropagation() {
143-
return new CopyPropagation(/*pruneDebug*/ false);
143+
SILTransform *swift::createCopyPropagation() {
144+
return new CopyPropagation(/*pruneDebug*/ true, /*unownedRemnant*/ false,
145+
/*canonicalizeAll*/ false);
144146
}

test/IRGen/struct_resilience.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %empty-directory(%t)
33
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
44
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_enum.swiftmodule -module-name=resilient_enum -I %t %S/../Inputs/resilient_enum.swift
5-
// RUN: %target-swift-frontend -module-name struct_resilience -Xllvm -sil-disable-pass=GuaranteedARCOpts -I %t -emit-ir -enable-library-evolution %s | %FileCheck %s
5+
// RUN: %target-swift-frontend -module-name struct_resilience -Xllvm -sil-disable-pass=MandatoryARCOpts -I %t -emit-ir -enable-library-evolution %s | %FileCheck %s
66
// RUN: %target-swift-frontend -module-name struct_resilience -I %t -emit-ir -enable-library-evolution -O %s
77

88
import resilient_struct

0 commit comments

Comments
 (0)