LLVM API Documentation
00001 //===- LoopVR.cpp - Value Range analysis driven by loop information -------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the interface for the loop-driven value range pass. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_ANALYSIS_LOOPVR_H 00015 #define LLVM_ANALYSIS_LOOPVR_H 00016 00017 #include "llvm/Pass.h" 00018 #include "llvm/Analysis/ScalarEvolution.h" 00019 #include "llvm/Support/ConstantRange.h" 00020 #include <iosfwd> 00021 #include <map> 00022 00023 namespace llvm { 00024 00025 /// LoopVR - This class maintains a mapping of Values to ConstantRanges. 00026 /// There are interfaces to look up and update ranges by value, and for 00027 /// accessing all values with range information. 00028 /// 00029 class LoopVR : public FunctionPass { 00030 public: 00031 static char ID; // Class identification, replacement for typeinfo 00032 00033 LoopVR() : FunctionPass(intptr_t(&ID)) {} 00034 00035 bool runOnFunction(Function &F); 00036 virtual void print(std::ostream &os, const Module *) const; 00037 void releaseMemory(); 00038 00039 void getAnalysisUsage(AnalysisUsage &AU) const { 00040 AU.addRequiredTransitive<LoopInfo>(); 00041 AU.addRequiredTransitive<ScalarEvolution>(); 00042 AU.setPreservesAll(); 00043 } 00044 00045 //===--------------------------------------------------------------------- 00046 // Methods that are used to look up and update particular values. 00047 00048 /// get - return the ConstantRange for a given Value of IntegerType. 00049 ConstantRange get(Value *V); 00050 00051 /// remove - remove a value from this analysis. 00052 void remove(Value *V); 00053 00054 /// narrow - improve our unterstanding of a Value by pointing out that it 00055 /// must fall within ConstantRange. To replace a range, remove it first. 00056 void narrow(Value *V, const ConstantRange &CR); 00057 00058 //===--------------------------------------------------------------------- 00059 // Methods that are used to iterate across all values with information. 00060 00061 /// size - returns the number of Values with information 00062 unsigned size() const { return Map.size(); } 00063 00064 typedef std::map<Value *, ConstantRange *>::iterator iterator; 00065 00066 /// begin - return an iterator to the first Value, ConstantRange pair 00067 iterator begin() { return Map.begin(); } 00068 00069 /// end - return an iterator one past the last Value, ConstantRange pair 00070 iterator end() { return Map.end(); } 00071 00072 /// getValue - return the Value referenced by an iterator 00073 Value *getValue(iterator I) { return I->first; } 00074 00075 /// getConstantRange - return the ConstantRange referenced by an iterator 00076 ConstantRange getConstantRange(iterator I) { return *I->second; } 00077 00078 private: 00079 ConstantRange compute(Value *V); 00080 00081 ConstantRange getRange(SCEVHandle S, Loop *L, ScalarEvolution &SE); 00082 00083 ConstantRange getRange(SCEVHandle S, SCEVHandle T, ScalarEvolution &SE); 00084 00085 std::map<Value *, ConstantRange *> Map; 00086 }; 00087 00088 } // end llvm namespace 00089 00090 #endif