From d083d55c2cd18437495abea791d3a8454c2f9861 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Mon, 19 Oct 2020 10:57:26 +0300 Subject: [PATCH] [NFC][SCEV] Rename SCEVCastExpr into SCEVIntegralCastExpr All existing SCEV cast types operate on integers. D89456 will add SCEVPtrToIntExpr cast expression type. I believe this is best for consistency. Reviewed By: mkazantsev Differential Revision: https://reviews.llvm.org/D89455 --- .../Analysis/ScalarEvolutionExpressions.h | 14 ++++---- llvm/lib/Analysis/DependenceAnalysis.cpp | 8 ++--- llvm/lib/Analysis/ScalarEvolution.cpp | 36 ++++++++++--------- llvm/lib/Analysis/VectorUtils.cpp | 4 +-- .../Transforms/Scalar/LoopStrengthReduce.cpp | 4 +-- .../Utils/ScalarEvolutionExpander.cpp | 8 ++--- 6 files changed, 38 insertions(+), 36 deletions(-) diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h index 21e6374b66df..e94dddbadec1 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h +++ b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h @@ -72,13 +72,13 @@ class Type; } /// This is the base class for unary cast operator classes. - class SCEVCastExpr : public SCEV { + class SCEVIntegralCastExpr : public SCEV { protected: std::array Operands; Type *Ty; - SCEVCastExpr(const FoldingSetNodeIDRef ID, - unsigned SCEVTy, const SCEV *op, Type *ty); + SCEVIntegralCastExpr(const FoldingSetNodeIDRef ID, unsigned SCEVTy, + const SCEV *op, Type *ty); public: const SCEV *getOperand() const { return Operands[0]; } @@ -105,7 +105,7 @@ class Type; /// This class represents a truncation of an integer value to a /// smaller integer value. - class SCEVTruncateExpr : public SCEVCastExpr { + class SCEVTruncateExpr : public SCEVIntegralCastExpr { friend class ScalarEvolution; SCEVTruncateExpr(const FoldingSetNodeIDRef ID, @@ -120,7 +120,7 @@ class Type; /// This class represents a zero extension of a small integer value /// to a larger integer value. - class SCEVZeroExtendExpr : public SCEVCastExpr { + class SCEVZeroExtendExpr : public SCEVIntegralCastExpr { friend class ScalarEvolution; SCEVZeroExtendExpr(const FoldingSetNodeIDRef ID, @@ -135,7 +135,7 @@ class Type; /// This class represents a sign extension of a small integer value /// to a larger integer value. - class SCEVSignExtendExpr : public SCEVCastExpr { + class SCEVSignExtendExpr : public SCEVIntegralCastExpr { friend class ScalarEvolution; SCEVSignExtendExpr(const FoldingSetNodeIDRef ID, @@ -610,7 +610,7 @@ class Type; case scTruncate: case scZeroExtend: case scSignExtend: - push(cast(S)->getOperand()); + push(cast(S)->getOperand()); break; case scAddExpr: case scMulExpr: diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp index 374085dadf66..b5e28e731ade 100644 --- a/llvm/lib/Analysis/DependenceAnalysis.cpp +++ b/llvm/lib/Analysis/DependenceAnalysis.cpp @@ -871,8 +871,8 @@ void DependenceInfo::removeMatchingExtensions(Subscript *Pair) { const SCEV *Dst = Pair->Dst; if ((isa(Src) && isa(Dst)) || (isa(Src) && isa(Dst))) { - const SCEVCastExpr *SrcCast = cast(Src); - const SCEVCastExpr *DstCast = cast(Dst); + const SCEVIntegralCastExpr *SrcCast = cast(Src); + const SCEVIntegralCastExpr *DstCast = cast(Dst); const SCEV *SrcCastOp = SrcCast->getOperand(); const SCEV *DstCastOp = DstCast->getOperand(); if (SrcCastOp->getType() == DstCastOp->getType()) { @@ -969,8 +969,8 @@ bool DependenceInfo::isKnownPredicate(ICmpInst::Predicate Pred, const SCEV *X, isa(Y)) || (isa(X) && isa(Y))) { - const SCEVCastExpr *CX = cast(X); - const SCEVCastExpr *CY = cast(Y); + const SCEVIntegralCastExpr *CX = cast(X); + const SCEVIntegralCastExpr *CY = cast(Y); const SCEV *Xop = CX->getOperand(); const SCEV *Yop = CY->getOperand(); if (Xop->getType() == Yop->getType()) { diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 2f91bcdd0ac2..40b1d90ed40d 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -367,7 +367,7 @@ Type *SCEV::getType() const { case scTruncate: case scZeroExtend: case scSignExtend: - return cast(this)->getType(); + return cast(this)->getType(); case scAddRecExpr: case scMulExpr: case scUMaxExpr: @@ -445,29 +445,30 @@ ScalarEvolution::getConstant(Type *Ty, uint64_t V, bool isSigned) { return getConstant(ConstantInt::get(ITy, V, isSigned)); } -SCEVCastExpr::SCEVCastExpr(const FoldingSetNodeIDRef ID, - unsigned SCEVTy, const SCEV *op, Type *ty) - : SCEV(ID, SCEVTy, computeExpressionSize(op)), Ty(ty) { - Operands[0] = op; +SCEVIntegralCastExpr::SCEVIntegralCastExpr(const FoldingSetNodeIDRef ID, + unsigned SCEVTy, const SCEV *op, + Type *ty) + : SCEV(ID, SCEVTy, computeExpressionSize(op)), Ty(ty) { + Operands[0] = op; } -SCEVTruncateExpr::SCEVTruncateExpr(const FoldingSetNodeIDRef ID, - const SCEV *op, Type *ty) - : SCEVCastExpr(ID, scTruncate, op, ty) { +SCEVTruncateExpr::SCEVTruncateExpr(const FoldingSetNodeIDRef ID, const SCEV *op, + Type *ty) + : SCEVIntegralCastExpr(ID, scTruncate, op, ty) { assert(getOperand()->getType()->isIntOrPtrTy() && Ty->isIntOrPtrTy() && "Cannot truncate non-integer value!"); } SCEVZeroExtendExpr::SCEVZeroExtendExpr(const FoldingSetNodeIDRef ID, const SCEV *op, Type *ty) - : SCEVCastExpr(ID, scZeroExtend, op, ty) { + : SCEVIntegralCastExpr(ID, scZeroExtend, op, ty) { assert(getOperand()->getType()->isIntOrPtrTy() && Ty->isIntOrPtrTy() && "Cannot zero extend non-integer value!"); } SCEVSignExtendExpr::SCEVSignExtendExpr(const FoldingSetNodeIDRef ID, const SCEV *op, Type *ty) - : SCEVCastExpr(ID, scSignExtend, op, ty) { + : SCEVIntegralCastExpr(ID, scSignExtend, op, ty) { assert(getOperand()->getType()->isIntOrPtrTy() && Ty->isIntOrPtrTy() && "Cannot sign extend non-integer value!"); } @@ -781,8 +782,8 @@ static int CompareSCEVComplexity( case scTruncate: case scZeroExtend: case scSignExtend: { - const SCEVCastExpr *LC = cast(LHS); - const SCEVCastExpr *RC = cast(RHS); + const SCEVIntegralCastExpr *LC = cast(LHS); + const SCEVIntegralCastExpr *RC = cast(RHS); // Compare cast expressions by operand. int X = CompareSCEVComplexity(EqCacheSCEV, EqCacheValue, LI, @@ -1052,7 +1053,8 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, Type *Ty, for (unsigned i = 0, e = CommOp->getNumOperands(); i != e && numTruncs < 2; ++i) { const SCEV *S = getTruncateExpr(CommOp->getOperand(i), Ty, Depth + 1); - if (!isa(CommOp->getOperand(i)) && isa(S)) + if (!isa(CommOp->getOperand(i)) && + isa(S)) numTruncs++; Operands.push_back(S); } @@ -3964,7 +3966,7 @@ const SCEV *ScalarEvolution::getPointerBase(const SCEV *V) { return V; while (true) { - if (const SCEVCastExpr *Cast = dyn_cast(V)) { + if (const SCEVIntegralCastExpr *Cast = dyn_cast(V)) { V = Cast->getOperand(); } else if (const SCEVNAryExpr *NAry = dyn_cast(V)) { const SCEV *PtrOp = nullptr; @@ -5721,7 +5723,7 @@ ConstantRange ScalarEvolution::getRangeViaFactoring(const SCEV *Start, } // Peel off a cast operation - if (auto *SCast = dyn_cast(S)) { + if (auto *SCast = dyn_cast(S)) { CastOp = SCast->getSCEVType(); S = SCast->getOperand(); } @@ -11795,7 +11797,7 @@ ScalarEvolution::computeLoopDisposition(const SCEV *S, const Loop *L) { case scTruncate: case scZeroExtend: case scSignExtend: - return getLoopDisposition(cast(S)->getOperand(), L); + return getLoopDisposition(cast(S)->getOperand(), L); case scAddRecExpr: { const SCEVAddRecExpr *AR = cast(S); @@ -11902,7 +11904,7 @@ ScalarEvolution::computeBlockDisposition(const SCEV *S, const BasicBlock *BB) { case scTruncate: case scZeroExtend: case scSignExtend: - return getBlockDisposition(cast(S)->getOperand(), BB); + return getBlockDisposition(cast(S)->getOperand(), BB); case scAddRecExpr: { // This uses a "dominates" query instead of "properly dominates" query // to test for proper dominance too, because the instruction which diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp index 34fa0f283b03..79be29c4533c 100644 --- a/llvm/lib/Analysis/VectorUtils.cpp +++ b/llvm/lib/Analysis/VectorUtils.cpp @@ -208,7 +208,7 @@ Value *llvm::getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp) { if (Ptr != OrigPtr) // Strip off casts. - while (const SCEVCastExpr *C = dyn_cast(V)) + while (const SCEVIntegralCastExpr *C = dyn_cast(V)) V = C->getOperand(); const SCEVAddRecExpr *S = dyn_cast(V); @@ -241,7 +241,7 @@ Value *llvm::getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp) { // Strip off casts. Type *StripedOffRecurrenceCast = nullptr; - if (const SCEVCastExpr *C = dyn_cast(V)) { + if (const SCEVIntegralCastExpr *C = dyn_cast(V)) { StripedOffRecurrenceCast = C->getType(); V = C->getOperand(); } diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 93b9917b5972..b6d987978f87 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1212,7 +1212,7 @@ static unsigned getSetupCost(const SCEV *Reg, unsigned Depth) { return 0; if (const auto *S = dyn_cast(Reg)) return getSetupCost(S->getStart(), Depth - 1); - if (auto S = dyn_cast(Reg)) + if (auto S = dyn_cast(Reg)) return getSetupCost(S->getOperand(), Depth - 1); if (auto S = dyn_cast(Reg)) return std::accumulate(S->op_begin(), S->op_end(), 0, @@ -3403,7 +3403,7 @@ LSRInstance::CollectLoopInvariantFixupsAndFormulae() { if (const SCEVNAryExpr *N = dyn_cast(S)) Worklist.append(N->op_begin(), N->op_end()); - else if (const SCEVCastExpr *C = dyn_cast(S)) + else if (const SCEVIntegralCastExpr *C = dyn_cast(S)) Worklist.push_back(C->getOperand()); else if (const SCEVUDivExpr *D = dyn_cast(S)) { Worklist.push_back(D->getLHS()); diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index edf995ab4bb0..cd7d87f8d138 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -663,7 +663,7 @@ const Loop *SCEVExpander::getRelevantLoop(const SCEV *S) { L = PickMostRelevantLoop(L, getRelevantLoop(Op), SE.DT); return RelevantLoops[N] = L; } - if (const SCEVCastExpr *C = dyn_cast(S)) { + if (const SCEVIntegralCastExpr *C = dyn_cast(S)) { const Loop *Result = getRelevantLoop(C->getOperand()); return RelevantLoops[C] = Result; } @@ -2364,9 +2364,9 @@ bool SCEVExpander::isHighCostExpansionHelper( TTI.getIntImmCostInst(WorkItem.ParentOpcode, WorkItem.OperandIdx, Imm, Ty, CostKind); return BudgetRemaining < 0; - } else if (isa(S)) { - int Cost = - costAndCollectOperands(WorkItem, TTI, CostKind, Worklist); + } else if (isa(S)) { + int Cost = costAndCollectOperands(WorkItem, TTI, + CostKind, Worklist); BudgetRemaining -= Cost; return false; // Will answer upon next entry into this function. } else if (isa(S)) {