Skip to content

Commit b999400

Browse files
committed
[SCEV] Add operand methods to Cast and UDiv
Add methods to access operands in a similar manner to NAryExpr. Differential Revision: https://reviews.llvm.org/D86083
1 parent fd48567 commit b999400

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ class Type;
8282

8383
public:
8484
const SCEV *getOperand() const { return Op; }
85+
const SCEV *getOperand(unsigned i) const {
86+
assert(i == 0 && "Operand index out of range!");
87+
return Op;
88+
}
89+
using op_iterator = const SCEV *const *;
90+
using op_range = iterator_range<op_iterator>;
91+
op_range operands() const {
92+
return make_range(&Op, &Op + 1);
93+
}
94+
size_t getNumOperands() const { return 1; }
8595
Type *getType() const { return Ty; }
8696

8797
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -263,16 +273,28 @@ class Type;
263273
class SCEVUDivExpr : public SCEV {
264274
friend class ScalarEvolution;
265275

266-
const SCEV *LHS;
267-
const SCEV *RHS;
276+
std::array<const SCEV*, 2> Operands;
268277

269278
SCEVUDivExpr(const FoldingSetNodeIDRef ID, const SCEV *lhs, const SCEV *rhs)
270-
: SCEV(ID, scUDivExpr, computeExpressionSize({lhs, rhs})), LHS(lhs),
271-
RHS(rhs) {}
279+
: SCEV(ID, scUDivExpr, computeExpressionSize({lhs, rhs})) {
280+
Operands[0] = lhs;
281+
Operands[1] = rhs;
282+
}
272283

273284
public:
274-
const SCEV *getLHS() const { return LHS; }
275-
const SCEV *getRHS() const { return RHS; }
285+
const SCEV *getLHS() const { return Operands[0]; }
286+
const SCEV *getRHS() const { return Operands[1]; }
287+
size_t getNumOperands() const { return 2; }
288+
const SCEV *getOperand(unsigned i) const {
289+
assert((i == 0 || i == 1) && "Operand index out of range!");
290+
return i == 0 ? getLHS() : getRHS();
291+
}
292+
293+
using op_iterator = const SCEV *const *;
294+
using op_range = iterator_range<op_iterator>;
295+
op_range operands() const {
296+
return make_range(Operands.begin(), Operands.end());
297+
}
276298

277299
Type *getType() const {
278300
// In most cases the types of LHS and RHS will be the same, but in some

0 commit comments

Comments
 (0)