Skip to content

Commit 874971c

Browse files
committed
[MoveOnlyAddressChecker] Complete lifetimes first.
It relies on complete lifetimes for its analysis. So if there are any instructions to check, complete all lifetimes in the function first.
1 parent 39b9616 commit 874971c

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerTester.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class MoveOnlyAddressCheckerTesterPass : public SILFunctionTransform {
109109
borrowtodestructure::IntervalMapAllocator allocator;
110110
MoveOnlyAddressChecker checker{getFunction(), diagnosticEmitter,
111111
allocator, domTree, poa};
112-
madeChange = checker.check(moveIntroducersToProcess);
112+
madeChange = checker.completeLifetimes();
113+
madeChange |= checker.check(moveIntroducersToProcess);
113114
}
114115

115116
// If we did not emit any diagnostics, emit a diagnostic if we missed any

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
#include "swift/SIL/FieldSensitivePrunedLiveness.h"
243243
#include "swift/SIL/InstructionUtils.h"
244244
#include "swift/SIL/MemAccessUtils.h"
245+
#include "swift/SIL/OSSALifetimeCompletion.h"
245246
#include "swift/SIL/OwnershipUtils.h"
246247
#include "swift/SIL/PrunedLiveness.h"
247248
#include "swift/SIL/SILArgument.h"
@@ -3986,3 +3987,29 @@ bool MoveOnlyAddressChecker::check(
39863987
}
39873988
return pimpl.changed;
39883989
}
3990+
bool MoveOnlyAddressChecker::completeLifetimes() {
3991+
// TODO: Delete once OSSALifetimeCompletion is run as part of SILGenCleanup
3992+
bool changed = false;
3993+
3994+
// Lifetimes must be completed inside out (bottom-up in the CFG).
3995+
PostOrderFunctionInfo *postOrder = poa->get(fn);
3996+
OSSALifetimeCompletion completion(fn, domTree);
3997+
for (auto *block : postOrder->getPostOrder()) {
3998+
for (SILInstruction &inst : reverse(*block)) {
3999+
for (auto result : inst.getResults()) {
4000+
if (completion.completeOSSALifetime(result) ==
4001+
LifetimeCompletion::WasCompleted) {
4002+
changed = true;
4003+
}
4004+
}
4005+
}
4006+
for (SILArgument *arg : block->getArguments()) {
4007+
assert(!arg->isReborrow() && "reborrows not legal at this SIL stage");
4008+
if (completion.completeOSSALifetime(arg) ==
4009+
LifetimeCompletion::WasCompleted) {
4010+
changed = true;
4011+
}
4012+
}
4013+
}
4014+
return changed;
4015+
}

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct MoveOnlyAddressChecker {
4444
/// \p diagnosticEmitter.getDiagnosticCount().
4545
bool check(llvm::SmallSetVector<MarkUnresolvedNonCopyableValueInst *, 32>
4646
&moveIntroducersToProcess);
47+
bool completeLifetimes();
4748
};
4849

4950
} // namespace siloptimizer

lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ void MoveOnlyChecker::checkAddresses() {
202202

203203
MoveOnlyAddressChecker checker{fn, diagnosticEmitter, allocator, domTree,
204204
poa};
205+
madeChange |= checker.completeLifetimes();
205206
madeChange |= checker.check(moveIntroducersToProcess);
206207
}
207208

0 commit comments

Comments
 (0)