[move-only] Update the non-address move checker part of the optimizer to handle mark_must_check on addresses.

This commit is contained in:
Michael Gottesman
2022-08-02 13:36:57 -07:00
parent 7b9d4e645c
commit 467b742a5c
10 changed files with 90 additions and 17 deletions

View File

@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "allocbox-to-stack"
#include "swift/AST/DiagnosticsSIL.h"
#include "swift/Basic/BlotMapVector.h"
#include "swift/Basic/GraphNodeWorklist.h"
@@ -591,9 +592,16 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
for (auto LastRelease : FinalReleases) {
SILBuilderWithScope Builder(LastRelease);
if (!isa<DeallocBoxInst>(LastRelease)&& !Lowering.isTrivial()) {
// If we have a mark_must_check use of our stack box, we want to destroy
// that.
SILValue valueToDestroy = StackBox;
if (auto *mmci = StackBox->getSingleUserOfType<MarkMustCheckInst>()) {
valueToDestroy = mmci;
}
// For non-trivial types, insert destroys for each final release-like
// instruction we found that isn't an explicit dealloc_box.
Builder.emitDestroyAddrAndFold(Loc, StackBox);
Builder.emitDestroyAddrAndFold(Loc, valueToDestroy);
}
Builder.createDeallocStack(Loc, ASI);
}