LLVM 23.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
60
61/// This class represents a constant integer value.
62class SCEVConstant : public SCEV {
63 friend class ScalarEvolution;
64
65 ConstantInt *V;
66
67 SCEVConstant(const FoldingSetNodeIDRef ID, ConstantInt *v)
68 : SCEV(ID, scConstant, 1), V(v) {}
69
70public:
71 ConstantInt *getValue() const { return V; }
72 const APInt &getAPInt() const { return getValue()->getValue(); }
73
74 Type *getType() const { return V->getType(); }
75
76 /// Methods for support type inquiry through isa, cast, and dyn_cast:
77 static bool classof(const SCEV *S) { return S->getSCEVType() == scConstant; }
78};
79
80/// This class represents the value of vscale, as used when defining the length
81/// of a scalable vector or returned by the llvm.vscale() intrinsic.
82class SCEVVScale : public SCEV {
83 friend class ScalarEvolution;
84
85 SCEVVScale(const FoldingSetNodeIDRef ID, Type *ty)
86 : SCEV(ID, scVScale, 0), Ty(ty) {}
87
88 Type *Ty;
89
90public:
91 Type *getType() const { return Ty; }
92
93 /// Methods for support type inquiry through isa, cast, and dyn_cast:
94 static bool classof(const SCEV *S) { return S->getSCEVType() == scVScale; }
95};
96
97inline unsigned short computeExpressionSize(ArrayRef<SCEVUse> Args) {
98 APInt Size(16, 1);
99 for (const SCEV *Arg : Args)
100 Size = Size.uadd_sat(APInt(16, Arg->getExpressionSize()));
101 return (unsigned short)Size.getZExtValue();
102}
103
104/// This is the base class for unary cast operator classes.
105class SCEVCastExpr : public SCEV {
106protected:
109
111 SCEVUse op, Type *ty);
112
113public:
114 SCEVUse getOperand() const { return Op; }
115 SCEVUse getOperand(unsigned i) const {
116 assert(i == 0 && "Operand index out of range!");
117 return Op;
118 }
119 ArrayRef<SCEVUse> operands() const { return Op; }
120 size_t getNumOperands() const { return 1; }
121 Type *getType() const { return Ty; }
122
123 /// Methods for support type inquiry through isa, cast, and dyn_cast:
124 static bool classof(const SCEV *S) {
125 return S->getSCEVType() == scPtrToAddr || S->getSCEVType() == scPtrToInt ||
126 S->getSCEVType() == scTruncate || S->getSCEVType() == scZeroExtend ||
128 }
129};
130
131/// This class represents a cast from a pointer to a pointer-sized integer
132/// value.
133class SCEVPtrToIntExpr : public SCEVCastExpr {
134 friend class ScalarEvolution;
135
136 SCEVPtrToIntExpr(const FoldingSetNodeIDRef ID, SCEVUse Op, Type *ITy);
137
138public:
139 /// Methods for support type inquiry through isa, cast, and dyn_cast:
140 static bool classof(const SCEV *S) { return S->getSCEVType() == scPtrToInt; }
141 static bool classof(const SCEVUse *U) { return classof(U->getPointer()); }
142};
143
144/// This class represents a cast from a pointer to a pointer-sized integer
145/// value, without capturing the provenance of the pointer.
146class SCEVPtrToAddrExpr : public SCEVCastExpr {
147 friend class ScalarEvolution;
148
149 SCEVPtrToAddrExpr(const FoldingSetNodeIDRef ID, const SCEV *Op, Type *ITy);
150
151public:
152 /// Methods for support type inquiry through isa, cast, and dyn_cast:
153 static bool classof(const SCEV *S) { return S->getSCEVType() == scPtrToAddr; }
154};
155
156/// This is the base class for unary integral cast operator classes.
158protected:
160 SCEVUse op, Type *ty);
161
162public:
163 /// Methods for support type inquiry through isa, cast, and dyn_cast:
164 static bool classof(const SCEV *S) {
165 return S->getSCEVType() == scTruncate || S->getSCEVType() == scZeroExtend ||
167 }
168};
169
170/// This class represents a truncation of an integer value to a
171/// smaller integer value.
172class SCEVTruncateExpr : public SCEVIntegralCastExpr {
173 friend class ScalarEvolution;
174
175 SCEVTruncateExpr(const FoldingSetNodeIDRef ID, SCEVUse op, Type *ty);
176
177public:
178 /// Methods for support type inquiry through isa, cast, and dyn_cast:
179 static bool classof(const SCEV *S) { return S->getSCEVType() == scTruncate; }
180};
181
182/// This class represents a zero extension of a small integer value
183/// to a larger integer value.
184class SCEVZeroExtendExpr : public SCEVIntegralCastExpr {
185 friend class ScalarEvolution;
186
187 SCEVZeroExtendExpr(const FoldingSetNodeIDRef ID, SCEVUse op, Type *ty);
188
189public:
190 /// Methods for support type inquiry through isa, cast, and dyn_cast:
191 static bool classof(const SCEV *S) {
192 return S->getSCEVType() == scZeroExtend;
193 }
194};
195
196/// This class represents a sign extension of a small integer value
197/// to a larger integer value.
198class SCEVSignExtendExpr : public SCEVIntegralCastExpr {
199 friend class ScalarEvolution;
200
201 SCEVSignExtendExpr(const FoldingSetNodeIDRef ID, SCEVUse op, Type *ty);
202
203public:
204 /// Methods for support type inquiry through isa, cast, and dyn_cast:
205 static bool classof(const SCEV *S) {
206 return S->getSCEVType() == scSignExtend;
207 }
208};
209
210/// This node is a base class providing common functionality for
211/// n'ary operators.
212class SCEVNAryExpr : public SCEV {
213protected:
214 // Since SCEVs are immutable, ScalarEvolution allocates operand
215 // arrays with its SCEVAllocator, so this class just needs a simple
216 // pointer rather than a more elaborate vector-like data structure.
217 // This also avoids the need for a non-trivial destructor.
220
222 size_t N)
224 NumOperands(N) {}
225
226public:
227 size_t getNumOperands() const { return NumOperands; }
228
229 SCEVUse getOperand(unsigned i) const {
230 assert(i < NumOperands && "Operand index out of range!");
231 return Operands[i];
232 }
233
235
237 return static_cast<NoWrapFlags>(SubclassData) & Mask;
238 }
239
240 bool hasNoUnsignedWrap() const {
242 }
243
244 bool hasNoSignedWrap() const {
246 }
247
248 bool hasNoSelfWrap() const { return getNoWrapFlags(FlagNW) != FlagAnyWrap; }
249
250 /// Methods for support type inquiry through isa, cast, and dyn_cast:
251 static bool classof(const SCEV *S) {
252 return S->getSCEVType() == scAddExpr || S->getSCEVType() == scMulExpr ||
253 S->getSCEVType() == scSMaxExpr || S->getSCEVType() == scUMaxExpr ||
254 S->getSCEVType() == scSMinExpr || S->getSCEVType() == scUMinExpr ||
257 }
258 static bool classof(const SCEVUse *U) { return classof(U->getPointer()); }
259};
260
261/// This node is the base class for n'ary commutative operators.
263protected:
265 const SCEVUse *O, size_t N)
266 : SCEVNAryExpr(ID, T, O, N) {}
267
268public:
269 /// Methods for support type inquiry through isa, cast, and dyn_cast:
270 static bool classof(const SCEV *S) {
271 return S->getSCEVType() == scAddExpr || S->getSCEVType() == scMulExpr ||
272 S->getSCEVType() == scSMaxExpr || S->getSCEVType() == scUMaxExpr ||
273 S->getSCEVType() == scSMinExpr || S->getSCEVType() == scUMinExpr;
274 }
275
276 /// Set flags for a non-recurrence without clearing previously set flags.
278 SubclassData |= static_cast<unsigned short>(Flags);
279 }
280};
281
282/// This node represents an addition of some number of SCEVs.
283class SCEVAddExpr : public SCEVCommutativeExpr {
284 friend class ScalarEvolution;
285
286 Type *Ty;
287
288 SCEVAddExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
290 auto *FirstPointerTypedOp = find_if(
291 operands(), [](SCEVUse Op) { return Op->getType()->isPointerTy(); });
292 if (FirstPointerTypedOp != operands().end())
293 Ty = (*FirstPointerTypedOp)->getType();
294 else
295 Ty = getOperand(0)->getType();
296 }
297
298public:
299 Type *getType() const { return Ty; }
300
301 /// Methods for support type inquiry through isa, cast, and dyn_cast:
302 static bool classof(const SCEV *S) { return S->getSCEVType() == scAddExpr; }
303 static bool classof(const SCEVUse *U) { return classof(U->getPointer()); }
304};
305
306/// This node represents multiplication of some number of SCEVs.
307class SCEVMulExpr : public SCEVCommutativeExpr {
308 friend class ScalarEvolution;
309
310 SCEVMulExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
312
313public:
314 Type *getType() const { return getOperand(0)->getType(); }
315
316 /// Methods for support type inquiry through isa, cast, and dyn_cast:
317 static bool classof(const SCEV *S) { return S->getSCEVType() == scMulExpr; }
318 static bool classof(const SCEVUse *U) { return classof(U->getPointer()); }
319};
320
321/// This class represents a binary unsigned division operation.
322class SCEVUDivExpr : public SCEV {
323 friend class ScalarEvolution;
324
325 std::array<SCEVUse, 2> Operands;
326
327 SCEVUDivExpr(const FoldingSetNodeIDRef ID, SCEVUse lhs, SCEVUse rhs)
328 : SCEV(ID, scUDivExpr, computeExpressionSize({lhs, rhs})) {
329 Operands[0] = lhs;
330 Operands[1] = rhs;
331 }
332
333public:
334 SCEVUse getLHS() const { return Operands[0]; }
335 SCEVUse getRHS() const { return Operands[1]; }
336 size_t getNumOperands() const { return 2; }
337 SCEVUse getOperand(unsigned i) const {
338 assert((i == 0 || i == 1) && "Operand index out of range!");
339 return i == 0 ? getLHS() : getRHS();
340 }
341
342 ArrayRef<SCEVUse> operands() const { return Operands; }
343
344 Type *getType() const {
345 // In most cases the types of LHS and RHS will be the same, but in some
346 // crazy cases one or the other may be a pointer. ScalarEvolution doesn't
347 // depend on the type for correctness, but handling types carefully can
348 // avoid extra casts in the SCEVExpander. The LHS is more likely to be
349 // a pointer type than the RHS, so use the RHS' type here.
350 return getRHS()->getType();
351 }
352
353 /// Methods for support type inquiry through isa, cast, and dyn_cast:
354 static bool classof(const SCEV *S) { return S->getSCEVType() == scUDivExpr; }
355};
356
357/// This node represents a polynomial recurrence on the trip count
358/// of the specified loop. This is the primary focus of the
359/// ScalarEvolution framework; all the other SCEV subclasses are
360/// mostly just supporting infrastructure to allow SCEVAddRecExpr
361/// expressions to be created and analyzed.
362///
363/// All operands of an AddRec are required to be loop invariant.
364///
365class SCEVAddRecExpr : public SCEVNAryExpr {
366 friend class ScalarEvolution;
367
368 const Loop *L;
369
370 SCEVAddRecExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N,
371 const Loop *l)
372 : SCEVNAryExpr(ID, scAddRecExpr, O, N), L(l) {}
373
374public:
375 Type *getType() const { return getStart()->getType(); }
376 SCEVUse getStart() const { return Operands[0]; }
377 const Loop *getLoop() const { return L; }
378
379 /// Constructs and returns the recurrence indicating how much this
380 /// expression steps by. If this is a polynomial of degree N, it
381 /// returns a chrec of degree N-1. We cannot determine whether
382 /// the step recurrence has self-wraparound.
384 if (isAffine())
385 return getOperand(1);
386 return SE.getAddRecExpr(SmallVector<SCEVUse, 3>(operands().drop_front()),
388 }
389
390 /// Return true if this represents an expression A + B*x where A
391 /// and B are loop invariant values.
392 bool isAffine() const {
393 // We know that the start value is invariant. This expression is thus
394 // affine iff the step is also invariant.
395 return getNumOperands() == 2;
396 }
397
398 /// Return true if this represents an expression A + B*x + C*x^2
399 /// where A, B and C are loop invariant values. This corresponds
400 /// to an addrec of the form {L,+,M,+,N}
401 bool isQuadratic() const { return getNumOperands() == 3; }
402
403 /// Set flags for a recurrence without clearing any previously set flags.
404 /// For AddRec, either NUW or NSW implies NW. Keep track of this fact here
405 /// to make it easier to propagate flags.
407 if (any(Flags & (FlagNUW | FlagNSW)))
408 Flags = ScalarEvolution::setFlags(Flags, FlagNW);
409 SubclassData |= static_cast<unsigned short>(Flags);
410 }
411
412 /// Return the value of this chain of recurrences at the specified
413 /// iteration number.
414 LLVM_ABI const SCEV *evaluateAtIteration(const SCEV *It,
415 ScalarEvolution &SE) const;
416
417 /// Return the value of this chain of recurrences at the specified iteration
418 /// number. Takes an explicit list of operands to represent an AddRec.
420 const SCEV *It,
421 ScalarEvolution &SE);
422
423 /// Return the number of iterations of this loop that produce
424 /// values in the specified constant range. Another way of
425 /// looking at this is that it returns the first iteration number
426 /// where the value is not in the condition, thus computing the
427 /// exit count. If the iteration count can't be computed, an
428 /// instance of SCEVCouldNotCompute is returned.
430 ScalarEvolution &SE) const;
431
432 /// Return an expression representing the value of this expression
433 /// one iteration of the loop ahead.
435
436 /// Methods for support type inquiry through isa, cast, and dyn_cast:
437 static bool classof(const SCEV *S) {
438 return S->getSCEVType() == scAddRecExpr;
439 }
440};
441
442/// This node is the base class min/max selections.
444 friend class ScalarEvolution;
445
446 static bool isMinMaxType(enum SCEVTypes T) {
447 return T == scSMaxExpr || T == scUMaxExpr || T == scSMinExpr ||
448 T == scUMinExpr;
449 }
450
451protected:
452 /// Note: Constructing subclasses via this constructor is allowed
454 const SCEVUse *O, size_t N)
455 : SCEVCommutativeExpr(ID, T, O, N) {
456 assert(isMinMaxType(T));
457 // Min and max never overflow
459 }
460
461public:
462 Type *getType() const { return getOperand(0)->getType(); }
463
464 static bool classof(const SCEV *S) { return isMinMaxType(S->getSCEVType()); }
465
466 static enum SCEVTypes negate(enum SCEVTypes T) {
467 switch (T) {
468 case scSMaxExpr:
469 return scSMinExpr;
470 case scSMinExpr:
471 return scSMaxExpr;
472 case scUMaxExpr:
473 return scUMinExpr;
474 case scUMinExpr:
475 return scUMaxExpr;
476 default:
477 llvm_unreachable("Not a min or max SCEV type!");
478 }
479 }
480};
481
482/// This class represents a signed maximum selection.
483class SCEVSMaxExpr : public SCEVMinMaxExpr {
484 friend class ScalarEvolution;
485
486 SCEVSMaxExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
487 : SCEVMinMaxExpr(ID, scSMaxExpr, O, N) {}
488
489public:
490 /// Methods for support type inquiry through isa, cast, and dyn_cast:
491 static bool classof(const SCEV *S) { return S->getSCEVType() == scSMaxExpr; }
492};
493
494/// This class represents an unsigned maximum selection.
495class SCEVUMaxExpr : public SCEVMinMaxExpr {
496 friend class ScalarEvolution;
497
498 SCEVUMaxExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
499 : SCEVMinMaxExpr(ID, scUMaxExpr, O, N) {}
500
501public:
502 /// Methods for support type inquiry through isa, cast, and dyn_cast:
503 static bool classof(const SCEV *S) { return S->getSCEVType() == scUMaxExpr; }
504};
505
506/// This class represents a signed minimum selection.
507class SCEVSMinExpr : public SCEVMinMaxExpr {
508 friend class ScalarEvolution;
509
510 SCEVSMinExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
511 : SCEVMinMaxExpr(ID, scSMinExpr, O, N) {}
512
513public:
514 /// Methods for support type inquiry through isa, cast, and dyn_cast:
515 static bool classof(const SCEV *S) { return S->getSCEVType() == scSMinExpr; }
516};
517
518/// This class represents an unsigned minimum selection.
519class SCEVUMinExpr : public SCEVMinMaxExpr {
520 friend class ScalarEvolution;
521
522 SCEVUMinExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O, size_t N)
523 : SCEVMinMaxExpr(ID, scUMinExpr, O, N) {}
524
525public:
526 /// Methods for support type inquiry through isa, cast, and dyn_cast:
527 static bool classof(const SCEV *S) { return S->getSCEVType() == scUMinExpr; }
528};
529
530/// This node is the base class for sequential/in-order min/max selections.
531/// Note that their fundamental difference from SCEVMinMaxExpr's is that they
532/// are early-returning upon reaching saturation point.
533/// I.e. given `0 umin_seq poison`, the result will be `0`, while the result of
534/// `0 umin poison` is `poison`. When returning early, later expressions are not
535/// executed, so `0 umin_seq (%x u/ 0)` does not result in undefined behavior.
537 friend class ScalarEvolution;
538
539 static bool isSequentialMinMaxType(enum SCEVTypes T) {
540 return T == scSequentialUMinExpr;
541 }
542
543 /// Set flags for a non-recurrence without clearing previously set flags.
544 void setNoWrapFlags(NoWrapFlags Flags) {
545 SubclassData |= static_cast<unsigned short>(Flags);
546 }
547
548protected:
549 /// Note: Constructing subclasses via this constructor is allowed
551 const SCEVUse *O, size_t N)
552 : SCEVNAryExpr(ID, T, O, N) {
553 assert(isSequentialMinMaxType(T));
554 // Min and max never overflow
555 setNoWrapFlags(FlagNUW | FlagNSW);
556 }
557
558public:
559 Type *getType() const { return getOperand(0)->getType(); }
560
562 assert(isSequentialMinMaxType(Ty));
563 switch (Ty) {
565 return scUMinExpr;
566 default:
567 llvm_unreachable("Not a sequential min/max type.");
568 }
569 }
570
574
575 static bool classof(const SCEV *S) {
576 return isSequentialMinMaxType(S->getSCEVType());
577 }
578 static bool classof(const SCEVUse *U) { return classof(U->getPointer()); }
579};
580
581/// This class represents a sequential/in-order unsigned minimum selection.
582class SCEVSequentialUMinExpr : public SCEVSequentialMinMaxExpr {
583 friend class ScalarEvolution;
584
585 SCEVSequentialUMinExpr(const FoldingSetNodeIDRef ID, const SCEVUse *O,
586 size_t N)
588
589public:
590 /// Methods for support type inquiry through isa, cast, and dyn_cast:
591 static bool classof(const SCEV *S) {
592 return S->getSCEVType() == scSequentialUMinExpr;
593 }
594};
595
596/// This means that we are dealing with an entirely unknown SCEV
597/// value, and only represent it as its LLVM Value. This is the
598/// "bottom" value for the analysis.
599class LLVM_ABI SCEVUnknown final : public SCEV, private CallbackVH {
600 friend class ScalarEvolution;
601
602 /// The parent ScalarEvolution value. This is used to update the
603 /// parent's maps when the value associated with a SCEVUnknown is
604 /// deleted or RAUW'd.
605 ScalarEvolution *SE;
606
607 /// The next pointer in the linked list of all SCEVUnknown
608 /// instances owned by a ScalarEvolution.
609 SCEVUnknown *Next;
610
611 SCEVUnknown(const FoldingSetNodeIDRef ID, Value *V, ScalarEvolution *se,
612 SCEVUnknown *next)
613 : SCEV(ID, scUnknown, 1), CallbackVH(V), SE(se), Next(next) {}
614
615 // Implement CallbackVH.
616 void deleted() override;
617 void allUsesReplacedWith(Value *New) override;
618
619public:
620 Value *getValue() const { return getValPtr(); }
621
622 Type *getType() const { return getValPtr()->getType(); }
623
624 /// Methods for support type inquiry through isa, cast, and dyn_cast:
625 static bool classof(const SCEV *S) { return S->getSCEVType() == scUnknown; }
626};
627
628/// This class defines a simple visitor class that may be used for
629/// various SCEV analysis purposes.
630template <typename SC, typename RetVal = void> struct SCEVVisitor {
631 RetVal visit(const SCEV *S) {
632 switch (S->getSCEVType()) {
633 case scConstant:
634 return ((SC *)this)->visitConstant((const SCEVConstant *)S);
635 case scVScale:
636 return ((SC *)this)->visitVScale((const SCEVVScale *)S);
637 case scPtrToAddr:
638 return ((SC *)this)->visitPtrToAddrExpr((const SCEVPtrToAddrExpr *)S);
639 case scPtrToInt:
640 return ((SC *)this)->visitPtrToIntExpr((const SCEVPtrToIntExpr *)S);
641 case scTruncate:
642 return ((SC *)this)->visitTruncateExpr((const SCEVTruncateExpr *)S);
643 case scZeroExtend:
644 return ((SC *)this)->visitZeroExtendExpr((const SCEVZeroExtendExpr *)S);
645 case scSignExtend:
646 return ((SC *)this)->visitSignExtendExpr((const SCEVSignExtendExpr *)S);
647 case scAddExpr:
648 return ((SC *)this)->visitAddExpr((const SCEVAddExpr *)S);
649 case scMulExpr:
650 return ((SC *)this)->visitMulExpr((const SCEVMulExpr *)S);
651 case scUDivExpr:
652 return ((SC *)this)->visitUDivExpr((const SCEVUDivExpr *)S);
653 case scAddRecExpr:
654 return ((SC *)this)->visitAddRecExpr((const SCEVAddRecExpr *)S);
655 case scSMaxExpr:
656 return ((SC *)this)->visitSMaxExpr((const SCEVSMaxExpr *)S);
657 case scUMaxExpr:
658 return ((SC *)this)->visitUMaxExpr((const SCEVUMaxExpr *)S);
659 case scSMinExpr:
660 return ((SC *)this)->visitSMinExpr((const SCEVSMinExpr *)S);
661 case scUMinExpr:
662 return ((SC *)this)->visitUMinExpr((const SCEVUMinExpr *)S);
664 return ((SC *)this)
665 ->visitSequentialUMinExpr((const SCEVSequentialUMinExpr *)S);
666 case scUnknown:
667 return ((SC *)this)->visitUnknown((const SCEVUnknown *)S);
669 return ((SC *)this)->visitCouldNotCompute((const SCEVCouldNotCompute *)S);
670 }
671 llvm_unreachable("Unknown SCEV kind!");
672 }
673
675 llvm_unreachable("Invalid use of SCEVCouldNotCompute!");
676 }
677};
678
679/// A visitor class for SCEVUse.
680template <typename SC, typename RetVal = void> struct SCEVUseVisitor {
681 RetVal visit(SCEVUse S) {
682 switch (S->getSCEVType()) {
683 case scConstant:
684 return ((SC *)this)
685 ->visitConstant(cast<SCEVUseT<const SCEVConstant *>>(S));
686 case scVScale:
687 return ((SC *)this)->visitVScale(cast<SCEVUseT<const SCEVVScale *>>(S));
688 case scPtrToAddr:
689 return ((SC *)this)
690 ->visitPtrToAddrExpr(cast<SCEVUseT<const SCEVPtrToAddrExpr *>>(S));
691 case scPtrToInt:
692 return ((SC *)this)
693 ->visitPtrToIntExpr(cast<SCEVUseT<const SCEVPtrToIntExpr *>>(S));
694 case scTruncate:
695 return ((SC *)this)
696 ->visitTruncateExpr(cast<SCEVUseT<const SCEVTruncateExpr *>>(S));
697 case scZeroExtend:
698 return ((SC *)this)
699 ->visitZeroExtendExpr(cast<SCEVUseT<const SCEVZeroExtendExpr *>>(S));
700 case scSignExtend:
701 return ((SC *)this)
702 ->visitSignExtendExpr(cast<SCEVUseT<const SCEVSignExtendExpr *>>(S));
703 case scAddExpr:
704 return ((SC *)this)->visitAddExpr(cast<SCEVUseT<const SCEVAddExpr *>>(S));
705 case scMulExpr:
706 return ((SC *)this)->visitMulExpr(cast<SCEVUseT<const SCEVMulExpr *>>(S));
707 case scUDivExpr:
708 return ((SC *)this)
709 ->visitUDivExpr(cast<SCEVUseT<const SCEVUDivExpr *>>(S));
710 case scAddRecExpr:
711 return ((SC *)this)
712 ->visitAddRecExpr(cast<SCEVUseT<const SCEVAddRecExpr *>>(S));
713 case scSMaxExpr:
714 return ((SC *)this)
715 ->visitSMaxExpr(cast<SCEVUseT<const SCEVSMaxExpr *>>(S));
716 case scUMaxExpr:
717 return ((SC *)this)
718 ->visitUMaxExpr(cast<SCEVUseT<const SCEVUMaxExpr *>>(S));
719 case scSMinExpr:
720 return ((SC *)this)
721 ->visitSMinExpr(cast<SCEVUseT<const SCEVSMinExpr *>>(S));
722 case scUMinExpr:
723 return ((SC *)this)
724 ->visitUMinExpr(cast<SCEVUseT<const SCEVUMinExpr *>>(S));
726 return ((SC *)this)
727 ->visitSequentialUMinExpr(
729 case scUnknown:
730 return ((SC *)this)->visitUnknown(cast<SCEVUseT<const SCEVUnknown *>>(S));
732 return ((SC *)this)
733 ->visitCouldNotCompute(
735 }
736 llvm_unreachable("Unknown SCEV kind!");
737 }
738
740 llvm_unreachable("Invalid use of SCEVCouldNotCompute!");
741 }
742};
743
744/// Visit all nodes in the expression tree using worklist traversal.
745///
746/// Visitor implements:
747/// // return true to follow this node.
748/// bool follow(const SCEV *S);
749/// // return true to terminate the search.
750/// bool isDone();
751template <typename SV> class SCEVTraversal {
752 SV &Visitor;
755
756 void push(const SCEV *S) {
757 if (Visited.insert(S).second && Visitor.follow(S))
758 Worklist.push_back(S);
759 }
760
761public:
762 SCEVTraversal(SV &V) : Visitor(V) {}
763
764 void visitAll(const SCEV *Root) {
765 push(Root);
766 while (!Worklist.empty() && !Visitor.isDone()) {
767 const SCEV *S = Worklist.pop_back_val();
768
769 switch (S->getSCEVType()) {
770 case scConstant:
771 case scVScale:
772 case scUnknown:
773 continue;
774 case scPtrToAddr:
775 case scPtrToInt:
776 case scTruncate:
777 case scZeroExtend:
778 case scSignExtend:
779 case scAddExpr:
780 case scMulExpr:
781 case scUDivExpr:
782 case scSMaxExpr:
783 case scUMaxExpr:
784 case scSMinExpr:
785 case scUMinExpr:
787 case scAddRecExpr:
788 for (const SCEV *Op : S->operands()) {
789 push(Op);
790 if (Visitor.isDone())
791 break;
792 }
793 continue;
795 llvm_unreachable("Attempt to use a SCEVCouldNotCompute object!");
796 }
797 llvm_unreachable("Unknown SCEV kind!");
798 }
799 }
800};
801
802/// Use SCEVTraversal to visit all nodes in the given expression tree.
803template <typename SV> void visitAll(const SCEV *Root, SV &Visitor) {
804 SCEVTraversal<SV> T(Visitor);
805 T.visitAll(Root);
806}
807
808/// Return true if any node in \p Root satisfies the predicate \p Pred.
809template <typename PredTy>
810bool SCEVExprContains(const SCEV *Root, PredTy Pred) {
811 struct FindClosure {
812 bool Found = false;
813 PredTy Pred;
814
815 FindClosure(PredTy Pred) : Pred(Pred) {}
816
817 bool follow(const SCEV *S) {
818 if (!Pred(S))
819 return true;
820
821 Found = true;
822 return false;
823 }
824
825 bool isDone() const { return Found; }
826 };
827
828 FindClosure FC(Pred);
829 visitAll(Root, FC);
830 return FC.Found;
831}
832
833/// This visitor recursively visits a SCEV expression and re-writes it.
834/// The result from each visit is cached, so it will return the same
835/// SCEV for the same input.
836template <typename SC>
837class SCEVRewriteVisitor : public SCEVVisitor<SC, const SCEV *> {
838protected:
840 // Memoize the result of each visit so that we only compute once for
841 // the same input SCEV. This is to avoid redundant computations when
842 // a SCEV is referenced by multiple SCEVs. Without memoization, this
843 // visit algorithm would have exponential time complexity in the worst
844 // case, causing the compiler to hang on certain tests.
846
847public:
849
850 const SCEV *visit(const SCEV *S) {
851 auto It = RewriteResults.find(S);
852 if (It != RewriteResults.end())
853 return It->second;
854 auto *Visited = SCEVVisitor<SC, const SCEV *>::visit(S);
855 auto Result = RewriteResults.try_emplace(S, Visited);
856 assert(Result.second && "Should insert a new entry");
857 return Result.first->second;
858 }
859
861
862 const SCEV *visitVScale(const SCEVVScale *VScale) { return VScale; }
863
865 const SCEV *Operand = ((SC *)this)->visit(Expr->getOperand());
866 return Operand == Expr->getOperand() ? Expr : SE.getPtrToAddrExpr(Operand);
867 }
868
870 const SCEV *Operand = ((SC *)this)->visit(Expr->getOperand());
871 return Operand == Expr->getOperand()
872 ? Expr
873 : SE.getPtrToIntExpr(Operand, Expr->getType());
874 }
875
877 const SCEV *Operand = ((SC *)this)->visit(Expr->getOperand());
878 return Operand == Expr->getOperand()
879 ? Expr
880 : SE.getTruncateExpr(Operand, Expr->getType());
881 }
882
884 const SCEV *Operand = ((SC *)this)->visit(Expr->getOperand());
885 return Operand == Expr->getOperand()
886 ? Expr
887 : SE.getZeroExtendExpr(Operand, Expr->getType());
888 }
889
891 const SCEV *Operand = ((SC *)this)->visit(Expr->getOperand());
892 return Operand == Expr->getOperand()
893 ? Expr
894 : SE.getSignExtendExpr(Operand, Expr->getType());
895 }
896
897 const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {
899 bool Changed = false;
900 for (const SCEV *Op : Expr->operands()) {
901 Operands.push_back(((SC *)this)->visit(Op));
902 Changed |= Op != Operands.back();
903 }
904 return !Changed ? Expr : SE.getAddExpr(Operands);
905 }
906
907 const SCEV *visitMulExpr(const SCEVMulExpr *Expr) {
909 bool Changed = false;
910 for (const SCEV *Op : Expr->operands()) {
911 Operands.push_back(((SC *)this)->visit(Op));
912 Changed |= Op != Operands.back();
913 }
914 return !Changed ? Expr : SE.getMulExpr(Operands);
915 }
916
917 const SCEV *visitUDivExpr(const SCEVUDivExpr *Expr) {
918 auto *LHS = ((SC *)this)->visit(Expr->getLHS());
919 auto *RHS = ((SC *)this)->visit(Expr->getRHS());
920 bool Changed = LHS != Expr->getLHS() || RHS != Expr->getRHS();
921 return !Changed ? Expr : SE.getUDivExpr(LHS, RHS);
922 }
923
924 const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
926 bool Changed = false;
927 for (const SCEV *Op : Expr->operands()) {
928 Operands.push_back(((SC *)this)->visit(Op));
929 Changed |= Op != Operands.back();
930 }
931 return !Changed ? Expr
932 : SE.getAddRecExpr(Operands, Expr->getLoop(),
933 Expr->getNoWrapFlags());
934 }
935
936 const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) {
938 bool Changed = false;
939 for (const SCEV *Op : Expr->operands()) {
940 Operands.push_back(((SC *)this)->visit(Op));
941 Changed |= Op != Operands.back();
942 }
943 return !Changed ? Expr : SE.getSMaxExpr(Operands);
944 }
945
946 const SCEV *visitUMaxExpr(const SCEVUMaxExpr *Expr) {
948 bool Changed = false;
949 for (const SCEV *Op : Expr->operands()) {
950 Operands.push_back(((SC *)this)->visit(Op));
951 Changed |= Op != Operands.back();
952 }
953 return !Changed ? Expr : SE.getUMaxExpr(Operands);
954 }
955
956 const SCEV *visitSMinExpr(const SCEVSMinExpr *Expr) {
958 bool Changed = false;
959 for (const SCEV *Op : Expr->operands()) {
960 Operands.push_back(((SC *)this)->visit(Op));
961 Changed |= Op != Operands.back();
962 }
963 return !Changed ? Expr : SE.getSMinExpr(Operands);
964 }
965
966 const SCEV *visitUMinExpr(const SCEVUMinExpr *Expr) {
968 bool Changed = false;
969 for (const SCEV *Op : Expr->operands()) {
970 Operands.push_back(((SC *)this)->visit(Op));
971 Changed |= Op != Operands.back();
972 }
973 return !Changed ? Expr : SE.getUMinExpr(Operands);
974 }
975
978 bool Changed = false;
979 for (const SCEV *Op : Expr->operands()) {
980 Operands.push_back(((SC *)this)->visit(Op));
981 Changed |= Op != Operands.back();
982 }
983 return !Changed ? Expr : SE.getUMinExpr(Operands, /*Sequential=*/true);
984 }
985
986 const SCEV *visitUnknown(const SCEVUnknown *Expr) { return Expr; }
987
989 return Expr;
990 }
991};
992
995
996/// The SCEVParameterRewriter takes a scalar evolution expression and updates
997/// the SCEVUnknown components following the Map (Value -> SCEV).
998class SCEVParameterRewriter : public SCEVRewriteVisitor<SCEVParameterRewriter> {
999public:
1000 static const SCEV *rewrite(const SCEV *Scev, ScalarEvolution &SE,
1001 ValueToSCEVMapTy &Map) {
1003 return Rewriter.visit(Scev);
1004 }
1005
1008
1009 const SCEV *visitUnknown(const SCEVUnknown *Expr) {
1010 auto I = Map.find(Expr->getValue());
1011 if (I == Map.end())
1012 return Expr;
1013 return I->second;
1014 }
1015
1016private:
1017 ValueToSCEVMapTy &Map;
1018};
1019
1021
1022/// The SCEVLoopAddRecRewriter takes a scalar evolution expression and applies
1023/// the Map (Loop -> SCEV) to all AddRecExprs.
1025 : public SCEVRewriteVisitor<SCEVLoopAddRecRewriter> {
1026public:
1029
1030 static const SCEV *rewrite(const SCEV *Scev, LoopToScevMapT &Map,
1033 return Rewriter.visit(Scev);
1034 }
1035
1037 SmallVector<SCEVUse, 2> Operands;
1038 for (SCEVUse Op : Expr->operands())
1039 Operands.push_back(visit(Op));
1040
1041 const Loop *L = Expr->getLoop();
1042 auto It = Map.find(L);
1043 if (It == Map.end())
1044 return SE.getAddRecExpr(Operands, L, Expr->getNoWrapFlags());
1045
1046 return SCEVAddRecExpr::evaluateAtIteration(Operands, It->second, SE);
1047 }
1048
1049private:
1050 LoopToScevMapT &Map;
1051};
1052
1053template <typename SCEVPtrT>
1054inline SCEVNoWrapFlags
1057 if (auto *NAry = dyn_cast<SCEVNAryExpr>(Base::getPointer()))
1058 Flags = NAry->getNoWrapFlags();
1059 return (Flags | getUseNoWrapFlags()) & Mask;
1060}
1061
1062} // end namespace llvm
1063
1064#endif // LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
#define op(i)
#define I(x, y, z)
Definition MD5.cpp:57
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
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
ArrayRef - 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
FoldingSetNodeIDRef - This class describes a reference to an interned FoldingSetNodeID,...
Definition FoldingSet.h:172
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 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:
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.
SCEVCommutativeExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N)
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
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
SCEVNAryExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N)
NoWrapFlags getNoWrapFlags(NoWrapFlags Mask=NoWrapMask) const
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:
This class represents a cast from a pointer to a pointer-sized integer value.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const SCEVUse *U)
const SCEV * visitPtrToAddrExpr(const SCEVPtrToAddrExpr *Expr)
const SCEV * visitSignExtendExpr(const SCEVSignExtendExpr *Expr)
const SCEV * visitPtrToIntExpr(const SCEVPtrToIntExpr *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)
SmallDenseMap< const SCEV *, const SCEV * > RewriteResults
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.
static constexpr auto NoWrapMask
SCEVNoWrapFlags NoWrapFlags
static constexpr auto FlagNUW
static constexpr auto FlagAnyWrap
static constexpr auto FlagNSW
LLVM_ABI ArrayRef< SCEVUse > operands() const
Return operands of this SCEV expression.
SCEV(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy, unsigned short ExpressionSize)
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
LLVM_ABI Type * getType() const
Return the LLVM type of this SCEV expression.
The main scalar evolution driver.
LLVM_ABI const SCEV * getAddRecExpr(SCEVUse Start, SCEVUse Step, const Loop *L, SCEV::NoWrapFlags Flags)
Get an add recurrence expression for the specified loop.
static SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OnFlags)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
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)
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:1772
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.
SCEVNoWrapFlags getNoWrapFlags(SCEVNoWrapFlags Mask=SCEVNoWrapFlags::NoWrapMask) 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)