Skip to content

Commit ff698f2

Browse files
committed
DI: Rip out the old 'self consumed' analysis now that it's dead
1 parent c69686f commit ff698f2

File tree

3 files changed

+3
-138
lines changed

3 files changed

+3
-138
lines changed

lib/SILOptimizer/Mandatory/DIMemoryUseCollectorOwnership.cpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -430,54 +430,6 @@ void DIElementUseInfo::trackStoreToSelf(SILInstruction *I) {
430430
StoresToSelf.push_back(I);
431431
}
432432

433-
void DIElementUseInfo::trackFailableInitCall(
434-
const DIMemoryObjectInfo &MemoryInfo, SILInstruction *I) {
435-
// If we have a store to self inside the normal BB, we have a 'real'
436-
// try_apply. Otherwise, this is a 'try? self.init()' or similar,
437-
// and there is a store after.
438-
if (auto *TAI = dyn_cast<TryApplyInst>(I)) {
439-
trackFailureBlock(MemoryInfo, TAI, TAI->getNormalBB());
440-
return;
441-
}
442-
443-
if (auto *AI = dyn_cast<ApplyInst>(I)) {
444-
// See if this is an optional initializer.
445-
for (auto Op : AI->getUses()) {
446-
SILInstruction *User = Op->getUser();
447-
448-
if (!isa<SelectEnumInst>(User) && !isa<SelectEnumAddrInst>(User))
449-
continue;
450-
451-
auto value = cast<SingleValueInstruction>(User);
452-
453-
if (!value->hasOneUse())
454-
continue;
455-
456-
User = value->use_begin()->getUser();
457-
if (auto *CBI = dyn_cast<CondBranchInst>(User)) {
458-
trackFailureBlock(MemoryInfo, CBI, CBI->getTrueBB());
459-
return;
460-
}
461-
}
462-
}
463-
}
464-
465-
/// We have to detect if the self box contents were consumed. Do this by
466-
/// checking for a store into the self box in the success branch. Once we rip
467-
/// this out of SILGen, DI will be able to figure this out in a more logical
468-
/// manner.
469-
void DIElementUseInfo::trackFailureBlock(const DIMemoryObjectInfo &TheMemory,
470-
TermInst *TI, SILBasicBlock *BB) {
471-
for (auto &II : *BB) {
472-
if (auto *SI = dyn_cast<StoreInst>(&II)) {
473-
if (SI->getDest() == TheMemory.MemoryInst) {
474-
FailableInits.push_back(TI);
475-
return;
476-
}
477-
}
478-
}
479-
}
480-
481433
//===----------------------------------------------------------------------===//
482434
// Scalarization Logic
483435
//===----------------------------------------------------------------------===//
@@ -1426,7 +1378,6 @@ void ElementUseCollector::collectClassSelfUses(
14261378
(isSelfInitUse(User) || isSuperInitUse(User))) {
14271379
if (isSelfOperand(Op, User)) {
14281380
Kind = DIUseKind::SelfInit;
1429-
UseInfo.trackFailableInitCall(TheMemory, User);
14301381
}
14311382
}
14321383

@@ -1708,7 +1659,6 @@ void DelegatingInitElementUseCollector::collectDelegatingClassInitSelfLoadUses(
17081659
(isSelfInitUse(User) || isSuperInitUse(User))) {
17091660
if (isSelfOperand(Op, User)) {
17101661
Kind = DIUseKind::SelfInit;
1711-
UseInfo.trackFailableInitCall(TheMemory, User);
17121662
}
17131663
}
17141664

lib/SILOptimizer/Mandatory/DIMemoryUseCollectorOwnership.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,13 @@ struct DIMemoryUse {
278278
struct DIElementUseInfo {
279279
SmallVector<DIMemoryUse, 16> Uses;
280280
SmallVector<SILInstruction *, 4> Releases;
281-
TinyPtrVector<TermInst *> FailableInits;
282281
TinyPtrVector<SILInstruction *> StoresToSelf;
283282

284283
void trackUse(DIMemoryUse Use) { Uses.push_back(Use); }
285284

286285
void trackDestroy(SILInstruction *Destroy) { Releases.push_back(Destroy); }
287286

288287
void trackStoreToSelf(SILInstruction *I);
289-
290-
void trackFailableInitCall(const DIMemoryObjectInfo &TheMemory,
291-
SILInstruction *I);
292-
293-
private:
294-
void trackFailureBlock(const DIMemoryObjectInfo &TheMemory, TermInst *TI,
295-
SILBasicBlock *BB);
296288
};
297289

298290
/// collectDIElementUsesFrom - Analyze all uses of the specified allocation

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,6 @@ namespace {
363363
/// plus the information merged-in from the predecessor blocks.
364364
AvailabilitySet OutAvailability;
365365

366-
/// Keep track of blocks where the contents of the self box are not valid
367-
/// because we're in an error path dominated by a self.init or super.init
368-
/// delegation.
369-
Optional<DIKind> LocalSelfConsumed;
370-
371-
/// The live out information of the block. This is the LocalSelfConsumed
372-
/// plus the information merged-in from the predecessor blocks.
373-
Optional<DIKind> OutSelfConsumed;
374-
375366
/// Keep track of blocks where the contents of the self box are stored to
376367
/// as a result of a successful self.init or super.init call.
377368
Optional<DIKind> LocalSelfInitialized;
@@ -391,10 +382,6 @@ namespace {
391382
void setUnknownToNotAvailable() {
392383
LocalAvailability.changeUnsetElementsTo(DIKind::No);
393384
OutAvailability.changeUnsetElementsTo(DIKind::No);
394-
if (!LocalSelfConsumed.hasValue())
395-
LocalSelfConsumed = DIKind::No;
396-
if (!OutSelfConsumed.hasValue())
397-
OutSelfConsumed = DIKind::No;
398385
if (!LocalSelfInitialized.hasValue())
399386
LocalSelfInitialized = DIKind::No;
400387
if (!OutSelfInitialized.hasValue())
@@ -441,15 +428,6 @@ namespace {
441428
}
442429
}
443430

444-
Optional<DIKind> temp;
445-
if (transferAvailability(Pred.OutSelfConsumed,
446-
OutSelfConsumed,
447-
LocalSelfConsumed,
448-
temp)) {
449-
changed = true;
450-
OutSelfConsumed = temp;
451-
}
452-
453431
Optional<DIKind> result;
454432
if (transferAvailability(Pred.OutSelfInitialized,
455433
OutSelfInitialized,
@@ -474,13 +452,6 @@ namespace {
474452
}
475453
}
476454

477-
/// Mark the block as a failure path, indicating the self value has been
478-
/// consumed.
479-
void markFailure(bool partial) {
480-
LocalSelfConsumed = (partial ? DIKind::Partial : DIKind::Yes);
481-
OutSelfConsumed = LocalSelfConsumed;
482-
}
483-
484455
/// Mark the block as storing to self, indicating the self box has been
485456
/// initialized.
486457
void markStoreToSelf() {
@@ -490,8 +461,7 @@ namespace {
490461

491462
/// If true, we're not done with our dataflow analysis yet.
492463
bool containsUndefinedValues() {
493-
return (!OutSelfConsumed.hasValue() ||
494-
!OutSelfInitialized.hasValue() ||
464+
return (!OutSelfInitialized.hasValue() ||
495465
OutAvailability.containsUnknownElements());
496466
}
497467
};
@@ -515,7 +485,6 @@ namespace {
515485
DIMemoryObjectInfo TheMemory;
516486

517487
SmallVectorImpl<DIMemoryUse> &Uses;
518-
TinyPtrVector<TermInst *> &FailableInits;
519488
TinyPtrVector<SILInstruction *> &StoresToSelf;
520489
SmallVectorImpl<SILInstruction *> &Destroys;
521490
std::vector<ConditionalDestroy> ConditionalDestroys;
@@ -566,7 +535,6 @@ namespace {
566535
int getAnyUninitializedMemberAtInst(SILInstruction *Inst, unsigned FirstElt,
567536
unsigned NumElts);
568537

569-
DIKind getSelfConsumedAtInst(SILInstruction *Inst);
570538
DIKind getSelfInitializedAtInst(SILInstruction *Inst);
571539

572540
bool isInitializedAtUse(const DIMemoryUse &Use,
@@ -601,7 +569,6 @@ namespace {
601569
void putIntoWorkList(SILBasicBlock *BB, WorkListType &WorkList);
602570
void computePredsLiveOut(SILBasicBlock *BB);
603571
void getOutAvailability(SILBasicBlock *BB, AvailabilitySet &Result);
604-
void getOutSelfConsumed(SILBasicBlock *BB, Optional<DIKind> &Result);
605572
void getOutSelfInitialized(SILBasicBlock *BB, Optional<DIKind> &Result);
606573

607574
bool shouldEmitError(SILInstruction *Inst);
@@ -620,8 +587,8 @@ namespace {
620587
LifetimeChecker::LifetimeChecker(const DIMemoryObjectInfo &TheMemory,
621588
DIElementUseInfo &UseInfo)
622589
: Module(TheMemory.MemoryInst->getModule()), TheMemory(TheMemory),
623-
Uses(UseInfo.Uses), FailableInits(UseInfo.FailableInits),
624-
StoresToSelf(UseInfo.StoresToSelf), Destroys(UseInfo.Releases) {
590+
Uses(UseInfo.Uses), StoresToSelf(UseInfo.StoresToSelf),
591+
Destroys(UseInfo.Releases) {
625592

626593
// The first step of processing an element is to collect information about the
627594
// element into data structures we use later.
@@ -653,16 +620,6 @@ LifetimeChecker::LifetimeChecker(const DIMemoryObjectInfo &TheMemory,
653620
getBlockInfo(bb).markStoreToSelf();
654621
}
655622

656-
// Mark blocks where the self value has been consumed.
657-
for (auto *I : FailableInits) {
658-
auto *bb = I->getSuccessors()[1].getBB();
659-
660-
// Horrible hack. Failing inits create critical edges, where all
661-
// 'return nil's end up. We'll split the edge later.
662-
bool criticalEdge = isCriticalEdge(I, 1);
663-
getBlockInfo(bb).markFailure(criticalEdge);
664-
}
665-
666623
// If isn't really a use, but we account for the alloc_box/mark_uninitialized
667624
// as a use so we see it in our dataflow walks.
668625
NonLoadUses[TheMemory.MemoryInst] = ~0U;
@@ -2535,14 +2492,6 @@ getOutAvailability(SILBasicBlock *BB, AvailabilitySet &Result) {
25352492
DEBUG(llvm::dbgs() << " Result: " << Result << "\n");
25362493
}
25372494

2538-
void LifetimeChecker::
2539-
getOutSelfConsumed(SILBasicBlock *BB, Optional<DIKind> &Result) {
2540-
computePredsLiveOut(BB);
2541-
2542-
for (auto *Pred : BB->getPredecessorBlocks())
2543-
Result = mergeKinds(Result, getBlockInfo(Pred).OutSelfConsumed);
2544-
}
2545-
25462495
void LifetimeChecker::
25472496
getOutSelfInitialized(SILBasicBlock *BB, Optional<DIKind> &Result) {
25482497
computePredsLiveOut(BB);
@@ -2685,32 +2634,6 @@ int LifetimeChecker::getAnyUninitializedMemberAtInst(SILInstruction *Inst,
26852634
return -1;
26862635
}
26872636

2688-
/// getSelfConsumedAtInst - Compute the liveness state for any number of tuple
2689-
/// elements at the specified instruction. The elements are returned as an
2690-
/// AvailabilitySet. Elements outside of the range specified may not be
2691-
/// computed correctly.
2692-
DIKind LifetimeChecker::
2693-
getSelfConsumedAtInst(SILInstruction *Inst) {
2694-
DEBUG(llvm::dbgs() << "Get self consumed at " << *Inst);
2695-
2696-
SILBasicBlock *InstBB = Inst->getParent();
2697-
auto &BlockInfo = getBlockInfo(InstBB);
2698-
2699-
if (BlockInfo.LocalSelfConsumed.hasValue())
2700-
return *BlockInfo.LocalSelfConsumed;
2701-
2702-
Optional<DIKind> Result;
2703-
getOutSelfConsumed(InstBB, Result);
2704-
2705-
// If the result wasn't computed, we must be analyzing code within
2706-
// an unreachable cycle that is not dominated by "TheMemory". Just force
2707-
// the result to unconsumed so that clients don't have to handle this.
2708-
if (!Result.hasValue())
2709-
Result = DIKind::No;
2710-
2711-
return *Result;
2712-
}
2713-
27142637
/// getSelfInitializedAtInst - Check if the self box in an initializer has
27152638
/// a fully initialized value at the specified instruction.
27162639
///

0 commit comments

Comments
 (0)