Skip to content

Commit 845e63f

Browse files
committed
Support ownershipKind in SILSSAUpdater
1 parent 341facf commit 845e63f

File tree

11 files changed

+30
-17
lines changed

11 files changed

+30
-17
lines changed

include/swift/SILOptimizer/Utils/SILSSAUpdater.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class SILSSAUpdater {
4949

5050
SILType type;
5151

52+
ValueOwnershipKind ownershipKind;
53+
5254
// The SSAUpdaterTraits specialization uses this sentinel to mark 'new' phi
5355
// nodes (all the incoming edge arguments have this sentinel set).
5456
std::unique_ptr<SILUndef, void (*)(SILUndef *)> phiSentinel;
@@ -69,8 +71,8 @@ class SILSSAUpdater {
6971
insertedPhis = inputInsertedPhis;
7072
}
7173

72-
/// Initialize for a use of a value of type.
73-
void initialize(SILType type);
74+
/// Initialize for a use of a value of type and ownershipKind
75+
void initialize(SILType type, ValueOwnershipKind ownershipKind);
7476

7577
bool hasValueForBlock(SILBasicBlock *block) const;
7678
void addAvailableValue(SILBasicBlock *block, SILValue value);

lib/SILOptimizer/LoopTransforms/ArrayPropertyOpt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ class RegionCloner : public SILCloner<RegionCloner> {
516516
return;
517517

518518
// Update SSA form.
519-
SSAUp.initialize(V->getType());
519+
SSAUp.initialize(V->getType(), V.getOwnershipKind());
520520
SSAUp.addAvailableValue(OrigBB, V);
521521
SILValue NewVal = getMappedValue(V);
522522
SSAUp.addAvailableValue(getOpBasicBlock(OrigBB), NewVal);

lib/SILOptimizer/LoopTransforms/LICM.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,8 @@ hoistLoadsAndStores(AccessPath accessPath, SILLoop *loop) {
13261326

13271327
if (!storeAddr) {
13281328
storeAddr = SI->getDest();
1329-
ssaUpdater.initialize(storeAddr->getType().getObjectType());
1329+
ssaUpdater.initialize(storeAddr->getType().getObjectType(),
1330+
storeAddr.getOwnershipKind());
13301331
} else if (SI->getDest()->getType() != storeAddr->getType()) {
13311332
// This transformation assumes that the values of all stores in the loop
13321333
// must be interchangeable. It won't work if stores different types

lib/SILOptimizer/LoopTransforms/LoopRotate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static void updateSSAForUseOfValue(
131131
assert(Res->getType() == MappedValue->getType() && "The types must match");
132132

133133
insertedPhis.clear();
134-
updater.initialize(Res->getType());
134+
updater.initialize(Res->getType(), Res.getOwnershipKind());
135135
updater.addAvailableValue(Header, Res);
136136
updater.addAvailableValue(EntryCheckBlock, MappedValue);
137137

lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ updateSSA(SILModule &M, SILLoop *Loop,
335335
if (!Loop->contains(Use->getUser()->getParent()))
336336
UseList.push_back(UseWrapper(Use));
337337
// Update SSA of use with the available values.
338-
SSAUp.initialize(OrigValue->getType());
338+
SSAUp.initialize(OrigValue->getType(), OrigValue.getOwnershipKind());
339339
SSAUp.addAvailableValue(OrigValue->getParentBlock(), OrigValue);
340340
for (auto NewValue : MapEntry.second)
341341
SSAUp.addAvailableValue(NewValue->getParentBlock(), NewValue);

lib/SILOptimizer/Mandatory/ClosureLifetimeFixup.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
245245
// lifetime respecting loops.
246246
SmallVector<SILPhiArgument *, 8> insertedPhis;
247247
SILSSAUpdater updater(&insertedPhis);
248-
updater.initialize(optionalEscapingClosureTy);
248+
updater.initialize(optionalEscapingClosureTy, fn.hasOwnership()
249+
? OwnershipKind::Owned
250+
: OwnershipKind::None);
249251

250252
// Create an Optional<() -> ()>.none in the entry block of the function and
251253
// add it as an available value to the SSAUpdater.
@@ -850,7 +852,9 @@ static bool fixupCopyBlockWithoutEscaping(CopyBlockWithoutEscapingInst *cb,
850852

851853
SmallVector<SILPhiArgument *, 8> insertedPhis;
852854
SILSSAUpdater updater(&insertedPhis);
853-
updater.initialize(optionalEscapingClosureTy);
855+
updater.initialize(optionalEscapingClosureTy, fn.hasOwnership()
856+
? OwnershipKind::Owned
857+
: OwnershipKind::None);
854858

855859
// Create the Optional.none as the beginning available value.
856860
SILValue entryBlockOptionalNone;

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,8 @@ AvailableValueAggregator::aggregateFullyAvailableValue(SILType loadTy,
684684
// have multiple insertion points if we are storing exactly the same value
685685
// implying that we can just copy firstVal at each insertion point.
686686
SILSSAUpdater updater(&insertedPhiNodes);
687-
updater.initialize(loadTy);
687+
updater.initialize(loadTy, B.hasOwnership() ? OwnershipKind::Owned
688+
: OwnershipKind::None);
688689

689690
Optional<SILValue> singularValue;
690691
for (auto *insertPt : insertPts) {
@@ -860,7 +861,8 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType loadTy,
860861
// never have the same value along all paths unless we have a trivial value
861862
// meaning the SSA updater given a non-trivial value must /always/ be used.
862863
SILSSAUpdater updater(&insertedPhiNodes);
863-
updater.initialize(loadTy);
864+
updater.initialize(loadTy, B.hasOwnership() ? OwnershipKind::Owned
865+
: OwnershipKind::None);
864866

865867
Optional<SILValue> singularValue;
866868
for (auto *i : insertPts) {

lib/SILOptimizer/Transforms/DeadObjectElimination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ static void insertReleases(ArrayRef<StoreInst*> Stores,
559559
assert(!Stores.empty());
560560
SILValue StVal = Stores.front()->getSrc();
561561

562-
SSAUp.initialize(StVal->getType());
562+
SSAUp.initialize(StVal->getType(), StVal.getOwnershipKind());
563563

564564
for (auto *Store : Stores)
565565
SSAUp.addAvailableValue(Store->getParent(), Store->getSrc());

lib/SILOptimizer/Transforms/RedundantLoadElimination.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,9 @@ SILValue RLEContext::computePredecessorLocationValue(SILBasicBlock *BB,
13491349
// the SSAUpdater.
13501350
Updater.initialize(
13511351
L.getType(&BB->getModule(), TypeExpansionContext(*BB->getParent()))
1352-
.getObjectType());
1352+
.getObjectType(),
1353+
Values[0].second.getOwnershipKind());
1354+
13531355
for (auto V : Values) {
13541356
Updater.addAvailableValue(V.first, V.second);
13551357
}

lib/SILOptimizer/Utils/BasicBlockOptUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void BasicBlockCloner::updateSSAAfterCloning() {
101101

102102
SILSSAUpdater ssaUpdater;
103103
for (auto availValPair : availVals) {
104-
ValueBase *inst = availValPair.first;
104+
auto inst = availValPair.first;
105105
if (inst->use_empty())
106106
continue;
107107

@@ -112,7 +112,7 @@ void BasicBlockCloner::updateSSAAfterCloning() {
112112
for (auto *use : inst->getUses())
113113
useList.push_back(UseWrapper(use));
114114

115-
ssaUpdater.initialize(inst->getType());
115+
ssaUpdater.initialize(inst->getType(), inst.getOwnershipKind());
116116
ssaUpdater.addAvailableValue(origBB, inst);
117117
ssaUpdater.addAvailableValue(getNewBB(), newResult);
118118

0 commit comments

Comments
 (0)