@@ -181,7 +181,7 @@ const SCEV *llvm::replaceSymbolicStrideSCEV(PredicatedScalarEvolution &PSE,
181
181
}
182
182
183
183
RuntimeCheckingPtrGroup::RuntimeCheckingPtrGroup (
184
- unsigned Index, RuntimePointerChecking &RtCheck)
184
+ unsigned Index, const RuntimePointerChecking &RtCheck)
185
185
: High(RtCheck.Pointers[Index].End), Low(RtCheck.Pointers[Index].Start),
186
186
AddressSpace(RtCheck.Pointers[Index]
187
187
.PointerValue->getType ()
@@ -280,8 +280,8 @@ bool RuntimePointerChecking::tryToCreateDiffCheck(
280
280
if (CGI.Members .size () != 1 || CGJ.Members .size () != 1 )
281
281
return false ;
282
282
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 ]];
285
285
286
286
// If either pointer is read and written, multiple checks may be needed. Bail
287
287
// out.
@@ -385,7 +385,7 @@ SmallVector<RuntimePointerCheck, 4> RuntimePointerChecking::generateChecks() {
385
385
386
386
if (needsChecking (CGI, CGJ)) {
387
387
CanUseDiffCheck = CanUseDiffCheck && tryToCreateDiffCheck (CGI, CGJ);
388
- Checks.push_back ( std::make_pair ( &CGI, &CGJ) );
388
+ Checks.emplace_back ( &CGI, &CGJ);
389
389
}
390
390
}
391
391
}
@@ -420,8 +420,8 @@ static const SCEV *getMinFromExprs(const SCEV *I, const SCEV *J,
420
420
return C->getValue ()->isNegative () ? J : I;
421
421
}
422
422
423
- bool RuntimeCheckingPtrGroup::addPointer (unsigned Index,
424
- RuntimePointerChecking &RtCheck) {
423
+ bool RuntimeCheckingPtrGroup::addPointer (
424
+ unsigned Index, const RuntimePointerChecking &RtCheck) {
425
425
return addPointer (
426
426
Index, RtCheck.Pointers [Index].Start , RtCheck.Pointers [Index].End ,
427
427
RtCheck.Pointers [Index].PointerValue ->getType ()->getPointerAddressSpace (),
@@ -507,7 +507,7 @@ void RuntimePointerChecking::groupChecks(
507
507
// pointers to the same underlying object.
508
508
if (!UseDependencies) {
509
509
for (unsigned I = 0 ; I < Pointers.size (); ++I)
510
- CheckingGroups.push_back ( RuntimeCheckingPtrGroup ( I, *this ) );
510
+ CheckingGroups.emplace_back ( I, *this );
511
511
return ;
512
512
}
513
513
@@ -575,7 +575,7 @@ void RuntimePointerChecking::groupChecks(
575
575
// We couldn't add this pointer to any existing set or the threshold
576
576
// for the number of comparisons has been reached. Create a new group
577
577
// to hold the current pointer.
578
- Groups.push_back ( RuntimeCheckingPtrGroup ( Pointer, *this ) );
578
+ Groups.emplace_back ( Pointer, *this );
579
579
}
580
580
}
581
581
@@ -605,10 +605,7 @@ bool RuntimePointerChecking::needsChecking(unsigned I, unsigned J) const {
605
605
return false ;
606
606
607
607
// 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 ;
612
609
}
613
610
614
611
void RuntimePointerChecking::printChecks (
@@ -658,7 +655,7 @@ class AccessAnalysis {
658
655
typedef PointerIntPair<Value *, 1 , bool > MemAccessInfo;
659
656
typedef SmallVector<MemAccessInfo, 8 > MemAccessInfoList;
660
657
661
- AccessAnalysis (Loop *TheLoop, AAResults *AA, LoopInfo *LI,
658
+ AccessAnalysis (const Loop *TheLoop, AAResults *AA, const LoopInfo *LI,
662
659
MemoryDepChecker::DepCandidates &DA,
663
660
PredicatedScalarEvolution &PSE,
664
661
SmallPtrSetImpl<MDNode *> &LoopAliasScopes)
@@ -669,7 +666,7 @@ class AccessAnalysis {
669
666
}
670
667
671
668
// / 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) {
673
670
Value *Ptr = const_cast <Value *>(Loc.Ptr );
674
671
AST.add (adjustLoc (Loc));
675
672
Accesses[MemAccessInfo (Ptr, false )].insert (AccessTy);
@@ -678,7 +675,7 @@ class AccessAnalysis {
678
675
}
679
676
680
677
// / Register a store.
681
- void addStore (MemoryLocation &Loc, Type *AccessTy) {
678
+ void addStore (const MemoryLocation &Loc, Type *AccessTy) {
682
679
Value *Ptr = const_cast <Value *>(Loc.Ptr );
683
680
AST.add (adjustLoc (Loc));
684
681
Accesses[MemAccessInfo (Ptr, true )].insert (AccessTy);
@@ -718,18 +715,18 @@ class AccessAnalysis {
718
715
// /
719
716
// / Note that this can later be cleared if we retry memcheck analysis without
720
717
// / dependency checking (i.e. FoundNonConstantDistanceDependence).
721
- bool isDependencyCheckNeeded () { return !CheckDeps.empty (); }
718
+ bool isDependencyCheckNeeded () const { return !CheckDeps.empty (); }
722
719
723
720
// / We decided that no dependence analysis would be used. Reset the state.
724
721
void resetDepChecks (MemoryDepChecker &DepChecker) {
725
722
CheckDeps.clear ();
726
723
DepChecker.clearDependences ();
727
724
}
728
725
729
- MemAccessInfoList &getDependenciesToCheck () { return CheckDeps; }
726
+ const MemAccessInfoList &getDependenciesToCheck () const { return CheckDeps; }
730
727
731
728
const DenseMap<Value *, SmallVector<const Value *, 16 >> &
732
- getUnderlyingObjects () {
729
+ getUnderlyingObjects () const {
733
730
return UnderlyingObjects;
734
731
}
735
732
@@ -844,10 +841,8 @@ static bool isNoWrap(PredicatedScalarEvolution &PSE,
844
841
return true ;
845
842
846
843
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);
851
846
}
852
847
853
848
static void visitPointers (Value *StartPtr, const Loop &InnermostLoop,
@@ -926,7 +921,7 @@ static void findForkedSCEVs(
926
921
unsigned Opcode = I->getOpcode ();
927
922
switch (Opcode) {
928
923
case Instruction::GetElementPtr: {
929
- GetElementPtrInst *GEP = cast<GetElementPtrInst>(I);
924
+ auto *GEP = cast<GetElementPtrInst>(I);
930
925
Type *SourceTy = GEP->getSourceElementType ();
931
926
// We only handle base + single offset GEPs here for now.
932
927
// Not dealing with preexisting gathers yet, so no vectors.
@@ -1081,7 +1076,7 @@ bool AccessAnalysis::createCheckForAccess(RuntimePointerChecking &RtCheck,
1081
1076
SmallVector<PointerIntPair<const SCEV *, 1 , bool >> TranslatedPtrs =
1082
1077
findForkedPointer (PSE, StridesMap, Ptr, TheLoop);
1083
1078
1084
- for (auto &P : TranslatedPtrs) {
1079
+ for (const auto &P : TranslatedPtrs) {
1085
1080
const SCEV *PtrExpr = get<0 >(P);
1086
1081
if (!hasComputableBounds (PSE, Ptr, PtrExpr, TheLoop, Assume))
1087
1082
return false ;
@@ -1146,7 +1141,7 @@ bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck,
1146
1141
// We assign a consecutive id to access from different alias sets.
1147
1142
// Accesses between different groups doesn't need to be checked.
1148
1143
unsigned ASId = 0 ;
1149
- for (auto &AS : AST) {
1144
+ for (const auto &AS : AST) {
1150
1145
int NumReadPtrChecks = 0 ;
1151
1146
int NumWritePtrChecks = 0 ;
1152
1147
bool CanDoAliasSetRT = true ;
@@ -1196,7 +1191,7 @@ bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck,
1196
1191
ShouldCheckWrap, false )) {
1197
1192
LLVM_DEBUG (dbgs () << " LAA: Can't find bounds for ptr:"
1198
1193
<< *Access.getPointer () << ' \n ' );
1199
- Retries.push_back ({ Access, AccessTy} );
1194
+ Retries.emplace_back ( Access, AccessTy);
1200
1195
CanDoAliasSetRT = false ;
1201
1196
}
1202
1197
}
@@ -1427,7 +1422,7 @@ static bool isNoWrapAddRec(Value *Ptr, const SCEVAddRecExpr *AR,
1427
1422
// non-wrapping for the *specific* value of Ptr.
1428
1423
1429
1424
// 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);
1431
1426
if (!GEP || !GEP->isInBounds ())
1432
1427
return false ;
1433
1428
@@ -1504,7 +1499,7 @@ std::optional<int64_t> llvm::getPtrStride(PredicatedScalarEvolution &PSE,
1504
1499
return std::nullopt;
1505
1500
}
1506
1501
1507
- auto &DL = Lp->getHeader ()->getDataLayout ();
1502
+ const auto &DL = Lp->getHeader ()->getDataLayout ();
1508
1503
TypeSize AllocSize = DL.getTypeAllocSize (AccessTy);
1509
1504
int64_t Size = AllocSize.getFixedValue ();
1510
1505
const APInt &APStepVal = C->getAPInt ();
@@ -1583,8 +1578,10 @@ std::optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA,
1583
1578
unsigned IdxWidth = DL.getIndexSizeInBits (ASA);
1584
1579
1585
1580
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);
1588
1585
1589
1586
int Val;
1590
1587
if (PtrA1 == PtrB1) {
@@ -1917,10 +1914,10 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
1917
1914
const AccessAnalysis::MemAccessInfo &B, Instruction *BInst,
1918
1915
const DenseMap<Value *, SmallVector<const Value *, 16 >>
1919
1916
&UnderlyingObjects) {
1920
- auto &DL = InnermostLoop->getHeader ()->getDataLayout ();
1917
+ const auto &DL = InnermostLoop->getHeader ()->getDataLayout ();
1921
1918
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;
1924
1921
1925
1922
// Two reads are independent.
1926
1923
if (!AIsWrite && !BIsWrite)
@@ -2252,7 +2249,7 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
2252
2249
}
2253
2250
2254
2251
bool MemoryDepChecker::areDepsSafe (
2255
- DepCandidates &AccessSets, MemAccessInfoList &CheckDeps,
2252
+ const DepCandidates &AccessSets, const MemAccessInfoList &CheckDeps,
2256
2253
const DenseMap<Value *, SmallVector<const Value *, 16 >>
2257
2254
&UnderlyingObjects) {
2258
2255
@@ -2307,7 +2304,7 @@ bool MemoryDepChecker::areDepsSafe(
2307
2304
// algorithm.
2308
2305
if (RecordDependences) {
2309
2306
if (Type != Dependence::NoDep)
2310
- Dependences.push_back ( Dependence ( A.second , B.second , Type) );
2307
+ Dependences.emplace_back ( A.second , B.second , Type);
2311
2308
2312
2309
if (Dependences.size () >= MaxDependences) {
2313
2310
RecordDependences = false ;
@@ -2397,7 +2394,7 @@ bool LoopAccessInfo::canAnalyzeLoop() {
2397
2394
return true ;
2398
2395
}
2399
2396
2400
- bool LoopAccessInfo::analyzeLoop (AAResults *AA, LoopInfo *LI,
2397
+ bool LoopAccessInfo::analyzeLoop (AAResults *AA, const LoopInfo *LI,
2401
2398
const TargetLibraryInfo *TLI,
2402
2399
DominatorTree *DT) {
2403
2400
// Holds the Load and Store instructions.
@@ -2638,7 +2635,7 @@ bool LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
2638
2635
Accesses.canCheckPtrAtRT (*PtrRtChecking, PSE->getSE (), TheLoop,
2639
2636
SymbolicStrides, UncomputablePtr, false );
2640
2637
if (!CanDoRTIfNeeded) {
2641
- auto *I = dyn_cast_or_null<Instruction>(UncomputablePtr);
2638
+ const auto *I = dyn_cast_or_null<Instruction>(UncomputablePtr);
2642
2639
recordAnalysis (" CantIdentifyArrayBounds" , I)
2643
2640
<< " cannot identify array bounds" ;
2644
2641
LLVM_DEBUG (dbgs () << " LAA: We can't vectorize because we can't find "
@@ -2776,15 +2773,15 @@ bool LoopAccessInfo::blockNeedsPredication(BasicBlock *BB, Loop *TheLoop,
2776
2773
assert (TheLoop->contains (BB) && " Unknown block used" );
2777
2774
2778
2775
// Blocks that do not dominate the latch need predication.
2779
- BasicBlock* Latch = TheLoop->getLoopLatch ();
2776
+ const BasicBlock * Latch = TheLoop->getLoopLatch ();
2780
2777
return !DT->dominates (BB, Latch);
2781
2778
}
2782
2779
2783
- OptimizationRemarkAnalysis &LoopAccessInfo::recordAnalysis (StringRef RemarkName,
2784
- Instruction *I) {
2780
+ OptimizationRemarkAnalysis &
2781
+ LoopAccessInfo::recordAnalysis (StringRef RemarkName, const Instruction *I) {
2785
2782
assert (!Report && " Multiple reports generated" );
2786
2783
2787
- Value *CodeRegion = TheLoop->getHeader ();
2784
+ const Value *CodeRegion = TheLoop->getHeader ();
2788
2785
DebugLoc DL = TheLoop->getStartLoc ();
2789
2786
2790
2787
if (I) {
@@ -2841,7 +2838,7 @@ static unsigned getGEPInductionOperand(const GetElementPtrInst *Gep) {
2841
2838
// / getGEPInductionOperand. However, if there is some other non-loop-invariant
2842
2839
// / operand, it returns that instead.
2843
2840
static Value *stripGetElementPtr (Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
2844
- GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr);
2841
+ auto *GEP = dyn_cast<GetElementPtrInst>(Ptr);
2845
2842
if (!GEP)
2846
2843
return Ptr;
2847
2844
@@ -3078,7 +3075,7 @@ void LoopAccessInfo::print(raw_ostream &OS, unsigned Depth) const {
3078
3075
}
3079
3076
3080
3077
const LoopAccessInfo &LoopAccessInfoManager::getInfo (Loop &L) {
3081
- auto [It, Inserted] = LoopAccessInfoMap.insert ({&L, nullptr });
3078
+ const auto & [It, Inserted] = LoopAccessInfoMap.insert ({&L, nullptr });
3082
3079
3083
3080
if (Inserted)
3084
3081
It->second =
0 commit comments