|
149 | 149 | #include "swift/SIL/SILInstruction.h"
|
150 | 150 | #include "swift/SIL/SILValue.h"
|
151 | 151 | #include "swift/SIL/SILVisitor.h"
|
| 152 | +#include "swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h" |
152 | 153 | #include "swift/SILOptimizer/Analysis/PostOrderAnalysis.h"
|
153 | 154 | #include "swift/SILOptimizer/PassManager/Transforms.h"
|
154 | 155 | #include "swift/SILOptimizer/Utils/BasicBlockOptUtils.h"
|
@@ -413,6 +414,9 @@ struct AddressLoweringState {
|
413 | 414 | // Dominators remain valid throughout this pass.
|
414 | 415 | DominanceInfo *domInfo;
|
415 | 416 |
|
| 417 | + // Dead-end blocks remain valid through this pass. |
| 418 | + DeadEndBlocks *deBlocks; |
| 419 | + |
416 | 420 | InstructionDeleter deleter;
|
417 | 421 |
|
418 | 422 | // All opaque values mapped to their associated storage.
|
@@ -441,9 +445,10 @@ struct AddressLoweringState {
|
441 | 445 | // Handle moves from a phi's operand storage to the phi storage.
|
442 | 446 | std::unique_ptr<PhiRewriter> phiRewriter;
|
443 | 447 |
|
444 |
| - AddressLoweringState(SILFunction *function, DominanceInfo *domInfo) |
| 448 | + AddressLoweringState(SILFunction *function, DominanceInfo *domInfo, |
| 449 | + DeadEndBlocks *deBlocks) |
445 | 450 | : function(function), loweredFnConv(getLoweredFnConv(function)),
|
446 |
| - domInfo(domInfo) { |
| 451 | + domInfo(domInfo), deBlocks(deBlocks) { |
447 | 452 | for (auto &block : *function) {
|
448 | 453 | if (block.getTerminator()->isFunctionExiting())
|
449 | 454 | exitingInsts.push_back(block.getTerminator());
|
@@ -1332,6 +1337,8 @@ void OpaqueStorageAllocation::finalizeOpaqueStorage() {
|
1332 | 1337 | // a use projection.
|
1333 | 1338 | computeDominatedBoundaryBlocks(alloc->getParent(), pass.domInfo, boundary);
|
1334 | 1339 | for (SILBasicBlock *deallocBlock : boundary) {
|
| 1340 | + if (pass.deBlocks->isDeadEnd(deallocBlock)) |
| 1341 | + continue; |
1335 | 1342 | auto deallocBuilder = pass.getBuilder(deallocBlock->back().getIterator());
|
1336 | 1343 | deallocBuilder.createDeallocStack(pass.genLoc(), alloc);
|
1337 | 1344 | }
|
@@ -3859,8 +3866,10 @@ void AddressLowering::runOnFunction(SILFunction *function) {
|
3859 | 3866 | removeUnreachableBlocks(*function);
|
3860 | 3867 |
|
3861 | 3868 | auto *dominance = PM->getAnalysis<DominanceAnalysis>();
|
| 3869 | + auto *deadEnds = PM->getAnalysis<DeadEndBlocksAnalysis>(); |
3862 | 3870 |
|
3863 |
| - AddressLoweringState pass(function, dominance->get(function)); |
| 3871 | + AddressLoweringState pass(function, dominance->get(function), |
| 3872 | + deadEnds->get(function)); |
3864 | 3873 |
|
3865 | 3874 | // ## Step #1: Map opaque values
|
3866 | 3875 | //
|
|
0 commit comments