@@ -34,8 +34,9 @@ using MemBehavior = SILInstruction::MemoryBehavior;
34
34
class MemoryBehaviorVisitor
35
35
: public SILInstructionVisitor<MemoryBehaviorVisitor, MemBehavior> {
36
36
37
- // / The alias analysis for any queries we may need.
38
- AliasAnalysis &AA;
37
+ AliasAnalysis *AA;
38
+
39
+ SideEffectAnalysis *SEA;
39
40
40
41
// / The value we are attempting to discover memory behavior relative to.
41
42
SILValue V;
@@ -45,12 +46,12 @@ class MemoryBehaviorVisitor
45
46
46
47
// / Should we treat instructions that increment ref counts as None instead of
47
48
// / MayHaveSideEffects.
48
- RetainObserveKind IgnoreRefCountIncrements ;
49
+ RetainObserveKind InspectionMode ;
49
50
50
51
public:
51
- MemoryBehaviorVisitor (AliasAnalysis &AA , SILValue V,
52
+ MemoryBehaviorVisitor (AliasAnalysis *AA, SideEffectAnalysis *SEA , SILValue V,
52
53
RetainObserveKind IgnoreRefCountIncs)
53
- : AA(AA), V(V), IgnoreRefCountIncrements (IgnoreRefCountIncs) {}
54
+ : AA(AA), SEA(SEA), V(V), InspectionMode (IgnoreRefCountIncs) {}
54
55
55
56
SILType getValueTBAAType () {
56
57
if (!TypedAccessTy)
@@ -98,7 +99,7 @@ class MemoryBehaviorVisitor
98
99
#define OPERANDALIAS_MEMBEHAVIOR_INST (Name ) \
99
100
MemBehavior visit##Name(Name *I) { \
100
101
for (Operand &Op : I->getAllOperands ()) { \
101
- if (!AA. isNoAlias (Op.get (), V)) { \
102
+ if (!AA-> isNoAlias (Op.get (), V)) { \
102
103
DEBUG (llvm::dbgs () << " " #Name \
103
104
" does alias inst. Returning Normal behavior.\n " ); \
104
105
return I->getMemoryBehavior (); \
@@ -133,7 +134,7 @@ class MemoryBehaviorVisitor
133
134
// memory this will be unnecessary.
134
135
#define REFCOUNTINC_MEMBEHAVIOR_INST (Name ) \
135
136
MemBehavior visit##Name(Name *I) { \
136
- if (IgnoreRefCountIncrements == RetainObserveKind::IgnoreRetains) \
137
+ if (InspectionMode == RetainObserveKind::IgnoreRetains) \
137
138
return MemBehavior::None; \
138
139
return I->getMemoryBehavior (); \
139
140
}
@@ -148,7 +149,7 @@ class MemoryBehaviorVisitor
148
149
} // end anonymous namespace
149
150
150
151
MemBehavior MemoryBehaviorVisitor::visitLoadInst (LoadInst *LI) {
151
- if (AA. isNoAlias (LI->getOperand (), V, computeTBAAType (LI->getOperand ()),
152
+ if (AA-> isNoAlias (LI->getOperand (), V, computeTBAAType (LI->getOperand ()),
152
153
getValueTBAAType ())) {
153
154
DEBUG (llvm::dbgs () << " Load Operand does not alias inst. Returning "
154
155
" None.\n " );
@@ -168,7 +169,7 @@ MemBehavior MemoryBehaviorVisitor::visitStoreInst(StoreInst *SI) {
168
169
169
170
// If the store dest cannot alias the pointer in question, then the
170
171
// specified value can not be modified by the store.
171
- if (AA. isNoAlias (SI->getDest (), V, computeTBAAType (SI->getDest ()),
172
+ if (AA-> isNoAlias (SI->getDest (), V, computeTBAAType (SI->getDest ()),
172
173
getValueTBAAType ())) {
173
174
DEBUG (llvm::dbgs () << " Store Dst does not alias inst. Returning "
174
175
" None.\n " );
@@ -228,29 +229,29 @@ MemBehavior MemoryBehaviorVisitor::visitTryApplyInst(TryApplyInst *AI) {
228
229
MemBehavior MemoryBehaviorVisitor::visitApplyInst (ApplyInst *AI) {
229
230
230
231
SideEffectAnalysis::FunctionEffects ApplyEffects;
231
- AA. getSideEffectAnalysis () ->getEffects (ApplyEffects, AI);
232
+ SEA ->getEffects (ApplyEffects, AI);
232
233
233
234
MemBehavior Behavior = MemBehavior::None;
234
235
235
236
// We can ignore mayTrap().
236
237
if (ApplyEffects.mayReadRC () ||
237
- (IgnoreRefCountIncrements == RetainObserveKind::ObserveRetains &&
238
+ (InspectionMode == RetainObserveKind::ObserveRetains &&
238
239
ApplyEffects.mayAllocObjects ())) {
239
240
Behavior = MemBehavior::MayHaveSideEffects;
240
241
} else {
241
242
auto &GlobalEffects = ApplyEffects.getGlobalEffects ();
242
- Behavior = GlobalEffects.getMemBehavior (IgnoreRefCountIncrements );
243
+ Behavior = GlobalEffects.getMemBehavior (InspectionMode );
243
244
244
245
// Check all parameter effects.
245
246
for (unsigned Idx = 0 , End = AI->getNumArguments ();
246
247
Idx < End && Behavior < MemBehavior::MayHaveSideEffects; ++Idx) {
247
248
auto &ArgEffect = ApplyEffects.getParameterEffects ()[Idx];
248
- auto ArgBehavior = ArgEffect.getMemBehavior (IgnoreRefCountIncrements );
249
+ auto ArgBehavior = ArgEffect.getMemBehavior (InspectionMode );
249
250
if (ArgBehavior > Behavior) {
250
251
SILValue Arg = AI->getArgument (Idx);
251
252
// We only consider the argument effects if the argument aliases V.
252
253
if (!Arg.getType ().isAddress () ||
253
- !AA. isNoAlias (Arg, V, computeTBAAType (Arg), getValueTBAAType ())) {
254
+ !AA-> isNoAlias (Arg, V, computeTBAAType (Arg), getValueTBAAType ())) {
254
255
Behavior = ArgBehavior;
255
256
}
256
257
}
@@ -307,8 +308,9 @@ MemBehavior MemoryBehaviorVisitor::visitReleaseValueInst(ReleaseValueInst *SI) {
307
308
308
309
MemBehavior
309
310
AliasAnalysis::computeMemoryBehavior (SILInstruction *Inst, SILValue V,
310
- RetainObserveKind IgnoreRefCountIncrements ) {
311
+ RetainObserveKind InspectionMode ) {
311
312
DEBUG (llvm::dbgs () << " GET MEMORY BEHAVIOR FOR:\n " << *Inst << " "
312
313
<< *V.getDef ());
313
- return MemoryBehaviorVisitor (*this , V, IgnoreRefCountIncrements).visit (Inst);
314
+ assert (SEA && " SideEffectsAnalysis must be initialized!" );
315
+ return MemoryBehaviorVisitor (this , SEA, V, InspectionMode).visit (Inst);
314
316
}
0 commit comments