Skip to content

Commit 3eaf9f7

Browse files
authored
LAA: fix style after cursory reading (NFC) (#100447)
1 parent 7304936 commit 3eaf9f7

File tree

2 files changed

+49
-50
lines changed

2 files changed

+49
-50
lines changed

llvm/include/llvm/Analysis/LoopAccessAnalysis.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ class MemoryDepChecker {
199199
/// Check whether the dependencies between the accesses are safe.
200200
///
201201
/// Only checks sets with elements in \p CheckDeps.
202-
bool areDepsSafe(DepCandidates &AccessSets, MemAccessInfoList &CheckDeps,
202+
bool areDepsSafe(const DepCandidates &AccessSets,
203+
const MemAccessInfoList &CheckDeps,
203204
const DenseMap<Value *, SmallVector<const Value *, 16>>
204205
&UnderlyingObjects);
205206

@@ -405,14 +406,15 @@ class RuntimePointerChecking;
405406
struct RuntimeCheckingPtrGroup {
406407
/// Create a new pointer checking group containing a single
407408
/// pointer, with index \p Index in RtCheck.
408-
RuntimeCheckingPtrGroup(unsigned Index, RuntimePointerChecking &RtCheck);
409+
RuntimeCheckingPtrGroup(unsigned Index,
410+
const RuntimePointerChecking &RtCheck);
409411

410412
/// Tries to add the pointer recorded in RtCheck at index
411413
/// \p Index to this pointer checking group. We can only add a pointer
412414
/// to a checking group if we will still be able to get
413415
/// the upper and lower bounds of the check. Returns true in case
414416
/// of success, false otherwise.
415-
bool addPointer(unsigned Index, RuntimePointerChecking &RtCheck);
417+
bool addPointer(unsigned Index, const RuntimePointerChecking &RtCheck);
416418
bool addPointer(unsigned Index, const SCEV *Start, const SCEV *End,
417419
unsigned AS, bool NeedsFreeze, ScalarEvolution &SE);
418420

@@ -718,8 +720,8 @@ class LoopAccessInfo {
718720
private:
719721
/// Analyze the loop. Returns true if all memory access in the loop can be
720722
/// vectorized.
721-
bool analyzeLoop(AAResults *AA, LoopInfo *LI, const TargetLibraryInfo *TLI,
722-
DominatorTree *DT);
723+
bool analyzeLoop(AAResults *AA, const LoopInfo *LI,
724+
const TargetLibraryInfo *TLI, DominatorTree *DT);
723725

724726
/// Check if the structure of the loop allows it to be analyzed by this
725727
/// pass.
@@ -730,8 +732,8 @@ class LoopAccessInfo {
730732
/// LAA does not directly emits the remarks. Instead it stores it which the
731733
/// client can retrieve and presents as its own analysis
732734
/// (e.g. -Rpass-analysis=loop-vectorize).
733-
OptimizationRemarkAnalysis &recordAnalysis(StringRef RemarkName,
734-
Instruction *Instr = nullptr);
735+
OptimizationRemarkAnalysis &
736+
recordAnalysis(StringRef RemarkName, const Instruction *Instr = nullptr);
735737

736738
/// Collect memory access with loop invariant strides.
737739
///

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ const SCEV *llvm::replaceSymbolicStrideSCEV(PredicatedScalarEvolution &PSE,
181181
}
182182

183183
RuntimeCheckingPtrGroup::RuntimeCheckingPtrGroup(
184-
unsigned Index, RuntimePointerChecking &RtCheck)
184+
unsigned Index, const RuntimePointerChecking &RtCheck)
185185
: High(RtCheck.Pointers[Index].End), Low(RtCheck.Pointers[Index].Start),
186186
AddressSpace(RtCheck.Pointers[Index]
187187
.PointerValue->getType()
@@ -280,8 +280,8 @@ bool RuntimePointerChecking::tryToCreateDiffCheck(
280280
if (CGI.Members.size() != 1 || CGJ.Members.size() != 1)
281281
return false;
282282

283-
PointerInfo *Src = &Pointers[CGI.Members[0]];
284-
PointerInfo *Sink = &Pointers[CGJ.Members[0]];
283+
const PointerInfo *Src = &Pointers[CGI.Members[0]];
284+
const PointerInfo *Sink = &Pointers[CGJ.Members[0]];
285285

286286
// If either pointer is read and written, multiple checks may be needed. Bail
287287
// out.
@@ -385,7 +385,7 @@ SmallVector<RuntimePointerCheck, 4> RuntimePointerChecking::generateChecks() {
385385

386386
if (needsChecking(CGI, CGJ)) {
387387
CanUseDiffCheck = CanUseDiffCheck && tryToCreateDiffCheck(CGI, CGJ);
388-
Checks.push_back(std::make_pair(&CGI, &CGJ));
388+
Checks.emplace_back(&CGI, &CGJ);
389389
}
390390
}
391391
}
@@ -420,8 +420,8 @@ static const SCEV *getMinFromExprs(const SCEV *I, const SCEV *J,
420420
return C->getValue()->isNegative() ? J : I;
421421
}
422422

423-
bool RuntimeCheckingPtrGroup::addPointer(unsigned Index,
424-
RuntimePointerChecking &RtCheck) {
423+
bool RuntimeCheckingPtrGroup::addPointer(
424+
unsigned Index, const RuntimePointerChecking &RtCheck) {
425425
return addPointer(
426426
Index, RtCheck.Pointers[Index].Start, RtCheck.Pointers[Index].End,
427427
RtCheck.Pointers[Index].PointerValue->getType()->getPointerAddressSpace(),
@@ -507,7 +507,7 @@ void RuntimePointerChecking::groupChecks(
507507
// pointers to the same underlying object.
508508
if (!UseDependencies) {
509509
for (unsigned I = 0; I < Pointers.size(); ++I)
510-
CheckingGroups.push_back(RuntimeCheckingPtrGroup(I, *this));
510+
CheckingGroups.emplace_back(I, *this);
511511
return;
512512
}
513513

@@ -575,7 +575,7 @@ void RuntimePointerChecking::groupChecks(
575575
// We couldn't add this pointer to any existing set or the threshold
576576
// for the number of comparisons has been reached. Create a new group
577577
// to hold the current pointer.
578-
Groups.push_back(RuntimeCheckingPtrGroup(Pointer, *this));
578+
Groups.emplace_back(Pointer, *this);
579579
}
580580
}
581581

@@ -605,10 +605,7 @@ bool RuntimePointerChecking::needsChecking(unsigned I, unsigned J) const {
605605
return false;
606606

607607
// Only need to check pointers in the same alias set.
608-
if (PointerI.AliasSetId != PointerJ.AliasSetId)
609-
return false;
610-
611-
return true;
608+
return PointerI.AliasSetId == PointerJ.AliasSetId;
612609
}
613610

614611
void RuntimePointerChecking::printChecks(
@@ -658,7 +655,7 @@ class AccessAnalysis {
658655
typedef PointerIntPair<Value *, 1, bool> MemAccessInfo;
659656
typedef SmallVector<MemAccessInfo, 8> MemAccessInfoList;
660657

661-
AccessAnalysis(Loop *TheLoop, AAResults *AA, LoopInfo *LI,
658+
AccessAnalysis(const Loop *TheLoop, AAResults *AA, const LoopInfo *LI,
662659
MemoryDepChecker::DepCandidates &DA,
663660
PredicatedScalarEvolution &PSE,
664661
SmallPtrSetImpl<MDNode *> &LoopAliasScopes)
@@ -669,7 +666,7 @@ class AccessAnalysis {
669666
}
670667

671668
/// Register a load and whether it is only read from.
672-
void addLoad(MemoryLocation &Loc, Type *AccessTy, bool IsReadOnly) {
669+
void addLoad(const MemoryLocation &Loc, Type *AccessTy, bool IsReadOnly) {
673670
Value *Ptr = const_cast<Value *>(Loc.Ptr);
674671
AST.add(adjustLoc(Loc));
675672
Accesses[MemAccessInfo(Ptr, false)].insert(AccessTy);
@@ -678,7 +675,7 @@ class AccessAnalysis {
678675
}
679676

680677
/// Register a store.
681-
void addStore(MemoryLocation &Loc, Type *AccessTy) {
678+
void addStore(const MemoryLocation &Loc, Type *AccessTy) {
682679
Value *Ptr = const_cast<Value *>(Loc.Ptr);
683680
AST.add(adjustLoc(Loc));
684681
Accesses[MemAccessInfo(Ptr, true)].insert(AccessTy);
@@ -718,18 +715,18 @@ class AccessAnalysis {
718715
///
719716
/// Note that this can later be cleared if we retry memcheck analysis without
720717
/// dependency checking (i.e. FoundNonConstantDistanceDependence).
721-
bool isDependencyCheckNeeded() { return !CheckDeps.empty(); }
718+
bool isDependencyCheckNeeded() const { return !CheckDeps.empty(); }
722719

723720
/// We decided that no dependence analysis would be used. Reset the state.
724721
void resetDepChecks(MemoryDepChecker &DepChecker) {
725722
CheckDeps.clear();
726723
DepChecker.clearDependences();
727724
}
728725

729-
MemAccessInfoList &getDependenciesToCheck() { return CheckDeps; }
726+
const MemAccessInfoList &getDependenciesToCheck() const { return CheckDeps; }
730727

731728
const DenseMap<Value *, SmallVector<const Value *, 16>> &
732-
getUnderlyingObjects() {
729+
getUnderlyingObjects() const {
733730
return UnderlyingObjects;
734731
}
735732

@@ -844,10 +841,8 @@ static bool isNoWrap(PredicatedScalarEvolution &PSE,
844841
return true;
845842

846843
int64_t Stride = getPtrStride(PSE, AccessTy, Ptr, L, Strides).value_or(0);
847-
if (Stride == 1 || PSE.hasNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW))
848-
return true;
849-
850-
return false;
844+
return Stride == 1 ||
845+
PSE.hasNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW);
851846
}
852847

853848
static void visitPointers(Value *StartPtr, const Loop &InnermostLoop,
@@ -926,7 +921,7 @@ static void findForkedSCEVs(
926921
unsigned Opcode = I->getOpcode();
927922
switch (Opcode) {
928923
case Instruction::GetElementPtr: {
929-
GetElementPtrInst *GEP = cast<GetElementPtrInst>(I);
924+
auto *GEP = cast<GetElementPtrInst>(I);
930925
Type *SourceTy = GEP->getSourceElementType();
931926
// We only handle base + single offset GEPs here for now.
932927
// Not dealing with preexisting gathers yet, so no vectors.
@@ -1081,7 +1076,7 @@ bool AccessAnalysis::createCheckForAccess(RuntimePointerChecking &RtCheck,
10811076
SmallVector<PointerIntPair<const SCEV *, 1, bool>> TranslatedPtrs =
10821077
findForkedPointer(PSE, StridesMap, Ptr, TheLoop);
10831078

1084-
for (auto &P : TranslatedPtrs) {
1079+
for (const auto &P : TranslatedPtrs) {
10851080
const SCEV *PtrExpr = get<0>(P);
10861081
if (!hasComputableBounds(PSE, Ptr, PtrExpr, TheLoop, Assume))
10871082
return false;
@@ -1146,7 +1141,7 @@ bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck,
11461141
// We assign a consecutive id to access from different alias sets.
11471142
// Accesses between different groups doesn't need to be checked.
11481143
unsigned ASId = 0;
1149-
for (auto &AS : AST) {
1144+
for (const auto &AS : AST) {
11501145
int NumReadPtrChecks = 0;
11511146
int NumWritePtrChecks = 0;
11521147
bool CanDoAliasSetRT = true;
@@ -1196,7 +1191,7 @@ bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck,
11961191
ShouldCheckWrap, false)) {
11971192
LLVM_DEBUG(dbgs() << "LAA: Can't find bounds for ptr:"
11981193
<< *Access.getPointer() << '\n');
1199-
Retries.push_back({Access, AccessTy});
1194+
Retries.emplace_back(Access, AccessTy);
12001195
CanDoAliasSetRT = false;
12011196
}
12021197
}
@@ -1427,7 +1422,7 @@ static bool isNoWrapAddRec(Value *Ptr, const SCEVAddRecExpr *AR,
14271422
// non-wrapping for the *specific* value of Ptr.
14281423

14291424
// The arithmetic implied by an inbounds GEP can't overflow.
1430-
auto *GEP = dyn_cast<GetElementPtrInst>(Ptr);
1425+
const auto *GEP = dyn_cast<GetElementPtrInst>(Ptr);
14311426
if (!GEP || !GEP->isInBounds())
14321427
return false;
14331428

@@ -1504,7 +1499,7 @@ std::optional<int64_t> llvm::getPtrStride(PredicatedScalarEvolution &PSE,
15041499
return std::nullopt;
15051500
}
15061501

1507-
auto &DL = Lp->getHeader()->getDataLayout();
1502+
const auto &DL = Lp->getHeader()->getDataLayout();
15081503
TypeSize AllocSize = DL.getTypeAllocSize(AccessTy);
15091504
int64_t Size = AllocSize.getFixedValue();
15101505
const APInt &APStepVal = C->getAPInt();
@@ -1583,8 +1578,10 @@ std::optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA,
15831578
unsigned IdxWidth = DL.getIndexSizeInBits(ASA);
15841579

15851580
APInt OffsetA(IdxWidth, 0), OffsetB(IdxWidth, 0);
1586-
Value *PtrA1 = PtrA->stripAndAccumulateInBoundsConstantOffsets(DL, OffsetA);
1587-
Value *PtrB1 = PtrB->stripAndAccumulateInBoundsConstantOffsets(DL, OffsetB);
1581+
const Value *PtrA1 =
1582+
PtrA->stripAndAccumulateInBoundsConstantOffsets(DL, OffsetA);
1583+
const Value *PtrB1 =
1584+
PtrB->stripAndAccumulateInBoundsConstantOffsets(DL, OffsetB);
15881585

15891586
int Val;
15901587
if (PtrA1 == PtrB1) {
@@ -1917,10 +1914,10 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
19171914
const AccessAnalysis::MemAccessInfo &B, Instruction *BInst,
19181915
const DenseMap<Value *, SmallVector<const Value *, 16>>
19191916
&UnderlyingObjects) {
1920-
auto &DL = InnermostLoop->getHeader()->getDataLayout();
1917+
const auto &DL = InnermostLoop->getHeader()->getDataLayout();
19211918
auto &SE = *PSE.getSE();
1922-
auto [APtr, AIsWrite] = A;
1923-
auto [BPtr, BIsWrite] = B;
1919+
const auto &[APtr, AIsWrite] = A;
1920+
const auto &[BPtr, BIsWrite] = B;
19241921

19251922
// Two reads are independent.
19261923
if (!AIsWrite && !BIsWrite)
@@ -2252,7 +2249,7 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
22522249
}
22532250

22542251
bool MemoryDepChecker::areDepsSafe(
2255-
DepCandidates &AccessSets, MemAccessInfoList &CheckDeps,
2252+
const DepCandidates &AccessSets, const MemAccessInfoList &CheckDeps,
22562253
const DenseMap<Value *, SmallVector<const Value *, 16>>
22572254
&UnderlyingObjects) {
22582255

@@ -2307,7 +2304,7 @@ bool MemoryDepChecker::areDepsSafe(
23072304
// algorithm.
23082305
if (RecordDependences) {
23092306
if (Type != Dependence::NoDep)
2310-
Dependences.push_back(Dependence(A.second, B.second, Type));
2307+
Dependences.emplace_back(A.second, B.second, Type);
23112308

23122309
if (Dependences.size() >= MaxDependences) {
23132310
RecordDependences = false;
@@ -2397,7 +2394,7 @@ bool LoopAccessInfo::canAnalyzeLoop() {
23972394
return true;
23982395
}
23992396

2400-
bool LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
2397+
bool LoopAccessInfo::analyzeLoop(AAResults *AA, const LoopInfo *LI,
24012398
const TargetLibraryInfo *TLI,
24022399
DominatorTree *DT) {
24032400
// Holds the Load and Store instructions.
@@ -2638,7 +2635,7 @@ bool LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
26382635
Accesses.canCheckPtrAtRT(*PtrRtChecking, PSE->getSE(), TheLoop,
26392636
SymbolicStrides, UncomputablePtr, false);
26402637
if (!CanDoRTIfNeeded) {
2641-
auto *I = dyn_cast_or_null<Instruction>(UncomputablePtr);
2638+
const auto *I = dyn_cast_or_null<Instruction>(UncomputablePtr);
26422639
recordAnalysis("CantIdentifyArrayBounds", I)
26432640
<< "cannot identify array bounds";
26442641
LLVM_DEBUG(dbgs() << "LAA: We can't vectorize because we can't find "
@@ -2776,15 +2773,15 @@ bool LoopAccessInfo::blockNeedsPredication(BasicBlock *BB, Loop *TheLoop,
27762773
assert(TheLoop->contains(BB) && "Unknown block used");
27772774

27782775
// Blocks that do not dominate the latch need predication.
2779-
BasicBlock* Latch = TheLoop->getLoopLatch();
2776+
const BasicBlock *Latch = TheLoop->getLoopLatch();
27802777
return !DT->dominates(BB, Latch);
27812778
}
27822779

2783-
OptimizationRemarkAnalysis &LoopAccessInfo::recordAnalysis(StringRef RemarkName,
2784-
Instruction *I) {
2780+
OptimizationRemarkAnalysis &
2781+
LoopAccessInfo::recordAnalysis(StringRef RemarkName, const Instruction *I) {
27852782
assert(!Report && "Multiple reports generated");
27862783

2787-
Value *CodeRegion = TheLoop->getHeader();
2784+
const Value *CodeRegion = TheLoop->getHeader();
27882785
DebugLoc DL = TheLoop->getStartLoc();
27892786

27902787
if (I) {
@@ -2841,7 +2838,7 @@ static unsigned getGEPInductionOperand(const GetElementPtrInst *Gep) {
28412838
/// getGEPInductionOperand. However, if there is some other non-loop-invariant
28422839
/// operand, it returns that instead.
28432840
static Value *stripGetElementPtr(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
2844-
GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr);
2841+
auto *GEP = dyn_cast<GetElementPtrInst>(Ptr);
28452842
if (!GEP)
28462843
return Ptr;
28472844

@@ -3078,7 +3075,7 @@ void LoopAccessInfo::print(raw_ostream &OS, unsigned Depth) const {
30783075
}
30793076

30803077
const LoopAccessInfo &LoopAccessInfoManager::getInfo(Loop &L) {
3081-
auto [It, Inserted] = LoopAccessInfoMap.insert({&L, nullptr});
3078+
const auto &[It, Inserted] = LoopAccessInfoMap.insert({&L, nullptr});
30823079

30833080
if (Inserted)
30843081
It->second =

0 commit comments

Comments
 (0)