Skip to content

Commit 39d68a1

Browse files
authored
Merge pull request #63267 from gottesmm/pr-54d720292aaf2996aea7f3288ebd7b911725d323
[consume-operator] Rename checker passes to have ConsumeOperator in the name to reduce confusion with MoveChecking passes.
2 parents 5b662d8 + 3a53828 commit 39d68a1

14 files changed

+56
-60
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,18 +440,16 @@ PASS(MoveOnlyObjectChecker, "sil-move-only-object-checker",
440440
"Pass that enforces move only invariants on raw SIL for objects")
441441
PASS(MoveOnlyAddressChecker, "sil-move-only-address-checker",
442442
"Pass that enforces move only invariants on raw SIL for addresses")
443-
PASS(MoveKillsCopyableValuesChecker, "sil-move-kills-copyable-values-checker",
444-
"Pass that checks that any copyable (non-move only) value that is passed "
445-
"to _move do not have any uses later than the _move")
443+
PASS(ConsumeOperatorCopyableValuesChecker, "sil-consume-operator-copyable-values-checker",
444+
"Pass that performs checking of the consume operator for copyable values")
446445
PASS(TrivialMoveOnlyTypeEliminator, "sil-trivial-move-only-type-eliminator",
447446
"Pass that rewrites SIL to remove move only types from values of trivial type")
448447
PASS(MoveOnlyTypeEliminator, "sil-move-only-type-eliminator",
449448
"Pass that rewrites SIL to remove move only types from all values")
450449
PASS(LexicalLifetimeEliminator, "sil-lexical-lifetime-eliminator",
451450
"Pass that removes lexical lifetime markers from borrows and alloc stack")
452-
PASS(MoveKillsCopyableAddressesChecker, "sil-move-kills-copyable-addresses-checker",
453-
"Pass that checks that any copyable (non-move only) address that is passed "
454-
"to _move do not have any uses later than the _move")
451+
PASS(ConsumeOperatorCopyableAddressesChecker, "sil-consume-operator-copyable-addresses-checker",
452+
"Pass that performs consume operator checking for copyable addresses")
455453
PASS(DebugInfoCanonicalizer, "sil-onone-debuginfo-canonicalizer",
456454
"Canonicalize debug info at -Onone by propagating debug info into coroutine funclets")
457455
PASS(PartialApplySimplification, "partial-apply-simplification",

lib/SILOptimizer/Mandatory/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ target_sources(swiftSILOptimizer PRIVATE
44
AddressLowering.cpp
55
CapturePromotion.cpp
66
ClosureLifetimeFixup.cpp
7+
ConsumeOperatorCopyableAddressesChecker.cpp
8+
ConsumeOperatorCopyableValuesChecker.cpp
79
PhiStorageOptimizer.cpp
810
ConstantPropagation.cpp
911
DebugInfoCanonicalizer.cpp
@@ -22,8 +24,6 @@ target_sources(swiftSILOptimizer PRIVATE
2224
LowerHopToActor.cpp
2325
MandatoryInlining.cpp
2426
MovedAsyncVarDebugInfoPropagator.cpp
25-
MoveKillsCopyableAddressesChecker.cpp
26-
MoveKillsCopyableValuesChecker.cpp
2727
MoveOnlyAddressChecker.cpp
2828
MoveOnlyBorrowToDestructureTransform.cpp
2929
MoveOnlyDeinitInsertion.cpp

lib/SILOptimizer/Mandatory/MoveKillsCopyableAddressesChecker.cpp renamed to lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- MoveKillsCopyableAddressesChecker.cpp ----------------------------===//
1+
//===--- ConsumeOperatorCopyableAddressChecker.cpp ------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -133,7 +133,7 @@
133133
///
134134
//===----------------------------------------------------------------------===//
135135

136-
#define DEBUG_TYPE "sil-move-kills-copyable-addresses-checker"
136+
#define DEBUG_TYPE "sil-consume-operator-copyable-addresses-checker"
137137

138138
#include "swift/AST/DiagnosticsSIL.h"
139139
#include "swift/AST/Types.h"
@@ -171,8 +171,8 @@
171171

172172
using namespace swift;
173173

174-
static llvm::cl::opt<bool>
175-
DisableUnhandledMoveDiagnostic("sil-disable-unknown-moveaddr-diagnostic");
174+
static llvm::cl::opt<bool> DisableUnhandledConsumeOperator(
175+
"sil-consume-operator-disable-unknown-moveaddr-diagnostic");
176176

177177
//===----------------------------------------------------------------------===//
178178
// Utilities
@@ -245,9 +245,7 @@ struct ClosureOperandState {
245245
/// points.
246246
DebugValueInst *singleDebugValue = nullptr;
247247

248-
bool isUpwardsUse() const {
249-
return result == DownwardScanResult::ClosureUse;
250-
}
248+
bool isUpwardsUse() const { return result == DownwardScanResult::ClosureUse; }
251249

252250
bool isUpwardsConsume() const {
253251
return result == DownwardScanResult::ClosureConsume;
@@ -1552,9 +1550,9 @@ bool DataflowState::cleanupAllDestroyAddr(
15521550
// be defined before the value.
15531551
SILBuilderWithScope reinitBuilder((*reinit)->getNextInstruction());
15541552
reinitBuilder.setCurrentDebugScope(addressDebugInst->getDebugScope());
1555-
reinitBuilder.createDebugValue(
1556-
addressDebugInst.inst->getLoc(), address, *varInfo, false,
1557-
/*was moved*/ true);
1553+
reinitBuilder.createDebugValue(addressDebugInst.inst->getLoc(), address,
1554+
*varInfo, false,
1555+
/*was moved*/ true);
15581556
}
15591557
}
15601558
madeChange = true;
@@ -1914,7 +1912,7 @@ void DataflowState::init() {
19141912

19151913
namespace {
19161914

1917-
struct MoveKillsCopyableAddressesChecker {
1915+
struct ConsumeOperatorCopyableAddressesChecker {
19181916
SILFunction *fn;
19191917
UseState useState;
19201918
DataflowState dataflowState;
@@ -1924,8 +1922,8 @@ struct MoveKillsCopyableAddressesChecker {
19241922
applySiteToPromotedArgIndices;
19251923
SmallBlotSetVector<SILInstruction *, 8> closureConsumes;
19261924

1927-
MoveKillsCopyableAddressesChecker(SILFunction *fn,
1928-
SILOptFunctionBuilder &funcBuilder)
1925+
ConsumeOperatorCopyableAddressesChecker(SILFunction *fn,
1926+
SILOptFunctionBuilder &funcBuilder)
19291927
: fn(fn), useState(),
19301928
dataflowState(funcBuilder, useState, applySiteToPromotedArgIndices,
19311929
closureConsumes),
@@ -1951,7 +1949,7 @@ struct MoveKillsCopyableAddressesChecker {
19511949

19521950
} // namespace
19531951

1954-
void MoveKillsCopyableAddressesChecker::cloneDeferCalleeAndRewriteUses(
1952+
void ConsumeOperatorCopyableAddressesChecker::cloneDeferCalleeAndRewriteUses(
19551953
SmallVectorImpl<SILValue> &newArgs, const SmallBitVector &bitVector,
19561954
FullApplySite oldApplySite,
19571955
SmallBlotSetVector<SILInstruction *, 8> &postDominatingConsumingUsers) {
@@ -2012,7 +2010,7 @@ void MoveKillsCopyableAddressesChecker::cloneDeferCalleeAndRewriteUses(
20122010
oldApplySite->eraseFromParent();
20132011
}
20142012

2015-
bool MoveKillsCopyableAddressesChecker::performClosureDataflow(
2013+
bool ConsumeOperatorCopyableAddressesChecker::performClosureDataflow(
20162014
Operand *callerOperand, ClosureOperandState &calleeOperandState) {
20172015
auto fas = FullApplySite::isa(callerOperand->getUser());
20182016
auto *func = fas.getCalleeFunction();
@@ -2060,7 +2058,7 @@ bool MoveKillsCopyableAddressesChecker::performClosureDataflow(
20602058
// Returns true if we emitted a diagnostic and handled the single block
20612059
// case. Returns false if we visited all of the uses and seeded the UseState
20622060
// struct with the information needed to perform our interprocedural dataflow.
2063-
bool MoveKillsCopyableAddressesChecker::performSingleBasicBlockAnalysis(
2061+
bool ConsumeOperatorCopyableAddressesChecker::performSingleBasicBlockAnalysis(
20642062
SILValue address, DebugVarCarryingInst addressDebugInst,
20652063
MarkUnresolvedMoveAddrInst *mvi) {
20662064
// First scan downwards to make sure we are move out of this block.
@@ -2215,8 +2213,8 @@ bool MoveKillsCopyableAddressesChecker::performSingleBasicBlockAnalysis(
22152213
auto *next = interestingUser->getNextInstruction();
22162214
SILBuilderWithScope reinitBuilder(next);
22172215
reinitBuilder.setCurrentDebugScope(addressDebugInst->getDebugScope());
2218-
reinitBuilder.createDebugValue(addressDebugInst->getLoc(),
2219-
address, *varInfo, false,
2216+
reinitBuilder.createDebugValue(addressDebugInst->getLoc(), address,
2217+
*varInfo, false,
22202218
/*was moved*/ true);
22212219
}
22222220
}
@@ -2287,7 +2285,7 @@ bool MoveKillsCopyableAddressesChecker::performSingleBasicBlockAnalysis(
22872285
return false;
22882286
}
22892287

2290-
bool MoveKillsCopyableAddressesChecker::check(SILValue address) {
2288+
bool ConsumeOperatorCopyableAddressesChecker::check(SILValue address) {
22912289
auto accessPathWithBase = AccessPathWithBase::compute(address);
22922290
auto accessPath = accessPathWithBase.accessPath;
22932291

@@ -2384,8 +2382,8 @@ bool MoveKillsCopyableAddressesChecker::check(SILValue address) {
23842382
// Ok, we need to perform global dataflow for one of our moves. Initialize our
23852383
// dataflow state engine and then run the dataflow itself.
23862384
dataflowState.init();
2387-
bool result = dataflowState.process(
2388-
address, addressDebugInst, closureConsumes);
2385+
bool result =
2386+
dataflowState.process(address, addressDebugInst, closureConsumes);
23892387
return result;
23902388
}
23912389

@@ -2395,7 +2393,8 @@ bool MoveKillsCopyableAddressesChecker::check(SILValue address) {
23952393

23962394
namespace {
23972395

2398-
class MoveKillsCopyableAddressesCheckerPass : public SILFunctionTransform {
2396+
class ConsumeOperatorCopyableAddressesCheckerPass
2397+
: public SILFunctionTransform {
23992398
void run() override {
24002399
auto *fn = getFunction();
24012400
auto &astContext = fn->getASTContext();
@@ -2442,7 +2441,7 @@ class MoveKillsCopyableAddressesCheckerPass : public SILFunctionTransform {
24422441

24432442
SILOptFunctionBuilder funcBuilder(*this);
24442443

2445-
MoveKillsCopyableAddressesChecker checker(getFunction(), funcBuilder);
2444+
ConsumeOperatorCopyableAddressesChecker checker(getFunction(), funcBuilder);
24462445

24472446
bool madeChange = false;
24482447
while (!addressToProcess.empty()) {
@@ -2481,7 +2480,7 @@ class MoveKillsCopyableAddressesCheckerPass : public SILFunctionTransform {
24812480
// uses have been resolved appropriately.
24822481
//
24832482
// TODO: Emit specific diagnostics here (e.x.: _move of global).
2484-
if (DisableUnhandledMoveDiagnostic)
2483+
if (DisableUnhandledConsumeOperator)
24852484
return;
24862485

24872486
bool lateMadeChange = false;
@@ -2513,6 +2512,6 @@ class MoveKillsCopyableAddressesCheckerPass : public SILFunctionTransform {
25132512

25142513
} // anonymous namespace
25152514

2516-
SILTransform *swift::createMoveKillsCopyableAddressesChecker() {
2517-
return new MoveKillsCopyableAddressesCheckerPass();
2515+
SILTransform *swift::createConsumeOperatorCopyableAddressesChecker() {
2516+
return new ConsumeOperatorCopyableAddressesCheckerPass();
25182517
}

lib/SILOptimizer/Mandatory/MoveKillsCopyableValuesChecker.cpp renamed to lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableValuesChecker.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- MoveKillsCopyableValuesChecker.cpp -------------------------------===//
1+
//===--- ConsumeOperatorCopyableValuesChecker.cpp -------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#define DEBUG_TYPE "sil-move-kills-copyable-values-checker"
13+
#define DEBUG_TYPE "sil-consume-operator-copyable-values-checker"
1414

1515
#include "swift/AST/DiagnosticsSIL.h"
1616
#include "swift/Basic/Defer.h"
@@ -34,8 +34,8 @@
3434

3535
using namespace swift;
3636

37-
static llvm::cl::opt<bool>
38-
DisableUnhandledMoveDiagnostic("sil-disable-unknown-move-diagnostic");
37+
static llvm::cl::opt<bool> DisableUnhandledMoveDiagnostic(
38+
"sil-consume-operator-disable-unknown-move-diagnostic");
3939

4040
//===----------------------------------------------------------------------===//
4141
// Diagnostic Utilities
@@ -152,8 +152,8 @@ bool CheckerLivenessInfo::compute() {
152152
// Otherwise, try to update liveness for a borrowing operand
153153
// use. This will make it so that we add the end_borrows of the
154154
// liveness use. If we have a reborrow here, we will bail.
155-
if (liveness.updateForBorrowingOperand(use)
156-
!= InnerBorrowKind::Contained) {
155+
if (liveness.updateForBorrowingOperand(use) !=
156+
InnerBorrowKind::Contained) {
157157
return false;
158158
}
159159
}
@@ -213,13 +213,13 @@ bool CheckerLivenessInfo::compute() {
213213

214214
namespace {
215215

216-
struct MoveKillsCopyableValuesChecker {
216+
struct ConsumeOperatorCopyableValuesChecker {
217217
SILFunction *fn;
218218
CheckerLivenessInfo livenessInfo;
219219
DominanceInfo *dominanceToUpdate;
220220
SILLoopInfo *loopInfoToUpdate;
221221

222-
MoveKillsCopyableValuesChecker(SILFunction *fn)
222+
ConsumeOperatorCopyableValuesChecker(SILFunction *fn)
223223
: fn(fn), livenessInfo(), dominanceToUpdate(nullptr),
224224
loopInfoToUpdate(nullptr) {}
225225

@@ -245,7 +245,7 @@ static SourceLoc getSourceLocFromValue(SILValue value) {
245245
llvm_unreachable("Do not know how to get source loc for value?!");
246246
}
247247

248-
void MoveKillsCopyableValuesChecker::emitDiagnosticForMove(
248+
void ConsumeOperatorCopyableValuesChecker::emitDiagnosticForMove(
249249
SILValue borrowedValue, StringRef borrowedValueName, MoveValueInst *mvi) {
250250
auto &astContext = fn->getASTContext();
251251

@@ -399,7 +399,7 @@ void MoveKillsCopyableValuesChecker::emitDiagnosticForMove(
399399
}
400400
}
401401

402-
bool MoveKillsCopyableValuesChecker::check() {
402+
bool ConsumeOperatorCopyableValuesChecker::check() {
403403
SmallSetVector<SILValue, 32> valuesToCheck;
404404

405405
for (auto *arg : fn->getEntryBlock()->getSILFunctionArguments()) {
@@ -511,8 +511,7 @@ bool MoveKillsCopyableValuesChecker::check() {
511511

512512
static void emitUnsupportedUseCaseError(MoveValueInst *mvi) {
513513
auto &astContext = mvi->getModule().getASTContext();
514-
auto diag = diag::
515-
sil_movekillscopyablevalue_move_applied_to_unsupported_move;
514+
auto diag = diag::sil_movekillscopyablevalue_move_applied_to_unsupported_move;
516515
diagnose(astContext, mvi->getLoc().getSourceLoc(), diag);
517516
mvi->setAllowsDiagnostics(false);
518517
}
@@ -523,7 +522,7 @@ static void emitUnsupportedUseCaseError(MoveValueInst *mvi) {
523522

524523
namespace {
525524

526-
class MoveKillsCopyableValuesCheckerPass : public SILFunctionTransform {
525+
class ConsumeOperatorCopyableValuesCheckerPass : public SILFunctionTransform {
527526
void run() override {
528527
auto *fn = getFunction();
529528

@@ -541,7 +540,7 @@ class MoveKillsCopyableValuesCheckerPass : public SILFunctionTransform {
541540
LLVM_DEBUG(llvm::dbgs() << "*** Checking moved values in fn: "
542541
<< getFunction()->getName() << '\n');
543542

544-
MoveKillsCopyableValuesChecker checker(getFunction());
543+
ConsumeOperatorCopyableValuesChecker checker(getFunction());
545544

546545
// If we already had dominance or loop info generated, update them when
547546
// splitting blocks.
@@ -590,6 +589,6 @@ class MoveKillsCopyableValuesCheckerPass : public SILFunctionTransform {
590589

591590
} // anonymous namespace
592591

593-
SILTransform *swift::createMoveKillsCopyableValuesChecker() {
594-
return new MoveKillsCopyableValuesCheckerPass();
592+
SILTransform *swift::createConsumeOperatorCopyableValuesChecker() {
593+
return new ConsumeOperatorCopyableValuesCheckerPass();
595594
}

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
162162
P.addMoveOnlyDeinitInsertion();
163163
// Lower move only wrapped trivial types.
164164
P.addTrivialMoveOnlyTypeEliminator();
165-
// Check no uses after _move of a value in an address.
166-
P.addMoveKillsCopyableAddressesChecker();
167-
// No uses after _move of copyable value.
168-
P.addMoveKillsCopyableValuesChecker();
165+
// Check no uses after consume operator of a value in an address.
166+
P.addConsumeOperatorCopyableAddressesChecker();
167+
// No uses after consume operator of copyable value.
168+
P.addConsumeOperatorCopyableValuesChecker();
169169

170170
//
171171
// End Ownership Optimizations

test/SILOptimizer/move_function_kills_addresses_dbginfo.sil renamed to test/SILOptimizer/consume_operator_kills_addresses_dbginfo.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt %s -enable-experimental-move-only -sil-move-kills-copyable-addresses-checker | %FileCheck %s
1+
// RUN: %target-sil-opt %s -enable-experimental-move-only -sil-consume-operator-copyable-addresses-checker | %FileCheck %s
22

33
// REQUIRES: optimized_stdlib
44

@@ -152,4 +152,4 @@ bb3:
152152
hop_to_executor %2 : $Optional<Builtin.Executor>
153153
%47 = tuple ()
154154
return %47 : $()
155-
}
155+
}

test/SILOptimizer/move_function_kills_copyable_addresses.sil renamed to test/SILOptimizer/consume_operator_kills_copyable_addresses.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-experimental-move-only -enable-sil-verify-all -o - -sil-move-kills-copyable-addresses-checker -verify %s
1+
// RUN: %target-sil-opt -enable-experimental-move-only -enable-sil-verify-all -o - -sil-consume-operator-copyable-addresses-checker -verify %s
22

33
// This file is meant for specific SIL patterns that may be hard to produce with
44
// the current swift frontend but have reproduced before and we want to make
@@ -36,4 +36,4 @@ bb0(%0 : @owned $Klass):
3636
destroy_value %0 : $Klass
3737
%23 = tuple ()
3838
return %23 : $()
39-
}
39+
}

test/SILOptimizer/move_function_kills_copyable_values.sil renamed to test/SILOptimizer/consume_operator_kills_copyable_values.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-experimental-move-only -enable-sil-verify-all -o - -sil-move-kills-copyable-values-checker -verify %s
1+
// RUN: %target-sil-opt -enable-experimental-move-only -enable-sil-verify-all -o - -sil-consume-operator-copyable-values-checker -verify %s
22

33
// This file is meant for specific SIL patterns that may be hard to produce with
44
// the current swift frontend but have reproduced before and we want to make

test/SILOptimizer/move_function_kills_values_dbginfo.sil renamed to test/SILOptimizer/consume_operator_kills_values_dbginfo.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt %s -enable-experimental-move-only -sil-move-kills-copyable-values-checker | %FileCheck %s
1+
// RUN: %target-sil-opt %s -enable-experimental-move-only -sil-consume-operator-copyable-values-checker | %FileCheck %s
22

33
// REQUIRES: optimized_stdlib
44

0 commit comments

Comments
 (0)