* Standardize how analysis results/passes as printed with the print() virtual
[oota-llvm.git] / include / llvm / Analysis / InductionVariable.h
1 //===- llvm/Analysis/InductionVariable.h - Induction variable ----*- C++ -*--=//
2 //
3 // This interface is used to identify and classify induction variables that
4 // exist in the program.  Induction variables must contain a PHI node that
5 // exists in a loop header.  Because of this, they are identified an managed by
6 // this PHI node.
7 //
8 // Induction variables are classified into a type.  Knowing that an induction
9 // variable is of a specific type can constrain the values of the start and
10 // step.  For example, a SimpleLinear induction variable must have a start and
11 // step values that are constants.
12 //
13 // Induction variables can be created with or without loop information.  If no
14 // loop information is available, induction variables cannot be recognized to be
15 // more than SimpleLinear variables.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_ANALYSIS_INDUCTIONVARIABLE_H
20 #define LLVM_ANALYSIS_INDUCTIONVARIABLE_H
21
22 #include <iosfwd>
23 class Value;
24 class PHINode;
25 class Instruction;
26 class LoopInfo; class Loop;
27
28 class InductionVariable {
29 public:
30   enum iType {               // Identify the type of this induction variable
31     Cannonical,              // Starts at 0, counts by 1
32     SimpleLinear,            // Simple linear: Constant start, constant step
33     Linear,                  // General linear:  loop invariant start, and step
34     Unknown,                 // Unknown type.  Start & Step are null
35   } InductionType;
36   
37   Value *Start, *Step;       // Start and step expressions for this indvar
38   PHINode *Phi;              // The PHI node that corresponds to this indvar
39 public:
40
41   // Create an induction variable for the specified value.  If it is a PHI, and
42   // if it's recognizable, classify it and fill in instance variables.
43   //
44   InductionVariable(PHINode *PN, LoopInfo *LoopInfo = 0);
45
46   // Classify Induction
47   static enum iType Classify(const Value *Start, const Value *Step,
48                              const Loop *L = 0);
49
50   void print(std::ostream &OS) const;
51 };
52
53 #endif