Skip to content

Commit 7163603

Browse files
committed
[Polly] Use const SCEV * explicitly in more places. (NFC)
Use const SCEV * explicitly in more places to prepare for #91961.
1 parent 8bf19ec commit 7163603

File tree

7 files changed

+47
-46
lines changed

7 files changed

+47
-46
lines changed

polly/lib/Analysis/ScopBuilder.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ bool ScopBuilder::buildAccessMemIntrinsic(MemAccInst Inst, ScopStmt *Stmt) {
15671567
return false;
15681568

15691569
auto *L = LI.getLoopFor(Inst->getParent());
1570-
auto *LengthVal = SE.getSCEVAtScope(MemIntr->getLength(), L);
1570+
const SCEV *LengthVal = SE.getSCEVAtScope(MemIntr->getLength(), L);
15711571
assert(LengthVal);
15721572

15731573
// Check if the length val is actually affine or if we overapproximate it
@@ -1586,7 +1586,7 @@ bool ScopBuilder::buildAccessMemIntrinsic(MemAccInst Inst, ScopStmt *Stmt) {
15861586
auto *DestPtrVal = MemIntr->getDest();
15871587
assert(DestPtrVal);
15881588

1589-
auto *DestAccFunc = SE.getSCEVAtScope(DestPtrVal, L);
1589+
const SCEV *DestAccFunc = SE.getSCEVAtScope(DestPtrVal, L);
15901590
assert(DestAccFunc);
15911591
// Ignore accesses to "NULL".
15921592
// TODO: We could use this to optimize the region further, e.g., intersect
@@ -1616,7 +1616,7 @@ bool ScopBuilder::buildAccessMemIntrinsic(MemAccInst Inst, ScopStmt *Stmt) {
16161616
auto *SrcPtrVal = MemTrans->getSource();
16171617
assert(SrcPtrVal);
16181618

1619-
auto *SrcAccFunc = SE.getSCEVAtScope(SrcPtrVal, L);
1619+
const SCEV *SrcAccFunc = SE.getSCEVAtScope(SrcPtrVal, L);
16201620
assert(SrcAccFunc);
16211621
// Ignore accesses to "NULL".
16221622
// TODO: See above TODO
@@ -1643,7 +1643,7 @@ bool ScopBuilder::buildAccessCallInst(MemAccInst Inst, ScopStmt *Stmt) {
16431643
if (CI->doesNotAccessMemory() || isIgnoredIntrinsic(CI) || isDebugCall(CI))
16441644
return true;
16451645

1646-
auto *AF = SE.getConstant(IntegerType::getInt64Ty(CI->getContext()), 0);
1646+
const SCEV *AF = SE.getConstant(IntegerType::getInt64Ty(CI->getContext()), 0);
16471647
auto *CalledFunction = CI->getCalledFunction();
16481648
MemoryEffects ME = AA.getMemoryEffects(CalledFunction);
16491649
if (ME.doesNotAccessMemory())
@@ -1658,7 +1658,7 @@ bool ScopBuilder::buildAccessCallInst(MemAccInst Inst, ScopStmt *Stmt) {
16581658
if (!Arg->getType()->isPointerTy())
16591659
continue;
16601660

1661-
auto *ArgSCEV = SE.getSCEVAtScope(Arg, L);
1661+
const SCEV *ArgSCEV = SE.getSCEVAtScope(Arg, L);
16621662
if (ArgSCEV->isZero())
16631663
continue;
16641664

@@ -2169,7 +2169,7 @@ static bool isDivisible(const SCEV *Expr, unsigned Size, ScalarEvolution &SE) {
21692169

21702170
// Only one factor needs to be divisible.
21712171
if (auto *MulExpr = dyn_cast<SCEVMulExpr>(Expr)) {
2172-
for (auto *FactorExpr : MulExpr->operands())
2172+
for (const SCEV *FactorExpr : MulExpr->operands())
21732173
if (isDivisible(FactorExpr, Size, SE))
21742174
return true;
21752175
return false;
@@ -2178,15 +2178,15 @@ static bool isDivisible(const SCEV *Expr, unsigned Size, ScalarEvolution &SE) {
21782178
// For other n-ary expressions (Add, AddRec, Max,...) all operands need
21792179
// to be divisible.
21802180
if (auto *NAryExpr = dyn_cast<SCEVNAryExpr>(Expr)) {
2181-
for (auto *OpExpr : NAryExpr->operands())
2181+
for (const SCEV *OpExpr : NAryExpr->operands())
21822182
if (!isDivisible(OpExpr, Size, SE))
21832183
return false;
21842184
return true;
21852185
}
21862186

2187-
auto *SizeSCEV = SE.getConstant(Expr->getType(), Size);
2188-
auto *UDivSCEV = SE.getUDivExpr(Expr, SizeSCEV);
2189-
auto *MulSCEV = SE.getMulExpr(UDivSCEV, SizeSCEV);
2187+
const SCEV *SizeSCEV = SE.getConstant(Expr->getType(), Size);
2188+
const SCEV *UDivSCEV = SE.getUDivExpr(Expr, SizeSCEV);
2189+
const SCEV *MulSCEV = SE.getMulExpr(UDivSCEV, SizeSCEV);
21902190
return MulSCEV == Expr;
21912191
}
21922192

@@ -3672,7 +3672,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
36723672
}
36733673

36743674
// Create memory accesses for global reads since all arrays are now known.
3675-
auto *AF = SE.getConstant(IntegerType::getInt64Ty(SE.getContext()), 0);
3675+
const SCEV *AF = SE.getConstant(IntegerType::getInt64Ty(SE.getContext()), 0);
36763676
for (auto GlobalReadPair : GlobalReads) {
36773677
ScopStmt *GlobalReadStmt = GlobalReadPair.first;
36783678
Instruction *GlobalRead = GlobalReadPair.second;

polly/lib/Analysis/ScopDetection.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,15 +520,15 @@ bool ScopDetection::involvesMultiplePtrs(const SCEV *S0, const SCEV *S1,
520520
if (!V->getType()->isPointerTy())
521521
continue;
522522

523-
auto *PtrSCEV = SE.getSCEVAtScope(V, Scope);
523+
const SCEV *PtrSCEV = SE.getSCEVAtScope(V, Scope);
524524
if (isa<SCEVConstant>(PtrSCEV))
525525
continue;
526526

527527
auto *BasePtr = dyn_cast<SCEVUnknown>(SE.getPointerBase(PtrSCEV));
528528
if (!BasePtr)
529529
return true;
530530

531-
auto *BasePtrVal = BasePtr->getValue();
531+
Value *BasePtrVal = BasePtr->getValue();
532532
if (PtrVals.insert(BasePtrVal).second) {
533533
for (auto *PtrVal : PtrVals)
534534
if (PtrVal != BasePtrVal && !AA.isNoAlias(PtrVal, BasePtrVal))
@@ -720,7 +720,8 @@ bool ScopDetection::isValidCallInst(CallInst &CI,
720720

721721
// Bail if a pointer argument has a base address not known to
722722
// ScalarEvolution. Note that a zero pointer is acceptable.
723-
auto *ArgSCEV = SE.getSCEVAtScope(Arg, LI.getLoopFor(CI.getParent()));
723+
const SCEV *ArgSCEV =
724+
SE.getSCEVAtScope(Arg, LI.getLoopFor(CI.getParent()));
724725
if (ArgSCEV->isZero())
725726
continue;
726727

@@ -891,7 +892,7 @@ ScopDetection::getDelinearizationTerms(DetectionContext &Context,
891892
if (auto *AF2 = dyn_cast<SCEVMulExpr>(Op)) {
892893
SmallVector<const SCEV *, 0> Operands;
893894

894-
for (auto *MulOp : AF2->operands()) {
895+
for (const SCEV *MulOp : AF2->operands()) {
895896
if (auto *Const = dyn_cast<SCEVConstant>(MulOp))
896897
Operands.push_back(Const);
897898
if (auto *Unknown = dyn_cast<SCEVUnknown>(MulOp)) {
@@ -1366,7 +1367,7 @@ bool ScopDetection::isValidLoop(Loop *L, DetectionContext &Context) {
13661367
ScopDetection::LoopStats
13671368
ScopDetection::countBeneficialSubLoops(Loop *L, ScalarEvolution &SE,
13681369
unsigned MinProfitableTrips) {
1369-
auto *TripCount = SE.getBackedgeTakenCount(L);
1370+
const SCEV *TripCount = SE.getBackedgeTakenCount(L);
13701371

13711372
int NumLoops = 1;
13721373
int MaxLoopDepth = 1;

polly/lib/Analysis/ScopInfo.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static const ScopArrayInfo *identifyBasePtrOriginSAI(Scop *S, Value *BasePtr) {
215215

216216
ScalarEvolution &SE = *S->getSE();
217217

218-
auto *OriginBaseSCEV =
218+
const SCEV *OriginBaseSCEV =
219219
SE.getPointerBase(SE.getSCEV(BasePtrLI->getPointerOperand()));
220220
if (!OriginBaseSCEV)
221221
return nullptr;
@@ -713,11 +713,11 @@ void MemoryAccess::computeBoundsOnAccessRelation(unsigned ElementSize) {
713713
if (!Ptr || !SE->isSCEVable(Ptr->getType()))
714714
return;
715715

716-
auto *PtrSCEV = SE->getSCEV(Ptr);
716+
const SCEV *PtrSCEV = SE->getSCEV(Ptr);
717717
if (isa<SCEVCouldNotCompute>(PtrSCEV))
718718
return;
719719

720-
auto *BasePtrSCEV = SE->getPointerBase(PtrSCEV);
720+
const SCEV *BasePtrSCEV = SE->getPointerBase(PtrSCEV);
721721
if (BasePtrSCEV && !isa<SCEVCouldNotCompute>(BasePtrSCEV))
722722
PtrSCEV = SE->getMinusSCEV(PtrSCEV, BasePtrSCEV);
723723

@@ -1384,10 +1384,10 @@ class SCEVSensitiveParameterRewriter final
13841384
}
13851385

13861386
const SCEV *visitAddRecExpr(const SCEVAddRecExpr *E) {
1387-
auto *Start = visit(E->getStart());
1388-
auto *AddRec = SE.getAddRecExpr(SE.getConstant(E->getType(), 0),
1389-
visit(E->getStepRecurrence(SE)),
1390-
E->getLoop(), SCEV::FlagAnyWrap);
1387+
const SCEV *Start = visit(E->getStart());
1388+
const SCEV *AddRec = SE.getAddRecExpr(SE.getConstant(E->getType(), 0),
1389+
visit(E->getStepRecurrence(SE)),
1390+
E->getLoop(), SCEV::FlagAnyWrap);
13911391
return SE.getAddExpr(Start, AddRec);
13921392
}
13931393

polly/lib/Support/SCEVAffinator.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ PWACtx SCEVAffinator::visitTruncateExpr(const SCEVTruncateExpr *Expr) {
281281
// to fit in the new type size instead of introducing a modulo with a very
282282
// large constant.
283283

284-
auto *Op = Expr->getOperand();
284+
const SCEV *Op = Expr->getOperand();
285285
auto OpPWAC = visit(Op);
286286

287287
unsigned Width = TD.getTypeSizeInBits(Expr->getType());
@@ -354,7 +354,7 @@ PWACtx SCEVAffinator::visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
354354
// bit-width is bigger than MaxZextSmallBitWidth we will employ overflow
355355
// assumptions and assume the "former negative" piece will not exist.
356356

357-
auto *Op = Expr->getOperand();
357+
const SCEV *Op = Expr->getOperand();
358358
auto OpPWAC = visit(Op);
359359

360360
// If the width is to big we assume the negative part does not occur.
@@ -483,8 +483,8 @@ PWACtx SCEVAffinator::visitUDivExpr(const SCEVUDivExpr *Expr) {
483483
// For the dividend we could choose from the different representation
484484
// schemes introduced for zero-extend operations but for now we will
485485
// simply use an assumption.
486-
auto *Dividend = Expr->getLHS();
487-
auto *Divisor = Expr->getRHS();
486+
const SCEV *Dividend = Expr->getLHS();
487+
const SCEV *Divisor = Expr->getRHS();
488488
assert(isa<SCEVConstant>(Divisor) &&
489489
"UDiv is no parameter but has a non-constant RHS.");
490490

@@ -518,13 +518,13 @@ PWACtx SCEVAffinator::visitSDivInstruction(Instruction *SDiv) {
518518

519519
auto *Scope = getScope();
520520
auto *Divisor = SDiv->getOperand(1);
521-
auto *DivisorSCEV = SE.getSCEVAtScope(Divisor, Scope);
521+
const SCEV *DivisorSCEV = SE.getSCEVAtScope(Divisor, Scope);
522522
auto DivisorPWAC = visit(DivisorSCEV);
523523
assert(isa<SCEVConstant>(DivisorSCEV) &&
524524
"SDiv is no parameter but has a non-constant RHS.");
525525

526526
auto *Dividend = SDiv->getOperand(0);
527-
auto *DividendSCEV = SE.getSCEVAtScope(Dividend, Scope);
527+
const SCEV *DividendSCEV = SE.getSCEVAtScope(Dividend, Scope);
528528
auto DividendPWAC = visit(DividendSCEV);
529529
DividendPWAC = combine(DividendPWAC, DivisorPWAC, isl_pw_aff_tdiv_q);
530530
return DividendPWAC;
@@ -535,13 +535,13 @@ PWACtx SCEVAffinator::visitSRemInstruction(Instruction *SRem) {
535535

536536
auto *Scope = getScope();
537537
auto *Divisor = SRem->getOperand(1);
538-
auto *DivisorSCEV = SE.getSCEVAtScope(Divisor, Scope);
538+
const SCEV *DivisorSCEV = SE.getSCEVAtScope(Divisor, Scope);
539539
auto DivisorPWAC = visit(DivisorSCEV);
540540
assert(isa<ConstantInt>(Divisor) &&
541541
"SRem is no parameter but has a non-constant RHS.");
542542

543543
auto *Dividend = SRem->getOperand(0);
544-
auto *DividendSCEV = SE.getSCEVAtScope(Dividend, Scope);
544+
const SCEV *DividendSCEV = SE.getSCEVAtScope(Dividend, Scope);
545545
auto DividendPWAC = visit(DividendSCEV);
546546
DividendPWAC = combine(DividendPWAC, DivisorPWAC, isl_pw_aff_tdiv_r);
547547
return DividendPWAC;

polly/lib/Support/SCEVValidator.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,17 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
403403
if (!PollyAllowUnsignedOperations)
404404
return ValidatorResult(SCEVType::INVALID);
405405

406-
auto *Dividend = Expr->getLHS();
407-
auto *Divisor = Expr->getRHS();
406+
const SCEV *Dividend = Expr->getLHS();
407+
const SCEV *Divisor = Expr->getRHS();
408408
return visitDivision(Dividend, Divisor, Expr);
409409
}
410410

411411
ValidatorResult visitSDivInstruction(Instruction *SDiv, const SCEV *Expr) {
412412
assert(SDiv->getOpcode() == Instruction::SDiv &&
413413
"Assumed SDiv instruction!");
414414

415-
auto *Dividend = SE.getSCEV(SDiv->getOperand(0));
416-
auto *Divisor = SE.getSCEV(SDiv->getOperand(1));
415+
const SCEV *Dividend = SE.getSCEV(SDiv->getOperand(0));
416+
const SCEV *Divisor = SE.getSCEV(SDiv->getOperand(1));
417417
return visitDivision(Dividend, Divisor, Expr, SDiv);
418418
}
419419

@@ -427,7 +427,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
427427
return visitGenericInst(SRem, S);
428428

429429
auto *Dividend = SRem->getOperand(0);
430-
auto *DividendSCEV = SE.getSCEV(Dividend);
430+
const SCEV *DividendSCEV = SE.getSCEV(Dividend);
431431
return visit(DividendSCEV);
432432
}
433433

@@ -566,11 +566,11 @@ class SCEVFindValues final {
566566
Inst->getOpcode() != Instruction::SDiv))
567567
return false;
568568

569-
auto *Dividend = SE.getSCEV(Inst->getOperand(1));
569+
const SCEV *Dividend = SE.getSCEV(Inst->getOperand(1));
570570
if (!isa<SCEVConstant>(Dividend))
571571
return false;
572572

573-
auto *Divisor = SE.getSCEV(Inst->getOperand(0));
573+
const SCEV *Divisor = SE.getSCEV(Inst->getOperand(0));
574574
SCEVFindValues FindValues(SE, Values);
575575
SCEVTraversal<SCEVFindValues> ST(FindValues);
576576
ST.visitAll(Dividend);
@@ -623,7 +623,7 @@ bool polly::isAffineExpr(const Region *R, llvm::Loop *Scope, const SCEV *Expr,
623623

624624
static bool isAffineExpr(Value *V, const Region *R, Loop *Scope,
625625
ScalarEvolution &SE, ParameterSetTy &Params) {
626-
auto *E = SE.getSCEV(V);
626+
const SCEV *E = SE.getSCEV(V);
627627
if (isa<SCEVCouldNotCompute>(E))
628628
return false;
629629

@@ -684,10 +684,10 @@ polly::extractConstantFactor(const SCEV *S, ScalarEvolution &SE) {
684684

685685
auto *AddRec = dyn_cast<SCEVAddRecExpr>(S);
686686
if (AddRec) {
687-
auto *StartExpr = AddRec->getStart();
687+
const SCEV *StartExpr = AddRec->getStart();
688688
if (StartExpr->isZero()) {
689689
auto StepPair = extractConstantFactor(AddRec->getStepRecurrence(SE), SE);
690-
auto *LeftOverAddRec =
690+
const SCEV *LeftOverAddRec =
691691
SE.getAddRecExpr(StartExpr, StepPair.second, AddRec->getLoop(),
692692
AddRec->getNoWrapFlags());
693693
return std::make_pair(StepPair.first, LeftOverAddRec);
@@ -717,7 +717,7 @@ polly::extractConstantFactor(const SCEV *S, ScalarEvolution &SE) {
717717
return std::make_pair(ConstPart, S);
718718
}
719719

720-
auto *NewAdd = SE.getAddExpr(LeftOvers, Add->getNoWrapFlags());
720+
const SCEV *NewAdd = SE.getAddExpr(LeftOvers, Add->getNoWrapFlags());
721721
return std::make_pair(Factor, NewAdd);
722722
}
723723

@@ -726,7 +726,7 @@ polly::extractConstantFactor(const SCEV *S, ScalarEvolution &SE) {
726726
return std::make_pair(ConstPart, S);
727727

728728
SmallVector<const SCEV *, 4> LeftOvers;
729-
for (auto *Op : Mul->operands())
729+
for (const SCEV *Op : Mul->operands())
730730
if (isa<SCEVConstant>(Op))
731731
ConstPart = cast<SCEVConstant>(SE.getMulExpr(ConstPart, Op));
732732
else

polly/lib/Support/ScopHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ struct ScopExpander final : SCEVVisitor<ScopExpander, const SCEV *> {
315315
auto *InstClone = Inst->clone();
316316
for (auto &Op : Inst->operands()) {
317317
assert(GenSE.isSCEVable(Op->getType()));
318-
auto *OpSCEV = GenSE.getSCEV(Op);
318+
const SCEV *OpSCEV = GenSE.getSCEV(Op);
319319
auto *OpClone = expandCodeFor(OpSCEV, Op->getType(), IP);
320320
InstClone->replaceUsesOfWith(Op, OpClone);
321321
}
@@ -330,7 +330,7 @@ struct ScopExpander final : SCEVVisitor<ScopExpander, const SCEV *> {
330330
// If a value mapping was given try if the underlying value is remapped.
331331
Value *NewVal = VMap ? VMap->lookup(E->getValue()) : nullptr;
332332
if (NewVal) {
333-
auto *NewE = GenSE.getSCEV(NewVal);
333+
const SCEV *NewE = GenSE.getSCEV(NewVal);
334334

335335
// While the mapped value might be different the SCEV representation might
336336
// not be. To this end we will check before we go into recursion here.

polly/lib/Support/VirtualInstruction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ VirtualUse VirtualUse::create(Scop *S, ScopStmt *UserStmt, Loop *UserScope,
6565
// We assume synthesizable which practically should have the same effect.
6666
auto *SE = S->getSE();
6767
if (SE->isSCEVable(Val->getType())) {
68-
auto *ScevExpr = SE->getSCEVAtScope(Val, UserScope);
68+
const SCEV *ScevExpr = SE->getSCEVAtScope(Val, UserScope);
6969
if (!UserStmt || canSynthesize(Val, *UserStmt->getParent(), SE, UserScope))
7070
return VirtualUse(UserStmt, Val, Synthesizable, ScevExpr, nullptr);
7171
}

0 commit comments

Comments
 (0)