@@ -584,7 +584,7 @@ extension LifetimeDependenceDefUseWalker {
584584
585585 // Override ForwardingDefUseWalker.
586586 mutating func walkDown( operand: Operand ) -> WalkResult {
587- // Initially delegate all usess to OwnershipUseVisitor.
587+ // Initially delegate all uses to OwnershipUseVisitor.
588588 // walkDownDefault will be called for uses that forward ownership.
589589 return classify ( operand: operand)
590590 }
@@ -631,7 +631,7 @@ extension LifetimeDependenceDefUseWalker {
631631 // like [nonescaping] even though they are not considered OSSA
632632 // borrows until after resolution.
633633 assert ( operand == mdi. baseOperand)
634- return dependentUse ( of: operand, into : mdi)
634+ return dependentUse ( of: operand, dependentValue : mdi)
635635
636636 case is ExistentialMetatypeInst , is FixLifetimeInst , is WitnessMethodInst ,
637637 is DynamicMethodBranchInst , is ValueMetatypeInst ,
@@ -676,11 +676,24 @@ extension LifetimeDependenceDefUseWalker {
676676 return escapingDependence ( on: operand)
677677 }
678678
679- mutating func dependentUse( of operand: Operand , into value: Value )
679+ // Handle address or non-address operands.
680+ mutating func dependentUse( of operand: Operand , dependentValue value: Value )
680681 -> WalkResult {
681682 return walkDownUses ( of: value, using: operand)
682683 }
683684
685+ // Handle address or non-address operands.
686+ mutating func dependentUse( of operand: Operand , dependentAddress address: Value )
687+ -> WalkResult {
688+ // Consider this a leaf use in addition to the dependent address uses, which might all occur earlier.
689+ if leafUse ( of: operand) == . abortWalk {
690+ return . abortWalk
691+ }
692+ // The lifetime dependence is effectively "copied into" the dependent address. Find all uses of the dependent
693+ // address as if this were a stored use.
694+ return visitStoredUses ( of: operand, into: address)
695+ }
696+
684697 mutating func borrowingUse( of operand: Operand ,
685698 by borrowInst: BorrowingInstruction )
686699 -> WalkResult {
@@ -736,7 +749,7 @@ extension LifetimeDependenceDefUseWalker {
736749 return visitAppliedUse ( of: operand, by: apply)
737750 }
738751
739- mutating func loadedAddressUse( of operand: Operand , into value: Value ) -> WalkResult {
752+ mutating func loadedAddressUse( of operand: Operand , intoValue value: Value ) -> WalkResult {
740753 // Record the load itself, in case the loaded value is Escapable.
741754 if leafUse ( of: operand) == . abortWalk {
742755 return . abortWalk
@@ -745,7 +758,7 @@ extension LifetimeDependenceDefUseWalker {
745758 }
746759
747760 // copy_addr
748- mutating func loadedAddressUse( of operand: Operand , into address: Operand ) -> WalkResult {
761+ mutating func loadedAddressUse( of operand: Operand , intoAddress address: Operand ) -> WalkResult {
749762 if leafUse ( of: operand) == . abortWalk {
750763 return . abortWalk
751764 }
@@ -761,18 +774,12 @@ extension LifetimeDependenceDefUseWalker {
761774 }
762775
763776 mutating func dependentAddressUse( of operand: Operand , dependentValue value: Value ) -> WalkResult {
764- walkDownUses ( of: value , using : operand )
777+ dependentUse ( of: operand , dependentValue : value )
765778 }
766779
767780 // mark_dependence_addr
768781 mutating func dependentAddressUse( of operand: Operand , dependentAddress address: Value ) -> WalkResult {
769- // Consider this a leaf use in addition to the dependent address uses, which might all occur earlier.
770- if leafUse ( of: operand) == . abortWalk {
771- return . abortWalk
772- }
773- // The lifetime dependence is effectively "copied into" the dependent address. Find all uses of the dependent
774- // address as if this were a stored use.
775- return visitStoredUses ( of: operand, into: address)
782+ dependentUse ( of: operand, dependentAddress: address)
776783 }
777784
778785 mutating func escapingAddressUse( of operand: Operand ) -> WalkResult {
@@ -898,19 +905,30 @@ extension LifetimeDependenceDefUseWalker {
898905 case . load:
899906 switch localAccess. instruction! {
900907 case let load as LoadInst :
901- return loadedAddressUse ( of: localAccess. operand!, into : load)
908+ return loadedAddressUse ( of: localAccess. operand!, intoValue : load)
902909 case let load as LoadBorrowInst :
903- return loadedAddressUse ( of: localAccess. operand!, into : load)
910+ return loadedAddressUse ( of: localAccess. operand!, intoValue : load)
904911 case let copyAddr as SourceDestAddrInstruction :
905- return loadedAddressUse ( of: localAccess. operand!, into: copyAddr. destinationOperand)
912+ return loadedAddressUse ( of: localAccess. operand!, intoAddress: copyAddr. destinationOperand)
913+ default :
914+ return . abortWalk
915+ }
916+ case . dependenceSource:
917+ switch localAccess. instruction! {
918+ case let md as MarkDependenceInst :
919+ if md. type. isAddress {
920+ return loadedAddressUse ( of: localAccess. operand!, intoAddress: md. valueOperand)
921+ }
922+ return loadedAddressUse ( of: localAccess. operand!, intoValue: md)
923+ case let md as MarkDependenceAddrInst :
924+ return loadedAddressUse ( of: localAccess. operand!, intoAddress: md. addressOperand)
906925 default :
907926 return . abortWalk
908927 }
909- case . dependence:
910- // An address-forwarding mark_dependence is simply a marker that indicates the start of an in-memory
911- // dependent value. Typically, it has no uses. If it does have uses, then they are visited earlier by
912- // LocalVariableAccessWalker to record any other local accesses.
913- return . continueWalk
928+ case . dependenceDest:
929+ // Simply a marker that indicates the start of an in-memory dependent value. If this was a mark_dependence, uses
930+ // of its forwarded address has were visited by LocalVariableAccessWalker and recorded as separate local accesses.
931+ return . continueWalk
914932 case . store:
915933 let si = localAccess. operand!. instruction as! StoringInstruction
916934 assert ( si. sourceOperand == initialValue, " the only reachable store should be the current assignment " )
@@ -948,13 +966,13 @@ extension LifetimeDependenceDefUseWalker {
948966 // because a mark_dependence [nonescaping] represents the
949967 // dependence.
950968 if let result = apply. singleDirectResult, !result. isEscapable {
951- if dependentUse ( of: operand, into : result) == . abortWalk {
969+ if dependentUse ( of: operand, dependentValue : result) == . abortWalk {
952970 return . abortWalk
953971 }
954972 }
955973 for resultAddr in apply. indirectResultOperands
956974 where !resultAddr. value. isEscapable {
957- if visitStoredUses ( of: operand, into : resultAddr. value) == . abortWalk {
975+ if dependentUse ( of: operand, dependentAddress : resultAddr. value) == . abortWalk {
958976 return . abortWalk
959977 }
960978 }
0 commit comments