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"
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.
29 class LoopVR : public FunctionPass {
31 static char ID; // Class identification, replacement for typeinfo
33 LoopVR() : FunctionPass(&ID) {}
35 bool runOnFunction(Function &F);
36 virtual void print(std::ostream &os, const Module *) const;
39 void getAnalysisUsage(AnalysisUsage &AU) const;
41 //===---------------------------------------------------------------------
42 // Methods that are used to look up and update particular values.
44 /// get - return the ConstantRange for a given Value of IntegerType.
45 ConstantRange get(Value *V);
47 /// remove - remove a value from this analysis.
48 void remove(Value *V);
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);
54 //===---------------------------------------------------------------------
55 // Methods that are used to iterate across all values with information.
57 /// size - returns the number of Values with information
58 unsigned size() const { return Map.size(); }
60 typedef std::map<Value *, ConstantRange *>::iterator iterator;
62 /// begin - return an iterator to the first Value, ConstantRange pair
63 iterator begin() { return Map.begin(); }
65 /// end - return an iterator one past the last Value, ConstantRange pair
66 iterator end() { return Map.end(); }
68 /// getValue - return the Value referenced by an iterator
69 Value *getValue(iterator I) { return I->first; }
71 /// getConstantRange - return the ConstantRange referenced by an iterator
72 ConstantRange getConstantRange(iterator I) { return *I->second; }
75 ConstantRange compute(Value *V);
77 ConstantRange getRange(const SCEV *S, Loop *L, ScalarEvolution &SE);
79 ConstantRange getRange(const SCEV *S, const SCEV *T, ScalarEvolution &SE);
81 std::map<Value *, ConstantRange *> Map;
84 } // end llvm namespace