Add support for many of the MRegisterInfo callbacks.
[oota-llvm.git] / include / llvm / Analysis / InductionVariable.h
1 //===- llvm/Analysis/InductionVariable.h - Induction variables --*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This interface is used to identify and classify induction variables that
11 // exist in the program.  Induction variables must contain a PHI node that
12 // exists in a loop header.  Because of this, they are identified and managed by
13 // this PHI node.
14 //
15 // Induction variables are classified into a type.  Knowing that an induction
16 // variable is of a specific type can constrain the values of the start and
17 // step.  For example, a SimpleLinear induction variable must have a start and
18 // step values that are constants.
19 //
20 // Induction variables can be created with or without loop information.  If no
21 // loop information is available, induction variables cannot be recognized to be
22 // more than SimpleLinear variables.
23 //
24 //===----------------------------------------------------------------------===//
25
26 #ifndef LLVM_ANALYSIS_INDUCTIONVARIABLE_H
27 #define LLVM_ANALYSIS_INDUCTIONVARIABLE_H
28
29 #include <iosfwd>
30
31 namespace llvm {
32
33 class Value;
34 class PHINode;
35 class Instruction;
36 class LoopInfo; class Loop;
37
38 class InductionVariable {
39 public:
40   enum iType {               // Identify the type of this induction variable
41     Canonical,               // Starts at 0, counts by 1
42     SimpleLinear,            // Simple linear: Constant start, constant step
43     Linear,                  // General linear:  loop invariant start, and step
44     Unknown,                 // Unknown type.  Start & Step are null
45   } InductionType;
46   
47   Value *Start, *Step, *End; // Start, step, and end expressions for this indvar
48   PHINode *Phi;              // The PHI node that corresponds to this indvar
49 public:
50
51   // Create an induction variable for the specified value.  If it is a PHI, and
52   // if it's recognizable, classify it and fill in instance variables.
53   //
54   InductionVariable(PHINode *PN, LoopInfo *LoopInfo = 0);
55
56   // Classify Induction
57   static enum iType Classify(const Value *Start, const Value *Step,
58                              const Loop *L = 0);
59
60   // Get number of times this loop will execute. Returns NULL if unpredictable.
61   Value* getExecutionCount(LoopInfo *LoopInfo);
62
63   void print(std::ostream &OS) const;
64 };
65
66 } // End llvm namespace
67
68 #endif