Skip to content

Commit cee2af0

Browse files
authored
Merge pull request #30289 from gottesmm/pr-645bd01cfa67ffe64ed23d74e1ee1333fce6ba8a
[semantic-arc-opts] Implement @owned phi web elimination for phi webs with a single phi node that only have copy_value introducers.
2 parents 98494bb + 6fee59b commit cee2af0

File tree

5 files changed

+956
-50
lines changed

5 files changed

+956
-50
lines changed

Diff for: include/swift/Basic/FrozenMultiMap.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,17 @@ class FrozenMultiMap {
9191
frozen = true;
9292
}
9393

94+
/// Reset the frozen multimap in an unfrozen state with its storage cleared.
95+
void reset() {
96+
storage.clear();
97+
frozen = false;
98+
}
99+
94100
unsigned size() const { return storage.size(); }
95101
bool empty() const { return storage.empty(); }
96102

97103
struct iterator : std::iterator<std::forward_iterator_tag,
98-
std::pair<Key, ArrayRef<Value>>> {
104+
std::pair<Key, PairToSecondEltRange>> {
99105
using base_iterator = typename decltype(storage)::iterator;
100106

101107
FrozenMultiMap &map;
@@ -159,9 +165,11 @@ class FrozenMultiMap {
159165
}
160166
};
161167

168+
using RangeType = llvm::iterator_range<iterator>;
169+
162170
/// Return a range of (key, ArrayRef<Value>) pairs. The keys are guaranteed to
163171
/// be in key sorted order and the ArrayRef<Value> are in insertion order.
164-
llvm::iterator_range<iterator> getRange() const {
172+
RangeType getRange() const {
165173
assert(isFrozen() &&
166174
"Can not create range until data structure is frozen?!");
167175
auto *self = const_cast<FrozenMultiMap *>(this);

Diff for: include/swift/SIL/OwnershipUtils.h

+22
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,28 @@ struct OwnedValueIntroducer {
598598
return OwnedValueIntroducer(value, *kind);
599599
}
600600

601+
/// Returns true if this owned introducer is able to be converted into a
602+
/// guaranteed form if none of its uses are consuming uses (looking through
603+
/// forwarding uses).
604+
bool isConvertableToGuaranteed() const {
605+
switch (kind) {
606+
case OwnedValueIntroducerKind::Copy:
607+
case OwnedValueIntroducerKind::LoadCopy:
608+
return true;
609+
case OwnedValueIntroducerKind::Apply:
610+
case OwnedValueIntroducerKind::BeginApply:
611+
case OwnedValueIntroducerKind::TryApply:
612+
case OwnedValueIntroducerKind::LoadTake:
613+
case OwnedValueIntroducerKind::Phi:
614+
case OwnedValueIntroducerKind::FunctionArgument:
615+
case OwnedValueIntroducerKind::PartialApplyInit:
616+
case OwnedValueIntroducerKind::AllocBoxInit:
617+
case OwnedValueIntroducerKind::AllocRefInit:
618+
return false;
619+
}
620+
llvm_unreachable("Covered switch isn't covered?!");
621+
}
622+
601623
bool operator==(const OwnedValueIntroducer &other) const {
602624
return value == other.value;
603625
}

0 commit comments

Comments
 (0)