More functionality, renamed API
[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 Value;
15 class ConstPoolInt;
16
17 namespace analysis {
18
19 struct ExprType;
20
21 // ClassifyExpression: Analyze an expression to determine the complexity of the
22 // expression, and which other values it depends on.  
23 //
24 ExprType ClassifyExpression(Value *Expr);
25
26 // ExprType - Represent an expression of the form CONST*VAR+CONST
27 // or simpler.  The expression form that yields the least information about the
28 // expression is just the Linear form with no offset.
29 //
30 struct ExprType {
31   enum ExpressionType {
32     Constant,            // Expr is a simple constant, Offset is value
33     Linear,              // Expr is linear expr, Value is Var+Offset
34     ScaledLinear,        // Expr is scaled linear exp, Value is Scale*Var+Offset
35   } ExprTy;
36
37   const ConstPoolInt *Offset;  // Offset of expr, or null if 0
38   Value              *Var;     // Var referenced, if Linear or above (null if 0)
39   const ConstPoolInt *Scale;   // Scale of var if ScaledLinear expr (null if 1)
40
41   inline ExprType(const ConstPoolInt *CPV = 0) {
42     Offset = CPV; Var = 0; Scale = 0;
43     ExprTy = Constant;
44   }
45   inline ExprType(Value *Val) {
46     Var = Val; Offset = Scale = 0;
47     ExprTy = Var ? Linear : Constant;
48   }
49   inline ExprType(const ConstPoolInt *scale, Value *var, 
50                   const ConstPoolInt *offset) {
51     Scale = scale; Var = var; Offset = offset;
52     ExprTy = Scale ? ScaledLinear : (Var ? Linear : Constant);
53   }
54 };
55
56 } // End namespace analysis
57
58 #endif