AliasMapXAIF.hpp

Go to the documentation of this file.
00001 
00022 #ifndef AliasMapXAIF_H
00023 #define AliasMapXAIF_H
00024 
00025 #include <cassert>
00026 #include <iostream>
00027 #include <map>
00028 #include <set>
00029 #include <vector>
00030 #include <OpenAnalysis/Utils/OA_ptr.hpp>
00031 #include <OpenAnalysis/Alias/Interface.hpp>
00032 #include <OpenAnalysis/Alias/AliasMap.hpp>
00033 #include <OpenAnalysis/MemRefExpr/MemRefExpr.hpp>
00034 #include <OpenAnalysis/Location/Locations.hpp>
00035 
00036 #include <OpenAnalysis/IRInterface/IRHandles.hpp>
00037 #include <OpenAnalysis/OABase/Annotation.hpp>
00038 
00039 namespace OA {
00040   namespace XAIF {
00041 
00042 typedef std::set<MemRefHandle> MemRefSet;
00043 //typedef std::set<OA_ptr<Location::Location> > LocSet;
00044 
00046 class LocRange : public virtual Annotation {
00047   public:
00048     LocRange(int start, int end) : mStart(start), mEnd(end) {}
00049     ~LocRange() {}
00050 
00051     int getStart() const { return mStart; }
00052     int getEnd() const { return mEnd; }
00053 
00054     void output(IRHandlesIRInterface& ir)
00055     {
00056         sOutBuild->objStart("LocRange");
00057         sOutBuild->field("mStart", OA::int2string(mStart) );
00058         sOutBuild->field("mEnd", OA::int2string(mEnd) );
00059         sOutBuild->objEnd("LocRange");
00060     }
00061   private:
00062     int mStart, mEnd;
00063 };
00064 
00067 class LocTuple : public virtual Annotation {
00068   public:
00069     LocTuple() : mRange(0,0), mFullOverlap(false) {}
00070     LocTuple(int start, int end, bool fullOverlap) 
00071         : mRange(start,end), mFullOverlap(fullOverlap) {}
00072     ~LocTuple() {}
00073 
00074     LocRange getLocRange() const { return mRange; }
00075     bool isFull() const { return mFullOverlap; }
00076 
00077     bool operator==(const LocTuple& other) const
00078     { if (mRange.getStart() == other.getLocRange().getStart()
00079           && mRange.getEnd() == other.getLocRange().getEnd()
00080           && mFullOverlap == other.mFullOverlap) 
00081       { return true;} else { return false; }
00082     }
00083 
00084     bool operator!=(const LocTuple& other) const 
00085     { return !(*this == other); }
00086 
00087     bool operator<(const LocTuple& other) const
00088     { if (*this == other)  { return false; }
00089       else if (mRange.getStart() < other.mRange.getStart()) { return true; }
00090       else if (mRange.getStart() > other.mRange.getStart()) { return false; }
00091       else if (mRange.getEnd() < other.mRange.getEnd()) { return true; }
00092       else if (mRange.getEnd() > other.mRange.getEnd()) { return false; }
00093       else if (mFullOverlap == true) { return true; }
00094       else { return false; }
00095     }
00096 
00097     void output(IRHandlesIRInterface& ir) 
00098     {
00099         sOutBuild->objStart("LocTuple");
00100         sOutBuild->fieldStart("mRange");
00101         mRange.output(ir);
00102         sOutBuild->fieldEnd("mRange");
00103         sOutBuild->field("mFullOverlap",OA::bool2string(mFullOverlap));
00104         sOutBuild->objEnd("LocTuple");
00105     }
00106        
00107   private:
00108     LocRange mRange;
00109     bool mFullOverlap;
00110 };
00111 
00112 
00114 class IdIterator{
00115   public:
00116     IdIterator(std::map<int,OA_ptr<std::set<LocTuple> > >& aMap)
00117       {
00118         // iterate through ids and put them in a set
00119         std::map<int,OA_ptr<std::set<LocTuple> > >::iterator mapIter;
00120         for (mapIter=aMap.begin(); mapIter!=aMap.end(); mapIter++) {
00121             mSet.insert(mapIter->first);
00122         }
00123         reset();
00124       }
00125     ~IdIterator() {}
00126 
00127     void operator++() { if (isValid()) mIter++; }
00128     bool isValid() const  { return mIter!=mSet.end(); }
00129     int current() const  { return *mIter; }
00130     void reset() { mIter = mSet.begin(); }
00131   private:
00132     std::set<int> mSet;
00133     std::set<int>::iterator mIter;
00134 };
00135 
00137 class LocTupleIterator {
00138   public:
00139     LocTupleIterator(std::set<LocTuple>& pSet)
00140       {
00141         // copy the set so we don't depend on aSet hanging around in memory
00142         mSet = pSet;
00143         reset();
00144       }
00145     ~LocTupleIterator() {}
00146 
00147     void operator++() { if (isValid()) mIter++; }
00148     bool isValid() const  { return mIter!=mSet.end(); }
00149     LocTuple current() const  { return *mIter; }
00150     void reset() { mIter = mSet.begin(); }
00151   private:
00152     std::set<LocTuple> mSet;
00153     std::set<LocTuple>::iterator  mIter;
00154 };
00155 
00156 
00157 class AliasMapXAIF : public virtual Annotation {
00158   public:
00159     AliasMapXAIF(ProcHandle p);
00160     ~AliasMapXAIF() {}
00161 
00162     static const int SET_ID_NONE = -1; 
00163 
00167     OA_ptr<MemRefHandleIterator> getMemRefIter();
00168 
00169     //*****************************************************************
00170     // Info methods unique to Alias::AliasMapXAIF
00171     //*****************************************************************
00172 
00175     int getMapSetId(MemRefHandle ref); 
00176      
00179     int findMapSet(MemRefHandle ref);
00180 
00183     int findMapSet(OA_ptr<std::set<LocTuple> > pLocTupleSet);
00184 
00186     OA_ptr<IdIterator> getIdIterator();
00187 
00189     OA_ptr<LocTupleIterator> getLocIterator(int setId); 
00190 
00191     //*****************************************************************
00192     // Construction methods 
00193     //*****************************************************************
00194     
00196     void mapLocTupleSet(OA_ptr<std::set<LocTuple> > ltSet, int setId);
00197 
00201     void mapMemRefToMapSet(MemRefHandle ref, int setId);
00202 
00203     //*****************************************************************
00204     // Output
00205     //*****************************************************************
00206 
00207     void output(IRHandlesIRInterface& ir);
00208 
00212     void dump(std::ostream& os, OA_ptr<OA::IRHandlesIRInterface> ir);
00213 
00214   private:
00215     // data members
00216     ProcHandle mProcHandle; // procedure these sets are associated with
00217 
00218     // keep track of id mapping to location sets and status with a map
00219     std::map<int,OA_ptr<std::set<LocTuple> > > mIdToLocTupleSetMap; 
00220 
00221     // what memory references map to this alias map set
00222     std::map<int,MemRefSet> mIdToMemRefSetMap;
00223 
00224     // the location set a MemRefHandle maps to
00225     std::map<MemRefHandle,int> mMemRefToIdMap;  
00226 
00227     // set of memrefexpr for a memref
00228     std::map<MemRefHandle,std::set<OA_ptr<MemRefExpr> > > 
00229         mMemRefToMRESetMap;
00230 };
00231 
00232 
00233   } // end of Alias namespace
00234 } // end of OA namespace
00235 
00236 #endif
00237 

Generated on Sat Oct 31 05:21:20 2009 for OpenAnalysis by  doxygen 1.6.1