Added LLVM copyright header (for lack of a better term).
[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 an 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 class Value;
31 class PHINode;
32 class Instruction;
33 class LoopInfo; class Loop;
34
35 class InductionVariable {
36 public:
37   enum iType {               // Identify the type of this induction variable
38     Canonical,               // Starts at 0, counts by 1
39     SimpleLinear,            // Simple linear: Constant start, constant step
40     Linear,                  // General linear:  loop invariant start, and step
41     Unknown,                 // Unknown type.  Start & Step are null
42   } InductionType;
43   
44   Value *Start, *Step, *End; // Start, step, and end expressions for this indvar
45   PHINode *Phi;              // The PHI node that corresponds to this indvar
46 public:
47
48   // Create an induction variable for the specified value.  If it is a PHI, and
49   // if it's recognizable, classify it and fill in instance variables.
50   //
51   InductionVariable(PHINode *PN, LoopInfo *LoopInfo = 0);
52
53   // Classify Induction
54   static enum iType Classify(const Value *Start, const Value *Step,
55                              const Loop *L = 0);
56
57   // Get number of times this loop will execute. Returns NULL if unpredictable.
58   Value* getExecutionCount(LoopInfo *LoopInfo);
59
60   void print(std::ostream &OS) const;
61 };
62
63 #endif