Skip to content

Commit 7feb7e2

Browse files
committed
[NFC] FSPrunedLiveness: Move impl to cpp file.
The function is long and will get longer.
1 parent 234e8bc commit 7feb7e2

File tree

2 files changed

+45
-42
lines changed

2 files changed

+45
-42
lines changed

include/swift/SIL/FieldSensitivePrunedLiveness.h

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -308,48 +308,7 @@ struct TypeTreeLeafTypeRange {
308308
/// This is a subset of (usually equal to) the bits of op->getType() in \p
309309
/// rootValue.
310310
static std::optional<TypeTreeLeafTypeRange> get(Operand *op,
311-
SILValue rootValue) {
312-
auto projectedValue = op->get();
313-
auto startEltOffset = SubElementOffset::compute(projectedValue, rootValue);
314-
if (!startEltOffset)
315-
return std::nullopt;
316-
317-
// A drop_deinit only consumes the deinit bit of its operand.
318-
if (isa<DropDeinitInst>(op->getUser())) {
319-
auto upperBound = *startEltOffset + TypeSubElementCount(projectedValue);
320-
return {{upperBound - 1, upperBound}};
321-
}
322-
323-
// An `inject_enum_addr` only initializes the enum tag.
324-
if (auto inject = dyn_cast<InjectEnumAddrInst>(op->getUser())) {
325-
auto upperBound = *startEltOffset + TypeSubElementCount(projectedValue);
326-
unsigned payloadUpperBound = 0;
327-
if (inject->getElement()->hasAssociatedValues()) {
328-
auto payloadTy = projectedValue->getType()
329-
.getEnumElementType(inject->getElement(), op->getFunction());
330-
331-
payloadUpperBound = *startEltOffset
332-
+ TypeSubElementCount(payloadTy, op->getFunction());
333-
}
334-
// TODO: account for deinit component if enum has deinit.
335-
assert(!projectedValue->getType().isValueTypeWithDeinit());
336-
return {{payloadUpperBound, upperBound}};
337-
}
338-
339-
// Uses that borrow a value do not involve the deinit bit.
340-
//
341-
// FIXME: This shouldn't be limited to applies.
342-
unsigned deinitBitOffset = 0;
343-
if (op->get()->getType().isValueTypeWithDeinit() &&
344-
op->getOperandOwnership() == OperandOwnership::Borrow &&
345-
ApplySite::isa(op->getUser())) {
346-
deinitBitOffset = 1;
347-
}
348-
349-
return {{*startEltOffset, *startEltOffset +
350-
TypeSubElementCount(projectedValue) -
351-
deinitBitOffset}};
352-
}
311+
SILValue rootValue);
353312

354313
static void constructProjectionsForNeededElements(
355314
SILValue rootValue, SILInstruction *insertPt,

lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,50 @@ void TypeTreeLeafTypeRange::constructFilteredProjections(
473473
llvm_unreachable("Not understand subtype");
474474
}
475475

476+
std::optional<TypeTreeLeafTypeRange>
477+
TypeTreeLeafTypeRange::get(Operand *op, SILValue rootValue) {
478+
auto projectedValue = op->get();
479+
auto startEltOffset = SubElementOffset::compute(projectedValue, rootValue);
480+
if (!startEltOffset)
481+
return std::nullopt;
482+
483+
// A drop_deinit only consumes the deinit bit of its operand.
484+
if (isa<DropDeinitInst>(op->getUser())) {
485+
auto upperBound = *startEltOffset + TypeSubElementCount(projectedValue);
486+
return {{upperBound - 1, upperBound}};
487+
}
488+
489+
// An `inject_enum_addr` only initializes the enum tag.
490+
if (auto inject = dyn_cast<InjectEnumAddrInst>(op->getUser())) {
491+
auto upperBound = *startEltOffset + TypeSubElementCount(projectedValue);
492+
unsigned payloadUpperBound = 0;
493+
if (inject->getElement()->hasAssociatedValues()) {
494+
auto payloadTy = projectedValue->getType().getEnumElementType(
495+
inject->getElement(), op->getFunction());
496+
497+
payloadUpperBound =
498+
*startEltOffset + TypeSubElementCount(payloadTy, op->getFunction());
499+
}
500+
// TODO: account for deinit component if enum has deinit.
501+
assert(!projectedValue->getType().isValueTypeWithDeinit());
502+
return {{payloadUpperBound, upperBound}};
503+
}
504+
505+
// Uses that borrow a value do not involve the deinit bit.
506+
//
507+
// FIXME: This shouldn't be limited to applies.
508+
unsigned deinitBitOffset = 0;
509+
if (op->get()->getType().isValueTypeWithDeinit() &&
510+
op->getOperandOwnership() == OperandOwnership::Borrow &&
511+
ApplySite::isa(op->getUser())) {
512+
deinitBitOffset = 1;
513+
}
514+
515+
return {{*startEltOffset, *startEltOffset +
516+
TypeSubElementCount(projectedValue) -
517+
deinitBitOffset}};
518+
}
519+
476520
void TypeTreeLeafTypeRange::constructProjectionsForNeededElements(
477521
SILValue rootValue, SILInstruction *insertPt,
478522
SmallBitVector &neededElements,

0 commit comments

Comments
 (0)