@@ -410,21 +410,21 @@ inline InnerBorrowKind meet(InnerBorrowKind lhs, InnerBorrowKind rhs) {
410410// / Summarize reborrows and pointer escapes that affect a live range. Reborrows
411411// / and pointer escapes that are encapsulated in a nested borrow don't affect
412412// / the outer live range.
413- struct SimpleLiveRangeSummary {
413+ struct LiveRangeSummary {
414414 InnerBorrowKind innerBorrowKind;
415415 AddressUseKind addressUseKind;
416416
417- SimpleLiveRangeSummary (): innerBorrowKind(InnerBorrowKind::Contained),
418- addressUseKind (AddressUseKind::NonEscaping)
419- {}
417+ LiveRangeSummary ()
418+ : innerBorrowKind(InnerBorrowKind::Contained),
419+ addressUseKind (AddressUseKind::NonEscaping) {}
420420
421421 void meet (const InnerBorrowKind lhs) {
422422 innerBorrowKind = swift::meet (innerBorrowKind, lhs);
423423 }
424424 void meet (const AddressUseKind lhs) {
425425 addressUseKind = swift::meet (addressUseKind, lhs);
426426 }
427- void meet (const SimpleLiveRangeSummary lhs) {
427+ void meet (const LiveRangeSummary lhs) {
428428 meet (lhs.innerBorrowKind );
429429 meet (lhs.addressUseKind );
430430 }
@@ -601,13 +601,15 @@ class PrunedLiveRange : public PrunedLiveness {
601601 PrunedLiveRange (SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr )
602602 : PrunedLiveness(discoveredBlocks) {}
603603
604- SimpleLiveRangeSummary recursivelyUpdateForDef (SILValue initialDef,
605- ValueSet &visited,
606- SILValue value);
604+ LiveRangeSummary recursivelyUpdateForDef (SILValue initialDef,
605+ ValueSet &visited,
606+ SILValue value);
607607
608608public:
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);
611613
612614 // / Check if \p inst occurs in between the definition this def and the
613615 // / liveness boundary.
@@ -716,7 +718,7 @@ class SSAPrunedLiveness : public PrunedLiveRange<SSAPrunedLiveness> {
716718 // / jointly-post dominate if dead-end blocks are present. Nested scopes may
717719 // / also lack scope-ending instructions, so the liveness of their nested uses
718720 // / may be ignored.
719- SimpleLiveRangeSummary computeSimple () {
721+ LiveRangeSummary computeSimple () {
720722 assert (def && " SSA def uninitialized" );
721723 return updateForDef (def);
722724 }
@@ -730,6 +732,13 @@ class MultiDefPrunedLiveness : public PrunedLiveRange<MultiDefPrunedLiveness> {
730732 NodeSetVector defs;
731733 BasicBlockSet defBlocks;
732734
735+ void initializeDefNode (SILNode *def) {
736+ defs.insert (def);
737+ auto *block = def->getParentBlock ();
738+ defBlocks.insert (block);
739+ initializeDefBlock (block);
740+ }
741+
733742public:
734743 MultiDefPrunedLiveness (
735744 SILFunction *function,
@@ -741,16 +750,25 @@ class MultiDefPrunedLiveness : public PrunedLiveRange<MultiDefPrunedLiveness> {
741750 llvm_unreachable (" multi-def liveness cannot be reused" );
742751 }
743752
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+ }
750765 }
751766
752767 bool isInitialized () const { return !defs.empty (); }
753768
769+ NodeSetVector::iterator defBegin () const { return defs.begin (); }
770+ NodeSetVector::iterator defEnd () const { return defs.end (); }
771+
754772 bool isDef (SILInstruction *inst) const {
755773 return defs.contains (cast<SILNode>(inst));
756774 }
@@ -779,7 +797,7 @@ class MultiDefPrunedLiveness : public PrunedLiveRange<MultiDefPrunedLiveness> {
779797 // / jointly-post dominate if dead-end blocks are present. Nested scopes may
780798 // / also lack scope-ending instructions, so the liveness of their nested uses
781799 // / may be ignored.
782- SimpleLiveRangeSummary computeSimple ();
800+ LiveRangeSummary computeSimple ();
783801};
784802
785803// ===----------------------------------------------------------------------===//
0 commit comments