Skip to content

Commit e9e704e

Browse files
committed
[move-only][borrow2destructure] Move destructureNeedingUses, instToInterestingOperandIdnexMap, and blocksToUses into the implementation.
For now, I am creating new implementations every time... but once I get the tests passing, I am going to improve the performance by reusing the same Implementation for all computations so we can reuse memory.
1 parent 8391805 commit e9e704e

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyBorrowToDestructure.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,11 @@ class BorrowToDestructureTransform {
6060
IntervalMapAllocator &allocator;
6161
MarkMustCheckInst *mmci;
6262
DiagnosticEmitter &diagnosticEmitter;
63-
SmallVector<Operand *, 8> destructureNeedingUses;
6463
PostOrderAnalysis *poa;
6564
PostOrderFunctionInfo *pofi = nullptr;
6665
SmallVector<SILInstruction *, 8> createdDestructures;
6766
SmallVector<SILPhiArgument *, 8> createdPhiArguments;
6867

69-
using InterestingUser = FieldSensitivePrunedLiveness::InterestingUser;
70-
SmallFrozenMultiMap<SILBasicBlock *, std::pair<Operand *, InterestingUser>, 8>
71-
blocksToUses;
72-
73-
/// A frozen multi-map we use to diagnose consuming uses that are used by the
74-
/// same instruction as another consuming use or non-consuming use.
75-
SmallFrozenMultiMap<SILInstruction *, Operand *, 8>
76-
instToInterestingOperandIndexMap;
77-
7868
public:
7969
BorrowToDestructureTransform(IntervalMapAllocator &allocator,
8070
MarkMustCheckInst *mmci,

lib/SILOptimizer/Mandatory/MoveOnlyBorrowToDestructureTransform.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ struct borrowtodestructure::Implementation {
192192
/// so that we have an independent owned value.
193193
SILValue initialValue;
194194

195+
using InterestingUser = FieldSensitivePrunedLiveness::InterestingUser;
196+
SmallFrozenMultiMap<SILBasicBlock *, std::pair<Operand *, InterestingUser>, 8>
197+
blocksToUses;
198+
199+
/// A frozen multi-map we use to diagnose consuming uses that are used by the
200+
/// same instruction as another consuming use or non-consuming use.
201+
SmallFrozenMultiMap<SILInstruction *, Operand *, 8>
202+
instToInterestingOperandIndexMap;
203+
204+
SmallVector<Operand *, 8> destructureNeedingUses;
205+
195206
Implementation(BorrowToDestructureTransform &interface,
196207
SmallVectorImpl<SILBasicBlock *> &discoveredBlocks)
197208
: interface(interface),
@@ -303,12 +314,12 @@ bool Implementation::gatherUses(SILValue value) {
303314
}
304315

305316
LLVM_DEBUG(llvm::dbgs() << " Found non lifetime ending use!\n");
306-
interface.blocksToUses.insert(
317+
blocksToUses.insert(
307318
nextUse->getParentBlock(),
308319
{nextUse, {*leafRange, false /*is lifetime ending*/}});
309320
liveness.updateForUse(nextUse->getUser(), *leafRange,
310321
false /*is lifetime ending*/);
311-
interface.instToInterestingOperandIndexMap.insert(nextUse->getUser(),
322+
instToInterestingOperandIndexMap.insert(nextUse->getUser(),
312323
nextUse);
313324
continue;
314325
}
@@ -329,13 +340,13 @@ bool Implementation::gatherUses(SILValue value) {
329340
}
330341

331342
LLVM_DEBUG(llvm::dbgs() << " Found lifetime ending use!\n");
332-
interface.destructureNeedingUses.push_back(nextUse);
333-
interface.blocksToUses.insert(
343+
destructureNeedingUses.push_back(nextUse);
344+
blocksToUses.insert(
334345
nextUse->getParentBlock(),
335346
{nextUse, {*leafRange, true /*is lifetime ending*/}});
336347
liveness.updateForUse(nextUse->getUser(), *leafRange,
337348
true /*is lifetime ending*/);
338-
interface.instToInterestingOperandIndexMap.insert(nextUse->getUser(),
349+
instToInterestingOperandIndexMap.insert(nextUse->getUser(),
339350
nextUse);
340351
continue;
341352
}
@@ -373,11 +384,11 @@ void Implementation::checkForErrorsOnSameInstruction() {
373384
// At this point, we have emitted all boundary checks. We also now need to
374385
// check if any of our consuming uses that are on the boundary are used by the
375386
// same instruction as a different consuming or non-consuming use.
376-
interface.instToInterestingOperandIndexMap.setFrozen();
387+
instToInterestingOperandIndexMap.setFrozen();
377388
SmallBitVector usedBits(liveness.getNumSubElements());
378389

379390
for (auto instRangePair :
380-
interface.instToInterestingOperandIndexMap.getRange()) {
391+
instToInterestingOperandIndexMap.getRange()) {
381392
SWIFT_DEFER { usedBits.reset(); };
382393

383394
// First loop through our uses and handle any consuming twice errors. We
@@ -487,7 +498,7 @@ void Implementation::checkDestructureUsesOnBoundary() const {
487498
// needing uses, make sure that none of our destructure needing uses are
488499
// within our boundary. If so, we have an automatic error since we have a
489500
// use-after-free.
490-
for (auto *use : interface.destructureNeedingUses) {
501+
for (auto *use : destructureNeedingUses) {
491502
LLVM_DEBUG(llvm::dbgs()
492503
<< " DestructureNeedingUse: " << *use->getUser());
493504

@@ -1158,7 +1169,7 @@ dumpIntervalMap(IntervalMapAllocator::Map &map) {
11581169
#endif
11591170

11601171
void Implementation::rewriteUses() {
1161-
interface.blocksToUses.setFrozen();
1172+
blocksToUses.setFrozen();
11621173

11631174
LLVM_DEBUG(llvm::dbgs()
11641175
<< "Performing BorrowToDestructureTransform::rewriteUses()!\n");
@@ -1189,7 +1200,7 @@ void Implementation::rewriteUses() {
11891200
<< "Visiting block bb" << block->getDebugID() << '\n');
11901201

11911202
// See if we have any operands that we need to process...
1192-
if (auto operandList = interface.blocksToUses.find(block)) {
1203+
if (auto operandList = blocksToUses.find(block)) {
11931204
// If we do, gather up the bits that we need.
11941205
for (auto operand : *operandList) {
11951206
auto &subEltSpan = operand.second.subEltSpan;

0 commit comments

Comments
 (0)