Skip to content

Commit 092b6f2

Browse files
committed
[SSADestroyHoisting] Expand store [assign]s first.
To create more opportunities for hoisting.
1 parent bd8626c commit 092b6f2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/SILOptimizer/Transforms/SSADestroyHoisting.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ void SSADestroyHoisting::run() {
565565

566566
llvm::SmallVector<AllocStackInst *, 4> asis;
567567
llvm::SmallVector<BeginAccessInst *, 4> bais;
568+
llvm::SmallVector<StoreInst *, 4> sis;
568569

569570
// Collect the instructions that we'll be transforming.
570571
for (auto &block : *getFunction()) {
@@ -575,10 +576,32 @@ void SSADestroyHoisting::run() {
575576
if (bai->getAccessKind() == SILAccessKind::Modify) {
576577
bais.push_back(bai);
577578
}
579+
} else if (auto *si = dyn_cast<StoreInst>(&inst)) {
580+
if (si->getOwnershipQualifier() == StoreOwnershipQualifier::Assign) {
581+
sis.push_back(si);
582+
}
578583
}
579584
}
580585
}
581586

587+
// Before hoisting, expand all
588+
//
589+
// store [assign]
590+
//
591+
// instructions into
592+
//
593+
// destroy_addr
594+
// store [init]
595+
//
596+
// sequences to create more destroy_addrs to hoist.
597+
for (auto *si : sis) {
598+
auto builder = SILBuilderWithScope(si);
599+
builder.createDestroyAddr(
600+
RegularLocation::getAutoGeneratedLocation(si->getLoc()),
601+
si->getOperand(1));
602+
si->setOwnershipQualifier(StoreOwnershipQualifier::Init);
603+
}
604+
582605
// We assume that the function is in reverse post order so visiting the
583606
// blocks and pushing begin_access as we see them and then popping them off
584607
// the end will result in hoisting inner begin_access' destroy_addrs first.

0 commit comments

Comments
 (0)