Forward-declare Loop and LoopInfo instead of #including LoopInfo.h.
[oota-llvm.git] / include / llvm / Analysis / LoopVR.h
1 //===- LoopVR.cpp - Value Range analysis driven by loop information -------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the interface for the loop-driven value range pass.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ANALYSIS_LOOPVR_H
15 #define LLVM_ANALYSIS_LOOPVR_H
16
17 #include "llvm/Pass.h"
18 #include "llvm/Analysis/ScalarEvolution.h"
19 #include "llvm/Support/ConstantRange.h"
20 #include <iosfwd>
21 #include <map>
22
23 namespace llvm {
24
25 /// LoopVR - This class maintains a mapping of Values to ConstantRanges.
26 /// There are interfaces to look up and update ranges by value, and for
27 /// accessing all values with range information.
28 ///
29 class LoopVR : public FunctionPass {
30 public:
31   static char ID; // Class identification, replacement for typeinfo
32
33   LoopVR() : FunctionPass(&ID) {}
34
35   bool runOnFunction(Function &F);
36   virtual void print(std::ostream &os, const Module *) const;
37   void releaseMemory();
38
39   void getAnalysisUsage(AnalysisUsage &AU) const;
40
41   //===---------------------------------------------------------------------
42   // Methods that are used to look up and update particular values.
43
44   /// get - return the ConstantRange for a given Value of IntegerType.
45   ConstantRange get(Value *V);
46
47   /// remove - remove a value from this analysis.
48   void remove(Value *V);
49
50   /// narrow - improve our unterstanding of a Value by pointing out that it
51   /// must fall within ConstantRange. To replace a range, remove it first.
52   void narrow(Value *V, const ConstantRange &CR);
53
54   //===---------------------------------------------------------------------
55   // Methods that are used to iterate across all values with information.
56
57   /// size - returns the number of Values with information
58   unsigned size() const { return Map.size(); }
59
60   typedef std::map<Value *, ConstantRange *>::iterator iterator;
61
62   /// begin - return an iterator to the first Value, ConstantRange pair
63   iterator begin() { return Map.begin(); }
64
65   /// end - return an iterator one past the last Value, ConstantRange pair
66   iterator end() { return Map.end(); }
67
68   /// getValue - return the Value referenced by an iterator
69   Value *getValue(iterator I) { return I->first; }
70
71   /// getConstantRange - return the ConstantRange referenced by an iterator
72   ConstantRange getConstantRange(iterator I) { return *I->second; }
73
74 private:
75   ConstantRange compute(Value *V);
76
77   ConstantRange getRange(const SCEV *S, Loop *L, ScalarEvolution &SE);
78
79   ConstantRange getRange(const SCEV *S, const SCEV *T, ScalarEvolution &SE);
80
81   std::map<Value *, ConstantRange *> Map;
82 };
83
84 } // end llvm namespace
85
86 #endif