2003-09-10 05:24:09 +00:00
|
|
|
//===- llvm/Analysis/InductionVariable.h - Induction variables --*- C++ -*-===//
|
2003-10-20 20:19:47 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-11-26 18:41:20 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2002-07-27 01:12:15 +00:00
|
|
|
#include <iosfwd>
|
2001-11-26 18:41:20 +00:00
|
|
|
class Value;
|
|
|
|
class PHINode;
|
|
|
|
class Instruction;
|
2002-04-28 16:19:42 +00:00
|
|
|
class LoopInfo; class Loop;
|
2001-11-26 18:41:20 +00:00
|
|
|
|
|
|
|
class InductionVariable {
|
|
|
|
public:
|
|
|
|
enum iType { // Identify the type of this induction variable
|
2003-09-10 05:24:09 +00:00
|
|
|
Canonical, // Starts at 0, counts by 1
|
2001-11-26 18:41:20 +00:00
|
|
|
SimpleLinear, // Simple linear: Constant start, constant step
|
|
|
|
Linear, // General linear: loop invariant start, and step
|
|
|
|
Unknown, // Unknown type. Start & Step are null
|
|
|
|
} InductionType;
|
|
|
|
|
2002-10-11 05:34:32 +00:00
|
|
|
Value *Start, *Step, *End; // Start, step, and end expressions for this indvar
|
2001-11-26 18:41:20 +00:00
|
|
|
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.
|
|
|
|
//
|
2002-04-28 16:19:42 +00:00
|
|
|
InductionVariable(PHINode *PN, LoopInfo *LoopInfo = 0);
|
2001-11-26 18:41:20 +00:00
|
|
|
|
|
|
|
// Classify Induction
|
|
|
|
static enum iType Classify(const Value *Start, const Value *Step,
|
2002-04-28 16:19:42 +00:00
|
|
|
const Loop *L = 0);
|
2002-07-27 01:12:15 +00:00
|
|
|
|
2002-10-11 05:34:32 +00:00
|
|
|
// Get number of times this loop will execute. Returns NULL if unpredictable.
|
|
|
|
Value* getExecutionCount(LoopInfo *LoopInfo);
|
|
|
|
|
2002-07-27 01:12:15 +00:00
|
|
|
void print(std::ostream &OS) const;
|
2001-11-26 18:41:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|