1 //===- llvm/Analysis/InductionVariable.h - Induction variable ----*- C++ -*--=//
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
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.
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.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_ANALYSIS_INDUCTIONVARIABLE_H
20 #define LLVM_ANALYSIS_INDUCTIONVARIABLE_H
26 class LoopInfo; class Loop;
28 class InductionVariable {
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
37 Value *Start, *Step, *End; // Start, step, and end expressions for this indvar
38 PHINode *Phi; // The PHI node that corresponds to this indvar
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.
44 InductionVariable(PHINode *PN, LoopInfo *LoopInfo = 0);
47 static enum iType Classify(const Value *Start, const Value *Step,
50 // Get number of times this loop will execute. Returns NULL if unpredictable.
51 Value* getExecutionCount(LoopInfo *LoopInfo);
53 void print(std::ostream &OS) const;