Skip to content

Commit 2ab2252

Browse files
committed
[NFC] MoveOnly: Map inst to array of ranges.
1 parent ef6cde5 commit 2ab2252

File tree

2 files changed

+40
-37
lines changed

2 files changed

+40
-37
lines changed

include/swift/SIL/FieldSensitivePrunedLiveness.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,13 @@ struct TypeTreeLeafTypeRange {
291291
/// The leaf type sub-range of the type tree of \p rootAddress, consisting of
292292
/// \p projectedAddress and all of \p projectedAddress's descendent fields in
293293
/// the type tree.
294-
///
295-
/// \returns None if we are unable to understand the path in between \p
296-
/// projectedAddress and \p rootAddress.
297-
static std::optional<TypeTreeLeafTypeRange> get(SILValue projectedValue,
298-
SILValue rootValue) {
294+
static void get(SILValue projectedValue, SILValue rootValue,
295+
SmallVectorImpl<TypeTreeLeafTypeRange> &ranges) {
299296
auto startEltOffset = SubElementOffset::compute(projectedValue, rootValue);
300297
if (!startEltOffset)
301-
return std::nullopt;
302-
return {{*startEltOffset,
303-
*startEltOffset + TypeSubElementCount(projectedValue)}};
298+
return;
299+
ranges.push_back({*startEltOffset,
300+
*startEltOffset + TypeSubElementCount(projectedValue)});
304301
}
305302

306303
/// Which bits of \p rootValue are involved in \p op.

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,22 +1876,25 @@ void PartialReinitChecker::performPartialReinitChecking(
18761876
// By computing the bits here directly, we do not need to worry about
18771877
// having to split contiguous ranges into separate representable SILTypes.
18781878
SmallBitVector neededElements(useState.getNumSubelements());
1879-
auto range = *TypeTreeLeafTypeRange::get(value, useState.address);
1880-
for (unsigned index : range.getRange()) {
1881-
emittedError = !liveness.findEarlierConsumingUse(
1882-
initToValues.first, index,
1883-
[&](SILInstruction *consumingInst) -> bool {
1884-
return !checkForPartialMutation(
1885-
useState, diagnosticEmitter, PartialMutation::Kind::Reinit,
1886-
initToValues.first, value->getType(),
1887-
TypeTreeLeafTypeRange(index, index + 1),
1888-
PartialMutation::reinit(*consumingInst));
1889-
});
1890-
1891-
// If we emitted an error for this index break. We only want to emit one
1892-
// error per value.
1893-
if (emittedError)
1894-
break;
1879+
SmallVector<TypeTreeLeafTypeRange, 2> ranges;
1880+
TypeTreeLeafTypeRange::get(value, useState.address, ranges);
1881+
for (auto range : ranges) {
1882+
for (unsigned index : range.getRange()) {
1883+
emittedError = !liveness.findEarlierConsumingUse(
1884+
initToValues.first, index,
1885+
[&](SILInstruction *consumingInst) -> bool {
1886+
return !checkForPartialMutation(
1887+
useState, diagnosticEmitter, PartialMutation::Kind::Reinit,
1888+
initToValues.first, value->getType(),
1889+
TypeTreeLeafTypeRange(index, index + 1),
1890+
PartialMutation::reinit(*consumingInst));
1891+
});
1892+
1893+
// If we emitted an error for this index break. We only want to emit
1894+
// one error per value.
1895+
if (emittedError)
1896+
break;
1897+
}
18951898
}
18961899

18971900
// If we emitted an error for this value break. We only want to emit one
@@ -1912,19 +1915,22 @@ void PartialReinitChecker::performPartialReinitChecking(
19121915
// By computing the bits here directly, we do not need to worry about
19131916
// having to split contiguous ranges into separate representable SILTypes.
19141917
SmallBitVector neededElements(useState.getNumSubelements());
1915-
auto range = *TypeTreeLeafTypeRange::get(value, useState.address);
1916-
for (unsigned index : range.getRange()) {
1917-
emittedError = !liveness.findEarlierConsumingUse(
1918-
reinitToValues.first, index,
1919-
[&](SILInstruction *consumingInst) -> bool {
1920-
return !checkForPartialMutation(
1921-
useState, diagnosticEmitter, PartialMutation::Kind::Reinit,
1922-
reinitToValues.first, value->getType(),
1923-
TypeTreeLeafTypeRange(index, index + 1),
1924-
PartialMutation::reinit(*consumingInst));
1925-
});
1926-
if (emittedError)
1927-
break;
1918+
SmallVector<TypeTreeLeafTypeRange, 2> ranges;
1919+
TypeTreeLeafTypeRange::get(value, useState.address, ranges);
1920+
for (auto range : ranges) {
1921+
for (unsigned index : range.getRange()) {
1922+
emittedError = !liveness.findEarlierConsumingUse(
1923+
reinitToValues.first, index,
1924+
[&](SILInstruction *consumingInst) -> bool {
1925+
return !checkForPartialMutation(
1926+
useState, diagnosticEmitter, PartialMutation::Kind::Reinit,
1927+
reinitToValues.first, value->getType(),
1928+
TypeTreeLeafTypeRange(index, index + 1),
1929+
PartialMutation::reinit(*consumingInst));
1930+
});
1931+
if (emittedError)
1932+
break;
1933+
}
19281934
}
19291935
if (emittedError)
19301936
break;

0 commit comments

Comments
 (0)