@@ -67,22 +67,21 @@ using llvm::DenseMap;
67
67
using llvm::SmallDenseSet;
68
68
69
69
// 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.
72
72
//
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 ;
78
79
switch (storage.getKind ()) {
79
80
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 ));
86
85
case AccessedStorage::Box:
87
86
case AccessedStorage::Stack:
88
87
case AccessedStorage::Tail:
@@ -169,15 +168,17 @@ void GlobalAccessRemoval::perform() {
169
168
170
169
void GlobalAccessRemoval::visitInstruction (SILInstruction *I) {
171
170
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 ());
175
175
return ;
176
176
}
177
177
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 ());
181
182
return ;
182
183
}
183
184
if (auto *KPI = dyn_cast<KeyPathInst>(I)) {
0 commit comments