[AddressLowering] Handle weak copies.

Lower the `strong_copy_weak_value` and `weak_copy_value` to `load_weak`
and `store_weak` respectively.
This commit is contained in:
Nate Chandler
2023-07-28 17:17:36 -07:00
parent c007bae723
commit 390d02f114
2 changed files with 49 additions and 1 deletions

View File

@@ -3483,6 +3483,14 @@ protected:
pass.deleter.forceDelete(sei);
}
void visitStrongCopyWeakValueInst(StrongCopyWeakValueInst *scwvi) {
auto sourceAddr = addrMat.materializeAddress(use->get());
SILValue value =
builder.createLoadWeak(scwvi->getLoc(), sourceAddr, IsNotTake);
scwvi->replaceAllUsesWith(value);
pass.deleter.forceDelete(scwvi);
}
// Extract from an opaque struct.
void visitStructExtractInst(StructExtractInst *extractInst);
@@ -4094,6 +4102,15 @@ protected:
rewriteUnconditionalCheckedCastInst(uncondCheckedCast, pass);
}
void visitWeakCopyValueInst(WeakCopyValueInst *wcsvi) {
auto &storage = pass.valueStorageMap.getStorage(wcsvi);
auto destAddr = addrMat.recursivelyMaterializeStorage(
storage, /*intoPhiOperand=*/false);
builder.createStoreWeak(wcsvi->getLoc(), wcsvi->getOperand(), destAddr,
IsInitialization);
}
};
} // end anonymous namespace