aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/Analysis/InductionVariable.h
blob: 26deb832f80770098ce14397cf6c8f8a98f8a3c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//===- llvm/Analysis/InductionVariable.h - Induction variables --*- C++ -*-===//
// 
//                     The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
// 
//===----------------------------------------------------------------------===//
//
// This interface is used to identify and classify induction variables that
// exist in the program.  Induction variables must contain a PHI node that
// exists in a loop header.  Because of this, they are identified an managed by
// this PHI node.
//
// Induction variables are classified into a type.  Knowing that an induction
// variable is of a specific type can constrain the values of the start and
// step.  For example, a SimpleLinear induction variable must have a start and
// step values that are constants.
//
// Induction variables can be created with or without loop information.  If no
// loop information is available, induction variables cannot be recognized to be
// more than SimpleLinear variables.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_ANALYSIS_INDUCTIONVARIABLE_H
#define LLVM_ANALYSIS_INDUCTIONVARIABLE_H

#include <iosfwd>
class Value;
class PHINode;
class Instruction;
class LoopInfo; class Loop;

class InductionVariable {
public:
  enum iType {               // Identify the type of this induction variable
    Canonical,               // Starts at 0, counts by 1
    SimpleLinear,            // Simple linear: Constant start, constant step
    Linear,                  // General linear:  loop invariant start, and step
    Unknown,                 // Unknown type.  Start & Step are null
  } InductionType;
  
  Value *Start, *Step, *End; // Start, step, and end expressions for this indvar
  PHINode *Phi;              // The PHI node that corresponds to this indvar
public:

  // Create an induction variable for the specified value.  If it is a PHI, and
  // if it's recognizable, classify it and fill in instance variables.
  //
  InductionVariable(PHINode *PN, LoopInfo *LoopInfo = 0);

  // Classify Induction
  static enum iType Classify(const Value *Start, const Value *Step,
			     const Loop *L = 0);

  // Get number of times this loop will execute. Returns NULL if unpredictable.
  Value* getExecutionCount(LoopInfo *LoopInfo);

  void print(std::ostream &OS) const;
};

#endif