Skip to content

Commit b195321

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 6c5ea6f commit b195321

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
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>

0 commit comments

Comments
 (0)