Minor code simplification.
[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 <map>
21
22 namespace llvm {
23
24 /// LoopVR - This class maintains a mapping of Values to ConstantRanges.
25 /// There are interfaces to look up and update ranges by value, and for
26 /// accessing all values with range information.
27 ///
28 class LoopVR : public FunctionPass {
29 public:
30   static char ID; // Class identification, replacement for typeinfo
31
32   LoopVR() : FunctionPass(&ID) {}
33
34   bool runOnFunction(Function &F);
35   virtual void print(raw_ostream &os, const Module *) const;
36   void releaseMemory();
37
38   void getAnalysisUsage(AnalysisUsage &AU) const;
39
40   //===---------------------------------------------------------------------
41   // Methods that are used to look up and update particular values.
42
43   /// get - return the ConstantRange for a given Value of IntegerType.
44   ConstantRange get(Value *V);
45
46   /// remove - remove a value from this analysis.
47   void remove(Value *V);
48
49   /// narrow - improve our unterstanding of a Value by pointing out that it
50   /// must fall within ConstantRange. To replace a range, remove it first.
51   void narrow(Value *V, const ConstantRange &CR);
52
53   //===---------------------------------------------------------------------
54   // Methods that are used to iterate across all values with information.
55
56   /// size - returns the number of Values with information
57   unsigned size() const { return Map.size(); }
58
59   typedef std::map<Value *, ConstantRange *>::iterator iterator;
60
61   /// begin - return an iterator to the first Value, ConstantRange pair
62   iterator begin() { return Map.begin(); }
63
64   /// end - return an iterator one past the last Value, ConstantRange pair
65   iterator end() { return Map.end(); }
66
67   /// getValue - return the Value referenced by an iterator
68   Value *getValue(iterator I) { return I->first; }
69
70   /// getConstantRange - return the ConstantRange referenced by an iterator
71   ConstantRange getConstantRange(iterator I) { return *I->second; }
72
73 private:
74   ConstantRange compute(Value *V);
75
76   ConstantRange getRange(const SCEV *S, Loop *L, ScalarEvolution &SE);
77
78   ConstantRange getRange(const SCEV *S, const SCEV *T, ScalarEvolution &SE);
79
80   std::map<Value *, ConstantRange *> Map;
81 };
82
83 } // end llvm namespace
84
85 #endif