Skip to content

Commit b74f50a

Browse files
committed
[LAA] Store reference to SymbolicStrides in MemoryDepChecker (NFC).
This reduces the need for explicitly passing it through multiple layers of function calls.
1 parent b98bce5 commit b74f50a

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

llvm/include/llvm/Analysis/LoopAccessAnalysis.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ class MemoryDepChecker {
182182
};
183183

184184
MemoryDepChecker(PredicatedScalarEvolution &PSE, const Loop *L,
185+
const DenseMap<Value *, const SCEV *> &SymbolicStrides,
185186
unsigned MaxTargetVectorWidthInBits)
186-
: PSE(PSE), InnermostLoop(L),
187+
: PSE(PSE), InnermostLoop(L), SymbolicStrides(SymbolicStrides),
187188
MaxTargetVectorWidthInBits(MaxTargetVectorWidthInBits) {}
188189

189190
/// Register the location (instructions are given increasing numbers)
@@ -198,7 +199,6 @@ class MemoryDepChecker {
198199
///
199200
/// Only checks sets with elements in \p CheckDeps.
200201
bool areDepsSafe(DepCandidates &AccessSets, MemAccessInfoList &CheckDeps,
201-
const DenseMap<Value *, const SCEV *> &Strides,
202202
const DenseMap<Value *, SmallVector<const Value *, 16>>
203203
&UnderlyingObjects);
204204

@@ -278,6 +278,10 @@ class MemoryDepChecker {
278278
PredicatedScalarEvolution &PSE;
279279
const Loop *InnermostLoop;
280280

281+
/// Reference to map of pointer values to
282+
/// their stride symbols, if they have a symbolic stride.
283+
const DenseMap<Value *, const SCEV *> &SymbolicStrides;
284+
281285
/// Maps access locations (ptr, read/write) to program order.
282286
DenseMap<MemAccessInfo, std::vector<unsigned> > Accesses;
283287

@@ -336,7 +340,7 @@ class MemoryDepChecker {
336340
/// Otherwise, this function returns true signaling a possible dependence.
337341
Dependence::DepType
338342
isDependent(const MemAccessInfo &A, unsigned AIdx, const MemAccessInfo &B,
339-
unsigned BIdx, const DenseMap<Value *, const SCEV *> &Strides,
343+
unsigned BIdx,
340344
const DenseMap<Value *, SmallVector<const Value *, 16>>
341345
&UnderlyingObjects);
342346

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,16 +2025,16 @@ getDependenceDistanceStrideAndSize(
20252025

20262026
MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
20272027
const MemAccessInfo &A, unsigned AIdx, const MemAccessInfo &B,
2028-
unsigned BIdx, const DenseMap<Value *, const SCEV *> &Strides,
2028+
unsigned BIdx,
20292029
const DenseMap<Value *, SmallVector<const Value *, 16>>
20302030
&UnderlyingObjects) {
20312031
assert(AIdx < BIdx && "Must pass arguments in program order");
20322032

20332033
// Get the dependence distance, stride, type size and what access writes for
20342034
// the dependence between A and B.
20352035
auto Res = getDependenceDistanceStrideAndSize(
2036-
A, InstMap[AIdx], B, InstMap[BIdx], Strides, UnderlyingObjects, PSE,
2037-
InnermostLoop);
2036+
A, InstMap[AIdx], B, InstMap[BIdx], SymbolicStrides, UnderlyingObjects,
2037+
PSE, InnermostLoop);
20382038
if (std::holds_alternative<Dependence::DepType>(Res))
20392039
return std::get<Dependence::DepType>(Res);
20402040

@@ -2269,7 +2269,6 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
22692269

22702270
bool MemoryDepChecker::areDepsSafe(
22712271
DepCandidates &AccessSets, MemAccessInfoList &CheckDeps,
2272-
const DenseMap<Value *, const SCEV *> &Strides,
22732272
const DenseMap<Value *, SmallVector<const Value *, 16>>
22742273
&UnderlyingObjects) {
22752274

@@ -2314,9 +2313,8 @@ bool MemoryDepChecker::areDepsSafe(
23142313
if (*I1 > *I2)
23152314
std::swap(A, B);
23162315

2317-
Dependence::DepType Type =
2318-
isDependent(*A.first, A.second, *B.first, B.second, Strides,
2319-
UnderlyingObjects);
2316+
Dependence::DepType Type = isDependent(*A.first, A.second, *B.first,
2317+
B.second, UnderlyingObjects);
23202318
mergeInStatus(Dependence::isSafeForVectorization(Type));
23212319

23222320
// Gather dependences unless we accumulated MaxDependences
@@ -2674,9 +2672,9 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
26742672
CanVecMem = true;
26752673
if (Accesses.isDependencyCheckNeeded()) {
26762674
LLVM_DEBUG(dbgs() << "LAA: Checking memory dependencies\n");
2677-
CanVecMem = DepChecker->areDepsSafe(
2678-
DependentAccesses, Accesses.getDependenciesToCheck(), SymbolicStrides,
2679-
Accesses.getUnderlyingObjects());
2675+
CanVecMem = DepChecker->areDepsSafe(DependentAccesses,
2676+
Accesses.getDependenciesToCheck(),
2677+
Accesses.getUnderlyingObjects());
26802678

26812679
if (!CanVecMem && DepChecker->shouldRetryWithRuntimeCheck()) {
26822680
LLVM_DEBUG(dbgs() << "LAA: Retrying with memory checks\n");
@@ -3066,8 +3064,8 @@ LoopAccessInfo::LoopAccessInfo(Loop *L, ScalarEvolution *SE,
30663064
if (ScalableWidth.isNonZero())
30673065
MaxTargetVectorWidthInBits = std::numeric_limits<unsigned>::max();
30683066
}
3069-
DepChecker =
3070-
std::make_unique<MemoryDepChecker>(*PSE, L, MaxTargetVectorWidthInBits);
3067+
DepChecker = std::make_unique<MemoryDepChecker>(*PSE, L, SymbolicStrides,
3068+
MaxTargetVectorWidthInBits);
30713069
PtrRtChecking = std::make_unique<RuntimePointerChecking>(*DepChecker, SE);
30723070
if (canAnalyzeLoop())
30733071
analyzeLoop(AA, LI, TLI, DT);

0 commit comments

Comments
 (0)