Skip to content

Commit d618e50

Browse files
authored
Merge pull request #59164 from meg-gupta/addressloweringminorfixes
[SIL Opaque Value] Minor fixes in AddressLowering
2 parents c59f473 + fb0be6a commit d618e50

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static bool isStoreCopy(SILValue value) {
339339
return false;
340340

341341
auto *user = value->getSingleUse()->getUser();
342-
return isa<StoreInst>(user) || isa<AssignInst>(user);
342+
return isa<StoreInst>(user);
343343
}
344344

345345
void ValueStorageMap::insertValue(SILValue value, SILValue storageAddress) {
@@ -1784,14 +1784,12 @@ void CallArgRewriter::rewriteIndirectArgument(Operand *operand) {
17841784
});
17851785
} else {
17861786
auto borrow = argBuilder.emitBeginBorrowOperation(callLoc, argValue);
1787-
auto *storeInst =
1788-
argBuilder.emitStoreBorrowOperation(callLoc, borrow, allocInst);
1787+
argBuilder.emitStoreBorrowOperation(callLoc, borrow, allocInst);
17891788

17901789
apply.insertAfterFullEvaluation([&](SILBuilder &callBuilder) {
1791-
if (auto *storeBorrow = dyn_cast<StoreBorrowInst>(storeInst)) {
1792-
callBuilder.emitEndBorrowOperation(callLoc, storeBorrow);
1790+
if (borrow != argValue) {
1791+
callBuilder.emitEndBorrowOperation(callLoc, borrow);
17931792
}
1794-
callBuilder.emitEndBorrowOperation(callLoc, borrow);
17951793
callBuilder.createDeallocStack(callLoc, allocInst);
17961794
});
17971795
}
@@ -2369,8 +2367,11 @@ class CheckedCastBrRewriter {
23692367
/// Return the storageAddress if \p value is opaque, otherwise create and
23702368
/// return a stack temporary.
23712369
SILValue getAddressForCastEntity(SILValue value, bool needsInit) {
2372-
if (value->getType().isAddressOnly(*func))
2373-
return pass.valueStorageMap.getStorage(value).storageAddress;
2370+
if (value->getType().isAddressOnly(*func)) {
2371+
auto builder = pass.getBuilder(ccb->getIterator());
2372+
AddressMaterialization addrMat(pass, builder);
2373+
return addrMat.materializeAddress(value);
2374+
}
23742375

23752376
// Create a stack temporary for a loadable value
23762377
auto *addr = termBuilder.createAllocStack(castLoc, value->getType());
@@ -2595,12 +2596,14 @@ class UseRewriter : SILInstructionVisitor<UseRewriter> {
25952596
}
25962597

25972598
void visitYieldInst(YieldInst *yield) {
2598-
SILValue addr =
2599-
pass.valueStorageMap.getStorage(yield->getOperand(0)).storageAddress;
2599+
SILValue addr = addrMat.materializeAddress(use->get());
26002600
yield->setOperand(0, addr);
26012601
}
26022602

2603-
void visitAssignInst(AssignInst *assignInst);
2603+
void visitValueMetatypeInst(ValueMetatypeInst *vmi) {
2604+
SILValue opAddr = addrMat.materializeAddress(use->get());
2605+
vmi->setOperand(opAddr);
2606+
}
26042607

26052608
void visitBeginBorrowInst(BeginBorrowInst *borrow);
26062609

@@ -2832,11 +2835,6 @@ void UseRewriter::visitStoreInst(StoreInst *storeInst) {
28322835
rewriteStore(storeInst->getSrc(), storeInst->getDest(), isInit);
28332836
}
28342837

2835-
void UseRewriter::visitAssignInst(AssignInst *assignInst) {
2836-
rewriteStore(assignInst->getSrc(), assignInst->getDest(),
2837-
IsNotInitialization);
2838-
}
2839-
28402838
/// Emit end_borrows for a an incomplete BorrowedValue with only nonlifetime
28412839
/// ending uses. This function inserts end_borrows on the lifetime boundary.
28422840
void UseRewriter::emitEndBorrows(SILValue value) {

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ static void addDefiniteInitialization(SILPassPipelinePlan &P) {
116116
static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
117117
P.startPipeline("Mandatory Diagnostic Passes + Enabling Optimization Passes");
118118
P.addSILGenCleanup();
119-
P.addAddressLowering();
120119
P.addDiagnoseInvalidEscapingCaptures();
121120
P.addDiagnoseStaticExclusivity();
122121
P.addNestedSemanticFunctionCheck();
@@ -129,6 +128,7 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
129128
P.addAllocBoxToStack();
130129
P.addNoReturnFolding();
131130
addDefiniteInitialization(P);
131+
P.addAddressLowering();
132132

133133
P.addFlowIsolation();
134134

0 commit comments

Comments
 (0)