@@ -584,7 +584,7 @@ extension LifetimeDependenceDefUseWalker {
584
584
585
585
// Override ForwardingDefUseWalker.
586
586
mutating func walkDown( operand: Operand ) -> WalkResult {
587
- // Initially delegate all usess to OwnershipUseVisitor.
587
+ // Initially delegate all uses to OwnershipUseVisitor.
588
588
// walkDownDefault will be called for uses that forward ownership.
589
589
return classify ( operand: operand)
590
590
}
@@ -631,7 +631,7 @@ extension LifetimeDependenceDefUseWalker {
631
631
// like [nonescaping] even though they are not considered OSSA
632
632
// borrows until after resolution.
633
633
assert ( operand == mdi. baseOperand)
634
- return dependentUse ( of: operand, into : mdi)
634
+ return dependentUse ( of: operand, dependentValue : mdi)
635
635
636
636
case is ExistentialMetatypeInst , is FixLifetimeInst , is WitnessMethodInst ,
637
637
is DynamicMethodBranchInst , is ValueMetatypeInst ,
@@ -676,11 +676,24 @@ extension LifetimeDependenceDefUseWalker {
676
676
return escapingDependence ( on: operand)
677
677
}
678
678
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 )
680
681
-> WalkResult {
681
682
return walkDownUses ( of: value, using: operand)
682
683
}
683
684
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
+
684
697
mutating func borrowingUse( of operand: Operand ,
685
698
by borrowInst: BorrowingInstruction )
686
699
-> WalkResult {
@@ -736,7 +749,7 @@ extension LifetimeDependenceDefUseWalker {
736
749
return visitAppliedUse ( of: operand, by: apply)
737
750
}
738
751
739
- mutating func loadedAddressUse( of operand: Operand , into value: Value ) -> WalkResult {
752
+ mutating func loadedAddressUse( of operand: Operand , intoValue value: Value ) -> WalkResult {
740
753
// Record the load itself, in case the loaded value is Escapable.
741
754
if leafUse ( of: operand) == . abortWalk {
742
755
return . abortWalk
@@ -745,7 +758,7 @@ extension LifetimeDependenceDefUseWalker {
745
758
}
746
759
747
760
// copy_addr
748
- mutating func loadedAddressUse( of operand: Operand , into address: Operand ) -> WalkResult {
761
+ mutating func loadedAddressUse( of operand: Operand , intoAddress address: Operand ) -> WalkResult {
749
762
if leafUse ( of: operand) == . abortWalk {
750
763
return . abortWalk
751
764
}
@@ -761,18 +774,12 @@ extension LifetimeDependenceDefUseWalker {
761
774
}
762
775
763
776
mutating func dependentAddressUse( of operand: Operand , dependentValue value: Value ) -> WalkResult {
764
- walkDownUses ( of: value , using : operand )
777
+ dependentUse ( of: operand , dependentValue : value )
765
778
}
766
779
767
780
// mark_dependence_addr
768
781
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)
776
783
}
777
784
778
785
mutating func escapingAddressUse( of operand: Operand ) -> WalkResult {
@@ -898,19 +905,30 @@ extension LifetimeDependenceDefUseWalker {
898
905
case . load:
899
906
switch localAccess. instruction! {
900
907
case let load as LoadInst :
901
- return loadedAddressUse ( of: localAccess. operand!, into : load)
908
+ return loadedAddressUse ( of: localAccess. operand!, intoValue : load)
902
909
case let load as LoadBorrowInst :
903
- return loadedAddressUse ( of: localAccess. operand!, into : load)
910
+ return loadedAddressUse ( of: localAccess. operand!, intoValue : load)
904
911
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)
906
925
default :
907
926
return . abortWalk
908
927
}
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
914
932
case . store:
915
933
let si = localAccess. operand!. instruction as! StoringInstruction
916
934
assert ( si. sourceOperand == initialValue, " the only reachable store should be the current assignment " )
@@ -948,13 +966,13 @@ extension LifetimeDependenceDefUseWalker {
948
966
// because a mark_dependence [nonescaping] represents the
949
967
// dependence.
950
968
if let result = apply. singleDirectResult, !result. isEscapable {
951
- if dependentUse ( of: operand, into : result) == . abortWalk {
969
+ if dependentUse ( of: operand, dependentValue : result) == . abortWalk {
952
970
return . abortWalk
953
971
}
954
972
}
955
973
for resultAddr in apply. indirectResultOperands
956
974
where !resultAddr. value. isEscapable {
957
- if visitStoredUses ( of: operand, into : resultAddr. value) == . abortWalk {
975
+ if dependentUse ( of: operand, dependentAddress : resultAddr. value) == . abortWalk {
958
976
return . abortWalk
959
977
}
960
978
}
0 commit comments