Add the ability to track HasNSW and HasNUW on more kinds of SCEV expressions.
[oota-llvm.git] / include / llvm / Analysis / ScalarEvolutionExpressions.h
1 //===- llvm/Analysis/ScalarEvolutionExpressions.h - SCEV Exprs --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the classes used to represent and build scalar expressions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ANALYSIS_SCALAREVOLUTION_EXPRESSIONS_H
15 #define LLVM_ANALYSIS_SCALAREVOLUTION_EXPRESSIONS_H
16
17 #include "llvm/Analysis/ScalarEvolution.h"
18 #include "llvm/Support/ErrorHandling.h"
19
20 namespace llvm {
21   class ConstantInt;
22   class ConstantRange;
23   class DominatorTree;
24
25   enum SCEVTypes {
26     // These should be ordered in terms of increasing complexity to make the
27     // folders simpler.
28     scConstant, scTruncate, scZeroExtend, scSignExtend, scAddExpr, scMulExpr,
29     scUDivExpr, scAddRecExpr, scUMaxExpr, scSMaxExpr,
30     scFieldOffset, scAllocSize, scUnknown, scCouldNotCompute
31   };
32
33   //===--------------------------------------------------------------------===//
34   /// SCEVConstant - This class represents a constant integer value.
35   ///
36   class SCEVConstant : public SCEV {
37     friend class ScalarEvolution;
38
39     ConstantInt *V;
40     SCEVConstant(const FoldingSetNodeID &ID, ConstantInt *v) :
41       SCEV(ID, scConstant), V(v) {}
42   public:
43     ConstantInt *getValue() const { return V; }
44
45     virtual bool isLoopInvariant(const Loop *L) const {
46       return true;
47     }
48
49     virtual bool hasComputableLoopEvolution(const Loop *L) const {
50       return false;  // Not loop variant
51     }
52
53     virtual const Type *getType() const;
54
55     virtual bool hasOperand(const SCEV *) const {
56       return false;
57     }
58
59     bool dominates(BasicBlock *BB, DominatorTree *DT) const {
60       return true;
61     }
62
63     bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const {
64       return true;
65     }
66
67     virtual void print(raw_ostream &OS) const;
68
69     /// Methods for support type inquiry through isa, cast, and dyn_cast:
70     static inline bool classof(const SCEVConstant *S) { return true; }
71     static inline bool classof(const SCEV *S) {
72       return S->getSCEVType() == scConstant;
73     }
74   };
75
76   //===--------------------------------------------------------------------===//
77   /// SCEVCastExpr - This is the base class for unary cast operator classes.
78   ///
79   class SCEVCastExpr : public SCEV {
80   protected:
81     const SCEV *Op;
82     const Type *Ty;
83
84     SCEVCastExpr(const FoldingSetNodeID &ID,
85                  unsigned SCEVTy, const SCEV *op, const Type *ty);
86
87   public:
88     const SCEV *getOperand() const { return Op; }
89     virtual const Type *getType() const { return Ty; }
90
91     virtual bool isLoopInvariant(const Loop *L) const {
92       return Op->isLoopInvariant(L);
93     }
94
95     virtual bool hasComputableLoopEvolution(const Loop *L) const {
96       return Op->hasComputableLoopEvolution(L);
97     }
98
99     virtual bool hasOperand(const SCEV *O) const {
100       return Op == O || Op->hasOperand(O);
101     }
102
103     virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const;
104
105     virtual bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const;
106
107     /// Methods for support type inquiry through isa, cast, and dyn_cast:
108     static inline bool classof(const SCEVCastExpr *S) { return true; }
109     static inline bool classof(const SCEV *S) {
110       return S->getSCEVType() == scTruncate ||
111              S->getSCEVType() == scZeroExtend ||
112              S->getSCEVType() == scSignExtend;
113     }
114   };
115
116   //===--------------------------------------------------------------------===//
117   /// SCEVTruncateExpr - This class represents a truncation of an integer value
118   /// to a smaller integer value.
119   ///
120   class SCEVTruncateExpr : public SCEVCastExpr {
121     friend class ScalarEvolution;
122
123     SCEVTruncateExpr(const FoldingSetNodeID &ID,
124                      const SCEV *op, const Type *ty);
125
126   public:
127     virtual void print(raw_ostream &OS) const;
128
129     /// Methods for support type inquiry through isa, cast, and dyn_cast:
130     static inline bool classof(const SCEVTruncateExpr *S) { return true; }
131     static inline bool classof(const SCEV *S) {
132       return S->getSCEVType() == scTruncate;
133     }
134   };
135
136   //===--------------------------------------------------------------------===//
137   /// SCEVZeroExtendExpr - This class represents a zero extension of a small
138   /// integer value to a larger integer value.
139   ///
140   class SCEVZeroExtendExpr : public SCEVCastExpr {
141     friend class ScalarEvolution;
142
143     SCEVZeroExtendExpr(const FoldingSetNodeID &ID,
144                        const SCEV *op, const Type *ty);
145
146   public:
147     virtual void print(raw_ostream &OS) const;
148
149     /// Methods for support type inquiry through isa, cast, and dyn_cast:
150     static inline bool classof(const SCEVZeroExtendExpr *S) { return true; }
151     static inline bool classof(const SCEV *S) {
152       return S->getSCEVType() == scZeroExtend;
153     }
154   };
155
156   //===--------------------------------------------------------------------===//
157   /// SCEVSignExtendExpr - This class represents a sign extension of a small
158   /// integer value to a larger integer value.
159   ///
160   class SCEVSignExtendExpr : public SCEVCastExpr {
161     friend class ScalarEvolution;
162
163     SCEVSignExtendExpr(const FoldingSetNodeID &ID,
164                        const SCEV *op, const Type *ty);
165
166   public:
167     virtual void print(raw_ostream &OS) const;
168
169     /// Methods for support type inquiry through isa, cast, and dyn_cast:
170     static inline bool classof(const SCEVSignExtendExpr *S) { return true; }
171     static inline bool classof(const SCEV *S) {
172       return S->getSCEVType() == scSignExtend;
173     }
174   };
175
176
177   //===--------------------------------------------------------------------===//
178   /// SCEVNAryExpr - This node is a base class providing common
179   /// functionality for n'ary operators.
180   ///
181   class SCEVNAryExpr : public SCEV {
182   protected:
183     SmallVector<const SCEV *, 8> Operands;
184
185     SCEVNAryExpr(const FoldingSetNodeID &ID,
186                  enum SCEVTypes T, const SmallVectorImpl<const SCEV *> &ops)
187       : SCEV(ID, T), Operands(ops.begin(), ops.end()) {}
188
189   public:
190     unsigned getNumOperands() const { return (unsigned)Operands.size(); }
191     const SCEV *getOperand(unsigned i) const {
192       assert(i < Operands.size() && "Operand index out of range!");
193       return Operands[i];
194     }
195
196     const SmallVectorImpl<const SCEV *> &getOperands() const {
197       return Operands;
198     }
199     typedef SmallVectorImpl<const SCEV *>::const_iterator op_iterator;
200     op_iterator op_begin() const { return Operands.begin(); }
201     op_iterator op_end() const { return Operands.end(); }
202
203     virtual bool isLoopInvariant(const Loop *L) const {
204       for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
205         if (!getOperand(i)->isLoopInvariant(L)) return false;
206       return true;
207     }
208
209     // hasComputableLoopEvolution - N-ary expressions have computable loop
210     // evolutions iff they have at least one operand that varies with the loop,
211     // but that all varying operands are computable.
212     virtual bool hasComputableLoopEvolution(const Loop *L) const {
213       bool HasVarying = false;
214       for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
215         if (!getOperand(i)->isLoopInvariant(L)) {
216           if (getOperand(i)->hasComputableLoopEvolution(L))
217             HasVarying = true;
218           else
219             return false;
220         }
221       return HasVarying;
222     }
223
224     virtual bool hasOperand(const SCEV *O) const {
225       for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
226         if (O == getOperand(i) || getOperand(i)->hasOperand(O))
227           return true;
228       return false;
229     }
230
231     bool dominates(BasicBlock *BB, DominatorTree *DT) const;
232
233     bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const;
234
235     virtual const Type *getType() const { return getOperand(0)->getType(); }
236
237     bool hasNoUnsignedWrap() const { return SubclassData & (1 << 0); }
238     void setHasNoUnsignedWrap(bool B) {
239       SubclassData = (SubclassData & ~(1 << 0)) | (B << 0);
240     }
241     bool hasNoSignedWrap() const { return SubclassData & (1 << 1); }
242     void setHasNoSignedWrap(bool B) {
243       SubclassData = (SubclassData & ~(1 << 1)) | (B << 1);
244     }
245
246     /// Methods for support type inquiry through isa, cast, and dyn_cast:
247     static inline bool classof(const SCEVNAryExpr *S) { return true; }
248     static inline bool classof(const SCEV *S) {
249       return S->getSCEVType() == scAddExpr ||
250              S->getSCEVType() == scMulExpr ||
251              S->getSCEVType() == scSMaxExpr ||
252              S->getSCEVType() == scUMaxExpr ||
253              S->getSCEVType() == scAddRecExpr;
254     }
255   };
256
257   //===--------------------------------------------------------------------===//
258   /// SCEVCommutativeExpr - This node is the base class for n'ary commutative
259   /// operators.
260   ///
261   class SCEVCommutativeExpr : public SCEVNAryExpr {
262   protected:
263     SCEVCommutativeExpr(const FoldingSetNodeID &ID,
264                         enum SCEVTypes T,
265                         const SmallVectorImpl<const SCEV *> &ops)
266       : SCEVNAryExpr(ID, T, ops) {}
267
268   public:
269     virtual const char *getOperationStr() const = 0;
270
271     virtual void print(raw_ostream &OS) const;
272
273     /// Methods for support type inquiry through isa, cast, and dyn_cast:
274     static inline bool classof(const SCEVCommutativeExpr *S) { return true; }
275     static inline bool classof(const SCEV *S) {
276       return S->getSCEVType() == scAddExpr ||
277              S->getSCEVType() == scMulExpr ||
278              S->getSCEVType() == scSMaxExpr ||
279              S->getSCEVType() == scUMaxExpr;
280     }
281   };
282
283
284   //===--------------------------------------------------------------------===//
285   /// SCEVAddExpr - This node represents an addition of some number of SCEVs.
286   ///
287   class SCEVAddExpr : public SCEVCommutativeExpr {
288     friend class ScalarEvolution;
289
290     SCEVAddExpr(const FoldingSetNodeID &ID,
291                 const SmallVectorImpl<const SCEV *> &ops)
292       : SCEVCommutativeExpr(ID, scAddExpr, ops) {
293     }
294
295   public:
296     virtual const char *getOperationStr() const { return " + "; }
297
298     /// Methods for support type inquiry through isa, cast, and dyn_cast:
299     static inline bool classof(const SCEVAddExpr *S) { return true; }
300     static inline bool classof(const SCEV *S) {
301       return S->getSCEVType() == scAddExpr;
302     }
303   };
304
305   //===--------------------------------------------------------------------===//
306   /// SCEVMulExpr - This node represents multiplication of some number of SCEVs.
307   ///
308   class SCEVMulExpr : public SCEVCommutativeExpr {
309     friend class ScalarEvolution;
310
311     SCEVMulExpr(const FoldingSetNodeID &ID,
312                 const SmallVectorImpl<const SCEV *> &ops)
313       : SCEVCommutativeExpr(ID, scMulExpr, ops) {
314     }
315
316   public:
317     virtual const char *getOperationStr() const { return " * "; }
318
319     /// Methods for support type inquiry through isa, cast, and dyn_cast:
320     static inline bool classof(const SCEVMulExpr *S) { return true; }
321     static inline bool classof(const SCEV *S) {
322       return S->getSCEVType() == scMulExpr;
323     }
324   };
325
326
327   //===--------------------------------------------------------------------===//
328   /// SCEVUDivExpr - This class represents a binary unsigned division operation.
329   ///
330   class SCEVUDivExpr : public SCEV {
331     friend class ScalarEvolution;
332
333     const SCEV *LHS;
334     const SCEV *RHS;
335     SCEVUDivExpr(const FoldingSetNodeID &ID, const SCEV *lhs, const SCEV *rhs)
336       : SCEV(ID, scUDivExpr), LHS(lhs), RHS(rhs) {}
337
338   public:
339     const SCEV *getLHS() const { return LHS; }
340     const SCEV *getRHS() const { return RHS; }
341
342     virtual bool isLoopInvariant(const Loop *L) const {
343       return LHS->isLoopInvariant(L) && RHS->isLoopInvariant(L);
344     }
345
346     virtual bool hasComputableLoopEvolution(const Loop *L) const {
347       return LHS->hasComputableLoopEvolution(L) &&
348              RHS->hasComputableLoopEvolution(L);
349     }
350
351     virtual bool hasOperand(const SCEV *O) const {
352       return O == LHS || O == RHS || LHS->hasOperand(O) || RHS->hasOperand(O);
353     }
354
355     bool dominates(BasicBlock *BB, DominatorTree *DT) const;
356
357     bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const;
358
359     virtual const Type *getType() const;
360
361     void print(raw_ostream &OS) const;
362
363     /// Methods for support type inquiry through isa, cast, and dyn_cast:
364     static inline bool classof(const SCEVUDivExpr *S) { return true; }
365     static inline bool classof(const SCEV *S) {
366       return S->getSCEVType() == scUDivExpr;
367     }
368   };
369
370
371   //===--------------------------------------------------------------------===//
372   /// SCEVAddRecExpr - This node represents a polynomial recurrence on the trip
373   /// count of the specified loop.  This is the primary focus of the
374   /// ScalarEvolution framework; all the other SCEV subclasses are mostly just
375   /// supporting infrastructure to allow SCEVAddRecExpr expressions to be
376   /// created and analyzed.
377   ///
378   /// All operands of an AddRec are required to be loop invariant.
379   ///
380   class SCEVAddRecExpr : public SCEVNAryExpr {
381     friend class ScalarEvolution;
382
383     const Loop *L;
384
385     SCEVAddRecExpr(const FoldingSetNodeID &ID,
386                    const SmallVectorImpl<const SCEV *> &ops, const Loop *l)
387       : SCEVNAryExpr(ID, scAddRecExpr, ops), L(l) {
388       for (size_t i = 0, e = Operands.size(); i != e; ++i)
389         assert(Operands[i]->isLoopInvariant(l) &&
390                "Operands of AddRec must be loop-invariant!");
391     }
392
393   public:
394     const SCEV *getStart() const { return Operands[0]; }
395     const Loop *getLoop() const { return L; }
396
397     /// getStepRecurrence - This method constructs and returns the recurrence
398     /// indicating how much this expression steps by.  If this is a polynomial
399     /// of degree N, it returns a chrec of degree N-1.
400     const SCEV *getStepRecurrence(ScalarEvolution &SE) const {
401       if (isAffine()) return getOperand(1);
402       return SE.getAddRecExpr(SmallVector<const SCEV *, 3>(op_begin()+1,
403                                                            op_end()),
404                               getLoop());
405     }
406
407     virtual bool hasComputableLoopEvolution(const Loop *QL) const {
408       if (L == QL) return true;
409       return false;
410     }
411
412     virtual bool isLoopInvariant(const Loop *QueryLoop) const;
413
414     /// isAffine - Return true if this is an affine AddRec (i.e., it represents
415     /// an expressions A+B*x where A and B are loop invariant values.
416     bool isAffine() const {
417       // We know that the start value is invariant.  This expression is thus
418       // affine iff the step is also invariant.
419       return getNumOperands() == 2;
420     }
421
422     /// isQuadratic - Return true if this is an quadratic AddRec (i.e., it
423     /// represents an expressions A+B*x+C*x^2 where A, B and C are loop
424     /// invariant values.  This corresponds to an addrec of the form {L,+,M,+,N}
425     bool isQuadratic() const {
426       return getNumOperands() == 3;
427     }
428
429     /// evaluateAtIteration - Return the value of this chain of recurrences at
430     /// the specified iteration number.
431     const SCEV *evaluateAtIteration(const SCEV *It, ScalarEvolution &SE) const;
432
433     /// getNumIterationsInRange - Return the number of iterations of this loop
434     /// that produce values in the specified constant range.  Another way of
435     /// looking at this is that it returns the first iteration number where the
436     /// value is not in the condition, thus computing the exit count.  If the
437     /// iteration count can't be computed, an instance of SCEVCouldNotCompute is
438     /// returned.
439     const SCEV *getNumIterationsInRange(ConstantRange Range,
440                                        ScalarEvolution &SE) const;
441
442     /// getPostIncExpr - Return an expression representing the value of
443     /// this expression one iteration of the loop ahead.
444     const SCEVAddRecExpr *getPostIncExpr(ScalarEvolution &SE) const {
445       return cast<SCEVAddRecExpr>(SE.getAddExpr(this, getStepRecurrence(SE)));
446     }
447
448     virtual void print(raw_ostream &OS) const;
449
450     /// Methods for support type inquiry through isa, cast, and dyn_cast:
451     static inline bool classof(const SCEVAddRecExpr *S) { return true; }
452     static inline bool classof(const SCEV *S) {
453       return S->getSCEVType() == scAddRecExpr;
454     }
455   };
456
457
458   //===--------------------------------------------------------------------===//
459   /// SCEVSMaxExpr - This class represents a signed maximum selection.
460   ///
461   class SCEVSMaxExpr : public SCEVCommutativeExpr {
462     friend class ScalarEvolution;
463
464     SCEVSMaxExpr(const FoldingSetNodeID &ID,
465                  const SmallVectorImpl<const SCEV *> &ops)
466       : SCEVCommutativeExpr(ID, scSMaxExpr, ops) {
467       // Max never overflows.
468       setHasNoUnsignedWrap(true);
469       setHasNoSignedWrap(true);
470     }
471
472   public:
473     virtual const char *getOperationStr() const { return " smax "; }
474
475     /// Methods for support type inquiry through isa, cast, and dyn_cast:
476     static inline bool classof(const SCEVSMaxExpr *S) { return true; }
477     static inline bool classof(const SCEV *S) {
478       return S->getSCEVType() == scSMaxExpr;
479     }
480   };
481
482
483   //===--------------------------------------------------------------------===//
484   /// SCEVUMaxExpr - This class represents an unsigned maximum selection.
485   ///
486   class SCEVUMaxExpr : public SCEVCommutativeExpr {
487     friend class ScalarEvolution;
488
489     SCEVUMaxExpr(const FoldingSetNodeID &ID,
490                  const SmallVectorImpl<const SCEV *> &ops)
491       : SCEVCommutativeExpr(ID, scUMaxExpr, ops) {
492       // Max never overflows.
493       setHasNoUnsignedWrap(true);
494       setHasNoSignedWrap(true);
495     }
496
497   public:
498     virtual const char *getOperationStr() const { return " umax "; }
499
500     /// Methods for support type inquiry through isa, cast, and dyn_cast:
501     static inline bool classof(const SCEVUMaxExpr *S) { return true; }
502     static inline bool classof(const SCEV *S) {
503       return S->getSCEVType() == scUMaxExpr;
504     }
505   };
506
507   //===--------------------------------------------------------------------===//
508   /// SCEVTargetDataConstant - This node is the base class for representing
509   /// target-dependent values in a target-independent way.
510   ///
511   class SCEVTargetDataConstant : public SCEV {
512   protected:
513     const Type *Ty;
514     SCEVTargetDataConstant(const FoldingSetNodeID &ID, enum SCEVTypes T,
515                            const Type *ty) :
516       SCEV(ID, T), Ty(ty) {}
517
518   public:
519     virtual bool isLoopInvariant(const Loop *) const { return true; }
520     virtual bool hasComputableLoopEvolution(const Loop *) const {
521       return false; // not computable
522     }
523
524     virtual bool hasOperand(const SCEV *) const {
525       return false;
526     }
527
528     bool dominates(BasicBlock *, DominatorTree *) const {
529       return true;
530     }
531
532     bool properlyDominates(BasicBlock *, DominatorTree *) const {
533       return true;
534     }
535
536     virtual const Type *getType() const { return Ty; }
537
538     /// Methods for support type inquiry through isa, cast, and dyn_cast:
539     static inline bool classof(const SCEVTargetDataConstant *S) { return true; }
540     static inline bool classof(const SCEV *S) {
541       return S->getSCEVType() == scFieldOffset ||
542              S->getSCEVType() == scAllocSize;
543     }
544   };
545
546   //===--------------------------------------------------------------------===//
547   /// SCEVFieldOffsetExpr - This node represents an offsetof expression.
548   ///
549   class SCEVFieldOffsetExpr : public SCEVTargetDataConstant {
550     friend class ScalarEvolution;
551
552     const StructType *STy;
553     unsigned FieldNo;
554     SCEVFieldOffsetExpr(const FoldingSetNodeID &ID, const Type *ty,
555                         const StructType *sty, unsigned fieldno) :
556       SCEVTargetDataConstant(ID, scFieldOffset, ty),
557       STy(sty), FieldNo(fieldno) {}
558
559   public:
560     const StructType *getStructType() const { return STy; }
561     unsigned getFieldNo() const { return FieldNo; }
562
563     virtual void print(raw_ostream &OS) const;
564
565     /// Methods for support type inquiry through isa, cast, and dyn_cast:
566     static inline bool classof(const SCEVFieldOffsetExpr *S) { return true; }
567     static inline bool classof(const SCEV *S) {
568       return S->getSCEVType() == scFieldOffset;
569     }
570   };
571
572   //===--------------------------------------------------------------------===//
573   /// SCEVAllocSize - This node represents a sizeof expression.
574   ///
575   class SCEVAllocSizeExpr : public SCEVTargetDataConstant {
576     friend class ScalarEvolution;
577
578     const Type *AllocTy;
579     SCEVAllocSizeExpr(const FoldingSetNodeID &ID,
580                       const Type *ty, const Type *allocty) :
581       SCEVTargetDataConstant(ID, scAllocSize, ty),
582       AllocTy(allocty) {}
583
584   public:
585     const Type *getAllocType() const { return AllocTy; }
586
587     virtual void print(raw_ostream &OS) const;
588
589     /// Methods for support type inquiry through isa, cast, and dyn_cast:
590     static inline bool classof(const SCEVAllocSizeExpr *S) { return true; }
591     static inline bool classof(const SCEV *S) {
592       return S->getSCEVType() == scAllocSize;
593     }
594   };
595
596   //===--------------------------------------------------------------------===//
597   /// SCEVUnknown - This means that we are dealing with an entirely unknown SCEV
598   /// value, and only represent it as its LLVM Value.  This is the "bottom"
599   /// value for the analysis.
600   ///
601   class SCEVUnknown : public SCEV {
602     friend class ScalarEvolution;
603
604     Value *V;
605     SCEVUnknown(const FoldingSetNodeID &ID, Value *v) :
606       SCEV(ID, scUnknown), V(v) {}
607
608   public:
609     Value *getValue() const { return V; }
610
611     virtual bool isLoopInvariant(const Loop *L) const;
612     virtual bool hasComputableLoopEvolution(const Loop *QL) const {
613       return false; // not computable
614     }
615
616     virtual bool hasOperand(const SCEV *) const {
617       return false;
618     }
619
620     bool dominates(BasicBlock *BB, DominatorTree *DT) const;
621
622     bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const;
623
624     virtual const Type *getType() const;
625
626     virtual void print(raw_ostream &OS) const;
627
628     /// Methods for support type inquiry through isa, cast, and dyn_cast:
629     static inline bool classof(const SCEVUnknown *S) { return true; }
630     static inline bool classof(const SCEV *S) {
631       return S->getSCEVType() == scUnknown;
632     }
633   };
634
635   /// SCEVVisitor - This class defines a simple visitor class that may be used
636   /// for various SCEV analysis purposes.
637   template<typename SC, typename RetVal=void>
638   struct SCEVVisitor {
639     RetVal visit(const SCEV *S) {
640       switch (S->getSCEVType()) {
641       case scConstant:
642         return ((SC*)this)->visitConstant((const SCEVConstant*)S);
643       case scTruncate:
644         return ((SC*)this)->visitTruncateExpr((const SCEVTruncateExpr*)S);
645       case scZeroExtend:
646         return ((SC*)this)->visitZeroExtendExpr((const SCEVZeroExtendExpr*)S);
647       case scSignExtend:
648         return ((SC*)this)->visitSignExtendExpr((const SCEVSignExtendExpr*)S);
649       case scAddExpr:
650         return ((SC*)this)->visitAddExpr((const SCEVAddExpr*)S);
651       case scMulExpr:
652         return ((SC*)this)->visitMulExpr((const SCEVMulExpr*)S);
653       case scUDivExpr:
654         return ((SC*)this)->visitUDivExpr((const SCEVUDivExpr*)S);
655       case scAddRecExpr:
656         return ((SC*)this)->visitAddRecExpr((const SCEVAddRecExpr*)S);
657       case scSMaxExpr:
658         return ((SC*)this)->visitSMaxExpr((const SCEVSMaxExpr*)S);
659       case scUMaxExpr:
660         return ((SC*)this)->visitUMaxExpr((const SCEVUMaxExpr*)S);
661       case scFieldOffset:
662         return ((SC*)this)->visitFieldOffsetExpr((const SCEVFieldOffsetExpr*)S);
663       case scAllocSize:
664         return ((SC*)this)->visitAllocSizeExpr((const SCEVAllocSizeExpr*)S);
665       case scUnknown:
666         return ((SC*)this)->visitUnknown((const SCEVUnknown*)S);
667       case scCouldNotCompute:
668         return ((SC*)this)->visitCouldNotCompute((const SCEVCouldNotCompute*)S);
669       default:
670         llvm_unreachable("Unknown SCEV type!");
671       }
672     }
673
674     RetVal visitCouldNotCompute(const SCEVCouldNotCompute *S) {
675       llvm_unreachable("Invalid use of SCEVCouldNotCompute!");
676       return RetVal();
677     }
678   };
679 }
680
681 #endif