/// This is the base class for unary cast operator classes.
class SCEVCastExpr : public SCEV {
protected:
- std::array<const SCEV *, 1> 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 SCEV *, 1>::const_iterator;
- using op_range = iterator_range<op_iterator>;
-
- op_range operands() const {
- return make_range(Operands.begin(), Operands.end());
+ return Op;
}
+ ArrayRef<const SCEV *> operands() const { return Op; }
size_t getNumOperands() const { return 1; }
Type *getType() const { return Ty; }
return Operands[i];
}
- using op_iterator = const SCEV *const *;
- using op_range = iterator_range<op_iterator>;
-
- 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<const SCEV *> operands() const {
+ return makeArrayRef(Operands, NumOperands);
+ }
NoWrapFlags getNoWrapFlags(NoWrapFlags Mask = NoWrapMask) const {
return (NoWrapFlags)(SubclassData & Mask);
return i == 0 ? getLHS() : getRHS();
}
- using op_iterator = std::array<const SCEV *, 2>::const_iterator;
- using op_range = iterator_range<op_iterator>;
- op_range operands() const {
- return make_range(Operands.begin(), Operands.end());
- }
+ ArrayRef<const SCEV *> operands() const { return Operands; }
Type *getType() const {
// In most cases the types of LHS and RHS will be the same, but in some
if (isAffine())
return getOperand(1);
return SE.getAddRecExpr(
- SmallVector<const SCEV *, 3>(op_begin() + 1, op_end()), getLoop(),
+ SmallVector<const SCEV *, 3>(operands().drop_front()), getLoop(),
FlagAnyWrap);
}
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)
/// 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 *
CollectAddOperandsWithScales(DenseMap<const SCEV *, APInt> &M,
SmallVectorImpl<const SCEV *> &NewOps,
APInt &AccumulatedConstant,
- const SCEV *const *Ops, size_t NumOperands,
- const APInt &Scale,
+ ArrayRef<const SCEV *> Ops, const APInt &Scale,
ScalarEvolution &SE) {
bool Interesting = false;
// 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<SCEVMulExpr>(Ops[i]);
if (Mul && isa<SCEVConstant>(Mul->getOperand(0))) {
APInt NewScale =
const SCEVAddExpr *Add = cast<SCEVAddExpr>(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.
// 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());
}
SmallVector<const SCEV *, 8> 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);
if (Mul->getNumOperands() != 2) {
// If the multiply has more than two operands, we must get the
// Y*Z term.
- SmallVector<const SCEV *, 4> MulOps(Mul->op_begin(),
- Mul->op_begin()+MulOp);
- MulOps.append(Mul->op_begin()+MulOp+1, Mul->op_end());
+ SmallVector<const SCEV *, 4> MulOps(
+ Mul->operands().take_front(MulOp));
+ append_range(MulOps, Mul->operands().drop_front(MulOp + 1));
InnerMul = getMulExpr(MulOps, SCEV::FlagAnyWrap, Depth + 1);
}
SmallVector<const SCEV *, 2> TwoOps = {getOne(Ty), InnerMul};
// 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<const SCEV *, 4> MulOps(Mul->op_begin(),
- Mul->op_begin()+MulOp);
- MulOps.append(Mul->op_begin()+MulOp+1, Mul->op_end());
+ SmallVector<const SCEV *, 4> 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<const SCEV *, 4> MulOps(OtherMul->op_begin(),
- OtherMul->op_begin()+OMulOp);
- MulOps.append(OtherMul->op_begin()+OMulOp+1, OtherMul->op_end());
+ SmallVector<const SCEV *, 4> MulOps(
+ OtherMul->operands().take_front(OMulOp));
+ append_range(MulOps, OtherMul->operands().drop_front(OMulOp+1));
InnerMul2 = getMulExpr(MulOps, SCEV::FlagAnyWrap, Depth + 1);
}
SmallVector<const SCEV *, 2> TwoOps = {InnerMul1, InnerMul2};
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<const SCEV *, 2> TwoOps = {
// 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;
}
cast<SCEVConstant>(getConstant(RHSCst->getAPInt().udiv(Factor)));
SmallVector<const SCEV *, 2> 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<SCEVMulExpr>(LHS);
for (int i = 0, e = Mul->getNumOperands(); i != e; ++i) {
if (Mul->getOperand(i) == RHS) {
SmallVector<const SCEV *, 2> 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);
}
}
Operands.push_back(Start);
if (const SCEVAddRecExpr *StepChrec = dyn_cast<SCEVAddRecExpr>(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));
}
while (Ops[Idx]->getSCEVType() == Kind) {
const SCEVMinMaxExpr *SMME = cast<SCEVMinMaxExpr>(Ops[Idx]);
Ops.erase(Ops.begin()+Idx);
- Ops.append(SMME->op_begin(), SMME->op_end());
+ append_range(Ops, SMME->operands());
DeletedAny = true;
}
auto *NAry = cast<SCEVNAryExpr>(S);
SmallVector<const SCEV *> NewOps;
- bool Changed =
- visit(Kind, makeArrayRef(NAry->op_begin(), NAry->op_end()), NewOps);
+ bool Changed = visit(Kind, NAry->operands(), NewOps);
if (!Changed)
return S;
}
const auto *SMME = cast<SCEVSequentialMinMaxExpr>(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;
}
APInt DivAmt = APInt::getOneBitSet(BitWidth, TZ - GCD);
SmallVector<const SCEV*, 4> 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));
}
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<const SCEV *, 8> NewOps(Comm->op_begin(),
- Comm->op_begin()+i);
+ SmallVector<const SCEV *, 8> NewOps(Comm->operands().take_front(i));
NewOps.push_back(OpAtScope);
for (++i; i != e; ++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<const SCEV *, 8> NewOps(AddRec->op_begin(),
- AddRec->op_begin()+i);
+ SmallVector<const SCEV *, 8> NewOps(AddRec->operands().take_front(i));
NewOps.push_back(OpAtScope);
for (++i; i != e; ++i)
NewOps.push_back(getSCEVAtScope(AddRec->getOperand(i), L));