Method.h no longer includes BasicBlock.h
[oota-llvm.git] / include / llvm / Analysis / Expressions.h
1 //===- llvm/Analysis/Expressions.h - Expression Analysis Utils ---*- C++ -*--=//
2 //
3 // This file defines a package of expression analysis utilties:
4 //
5 // ClassifyExpression: Analyze an expression to determine the complexity of the
6 //   expression, and which other variables it depends on.  
7 // 
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_ANALYSIS_EXPRESSIONS_H
11 #define LLVM_ANALYSIS_EXPRESSIONS_H
12
13 #include <assert.h>
14 class Type;
15 class Value;
16 class ConstantInt;
17
18 namespace analysis {
19
20 struct ExprType;
21
22 // ClassifyExpression: Analyze an expression to determine the complexity of the
23 // expression, and which other values it depends on.  
24 //
25 ExprType ClassifyExpression(Value *Expr);
26
27 // ExprType - Represent an expression of the form CONST*VAR+CONST
28 // or simpler.  The expression form that yields the least information about the
29 // expression is just the Linear form with no offset.
30 //
31 struct ExprType {
32   enum ExpressionType {
33     Constant,            // Expr is a simple constant, Offset is value
34     Linear,              // Expr is linear expr, Value is Var+Offset
35     ScaledLinear,        // Expr is scaled linear exp, Value is Scale*Var+Offset
36   } ExprTy;
37
38   const ConstantInt *Offset;  // Offset of expr, or null if 0
39   Value             *Var;     // Var referenced, if Linear or above (null if 0)
40   const ConstantInt *Scale;   // Scale of var if ScaledLinear expr (null if 1)
41
42   inline ExprType(const ConstantInt *CPV = 0) {
43     Offset = CPV; Var = 0; Scale = 0;
44     ExprTy = Constant;
45   }
46   ExprType(Value *Val);        // Create a linear or constant expression
47   ExprType(const ConstantInt *scale, Value *var, const ConstantInt *offset);
48
49   // If this expression has an intrinsic type, return it.  If it is zero, return
50   // the specified type.
51   //
52   const Type *getExprType(const Type *Default) const;
53 };
54
55 } // End namespace analysis
56
57 #endif