@@ -410,21 +410,21 @@ inline InnerBorrowKind meet(InnerBorrowKind lhs, InnerBorrowKind rhs) {
410
410
// / Summarize reborrows and pointer escapes that affect a live range. Reborrows
411
411
// / and pointer escapes that are encapsulated in a nested borrow don't affect
412
412
// / the outer live range.
413
- struct SimpleLiveRangeSummary {
413
+ struct LiveRangeSummary {
414
414
InnerBorrowKind innerBorrowKind;
415
415
AddressUseKind addressUseKind;
416
416
417
- SimpleLiveRangeSummary (): innerBorrowKind(InnerBorrowKind::Contained),
418
- addressUseKind (AddressUseKind::NonEscaping)
419
- {}
417
+ LiveRangeSummary ()
418
+ : innerBorrowKind(InnerBorrowKind::Contained),
419
+ addressUseKind (AddressUseKind::NonEscaping) {}
420
420
421
421
void meet (const InnerBorrowKind lhs) {
422
422
innerBorrowKind = swift::meet (innerBorrowKind, lhs);
423
423
}
424
424
void meet (const AddressUseKind lhs) {
425
425
addressUseKind = swift::meet (addressUseKind, lhs);
426
426
}
427
- void meet (const SimpleLiveRangeSummary lhs) {
427
+ void meet (const LiveRangeSummary lhs) {
428
428
meet (lhs.innerBorrowKind );
429
429
meet (lhs.addressUseKind );
430
430
}
@@ -601,13 +601,15 @@ class PrunedLiveRange : public PrunedLiveness {
601
601
PrunedLiveRange (SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr )
602
602
: PrunedLiveness(discoveredBlocks) {}
603
603
604
- SimpleLiveRangeSummary recursivelyUpdateForDef (SILValue initialDef,
605
- ValueSet &visited,
606
- SILValue value);
604
+ LiveRangeSummary recursivelyUpdateForDef (SILValue initialDef,
605
+ ValueSet &visited,
606
+ SILValue value);
607
607
608
608
public:
609
- // / Update liveness for all direct uses of \p def.
610
- SimpleLiveRangeSummary updateForDef (SILValue def);
609
+ // / Update liveness for all direct uses of \p def. Transitively follows
610
+ // / guaranteed forwards up to but not including guaranteed phis. If \p def is
611
+ // / used by a guaranteed phi return InnerBorrowKind::Reborrowed.
612
+ LiveRangeSummary updateForDef (SILValue def);
611
613
612
614
// / Check if \p inst occurs in between the definition this def and the
613
615
// / liveness boundary.
@@ -716,7 +718,7 @@ class SSAPrunedLiveness : public PrunedLiveRange<SSAPrunedLiveness> {
716
718
// / jointly-post dominate if dead-end blocks are present. Nested scopes may
717
719
// / also lack scope-ending instructions, so the liveness of their nested uses
718
720
// / may be ignored.
719
- SimpleLiveRangeSummary computeSimple () {
721
+ LiveRangeSummary computeSimple () {
720
722
assert (def && " SSA def uninitialized" );
721
723
return updateForDef (def);
722
724
}
@@ -730,6 +732,13 @@ class MultiDefPrunedLiveness : public PrunedLiveRange<MultiDefPrunedLiveness> {
730
732
NodeSetVector defs;
731
733
BasicBlockSet defBlocks;
732
734
735
+ void initializeDefNode (SILNode *def) {
736
+ defs.insert (def);
737
+ auto *block = def->getParentBlock ();
738
+ defBlocks.insert (block);
739
+ initializeDefBlock (block);
740
+ }
741
+
733
742
public:
734
743
MultiDefPrunedLiveness (
735
744
SILFunction *function,
@@ -741,16 +750,25 @@ class MultiDefPrunedLiveness : public PrunedLiveRange<MultiDefPrunedLiveness> {
741
750
llvm_unreachable (" multi-def liveness cannot be reused" );
742
751
}
743
752
744
- void initializeDef (SILNode *def) {
745
- assert (isa<SILInstruction>(def) || isa<SILArgument>(def));
746
- defs.insert (def);
747
- auto *block = def->getParentBlock ();
748
- defBlocks.insert (block);
749
- initializeDefBlock (block);
753
+ void initializeDef (SILInstruction *defInst) {
754
+ initializeDefNode (defInst->asSILNode ());
755
+ }
756
+
757
+ void initializeDef (SILArgument *defArg) { initializeDefNode (defArg); }
758
+
759
+ void initializeDef (SILValue value) {
760
+ if (auto arg = dyn_cast<SILArgument>(value)) {
761
+ initializeDefNode (arg);
762
+ } else {
763
+ initializeDef (value->getDefiningInstruction ());
764
+ }
750
765
}
751
766
752
767
bool isInitialized () const { return !defs.empty (); }
753
768
769
+ NodeSetVector::iterator defBegin () const { return defs.begin (); }
770
+ NodeSetVector::iterator defEnd () const { return defs.end (); }
771
+
754
772
bool isDef (SILInstruction *inst) const {
755
773
return defs.contains (cast<SILNode>(inst));
756
774
}
@@ -779,7 +797,7 @@ class MultiDefPrunedLiveness : public PrunedLiveRange<MultiDefPrunedLiveness> {
779
797
// / jointly-post dominate if dead-end blocks are present. Nested scopes may
780
798
// / also lack scope-ending instructions, so the liveness of their nested uses
781
799
// / may be ignored.
782
- SimpleLiveRangeSummary computeSimple ();
800
+ LiveRangeSummary computeSimple ();
783
801
};
784
802
785
803
// ===----------------------------------------------------------------------===//
0 commit comments