@@ -67,22 +67,21 @@ using llvm::DenseMap;
6767using llvm::SmallDenseSet;
6868
6969// Get the VarDecl that represents the DisjointAccessLocation for the given
70- // AccessedStorage . Returns nullptr for any storage that can't be partitioned
71- // into a disjoint location.
70+ // storage and access base . Returns nullptr for any storage that can't be
71+ // partitioned into a disjoint location.
7272//
73- // identifyFormalAccess may only return Unidentified storage for a global
74- // variable access if the global is defined in a different module.
75- //
76- // WARNING: Retrieving VarDecl for Class access is not constant time.
77- const VarDecl *getDisjointAccessLocation (const AccessedStorage &storage) {
73+ // Global storage is expected to be disjoint because identifyFormalAccess may
74+ // only return Unidentified storage for a global variable access if the global
75+ // is defined in a different module.
76+ const VarDecl *
77+ getDisjointAccessLocation (AccessedStorageWithBase storageAndBase) {
78+ auto storage = storageAndBase.storage ;
7879 switch (storage.getKind ()) {
7980 case AccessedStorage::Global:
80- // A global variable may return a null decl. These variables are
81- // implementation details that aren't formally accessed.
82- return storage.getGlobal ()->getDecl ();
83- case AccessedStorage::Class: {
84- return cast<VarDecl>(storage.getDecl ());
85- }
81+ case AccessedStorage::Class:
82+ // Class and Globals are always a VarDecl, but the global decl may have a
83+ // null value for global_addr -> phi.
84+ return cast_or_null<VarDecl>(storage.getDecl (storageAndBase.base ));
8685 case AccessedStorage::Box:
8786 case AccessedStorage::Stack:
8887 case AccessedStorage::Tail:
@@ -169,15 +168,17 @@ void GlobalAccessRemoval::perform() {
169168
170169void GlobalAccessRemoval::visitInstruction (SILInstruction *I) {
171170 if (auto *BAI = dyn_cast<BeginAccessInst>(I)) {
172- auto storage = AccessedStorage::compute (BAI->getSource ());
173- const VarDecl *decl = getDisjointAccessLocation (storage);
174- recordAccess (BAI, decl, storage.getKind (), BAI->hasNoNestedConflict ());
171+ auto storageAndBase = AccessedStorageWithBase::compute (BAI->getSource ());
172+ const VarDecl *decl = getDisjointAccessLocation (storageAndBase);
173+ recordAccess (BAI, decl, storageAndBase.storage .getKind (),
174+ BAI->hasNoNestedConflict ());
175175 return ;
176176 }
177177 if (auto *BUAI = dyn_cast<BeginUnpairedAccessInst>(I)) {
178- auto storage = AccessedStorage::compute (BUAI->getSource ());
179- const VarDecl *decl = getDisjointAccessLocation (storage);
180- recordAccess (BUAI, decl, storage.getKind (), BUAI->hasNoNestedConflict ());
178+ auto storageAndBase = AccessedStorageWithBase::compute (BUAI->getSource ());
179+ const VarDecl *decl = getDisjointAccessLocation (storageAndBase);
180+ recordAccess (BUAI, decl, storageAndBase.storage .getKind (),
181+ BUAI->hasNoNestedConflict ());
181182 return ;
182183 }
183184 if (auto *KPI = dyn_cast<KeyPathInst>(I)) {
0 commit comments