@@ -308,60 +308,7 @@ struct TypeTreeLeafTypeRange {
308
308
// / This is a subset of (usually equal to) the bits of op->getType() in \p
309
309
// / rootValue.
310
310
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
- }
353
-
354
- // / Given a type \p rootType and a set of needed elements specified by the bit
355
- // / vector \p neededElements, place into \p foundContiguousTypeRanges a set of
356
- // / TypeTreeLeafTypeRanges that are associated with the bit vectors
357
- // / elements. As a constraint, we ensure that if \p neededElements has bits
358
- // / set that are part of subsequent fields of a type that is only partially
359
- // / needed, the two fields are represented as separate ranges. This ensures
360
- // / that it is easy to use this API to correspond to independent operations
361
- // / for the fields.
362
- static void convertNeededElementsToContiguousTypeRanges (
363
- SILFunction *fn, SILType rootType, SmallBitVector &neededElements,
364
- SmallVectorImpl<TypeTreeLeafTypeRange> &foundContiguousTypeRanges);
311
+ SILValue rootValue);
365
312
366
313
static void constructProjectionsForNeededElements (
367
314
SILValue rootValue, SILInstruction *insertPt,
@@ -533,10 +480,10 @@ class FieldSensitivePrunedLiveBlocks {
533
480
534
481
// / Returns the liveness in \p resultingFoundLiveness. We only return the
535
482
// / bits for endBitNo - startBitNo.
536
- void getLiveness (unsigned startBitNo, unsigned endBitNo ,
483
+ void getLiveness (SmallBitVector const &bitsOfInterest ,
537
484
SmallVectorImpl<IsLive> &resultingFoundLiveness) const {
538
- for (unsigned i = startBitNo, e = endBitNo; i != e; ++i ) {
539
- resultingFoundLiveness.push_back (getLiveness (i ));
485
+ for (auto bit : bitsOfInterest. set_bits () ) {
486
+ resultingFoundLiveness.push_back (getLiveness (bit ));
540
487
}
541
488
}
542
489
@@ -654,17 +601,26 @@ class FieldSensitivePrunedLiveBlocks {
654
601
void getBlockLiveness (SILBasicBlock *bb, unsigned startBitNo,
655
602
unsigned endBitNo,
656
603
SmallVectorImpl<IsLive> &foundLivenessInfo) const {
604
+ SmallBitVector bits (*numBitsToTrack);
605
+ for (auto index = startBitNo; index < endBitNo; ++index) {
606
+ bits.set (index);
607
+ }
608
+ getBlockLiveness (bb, bits, foundLivenessInfo);
609
+ }
610
+
611
+ void getBlockLiveness (SILBasicBlock *bb, SmallBitVector const &bits,
612
+ SmallVectorImpl<IsLive> &foundLivenessInfo) const {
657
613
assert (isInitialized ());
658
614
auto liveBlockIter = liveBlocks.find (bb);
659
615
if (liveBlockIter == liveBlocks.end ()) {
660
- for (unsigned i : range (endBitNo - startBitNo )) {
661
- (void )i ;
616
+ for (auto bit : bits. set_bits ( )) {
617
+ (void )bit ;
662
618
foundLivenessInfo.push_back (Dead);
663
619
}
664
620
return ;
665
621
}
666
622
667
- liveBlockIter->second .getLiveness (startBitNo, endBitNo , foundLivenessInfo);
623
+ liveBlockIter->second .getLiveness (bits , foundLivenessInfo);
668
624
}
669
625
670
626
llvm::StringRef getStringRef (IsLive isLive) const ;
@@ -972,6 +928,12 @@ class FieldSensitivePrunedLiveness {
972
928
resultingFoundLiveness);
973
929
}
974
930
931
+ void getBlockLiveness (SILBasicBlock *bb, SmallBitVector const &bits,
932
+ SmallVectorImpl<FieldSensitivePrunedLiveBlocks::IsLive>
933
+ &foundLivenessInfo) const {
934
+ liveBlocks.getBlockLiveness (bb, bits, foundLivenessInfo);
935
+ }
936
+
975
937
// / Return the liveness for this specific sub-element of our root value.
976
938
FieldSensitivePrunedLiveBlocks::IsLive
977
939
getBlockLiveness (SILBasicBlock *bb, unsigned subElementNumber) const {
@@ -1016,16 +978,16 @@ class FieldSensitivePrunedLiveness {
1016
978
return record->isInterestingUser (element);
1017
979
}
1018
980
1019
- // / Whether \p user uses the fields in \p range as indicated by \p kind.
981
+ // / Whether \p user uses the fields in \p bits as indicated by \p kind.
1020
982
bool isInterestingUserOfKind (SILInstruction *user, IsInterestingUser kind,
1021
- TypeTreeLeafTypeRange range ) const {
983
+ SmallBitVector const &bits ) const {
1022
984
auto *record = getInterestingUser (user);
1023
985
if (!record) {
1024
986
return kind == IsInterestingUser::NonUser;
1025
987
}
1026
988
1027
- for (auto element : range. getRange ()) {
1028
- if (record->isInterestingUser (element ) != kind)
989
+ for (auto bit : bits. set_bits ()) {
990
+ if (record->isInterestingUser (bit ) != kind)
1029
991
return false ;
1030
992
}
1031
993
return true ;
@@ -1172,10 +1134,10 @@ class FieldSensitivePrunedLiveRange : public FieldSensitivePrunedLiveness {
1172
1134
: FieldSensitivePrunedLiveness(fn, discoveredBlocks) {}
1173
1135
1174
1136
// / Check if \p inst occurs in between the definition of a def and the
1175
- // / liveness boundary for bits in \p span .
1137
+ // / liveness boundary for \p bits .
1176
1138
// /
1177
- // / NOTE: It is assumed that \p inst is correctly described by span .
1178
- bool isWithinBoundary (SILInstruction *inst, TypeTreeLeafTypeRange span ) const ;
1139
+ // / NOTE: It is assumed that \p inst is correctly described by \p bits .
1140
+ bool isWithinBoundary (SILInstruction *inst, SmallBitVector const &bits ) const ;
1179
1141
1180
1142
// / Customize updateForUse for FieldSensitivePrunedLiveness such that we check
1181
1143
// / that we consider defs as stopping liveness from being propagated up.
0 commit comments