Skip to content

Commit aea53a1

Browse files
committed
[NFC] OSSACanonicalizeOwned: Record originals.
When recording a def that's a copy, also record what value it's a copy of. This _could_ be rediscovered later, but it's more obvious when done here. (A note on rediscovery: it would be equivalent to recursing through copy_value instructions until finding either (1) some value which wasn't produced by a copy_value or (2) a copy_value which is the current def.)
1 parent cd54bbe commit aea53a1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class CanonicalizeOSSALifetime final {
285285
};
286286
struct Copy {
287287
CopyValueInst *cvi;
288+
SILValue original;
288289
};
289290
struct BorrowedFrom {
290291
BorrowedFromInst *bfi;
@@ -321,7 +322,9 @@ class CanonicalizeOSSALifetime final {
321322
return getKind() == rhs.getKind() && getValue() == rhs.getValue();
322323
}
323324
static Def root(SILValue value) { return {Root{value}}; }
324-
static Def copy(CopyValueInst *cvi) { return {Copy{cvi}}; }
325+
static Def copy(CopyValueInst *cvi, SILValue original) {
326+
return {Copy{cvi, original}};
327+
}
325328
static Def borrowedFrom(BorrowedFromInst *bfi) {
326329
return {BorrowedFrom{bfi}};
327330
}
@@ -339,6 +342,17 @@ class CanonicalizeOSSALifetime final {
339342
}
340343
llvm_unreachable("covered switch");
341344
}
345+
SILValue getOriginalValue() const {
346+
switch (*this) {
347+
case Kind::Copy:
348+
return payload.get<Copy>().original;
349+
case Kind::Root:
350+
case Kind::BorrowedFrom:
351+
case Kind::Reborrow:
352+
return getValue();
353+
}
354+
llvm_unreachable("covered switch");
355+
}
342356
};
343357
friend llvm::DenseMapInfo<Def>;
344358

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ bool CanonicalizeOSSALifetime::computeCanonicalLiveness() {
165165
auto *user = use->getUser();
166166
// Recurse through copies.
167167
if (auto *copy = dyn_cast<CopyValueInst>(user)) {
168-
addDefToWorklist(Def::copy(copy));
168+
addDefToWorklist(Def::copy(copy, def.getOriginalValue()));
169169
continue;
170170
}
171171
if (auto *bfi = dyn_cast<BorrowedFromInst>(user)) {

0 commit comments

Comments
 (0)