[polly] 7163603 - [Polly] Use const SCEV * explicitly in more places. (NFC)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 03:30:16 PST 2024


Author: Florian Hahn
Date: 2024-12-13T11:29:33Z
New Revision: 716360367fbdabac2c374c19b8746f4de49a5599

URL: https://github.com/llvm/llvm-project/commit/716360367fbdabac2c374c19b8746f4de49a5599
DIFF: https://github.com/llvm/llvm-project/commit/716360367fbdabac2c374c19b8746f4de49a5599.diff

LOG: [Polly] Use const SCEV * explicitly in more places. (NFC)

Use const SCEV * explicitly in more places to prepare for
https://github.com/llvm/llvm-project/pull/91961.

Added: 
    

Modified: 
    polly/lib/Analysis/ScopBuilder.cpp
    polly/lib/Analysis/ScopDetection.cpp
    polly/lib/Analysis/ScopInfo.cpp
    polly/lib/Support/SCEVAffinator.cpp
    polly/lib/Support/SCEVValidator.cpp
    polly/lib/Support/ScopHelper.cpp
    polly/lib/Support/VirtualInstruction.cpp

Removed: 
    


################################################################################
diff  --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp
index c05fc1a347c258..82fa9e11550f2f 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -1567,7 +1567,7 @@ bool ScopBuilder::buildAccessMemIntrinsic(MemAccInst Inst, ScopStmt *Stmt) {
     return false;
 
   auto *L = LI.getLoopFor(Inst->getParent());
-  auto *LengthVal = SE.getSCEVAtScope(MemIntr->getLength(), L);
+  const SCEV *LengthVal = SE.getSCEVAtScope(MemIntr->getLength(), L);
   assert(LengthVal);
 
   // Check if the length val is actually affine or if we overapproximate it
@@ -1586,7 +1586,7 @@ bool ScopBuilder::buildAccessMemIntrinsic(MemAccInst Inst, ScopStmt *Stmt) {
   auto *DestPtrVal = MemIntr->getDest();
   assert(DestPtrVal);
 
-  auto *DestAccFunc = SE.getSCEVAtScope(DestPtrVal, L);
+  const SCEV *DestAccFunc = SE.getSCEVAtScope(DestPtrVal, L);
   assert(DestAccFunc);
   // Ignore accesses to "NULL".
   // TODO: We could use this to optimize the region further, e.g., intersect
@@ -1616,7 +1616,7 @@ bool ScopBuilder::buildAccessMemIntrinsic(MemAccInst Inst, ScopStmt *Stmt) {
   auto *SrcPtrVal = MemTrans->getSource();
   assert(SrcPtrVal);
 
-  auto *SrcAccFunc = SE.getSCEVAtScope(SrcPtrVal, L);
+  const SCEV *SrcAccFunc = SE.getSCEVAtScope(SrcPtrVal, L);
   assert(SrcAccFunc);
   // Ignore accesses to "NULL".
   // TODO: See above TODO
@@ -1643,7 +1643,7 @@ bool ScopBuilder::buildAccessCallInst(MemAccInst Inst, ScopStmt *Stmt) {
   if (CI->doesNotAccessMemory() || isIgnoredIntrinsic(CI) || isDebugCall(CI))
     return true;
 
-  auto *AF = SE.getConstant(IntegerType::getInt64Ty(CI->getContext()), 0);
+  const SCEV *AF = SE.getConstant(IntegerType::getInt64Ty(CI->getContext()), 0);
   auto *CalledFunction = CI->getCalledFunction();
   MemoryEffects ME = AA.getMemoryEffects(CalledFunction);
   if (ME.doesNotAccessMemory())
@@ -1658,7 +1658,7 @@ bool ScopBuilder::buildAccessCallInst(MemAccInst Inst, ScopStmt *Stmt) {
       if (!Arg->getType()->isPointerTy())
         continue;
 
-      auto *ArgSCEV = SE.getSCEVAtScope(Arg, L);
+      const SCEV *ArgSCEV = SE.getSCEVAtScope(Arg, L);
       if (ArgSCEV->isZero())
         continue;
 
@@ -2169,7 +2169,7 @@ static bool isDivisible(const SCEV *Expr, unsigned Size, ScalarEvolution &SE) {
 
   // Only one factor needs to be divisible.
   if (auto *MulExpr = dyn_cast<SCEVMulExpr>(Expr)) {
-    for (auto *FactorExpr : MulExpr->operands())
+    for (const SCEV *FactorExpr : MulExpr->operands())
       if (isDivisible(FactorExpr, Size, SE))
         return true;
     return false;
@@ -2178,15 +2178,15 @@ static bool isDivisible(const SCEV *Expr, unsigned Size, ScalarEvolution &SE) {
   // For other n-ary expressions (Add, AddRec, Max,...) all operands need
   // to be divisible.
   if (auto *NAryExpr = dyn_cast<SCEVNAryExpr>(Expr)) {
-    for (auto *OpExpr : NAryExpr->operands())
+    for (const SCEV *OpExpr : NAryExpr->operands())
       if (!isDivisible(OpExpr, Size, SE))
         return false;
     return true;
   }
 
-  auto *SizeSCEV = SE.getConstant(Expr->getType(), Size);
-  auto *UDivSCEV = SE.getUDivExpr(Expr, SizeSCEV);
-  auto *MulSCEV = SE.getMulExpr(UDivSCEV, SizeSCEV);
+  const SCEV *SizeSCEV = SE.getConstant(Expr->getType(), Size);
+  const SCEV *UDivSCEV = SE.getUDivExpr(Expr, SizeSCEV);
+  const SCEV *MulSCEV = SE.getMulExpr(UDivSCEV, SizeSCEV);
   return MulSCEV == Expr;
 }
 
@@ -3672,7 +3672,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
   }
 
   // Create memory accesses for global reads since all arrays are now known.
-  auto *AF = SE.getConstant(IntegerType::getInt64Ty(SE.getContext()), 0);
+  const SCEV *AF = SE.getConstant(IntegerType::getInt64Ty(SE.getContext()), 0);
   for (auto GlobalReadPair : GlobalReads) {
     ScopStmt *GlobalReadStmt = GlobalReadPair.first;
     Instruction *GlobalRead = GlobalReadPair.second;

diff  --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 73c26578005c35..7ad2e53b589aec 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -520,7 +520,7 @@ bool ScopDetection::involvesMultiplePtrs(const SCEV *S0, const SCEV *S1,
     if (!V->getType()->isPointerTy())
       continue;
 
-    auto *PtrSCEV = SE.getSCEVAtScope(V, Scope);
+    const SCEV *PtrSCEV = SE.getSCEVAtScope(V, Scope);
     if (isa<SCEVConstant>(PtrSCEV))
       continue;
 
@@ -528,7 +528,7 @@ bool ScopDetection::involvesMultiplePtrs(const SCEV *S0, const SCEV *S1,
     if (!BasePtr)
       return true;
 
-    auto *BasePtrVal = BasePtr->getValue();
+    Value *BasePtrVal = BasePtr->getValue();
     if (PtrVals.insert(BasePtrVal).second) {
       for (auto *PtrVal : PtrVals)
         if (PtrVal != BasePtrVal && !AA.isNoAlias(PtrVal, BasePtrVal))
@@ -720,7 +720,8 @@ bool ScopDetection::isValidCallInst(CallInst &CI,
 
         // Bail if a pointer argument has a base address not known to
         // ScalarEvolution. Note that a zero pointer is acceptable.
-        auto *ArgSCEV = SE.getSCEVAtScope(Arg, LI.getLoopFor(CI.getParent()));
+        const SCEV *ArgSCEV =
+            SE.getSCEVAtScope(Arg, LI.getLoopFor(CI.getParent()));
         if (ArgSCEV->isZero())
           continue;
 
@@ -891,7 +892,7 @@ ScopDetection::getDelinearizationTerms(DetectionContext &Context,
         if (auto *AF2 = dyn_cast<SCEVMulExpr>(Op)) {
           SmallVector<const SCEV *, 0> Operands;
 
-          for (auto *MulOp : AF2->operands()) {
+          for (const SCEV *MulOp : AF2->operands()) {
             if (auto *Const = dyn_cast<SCEVConstant>(MulOp))
               Operands.push_back(Const);
             if (auto *Unknown = dyn_cast<SCEVUnknown>(MulOp)) {
@@ -1366,7 +1367,7 @@ bool ScopDetection::isValidLoop(Loop *L, DetectionContext &Context) {
 ScopDetection::LoopStats
 ScopDetection::countBeneficialSubLoops(Loop *L, ScalarEvolution &SE,
                                        unsigned MinProfitableTrips) {
-  auto *TripCount = SE.getBackedgeTakenCount(L);
+  const SCEV *TripCount = SE.getBackedgeTakenCount(L);
 
   int NumLoops = 1;
   int MaxLoopDepth = 1;

diff  --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index 56ffb990faf1c2..ab9330581eb5b3 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -215,7 +215,7 @@ static const ScopArrayInfo *identifyBasePtrOriginSAI(Scop *S, Value *BasePtr) {
 
   ScalarEvolution &SE = *S->getSE();
 
-  auto *OriginBaseSCEV =
+  const SCEV *OriginBaseSCEV =
       SE.getPointerBase(SE.getSCEV(BasePtrLI->getPointerOperand()));
   if (!OriginBaseSCEV)
     return nullptr;
@@ -713,11 +713,11 @@ void MemoryAccess::computeBoundsOnAccessRelation(unsigned ElementSize) {
   if (!Ptr || !SE->isSCEVable(Ptr->getType()))
     return;
 
-  auto *PtrSCEV = SE->getSCEV(Ptr);
+  const SCEV *PtrSCEV = SE->getSCEV(Ptr);
   if (isa<SCEVCouldNotCompute>(PtrSCEV))
     return;
 
-  auto *BasePtrSCEV = SE->getPointerBase(PtrSCEV);
+  const SCEV *BasePtrSCEV = SE->getPointerBase(PtrSCEV);
   if (BasePtrSCEV && !isa<SCEVCouldNotCompute>(BasePtrSCEV))
     PtrSCEV = SE->getMinusSCEV(PtrSCEV, BasePtrSCEV);
 
@@ -1384,10 +1384,10 @@ class SCEVSensitiveParameterRewriter final
   }
 
   const SCEV *visitAddRecExpr(const SCEVAddRecExpr *E) {
-    auto *Start = visit(E->getStart());
-    auto *AddRec = SE.getAddRecExpr(SE.getConstant(E->getType(), 0),
-                                    visit(E->getStepRecurrence(SE)),
-                                    E->getLoop(), SCEV::FlagAnyWrap);
+    const SCEV *Start = visit(E->getStart());
+    const SCEV *AddRec = SE.getAddRecExpr(SE.getConstant(E->getType(), 0),
+                                          visit(E->getStepRecurrence(SE)),
+                                          E->getLoop(), SCEV::FlagAnyWrap);
     return SE.getAddExpr(Start, AddRec);
   }
 

diff  --git a/polly/lib/Support/SCEVAffinator.cpp b/polly/lib/Support/SCEVAffinator.cpp
index d8463b238822d9..ce4467f082ba43 100644
--- a/polly/lib/Support/SCEVAffinator.cpp
+++ b/polly/lib/Support/SCEVAffinator.cpp
@@ -281,7 +281,7 @@ PWACtx SCEVAffinator::visitTruncateExpr(const SCEVTruncateExpr *Expr) {
   // to fit in the new type size instead of introducing a modulo with a very
   // large constant.
 
-  auto *Op = Expr->getOperand();
+  const SCEV *Op = Expr->getOperand();
   auto OpPWAC = visit(Op);
 
   unsigned Width = TD.getTypeSizeInBits(Expr->getType());
@@ -354,7 +354,7 @@ PWACtx SCEVAffinator::visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
   // bit-width is bigger than MaxZextSmallBitWidth we will employ overflow
   // assumptions and assume the "former negative" piece will not exist.
 
-  auto *Op = Expr->getOperand();
+  const SCEV *Op = Expr->getOperand();
   auto OpPWAC = visit(Op);
 
   // If the width is to big we assume the negative part does not occur.
@@ -483,8 +483,8 @@ PWACtx SCEVAffinator::visitUDivExpr(const SCEVUDivExpr *Expr) {
   // For the dividend we could choose from the 
diff erent representation
   // schemes introduced for zero-extend operations but for now we will
   // simply use an assumption.
-  auto *Dividend = Expr->getLHS();
-  auto *Divisor = Expr->getRHS();
+  const SCEV *Dividend = Expr->getLHS();
+  const SCEV *Divisor = Expr->getRHS();
   assert(isa<SCEVConstant>(Divisor) &&
          "UDiv is no parameter but has a non-constant RHS.");
 
@@ -518,13 +518,13 @@ PWACtx SCEVAffinator::visitSDivInstruction(Instruction *SDiv) {
 
   auto *Scope = getScope();
   auto *Divisor = SDiv->getOperand(1);
-  auto *DivisorSCEV = SE.getSCEVAtScope(Divisor, Scope);
+  const SCEV *DivisorSCEV = SE.getSCEVAtScope(Divisor, Scope);
   auto DivisorPWAC = visit(DivisorSCEV);
   assert(isa<SCEVConstant>(DivisorSCEV) &&
          "SDiv is no parameter but has a non-constant RHS.");
 
   auto *Dividend = SDiv->getOperand(0);
-  auto *DividendSCEV = SE.getSCEVAtScope(Dividend, Scope);
+  const SCEV *DividendSCEV = SE.getSCEVAtScope(Dividend, Scope);
   auto DividendPWAC = visit(DividendSCEV);
   DividendPWAC = combine(DividendPWAC, DivisorPWAC, isl_pw_aff_tdiv_q);
   return DividendPWAC;
@@ -535,13 +535,13 @@ PWACtx SCEVAffinator::visitSRemInstruction(Instruction *SRem) {
 
   auto *Scope = getScope();
   auto *Divisor = SRem->getOperand(1);
-  auto *DivisorSCEV = SE.getSCEVAtScope(Divisor, Scope);
+  const SCEV *DivisorSCEV = SE.getSCEVAtScope(Divisor, Scope);
   auto DivisorPWAC = visit(DivisorSCEV);
   assert(isa<ConstantInt>(Divisor) &&
          "SRem is no parameter but has a non-constant RHS.");
 
   auto *Dividend = SRem->getOperand(0);
-  auto *DividendSCEV = SE.getSCEVAtScope(Dividend, Scope);
+  const SCEV *DividendSCEV = SE.getSCEVAtScope(Dividend, Scope);
   auto DividendPWAC = visit(DividendSCEV);
   DividendPWAC = combine(DividendPWAC, DivisorPWAC, isl_pw_aff_tdiv_r);
   return DividendPWAC;

diff  --git a/polly/lib/Support/SCEVValidator.cpp b/polly/lib/Support/SCEVValidator.cpp
index 5bb82624ed7844..599d7f9d60802e 100644
--- a/polly/lib/Support/SCEVValidator.cpp
+++ b/polly/lib/Support/SCEVValidator.cpp
@@ -403,8 +403,8 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
     if (!PollyAllowUnsignedOperations)
       return ValidatorResult(SCEVType::INVALID);
 
-    auto *Dividend = Expr->getLHS();
-    auto *Divisor = Expr->getRHS();
+    const SCEV *Dividend = Expr->getLHS();
+    const SCEV *Divisor = Expr->getRHS();
     return visitDivision(Dividend, Divisor, Expr);
   }
 
@@ -412,8 +412,8 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
     assert(SDiv->getOpcode() == Instruction::SDiv &&
            "Assumed SDiv instruction!");
 
-    auto *Dividend = SE.getSCEV(SDiv->getOperand(0));
-    auto *Divisor = SE.getSCEV(SDiv->getOperand(1));
+    const SCEV *Dividend = SE.getSCEV(SDiv->getOperand(0));
+    const SCEV *Divisor = SE.getSCEV(SDiv->getOperand(1));
     return visitDivision(Dividend, Divisor, Expr, SDiv);
   }
 
@@ -427,7 +427,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
       return visitGenericInst(SRem, S);
 
     auto *Dividend = SRem->getOperand(0);
-    auto *DividendSCEV = SE.getSCEV(Dividend);
+    const SCEV *DividendSCEV = SE.getSCEV(Dividend);
     return visit(DividendSCEV);
   }
 
@@ -566,11 +566,11 @@ class SCEVFindValues final {
                   Inst->getOpcode() != Instruction::SDiv))
       return false;
 
-    auto *Dividend = SE.getSCEV(Inst->getOperand(1));
+    const SCEV *Dividend = SE.getSCEV(Inst->getOperand(1));
     if (!isa<SCEVConstant>(Dividend))
       return false;
 
-    auto *Divisor = SE.getSCEV(Inst->getOperand(0));
+    const SCEV *Divisor = SE.getSCEV(Inst->getOperand(0));
     SCEVFindValues FindValues(SE, Values);
     SCEVTraversal<SCEVFindValues> ST(FindValues);
     ST.visitAll(Dividend);
@@ -623,7 +623,7 @@ bool polly::isAffineExpr(const Region *R, llvm::Loop *Scope, const SCEV *Expr,
 
 static bool isAffineExpr(Value *V, const Region *R, Loop *Scope,
                          ScalarEvolution &SE, ParameterSetTy &Params) {
-  auto *E = SE.getSCEV(V);
+  const SCEV *E = SE.getSCEV(V);
   if (isa<SCEVCouldNotCompute>(E))
     return false;
 
@@ -684,10 +684,10 @@ polly::extractConstantFactor(const SCEV *S, ScalarEvolution &SE) {
 
   auto *AddRec = dyn_cast<SCEVAddRecExpr>(S);
   if (AddRec) {
-    auto *StartExpr = AddRec->getStart();
+    const SCEV *StartExpr = AddRec->getStart();
     if (StartExpr->isZero()) {
       auto StepPair = extractConstantFactor(AddRec->getStepRecurrence(SE), SE);
-      auto *LeftOverAddRec =
+      const SCEV *LeftOverAddRec =
           SE.getAddRecExpr(StartExpr, StepPair.second, AddRec->getLoop(),
                            AddRec->getNoWrapFlags());
       return std::make_pair(StepPair.first, LeftOverAddRec);
@@ -717,7 +717,7 @@ polly::extractConstantFactor(const SCEV *S, ScalarEvolution &SE) {
         return std::make_pair(ConstPart, S);
     }
 
-    auto *NewAdd = SE.getAddExpr(LeftOvers, Add->getNoWrapFlags());
+    const SCEV *NewAdd = SE.getAddExpr(LeftOvers, Add->getNoWrapFlags());
     return std::make_pair(Factor, NewAdd);
   }
 
@@ -726,7 +726,7 @@ polly::extractConstantFactor(const SCEV *S, ScalarEvolution &SE) {
     return std::make_pair(ConstPart, S);
 
   SmallVector<const SCEV *, 4> LeftOvers;
-  for (auto *Op : Mul->operands())
+  for (const SCEV *Op : Mul->operands())
     if (isa<SCEVConstant>(Op))
       ConstPart = cast<SCEVConstant>(SE.getMulExpr(ConstPart, Op));
     else

diff  --git a/polly/lib/Support/ScopHelper.cpp b/polly/lib/Support/ScopHelper.cpp
index 754bf50e2911f1..6d50e297ef7154 100644
--- a/polly/lib/Support/ScopHelper.cpp
+++ b/polly/lib/Support/ScopHelper.cpp
@@ -315,7 +315,7 @@ struct ScopExpander final : SCEVVisitor<ScopExpander, const SCEV *> {
     auto *InstClone = Inst->clone();
     for (auto &Op : Inst->operands()) {
       assert(GenSE.isSCEVable(Op->getType()));
-      auto *OpSCEV = GenSE.getSCEV(Op);
+      const SCEV *OpSCEV = GenSE.getSCEV(Op);
       auto *OpClone = expandCodeFor(OpSCEV, Op->getType(), IP);
       InstClone->replaceUsesOfWith(Op, OpClone);
     }
@@ -330,7 +330,7 @@ struct ScopExpander final : SCEVVisitor<ScopExpander, const SCEV *> {
     // If a value mapping was given try if the underlying value is remapped.
     Value *NewVal = VMap ? VMap->lookup(E->getValue()) : nullptr;
     if (NewVal) {
-      auto *NewE = GenSE.getSCEV(NewVal);
+      const SCEV *NewE = GenSE.getSCEV(NewVal);
 
       // While the mapped value might be 
diff erent the SCEV representation might
       // not be. To this end we will check before we go into recursion here.

diff  --git a/polly/lib/Support/VirtualInstruction.cpp b/polly/lib/Support/VirtualInstruction.cpp
index e570d8d5464948..96197aaececac5 100644
--- a/polly/lib/Support/VirtualInstruction.cpp
+++ b/polly/lib/Support/VirtualInstruction.cpp
@@ -65,7 +65,7 @@ VirtualUse VirtualUse::create(Scop *S, ScopStmt *UserStmt, Loop *UserScope,
   // We assume synthesizable which practically should have the same effect.
   auto *SE = S->getSE();
   if (SE->isSCEVable(Val->getType())) {
-    auto *ScevExpr = SE->getSCEVAtScope(Val, UserScope);
+    const SCEV *ScevExpr = SE->getSCEVAtScope(Val, UserScope);
     if (!UserStmt || canSynthesize(Val, *UserStmt->getParent(), SE, UserScope))
       return VirtualUse(UserStmt, Val, Synthesizable, ScevExpr, nullptr);
   }


        


More information about the llvm-commits mailing list