llvm_unreachable("Unknown SCEV kind!");
}
+ArrayRef<const SCEV *> SCEV::operands() const {
+ switch (getSCEVType()) {
+ case scConstant:
+ case scUnknown:
+ return {};
+ case scPtrToInt:
+ case scTruncate:
+ case scZeroExtend:
+ case scSignExtend:
+ return cast<SCEVCastExpr>(this)->operands();
+ case scAddRecExpr:
+ case scAddExpr:
+ case scMulExpr:
+ case scUMaxExpr:
+ case scSMaxExpr:
+ case scUMinExpr:
+ case scSMinExpr:
+ case scSequentialUMinExpr:
+ return cast<SCEVNAryExpr>(this)->operands();
+ case scUDivExpr:
+ return cast<SCEVUDivExpr>(this)->operands();
+ case scCouldNotCompute:
+ llvm_unreachable("Attempt to use a SCEVCouldNotCompute object!");
+ }
+ llvm_unreachable("Unknown SCEV kind!");
+}
+
bool SCEV::isZero() const {
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(this))
return SC->getValue()->isZero();
return nullptr;
}
-/// Fills \p Ops with unique operands of \p S, if it has operands. If not,
-/// \p Ops remains unmodified.
-static void collectUniqueOps(const SCEV *S,
- SmallVectorImpl<const SCEV *> &Ops) {
- SmallPtrSet<const SCEV *, 4> Unique;
- auto InsertUnique = [&](const SCEV *S) {
- if (Unique.insert(S).second)
- Ops.push_back(S);
- };
- if (auto *S2 = dyn_cast<SCEVCastExpr>(S))
- for (const auto *Op : S2->operands())
- InsertUnique(Op);
- else if (auto *S2 = dyn_cast<SCEVNAryExpr>(S))
- for (const auto *Op : S2->operands())
- InsertUnique(Op);
- else if (auto *S2 = dyn_cast<SCEVUDivExpr>(S))
- for (const auto *Op : S2->operands())
- InsertUnique(Op);
-}
-
const Instruction *
ScalarEvolution::getDefiningScopeBound(ArrayRef<const SCEV *> Ops,
bool &Precise) {
if (!Bound || DT.dominates(Bound, DefI))
Bound = DefI;
} else {
- SmallVector<const SCEV *, 4> Ops;
- collectUniqueOps(S, Ops);
- for (const auto *Op : Ops)
+ for (const auto *Op : S->operands())
pushOp(Op);
}
}
// Verify integrity of SCEV users.
for (const auto &S : UniqueSCEVs) {
- SmallVector<const SCEV *, 4> Ops;
- collectUniqueOps(&S, Ops);
- for (const auto *Op : Ops) {
+ for (const auto *Op : S.operands()) {
// We do not store dependencies of constants.
if (isa<SCEVConstant>(Op))
continue;