Skip to content

Commit bb46f74

Browse files
committed
[AddressLowering] NFC: Extracted common visitor.
In preparation for supporting move_value which should be treated exactly the same way as begin_borrow, factored visitBeginBorrow through the new visitLifetimeIntroducer.
1 parent 003b335 commit bb46f74

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,6 +3050,9 @@ class UseRewriter : SILInstructionVisitor<UseRewriter> {
30503050
}
30513051
}
30523052

3053+
template <typename Introducer>
3054+
void visitLifetimeIntroducer(Introducer *introducer);
3055+
30533056
void visitBeginBorrowInst(BeginBorrowInst *borrow);
30543057

30553058
void visitEndBorrowInst(EndBorrowInst *end) {}
@@ -3263,15 +3266,16 @@ void UseRewriter::rewriteDestructure(SILInstruction *destructure) {
32633266
}
32643267
}
32653268

3266-
void UseRewriter::visitBeginBorrowInst(BeginBorrowInst *borrow) {
3267-
assert(use == getProjectedDefOperand(borrow));
3269+
template <typename Introducer>
3270+
void UseRewriter::visitLifetimeIntroducer(Introducer *introducer) {
3271+
assert(use == getProjectedDefOperand(introducer));
32683272

32693273
// Mark the value as rewritten and use the operand's storage.
32703274
auto address = pass.valueStorageMap.getStorage(use->get()).storageAddress;
3271-
markRewritten(borrow, address);
3275+
markRewritten(introducer, address);
32723276

3273-
// Borrows are irrelevant unless they are marked lexical.
3274-
if (borrow->isLexical()) {
3277+
// Lifetime introducers are irrelevant unless they are marked lexical.
3278+
if (introducer->isLexical()) {
32753279
if (auto base = getAccessBase(address)) {
32763280
if (auto *allocStack = dyn_cast<AllocStackInst>(base)) {
32773281
allocStack->setIsLexical();
@@ -3287,6 +3291,10 @@ void UseRewriter::visitBeginBorrowInst(BeginBorrowInst *borrow) {
32873291
}
32883292
}
32893293

3294+
void UseRewriter::visitBeginBorrowInst(BeginBorrowInst *borrow) {
3295+
visitLifetimeIntroducer(borrow);
3296+
}
3297+
32903298
// Opening an opaque existential. Rewrite the opened existentials here on
32913299
// the use-side because it may produce either loadable or address-only
32923300
// types.

0 commit comments

Comments
 (0)