Skip to content

Commit 15796e3

Browse files
committed
PrunedLiveness: add a SILFunction argument
So that liveness can migrate to using a SILBitfield.
1 parent 2fc5008 commit 15796e3

18 files changed

+45
-35
lines changed

include/swift/SIL/OwnershipLiveness.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ class OSSALiveness {
178178
OSSALiveness &operator=(const OSSALiveness &) = delete;
179179

180180
public:
181-
OSSALiveness(SILValue def): ownershipDef(def), liveness(&discoveredBlocks) {}
181+
OSSALiveness(SILValue def): ownershipDef(def),
182+
liveness(def->getFunction(), &discoveredBlocks) {}
182183

183184
const SSAPrunedLiveness &getLiveness() const { return liveness; }
184185

include/swift/SIL/PrunedLiveness.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,9 @@ class PrunedLiveness {
479479
llvm::SmallMapVector<SILInstruction *, bool, 8> users;
480480

481481
public:
482-
PrunedLiveness(SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr)
483-
: liveBlocks(1 /*num bits*/, discoveredBlocks) {}
482+
PrunedLiveness(SILFunction *function,
483+
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr)
484+
: liveBlocks(function, discoveredBlocks) {}
484485

485486
bool empty() const {
486487
assert(!liveBlocks.empty() || users.empty());
@@ -745,8 +746,9 @@ class SSAPrunedLiveness : public PrunedLiveRange<SSAPrunedLiveness> {
745746

746747
public:
747748
SSAPrunedLiveness(
749+
SILFunction *function,
748750
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr)
749-
: PrunedLiveRange(discoveredBlocks) {}
751+
: PrunedLiveRange(function, discoveredBlocks) {}
750752

751753
SILValue getDef() const { return def; }
752754

@@ -815,8 +817,8 @@ class MultiDefPrunedLiveness : public PrunedLiveRange<MultiDefPrunedLiveness> {
815817
MultiDefPrunedLiveness(
816818
SILFunction *function,
817819
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr)
818-
: PrunedLiveRange(discoveredBlocks), defs(function), defBlocks(function) {
819-
}
820+
: PrunedLiveRange(function, discoveredBlocks), defs(function),
821+
defBlocks(function) {}
820822

821823
void clear() {
822824
llvm_unreachable("multi-def liveness cannot be reused");
@@ -886,10 +888,11 @@ class DiagnosticPrunedLiveness : public SSAPrunedLiveness {
886888

887889
public:
888890
DiagnosticPrunedLiveness(
891+
SILFunction *function,
889892
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr,
890893
SmallSetVector<SILInstruction *, 8> *nonLifetimeEndingUsesInLiveOut =
891894
nullptr)
892-
: SSAPrunedLiveness(discoveredBlocks),
895+
: SSAPrunedLiveness(function, discoveredBlocks),
893896
nonLifetimeEndingUsesInLiveOut(nonLifetimeEndingUsesInLiveOut) {}
894897

895898
void clear() {

include/swift/SILOptimizer/Utils/CanonicalizeBorrowScope.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class CanonicalizeBorrowScope {
8585
llvm::SmallDenseMap<SILBasicBlock *, CopyValueInst *, 4> persistentCopies;
8686

8787
public:
88-
CanonicalizeBorrowScope(InstructionDeleter &deleter) : deleter(deleter) {}
88+
CanonicalizeBorrowScope(SILFunction *function, InstructionDeleter &deleter)
89+
: liveness(function), deleter(deleter) {}
8990

9091
BorrowedValue getBorrowedValue() const { return borrowedValue; }
9192

include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,13 @@ class CanonicalizeOSSALifetime final {
281281
}
282282

283283
CanonicalizeOSSALifetime(bool pruneDebugMode, bool maximizeLifetime,
284+
SILFunction *function,
284285
NonLocalAccessBlockAnalysis *accessBlockAnalysis,
285286
DominanceInfo *domTree, InstructionDeleter &deleter)
286287
: pruneDebugMode(pruneDebugMode), maximizeLifetime(maximizeLifetime),
287288
accessBlockAnalysis(accessBlockAnalysis), domTree(domTree),
288289
deleter(deleter),
289-
liveness(maximizeLifetime ? &discoveredBlocks : nullptr) {}
290+
liveness(function, maximizeLifetime ? &discoveredBlocks : nullptr) {}
290291

291292
SILValue getCurrentDef() const { return liveness.getDef(); }
292293

include/swift/SILOptimizer/Utils/OwnershipOptUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class GuaranteedOwnershipExtension {
113113
GuaranteedOwnershipExtension(InstructionDeleter &deleter,
114114
DeadEndBlocks &deBlocks, SILFunction *function)
115115
: deleter(deleter), deBlocks(deBlocks),
116-
guaranteedLiveness(function) {}
116+
guaranteedLiveness(function), ownedLifetime(function) {}
117117

118118
void clear() {
119119
guaranteedLiveness.clear();

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ bool AddressOwnership::areUsesWithinLifetime(
12131213
// --- A reference with no borrow scope! Currently happens for project_box.
12141214

12151215
// Compute the reference value's liveness.
1216-
SSAPrunedLiveness liveness;
1216+
SSAPrunedLiveness liveness(root->getFunction());
12171217
liveness.initializeDef(root);
12181218
LiveRangeSummary summary = liveness.computeSimple();
12191219
// Conservatively ignore InnerBorrowKind::Reborrowed and

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
25452545
SI->getSrc()->getType(),
25462546
"Store operand type and dest type mismatch");
25472547

2548-
SSAPrunedLiveness scopedAddressLiveness;
2548+
SSAPrunedLiveness scopedAddressLiveness(SI->getFunction());
25492549
ScopedAddressValue scopedAddress(SI);
25502550
// FIXME: Reenable @test_load_borrow_store_borrow_nested in
25512551
// store_borrow_verify_errors once computeLivess can successfully handle a

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static bool isStoreCopy(SILValue value) {
352352
if (!storeInst)
353353
return false;
354354

355-
SSAPrunedLiveness liveness;
355+
SSAPrunedLiveness liveness(copyInst->getFunction());
356356
auto isStoreOutOfRange = [&liveness, storeInst](SILValue root) {
357357
liveness.initializeDef(root);
358358
auto summary = liveness.computeSimple();
@@ -3366,7 +3366,7 @@ static void emitEndBorrows(SILValue value, AddressLoweringState &pass) {
33663366
findInnerTransitiveGuaranteedUses(value, &usePoints);
33673367

33683368
SmallVector<SILBasicBlock *, 4> discoveredBlocks;
3369-
SSAPrunedLiveness liveness(&discoveredBlocks);
3369+
SSAPrunedLiveness liveness(value->getFunction(), &discoveredBlocks);
33703370
liveness.initializeDef(value);
33713371
for (auto *use : usePoints) {
33723372
assert(!use->isLifetimeEnding() || isa<EndBorrowInst>(use->getUser()));

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableValuesChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ struct CheckerLivenessInfo {
6060
SmallVector<Operand *, 8> interiorPointerTransitiveUses;
6161
DiagnosticPrunedLiveness liveness;
6262

63-
CheckerLivenessInfo()
63+
CheckerLivenessInfo(SILFunction *fn)
6464
: nonLifetimeEndingUsesInLiveOut(),
65-
liveness(nullptr, &nonLifetimeEndingUsesInLiveOut) {}
65+
liveness(fn, nullptr, &nonLifetimeEndingUsesInLiveOut) {}
6666

6767
void initDef(SILValue def) {
6868
liveness.initializeDef(def);
@@ -220,7 +220,7 @@ struct ConsumeOperatorCopyableValuesChecker {
220220
SILLoopInfo *loopInfoToUpdate;
221221

222222
ConsumeOperatorCopyableValuesChecker(SILFunction *fn)
223-
: fn(fn), livenessInfo(), dominanceToUpdate(nullptr),
223+
: fn(fn), livenessInfo(fn), dominanceToUpdate(nullptr),
224224
loopInfoToUpdate(nullptr) {}
225225

226226
void setDominanceToUpdate(DominanceInfo *newDFI) {

lib/SILOptimizer/Mandatory/DiagnoseLifetimeIssues.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class DiagnoseLifetimeIssues {
6363
/// callgraphs, with pass down references.
6464
static constexpr int maxCallDepth = 8;
6565

66+
SILFunction *function = nullptr;
67+
6668
/// The liveness of the object in question, computed in visitUses.
6769
SSAPrunedLiveness liveness;
6870

@@ -84,9 +86,10 @@ class DiagnoseLifetimeIssues {
8486
void reportDeadStore(SILInstruction *allocationInst);
8587

8688
public:
87-
DiagnoseLifetimeIssues() {}
89+
DiagnoseLifetimeIssues(SILFunction *function)
90+
: function(function), liveness(function) {}
8891

89-
void diagnose(SILFunction *function);
92+
void diagnose();
9093
};
9194

9295
/// Returns true if def is an owned value resulting from an object allocation.
@@ -352,7 +355,7 @@ void DiagnoseLifetimeIssues::reportDeadStore(SILInstruction *allocationInst) {
352355
}
353356

354357
/// Prints warnings for dead weak stores in \p function.
355-
void DiagnoseLifetimeIssues::diagnose(SILFunction *function) {
358+
void DiagnoseLifetimeIssues::diagnose() {
356359
for (SILBasicBlock &block : *function) {
357360
for (SILInstruction &inst : block) {
358361
// Only for allocations we know that a destroy will actually deallocate

0 commit comments

Comments
 (0)