LLVM API Documentation

LoopVR.h

Go to the documentation of this file.
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(&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 
00041   //===---------------------------------------------------------------------
00042   // Methods that are used to look up and update particular values.
00043 
00044   /// get - return the ConstantRange for a given Value of IntegerType.
00045   ConstantRange get(Value *V);
00046 
00047   /// remove - remove a value from this analysis.
00048   void remove(Value *V);
00049 
00050   /// narrow - improve our unterstanding of a Value by pointing out that it
00051   /// must fall within ConstantRange. To replace a range, remove it first.
00052   void narrow(Value *V, const ConstantRange &CR);
00053 
00054   //===---------------------------------------------------------------------
00055   // Methods that are used to iterate across all values with information.
00056 
00057   /// size - returns the number of Values with information
00058   unsigned size() const { return Map.size(); }
00059 
00060   typedef std::map<Value *, ConstantRange *>::iterator iterator;
00061 
00062   /// begin - return an iterator to the first Value, ConstantRange pair
00063   iterator begin() { return Map.begin(); }
00064 
00065   /// end - return an iterator one past the last Value, ConstantRange pair
00066   iterator end() { return Map.end(); }
00067 
00068   /// getValue - return the Value referenced by an iterator
00069   Value *getValue(iterator I) { return I->first; }
00070 
00071   /// getConstantRange - return the ConstantRange referenced by an iterator
00072   ConstantRange getConstantRange(iterator I) { return *I->second; }
00073 
00074 private:
00075   ConstantRange compute(Value *V);
00076 
00077   ConstantRange getRange(const SCEV *S, Loop *L, ScalarEvolution &SE);
00078 
00079   ConstantRange getRange(const SCEV *S, const SCEV *T, ScalarEvolution &SE);
00080 
00081   std::map<Value *, ConstantRange *> Map;
00082 };
00083 
00084 } // end llvm namespace
00085 
00086 #endif