Skip to content

[SIL Opaque Value] Minor fixes in AddressLowering #59164

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
merged 4 commits into from
Jun 1, 2022
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
30 changes: 14 additions & 16 deletions lib/SILOptimizer/Mandatory/AddressLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static bool isStoreCopy(SILValue value) {
return false;

auto *user = value->getSingleUse()->getUser();
return isa<StoreInst>(user) || isa<AssignInst>(user);
return isa<StoreInst>(user);
}

void ValueStorageMap::insertValue(SILValue value, SILValue storageAddress) {
Expand Down Expand Up @@ -1784,14 +1784,12 @@ void CallArgRewriter::rewriteIndirectArgument(Operand *operand) {
});
} else {
auto borrow = argBuilder.emitBeginBorrowOperation(callLoc, argValue);
auto *storeInst =
argBuilder.emitStoreBorrowOperation(callLoc, borrow, allocInst);
argBuilder.emitStoreBorrowOperation(callLoc, borrow, allocInst);

apply.insertAfterFullEvaluation([&](SILBuilder &callBuilder) {
if (auto *storeBorrow = dyn_cast<StoreBorrowInst>(storeInst)) {
callBuilder.emitEndBorrowOperation(callLoc, storeBorrow);
if (borrow != argValue) {
callBuilder.emitEndBorrowOperation(callLoc, borrow);
}
callBuilder.emitEndBorrowOperation(callLoc, borrow);
callBuilder.createDeallocStack(callLoc, allocInst);
});
}
Expand Down Expand Up @@ -2369,8 +2367,11 @@ class CheckedCastBrRewriter {
/// Return the storageAddress if \p value is opaque, otherwise create and
/// return a stack temporary.
SILValue getAddressForCastEntity(SILValue value, bool needsInit) {
if (value->getType().isAddressOnly(*func))
return pass.valueStorageMap.getStorage(value).storageAddress;
if (value->getType().isAddressOnly(*func)) {
auto builder = pass.getBuilder(ccb->getIterator());
AddressMaterialization addrMat(pass, builder);
return addrMat.materializeAddress(value);
}

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

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

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

void visitBeginBorrowInst(BeginBorrowInst *borrow);

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

void UseRewriter::visitAssignInst(AssignInst *assignInst) {
rewriteStore(assignInst->getSrc(), assignInst->getDest(),
IsNotInitialization);
}

/// Emit end_borrows for a an incomplete BorrowedValue with only nonlifetime
/// ending uses. This function inserts end_borrows on the lifetime boundary.
void UseRewriter::emitEndBorrows(SILValue value) {
Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/PassManager/PassPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ static void addDefiniteInitialization(SILPassPipelinePlan &P) {
static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
P.startPipeline("Mandatory Diagnostic Passes + Enabling Optimization Passes");
P.addSILGenCleanup();
P.addAddressLowering();
P.addDiagnoseInvalidEscapingCaptures();
P.addDiagnoseStaticExclusivity();
P.addNestedSemanticFunctionCheck();
Expand All @@ -129,6 +128,7 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
P.addAllocBoxToStack();
P.addNoReturnFolding();
addDefiniteInitialization(P);
P.addAddressLowering();

P.addFlowIsolation();

Expand Down