Skip to content

6.0: [MoveOnlyAddressChecker] Exclusivity handles DeadEnds. #75408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class MoveOnlyAddressCheckerTesterPass : public SILFunctionTransform {
auto *dominanceAnalysis = getAnalysis<DominanceAnalysis>();
DominanceInfo *domTree = dominanceAnalysis->get(fn);
auto *poa = getAnalysis<PostOrderAnalysis>();
auto *deadEndBlocksAnalysis = getAnalysis<DeadEndBlocksAnalysis>();

DiagnosticEmitter diagnosticEmitter(fn);
llvm::SmallSetVector<MarkUnresolvedNonCopyableValueInst *, 32>
Expand All @@ -108,7 +109,8 @@ class MoveOnlyAddressCheckerTesterPass : public SILFunctionTransform {
} else {
borrowtodestructure::IntervalMapAllocator allocator;
MoveOnlyAddressChecker checker{getFunction(), diagnosticEmitter,
allocator, domTree, poa};
allocator, domTree,
poa, deadEndBlocksAnalysis};
madeChange = checker.completeLifetimes();
madeChange |= checker.check(moveIntroducersToProcess);
}
Expand Down
11 changes: 8 additions & 3 deletions lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,8 @@ struct MoveOnlyAddressCheckerPImpl {
/// Information about destroys that we use when inserting destroys.
ConsumeInfo consumes;

DeadEndBlocksAnalysis *deba;

/// PostOrderAnalysis used by the BorrowToDestructureTransform.
PostOrderAnalysis *poa;

Expand All @@ -1482,10 +1484,11 @@ struct MoveOnlyAddressCheckerPImpl {
MoveOnlyAddressCheckerPImpl(
SILFunction *fn, DiagnosticEmitter &diagnosticEmitter,
DominanceInfo *domTree, PostOrderAnalysis *poa,
DeadEndBlocksAnalysis *deba,
borrowtodestructure::IntervalMapAllocator &allocator)
: fn(fn), deleter(), canonicalizer(fn, domTree, deleter),
addressUseState(domTree), diagnosticEmitter(diagnosticEmitter),
poa(poa), allocator(allocator) {
deba(deba), poa(poa), allocator(allocator) {
deleter.setCallbacks(std::move(
InstModCallbacks().onDelete([&](SILInstruction *instToDelete) {
if (auto *mvi =
Expand Down Expand Up @@ -2045,7 +2048,9 @@ struct GatherUsesVisitor : public TransitiveAddressWalker<GatherUsesVisitor> {
liveness->initializeDef(bai);
liveness->computeSimple();
for (auto *consumingUse : li->getConsumingUses()) {
if (!liveness->isWithinBoundary(consumingUse->getUser())) {
if (!liveness->areUsesWithinBoundary(
{consumingUse},
moveChecker.deba->get(consumingUse->getFunction()))) {
diagnosticEmitter.emitAddressExclusivityHazardDiagnostic(
markedValue, consumingUse->getUser());
emittedError = true;
Expand Down Expand Up @@ -3976,7 +3981,7 @@ bool MoveOnlyAddressChecker::check(
assert(moveIntroducersToProcess.size() &&
"Must have checks to process to call this function");
MoveOnlyAddressCheckerPImpl pimpl(fn, diagnosticEmitter, domTree, poa,
allocator);
deadEndBlocksAnalysis, allocator);

#ifndef NDEBUG
static uint64_t numProcessed = 0;
Expand Down
2 changes: 2 additions & 0 deletions lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace swift {

class PostOrderAnalysis;
class DeadEndBlocksAnalysis;

namespace siloptimizer {

Expand All @@ -39,6 +40,7 @@ struct MoveOnlyAddressChecker {
borrowtodestructure::IntervalMapAllocator &allocator;
DominanceInfo *domTree;
PostOrderAnalysis *poa;
DeadEndBlocksAnalysis *deadEndBlocksAnalysis;

/// \returns true if we changed the IR. To see if we emitted a diagnostic, use
/// \p diagnosticEmitter.getDiagnosticCount().
Expand Down
16 changes: 8 additions & 8 deletions lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ struct MoveOnlyChecker {
SILFunction *fn;
DominanceInfo *domTree;
PostOrderAnalysis *poa;
DeadEndBlocksAnalysis *deba;
bool madeChange = false;
borrowtodestructure::IntervalMapAllocator allocator;

MoveOnlyChecker(SILFunction *fn, DominanceInfo *domTree,
PostOrderAnalysis *poa)
: diagnosticEmitter(fn), fn(fn), domTree(domTree), poa(poa) {
}
PostOrderAnalysis *poa, DeadEndBlocksAnalysis *deba)
: diagnosticEmitter(fn), fn(fn), domTree(domTree), poa(poa), deba(deba) {}

void checkObjects();
void completeObjectLifetimes(ArrayRef<MarkUnresolvedNonCopyableValueInst *>);
Expand Down Expand Up @@ -200,8 +200,8 @@ void MoveOnlyChecker::checkAddresses() {
return;
}

MoveOnlyAddressChecker checker{fn, diagnosticEmitter, allocator, domTree,
poa};
MoveOnlyAddressChecker checker{
fn, diagnosticEmitter, allocator, domTree, poa, deba};
madeChange |= checker.completeLifetimes();
madeChange |= checker.check(moveIntroducersToProcess);
}
Expand Down Expand Up @@ -253,9 +253,9 @@ class MoveOnlyCheckerPass : public SILFunctionTransform {
LLVM_DEBUG(llvm::dbgs()
<< "===> MoveOnly Checker. Visiting: " << fn->getName() << '\n');

MoveOnlyChecker checker(
fn, getAnalysis<DominanceAnalysis>()->get(fn),
getAnalysis<PostOrderAnalysis>());
MoveOnlyChecker checker(fn, getAnalysis<DominanceAnalysis>()->get(fn),
getAnalysis<PostOrderAnalysis>(),
getAnalysis<DeadEndBlocksAnalysis>());

checker.checkObjects();
checker.checkAddresses();
Expand Down
11 changes: 11 additions & 0 deletions test/SILOptimizer/moveonly_addresschecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,14 @@ func testAssertLikeUseDifferentBits() {
}
}
}

// issue #75312
struct S
{
@usableFromInline
init(utf8:consuming [UInt8])
{
utf8.withUnsafeBufferPointer { _ in }
fatalError()
}
}