Skip to content

Commit aced5c7

Browse files
committed
SILOptimizer: Remove InspectionMode from MemBehehaviorVisitor
The InspectionMode was never set to anything else than "IgnoreRetains"
1 parent a665ba6 commit aced5c7

File tree

5 files changed

+63
-108
lines changed

5 files changed

+63
-108
lines changed

include/swift/SILOptimizer/Analysis/AliasAnalysis.h

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ namespace {
4747
struct MemBehaviorKeyTy {
4848
// The SILValue pair:
4949
size_t V1, V2;
50-
RetainObserveKind InspectionMode;
5150
};
5251
}
5352

@@ -201,24 +200,16 @@ class AliasAnalysis : public SILAnalysis {
201200

202201
/// Use the alias analysis to determine the memory behavior of Inst with
203202
/// respect to V.
204-
///
205-
/// TODO: When ref count behavior is separated from generic memory behavior,
206-
/// the InspectionMode flag will be unnecessary.
207-
MemoryBehavior computeMemoryBehavior(SILInstruction *Inst, SILValue V,
208-
RetainObserveKind);
203+
MemoryBehavior computeMemoryBehavior(SILInstruction *Inst, SILValue V);
209204

210205
/// Use the alias analysis to determine the memory behavior of Inst with
211206
/// respect to V.
212-
///
213-
/// TODO: When ref count behavior is separated from generic memory behavior,
214-
/// the InspectionMode flag will be unnecessary.
215-
MemoryBehavior computeMemoryBehaviorInner(SILInstruction *Inst, SILValue V,
216-
RetainObserveKind);
207+
MemoryBehavior computeMemoryBehaviorInner(SILInstruction *Inst, SILValue V);
217208

218209
/// Returns true if \p Inst may read from memory in a manner that
219210
/// affects V.
220211
bool mayReadFromMemory(SILInstruction *Inst, SILValue V) {
221-
auto B = computeMemoryBehavior(Inst, V, RetainObserveKind::IgnoreRetains);
212+
auto B = computeMemoryBehavior(Inst, V);
222213
return B == MemoryBehavior::MayRead ||
223214
B == MemoryBehavior::MayReadWrite ||
224215
B == MemoryBehavior::MayHaveSideEffects;
@@ -227,7 +218,7 @@ class AliasAnalysis : public SILAnalysis {
227218
/// Returns true if \p Inst may write to memory in a manner that
228219
/// affects V.
229220
bool mayWriteToMemory(SILInstruction *Inst, SILValue V) {
230-
auto B = computeMemoryBehavior(Inst, V, RetainObserveKind::IgnoreRetains);
221+
auto B = computeMemoryBehavior(Inst, V);
231222
return B == MemoryBehavior::MayWrite ||
232223
B == MemoryBehavior::MayReadWrite ||
233224
B == MemoryBehavior::MayHaveSideEffects;
@@ -236,26 +227,10 @@ class AliasAnalysis : public SILAnalysis {
236227
/// Returns true if \p Inst may read or write to memory in a manner that
237228
/// affects V.
238229
bool mayReadOrWriteMemory(SILInstruction *Inst, SILValue V) {
239-
auto B = computeMemoryBehavior(Inst, V, RetainObserveKind::IgnoreRetains);
230+
auto B = computeMemoryBehavior(Inst, V);
240231
return MemoryBehavior::None != B;
241232
}
242233

243-
/// Returns true if Inst may have side effects in a manner that affects V.
244-
bool mayHaveSideEffects(SILInstruction *Inst, SILValue V) {
245-
auto B = computeMemoryBehavior(Inst, V, RetainObserveKind::ObserveRetains);
246-
return B == MemoryBehavior::MayWrite ||
247-
B == MemoryBehavior::MayReadWrite ||
248-
B == MemoryBehavior::MayHaveSideEffects;
249-
}
250-
251-
/// Returns true if Inst may have side effects in a manner that affects
252-
/// V. This is independent of whether or not Inst may write to V and is meant
253-
/// to encode notions such as ref count modifications.
254-
bool mayHavePureSideEffects(SILInstruction *Inst, SILValue V) {
255-
auto B = computeMemoryBehavior(Inst, V, RetainObserveKind::ObserveRetains);
256-
return MemoryBehavior::MayHaveSideEffects == B;
257-
}
258-
259234
/// Returns true if \p Ptr may be released in the function call \p FAS.
260235
bool canApplyDecrementRefCount(FullApplySite FAS, SILValue Ptr);
261236

@@ -268,8 +243,7 @@ class AliasAnalysis : public SILAnalysis {
268243
AliasKeyTy toAliasKey(SILValue V1, SILValue V2, SILType Type1, SILType Type2);
269244

270245
/// Encodes the memory behavior query as a MemBehaviorKeyTy.
271-
MemBehaviorKeyTy toMemoryBehaviorKey(SILInstruction *V1, SILValue V2,
272-
RetainObserveKind K);
246+
MemBehaviorKeyTy toMemoryBehaviorKey(SILInstruction *V1, SILValue V2);
273247

274248
virtual void invalidate() override {
275249
AliasCache.clear();
@@ -330,24 +304,21 @@ namespace llvm {
330304
template <> struct DenseMapInfo<MemBehaviorKeyTy> {
331305
static inline MemBehaviorKeyTy getEmptyKey() {
332306
auto Allone = std::numeric_limits<size_t>::max();
333-
return {0, Allone, RetainObserveKind::RetainObserveKindEnd};
307+
return {0, Allone};
334308
}
335309
static inline MemBehaviorKeyTy getTombstoneKey() {
336310
auto Allone = std::numeric_limits<size_t>::max();
337-
return {Allone, 0, RetainObserveKind::RetainObserveKindEnd};
311+
return {Allone, 0};
338312
}
339313
static unsigned getHashValue(const MemBehaviorKeyTy V) {
340314
unsigned H = 0;
341315
H ^= DenseMapInfo<size_t>::getHashValue(V.V1);
342316
H ^= DenseMapInfo<size_t>::getHashValue(V.V2);
343-
H ^= DenseMapInfo<int>::getHashValue(static_cast<int>(V.InspectionMode));
344317
return H;
345318
}
346319
static bool isEqual(const MemBehaviorKeyTy LHS,
347320
const MemBehaviorKeyTy RHS) {
348-
return LHS.V1 == RHS.V1 &&
349-
LHS.V2 == RHS.V2 &&
350-
LHS.InspectionMode == RHS.InspectionMode;
321+
return LHS.V1 == RHS.V1 && LHS.V2 == RHS.V2;
351322
}
352323
};
353324
}

lib/SILOptimizer/Analysis/MemoryBehavior.cpp

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,10 @@ class MemoryBehaviorVisitor
6666
/// The SILType of the value.
6767
Optional<SILType> TypedAccessTy;
6868

69-
/// Should we treat instructions that increment ref counts as None instead of
70-
/// MayHaveSideEffects.
71-
RetainObserveKind InspectionMode;
72-
7369
public:
7470
MemoryBehaviorVisitor(AliasAnalysis *AA, SideEffectAnalysis *SEA,
75-
EscapeAnalysis *EA, SILValue V,
76-
RetainObserveKind IgnoreRefCountIncs)
77-
: AA(AA), SEA(SEA), EA(EA), V(V), InspectionMode(IgnoreRefCountIncs) {}
71+
EscapeAnalysis *EA, SILValue V)
72+
: AA(AA), SEA(SEA), EA(EA), V(V) {}
7873

7974
SILType getValueTBAAType() {
8075
if (!TypedAccessTy)
@@ -223,9 +218,7 @@ class MemoryBehaviorVisitor
223218
// memory this will be unnecessary.
224219
#define REFCOUNTINC_MEMBEHAVIOR_INST(Name) \
225220
MemBehavior visit##Name(Name *I) { \
226-
if (InspectionMode == RetainObserveKind::IgnoreRetains) \
227-
return MemBehavior::None; \
228-
return I->getMemoryBehavior(); \
221+
return MemBehavior::None; \
229222
}
230223
REFCOUNTINC_MEMBEHAVIOR_INST(StrongRetainInst)
231224
REFCOUNTINC_MEMBEHAVIOR_INST(RetainValueInst)
@@ -364,19 +357,15 @@ MemBehavior MemoryBehaviorVisitor::visitApplyInst(ApplyInst *AI) {
364357
// one the parameters in the function call is @in_guaranteed of V, ie. the
365358
// callee isn't allowed to modify it.
366359
Behavior = MemBehavior::MayRead;
367-
} else if (ApplyEffects.mayReadRC() ||
368-
(InspectionMode == RetainObserveKind::ObserveRetains &&
369-
ApplyEffects.mayAllocObjects())) {
370-
Behavior = MemBehavior::MayHaveSideEffects;
371360
} else {
372361
auto &GlobalEffects = ApplyEffects.getGlobalEffects();
373-
Behavior = GlobalEffects.getMemBehavior(InspectionMode);
362+
Behavior = GlobalEffects.getMemBehavior(RetainObserveKind::IgnoreRetains);
374363

375364
// Check all parameter effects.
376365
for (unsigned Idx = 0, End = AI->getNumArguments();
377366
Idx < End && Behavior < MemBehavior::MayHaveSideEffects; ++Idx) {
378367
auto &ArgEffect = ApplyEffects.getParameterEffects()[Idx];
379-
auto ArgBehavior = ArgEffect.getMemBehavior(InspectionMode);
368+
auto ArgBehavior = ArgEffect.getMemBehavior(RetainObserveKind::IgnoreRetains);
380369
if (ArgEffect.mayRelease()) {
381370
Behavior = MemBehavior::MayHaveSideEffects;
382371
break;
@@ -442,9 +431,8 @@ visitBeginCOWMutationInst(BeginCOWMutationInst *BCMI) {
442431
//===----------------------------------------------------------------------===//
443432

444433
MemBehavior
445-
AliasAnalysis::computeMemoryBehavior(SILInstruction *Inst, SILValue V,
446-
RetainObserveKind InspectionMode) {
447-
MemBehaviorKeyTy Key = toMemoryBehaviorKey(Inst, V, InspectionMode);
434+
AliasAnalysis::computeMemoryBehavior(SILInstruction *Inst, SILValue V) {
435+
MemBehaviorKeyTy Key = toMemoryBehaviorKey(Inst, V);
448436
// Check if we've already computed this result.
449437
auto It = MemoryBehaviorCache.find(Key);
450438
if (It != MemoryBehaviorCache.end()) {
@@ -457,27 +445,25 @@ AliasAnalysis::computeMemoryBehavior(SILInstruction *Inst, SILValue V,
457445
MemoryBehaviorNodeToIndex.clear();
458446

459447
// Key is no longer valid as we cleared the MemoryBehaviorNodeToIndex.
460-
Key = toMemoryBehaviorKey(Inst, V, InspectionMode);
448+
Key = toMemoryBehaviorKey(Inst, V);
461449
}
462450

463451
// Calculate the aliasing result and store it in the cache.
464-
auto Result = computeMemoryBehaviorInner(Inst, V, InspectionMode);
452+
auto Result = computeMemoryBehaviorInner(Inst, V);
465453
MemoryBehaviorCache[Key] = Result;
466454
return Result;
467455
}
468456

469457
MemBehavior
470-
AliasAnalysis::computeMemoryBehaviorInner(SILInstruction *Inst, SILValue V,
471-
RetainObserveKind InspectionMode) {
458+
AliasAnalysis::computeMemoryBehaviorInner(SILInstruction *Inst, SILValue V) {
472459
LLVM_DEBUG(llvm::dbgs() << "GET MEMORY BEHAVIOR FOR:\n " << *Inst << " "
473460
<< *V);
474461
assert(SEA && "SideEffectsAnalysis must be initialized!");
475-
return MemoryBehaviorVisitor(this, SEA, EA, V, InspectionMode).visit(Inst);
462+
return MemoryBehaviorVisitor(this, SEA, EA, V).visit(Inst);
476463
}
477464

478465
MemBehaviorKeyTy AliasAnalysis::toMemoryBehaviorKey(SILInstruction *V1,
479-
SILValue V2,
480-
RetainObserveKind M) {
466+
SILValue V2) {
481467
size_t idx1 =
482468
MemoryBehaviorNodeToIndex.getIndex(V1->getRepresentativeSILNodeInObject());
483469
assert(idx1 != std::numeric_limits<size_t>::max() &&
@@ -486,5 +472,5 @@ MemBehaviorKeyTy AliasAnalysis::toMemoryBehaviorKey(SILInstruction *V1,
486472
V2->getRepresentativeSILNodeInObject());
487473
assert(idx2 != std::numeric_limits<size_t>::max() &&
488474
"~0 index reserved for empty/tombstone keys");
489-
return {idx1, idx2, M};
475+
return {idx1, idx2};
490476
}

lib/SILOptimizer/UtilityPasses/MemBehaviorDumper.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,9 @@ class MemBehaviorDumper : public SILModuleTransform {
8888

8989
bool Read = AA->mayReadFromMemory(&I, V);
9090
bool Write = AA->mayWriteToMemory(&I, V);
91-
bool SideEffects = AA->mayHaveSideEffects(&I, V);
9291
llvm::outs() << "PAIR #" << PairCount++ << ".\n"
9392
<< " " << I << " " << V
94-
<< " r=" << Read << ",w=" << Write
95-
<< ",se=" << SideEffects << "\n";
93+
<< " r=" << Read << ",w=" << Write << "\n";
9694
}
9795
}
9896
}

0 commit comments

Comments
 (0)