LLVM 24.0.0git
ScalarEvolutionExpressions.h
Go to the documentation of this file.
1//===- llvm/Analysis/ScalarEvolutionExpressions.h - SCEV Exprs --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the classes used to represent and build scalar expressions.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H
14#define LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H
15
16#include "llvm/ADT/DenseMap.h"
20#include "llvm/IR/Constants.h"
21#include "llvm/IR/ValueHandle.h"
25#include <cassert>
26#include <cstddef>
27
28namespace llvm {
29
30class APInt;
31class Constant;
32class ConstantInt;
33class ConstantRange;
34class Loop;
35class Type;
36class Value;
37
59
60/// This class represents a constant integer value.
61class SCEVConstant : public SCEV {
62 friend class ScalarEvolution;
63
64 ConstantInt *V;
65
66 SCEVConstant(const FoldingSetNodeIDRef ID, ConstantInt *v)
67 : SCEV(ID, scConstant, 1, v->getType()), V(v) {}
68
69public:
70 ConstantInt *getValue() const { return V; }
71 const APInt &getAPInt() const { return getValue()->getValue(); }
72
73 /// Methods for support type inquiry through isa, cast, and dyn_cast:
74 static bool classof(const SCEV *S) { return S->getSCEVType() == scConstant; }
75};
76
77/// This class represents the value of vscale, as used when defining the length
78/// of a scalable vector or returned by the llvm.vscale() intrinsic.
79class SCEVVScale : public SCEV {
80 friend class ScalarEvolution;
81
82 SCEVVScale(const FoldingSetNodeIDRef ID, Type *ty)
83 : SCEV(ID, scVScale, 0, ty) {}
84
85public:
86 /// Methods for support type inquiry through isa, cast, and dyn_cast:
87 static bool classof(const SCEV *S) { return S->getSCEVType() == scVScale; }
88};
89
90inline unsigned short computeExpressionSize(ArrayRef<SCEVUse> Args) {
91 APInt Size(16, 1);
92 for (const SCEV *Arg : Args)
93 Size = Size.uadd_sat(APInt(16, Arg->getExpressionSize()));
94 return (unsigned short)Size.getZExtValue();
95}
96
97/// This is the base class for unary cast operator classes.
98class SCEVCastExpr : public SCEV {
99protected:
101
103 SCEVUse op, Type *ty);
104
105public:
106 SCEVUse getOperand() const { return Op; }
107 SCEVUse getOperand(unsigned i) const {
108 assert(i == 0 && "Operand index out of range!");
109 return Op;
110 }
111 ArrayRef<SCEVUse> operands() const { return Op; }
112 size_t getNumOperands() const { return 1; }
113
114 /// Methods for support type inquiry through isa, cast, and dyn_cast:
115 static bool classof(const SCEV *S) {
116 return S->getSCEVType() == scPtrToAddr || S->getSCEVType() == scTruncate ||
118 }
119};
120
121/// This class represents a cast from a pointer to a pointer-sized integer
122/// value, without capturing the provenance of the pointer.
123class SCEVPtrToAddrExpr : public SCEVCastExpr {
124 friend class ScalarEvolution;
125
126 SCEVPtrToAddrExpr(const FoldingSetNodeIDRef ID, const SCEV *Op, Type *ITy);
127
128public:
129 /// Methods for support type inquiry through isa, cast, and dyn_cast:
130 static bool classof(const SCEV *S) { return S->getSCEVType() == scPtrToAddr; }
131};
132
133/// This is the base class for unary integral cast operator classes.
135protected:
137 SCEVUse op, Type *ty);
138
139public:
140 /// Methods for support type inquiry through isa, cast, and dyn_cast:
141 static bool classof(const SCEV *S) {
142 return S->getSCEVType() == scTruncate || S->getSCEVType() == scZeroExtend ||
144 }
145};
146
147/// This class represents a truncation of an integer value to a
148/// smaller integer value.
149class SCEVTruncateExpr : public SCEVIntegralCastExpr {
150 friend class ScalarEvolution;
151
152 SCEVTruncateExpr(const FoldingSetNodeIDRef ID, SCEVUse op, Type *ty);
153
154public:
155 /// Methods for support type inquiry through isa, cast, and dyn_cast:
156 static bool classof(const SCEV *S) { return S->getSCEVType() == scTruncate; }
157};
158
159/// This class represents a zero extension of a small integer value
160/// to a larger integer value.
161class SCEVZeroExtendExpr : public SCEVIntegralCastExpr {
162 friend class ScalarEvolution;
163
164 SCEVZeroExtendExpr(const FoldingSetNodeIDRef ID, SCEVUse op, Type *ty);
165
166public:
167 /// Methods for support type inquiry through isa, cast, and dyn_cast:
168 static bool classof(const SCEV *S) {
169 return S->getSCEVType() == scZeroExtend;
170 }
171};
172
173/// This class represents a sign extension of a small integer value
174/// to a larger integer value.
175class SCEVSignExtendExpr : public SCEVIntegralCastExpr {
176 friend class ScalarEvolution;
177
178 SCEVSignExtendExpr(const FoldingSetNodeIDRef ID, SCEVUse op, Type *ty);
179
180public:
181 /// Methods for support type inquiry through isa, cast, and dyn_cast:
182 static bool classof(const SCEV *S) {
183 return S->getSCEVType() == scSignExtend;
184 }
185};
186
187/// This node is a base class providing common functionality for
188/// n'ary operators.
189class SCEVNAryExpr : public SCEV {
190protected:
191 // Since SCEVs are immutable, ScalarEvolution allocates operand
192 // arrays with its SCEVAllocator, so this class just needs a simple
193 // pointer rather than a more elaborate vector-like data structure.
194 // This also avoids the need for a non-trivial destructor.
197
199 size_t N, Type *Ty)
200 : SCEV(ID, T, computeExpressionSize(ArrayRef(O, N)), Ty), Operands(O),
201 NumOperands(N) {}
202
203public:
204 size_t getNumOperands() const { return NumOperands; }
205
206 SCEVUse getOperand(unsigned i) const {
207 assert(i < NumOperands && "Operand index out of range!");
208 return Operands[i];
209 }
210
212
214 return static_cast<NoWrapFlags>(SubclassData) & Mask;
215 }
216
218
219 bool hasNoSignedWrap() const { return getNoWrapFlags(FlagNSW) != FlagNone; }
220
221 bool hasNoSelfWrap() const { return getNoWrapFlags(FlagNW) != FlagNone; }
222
223 /// Methods for support type inquiry through isa, cast, and dyn_cast:
224 static bool classof(const SCEV *S) {
225 return S->getSCEVType() == scAddExpr || S->getSCEVType() == scMulExpr ||
226 S->getSCEVType() == scSMaxExpr || S->getSCEVType() == scUMaxExpr ||
227 S->getSCEVType() == scSMinExpr || S->getSCEVType() == scUMinExpr ||
230 }
231 static bool classof(const SCEVUse *U) { return classof(U->getPointer()); }
232};
233
234/// This node is the base class for n'ary commutative operators.
236protected:
238 const SCEVUse *O, size_t N, Type *Ty)
239 : SCEVNAryExpr(ID, T, O, N, Ty) {}
240
241public:
242 /// Methods for support type inquiry through isa, cast, and dyn_cast:
243 static bool classof(const SCEV *S) {
244 return S->getSCEVType() == scAddExpr || S->getSCEVType() == scMulExpr ||
245 S->getSCEVType() == scSMaxExpr || S->getSCEVType() == scUMaxExpr ||
246 S->getSCEVType() == scSMinExpr || S->getSCEVType() == scUMinExpr;
247 }
248
249 /// Set flags for a non-recurrence without clearing previously set flags.
251 SubclassData |= static_cast<unsigned short>(Flags);
252 }
253};
254
255/// This node represents an addition of some number of SCEVs.
256class SCEVAddExpr : public SCEVCommutativeExpr {
257 friend class ScalarEvolution;
258
259 /// The type of an add is the type of its first pointer-typed operand, if
260 /// any, otherwise the type of operand 0.
261 static Type *computeType(const SCEVUse *O, size_t N) {
263 auto *FirstPointerTypedOp =
264 find_if(Ops, [](SCEVUse Op) { return Op->getType()->isPointerTy(); });
265 if (FirstPointerTypedOp != Ops.end())
266 return (*FirstPointerTypedOp)->getType();
267 return Ops[0]->getType();
268 }
269
270 SCEVAddExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
271 : SCEVCommutativeExpr(ID, scAddExpr, O, N, computeType(O, N)) {}
272
273public:
274 /// Methods for support type inquiry through isa, cast, and dyn_cast:
275 static bool classof(const SCEV *S) { return S->getSCEVType() == scAddExpr; }
276 static bool classof(const SCEVUse *U) { return classof(U->getPointer()); }
277};
278
279/// This node represents multiplication of some number of SCEVs.
280class SCEVMulExpr : public SCEVCommutativeExpr {
281 friend class ScalarEvolution;
282
283 SCEVMulExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
284 : SCEVCommutativeExpr(ID, scMulExpr, O, N, O[0]->getType()) {}
285
286public:
287 /// Methods for support type inquiry through isa, cast, and dyn_cast:
288 static bool classof(const SCEV *S) { return S->getSCEVType() == scMulExpr; }
289 static bool classof(const SCEVUse *U) { return classof(U->getPointer()); }
290};
291
292/// This class represents a binary unsigned division operation.
293class SCEVUDivExpr : public SCEV {
294 friend class ScalarEvolution;
295
296 std::array<SCEVUse, 2> Operands;
297
298 SCEVUDivExpr(const FoldingSetNodeIDRef ID, SCEVUse lhs, SCEVUse rhs)
299 : SCEV(ID, scUDivExpr, computeExpressionSize({lhs, rhs}),
300 lhs->getType()) {
301 Operands[0] = lhs;
302 Operands[1] = rhs;
303 }
304
305public:
306 SCEVUse getLHS() const { return Operands[0]; }
307 SCEVUse getRHS() const { return Operands[1]; }
308 size_t getNumOperands() const { return 2; }
309 SCEVUse getOperand(unsigned i) const {
310 assert((i == 0 || i == 1) && "Operand index out of range!");
311 return i == 0 ? getLHS() : getRHS();
312 }
313
314 ArrayRef<SCEVUse> operands() const { return Operands; }
315
316 /// Methods for support type inquiry through isa, cast, and dyn_cast:
317 static bool classof(const SCEV *S) { return S->getSCEVType() == scUDivExpr; }
318};
319
320/// This node represents a polynomial recurrence on the trip count
321/// of the specified loop. This is the primary focus of the
322/// ScalarEvolution framework; all the other SCEV subclasses are
323/// mostly just supporting infrastructure to allow SCEVAddRecExpr
324/// expressions to be created and analyzed.
325///
326/// All operands of an AddRec are required to be loop invariant.
327///
328class SCEVAddRecExpr : public SCEVNAryExpr {
329 friend class ScalarEvolution;
330
331 const Loop *L;
332
333 SCEVAddRecExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N,
334 const Loop *l)
335 : SCEVNAryExpr(ID, scAddRecExpr, O, N, O[0]->getType()), L(l) {}
336
337public:
338 SCEVUse getStart() const { return Operands[0]; }
339 const Loop *getLoop() const { return L; }
340
341 /// Constructs and returns the recurrence indicating how much this
342 /// expression steps by. If this is a polynomial of degree N, it
343 /// returns a chrec of degree N-1. We cannot determine whether
344 /// the step recurrence has self-wraparound.
346 if (isAffine())
347 return getOperand(1);
348 return SE.getAddRecExpr(SmallVector<SCEVUse, 3>(operands().drop_front()),
349 getLoop(), FlagNone);
350 }
351
352 /// Return true if this represents an expression A + B*x where A
353 /// and B are loop invariant values.
354 bool isAffine() const {
355 // We know that the start value is invariant. This expression is thus
356 // affine iff the step is also invariant.
357 return getNumOperands() == 2;
358 }
359
360 /// Return true if this represents an expression A + B*x + C*x^2
361 /// where A, B and C are loop invariant values. This corresponds
362 /// to an addrec of the form {L,+,M,+,N}
363 bool isQuadratic() const { return getNumOperands() == 3; }
364
365 /// Set flags for a recurrence without clearing any previously set flags.
366 /// For AddRec, either NUW or NSW implies NW. Keep track of this fact here
367 /// to make it easier to propagate flags.
369 if (any(Flags & (FlagNUW | FlagNSW)))
370 Flags = ScalarEvolution::setFlags(Flags, FlagNW);
371 SubclassData |= static_cast<unsigned short>(Flags);
372 }
373
374 /// Return the value of this chain of recurrences at the specified
375 /// iteration number.
376 LLVM_ABI const SCEV *evaluateAtIteration(const SCEV *It,
377 ScalarEvolution &SE) const;
378
379 /// Return the value of this chain of recurrences at the specified iteration
380 /// number. Takes an explicit list of operands to represent an AddRec.
381 LLVM_ABI static SCEVUse
383 ScalarEvolution &SE,
385
386 /// Return the value of this recurrences when its loop exits, i.e. its value
387 /// at the loop's exact backedge-taken count, or SCEVCouldNotCompute if that
388 /// count cannot be computed.
390
391 /// Return the number of iterations of this loop that produce
392 /// values in the specified constant range. Another way of
393 /// looking at this is that it returns the first iteration number
394 /// where the value is not in the condition, thus computing the
395 /// exit count. If the iteration count can't be computed, an
396 /// instance of SCEVCouldNotCompute is returned.
398 ScalarEvolution &SE) const;
399
400 /// Return an expression representing the value of this expression
401 /// one iteration of the loop ahead.
403
404 /// Methods for support type inquiry through isa, cast, and dyn_cast:
405 static bool classof(const SCEV *S) {
406 return S->getSCEVType() == scAddRecExpr;
407 }
408};
409
410/// This node is the base class min/max selections.
412 friend class ScalarEvolution;
413
414 static bool isMinMaxType(enum SCEVTypes T) {
415 return T == scSMaxExpr || T == scUMaxExpr || T == scSMinExpr ||
416 T == scUMinExpr;
417 }
418
419protected:
420 /// Note: Constructing subclasses via this constructor is allowed
422 const SCEVUse *O, size_t N)
423 : SCEVCommutativeExpr(ID, T, O, N, O[0]->getType()) {
424 assert(isMinMaxType(T));
425 // Min and max never overflow
427 }
428
429public:
430 static bool classof(const SCEV *S) { return isMinMaxType(S->getSCEVType()); }
431
432 static enum SCEVTypes negate(enum SCEVTypes T) {
433 switch (T) {
434 case scSMaxExpr:
435 return scSMinExpr;
436 case scSMinExpr:
437 return scSMaxExpr;
438 case scUMaxExpr:
439 return scUMinExpr;
440 case scUMinExpr:
441 return scUMaxExpr;
442 default:
443 llvm_unreachable("Not a min or max SCEV type!");
444 }
445 }
446};
447
448/// This class represents a signed maximum selection.
449class SCEVSMaxExpr : public SCEVMinMaxExpr {
450 friend class ScalarEvolution;
451
452 SCEVSMaxExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
453 : SCEVMinMaxExpr(ID, scSMaxExpr, O, N) {}
454
455public:
456 /// Methods for support type inquiry through isa, cast, and dyn_cast:
457 static bool classof(const SCEV *S) { return S->getSCEVType() == scSMaxExpr; }
458};
459
460/// This class represents an unsigned maximum selection.
461class SCEVUMaxExpr : public SCEVMinMaxExpr {
462 friend class ScalarEvolution;
463
464 SCEVUMaxExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
465 : SCEVMinMaxExpr(ID, scUMaxExpr, O, N) {}
466
467public:
468 /// Methods for support type inquiry through isa, cast, and dyn_cast:
469 static bool classof(const SCEV *S) { return S->getSCEVType() == scUMaxExpr; }
470};
471
472/// This class represents a signed minimum selection.
473class SCEVSMinExpr : public SCEVMinMaxExpr {
474 friend class ScalarEvolution;
475
476 SCEVSMinExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
477 : SCEVMinMaxExpr(ID, scSMinExpr, O, N) {}
478
479public:
480 /// Methods for support type inquiry through isa, cast, and dyn_cast:
481 static bool classof(const SCEV *S) { return S->getSCEVType() == scSMinExpr; }
482};
483
484/// This class represents an unsigned minimum selection.
485class SCEVUMinExpr : public SCEVMinMaxExpr {
486 friend class ScalarEvolution;
487
488 SCEVUMinExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
489 : SCEVMinMaxExpr(ID, scUMinExpr, O, N) {}
490
491public:
492 /// Methods for support type inquiry through isa, cast, and dyn_cast:
493 static bool classof(const SCEV *S) { return S->getSCEVType() == scUMinExpr; }
494};
495
496/// This node is the base class for sequential/in-order min/max selections.
497/// Note that their fundamental difference from SCEVMinMaxExpr's is that they
498/// are early-returning upon reaching saturation point.
499/// I.e. given `0 umin_seq poison`, the result will be `0`, while the result of
500/// `0 umin poison` is `poison`. When returning early, later expressions are not
501/// executed, so `0 umin_seq (%x u/ 0)` does not result in undefined behavior.
503 friend class ScalarEvolution;
504
505 static bool isSequentialMinMaxType(enum SCEVTypes T) {
506 return T == scSequentialUMinExpr;
507 }
508
509 /// Set flags for a non-recurrence without clearing previously set flags.
510 void setNoWrapFlags(NoWrapFlags Flags) {
511 SubclassData |= static_cast<unsigned short>(Flags);
512 }
513
514protected:
515 /// Note: Constructing subclasses via this constructor is allowed
517 const SCEVUse *O, size_t N)
518 : SCEVNAryExpr(ID, T, O, N, O[0]->getType()) {
519 assert(isSequentialMinMaxType(T));
520 // Min and max never overflow
521 setNoWrapFlags(FlagNUW | FlagNSW);
522 }
523
524public:
526 assert(isSequentialMinMaxType(Ty));
527 switch (Ty) {
529 return scUMinExpr;
530 default:
531 llvm_unreachable("Not a sequential min/max type.");
532 }
533 }
534
538
539 static bool classof(const SCEV *S) {
540 return isSequentialMinMaxType(S->getSCEVType());
541 }
542 static bool classof(const SCEVUse *U) { return classof(U->getPointer()); }
543};
544
545/// This class represents a sequential/in-order unsigned minimum selection.
546class SCEVSequentialUMinExpr : public SCEVSequentialMinMaxExpr {
547 friend class ScalarEvolution;
548
549 SCEVSequentialUMinExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O,
550 size_t N)
552
553public:
554 /// Methods for support type inquiry through isa, cast, and dyn_cast:
555 static bool classof(const SCEV *S) {
556 return S->getSCEVType() == scSequentialUMinExpr;
557 }
558};
559
560/// This means that we are dealing with an entirely unknown SCEV
561/// value, and only represent it as its LLVM Value. This is the
562/// "bottom" value for the analysis.
563class LLVM_ABI SCEVUnknown final : public SCEV, private CallbackVH {
564 friend class ScalarEvolution;
565
566 /// The parent ScalarEvolution value. This is used to update the
567 /// parent's maps when the value associated with a SCEVUnknown is
568 /// deleted or RAUW'd.
569 ScalarEvolution *SE;
570
571 /// The next pointer in the linked list of all SCEVUnknown
572 /// instances owned by a ScalarEvolution.
573 SCEVUnknown *Next;
574
575 SCEVUnknown(const FoldingSetNodeIDRef ID, Value *V, ScalarEvolution *se,
576 SCEVUnknown *next)
577 : SCEV(ID, scUnknown, 1, V->getType()), CallbackVH(V), SE(se),
578 Next(next) {}
579
580 // Implement CallbackVH.
581 void deleted() override;
582 void allUsesReplacedWith(Value *New) override;
583
584public:
585 Value *getValue() const { return getValPtr(); }
586
587 /// Methods for support type inquiry through isa, cast, and dyn_cast:
588 static bool classof(const SCEV *S) { return S->getSCEVType() == scUnknown; }
589};
590
591/// This class defines a simple visitor class that may be used for
592/// various SCEV analysis purposes.
593template <typename SC, typename RetVal = void> struct SCEVVisitor {
594 RetVal visit(const SCEV *S) {
595 switch (S->getSCEVType()) {
596 case scConstant:
597 return ((SC *)this)->visitConstant((const SCEVConstant *)S);
598 case scVScale:
599 return ((SC *)this)->visitVScale((const SCEVVScale *)S);
600 case scPtrToAddr:
601 return ((SC *)this)->visitPtrToAddrExpr((const SCEVPtrToAddrExpr *)S);
602 case scTruncate:
603 return ((SC *)this)->visitTruncateExpr((const SCEVTruncateExpr *)S);
604 case scZeroExtend:
605 return ((SC *)this)->visitZeroExtendExpr((const SCEVZeroExtendExpr *)S);
606 case scSignExtend:
607 return ((SC *)this)->visitSignExtendExpr((const SCEVSignExtendExpr *)S);
608 case scAddExpr:
609 return ((SC *)this)->visitAddExpr((const SCEVAddExpr *)S);
610 case scMulExpr:
611 return ((SC *)this)->visitMulExpr((const SCEVMulExpr *)S);
612 case scUDivExpr:
613 return ((SC *)this)->visitUDivExpr((const SCEVUDivExpr *)S);
614 case scAddRecExpr:
615 return ((SC *)this)->visitAddRecExpr((const SCEVAddRecExpr *)S);
616 case scSMaxExpr:
617 return ((SC *)this)->visitSMaxExpr((const SCEVSMaxExpr *)S);
618 case scUMaxExpr:
619 return ((SC *)this)->visitUMaxExpr((const SCEVUMaxExpr *)S);
620 case scSMinExpr:
621 return ((SC *)this)->visitSMinExpr((const SCEVSMinExpr *)S);
622 case scUMinExpr:
623 return ((SC *)this)->visitUMinExpr((const SCEVUMinExpr *)S);
625 return ((SC *)this)
626 ->visitSequentialUMinExpr((const SCEVSequentialUMinExpr *)S);
627 case scUnknown:
628 return ((SC *)this)->visitUnknown((const SCEVUnknown *)S);
630 return ((SC *)this)->visitCouldNotCompute((const SCEVCouldNotCompute *)S);
631 }
632 llvm_unreachable("Unknown SCEV kind!");
633 }
634
636 llvm_unreachable("Invalid use of SCEVCouldNotCompute!");
637 }
638};
639
640/// A visitor class for SCEVUse.
641template <typename SC, typename RetVal = void> struct SCEVUseVisitor {
642 RetVal visit(SCEVUse S) {
643 switch (S->getSCEVType()) {
644 case scConstant:
645 return ((SC *)this)
646 ->visitConstant(cast<SCEVUseT<const SCEVConstant *>>(S));
647 case scVScale:
648 return ((SC *)this)->visitVScale(cast<SCEVUseT<const SCEVVScale *>>(S));
649 case scPtrToAddr:
650 return ((SC *)this)
651 ->visitPtrToAddrExpr(cast<SCEVUseT<const SCEVPtrToAddrExpr *>>(S));
652 case scTruncate:
653 return ((SC *)this)
654 ->visitTruncateExpr(cast<SCEVUseT<const SCEVTruncateExpr *>>(S));
655 case scZeroExtend:
656 return ((SC *)this)
657 ->visitZeroExtendExpr(cast<SCEVUseT<const SCEVZeroExtendExpr *>>(S));
658 case scSignExtend:
659 return ((SC *)this)
660 ->visitSignExtendExpr(cast<SCEVUseT<const SCEVSignExtendExpr *>>(S));
661 case scAddExpr:
662 return ((SC *)this)->visitAddExpr(cast<SCEVUseT<const SCEVAddExpr *>>(S));
663 case scMulExpr:
664 return ((SC *)this)->visitMulExpr(cast<SCEVUseT<const SCEVMulExpr *>>(S));
665 case scUDivExpr:
666 return ((SC *)this)
667 ->visitUDivExpr(cast<SCEVUseT<const SCEVUDivExpr *>>(S));
668 case scAddRecExpr:
669 return ((SC *)this)
670 ->visitAddRecExpr(cast<SCEVUseT<const SCEVAddRecExpr *>>(S));
671 case scSMaxExpr:
672 return ((SC *)this)
673 ->visitSMaxExpr(cast<SCEVUseT<const SCEVSMaxExpr *>>(S));
674 case scUMaxExpr:
675 return ((SC *)this)
676 ->visitUMaxExpr(cast<SCEVUseT<const SCEVUMaxExpr *>>(S));
677 case scSMinExpr:
678 return ((SC *)this)
679 ->visitSMinExpr(cast<SCEVUseT<const SCEVSMinExpr *>>(S));
680 case scUMinExpr:
681 return ((SC *)this)
682 ->visitUMinExpr(cast<SCEVUseT<const SCEVUMinExpr *>>(S));
684 return ((SC *)this)
685 ->visitSequentialUMinExpr(
687 case scUnknown:
688 return ((SC *)this)->visitUnknown(cast<SCEVUseT<const SCEVUnknown *>>(S));
690 return ((SC *)this)
691 ->visitCouldNotCompute(
693 }
694 llvm_unreachable("Unknown SCEV kind!");
695 }
696
698 llvm_unreachable("Invalid use of SCEVCouldNotCompute!");
699 }
700};
701
702/// Visit all nodes in the expression tree using worklist traversal.
703///
704/// Visitor implements:
705/// // return true to follow this node.
706/// bool follow(const SCEV *S);
707/// // return true to terminate the search.
708/// bool isDone();
709template <typename SV> class SCEVTraversal {
710 SV &Visitor;
713
714 void push(const SCEV *S) {
715 if (Visited.insert(S).second && Visitor.follow(S))
716 Worklist.push_back(S);
717 }
718
719public:
720 SCEVTraversal(SV &V) : Visitor(V) {}
721
722 void visitAll(const SCEV *Root) {
723 push(Root);
724 while (!Worklist.empty() && !Visitor.isDone()) {
725 const SCEV *S = Worklist.pop_back_val();
726
727 switch (S->getSCEVType()) {
728 case scConstant:
729 case scVScale:
730 case scUnknown:
731 continue;
732 case scPtrToAddr:
733 case scTruncate:
734 case scZeroExtend:
735 case scSignExtend:
736 case scAddExpr:
737 case scMulExpr:
738 case scUDivExpr:
739 case scSMaxExpr:
740 case scUMaxExpr:
741 case scSMinExpr:
742 case scUMinExpr:
744 case scAddRecExpr:
745 for (const SCEV *Op : S->operands()) {
746 push(Op);
747 if (Visitor.isDone())
748 break;
749 }
750 continue;
752 llvm_unreachable("Attempt to use a SCEVCouldNotCompute object!");
753 }
754 llvm_unreachable("Unknown SCEV kind!");
755 }
756 }
757};
758
759/// Use SCEVTraversal to visit all nodes in the given expression tree.
760template <typename SV> void visitAll(const SCEV *Root, SV &Visitor) {
761 SCEVTraversal<SV> T(Visitor);
762 T.visitAll(Root);
763}
764
765/// Return true if any node in \p Root satisfies the predicate \p Pred.
766template <typename PredTy>
767bool SCEVExprContains(const SCEV *Root, PredTy Pred) {
768 struct FindClosure {
769 bool Found = false;
770 PredTy Pred;
771
772 FindClosure(PredTy Pred) : Pred(Pred) {}
773
774 bool follow(const SCEV *S) {
775 if (!Pred(S))
776 return true;
777
778 Found = true;
779 return false;
780 }
781
782 bool isDone() const { return Found; }
783 };
784
785 FindClosure FC(Pred);
786 visitAll(Root, FC);
787 return FC.Found;
788}
789
790/// This visitor recursively visits a SCEV expression and re-writes it.
791/// The result from each visit is cached, so it will return the same
792/// SCEV for the same input.
793template <typename SC>
794class SCEVRewriteVisitor : public SCEVVisitor<SC, const SCEV *> {
795protected:
797 // Memoize the result of each visit so that we only compute once for
798 // the same input SCEV. This is to avoid redundant computations when
799 // a SCEV is referenced by multiple SCEVs. Without memoization, this
800 // visit algorithm would have exponential time complexity in the worst
801 // case, causing the compiler to hang on certain tests.
803
804public:
806
807 const SCEV *visit(const SCEV *S) {
808 auto It = RewriteResults.find(S);
809 if (It != RewriteResults.end())
810 return It->second;
811 auto *Visited = SCEVVisitor<SC, const SCEV *>::visit(S);
812 auto Result = RewriteResults.try_emplace(S, Visited);
813 assert(Result.second && "Should insert a new entry");
814 return Result.first->second;
815 }
816
818
819 const SCEV *visitVScale(const SCEVVScale *VScale) { return VScale; }
820
822 const SCEV *Operand = ((SC *)this)->visit(Expr->getOperand());
823 return Operand == Expr->getOperand() ? Expr : SE.getPtrToAddrExpr(Operand);
824 }
825
827 const SCEV *Operand = ((SC *)this)->visit(Expr->getOperand());
828 return Operand == Expr->getOperand()
829 ? Expr
830 : SE.getTruncateExpr(Operand, Expr->getType());
831 }
832
834 const SCEV *Operand = ((SC *)this)->visit(Expr->getOperand());
835 return Operand == Expr->getOperand()
836 ? Expr
837 : SE.getZeroExtendExpr(Operand, Expr->getType());
838 }
839
841 const SCEV *Operand = ((SC *)this)->visit(Expr->getOperand());
842 return Operand == Expr->getOperand()
843 ? Expr
844 : SE.getSignExtendExpr(Operand, Expr->getType());
845 }
846
847 const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {
849 bool Changed = false;
850 for (const SCEV *Op : Expr->operands()) {
851 Operands.push_back(((SC *)this)->visit(Op));
852 Changed |= Op != Operands.back();
853 }
854 return !Changed ? Expr : SE.getAddExpr(Operands);
855 }
856
857 const SCEV *visitMulExpr(const SCEVMulExpr *Expr) {
859 bool Changed = false;
860 for (const SCEV *Op : Expr->operands()) {
861 Operands.push_back(((SC *)this)->visit(Op));
862 Changed |= Op != Operands.back();
863 }
864 return !Changed ? Expr : SE.getMulExpr(Operands);
865 }
866
867 const SCEV *visitUDivExpr(const SCEVUDivExpr *Expr) {
868 auto *LHS = ((SC *)this)->visit(Expr->getLHS());
869 auto *RHS = ((SC *)this)->visit(Expr->getRHS());
870 bool Changed = LHS != Expr->getLHS() || RHS != Expr->getRHS();
871 return !Changed ? Expr : SE.getUDivExpr(LHS, RHS);
872 }
873
874 const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
876 bool Changed = false;
877 for (const SCEV *Op : Expr->operands()) {
878 Operands.push_back(((SC *)this)->visit(Op));
879 Changed |= Op != Operands.back();
880 }
881 return !Changed ? Expr
882 : SE.getAddRecExpr(Operands, Expr->getLoop(),
883 Expr->getNoWrapFlags());
884 }
885
886 const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) {
888 bool Changed = false;
889 for (const SCEV *Op : Expr->operands()) {
890 Operands.push_back(((SC *)this)->visit(Op));
891 Changed |= Op != Operands.back();
892 }
893 return !Changed ? Expr : SE.getSMaxExpr(Operands);
894 }
895
896 const SCEV *visitUMaxExpr(const SCEVUMaxExpr *Expr) {
898 bool Changed = false;
899 for (const SCEV *Op : Expr->operands()) {
900 Operands.push_back(((SC *)this)->visit(Op));
901 Changed |= Op != Operands.back();
902 }
903 return !Changed ? Expr : SE.getUMaxExpr(Operands);
904 }
905
906 const SCEV *visitSMinExpr(const SCEVSMinExpr *Expr) {
908 bool Changed = false;
909 for (const SCEV *Op : Expr->operands()) {
910 Operands.push_back(((SC *)this)->visit(Op));
911 Changed |= Op != Operands.back();
912 }
913 return !Changed ? Expr : SE.getSMinExpr(Operands);
914 }
915
916 const SCEV *visitUMinExpr(const SCEVUMinExpr *Expr) {
918 bool Changed = false;
919 for (const SCEV *Op : Expr->operands()) {
920 Operands.push_back(((SC *)this)->visit(Op));
921 Changed |= Op != Operands.back();
922 }
923 return !Changed ? Expr : SE.getUMinExpr(Operands);
924 }
925
928 bool Changed = false;
929 for (const SCEV *Op : Expr->operands()) {
930 Operands.push_back(((SC *)this)->visit(Op));
931 Changed |= Op != Operands.back();
932 }
933 return !Changed ? Expr : SE.getUMinExpr(Operands, /*Sequential=*/true);
934 }
935
936 const SCEV *visitUnknown(const SCEVUnknown *Expr) { return Expr; }
937
939 return Expr;
940 }
941};
942
945
946/// The SCEVParameterRewriter takes a scalar evolution expression and updates
947/// the SCEVUnknown components following the Map (Value -> SCEV).
948class SCEVParameterRewriter : public SCEVRewriteVisitor<SCEVParameterRewriter> {
949public:
950 static const SCEV *rewrite(const SCEV *Scev, ScalarEvolution &SE,
951 ValueToSCEVMapTy &Map) {
953 return Rewriter.visit(Scev);
954 }
955
958
959 const SCEV *visitUnknown(const SCEVUnknown *Expr) {
960 auto I = Map.find(Expr->getValue());
961 if (I == Map.end())
962 return Expr;
963 return I->second;
964 }
965
966private:
967 ValueToSCEVMapTy &Map;
968};
969
971
972/// The SCEVLoopAddRecRewriter takes a scalar evolution expression and applies
973/// the Map (Loop -> SCEV) to all AddRecExprs.
975 : public SCEVRewriteVisitor<SCEVLoopAddRecRewriter> {
976public:
979
980 static const SCEV *rewrite(const SCEV *Scev, LoopToScevMapT &Map,
983 return Rewriter.visit(Scev);
984 }
985
986 const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
988 for (SCEVUse Op : Expr->operands())
989 Operands.push_back(visit(Op));
990
991 const Loop *L = Expr->getLoop();
992 auto It = Map.find(L);
993 if (It == Map.end())
994 return SE.getAddRecExpr(Operands, L, Expr->getNoWrapFlags());
995
997 }
998
999private:
1000 LoopToScevMapT &Map;
1001};
1002
1003template <typename SCEVPtrT>
1005 : Base(S, 0) {
1006 if (any(Flags)) {
1008 "use flags require an expression that can carry no-wrap flags");
1009 // Drop flags already present on S.
1010 Flags &= ~cast<SCEVNAryExpr>(S)->getNoWrapFlags();
1011 }
1012 Base::setInt(static_cast<unsigned>(Flags) >> 1);
1013}
1014
1015template <typename SCEVPtrT>
1016inline SCEVNoWrapFlags
1019 if (auto *NAry = dyn_cast<SCEVNAryExpr>(Base::getPointer()))
1020 Flags = NAry->getNoWrapFlags();
1021 return (Flags | getUseNoWrapFlags()) & Mask;
1022}
1023
1024} // end namespace llvm
1025
1026#endif // LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:215
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
#define op(i)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define I(x, y, z)
Definition MD5.cpp:57
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
SI Fold Operands
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
Virtual Register Rewriter
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
CallbackVH(const CallbackVH &)=default
This is the shared class of boolean and integer constants.
Definition Constants.h:87
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition Constants.h:159
This class represents a range of values.
This is an important base class in LLVM.
Definition Constant.h:43
This class describes a reference to an interned FoldingSetNodeID, which can be a useful to store node...
Definition FoldingSet.h:123
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
This node represents an addition of some number of SCEVs.
static bool classof(const SCEVUse *U)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This node represents a polynomial recurrence on the trip count of the specified loop.
LLVM_ABI SCEVUse getExitValue(ScalarEvolution &SE) const
Return the value of this recurrences when its loop exits, i.e.
LLVM_ABI const SCEV * evaluateAtIteration(const SCEV *It, ScalarEvolution &SE) const
Return the value of this chain of recurrences at the specified iteration number.
void setNoWrapFlags(NoWrapFlags Flags)
Set flags for a recurrence without clearing any previously set flags.
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values.
bool isQuadratic() const
Return true if this represents an expression A + B*x + C*x^2 where A, B and C are loop invariant valu...
LLVM_ABI const SCEV * getNumIterationsInRange(const ConstantRange &Range, ScalarEvolution &SE) const
Return the number of iterations of this loop that produce values in the specified constant range.
LLVM_ABI const SCEVAddRecExpr * getPostIncExpr(ScalarEvolution &SE) const
Return an expression representing the value of this expression one iteration of the loop ahead.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
SCEVUse getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
ArrayRef< SCEVUse > operands() const
SCEVUse getOperand(unsigned i) const
LLVM_ABI SCEVCastExpr(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy, SCEVUse op, Type *ty)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
SCEVCommutativeExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N, Type *Ty)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
void setNoWrapFlags(NoWrapFlags Flags)
Set flags for a non-recurrence without clearing previously set flags.
This class represents a constant integer value.
ConstantInt * getValue() const
const APInt & getAPInt() const
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
LLVM_ABI SCEVIntegralCastExpr(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy, SCEVUse op, Type *ty)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
static const SCEV * rewrite(const SCEV *Scev, LoopToScevMapT &Map, ScalarEvolution &SE)
const SCEV * visitAddRecExpr(const SCEVAddRecExpr *Expr)
SCEVLoopAddRecRewriter(ScalarEvolution &SE, LoopToScevMapT &M)
static enum SCEVTypes negate(enum SCEVTypes T)
SCEVMinMaxExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N)
Note: Constructing subclasses via this constructor is allowed.
static bool classof(const SCEV *S)
This node represents multiplication of some number of SCEVs.
static bool classof(const SCEVUse *U)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
ArrayRef< SCEVUse > operands() const
NoWrapFlags getNoWrapFlags(NoWrapFlags Mask=FlagsMask) const
SCEVNAryExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N, Type *Ty)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
SCEVUse getOperand(unsigned i) const
static bool classof(const SCEVUse *U)
const SCEV * visitUnknown(const SCEVUnknown *Expr)
static const SCEV * rewrite(const SCEV *Scev, ScalarEvolution &SE, ValueToSCEVMapTy &Map)
SCEVParameterRewriter(ScalarEvolution &SE, ValueToSCEVMapTy &M)
This class represents a cast from a pointer to a pointer-sized integer value, without capturing the p...
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
SmallDenseMap< const SCEV *, const SCEV *, 16 > RewriteResults
const SCEV * visitPtrToAddrExpr(const SCEVPtrToAddrExpr *Expr)
const SCEV * visitSignExtendExpr(const SCEVSignExtendExpr *Expr)
const SCEV * visit(const SCEV *S)
const SCEV * visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr)
const SCEV * visitUnknown(const SCEVUnknown *Expr)
const SCEV * visitSMinExpr(const SCEVSMinExpr *Expr)
const SCEV * visitSequentialUMinExpr(const SCEVSequentialUMinExpr *Expr)
const SCEV * visitAddExpr(const SCEVAddExpr *Expr)
const SCEV * visitUMinExpr(const SCEVUMinExpr *Expr)
const SCEV * visitMulExpr(const SCEVMulExpr *Expr)
const SCEV * visitTruncateExpr(const SCEVTruncateExpr *Expr)
const SCEV * visitUMaxExpr(const SCEVUMaxExpr *Expr)
const SCEV * visitSMaxExpr(const SCEVSMaxExpr *Expr)
const SCEV * visitUDivExpr(const SCEVUDivExpr *Expr)
const SCEV * visitCouldNotCompute(const SCEVCouldNotCompute *Expr)
const SCEV * visitVScale(const SCEVVScale *VScale)
const SCEV * visitAddRecExpr(const SCEVAddRecExpr *Expr)
const SCEV * visitConstant(const SCEVConstant *Constant)
This class represents a signed maximum selection.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents a signed minimum selection.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const SCEVUse *U)
static SCEVTypes getEquivalentNonSequentialSCEVType(SCEVTypes Ty)
SCEVSequentialMinMaxExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N)
Note: Constructing subclasses via this constructor is allowed.
This class represents a sequential/in-order unsigned minimum selection.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents a sign extension of a small integer value to a larger integer value.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
Visit all nodes in the expression tree using worklist traversal.
void visitAll(const SCEV *Root)
This class represents a truncation of an integer value to a smaller integer value.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents a binary unsigned division operation.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
ArrayRef< SCEVUse > operands() const
SCEVUse getOperand(unsigned i) const
This class represents an unsigned maximum selection.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents an unsigned minimum selection.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents the value of vscale, as used when defining the length of a scalable vector or r...
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents a zero extension of a small integer value to a larger integer value.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents an analyzed expression in the program.
SCEVNoWrapFlags NoWrapFlags
SCEV(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy, unsigned short ExpressionSize, Type *Ty)
static constexpr auto FlagNUW
static constexpr auto FlagsMask
Type *const Ty
Immutable type of the SCEV.
static constexpr auto FlagNSW
LLVM_ABI ArrayRef< SCEVUse > operands() const
Return operands of this SCEV expression.
Type * getType() const
Return the LLVM type of this SCEV expression.
static constexpr auto FlagNone
SCEVTypes getSCEVType() const
unsigned short SubclassData
This field is initialized to zero and may be used in subclasses to store miscellaneous information.
static constexpr auto FlagNW
The main scalar evolution driver.
static SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OnFlags)
LLVM_ABI SCEVUse getAddRecExpr(SCEVUse Start, SCEVUse Step, const Loop *L, SCEVFlags Flags)
Get an add recurrence expression for the specified loop.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
Value * getValPtr() const
LLVM Value Representation.
Definition Value.h:75
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
void visitAll(const SCEV *Root, SV &Visitor)
Use SCEVTraversal to visit all nodes in the given expression tree.
DenseMap< const Value *, const SCEV * > ValueToSCEVMapTy
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
DenseMap< const Loop *, const SCEV * > LoopToScevMapT
SCEVNoWrapFlags
NoWrapFlags are bitfield indices into SCEV's SubclassData.
unsigned short computeExpressionSize(ArrayRef< SCEVUse > Args)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1788
DenseMap< const Value *, Value * > ValueToValueMap
SCEVUseT< const SCEV * > SCEVUse
bool SCEVExprContains(const SCEV *Root, PredTy Pred)
Return true if any node in Root satisfies the predicate Pred.
#define N
An object of this class is returned by queries that could not be answered.
SCEVNoWrapFlags getUseNoWrapFlags() const
Return only the use-specific no-wrap flags (NUW/NSW) without the underlying SCEV's flags.
PointerIntPair< SCEVPtrT, 2 > Base
SCEVNoWrapFlags getNoWrapFlags(SCEVNoWrapFlags Mask=SCEVNoWrapFlags::FlagsMask) const
Return the no-wrap flags for this SCEVUse, which is the union of the use-specific flags and the under...
A visitor class for SCEVUse.
RetVal visitCouldNotCompute(SCEVUseT< const SCEVCouldNotCompute * > S)
This class defines a simple visitor class that may be used for various SCEV analysis purposes.
RetVal visit(const SCEV *S)
RetVal visitCouldNotCompute(const SCEVCouldNotCompute *S)