1 //===- llvm/Analysis/InductionVariable.h - Induction variables --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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
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.
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.
24 //===----------------------------------------------------------------------===//
26 #ifndef LLVM_ANALYSIS_INDUCTIONVARIABLE_H
27 #define LLVM_ANALYSIS_INDUCTIONVARIABLE_H
33 class LoopInfo; class Loop;
35 class InductionVariable {
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
44 Value *Start, *Step, *End; // Start, step, and end expressions for this indvar
45 PHINode *Phi; // The PHI node that corresponds to this indvar
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.
51 InductionVariable(PHINode *PN, LoopInfo *LoopInfo = 0);
54 static enum iType Classify(const Value *Start, const Value *Step,
57 // Get number of times this loop will execute. Returns NULL if unpredictable.
58 Value* getExecutionCount(LoopInfo *LoopInfo);
60 void print(std::ostream &OS) const;