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 {
40 AU.addRequiredTransitive<LoopInfo>();
41 AU.addRequiredTransitive<ScalarEvolution>();
45 //===---------------------------------------------------------------------
46 // Methods that are used to look up and update particular values.
48 /// get - return the ConstantRange for a given Value of IntegerType.
49 ConstantRange get(Value *V);
51 /// remove - remove a value from this analysis.
52 void remove(Value *V);
54 /// narrow - improve our unterstanding of a Value by pointing out that it
55 /// must fall within ConstantRange. To replace a range, remove it first.
56 void narrow(Value *V, const ConstantRange &CR);
58 //===---------------------------------------------------------------------
59 // Methods that are used to iterate across all values with information.
61 /// size - returns the number of Values with information
62 unsigned size() const { return Map.size(); }
64 typedef std::map<Value *, ConstantRange *>::iterator iterator;
66 /// begin - return an iterator to the first Value, ConstantRange pair
67 iterator begin() { return Map.begin(); }
69 /// end - return an iterator one past the last Value, ConstantRange pair
70 iterator end() { return Map.end(); }
72 /// getValue - return the Value referenced by an iterator
73 Value *getValue(iterator I) { return I->first; }
75 /// getConstantRange - return the ConstantRange referenced by an iterator
76 ConstantRange getConstantRange(iterator I) { return *I->second; }
79 ConstantRange compute(Value *V);
81 ConstantRange getRange(const SCEV* S, Loop *L, ScalarEvolution &SE);
83 ConstantRange getRange(const SCEV* S, const SCEV* T, ScalarEvolution &SE);
85 std::map<Value *, ConstantRange *> Map;
88 } // end llvm namespace