@@ -477,7 +477,7 @@ private extension PointerToAddressInst {
477
477
}
478
478
}
479
479
480
- /// The `EnclosingScope ` of an access is the innermost `begin_access`
480
+ /// The `EnclosingAccessScope ` of an access is the innermost `begin_access`
481
481
/// instruction that checks for exclusivity of the access.
482
482
/// If there is no `begin_access` instruction found, then the scope is
483
483
/// the base itself.
@@ -497,13 +497,29 @@ private extension PointerToAddressInst {
497
497
/// %l3 = load %a3 : $*Int64
498
498
/// end_access %a3 : $*Int64
499
499
/// ```
500
- public enum EnclosingScope {
501
- case scope ( BeginAccessInst )
500
+ public enum EnclosingAccessScope {
501
+ case access ( BeginAccessInst )
502
502
case base( AccessBase )
503
+ case dependence( MarkDependenceInst )
504
+ }
505
+
506
+ // An AccessBase with the nested enclosing scopes that contain the original address in bottom-up order.
507
+ public struct AccessBaseAndScopes {
508
+ public let base : AccessBase
509
+ public let scopes : SingleInlineArray < EnclosingAccessScope >
510
+
511
+ public var innermostAccess : BeginAccessInst ? {
512
+ for scope in scopes {
513
+ if case let . access( beginAccess) = scope {
514
+ return beginAccess
515
+ }
516
+ }
517
+ return nil
518
+ }
503
519
}
504
520
505
521
private struct EnclosingAccessWalker : AddressUseDefWalker {
506
- var enclosingScope : EnclosingScope ?
522
+ var enclosingScope : EnclosingAccessScope ?
507
523
508
524
mutating func walk( startAt address: Value , initialPath: UnusedWalkingPath = UnusedWalkingPath ( ) ) {
509
525
if walkUp ( address: address, path: UnusedWalkingPath ( ) ) == . abortWalk {
@@ -522,19 +538,24 @@ private struct EnclosingAccessWalker : AddressUseDefWalker {
522
538
}
523
539
524
540
mutating func walkUp( address: Value , path: UnusedWalkingPath ) -> WalkResult {
525
- if let ba = address as? BeginAccessInst {
526
- enclosingScope = . scope( ba)
541
+ switch address {
542
+ case let ba as BeginAccessInst :
543
+ enclosingScope = . access( ba)
527
544
return . continueWalk
545
+ case let md as MarkDependenceInst :
546
+ enclosingScope = . dependence( md)
547
+ return . continueWalk
548
+ default :
549
+ return walkUpDefault ( address: address, path: path)
528
550
}
529
- return walkUpDefault ( address: address, path: path)
530
551
}
531
552
}
532
553
533
554
private struct AccessPathWalker : AddressUseDefWalker {
534
555
var result = AccessPath . unidentified ( )
535
556
536
- // List of nested BeginAccessInst: inside-out order.
537
- var foundBeginAccesses = SingleInlineArray < BeginAccessInst > ( )
557
+ // List of nested BeginAccessInst & MarkDependenceInst : inside-out order.
558
+ var foundEnclosingScopes = SingleInlineArray < EnclosingAccessScope > ( )
538
559
539
560
let enforceConstantProjectionPath : Bool
540
561
@@ -602,7 +623,9 @@ private struct AccessPathWalker : AddressUseDefWalker {
602
623
// projection. Bail out
603
624
return . abortWalk
604
625
} else if let ba = address as? BeginAccessInst {
605
- foundBeginAccesses. push ( ba)
626
+ foundEnclosingScopes. push ( . access( ba) )
627
+ } else if let md = address as? MarkDependenceInst {
628
+ foundEnclosingScopes. push ( . dependence( md) )
606
629
}
607
630
return walkUpDefault ( address: address, path: path. with ( indexAddr: false ) )
608
631
}
@@ -655,20 +678,21 @@ extension Value {
655
678
public var accessPathWithScope : ( AccessPath , scope: BeginAccessInst ? ) {
656
679
var walker = AccessPathWalker ( )
657
680
walker. walk ( startAt: self )
658
- return ( walker. result, walker. foundBeginAccesses. first)
681
+ let baseAndScopes = AccessBaseAndScopes ( base: walker. result. base, scopes: walker. foundEnclosingScopes)
682
+ return ( walker. result, baseAndScopes. innermostAccess)
659
683
}
660
684
661
685
/// Computes the enclosing access scope of this address value.
662
- public var enclosingAccessScope : EnclosingScope {
686
+ public var enclosingAccessScope : EnclosingAccessScope {
663
687
var walker = EnclosingAccessWalker ( )
664
688
walker. walk ( startAt: self )
665
689
return walker. enclosingScope ?? . base( . unidentified)
666
690
}
667
691
668
- public var accessBaseWithScopes : ( AccessBase , SingleInlineArray < BeginAccessInst > ) {
692
+ public var accessBaseWithScopes : AccessBaseAndScopes {
669
693
var walker = AccessPathWalker ( )
670
694
walker. walk ( startAt: self )
671
- return ( walker. result. base, walker. foundBeginAccesses )
695
+ return AccessBaseAndScopes ( base : walker. result. base, scopes : walker. foundEnclosingScopes )
672
696
}
673
697
674
698
/// The root definition of a reference, obtained by skipping ownership forwarding and ownership transition.
0 commit comments