951ac05135214ffc2f54dbf81ea5ad82e68a7ec6
[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 class Value;
23 class PHINode;
24 class Instruction;
25 class LoopInfo; class Loop;
26
27 class InductionVariable {
28 public:
29   enum iType {               // Identify the type of this induction variable
30     Cannonical,              // Starts at 0, counts by 1
31     SimpleLinear,            // Simple linear: Constant start, constant step
32     Linear,                  // General linear:  loop invariant start, and step
33     Unknown,                 // Unknown type.  Start & Step are null
34   } InductionType;
35   
36   Value *Start, *Step;       // Start and step expressions for this indvar
37   PHINode *Phi;              // The PHI node that corresponds to this indvar
38 public:
39
40   // Create an induction variable for the specified value.  If it is a PHI, and
41   // if it's recognizable, classify it and fill in instance variables.
42   //
43   InductionVariable(PHINode *PN, LoopInfo *LoopInfo = 0);
44
45   // Classify Induction
46   static enum iType Classify(const Value *Start, const Value *Step,
47                              const Loop *L = 0);
48 };
49
50 #endif