1 //===- LoopVR.cpp - Value Range analysis driven by loop information -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interface for the loop-driven value range pass.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_LOOPVR_H
15 #define LLVM_ANALYSIS_LOOPVR_H
17 #include "llvm/Pass.h"
18 #include "llvm/Analysis/ScalarEvolution.h"
19 #include "llvm/Support/ConstantRange.h"
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.
28 class LoopVR : public FunctionPass {
30 static char ID; // Class identification, replacement for typeinfo
32 LoopVR() : FunctionPass(&ID) {}
34 bool runOnFunction(Function &F);
35 virtual void print(raw_ostream &os, const Module *) const;
38 void getAnalysisUsage(AnalysisUsage &AU) const;
40 //===---------------------------------------------------------------------
41 // Methods that are used to look up and update particular values.
43 /// get - return the ConstantRange for a given Value of IntegerType.
44 ConstantRange get(Value *V);
46 /// remove - remove a value from this analysis.
47 void remove(Value *V);
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);
53 //===---------------------------------------------------------------------
54 // Methods that are used to iterate across all values with information.
56 /// size - returns the number of Values with information
57 unsigned size() const { return Map.size(); }
59 typedef std::map<Value *, ConstantRange *>::iterator iterator;
61 /// begin - return an iterator to the first Value, ConstantRange pair
62 iterator begin() { return Map.begin(); }
64 /// end - return an iterator one past the last Value, ConstantRange pair
65 iterator end() { return Map.end(); }
67 /// getValue - return the Value referenced by an iterator
68 Value *getValue(iterator I) { return I->first; }
70 /// getConstantRange - return the ConstantRange referenced by an iterator
71 ConstantRange getConstantRange(iterator I) { return *I->second; }
74 ConstantRange compute(Value *V);
76 ConstantRange getRange(const SCEV *S, Loop *L, ScalarEvolution &SE);
78 ConstantRange getRange(const SCEV *S, const SCEV *T, ScalarEvolution &SE);
80 std::map<Value *, ConstantRange *> Map;
83 } // end llvm namespace