Skip to content

Commit e40581a

Browse files
committed
[MoveChecker] Visit and delete markers in PO.
Visit in post-order in order to resolve markers from the inside out, required for per-field consume.
1 parent fb0ae6e commit e40581a

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerTester.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class MoveOnlyAddressCheckerTesterPass : public SILFunctionTransform {
9494
llvm::SmallSetVector<MarkUnresolvedNonCopyableValueInst *, 32>
9595
moveIntroducersToProcess;
9696
searchForCandidateAddressMarkUnresolvedNonCopyableValueInsts(
97-
fn, moveIntroducersToProcess, diagnosticEmitter);
97+
fn, getAnalysis<PostOrderAnalysis>(), moveIntroducersToProcess,
98+
diagnosticEmitter);
9899

99100
LLVM_DEBUG(llvm::dbgs()
100101
<< "Emitting diagnostic when checking for mark must check inst: "

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,14 @@ static bool isCopyableValue(SILValue value) {
479479

480480
void swift::siloptimizer::
481481
searchForCandidateAddressMarkUnresolvedNonCopyableValueInsts(
482-
SILFunction *fn,
482+
SILFunction *fn, PostOrderAnalysis *poa,
483483
llvm::SmallSetVector<MarkUnresolvedNonCopyableValueInst *, 32>
484484
&moveIntroducersToProcess,
485485
DiagnosticEmitter &diagnosticEmitter) {
486-
for (auto &block : *fn) {
487-
for (auto ii = block.begin(), ie = block.end(); ii != ie;) {
488-
auto *mmci = dyn_cast<MarkUnresolvedNonCopyableValueInst>(&*ii);
489-
++ii;
486+
auto *po = poa->get(fn);
487+
for (auto *block : po->getPostOrder()) {
488+
for (auto &ii : llvm::make_range(block->rbegin(), block->rend())) {
489+
auto *mmci = dyn_cast<MarkUnresolvedNonCopyableValueInst>(&ii);
490490

491491
if (!mmci || !mmci->hasMoveCheckerKind() || !mmci->getType().isAddress())
492492
continue;
@@ -3877,6 +3877,9 @@ bool MoveOnlyAddressChecker::check(
38773877
// If we fail the address check in some way, set the diagnose!
38783878
diagnosticEmitter.emitCheckerDoesntUnderstandDiagnostic(markedValue);
38793879
}
3880+
3881+
markedValue->replaceAllUsesWith(markedValue->getOperand());
3882+
markedValue->eraseFromParent();
38803883
}
38813884

38823885
if (DumpSILBeforeRemovingMarkUnresolvedNonCopyableValueInst) {

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace swift {
1919

20+
class PostOrderAnalysis;
21+
2022
namespace siloptimizer {
2123

2224
class DiagnosticEmitter;
@@ -26,7 +28,7 @@ class DiagnosticEmitter;
2628
/// NOTE: To see if we emitted a diagnostic, use \p
2729
/// diagnosticEmitter.getDiagnosticCount().
2830
void searchForCandidateAddressMarkUnresolvedNonCopyableValueInsts(
29-
SILFunction *fn,
31+
SILFunction *fn, PostOrderAnalysis *poa,
3032
llvm::SmallSetVector<MarkUnresolvedNonCopyableValueInst *, 32>
3133
&moveIntroducersToProcess,
3234
DiagnosticEmitter &diagnosticEmitter);

lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void MoveOnlyChecker::checkAddresses() {
186186
llvm::SmallSetVector<MarkUnresolvedNonCopyableValueInst *, 32>
187187
moveIntroducersToProcess;
188188
searchForCandidateAddressMarkUnresolvedNonCopyableValueInsts(
189-
fn, moveIntroducersToProcess, diagnosticEmitter);
189+
fn, poa, moveIntroducersToProcess, diagnosticEmitter);
190190

191191
LLVM_DEBUG(
192192
llvm::dbgs()

lib/SILOptimizer/Mandatory/MoveOnlyTempAllocationFromLetTester.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ struct MoveOnlyTempAllocationFromLetTester : SILFunctionTransform {
5151

5252
unsigned diagCount = diagnosticEmitter.getDiagnosticCount();
5353
searchForCandidateAddressMarkUnresolvedNonCopyableValueInsts(
54-
getFunction(), moveIntroducersToProcess, diagnosticEmitter);
54+
getFunction(), getAnalysis<PostOrderAnalysis>(),
55+
moveIntroducersToProcess, diagnosticEmitter);
5556

5657
// Return early if we emitted a diagnostic.
5758
if (diagCount != diagnosticEmitter.getDiagnosticCount())

test/Interop/Cxx/operators/move-only/move-only-synthesized-property-typecheck.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ func testNonCopyableHolderConstDerefPointee() {
3030
holder.pointee.mutMethod(1) // expected-error {{cannot use mutating member on immutable value: 'pointee' is a get-only property}}
3131
holder.pointee.x = 2 // expected-error {{cannot assign to property: 'pointee' is a get-only property}}
3232
#else
33-
consumingNC(holder.pointee) // CHECK: [[@LINE]]:{{.*}}: error:
34-
let consumeVal = holder.pointee // CHECK: [[@LINE]]:{{.*}}: error:
33+
consumingNC(holder.pointee) // CHECK-DAG: [[@LINE]]:{{.*}}: error:
34+
let consumeVal = holder.pointee // CHECK-DAG: [[@LINE]]:{{.*}}: error:
3535
#endif
3636
}
3737

0 commit comments

Comments
 (0)