Skip to content

Commit a3020a8

Browse files
committed
[AliasAnalysis] Make the dependence on SideEffectsAnalysis internal.
This commit removes the public method for fetching SideEffectsAnalysis. The dependency on SEA is now an implementation detail of AliasAnalysis and computeMemoryBehavior.
1 parent 3d35b03 commit a3020a8

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

Diff for: include/swift/SILAnalysis/AliasAnalysis.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ class AliasAnalysis : public SILAnalysis {
7878

7979
virtual void initialize(SILPassManager *PM);
8080

81-
SideEffectAnalysis *getSideEffectAnalysis() const { return SEA; }
82-
8381
/// Perform an alias query to see if V1, V2 refer to the same values.
8482
AliasResult alias(SILValue V1, SILValue V2, SILType TBAAType1 = SILType(),
8583
SILType TBAAType2 = SILType());
@@ -112,7 +110,7 @@ class AliasAnalysis : public SILAnalysis {
112110
/// respect to V.
113111
///
114112
/// TODO: When ref count behavior is separated from generic memory behavior,
115-
/// the IgnoreRefCountIncrements flag will be unnecessary.
113+
/// the InspectionMode flag will be unnecessary.
116114
MemoryBehavior computeMemoryBehavior(SILInstruction *Inst, SILValue V,
117115
RetainObserveKind);
118116

Diff for: lib/SILAnalysis/MemoryBehavior.cpp

+18-16
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ using MemBehavior = SILInstruction::MemoryBehavior;
3434
class MemoryBehaviorVisitor
3535
: public SILInstructionVisitor<MemoryBehaviorVisitor, MemBehavior> {
3636

37-
/// The alias analysis for any queries we may need.
38-
AliasAnalysis &AA;
37+
AliasAnalysis *AA;
38+
39+
SideEffectAnalysis *SEA;
3940

4041
/// The value we are attempting to discover memory behavior relative to.
4142
SILValue V;
@@ -45,12 +46,12 @@ class MemoryBehaviorVisitor
4546

4647
/// Should we treat instructions that increment ref counts as None instead of
4748
/// MayHaveSideEffects.
48-
RetainObserveKind IgnoreRefCountIncrements;
49+
RetainObserveKind InspectionMode;
4950

5051
public:
51-
MemoryBehaviorVisitor(AliasAnalysis &AA, SILValue V,
52+
MemoryBehaviorVisitor(AliasAnalysis *AA, SideEffectAnalysis *SEA, SILValue V,
5253
RetainObserveKind IgnoreRefCountIncs)
53-
: AA(AA), V(V), IgnoreRefCountIncrements(IgnoreRefCountIncs) {}
54+
: AA(AA), SEA(SEA), V(V), InspectionMode(IgnoreRefCountIncs) {}
5455

5556
SILType getValueTBAAType() {
5657
if (!TypedAccessTy)
@@ -98,7 +99,7 @@ class MemoryBehaviorVisitor
9899
#define OPERANDALIAS_MEMBEHAVIOR_INST(Name) \
99100
MemBehavior visit##Name(Name *I) { \
100101
for (Operand &Op : I->getAllOperands()) { \
101-
if (!AA.isNoAlias(Op.get(), V)) { \
102+
if (!AA->isNoAlias(Op.get(), V)) { \
102103
DEBUG(llvm::dbgs() << " " #Name \
103104
" does alias inst. Returning Normal behavior.\n"); \
104105
return I->getMemoryBehavior(); \
@@ -133,7 +134,7 @@ class MemoryBehaviorVisitor
133134
// memory this will be unnecessary.
134135
#define REFCOUNTINC_MEMBEHAVIOR_INST(Name) \
135136
MemBehavior visit##Name(Name *I) { \
136-
if (IgnoreRefCountIncrements == RetainObserveKind::IgnoreRetains) \
137+
if (InspectionMode == RetainObserveKind::IgnoreRetains) \
137138
return MemBehavior::None; \
138139
return I->getMemoryBehavior(); \
139140
}
@@ -148,7 +149,7 @@ class MemoryBehaviorVisitor
148149
} // end anonymous namespace
149150

150151
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()),
152153
getValueTBAAType())) {
153154
DEBUG(llvm::dbgs() << " Load Operand does not alias inst. Returning "
154155
"None.\n");
@@ -168,7 +169,7 @@ MemBehavior MemoryBehaviorVisitor::visitStoreInst(StoreInst *SI) {
168169

169170
// If the store dest cannot alias the pointer in question, then the
170171
// 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()),
172173
getValueTBAAType())) {
173174
DEBUG(llvm::dbgs() << " Store Dst does not alias inst. Returning "
174175
"None.\n");
@@ -228,29 +229,29 @@ MemBehavior MemoryBehaviorVisitor::visitTryApplyInst(TryApplyInst *AI) {
228229
MemBehavior MemoryBehaviorVisitor::visitApplyInst(ApplyInst *AI) {
229230

230231
SideEffectAnalysis::FunctionEffects ApplyEffects;
231-
AA.getSideEffectAnalysis()->getEffects(ApplyEffects, AI);
232+
SEA->getEffects(ApplyEffects, AI);
232233

233234
MemBehavior Behavior = MemBehavior::None;
234235

235236
// We can ignore mayTrap().
236237
if (ApplyEffects.mayReadRC() ||
237-
(IgnoreRefCountIncrements == RetainObserveKind::ObserveRetains &&
238+
(InspectionMode == RetainObserveKind::ObserveRetains &&
238239
ApplyEffects.mayAllocObjects())) {
239240
Behavior = MemBehavior::MayHaveSideEffects;
240241
} else {
241242
auto &GlobalEffects = ApplyEffects.getGlobalEffects();
242-
Behavior = GlobalEffects.getMemBehavior(IgnoreRefCountIncrements);
243+
Behavior = GlobalEffects.getMemBehavior(InspectionMode);
243244

244245
// Check all parameter effects.
245246
for (unsigned Idx = 0, End = AI->getNumArguments();
246247
Idx < End && Behavior < MemBehavior::MayHaveSideEffects; ++Idx) {
247248
auto &ArgEffect = ApplyEffects.getParameterEffects()[Idx];
248-
auto ArgBehavior = ArgEffect.getMemBehavior(IgnoreRefCountIncrements);
249+
auto ArgBehavior = ArgEffect.getMemBehavior(InspectionMode);
249250
if (ArgBehavior > Behavior) {
250251
SILValue Arg = AI->getArgument(Idx);
251252
// We only consider the argument effects if the argument aliases V.
252253
if (!Arg.getType().isAddress() ||
253-
!AA.isNoAlias(Arg, V, computeTBAAType(Arg), getValueTBAAType())) {
254+
!AA->isNoAlias(Arg, V, computeTBAAType(Arg), getValueTBAAType())) {
254255
Behavior = ArgBehavior;
255256
}
256257
}
@@ -307,8 +308,9 @@ MemBehavior MemoryBehaviorVisitor::visitReleaseValueInst(ReleaseValueInst *SI) {
307308

308309
MemBehavior
309310
AliasAnalysis::computeMemoryBehavior(SILInstruction *Inst, SILValue V,
310-
RetainObserveKind IgnoreRefCountIncrements) {
311+
RetainObserveKind InspectionMode) {
311312
DEBUG(llvm::dbgs() << "GET MEMORY BEHAVIOR FOR:\n " << *Inst << " "
312313
<< *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);
314316
}

0 commit comments

Comments
 (0)