Skip to content

Commit 9d7db52

Browse files
committed
[NFC] PrunedLiveness: Tweaked enum wrapper.
Clarify methods. Unfortunately, without other changes I haven't identified, the `enum class` can't be made an `enum` for ideal usage.
1 parent c289029 commit 9d7db52

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

include/swift/SIL/PrunedLiveness.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -391,22 +391,20 @@ class PrunedLiveness {
391391
Ending,
392392
// The instruction doesn't use the value.
393393
NonUse,
394-
};
395-
Value value;
394+
} value;
396395

397396
LifetimeEnding(Value value) : value(value) {}
398-
explicit LifetimeEnding(bool lifetimeEnding)
399-
: value(lifetimeEnding ? Value::Ending : Value::NonEnding) {}
400397
operator Value() const { return value; }
398+
399+
static LifetimeEnding forUse(bool lifetimeEnding) {
400+
return lifetimeEnding ? Value::Ending : Value::NonEnding;
401+
}
402+
bool isEnding() const { return value == Value::Ending; }
403+
401404
LifetimeEnding meet(LifetimeEnding const other) const {
402405
return value < other.value ? *this : other;
403406
}
404407
void meetInPlace(LifetimeEnding const other) { *this = meet(other); }
405-
bool isEnding() const { return value == Value::Ending; }
406-
407-
static LifetimeEnding NonUse() { return {Value::NonUse}; };
408-
static LifetimeEnding Ending() { return {Value::Ending}; };
409-
static LifetimeEnding NonEnding() { return {Value::NonEnding}; };
410408
};
411409

412410
protected:
@@ -467,8 +465,8 @@ class PrunedLiveness {
467465
auto useIter = users.find(user);
468466
if (useIter == users.end())
469467
return NonUser;
470-
return useIter->second == LifetimeEnding::Ending() ? LifetimeEndingUse
471-
: NonLifetimeEndingUse;
468+
return useIter->second.isEnding() ? LifetimeEndingUse
469+
: NonLifetimeEndingUse;
472470
}
473471

474472
using ConstUserRange =

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ void PrunedLiveRange<LivenessWithDefs>::updateForUse(
216216
template <typename LivenessWithDefs>
217217
void PrunedLiveRange<LivenessWithDefs>::updateForUse(SILInstruction *user,
218218
bool lifetimeEnding) {
219-
updateForUse(user, LifetimeEnding(lifetimeEnding));
219+
updateForUse(user, LifetimeEnding::forUse(lifetimeEnding));
220220
}
221221

222222
template <typename LivenessWithDefs>
223223
void PrunedLiveRange<LivenessWithDefs>::extendToNonUse(SILInstruction *inst) {
224-
updateForUse(inst, LifetimeEnding::NonUse());
224+
updateForUse(inst, LifetimeEnding::Value::NonUse);
225225
}
226226

227227
template <typename LivenessWithDefs>

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ void CanonicalizeOSSALifetime::visitExtendedUnconsumedBoundary(
674674
// Add "the instruction(s) before the terminator" of the predecessor to
675675
// liveness.
676676
predecessor->getTerminator()->visitPriorInstructions([&](auto *inst) {
677-
visitor(inst, PrunedLiveness::LifetimeEnding::NonUse());
677+
visitor(inst, PrunedLiveness::LifetimeEnding::Value::NonUse);
678678
return true;
679679
});
680680
}
@@ -688,7 +688,7 @@ void CanonicalizeOSSALifetime::visitExtendedUnconsumedBoundary(
688688
// hoisting it would avoid a copy.
689689
if (consumedAtExitBlocks.contains(block))
690690
continue;
691-
visitor(destroy, PrunedLiveness::LifetimeEnding::Ending());
691+
visitor(destroy, PrunedLiveness::LifetimeEnding::Value::Ending);
692692
}
693693
}
694694

0 commit comments

Comments
 (0)