Skip to content

Commit a1d1099

Browse files
committed
[SIL] Promoted least-common ancestor to Dominance.
It's a general purpose helper and there will soon be another user.
1 parent 4e6eb51 commit a1d1099

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

include/swift/SIL/Dominance.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class DominanceInfo : public DominatorTreeBase {
6161
/// Does value A properly dominate instruction B?
6262
bool properlyDominates(SILValue a, SILInstruction *b);
6363

64+
/// The nearest block which dominates all the uses of \p value.
65+
SILBasicBlock *getLeastCommonAncestorOfUses(SILValue value);
66+
6467
void verify() const;
6568

6669
/// Return true if the other dominator tree does not match this dominator

lib/SIL/Utils/Dominance.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ bool DominanceInfo::properlyDominates(SILValue a, SILInstruction *b) {
7373
return false;
7474
}
7575

76+
SILBasicBlock *DominanceInfo::getLeastCommonAncestorOfUses(SILValue value) {
77+
SILBasicBlock *lca = nullptr;
78+
for (auto *use : value->getUses()) {
79+
auto *block = use->getParentBlock();
80+
lca = lca ? findNearestCommonDominator(lca, block) : block;
81+
}
82+
return lca;
83+
}
84+
7685
void DominanceInfo::verify() const {
7786
// Recompute.
7887
auto *F = getRoot()->getParent();

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,6 @@ class OpaqueStorageAllocation {
11271127

11281128
AllocStackInst *createStackAllocation(SILValue value);
11291129

1130-
SILBasicBlock *getLeastCommonAncestorOfUses(SILValue value);
1131-
11321130
void createStackAllocationStorage(SILValue value) {
11331131
pass.valueStorageMap.getStorage(value).storageAddress =
11341132
createStackAllocation(value);
@@ -1322,16 +1320,6 @@ void OpaqueStorageAllocation::removeAllocation(SILValue value) {
13221320
pass.deleter.forceDelete(allocInst);
13231321
}
13241322

1325-
SILBasicBlock *
1326-
OpaqueStorageAllocation::getLeastCommonAncestorOfUses(SILValue value) {
1327-
SILBasicBlock *lca = nullptr;
1328-
for (auto *use : value->getUses()) {
1329-
auto *block = use->getParentBlock();
1330-
lca = lca ? pass.domInfo->findNearestCommonDominator(lca, block) : block;
1331-
}
1332-
return lca;
1333-
}
1334-
13351323
// Create alloc_stack that dominates an owned value \p value. Create
13361324
// jointly-postdominating dealloc_stack instructions. Nesting will be fixed
13371325
// later.
@@ -1400,7 +1388,8 @@ void OpaqueStorageAllocation::finalizeOpaqueStorage() {
14001388
auto *alloc = maybeAlloc.value();
14011389

14021390
if (allocsToReposition.contains(alloc)) {
1403-
auto allocPt = &*getLeastCommonAncestorOfUses(alloc)->begin();
1391+
auto allocPt =
1392+
&*pass.domInfo->getLeastCommonAncestorOfUses(alloc)->begin();
14041393
alloc->moveBefore(allocPt);
14051394
}
14061395

0 commit comments

Comments
 (0)