From: Nikita Popov Date: Fri, 16 Dec 2022 14:29:47 +0000 (+0100) Subject: [SCEV] Return ArrayRef for SCEV operands() (NFC) X-Git-Tag: upstream/17.0.6~23551 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04d652994d479c98980e85d5742fc283a12ca3d4;p=platform%2Fupstream%2Fllvm.git [SCEV] Return ArrayRef for SCEV operands() (NFC) Use a consistent type for the operands() methods of different SCEV types. Also make the API consistent by only providing operands(), rather than also providin op_begin() and op_end() for some of them. --- diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h index c8bc8b6..6132a14 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h +++ b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h @@ -85,24 +85,19 @@ inline unsigned short computeExpressionSize(ArrayRef Args) { /// This is the base class for unary cast operator classes. class SCEVCastExpr : public SCEV { protected: - std::array Operands; + const SCEV *Op; Type *Ty; SCEVCastExpr(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy, const SCEV *op, Type *ty); public: - const SCEV *getOperand() const { return Operands[0]; } + const SCEV *getOperand() const { return Op; } const SCEV *getOperand(unsigned i) const { assert(i == 0 && "Operand index out of range!"); - return Operands[0]; - } - using op_iterator = std::array::const_iterator; - using op_range = iterator_range; - - op_range operands() const { - return make_range(Operands.begin(), Operands.end()); + return Op; } + ArrayRef operands() const { return Op; } size_t getNumOperands() const { return 1; } Type *getType() const { return Ty; } @@ -203,12 +198,9 @@ public: return Operands[i]; } - using op_iterator = const SCEV *const *; - using op_range = iterator_range; - - op_iterator op_begin() const { return Operands; } - op_iterator op_end() const { return Operands + NumOperands; } - op_range operands() const { return make_range(op_begin(), op_end()); } + ArrayRef operands() const { + return makeArrayRef(Operands, NumOperands); + } NoWrapFlags getNoWrapFlags(NoWrapFlags Mask = NoWrapMask) const { return (NoWrapFlags)(SubclassData & Mask); @@ -312,11 +304,7 @@ public: return i == 0 ? getLHS() : getRHS(); } - using op_iterator = std::array::const_iterator; - using op_range = iterator_range; - op_range operands() const { - return make_range(Operands.begin(), Operands.end()); - } + ArrayRef operands() const { return Operands; } Type *getType() const { // In most cases the types of LHS and RHS will be the same, but in some @@ -361,7 +349,7 @@ public: if (isAffine()) return getOperand(1); return SE.getAddRecExpr( - SmallVector(op_begin() + 1, op_end()), getLoop(), + SmallVector(operands().drop_front()), getLoop(), FlagAnyWrap); } diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 2a9dcac..db7f7da 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -490,9 +490,7 @@ ScalarEvolution::getConstant(Type *Ty, uint64_t V, bool isSigned) { SCEVCastExpr::SCEVCastExpr(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy, const SCEV *op, Type *ty) - : SCEV(ID, SCEVTy, computeExpressionSize(op)), Ty(ty) { - Operands[0] = op; -} + : SCEV(ID, SCEVTy, computeExpressionSize(op)), Op(op), Ty(ty) {} SCEVPtrToIntExpr::SCEVPtrToIntExpr(const FoldingSetNodeIDRef ID, const SCEV *Op, Type *ITy) @@ -1050,7 +1048,7 @@ static const SCEV *BinomialCoefficient(const SCEV *It, unsigned K, /// where BC(It, k) stands for binomial coefficient. const SCEV *SCEVAddRecExpr::evaluateAtIteration(const SCEV *It, ScalarEvolution &SE) const { - return evaluateAtIteration(makeArrayRef(op_begin(), op_end()), It, SE); + return evaluateAtIteration(operands(), It, SE); } const SCEV * @@ -2280,8 +2278,7 @@ static bool CollectAddOperandsWithScales(DenseMap &M, SmallVectorImpl &NewOps, APInt &AccumulatedConstant, - const SCEV *const *Ops, size_t NumOperands, - const APInt &Scale, + ArrayRef Ops, const APInt &Scale, ScalarEvolution &SE) { bool Interesting = false; @@ -2297,7 +2294,7 @@ CollectAddOperandsWithScales(DenseMap &M, // Next comes everything else. We're especially interested in multiplies // here, but they're in the middle, so just visit the rest with one loop. - for (; i != NumOperands; ++i) { + for (; i != Ops.size(); ++i) { const SCEVMulExpr *Mul = dyn_cast(Ops[i]); if (Mul && isa(Mul->getOperand(0))) { APInt NewScale = @@ -2307,8 +2304,7 @@ CollectAddOperandsWithScales(DenseMap &M, const SCEVAddExpr *Add = cast(Mul->getOperand(1)); Interesting |= CollectAddOperandsWithScales(M, NewOps, AccumulatedConstant, - Add->op_begin(), Add->getNumOperands(), - NewScale, SE); + Add->operands(), NewScale, SE); } else { // A multiplication of a constant with some other value. Update // the map. @@ -2755,7 +2751,7 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl &Ops, // If we have an add, expand the add operands onto the end of the operands // list. Ops.erase(Ops.begin()+Idx); - Ops.append(Add->op_begin(), Add->op_end()); + append_range(Ops, Add->operands()); DeletedAdd = true; CommonFlags = maskFlags(CommonFlags, Add->getNoWrapFlags()); } @@ -2779,8 +2775,7 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl &Ops, SmallVector NewOps; APInt AccumulatedConstant(BitWidth, 0); if (CollectAddOperandsWithScales(M, NewOps, AccumulatedConstant, - Ops.data(), Ops.size(), - APInt(BitWidth, 1), *this)) { + Ops, APInt(BitWidth, 1), *this)) { struct APIntCompare { bool operator()(const APInt &LHS, const APInt &RHS) const { return LHS.ult(RHS); @@ -2831,9 +2826,9 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl &Ops, if (Mul->getNumOperands() != 2) { // If the multiply has more than two operands, we must get the // Y*Z term. - SmallVector MulOps(Mul->op_begin(), - Mul->op_begin()+MulOp); - MulOps.append(Mul->op_begin()+MulOp+1, Mul->op_end()); + SmallVector MulOps( + Mul->operands().take_front(MulOp)); + append_range(MulOps, Mul->operands().drop_front(MulOp + 1)); InnerMul = getMulExpr(MulOps, SCEV::FlagAnyWrap, Depth + 1); } SmallVector TwoOps = {getOne(Ty), InnerMul}; @@ -2865,16 +2860,16 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl &Ops, // Fold X + (A*B*C) + (A*D*E) --> X + (A*(B*C+D*E)) const SCEV *InnerMul1 = Mul->getOperand(MulOp == 0); if (Mul->getNumOperands() != 2) { - SmallVector MulOps(Mul->op_begin(), - Mul->op_begin()+MulOp); - MulOps.append(Mul->op_begin()+MulOp+1, Mul->op_end()); + SmallVector MulOps( + Mul->operands().take_front(MulOp)); + append_range(MulOps, Mul->operands().drop_front(MulOp+1)); InnerMul1 = getMulExpr(MulOps, SCEV::FlagAnyWrap, Depth + 1); } const SCEV *InnerMul2 = OtherMul->getOperand(OMulOp == 0); if (OtherMul->getNumOperands() != 2) { - SmallVector MulOps(OtherMul->op_begin(), - OtherMul->op_begin()+OMulOp); - MulOps.append(OtherMul->op_begin()+OMulOp+1, OtherMul->op_end()); + SmallVector MulOps( + OtherMul->operands().take_front(OMulOp)); + append_range(MulOps, OtherMul->operands().drop_front(OMulOp+1)); InnerMul2 = getMulExpr(MulOps, SCEV::FlagAnyWrap, Depth + 1); } SmallVector TwoOps = {InnerMul1, InnerMul2}; @@ -2985,8 +2980,7 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl &Ops, for (unsigned i = 0, e = OtherAddRec->getNumOperands(); i != e; ++i) { if (i >= AddRecOps.size()) { - AddRecOps.append(OtherAddRec->op_begin()+i, - OtherAddRec->op_end()); + append_range(AddRecOps, OtherAddRec->operands().drop_front(i)); break; } SmallVector TwoOps = { @@ -3255,7 +3249,7 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl &Ops, // If we have an mul, expand the mul operands onto the end of the // operands list. Ops.erase(Ops.begin()+Idx); - Ops.append(Mul->op_begin(), Mul->op_end()); + append_range(Ops, Mul->operands()); DeletedMul = true; } @@ -3631,7 +3625,7 @@ const SCEV *ScalarEvolution::getUDivExactExpr(const SCEV *LHS, cast(getConstant(RHSCst->getAPInt().udiv(Factor))); SmallVector Operands; Operands.push_back(LHSCst); - Operands.append(Mul->op_begin() + 1, Mul->op_end()); + append_range(Operands, Mul->operands().drop_front()); LHS = getMulExpr(Operands); RHS = RHSCst; Mul = dyn_cast(LHS); @@ -3644,8 +3638,8 @@ const SCEV *ScalarEvolution::getUDivExactExpr(const SCEV *LHS, for (int i = 0, e = Mul->getNumOperands(); i != e; ++i) { if (Mul->getOperand(i) == RHS) { SmallVector Operands; - Operands.append(Mul->op_begin(), Mul->op_begin() + i); - Operands.append(Mul->op_begin() + i + 1, Mul->op_end()); + append_range(Operands, Mul->operands().take_front(i)); + append_range(Operands, Mul->operands().drop_front(i + 1)); return getMulExpr(Operands); } } @@ -3662,7 +3656,7 @@ const SCEV *ScalarEvolution::getAddRecExpr(const SCEV *Start, const SCEV *Step, Operands.push_back(Start); if (const SCEVAddRecExpr *StepChrec = dyn_cast(Step)) if (StepChrec->getLoop() == L) { - Operands.append(StepChrec->op_begin(), StepChrec->op_end()); + append_range(Operands, StepChrec->operands()); return getAddRecExpr(Operands, L, maskFlags(Flags, SCEV::FlagNW)); } @@ -3920,7 +3914,7 @@ const SCEV *ScalarEvolution::getMinMaxExpr(SCEVTypes Kind, while (Ops[Idx]->getSCEVType() == Kind) { const SCEVMinMaxExpr *SMME = cast(Ops[Idx]); Ops.erase(Ops.begin()+Idx); - Ops.append(SMME->op_begin(), SMME->op_end()); + append_range(Ops, SMME->operands()); DeletedAny = true; } @@ -4007,8 +4001,7 @@ class SCEVSequentialMinMaxDeduplicatingVisitor final auto *NAry = cast(S); SmallVector NewOps; - bool Changed = - visit(Kind, makeArrayRef(NAry->op_begin(), NAry->op_end()), NewOps); + bool Changed = visit(Kind, NAry->operands(), NewOps); if (!Changed) return S; @@ -4200,7 +4193,8 @@ ScalarEvolution::getSequentialMinMaxExpr(SCEVTypes Kind, } const auto *SMME = cast(Ops[Idx]); Ops.erase(Ops.begin() + Idx); - Ops.insert(Ops.begin() + Idx, SMME->op_begin(), SMME->op_end()); + Ops.insert(Ops.begin() + Idx, SMME->operands().begin(), + SMME->operands().end()); DeletedAny = true; } @@ -7743,7 +7737,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) { APInt DivAmt = APInt::getOneBitSet(BitWidth, TZ - GCD); SmallVector MulOps; MulOps.push_back(getConstant(OpC->getAPInt().lshr(GCD))); - MulOps.append(LHSMul->op_begin() + 1, LHSMul->op_end()); + append_range(MulOps, LHSMul->operands().drop_front()); auto *NewMul = getMulExpr(MulOps, LHSMul->getNoWrapFlags()); ShiftedLHS = getUDivExpr(NewMul, getConstant(DivAmt)); } @@ -9927,8 +9921,7 @@ const SCEV *ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) { if (OpAtScope != Comm->getOperand(i)) { // Okay, at least one of these operands is loop variant but might be // foldable. Build a new instance of the folded commutative expression. - SmallVector NewOps(Comm->op_begin(), - Comm->op_begin()+i); + SmallVector NewOps(Comm->operands().take_front(i)); NewOps.push_back(OpAtScope); for (++i; i != e; ++i) { @@ -9971,8 +9964,7 @@ const SCEV *ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) { // Okay, at least one of these operands is loop variant but might be // foldable. Build a new instance of the folded commutative expression. - SmallVector NewOps(AddRec->op_begin(), - AddRec->op_begin()+i); + SmallVector NewOps(AddRec->operands().take_front(i)); NewOps.push_back(OpAtScope); for (++i; i != e; ++i) NewOps.push_back(getSCEVAtScope(AddRec->getOperand(i), L)); diff --git a/llvm/lib/Transforms/Scalar/LoopFuse.cpp b/llvm/lib/Transforms/Scalar/LoopFuse.cpp index abbc592..3e879a2 100644 --- a/llvm/lib/Transforms/Scalar/LoopFuse.cpp +++ b/llvm/lib/Transforms/Scalar/LoopFuse.cpp @@ -1216,7 +1216,7 @@ private: const Loop *ExprL = Expr->getLoop(); SmallVector Operands; if (ExprL == &OldL) { - Operands.append(Expr->op_begin(), Expr->op_end()); + append_range(Operands, Expr->operands()); return SE.getAddRecExpr(Operands, &NewL, Expr->getNoWrapFlags()); } diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index ec6523b..502c2a8 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1268,7 +1268,7 @@ static unsigned getSetupCost(const SCEV *Reg, unsigned Depth) { 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, + return std::accumulate(S->operands().begin(), S->operands().end(), 0, [&](unsigned i, const SCEV *Reg) { return i + getSetupCost(Reg, Depth - 1); }); @@ -2723,7 +2723,7 @@ void LSRInstance::CollectInterestingTypesAndFactors() { Strides.insert(AR->getStepRecurrence(SE)); Worklist.push_back(AR->getStart()); } else if (const SCEVAddExpr *Add = dyn_cast(S)) { - Worklist.append(Add->op_begin(), Add->op_end()); + append_range(Worklist, Add->operands()); } } while (!Worklist.empty()); } @@ -3490,7 +3490,7 @@ LSRInstance::CollectLoopInvariantFixupsAndFormulae() { continue; if (const SCEVNAryExpr *N = dyn_cast(S)) - Worklist.append(N->op_begin(), N->op_end()); + append_range(Worklist, N->operands()); else if (const SCEVIntegralCastExpr *C = dyn_cast(S)) Worklist.push_back(C->getOperand()); else if (const SCEVUDivExpr *D = dyn_cast(S)) { diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index 86d524f..8653d13 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -381,7 +381,7 @@ static void SimplifyAddOperands(SmallVectorImpl &Ops, // the sum into a single value, so just use that. Ops.clear(); if (const SCEVAddExpr *Add = dyn_cast(Sum)) - Ops.append(Add->op_begin(), Add->op_end()); + append_range(Ops, Add->operands()); else if (!Sum->isZero()) Ops.push_back(Sum); // Then append the addrecs. @@ -409,7 +409,7 @@ static void SplitAddRecs(SmallVectorImpl &Ops, A->getNoWrapFlags(SCEV::FlagNW))); if (const SCEVAddExpr *Add = dyn_cast(Start)) { Ops[i] = Zero; - Ops.append(Add->op_begin(), Add->op_end()); + append_range(Ops, Add->operands()); e += Add->getNumOperands(); } else { Ops[i] = Start; @@ -1549,7 +1549,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) { !S->getType()->isPointerTy()) { SmallVector NewOps(S->getNumOperands()); for (unsigned i = 0, e = S->getNumOperands(); i != e; ++i) - NewOps[i] = SE.getAnyExtendExpr(S->op_begin()[i], CanonicalIV->getType()); + NewOps[i] = SE.getAnyExtendExpr(S->getOperand(i), CanonicalIV->getType()); Value *V = expand(SE.getAddRecExpr(NewOps, S->getLoop(), S->getNoWrapFlags(SCEV::FlagNW))); BasicBlock::iterator NewInsertPt =